Stackedit/public/res/main.js

223 lines
5.8 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({
2014-04-27 20:10:30 +00:00
waitSeconds: 0,
packages: [
{
name: 'css',
location: 'bower-libs/require-css',
main: 'css'
},
{
name: 'less',
location: 'bower-libs/require-less',
main: 'less'
}
],
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',
'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',
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',
'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',
normalize: 'bower-libs/require-css/normalize',
prism: 'bower-libs/prism/prism',
'prism-core': 'bower-libs/prism/components/prism-core',
MutationObservers: 'bower-libs/MutationObservers/MutationObserver',
WeakMap: 'bower-libs/WeakMap/weakmap',
rangy: 'bower-libs/rangy/rangy-core',
'rangy-cssclassapplier': 'bower-libs/rangy/rangy-cssclassapplier',
diff_match_patch: 'bower-libs/google-diff-match-patch-js/diff_match_patch',
diff_match_patch_uncompressed: 'bower-libs/google-diff-match-patch-js/diff_match_patch_uncompressed',
jsondiffpatch: 'bower-libs/jsondiffpatch/build/bundle',
hammerjs: 'bower-libs/hammerjs/hammer',
'sequence-diagram': 'libs/sequence-diagram',
raphael: 'bower-libs/raphael/raphael',
'flow-chart': 'bower-libs/flowchart/release/flowchart.amd-1.2.10.min',
flowchart: 'bower-libs/flowchart/release/flowchart-1.2.10.min'
},
shim: {
underscore: {
exports: '_'
},
mathjax: [
'libs/mathjax_init'
],
jgrowl: {
deps: [
'jquery'
],
exports: 'jQuery.jGrowl'
},
diff_match_patch_uncompressed: {
exports: 'diff_match_patch'
},
jsondiffpatch: [
'diff_match_patch_uncompressed'
],
rangy: {
exports: 'rangy'
},
'rangy-cssclassapplier': [
'rangy'
],
mousetrap: {
exports: 'Mousetrap'
},
'yaml-js': {
exports: 'YAML'
},
'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'
],
toMarkdown: {
deps: [
'jquery'
],
exports: 'toMarkdown'
},
stacktrace: {
exports: 'printStackTrace'
},
FileSaver: {
exports: 'saveAs'
},
MutationObservers: [
'WeakMap'
],
highlightjs: {
exports: 'hljs'
},
'bootstrap-tour': {
deps: [
'bootstrap'
],
exports: 'Tour'
},
bootstrap: [
'jquery'
],
'jquery-waitforimages': [
'jquery'
],
pagedown: [
'libs/Markdown.Converter'
],
'pagedown-extra': [
'libs/Markdown.Converter'
],
'flow-chart': [
'raphael'
]
}
2013-10-19 22:59:17 +00:00
});
// Check browser compatibility
try {
2014-04-27 20:10:30 +00:00
var test = 'seLocalStorageCheck';
localStorage.setItem(test, test);
localStorage.removeItem(test);
var obj = {};
Object.defineProperty(obj, 'prop', {
get: function() {
},
set: function() {
}
});
2013-10-19 22:59:17 +00:00
}
2014-04-27 20:10:30 +00:00
catch(e) {
alert('Your browser is not supported, sorry!');
throw e;
2013-10-19 22:59:17 +00:00
}
// 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;
2014-04-27 20:10:30 +00:00
if(window.baseDir.indexOf('-min') !== -1) {
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-04-27 20:10:30 +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
2014-04-27 20:10:30 +00:00
if(window.noStart) {
return;
}
2013-10-19 22:59:17 +00:00
2014-04-27 20:10:30 +00:00
$(function() {
rangy.init();
2014-03-22 01:57:31 +00:00
2014-04-27 20:10:30 +00:00
// Here, all the modules are loaded and the DOM is ready
core.onReady();
2013-10-19 22:59:17 +00:00
2014-04-27 20:10:30 +00:00
// If browser has detected a new application cache.
if(window.applicationCache) {
window.applicationCache.addEventListener('updateready', function() {
if(window.applicationCache.status === window.applicationCache.UPDATEREADY) {
window.applicationCache.swapCache();
eventMgr.onMessage('New version available!\nJust refresh the page to upgrade.');
}
}, false);
}
});
2013-10-19 22:59:17 +00:00
});