Stackedit/public/res/main.js

225 lines
7.1 KiB
JavaScript
Raw Normal View History

2013-10-19 22:59:17 +00:00
// RequireJS configuration
2013-11-05 23:03:38 +00:00
/*global requirejs */
2013-10-19 22:59:17 +00:00
requirejs.config({
waitSeconds: 0,
packages: [
{
name: 'css',
location: 'bower-libs/require-css',
main: 'css'
},
{
name: 'less',
location: 'bower-libs/require-less',
main: 'less'
}
],
2013-10-19 22:59:17 +00:00
paths: {
jquery: 'bower-libs/jquery/jquery',
underscore: 'bower-libs/underscore/underscore',
crel: 'bower-libs/crel/crel',
jgrowl: 'bower-libs/jgrowl/jquery.jgrowl',
mousetrap: 'bower-libs/mousetrap/mousetrap',
'mousetrap-record': 'bower-libs/mousetrap/plugins/record/mousetrap-record',
toMarkdown: 'bower-libs/to-markdown/src/to-markdown',
text: 'bower-libs/requirejs-text/text',
mathjax: '../libs/MathJax/MathJax.js?config=TeX-AMS_HTML',
bootstrap: 'bower-libs/bootstrap/dist/js/bootstrap',
requirejs: 'bower-libs/requirejs/require',
'google-code-prettify': 'bower-libs/google-code-prettify/src/prettify',
highlightjs: 'libs/highlight/highlight.pack',
2013-10-19 22:59:17 +00:00
'jquery-waitforimages': 'bower-libs/waitForImages/src/jquery.waitforimages',
'jquery-ui': 'bower-libs/jquery-ui/ui/jquery-ui',
'jquery-ui-core': 'bower-libs/jquery-ui/ui/jquery.ui.core',
'jquery-ui-widget': 'bower-libs/jquery-ui/ui/jquery.ui.widget',
'jquery-ui-mouse': 'bower-libs/jquery-ui/ui/jquery.ui.mouse',
'jquery-ui-draggable': 'bower-libs/jquery-ui/ui/jquery.ui.draggable',
'jquery-ui-effect': 'bower-libs/jquery-ui/ui/jquery.ui.effect',
'jquery-ui-effect-slide': 'bower-libs/jquery-ui/ui/jquery.ui.effect-slide',
uilayout: 'libs/layout',
FileSaver: 'bower-libs/FileSaver/FileSaver',
stacktrace: 'bower-libs/stacktrace/stacktrace',
'requirejs-text': 'bower-libs/requirejs-text/text',
'bootstrap-tour': 'bower-libs/bootstrap-tour/build/js/bootstrap-tour',
css_browser_selector: 'bower-libs/css_browser_selector/css_browser_selector',
'pagedown-extra': 'bower-libs/pagedown-extra/Markdown.Extra',
pagedown: 'libs/Markdown.Editor',
2013-10-19 22:59:17 +00:00
'require-css': 'bower-libs/require-css/css',
xregexp: 'bower-libs/xregexp/xregexp-all',
yaml: 'bower-libs/yaml.js',
'yaml.js': 'bower-libs/yaml.js',
'yaml-js': 'bower-libs/yaml.js/bin/yaml',
css: 'bower-libs/require-css/css',
'css-builder': 'bower-libs/require-css/css-builder',
2014-03-16 02:13:42 +00:00
normalize: 'bower-libs/require-css/normalize',
prism: 'bower-libs/prism/prism',
2014-03-21 00:36:28 +00:00
'prism-core': 'bower-libs/prism/components/prism-core',
MutationObservers: 'bower-libs/MutationObservers/MutationObserver',
2014-03-22 01:57:31 +00:00
WeakMap: 'bower-libs/WeakMap/weakmap',
rangy: 'bower-libs/rangy/rangy-core',
2014-03-25 00:23:42 +00:00
'rangy-cssclassapplier': 'bower-libs/rangy/rangy-cssclassapplier',
diff_match_patch: 'bower-libs/google-diff-match-patch-js/diff_match_patch',
2014-03-27 00:20:08 +00:00
diff_match_patch_uncompressed: 'bower-libs/google-diff-match-patch-js/diff_match_patch_uncompressed',
jsondiffpatch: 'bower-libs/jsondiffpatch/build/bundle'
2013-10-19 22:59:17 +00:00
},
shim: {
underscore: {
exports: '_'
},
mathjax: [
'libs/mathjax_init'
],
2013-10-19 22:59:17 +00:00
jgrowl: {
deps: [
'jquery'
],
2013-10-19 22:59:17 +00:00
exports: 'jQuery.jGrowl'
},
2014-03-25 00:23:42 +00:00
diff_match_patch_uncompressed: {
exports: 'diff_match_patch'
},
2014-03-27 00:20:08 +00:00
jsondiffpatch: [
'diff_match_patch_uncompressed'
],
2014-03-22 01:57:31 +00:00
rangy: {
exports: 'rangy'
},
'rangy-cssclassapplier': [
'rangy'
],
2013-10-19 22:59:17 +00:00
mousetrap: {
exports: 'Mousetrap'
},
'yaml-js': {
exports: 'YAML'
},
2014-03-16 02:13:42 +00:00
'prism-core': {
exports: 'Prism'
},
'bower-libs/prism/components/prism-markup': [
'prism-core'
],
'libs/prism-latex': [
'prism-core'
],
'libs/prism-markdown': [
'bower-libs/prism/components/prism-markup',
'libs/prism-latex'
],
'bootstrap-record': [
'mousetrap'
],
2013-10-19 22:59:17 +00:00
toMarkdown: {
deps: [
'jquery'
],
2013-10-19 22:59:17 +00:00
exports: 'toMarkdown'
},
2013-11-05 23:03:38 +00:00
stacktrace: {
exports: 'printStackTrace'
},
FileSaver: {
exports: 'saveAs'
},
2014-03-21 00:36:28 +00:00
MutationObservers: [
'WeakMap'
],
2013-11-07 23:10:38 +00:00
highlightjs: {
exports: 'hljs'
},
'bootstrap-tour': {
deps: [
'bootstrap'
],
2013-11-07 23:10:38 +00:00
exports: 'Tour'
},
bootstrap: [
'jquery'
],
'jquery-waitforimages': [
'jquery'
],
uilayout: [
'jquery-ui-effect-slide'
],
'jquery-ui-effect-slide': [
'jquery-ui-effect'
],
'jquery-ui-effect': [
'jquery-ui-draggable'
],
'jquery-ui-draggable': [
'jquery-ui-mouse'
],
'jquery-ui-mouse': [
'jquery-ui-widget'
],
'jquery-ui-widget': [
'jquery-ui-core'
],
'jquery-ui-core': [
'jquery'
],
2014-03-21 00:36:28 +00:00
pagedown: [
'libs/Markdown.Converter'
],
2014-03-20 00:24:56 +00:00
'pagedown-extra': [
'libs/Markdown.Converter'
2014-03-21 00:36:28 +00:00
]
2013-10-19 22:59:17 +00:00
}
});
// Check browser compatibility
try {
var test = 'seLocalStorageCheck';
localStorage.setItem(test, test);
localStorage.removeItem(test);
var obj = {};
Object.defineProperty(obj, 'prop', {
get: function() {},
set: function() {}
});
}
catch (e) {
alert('Your browser is not supported, sorry!');
throw e;
}
// Viewer mode is deduced from the body class
2013-11-05 23:03:38 +00:00
window.viewerMode = /(^| )viewer($| )/.test(document.body.className);
2013-10-19 22:59:17 +00:00
// Keep the theme in a global variable
2013-12-02 23:29:48 +00:00
window.theme = localStorage.themeV3 || 'default';
2013-11-07 23:10:38 +00:00
var themeModule = "less!themes/" + window.theme;
2013-11-05 23:03:38 +00:00
if (window.baseDir.indexOf('-min') !== -1) {
2013-11-07 23:10:38 +00:00
themeModule = "css!themes/" + window.theme;
2013-10-19 22:59:17 +00:00
}
// RequireJS entry point. By requiring synchronizer, publisher and
// media-importer, we are actually loading all the modules
2014-03-22 01:57:31 +00:00
require(["jquery", "rangy", "core", "eventMgr", "synchronizer", "publisher", "mediaImporter", "css", "rangy-cssclassapplier",
themeModule, ], function($, rangy, core, eventMgr) {
2014-03-20 00:24:56 +00:00
2013-11-05 23:03:38 +00:00
if(window.noStart) {
2013-10-20 14:00:08 +00:00
return;
}
2013-10-19 22:59:17 +00:00
$(function() {
2014-03-22 01:57:31 +00:00
rangy.init();
2013-10-19 22:59:17 +00:00
// Here, all the modules are loaded and the DOM is ready
core.onReady();
// If browser has detected a new application cache.
if (window.applicationCache) {
2013-11-05 23:03:38 +00:00
window.applicationCache.addEventListener('updateready', function() {
2013-10-19 22:59:17 +00:00
if (window.applicationCache.status === window.applicationCache.UPDATEREADY) {
window.applicationCache.swapCache();
eventMgr.onMessage('New version available!\nJust refresh the page to upgrade.');
}
}, false);
}
});
});