diff --git a/js/classes/AsyncTask.js b/js/classes/AsyncTask.js index bc1d1531..52c20061 100644 --- a/js/classes/AsyncTask.js +++ b/js/classes/AsyncTask.js @@ -2,10 +2,10 @@ define([ "underscore", "core", "utils", - "extensionMgr", + "eventMgr", "config", "libs/stacktrace", -], function(_, core, utils, extensionMgr) { +], function(_, core, utils, eventMgr) { var taskQueue = []; @@ -85,7 +85,7 @@ define([ } error = error || new Error("Unknown error"); if(error.message) { - extensionMgr.onError(error); + eventMgr.onError(error); } runSafe(this, this.errorCallbacks, error); // Exit the current call stack @@ -156,7 +156,7 @@ define([ currentTaskStartTime = utils.currentTime; if(asyncRunning === false) { asyncRunning = true; - extensionMgr.onAsyncRunning(true); + eventMgr.onAsyncRunning(true); } } @@ -185,7 +185,7 @@ define([ } if(taskQueue.length === 0) { asyncRunning = false; - extensionMgr.onAsyncRunning(false); + eventMgr.onAsyncRunning(false); } else { runTask(); diff --git a/js/core.js b/js/core.js index 07ccc345..5a650c00 100644 --- a/js/core.js +++ b/js/core.js @@ -3,7 +3,7 @@ define([ "underscore", "utils", "settings", - "extensionMgr", + "eventMgr", "mousetrap", "text!html/settingsTemplateTooltip.html", "text!html/settingsUserCustomExtensionTooltip.html", @@ -12,14 +12,14 @@ define([ "libs/bootstrap", "libs/layout", "libs/Markdown.Editor" -], function($, _, utils, settings, extensionMgr, mousetrap, settingsTemplateTooltipHTML, settingsUserCustomExtensionTooltipHTML) { +], function($, _, utils, settings, eventMgr, mousetrap, settingsTemplateTooltipHTML, settingsUserCustomExtensionTooltipHTML) { var core = {}; // Used for periodic tasks var intervalId = undefined; var periodicCallbacks = [ - extensionMgr.onPeriodicRun + eventMgr.onPeriodicRun ]; core.runPeriodically = function(callback) { periodicCallbacks.push(callback); @@ -74,13 +74,13 @@ define([ offlineTime = utils.currentTime; if(core.isOffline === false) { core.isOffline = true; - extensionMgr.onOfflineChanged(true); + eventMgr.onOfflineChanged(true); } }; function setOnline() { if(core.isOffline === true) { core.isOffline = false; - extensionMgr.onOfflineChanged(false); + eventMgr.onOfflineChanged(false); } } function checkOnline() { @@ -121,7 +121,7 @@ define([ utils.setInputValue("#input-settings-ssh-proxy", settings.sshProxy); // Load extension settings - extensionMgr.onLoadSettings(); + eventMgr.onLoadSettings(); } // Save settings from settings dialog @@ -149,7 +149,7 @@ define([ // Save extension settings newSettings.extensionSettings = {}; - extensionMgr.onSaveSettings(newSettings.extensionSettings, event); + eventMgr.onSaveSettings(newSettings.extensionSettings, event); if(!event.isPropagationStopped()) { $.extend(settings, newSettings); @@ -178,7 +178,7 @@ define([ center__minWidth: 200, center__minHeight: 200 }; - extensionMgr.onLayoutConfigure(layoutGlobalConfig); + eventMgr.onLayoutConfigure(layoutGlobalConfig); if(settings.layoutOrientation == "horizontal") { $(".ui-layout-south").remove(); $(".preview-container").html('
'); @@ -204,7 +204,7 @@ define([ $(".ui-layout-toggler-south").addClass("btn").append($("").addClass("caret")); $(".ui-layout-toggler-east").addClass("btn").append($("").addClass("caret")); - extensionMgr.onLayoutCreated(layout); + eventMgr.onLayoutCreated(layout); } ; @@ -214,7 +214,7 @@ define([ var documentContent = undefined; core.initEditor = function(fileDescParam) { if(fileDesc !== undefined) { - extensionMgr.onFileClosed(fileDesc); + eventMgr.onFileClosed(fileDesc); } fileDesc = fileDescParam; documentContent = undefined; @@ -224,7 +224,7 @@ define([ if(editor !== undefined) { // If the editor is already created editor.undoManager.reinit(initDocumentContent, fileDesc.editorStart, fileDesc.editorEnd, fileDesc.editorScrollTop); - extensionMgr.onFileOpen(fileDesc); + eventMgr.onFileOpen(fileDesc); editor.refreshPreview(); return; } @@ -268,7 +268,7 @@ define([ }); // Last section sectionList.push(tmpText.substring(offset, text.length)); - extensionMgr.onSectionsCreated(sectionList); + eventMgr.onSectionsCreated(sectionList); return text; }); editor = new Markdown.Editor(converter); @@ -294,7 +294,7 @@ define([ var newDocumentContent = editorElt.val(); if(documentContent !== undefined && documentContent != newDocumentContent) { fileDesc.content = newDocumentContent; - extensionMgr.onContentChanged(fileDesc); + eventMgr.onContentChanged(fileDesc); } documentContent = newDocumentContent; } @@ -318,7 +318,7 @@ define([ else { previewWrapper = function(makePreview) { return function() { - extensionMgr.previewStartTime = new Date(); + eventMgr.previewStartTime = new Date(); makePreview(); if(documentContent === undefined) { previewContainerElt.scrollTop(fileDesc.previewScrollTop); @@ -327,8 +327,8 @@ define([ }; }; } - extensionMgr.onEditorConfigure(editor); - editor.hooks.chain("onPreviewRefresh", extensionMgr.onAsyncPreview); + eventMgr.onEditorConfigure(editor); + editor.hooks.chain("onPreviewRefresh", eventMgr.onAsyncPreview); editor.run(previewWrapper); editor.undoManager.reinit(initDocumentContent, fileDesc.editorStart, fileDesc.editorEnd, fileDesc.editorScrollTop); @@ -349,7 +349,7 @@ define([ $("#wmd-undo-button").append($('')); $("#wmd-redo-button").append($('')); - extensionMgr.onFileOpen(fileDesc); + eventMgr.onFileOpen(fileDesc); }; // Used to lock the editor from the user interaction during asynchronous tasks @@ -489,7 +489,7 @@ define([ JSON.parse(content); } catch(e) { - extensionMgr.onError(importedFile.name + " is not a valid JSON file."); + eventMgr.onError(importedFile.name + " is not a valid JSON file."); return; } localStorage.settings = content; @@ -561,7 +561,7 @@ define([ } }, 1000); }); - core.onReady(extensionMgr.onReady); + core.onReady(eventMgr.onReady); // After extensions onReady callbacks core.onReady(function() { diff --git a/js/eventMgr.js b/js/eventMgr.js new file mode 100644 index 00000000..60aec637 --- /dev/null +++ b/js/eventMgr.js @@ -0,0 +1,251 @@ +define([ + "jquery", + "underscore", + "crel", + "utils", + "classes/Extension", + "settings", + "text!html/settingsExtensionsAccordion.html", + "extensions/partialRendering", + "extensions/userCustom", + "extensions/googleAnalytics", + "extensions/dialogAbout", + "extensions/dialogManagePublication", + "extensions/dialogManageSynchronization", + "extensions/dialogOpenHarddrive", + "extensions/documentSelector", + "extensions/documentTitle", + "extensions/workingIndicator", + "extensions/notifications", + "extensions/markdownExtra", + "extensions/toc", + "extensions/mathJax", + "extensions/emailConverter", + "extensions/scrollLink", + "extensions/buttonSync", + "extensions/buttonPublish", + "extensions/buttonShare", + "extensions/buttonStat", + "extensions/buttonHtmlCode", + "extensions/buttonMarkdownSyntax", + "extensions/buttonViewer", + "libs/bootstrap", + "libs/jquery.waitforimages" +], function($, _, crel, utils, Extension, settings, settingsExtensionsAccordionHTML) { + + var eventMgr = {}; + + // Create a list of extensions from module arguments + var extensionList = _.chain(arguments).map(function(argument) { + return argument instanceof Extension && argument; + }).compact().value(); + + // Configure extensions + extensionSettings = settings.extensionSettings || {}; + _.each(extensionList, function(extension) { + // Set the extension.config attribute from settings or default configuration + extension.config = _.extend({}, extension.defaultConfig, extensionSettings[extension.extensionId]); + // Skip enabling the extension if we are in the viewer and extension doesn't support it + if(viewerMode === true && extension.disableInViewer) { + return; + } + // Enable the extension if it's not optional or it has not been disabled by the user + extension.config.enabled = !extension.isOptional || extension.config.enabled === undefined || extension.config.enabled === true; + }); + + // Returns all listeners with the specified name that are implemented in the enabled extensions + function getExtensionListenerList(eventName) { + return _.chain(extensionList).map(function(extension) { + return extension.config.enabled && extension[eventName]; + }).compact().value(); + } + + // Returns a function that calls every listeners with the specified name from all enabled extensions + var eventListenerListMap = {}; + function createEventHook(eventName) { + eventListenerListMap[eventName] = getExtensionListenerList(eventName); + return function() { + logger.log(eventName, arguments); + var eventArguments = arguments; + _.each(eventListenerListMap[eventName], function(listener) { + // Use try/catch in case userCustom listener contains error + try { + listener.apply(null, eventArguments); + } + catch(e) { + console.error(e); + } + }); + }; + } + + // Add a Hook to the eventMgr that we can fire using eventMgr.eventName() + function addEventHook(eventName) { + eventMgr[eventName] = createEventHook(eventName); + } + + // Used by external modules (not extensions) to listen to events + eventMgr.addListener = function(eventName, listener) { + try { + eventListenerListMap[eventName].push(listener); + } catch(e) { + console.error('No event listener called ' + eventName); + } + }; + + // Call every onInit listeners (extensions only) + createEventHook("onInit")(); + + // Load/Save extension config from/to settings + eventMgr["onLoadSettings"] = function() { + logger.log("onLoadSettings"); + _.each(extensionList, function(extension) { + utils.setInputChecked("#input-enable-extension-" + extension.extensionId, extension.config.enabled); + var onLoadSettingsListener = extension.onLoadSettings; + onLoadSettingsListener && onLoadSettingsListener(); + }); + }; + eventMgr["onSaveSettings"] = function(newExtensionSettings, event) { + logger.log("onSaveSettings"); + _.each(extensionList, function(extension) { + var newExtensionConfig = _.extend({}, extension.defaultConfig); + newExtensionConfig.enabled = utils.getInputChecked("#input-enable-extension-" + extension.extensionId); + var onSaveSettingsListener = extension.onSaveSettings; + onSaveSettingsListener && onSaveSettingsListener(newExtensionConfig, event); + newExtensionSettings[extension.extensionId] = newExtensionConfig; + }); + }; + + addEventHook("onMessage"); + addEventHook("onError"); + addEventHook("onOfflineChanged"); + addEventHook("onAsyncRunning", true); + addEventHook("onPeriodicRun", true); + + // To access modules that are loaded after extensions + addEventHook("onFileMgrCreated"); + addEventHook("onSynchronizerCreated"); + addEventHook("onPublisherCreated"); + addEventHook("onEventMgrCreated"); + + // Operations on files + addEventHook("onFileCreated"); + addEventHook("onFileDeleted"); + addEventHook("onFileSelected"); + addEventHook("onFileOpen"); + addEventHook("onFileClosed"); + addEventHook("onContentChanged"); + addEventHook("onTitleChanged"); + + // Sync events + addEventHook("onSyncRunning"); + addEventHook("onSyncSuccess"); + addEventHook("onSyncImportSuccess"); + addEventHook("onSyncExportSuccess"); + addEventHook("onSyncRemoved"); + + // Publish events + addEventHook("onPublishRunning"); + addEventHook("onPublishSuccess"); + addEventHook("onNewPublishSuccess"); + addEventHook("onPublishRemoved"); + + // Operations on Layout + addEventHook("onLayoutConfigure"); + addEventHook("onLayoutCreated"); + + // Operations on PageDown + addEventHook("onEditorConfigure"); + addEventHook("onSectionsCreated"); + + var onPreviewFinished = createEventHook("onPreviewFinished"); + var onAsyncPreviewListenerList = getExtensionListenerList("onAsyncPreview"); + // The number of times we expect tryFinished to be called + var nbAsyncPreviewListener = onAsyncPreviewListenerList.length + 1; + var previewContentsElt = undefined; + var previewContentsJQElt = undefined; + eventMgr["onAsyncPreview"] = function() { + logger.log("onAsyncPreview"); + logger.log("Conversion time: " + (new Date() - eventMgr.previewStartTime)); + // Call onPreviewFinished listeners when all async preview are finished + var counter = 0; + function tryFinished() { + if(++counter === nbAsyncPreviewListener) { + logger.log("Preview time: " + (new Date() - eventMgr.previewStartTime)); + _.defer(function() { + var html = ""; + _.each(previewContentsElt.children, function(elt) { + html += elt.innerHTML; + }); + onPreviewFinished(utils.trim(html)); + }); + } + } + // We assume images are loading in the preview + previewContentsJQElt.waitForImages(tryFinished); + _.each(onAsyncPreviewListenerList, function(asyncPreviewListener) { + asyncPreviewListener(tryFinished); + }); + }; + + var onReady = createEventHook("onReady"); + eventMgr["onReady"] = function() { + previewContentsElt = document.getElementById('preview-contents'); + previewContentsJQElt = $(previewContentsElt); + + if(viewerMode === false) { + // Create accordion in settings dialog + var accordionHtml = _.chain(extensionList).sortBy(function(extension) { + return extension.extensionName.toLowerCase(); + }).reduce(function(html, extension) { + return html + _.template(settingsExtensionsAccordionHTML, { + extensionId: extension.extensionId, + extensionName: extension.extensionName, + isOptional: extension.isOptional, + settingsBlock: extension.settingsBlock + }); + }, "").value(); + document.getElementById('accordion-extensions').innerHTML = accordionHtml; + + // Create a button from an extension listener + function createBtn(listener) { + var buttonGrpElt = crel('div', { + class: 'btn-group' + }); + var btnElt = listener(); + if(_.isString(btnElt)) { + buttonGrpElt.innerHTML = btnElt; + } + else if(_.isElement(btnElt)) { + buttonGrpElt.appendChild(btnElt); + } + return buttonGrpElt; + } + + // Create extension buttons + logger.log("onCreateButton"); + var onCreateButtonListenerList = getExtensionListenerList("onCreateButton"); + var extensionButtonsFragment = document.createDocumentFragment(); + _.each(onCreateButtonListenerList, function(listener) { + extensionButtonsFragment.appendChild(createBtn(listener)); + }); + document.getElementById('extension-buttons').appendChild(extensionButtonsFragment); + + // Create extension preview buttons + logger.log("onCreatePreviewButton"); + var onCreatePreviewButtonListenerList = getExtensionListenerList("onCreatePreviewButton"); + var extensionPreviewButtonsFragment = document.createDocumentFragment(); + _.each(onCreatePreviewButtonListenerList, function(listener) { + extensionPreviewButtonsFragment.appendChild(createBtn(listener)); + }); + document.getElementById('extension-preview-buttons').appendChild(extensionPreviewButtonsFragment); + } + + // Call onReady listeners + onReady(); + }; + + // For extensions that need to call other extensions + eventMgr.onEventMgrCreated(eventMgr); + return eventMgr; +}); \ No newline at end of file diff --git a/js/extensionMgr.js b/js/extensionMgr.js deleted file mode 100644 index bb0ac506..00000000 --- a/js/extensionMgr.js +++ /dev/null @@ -1,225 +0,0 @@ -define([ - "jquery", - "underscore", - "utils", - "classes/Extension", - "settings", - "text!html/settingsExtensionsAccordion.html", - "extensions/partialRendering", - "extensions/userCustom", - "extensions/googleAnalytics", - "extensions/dialogAbout", - "extensions/dialogManagePublication", - "extensions/dialogManageSynchronization", - "extensions/dialogOpenHarddrive", - "extensions/documentSelector", - "extensions/documentTitle", - "extensions/workingIndicator", - "extensions/notifications", - "extensions/markdownExtra", - "extensions/toc", - "extensions/mathJax", - "extensions/emailConverter", - "extensions/scrollLink", - "extensions/buttonSync", - "extensions/buttonPublish", - "extensions/buttonShare", - "extensions/buttonStat", - "extensions/buttonHtmlCode", - "extensions/buttonMarkdownSyntax", - "extensions/buttonViewer", - "libs/bootstrap", - "libs/jquery.waitforimages" -], function($, _, utils, Extension, settings, settingsExtensionsAccordionHTML) { - - var extensionMgr = {}; - - // Create a list of extensions - var extensionList = _.chain(arguments).map(function(argument) { - return argument instanceof Extension && argument; - }).compact().value(); - - // Returns all callbacks with the specified name that are implemented in extensions - function getExtensionCallbackList(hookName) { - return _.chain(extensionList).map(function(extension) { - return extension.config.enabled && extension[hookName]; - }).compact().value(); - } - - // Return a function that calls every callbacks with the specified name from all extensions - var hookCallbackList = {}; - function createHook(hookName, noLog) { - hookCallbackList[hookName] = getExtensionCallbackList(hookName); - return function() { - if(!noLog) { - logger.log(hookName, arguments); - } - var callbackArguments = arguments; - _.each(hookCallbackList[hookName], function(callback) { - // In case user custom callback contains error - try { - callback.apply(null, callbackArguments); - } - catch(e) { - console.error(e); - } - }); - }; - } - - // Add a Hook to the extensionMgr - function addHook(hookName, noLog) { - extensionMgr[hookName] = createHook(hookName, noLog); - } - - // Used by external modules to listen to extension events - extensionMgr.addHookCallback = function(hookName, callback) { - hookCallbackList[hookName].push(callback); - }; - - // Set extension config - extensionSettings = settings.extensionSettings || {}; - _.each(extensionList, function(extension) { - extension.config = _.extend({}, extension.defaultConfig, extensionSettings[extension.extensionId]); - extension.config.enabled = !extension.isOptional || extension.config.enabled === undefined || extension.config.enabled === true; - if(viewerMode === true && extension.disableInViewer) { - extension.config.enabled = false; - } - }); - - // Call every onInit callbacks - createHook("onInit")(); - - // Load/Save extension config from/to settings - extensionMgr["onLoadSettings"] = function() { - logger.log("onLoadSettings"); - _.each(extensionList, function(extension) { - utils.setInputChecked("#input-enable-extension-" + extension.extensionId, extension.config.enabled); - var onLoadSettingsCallback = extension.onLoadSettings; - onLoadSettingsCallback && onLoadSettingsCallback(); - }); - }; - extensionMgr["onSaveSettings"] = function(newExtensionSettings, event) { - logger.log("onSaveSettings"); - _.each(extensionList, function(extension) { - var newExtensionConfig = _.extend({}, extension.defaultConfig); - newExtensionConfig.enabled = utils.getInputChecked("#input-enable-extension-" + extension.extensionId); - var onSaveSettingsCallback = extension.onSaveSettings; - onSaveSettingsCallback && onSaveSettingsCallback(newExtensionConfig, event); - newExtensionSettings[extension.extensionId] = newExtensionConfig; - }); - }; - - addHook("onMessage"); - addHook("onError"); - addHook("onOfflineChanged"); - addHook("onAsyncRunning", true); - addHook("onPeriodicRun", true); - - // To access modules that are loaded after extensions - addHook("onFileMgrCreated"); - addHook("onSynchronizerCreated"); - addHook("onPublisherCreated"); - addHook("onExtensionMgrCreated"); - - // Operations on files - addHook("onFileCreated"); - addHook("onFileDeleted"); - addHook("onFileSelected"); - addHook("onFileOpen"); - addHook("onFileClosed"); - addHook("onContentChanged"); - addHook("onTitleChanged"); - - // Sync events - addHook("onSyncRunning"); - addHook("onSyncSuccess"); - addHook("onSyncImportSuccess"); - addHook("onSyncExportSuccess"); - addHook("onSyncRemoved"); - - // Publish events - addHook("onPublishRunning"); - addHook("onPublishSuccess"); - addHook("onNewPublishSuccess"); - addHook("onPublishRemoved"); - - // Operations on Layout - addHook("onLayoutConfigure"); - addHook("onLayoutCreated"); - - // Operations on PageDown - addHook("onEditorConfigure"); - addHook("onSectionsCreated"); - - var onPreviewFinished = createHook("onPreviewFinished"); - var onAsyncPreviewCallbackList = getExtensionCallbackList("onAsyncPreview"); - // The number of times we expect tryFinished to be called - var nbAsyncPreviewCallback = onAsyncPreviewCallbackList.length + 1; - var previewContentsElt = undefined; - var previewContentsJQElt = undefined; - extensionMgr["onAsyncPreview"] = function() { - logger.log("onAsyncPreview"); - logger.log("Conversion time: " + (new Date() - extensionMgr.previewStartTime)); - // Call onPreviewFinished callbacks when all async preview are finished - var counter = 0; - function tryFinished() { - if(++counter === nbAsyncPreviewCallback) { - logger.log("Preview time: " + (new Date() - extensionMgr.previewStartTime)); - _.defer(function() { - var html = ""; - _.each(previewContentsElt.children, function(elt) { - html += elt.innerHTML; - }); - onPreviewFinished(utils.trim(html)); - }); - } - } - // We assume images are loading in the preview - previewContentsJQElt.waitForImages(tryFinished); - _.each(onAsyncPreviewCallbackList, function(asyncPreviewCallback) { - asyncPreviewCallback(tryFinished); - }); - }; - - function createSettings(extension) { - $("#accordion-extensions").append($(_.template(settingsExtensionsAccordionHTML, { - extensionId: extension.extensionId, - extensionName: extension.extensionName, - isOptional: extension.isOptional, - settingsBlock: extension.settingsBlock - }))); - } - - extensionMgr["onReady"] = function() { - previewContentsElt = document.getElementById('preview-contents'); - previewContentsJQElt = $(previewContentsElt); - - // Create accordion in settings dialog - _.chain(extensionList).sortBy(function(extension) { - return extension.extensionName.toLowerCase(); - }).each(createSettings); - - // Create extension buttons - logger.log("onCreateButton"); - var onCreateButtonCallbackList = getExtensionCallbackList("onCreateButton"); - _.each(onCreateButtonCallbackList, function(callback) { - $("#extension-buttons").append($('
').append(callback())); - }); - - // Create extension preview buttons - logger.log("onCreatePreviewButton"); - var onCreatePreviewButtonCallbackList = getExtensionCallbackList("onCreatePreviewButton"); - _.each(onCreatePreviewButtonCallbackList, function(callback) { - $("#extension-preview-buttons").append($('
').append(callback())); - }); - - // Call extensions onReady callbacks - var onReady = createHook("onReady"); - onReady(); - }; - - // For extensions that need to call other extensions - extensionMgr.onExtensionMgrCreated(extensionMgr); - return extensionMgr; -}); \ No newline at end of file diff --git a/js/extensions/buttonHtmlCode.js b/js/extensions/buttonHtmlCode.js index 3119065a..8836496c 100644 --- a/js/extensions/buttonHtmlCode.js +++ b/js/extensions/buttonHtmlCode.js @@ -21,13 +21,13 @@ define([ newConfig.template = utils.getInputValue("#textarea-html-code-template"); }; - var extensionMgr = undefined; - buttonHtmlCode.onExtensionMgrCreated = function(extensionMgrParameter) { - extensionMgr = extensionMgrParameter; + var eventMgr = undefined; + buttonHtmlCode.onEventMgrCreated = function(eventMgrParameter) { + eventMgr = eventMgrParameter; }; buttonHtmlCode.onCreatePreviewButton = function() { - return $(buttonHtmlCodeHTML); + return buttonHtmlCodeHTML; }; var selectedFileDesc = undefined; @@ -46,7 +46,7 @@ define([ textareaElt.value = htmlCode; } catch(e) { - extensionMgr.onError(e); + eventMgr.onError(e); return e.message; } }; diff --git a/js/extensions/buttonMarkdownSyntax.js b/js/extensions/buttonMarkdownSyntax.js index 4480f9db..38e8a563 100644 --- a/js/extensions/buttonMarkdownSyntax.js +++ b/js/extensions/buttonMarkdownSyntax.js @@ -8,7 +8,7 @@ define([ buttonMarkdownSyntax.settingsBlock = '

Adds a "Markdown syntax" button over the preview.

'; buttonMarkdownSyntax.onCreatePreviewButton = function() { - return $(buttonMarkdownSyntaxHTML); + return buttonMarkdownSyntaxHTML; }; return buttonMarkdownSyntax; diff --git a/js/extensions/buttonPublish.js b/js/extensions/buttonPublish.js index 3ed9af77..de18bce5 100644 --- a/js/extensions/buttonPublish.js +++ b/js/extensions/buttonPublish.js @@ -38,7 +38,7 @@ define([ publisher.publish(); } }); - return button; + return button[0]; }; buttonPublish.onPublishRunning = function(isRunning) { diff --git a/js/extensions/buttonShare.js b/js/extensions/buttonShare.js index a1b1f210..dbb831b1 100644 --- a/js/extensions/buttonShare.js +++ b/js/extensions/buttonShare.js @@ -10,7 +10,7 @@ define([ buttonShare.settingsBlock = '

Adds a "Share document" button in the navigation bar.

'; buttonShare.onCreateButton = function() { - return $(buttonShareHTML); + return buttonShareHTML; }; var fileDesc = undefined; diff --git a/js/extensions/buttonStat.js b/js/extensions/buttonStat.js index 296eb84d..bb284d37 100644 --- a/js/extensions/buttonStat.js +++ b/js/extensions/buttonStat.js @@ -41,7 +41,7 @@ define([ }; buttonStat.onCreatePreviewButton = function() { - return $(_.template(buttonStatHTML, buttonStat.config)); + return _.template(buttonStatHTML, buttonStat.config); }; var previewContentsElt = undefined; diff --git a/js/extensions/buttonSync.js b/js/extensions/buttonSync.js index db642e80..3ed12bc6 100644 --- a/js/extensions/buttonSync.js +++ b/js/extensions/buttonSync.js @@ -59,7 +59,7 @@ define([ synchronizer.sync(); } }); - return button; + return button[0]; }; buttonSync.onReady = updateButtonState; diff --git a/js/extensions/buttonViewer.js b/js/extensions/buttonViewer.js index db3be4c6..e824b874 100644 --- a/js/extensions/buttonViewer.js +++ b/js/extensions/buttonViewer.js @@ -8,7 +8,7 @@ define([ buttonViewer.settingsBlock = '

Adds a "Viewer" button over the preview.

'; buttonViewer.onCreatePreviewButton = function() { - return $(buttonViewerHTML); + return buttonViewerHTML; }; return buttonViewer; diff --git a/js/extensions/dialogManagePublication.js b/js/extensions/dialogManagePublication.js index 44aea9a7..0327f1b6 100644 --- a/js/extensions/dialogManagePublication.js +++ b/js/extensions/dialogManagePublication.js @@ -8,9 +8,9 @@ define([ var dialogManagePublication = new Extension("dialogManagePublication", 'Dialog "Manage publication"'); dialogManagePublication.settingsBlock = '

Populates the "Manage publication" dialog box.

'; - var extensionMgr = undefined; - dialogManagePublication.onExtensionMgrCreated = function(extensionMgrParameter) { - extensionMgr = extensionMgrParameter; + var eventMgr = undefined; + dialogManagePublication.onEventMgrCreated = function(eventMgrParameter) { + eventMgr = eventMgrParameter; }; var fileDesc = undefined; @@ -41,7 +41,7 @@ define([ })); lineElement.append($(removeButtonTemplate).click(function() { fileDesc.removePublishLocation(publishAttributes); - extensionMgr.onPublishRemoved(fileDesc, publishAttributes); + eventMgr.onPublishRemoved(fileDesc, publishAttributes); })); publishList.append(lineElement); }); diff --git a/js/extensions/dialogManageSynchronization.js b/js/extensions/dialogManageSynchronization.js index ff31a9a0..faf338d1 100644 --- a/js/extensions/dialogManageSynchronization.js +++ b/js/extensions/dialogManageSynchronization.js @@ -8,9 +8,9 @@ define([ var dialogManageSynchronization = new Extension("dialogManageSynchronization", 'Dialog "Manage synchronization"'); dialogManageSynchronization.settingsBlock = '

Populates the "Manage synchronization" dialog box.

'; - var extensionMgr = undefined; - dialogManageSynchronization.onExtensionMgrCreated = function(extensionMgrParameter) { - extensionMgr = extensionMgrParameter; + var eventMgr = undefined; + dialogManageSynchronization.onEventMgrCreated = function(eventMgrParameter) { + eventMgr = eventMgrParameter; }; var synchronizer = undefined; @@ -44,7 +44,7 @@ define([ lineElement.append($(removeButtonTemplate).click(function() { synchronizer.tryStopRealtimeSync(); fileDesc.removeSyncLocation(syncAttributes); - extensionMgr.onSyncRemoved(fileDesc, syncAttributes); + eventMgr.onSyncRemoved(fileDesc, syncAttributes); })); syncList.append(lineElement); }); diff --git a/js/extensions/dialogOpenHarddrive.js b/js/extensions/dialogOpenHarddrive.js index 065dbabc..c41fc6b8 100644 --- a/js/extensions/dialogOpenHarddrive.js +++ b/js/extensions/dialogOpenHarddrive.js @@ -15,9 +15,9 @@ define([ fileMgr = fileMgrParameter; }; - var extensionMgr = undefined; - dialogOpenHarddrive.onExtensionMgrCreated = function(extensionMgrParameter) { - extensionMgr = extensionMgrParameter; + var eventMgr = undefined; + dialogOpenHarddrive.onEventMgrCreated = function(eventMgrParameter) { + eventMgr = eventMgrParameter; }; var contentWrapper = undefined; @@ -39,12 +39,12 @@ define([ return function(e) { var content = e.target.result; if(content.match(/\uFFFD/)) { - extensionMgr.onError(importedFile.name + " is a binary file."); + eventMgr.onError(importedFile.name + " is a binary file."); return; } content = contentWrapper ? contentWrapper(content) : content; if(content === undefined) { - extensionMgr.onError(importedFile.name + " is not a valid HTML file."); + eventMgr.onError(importedFile.name + " is not a valid HTML file."); return; } var title = importedFile.name; @@ -96,7 +96,7 @@ define([ } content = converter.makeMd(content); if(content === undefined) { - extensionMgr.onError("Invalid HTML code."); + eventMgr.onError("Invalid HTML code."); return; } var fileDesc = fileMgr.createFile(undefined, content); diff --git a/js/extensions/toc.js b/js/extensions/toc.js index bbd0ede4..b5885bf6 100644 --- a/js/extensions/toc.js +++ b/js/extensions/toc.js @@ -26,7 +26,7 @@ define([ toc.onCreatePreviewButton = function() { if(toc.config.button) { - return $(buttonTocHTML); + return buttonTocHTML; } }; diff --git a/js/extensions/userCustom.js b/js/extensions/userCustom.js index 8370f54a..e6f8d82e 100644 --- a/js/extensions/userCustom.js +++ b/js/extensions/userCustom.js @@ -29,9 +29,9 @@ define([ publisher = publisherParameter; }; - var extensionMgr = undefined; - userCustom.onExtensionMgrCreated = function(extensionMgrParameter) { - extensionMgr = extensionMgrParameter; + var eventMgr = undefined; + userCustom.onEventMgrCreated = function(eventMgrParameter) { + eventMgr = eventMgrParameter; }; userCustom.onLoadSettings = function() { @@ -44,7 +44,7 @@ define([ eval(newConfig.code); } catch(e) { - extensionMgr.onError(e); + eventMgr.onError(e); // Mark the textarea as error utils.getInputTextValue("#textarea-usercustom-code", event, /^$/); } diff --git a/js/fileMgr.js b/js/fileMgr.js index c9d924e8..52a0c6f1 100644 --- a/js/fileMgr.js +++ b/js/fileMgr.js @@ -4,11 +4,11 @@ define([ "core", "utils", "settings", - "extensionMgr", + "eventMgr", "fileSystem", "classes/FileDescriptor", "text!../WELCOME.md" -], function($, _, core, utils, settings, extensionMgr, fileSystem, FileDescriptor, welcomeContent) { +], function($, _, core, utils, settings, eventMgr, fileSystem, FileDescriptor, welcomeContent) { var fileMgr = {}; @@ -38,7 +38,7 @@ define([ fileDesc.selectTime = new Date().getTime(); // Notify extensions - extensionMgr.onFileSelected(fileDesc); + eventMgr.onFileSelected(fileDesc); // Hide the viewer pencil button if(fileDesc.fileIndex == TEMPORARY_FILE_INDEX) { @@ -93,7 +93,7 @@ define([ if(!isTemporary) { utils.appendIndexToArray("file.list", fileIndex); fileSystem[fileIndex] = fileDesc; - extensionMgr.onFileCreated(fileDesc); + eventMgr.onFileCreated(fileDesc); } return fileDesc; }; @@ -127,7 +127,7 @@ define([ localStorage.removeItem(fileDesc.fileIndex + ".sync"); localStorage.removeItem(fileDesc.fileIndex + ".publish"); - extensionMgr.onFileDeleted(fileDesc); + eventMgr.onFileDeleted(fileDesc); }; // Get the file descriptor associated to a syncIndex @@ -143,15 +143,6 @@ define([ return fileDesc && fileDesc.syncLocations[syncIndex]; }; - // Returns true if provider has locations to synchronize - fileMgr.hasSync = function(provider) { - return _.some(fileSystem, function(fileDesc) { - return _.some(fileDesc.syncLocations, function(syncAttributes) { - return syncAttributes.provider === provider; - }); - }); - }; - // Get the file descriptor associated to a publishIndex fileMgr.getFileFromPublishIndex = function(publishIndex) { return _.find(fileSystem, function(fileDesc) { @@ -192,7 +183,7 @@ define([ var fileDesc = fileMgr.currentFile; if(title && title != fileDesc.title) { fileDesc.title = title; - extensionMgr.onTitleChanged(fileDesc); + eventMgr.onTitleChanged(fileDesc); } input.val(fileDesc.title); $("#wmd-input").focus(); @@ -224,6 +215,6 @@ define([ }); }); - extensionMgr.onFileMgrCreated(fileMgr); + eventMgr.onFileMgrCreated(fileMgr); return fileMgr; }); diff --git a/js/helpers/dropboxHelper.js b/js/helpers/dropboxHelper.js index 30a2e97c..0b59cc05 100644 --- a/js/helpers/dropboxHelper.js +++ b/js/helpers/dropboxHelper.js @@ -2,9 +2,9 @@ define([ "jquery", "underscore", "core", - "extensionMgr", + "eventMgr", "classes/AsyncTask" -], function($, _, core, extensionMgr, AsyncTask) { +], function($, _, core, eventMgr, AsyncTask) { var client = undefined; var authenticated = false; @@ -57,7 +57,7 @@ define([ var immediate = true; function localAuthenticate() { if(immediate === false) { - extensionMgr.onMessage("Please make sure the Dropbox authorization popup is not blocked by your browser."); + eventMgr.onMessage("Please make sure the Dropbox authorization popup is not blocked by your browser."); // If not immediate we add time for user to enter his // credentials task.timeout = ASYNC_TASK_LONG_TIMEOUT; @@ -320,7 +320,7 @@ define([ task.chain(); }; Dropbox.choose(options); - extensionMgr.onMessage("Please make sure the Dropbox chooser popup is not blocked by your browser."); + eventMgr.onMessage("Please make sure the Dropbox chooser popup is not blocked by your browser."); }); task.onSuccess(function() { callback(undefined, paths); diff --git a/js/helpers/githubHelper.js b/js/helpers/githubHelper.js index 4fb96b24..f44b6bea 100644 --- a/js/helpers/githubHelper.js +++ b/js/helpers/githubHelper.js @@ -2,9 +2,9 @@ define([ "jquery", "core", "utils", - "extensionMgr", + "eventMgr", "classes/AsyncTask" -], function($, core, utils, extensionMgr, AsyncTask) { +], function($, core, utils, eventMgr, AsyncTask) { var connected = undefined; var github = undefined; @@ -58,7 +58,7 @@ define([ task.chain(); return; } - extensionMgr.onMessage("Please make sure the Github authorization popup is not blocked by your browser."); + eventMgr.onMessage("Please make sure the Github authorization popup is not blocked by your browser."); var errorMsg = "Failed to retrieve a token from GitHub."; // We add time for user to enter his credentials task.timeout = ASYNC_TASK_LONG_TIMEOUT; diff --git a/js/helpers/googleHelper.js b/js/helpers/googleHelper.js index 7febb083..b0421ffb 100644 --- a/js/helpers/googleHelper.js +++ b/js/helpers/googleHelper.js @@ -2,9 +2,9 @@ define([ "jquery", "core", "utils", - "extensionMgr", + "eventMgr", "classes/AsyncTask" -], function($, core, utils, extensionMgr, AsyncTask) { +], function($, core, utils, eventMgr, AsyncTask) { var connected = false; var authenticated = false; @@ -53,7 +53,7 @@ define([ var immediate = true; function localAuthenticate() { if(immediate === false) { - extensionMgr.onMessage("Please make sure the Google authorization popup is not blocked by your browser."); + eventMgr.onMessage("Please make sure the Google authorization popup is not blocked by your browser."); // If not immediate we add time for user to enter his // credentials task.timeout = ASYNC_TASK_LONG_TIMEOUT; diff --git a/js/helpers/tumblrHelper.js b/js/helpers/tumblrHelper.js index de6dd1a6..9b8b62d5 100644 --- a/js/helpers/tumblrHelper.js +++ b/js/helpers/tumblrHelper.js @@ -2,9 +2,9 @@ define([ "jquery", "core", "utils", - "extensionMgr", + "eventMgr", "classes/AsyncTask" -], function($, core, utils, extensionMgr, AsyncTask) { +], function($, core, utils, eventMgr, AsyncTask) { var oauthParams = undefined; @@ -36,7 +36,7 @@ define([ task.chain(); return; } - extensionMgr.onMessage("Please make sure the Tumblr authorization popup is not blocked by your browser."); + eventMgr.onMessage("Please make sure the Tumblr authorization popup is not blocked by your browser."); var errorMsg = "Failed to retrieve a token from Tumblr."; // We add time for user to enter his credentials task.timeout = ASYNC_TASK_LONG_TIMEOUT; diff --git a/js/helpers/wordpressHelper.js b/js/helpers/wordpressHelper.js index b3eef5cb..4c2fbb9b 100644 --- a/js/helpers/wordpressHelper.js +++ b/js/helpers/wordpressHelper.js @@ -2,9 +2,9 @@ define([ "jquery", "core", "utils", - "extensionMgr", + "eventMgr", "classes/AsyncTask" -], function($, core, utils, extensionMgr, AsyncTask) { +], function($, core, utils, eventMgr, AsyncTask) { var token = undefined; @@ -31,7 +31,7 @@ define([ task.chain(); return; } - extensionMgr.onMessage("Please make sure the Wordpress authorization popup is not blocked by your browser."); + eventMgr.onMessage("Please make sure the Wordpress authorization popup is not blocked by your browser."); var errorMsg = "Failed to retrieve a token from Wordpress."; // We add time for user to enter his credentials task.timeout = ASYNC_TASK_LONG_TIMEOUT; diff --git a/js/html/settingsUserCustomExtensionTooltip.html b/js/html/settingsUserCustomExtensionTooltip.html index 2dfd1833..3339c34c 100644 --- a/js/html/settingsUserCustomExtensionTooltip.html +++ b/js/html/settingsUserCustomExtensionTooltip.html @@ -6,7 +6,7 @@ Extension variable name:
userCustom.onPreviewFinished = function() {
-  extensionMgr.onMessage("Finished!"); +  eventMgr.onMessage("Finished!");
};
diff --git a/js/main-min.js b/js/main-min.js index 83516f28..aad9e925 100644 --- a/js/main-min.js +++ b/js/main-min.js @@ -4861,9 +4861,9 @@ define("config", function() {}), define("settings", [ "underscore", "config" ], userCustom.onPublisherCreated = function(e) { publisher = e; }; - var extensionMgr = void 0; - return userCustom.onExtensionMgrCreated = function(e) { - extensionMgr = e; + var eventMgr = void 0; + return userCustom.oneventMgrCreated = function(e) { + eventMgr = e; }, userCustom.onLoadSettings = function() { utils.setInputValue("#textarea-usercustom-code", userCustom.config.code); }, userCustom.onSaveSettings = function(newConfig, event) { @@ -4871,7 +4871,7 @@ define("config", function() {}), define("settings", [ "underscore", "config" ], try { eval(newConfig.code); } catch (e) { - extensionMgr.onError(e), utils.getInputTextValue("#textarea-usercustom-code", event, /^$/); + eventMgr.onError(e), utils.getInputTextValue("#textarea-usercustom-code", event, /^$/); } }, userCustom.onInit = function() { try { @@ -4987,7 +4987,7 @@ define("config", function() {}), define("settings", [ "underscore", "config" ], var o = new n("dialogManagePublication", 'Dialog "Manage publication"'); o.settingsBlock = '

Populates the "Manage publication" dialog box.

'; var r = void 0; - o.onExtensionMgrCreated = function(e) { + o.oneventMgrCreated = function(e) { r = e; }; var s = void 0, a = '', l = function(n) { @@ -5017,7 +5017,7 @@ define("config", function() {}), define("settings", [ "underscore", "config" ], var o = new n("dialogManageSynchronization", 'Dialog "Manage synchronization"'); o.settingsBlock = '

Populates the "Manage synchronization" dialog box.

'; var r = void 0; - o.onExtensionMgrCreated = function(e) { + o.oneventMgrCreated = function(e) { r = e; }; var s = void 0; @@ -5218,7 +5218,7 @@ define("config", function() {}), define("settings", [ "underscore", "config" ], u = e; }; var d = void 0; - c.onExtensionMgrCreated = function(e) { + c.oneventMgrCreated = function(e) { d = e; }; var p = void 0, f = void 0, h = function(e) { @@ -8414,7 +8414,7 @@ function(e) { e.template = n.getInputValue("#textarea-html-code-template"); }; var a = void 0; - s.onExtensionMgrCreated = function(e) { + s.oneventMgrCreated = function(e) { a = e; }, s.onCreatePreviewButton = function() { return e(o); @@ -9324,7 +9324,7 @@ function(e) { }); }); }; -}(jQuery), define("libs/jquery.waitforimages", function() {}), define("extensionMgr", [ "jquery", "underscore", "utils", "classes/Extension", "settings", "text!html/settingsExtensionsAccordion.html", "extensions/partialRendering", "extensions/userCustom", "extensions/googleAnalytics", "extensions/dialogAbout", "extensions/dialogManagePublication", "extensions/dialogManageSynchronization", "extensions/dialogOpenHarddrive", "extensions/documentSelector", "extensions/documentTitle", "extensions/workingIndicator", "extensions/notifications", "extensions/markdownExtra", "extensions/toc", "extensions/mathJax", "extensions/emailConverter", "extensions/scrollLink", "extensions/buttonSync", "extensions/buttonPublish", "extensions/buttonShare", "extensions/buttonStat", "extensions/buttonHtmlCode", "extensions/buttonMarkdownSyntax", "extensions/buttonViewer", "libs/bootstrap", "libs/jquery.waitforimages" ], function(e, t, n, i, o, r) { +}(jQuery), define("libs/jquery.waitforimages", function() {}), define("eventMgr", [ "jquery", "underscore", "utils", "classes/Extension", "settings", "text!html/settingsExtensionsAccordion.html", "extensions/partialRendering", "extensions/userCustom", "extensions/googleAnalytics", "extensions/dialogAbout", "extensions/dialogManagePublication", "extensions/dialogManageSynchronization", "extensions/dialogOpenHarddrive", "extensions/documentSelector", "extensions/documentTitle", "extensions/workingIndicator", "extensions/notifications", "extensions/markdownExtra", "extensions/toc", "extensions/mathJax", "extensions/emailConverter", "extensions/scrollLink", "extensions/buttonSync", "extensions/buttonPublish", "extensions/buttonShare", "extensions/buttonStat", "extensions/buttonHtmlCode", "extensions/buttonMarkdownSyntax", "extensions/buttonViewer", "libs/bootstrap", "libs/jquery.waitforimages" ], function(e, t, n, i, o, r) { function s(e) { return t.chain(d).map(function(t) { return t.config.enabled && t[e]; @@ -9377,7 +9377,7 @@ function(e) { }); }, l("onMessage"), l("onError"), l("onOfflineChanged"), l("onAsyncRunning", !0), l("onPeriodicRun", !0), l("onFileMgrCreated"), l("onSynchronizerCreated"), l("onPublisherCreated"), - l("onExtensionMgrCreated"), l("onFileCreated"), l("onFileDeleted"), l("onFileSelected"), + l("oneventMgrCreated"), l("onFileCreated"), l("onFileDeleted"), l("onFileSelected"), l("onFileOpen"), l("onFileClosed"), l("onContentChanged"), l("onTitleChanged"), l("onSyncRunning"), l("onSyncSuccess"), l("onSyncImportSuccess"), l("onSyncExportSuccess"), l("onSyncRemoved"), l("onPublishRunning"), l("onPublishSuccess"), l("onNewPublishSuccess"), @@ -9413,11 +9413,11 @@ function(e) { }); var o = a("onReady"); o(); - }, u.onExtensionMgrCreated(u), u; + }, u.oneventMgrCreated(u), u; }), define("text!html/settingsTemplateTooltip.html", [], function() { return 'Available variables:\n
\n
    \n
  • documentTitle: document title
  • \n
  • documentMarkdown: document in Markdown format
  • \n
  • documentHTML: document in HTML format
  • \n
  • publishAttributes: attributes of the publish location\n (undefined if not publishing)
  • \n
\nExamples:\n
\n<title><%= documentTitle %></title>\n
\n<div><%- documentHTML %></div>\n
\n<%
\nif(publishAttributes.provider.providerId == "github")\nprint(documentMarkdown);
\n%>\n
\n
\nMore\n info'; }), define("text!html/settingsUserCustomExtensionTooltip.html", [], function() { - return 'Extension variable name:\nuserCustom\n
\n
\nExample:\n
\nuserCustom.onPreviewFinished = function() {\n
\n  extensionMgr.onMessage("Finished!");\n
\n};\n
\n
\nMore\n info'; + return 'Extension variable name:\nuserCustom\n
\n
\nExample:\n
\nuserCustom.onPreviewFinished = function() {\n
\n  eventMgr.onMessage("Finished!");\n
\n};\n
\n
\nMore\n info'; }), function(e, t) { function n(t, n) { var o, r, s, a = t.nodeName.toLowerCase(); @@ -13641,7 +13641,7 @@ function(e) { }, y.doHorizontalRule = function(e) { e.startTag = "----------\n", e.selection = "", e.skipLines(2, 1, !0); }; -}(), define("libs/Markdown.Editor", function() {}), define("core", [ "jquery", "underscore", "utils", "settings", "extensionMgr", "mousetrap", "text!html/settingsTemplateTooltip.html", "text!html/settingsUserCustomExtensionTooltip.html", "storage", "config", "libs/bootstrap", "libs/layout", "libs/Markdown.Editor" ], function(e, t, n, i, o, r, s, a) { +}(), define("libs/Markdown.Editor", function() {}), define("core", [ "jquery", "underscore", "utils", "settings", "eventMgr", "mousetrap", "text!html/settingsTemplateTooltip.html", "text!html/settingsUserCustomExtensionTooltip.html", "storage", "config", "libs/bootstrap", "libs/layout", "libs/Markdown.Editor" ], function(e, t, n, i, o, r, s, a) { function l() { v.isUserReal = !0, w = !0, k = n.currentTime; } @@ -13921,7 +13921,7 @@ function(e) { }), v; }), define("text!../WELCOME.md", [], function() { return '\nWelcome to StackEdit! {#welcome}\n=====================\n\n\nHello, I am your first Markdown document within **StackEdit**[^stackedit]. Don\'t delete me, I can be helpful. I can be recovered anyway in the `Utils` tab of the `Settings` dialog.\n\n----------\n\n\nDocuments\n---------\n\n**StackEdit** stores your documents in the browser local storage, which means all your documents are automatically saved locally and are accessible offline.\n\n#### Create a document\n\nYou can create a new document by clicking the button in the navigation bar. This will switch from the current document to the new one.\n\n#### Switch to another document\n\nYou can list all your local documents and switch from one to another by clicking the button in the navigation bar.\n\n#### Rename a document\n\nYou can rename the current document by clicking the document title in the navigation bar.\n\n#### Delete a document\n\nYou can delete the current document by clicking the button in the navigation bar.\n\n----------\n\n\nSynchronization\n---------------\n\n**StackEdit** can be combined with **Google Drive** and **Dropbox** to have your documents centralized in the *Cloud*. The synchronization mechanism will take care of uploading your modifications or downloading the latest version of your documents.\n\n#### Import a document\n\nYou can import a document from the *Cloud* by going to the `Google Drive` or the `Dropbox` sub-menu and by clicking `Import from...`. Once imported, your document will be automatically synchronized with the **Google Drive** / **Dropbox** file.\n\n#### Export a document\n\nYou can export any document by going to the `Google Drive` or the `Dropbox` sub-menu and by clicking `Export to...`. Even if your document is already synchronized with **Google Drive** or **Dropbox**, you can export it to a another location. **StackEdit** can synchronize one document with multiple locations.\n\n#### Synchronize a document\n\nOnce your document is linked to a **Google Drive** or a **Dropbox** file, **StackEdit** will periodically (every 3 minutes) synchronize it by downloading/uploading any modification. Any conflict will be detected, and a local copy of your document will be created as a backup if necessary.\n\nIf you just have modified your document and you want to force the synchronization, click the button in the navigation bar.\n\n> **NOTE:** The button is disabled when:\n> \n> - you are offline,\n> - or the document is not synchronized with any location,\n> - or the document has not been modified since the last synchronization.\n\n#### Manage document synchronization\n\nSince one document can be synchronized with multiple locations, you can list and manage synchronized locations by clicking `Manage synchronization` in the menu. This will open a dialog box allowing you to add or remove synchronization links that are associated to your document.\n\n> **NOTE:** If you delete the file from **Google Drive** or from **Dropbox**, the document will no longer be synchronized with that location.\n\n----------\n\n\nPublication\n-----------\n\nOnce you are happy with your document, you can publish it on different websites directly from **StackEdit**. As for now, **StackEdit** can publish on **Blogger**, **Dropbox**, **Gist**, **GitHub**, **Google Drive**, **Tumblr**, **WordPress** and on any SSH server.\n\n#### Publish a document\n\nYou can publish your document by going to the `Publish on` sub-menu and by choosing a website. In the dialog box, you can choose the publication format:\n\n- Markdown, to publish the Markdown text on a website that can interpret it (**GitHub** for instance),\n- HTML, to publish the document converted into HTML (on a blog for instance),\n- Template, to have a full control of the output.\n\n> **NOTE:** The default template is a simple webpage that wraps your document in HTML format. You can customize it in the `Publish` tab of the `Settings` dialog.\n\n#### Update a publication\n\nAfter publishing, **StackEdit** will keep your document linked to that publish location so that you can update it easily. Once you have modified your document and you want to update your publication, click on the button in the navigation bar.\n\n> **NOTE:** The button is disabled when:\n> \n> - you are offline,\n> - or the document has not been published anywhere.\n\n#### Manage document publication\n\nSince one document can be published on multiple locations, you can list and manage publish locations by clicking `Manage publication` in the menu. This will open a dialog box allowing you to remove publication links that are associated to your document.\n\n> **NOTE:** In some cases, if you remove the file from the website or the post from the blog, the document will no longer be published on that location.\n\n----------\n\n\nMarkdown Extra\n--------------\n\n**StackEdit** supports **Markdown Extra**, which extends **Markdown** syntax with some nice features.\n\n\n### Tables\n\n**Markdown Extra** has a special syntax for tables:\n\nItem | Value\n--------- | -----\nComputer | \\$1600\nPhone | \\$12\nPipe | \\$1\n\nYou can specify column alignment with one or two colons:\n\n| Item | Value | Qty |\n| :-------- | ------:| :--: |\n| Computer | \\$1600 | 5 |\n| Phone | \\$12 | 12 |\n| Pipe | \\$1 | 234 |\n\n\n### Definition Lists\n\n**Markdown Extra** has a special syntax for definition lists too:\n\nTerm 1\nTerm 2\n: Definition A\n: Definition B\n\nTerm 3\n\n: Definition C\n\n: Definition D\n\n > part of definition D\n\n\n### Fenced code blocks\n\n**GitHub**\'s fenced code blocks are also supported with **Prettify** syntax highlighting:\n\n```\n// Foo\nvar bar = 0;\n```\n\n> **NOTE:** To use **Highlight.js** instead of **Prettify**, just configure the `Markdown Extra` extension in the `Settings` dialog.\n\n\n### Special Attributes\n\nWith **Markdown Extra**, you can specify `class` and `id` attributes on headers and fenced code blocks just like this:\n\n##### Header example {#my-header}\n\n``` {#my-id .my-class}\nvar foo = bar;\n```\n\nThen you can create cross-references like this: [beginning of the document](#welcome).\n\n\n### Footnotes\n\nYou can create footnotes like this[^footnote].\n\n [^footnote]: Here is the *text* of the **footnote**.\n\n\n### Table of contents\n\nYou can insert a table of contents using the marker `[TOC]`:\n\n[TOC]\n\n\n### MathJax\n \nYou can render *LaTeX* mathematical expressions using **MathJax**, as on [math.stackexchange.com][1]:\n\nThe *Gamma function* satisfying $\\Gamma(n) = (n-1)!\\quad\\forall\nn\\in\\mathbb N$ is via through the Euler integral\n\n$$\n\\Gamma(z) = \\int_0^\\infty t^{z-1}e^{-t}dt\\,.\n$$\n\n\n> **NOTE:** You can find more information:\n>\n> - about **Markdown** syntax [here][2],\n> - about **Markdown Extra** extension [here][3],\n> - about **Prettify** syntax highlighting [here][4].\n> - about **Highlight.js** syntax highlighting [here][5].\n\n [^stackedit]: StackEdit is a free, open-source Markdown editor based on PageDown, the Markdown library used by Stack Overflow and the other Stack Exchange sites.\n\n\n [1]: http://math.stackexchange.com/\n [2]: http://daringfireball.net/projects/markdown/syntax "Markdown"\n [3]: https://github.com/jmcmanus/pagedown-extra "Pagedown Extra"\n [4]: https://code.google.com/p/google-code-prettify/\n [5]: http://softwaremaniacs.org/soft/highlight/en/'; -}), define("fileMgr", [ "jquery", "underscore", "core", "utils", "settings", "extensionMgr", "fileSystem", "classes/FileDescriptor", "text!../WELCOME.md" ], function(e, t, n, i, o, r, s, a, l) { +}), define("fileMgr", [ "jquery", "underscore", "core", "utils", "settings", "eventMgr", "fileSystem", "classes/FileDescriptor", "text!../WELCOME.md" ], function(e, t, n, i, o, r, s, a, l) { var c = {}; return c.currentFile = void 0, c.selectFile = function(i) { if (i = i || c.currentFile, void 0 === i) { @@ -14017,7 +14017,7 @@ function(e) { this.providerId = e, this.providerName = t; } return e; -}), define("classes/AsyncTask", [ "underscore", "core", "utils", "extensionMgr", "config", "libs/stacktrace" ], function(e, t, n, i) { +}), define("classes/AsyncTask", [ "underscore", "core", "utils", "eventMgr", "config", "libs/stacktrace" ], function(e, t, n, i) { function o() { this.finished = !1, this.timeout = ASYNC_TASK_DEFAULT_TIMEOUT, this.retryCounter = 0, this.runCallbacks = [], this.successCallbacks = [], this.errorCallbacks = []; @@ -14072,7 +14072,7 @@ function(e) { }; var l = !1, c = void 0, u = !1, d = 0; return t.runPeriodically(r), o; -}), define("helpers/dropboxHelper", [ "jquery", "underscore", "core", "extensionMgr", "classes/AsyncTask" ], function(e, t, n, i, o) { +}), define("helpers/dropboxHelper", [ "jquery", "underscore", "core", "eventMgr", "classes/AsyncTask" ], function(e, t, n, i, o) { function r(t) { t.onRun(function() { return n.isOffline === !0 ? (c = void 0, t.error(new Error("Operation not available in offline mode.|stopPublish")), @@ -14226,7 +14226,7 @@ function(e) { e(t); }), n.enqueue(); }, d; -}), define("providers/dropboxProvider", [ "underscore", "utils", "classes/Provider", "extensionMgr", "fileMgr", "helpers/dropboxHelper" ], function(e, t, n, i, o, r) { +}), define("providers/dropboxProvider", [ "underscore", "utils", "classes/Provider", "eventMgr", "fileMgr", "helpers/dropboxHelper" ], function(e, t, n, i, o, r) { function s(e) { return void 0 === e ? void 0 : e.match(/^[^\\<>:"\|?\*]+$/) ? 0 !== e.indexOf("/") ? "/" + e : e : (i.onError('"' + e + '" contains invalid characters.'), void 0); @@ -14324,7 +14324,7 @@ function(e) { var n = {}; return n.path = t.getInputTextValue("#input-publish-dropbox-path", e), e.isPropagationStopped() ? void 0 : n; }, p; -}), define("helpers/googleHelper", [ "jquery", "core", "utils", "extensionMgr", "classes/AsyncTask" ], function(e, t, n, i, o) { +}), define("helpers/googleHelper", [ "jquery", "core", "utils", "eventMgr", "classes/AsyncTask" ], function(e, t, n, i, o) { function r(n) { n.onRun(function() { return t.isOffline === !0 ? (c = !1, n.error(new Error("Operation not available in offline mode.|stopPublish")), @@ -14683,7 +14683,7 @@ function(e) { d(e); }), p.enqueue(); }, d; -}), define("providers/gdriveProvider", [ "underscore", "core", "utils", "classes/Provider", "settings", "extensionMgr", "fileMgr", "helpers/googleHelper" ], function(e, t, n, i, o, r, s, a) { +}), define("providers/gdriveProvider", [ "underscore", "core", "utils", "classes/Provider", "settings", "eventMgr", "fileMgr", "helpers/googleHelper" ], function(e, t, n, i, o, r, s, a) { function l(e) { return "sync." + d + "." + e; } @@ -14851,7 +14851,7 @@ function(e) { }), u(i); } }), p; -}), define("synchronizer", [ "jquery", "underscore", "core", "utils", "extensionMgr", "fileSystem", "fileMgr", "classes/Provider", "providers/dropboxProvider", "providers/gdriveProvider" ], function(e, t, n, i, o, r, s, a) { +}), define("synchronizer", [ "jquery", "underscore", "core", "utils", "eventMgr", "fileSystem", "fileMgr", "classes/Provider", "providers/dropboxProvider", "providers/gdriveProvider" ], function(e, t, n, i, o, r, s, a) { function l(e) { if (0 === y.length) return c(e), void 0; var t = y.pop(); @@ -14990,7 +14990,7 @@ function(e) { n(e); }), s.enqueue(); }, o; -}), define("helpers/githubHelper", [ "jquery", "core", "utils", "extensionMgr", "classes/AsyncTask" ], function(e, t, n, i, o) { +}), define("helpers/githubHelper", [ "jquery", "core", "utils", "eventMgr", "classes/AsyncTask" ], function(e, t, n, i, o) { function r(n) { n.onRun(function() { return t.isOffline === !0 ? (l = !1, n.error(new Error("Operation not available in offline mode.|stopPublish")), @@ -15128,7 +15128,7 @@ function(e) { }, i.importPublic = function(e, t) { n.downloadGist(e.gistId, e.filename, t); }, i; -}), define("sharing", [ "jquery", "underscore", "core", "utils", "extensionMgr", "fileMgr", "classes/AsyncTask", "classes/Provider", "providers/downloadProvider", "providers/gistProvider" ], function(e, t, n, i, o, r, s, a) { +}), define("sharing", [ "jquery", "underscore", "core", "utils", "eventMgr", "fileMgr", "classes/AsyncTask", "classes/Provider", "providers/downloadProvider", "providers/gistProvider" ], function(e, t, n, i, o, r, s, a) { var l = {}, c = t.chain(arguments).map(function(e) { return e instanceof a && [ e.providerId, e ]; }).compact().object().value(); @@ -15258,7 +15258,7 @@ function(e) { n.password = e.getInputTextValue("#input-publish-ssh-password", t), n.path = e.getInputTextValue("#input-publish-file-path", t), t.isPropagationStopped() ? void 0 : n; }, i; -}), define("helpers/tumblrHelper", [ "jquery", "core", "utils", "extensionMgr", "classes/AsyncTask" ], function(e, t, n, i, o) { +}), define("helpers/tumblrHelper", [ "jquery", "core", "utils", "eventMgr", "classes/AsyncTask" ], function(e, t, n, i, o) { function r(e) { e.onRun(function() { return t.isOffline === !0 ? (e.error(new Error("Operation not available in offline mode.|stopPublish")), @@ -15357,7 +15357,7 @@ function(e) { n.postId = e.getInputTextValue("#input-publish-postid"), n.tags = e.getInputTextValue("#input-publish-tags"), t.isPropagationStopped() ? void 0 : n; }, i; -}), define("helpers/wordpressHelper", [ "jquery", "core", "utils", "extensionMgr", "classes/AsyncTask" ], function(e, t, n, i, o) { +}), define("helpers/wordpressHelper", [ "jquery", "core", "utils", "eventMgr", "classes/AsyncTask" ], function(e, t, n, i, o) { function r(e) { e.onRun(function() { return t.isOffline === !0 ? (e.error(new Error("Operation not available in offline mode.|stopPublish")), @@ -15454,7 +15454,7 @@ function(e) { n.postId = e.getInputTextValue("#input-publish-postid"), n.tags = e.getInputTextValue("#input-publish-tags"), t.isPropagationStopped() ? void 0 : n; }, i; -}), define("publisher", [ "jquery", "underscore", "core", "utils", "settings", "extensionMgr", "fileSystem", "fileMgr", "sharing", "classes/Provider", "providers/bloggerProvider", "providers/dropboxProvider", "providers/gistProvider", "providers/githubProvider", "providers/gdriveProvider", "providers/sshProvider", "providers/tumblrProvider", "providers/wordpressProvider" ], function(e, t, n, i, o, r, s, a, l, c) { +}), define("publisher", [ "jquery", "underscore", "core", "utils", "settings", "eventMgr", "fileSystem", "fileMgr", "sharing", "classes/Provider", "providers/bloggerProvider", "providers/dropboxProvider", "providers/gistProvider", "providers/githubProvider", "providers/gdriveProvider", "providers/sshProvider", "providers/tumblrProvider", "providers/wordpressProvider" ], function(e, t, n, i, o, r, s, a, l, c) { function u(t, n, i) { return void 0 === n.format && (n.format = e("input:radio[name=radio-publish-format]:checked").prop("value")), "markdown" == n.format ? t.content : "html" == n.format ? i : g.applyTemplate(t, n, i); @@ -15558,7 +15558,7 @@ function(e) { i.saveAs(t, e.title + (-1 === o.template.indexOf("documentHTML") ? ".md" : ".html")); }); }), r.onPublisherCreated(g), g; -}), define("providers/gplusProvider", [ "underscore", "core", "utils", "classes/Provider", "extensionMgr", "helpers/googleHelper" ], function(e, t, n, i, o, r) { +}), define("providers/gplusProvider", [ "underscore", "core", "utils", "classes/Provider", "eventMgr", "helpers/googleHelper" ], function(e, t, n, i, o, r) { function s(t, n) { var i = void 0; return e.find(t.thumbnails, function(e) { @@ -15596,7 +15596,7 @@ function(e) { t && (i += ' "' + t + '"'), p(void 0, i), d = {}, e && (d.size = e), localStorage[l + ".importImagePreferences"] = JSON.stringify(d); }); }), c; -}), define("mediaImporter", [ "jquery", "underscore", "classes/Provider", "core", "extensionMgr", "providers/gplusProvider" ], function(e, t, n, i) { +}), define("mediaImporter", [ "jquery", "underscore", "classes/Provider", "core", "eventMgr", "providers/gplusProvider" ], function(e, t, n, i) { var o = {}, r = t.chain(arguments).map(function(e) { return e instanceof n && [ e.providerId, e ]; }).compact().object().value(); diff --git a/js/mediaImporter.js b/js/mediaImporter.js index 365852fb..9ec0e8e9 100644 --- a/js/mediaImporter.js +++ b/js/mediaImporter.js @@ -3,9 +3,9 @@ define([ "underscore", "classes/Provider", "core", - "extensionMgr", + "eventMgr", "providers/gplusProvider" -], function($, _, Provider, core, extensionMgr) { +], function($, _, Provider, core, eventMgr) { var mediaImporter = {}; diff --git a/js/providers/dropboxProvider.js b/js/providers/dropboxProvider.js index 83b76cc2..4f54ca1c 100644 --- a/js/providers/dropboxProvider.js +++ b/js/providers/dropboxProvider.js @@ -2,10 +2,10 @@ define([ "underscore", "utils", "classes/Provider", - "extensionMgr", + "eventMgr", "fileMgr", "helpers/dropboxHelper" -], function(_, utils, Provider, extensionMgr, fileMgr, dropboxHelper) { +], function(_, utils, Provider, eventMgr, fileMgr, dropboxHelper) { var PROVIDER_DROPBOX = "dropbox"; @@ -17,7 +17,7 @@ define([ return undefined; } if(!path.match(/^[^\\<>:"\|?\*]+$/)) { - extensionMgr.onError('"' + path + '" contains invalid characters.'); + eventMgr.onError('"' + path + '" contains invalid characters.'); return undefined; } if(path.indexOf("/") !== 0) { @@ -59,7 +59,7 @@ define([ fileDescList.push(fileDesc); }); if(fileDescList.length !== 0) { - extensionMgr.onSyncImportSuccess(fileDescList, dropboxProvider); + eventMgr.onSyncImportSuccess(fileDescList, dropboxProvider); } }); }); @@ -75,7 +75,7 @@ define([ var syncIndex = createSyncIndex(path); var fileDesc = fileMgr.getFileFromSyncIndex(syncIndex); if(fileDesc !== undefined) { - extensionMgr.onError('"' + fileDesc.title + '" was already imported.'); + eventMgr.onError('"' + fileDesc.title + '" was already imported.'); return; } importPaths.push(path); @@ -95,7 +95,7 @@ define([ var fileDesc = fileMgr.getFileFromSyncIndex(syncIndex); if(fileDesc !== undefined) { var existingTitle = fileDesc.title; - extensionMgr.onError('File path is already synchronized with "' + existingTitle + '".'); + eventMgr.onError('File path is already synchronized with "' + existingTitle + '".'); callback(true); return; } @@ -180,9 +180,9 @@ define([ var localTitle = fileDesc.title; // File deleted if(change.wasRemoved === true) { - extensionMgr.onError('"' + localTitle + '" has been removed from Dropbox.'); + eventMgr.onError('"' + localTitle + '" has been removed from Dropbox.'); fileDesc.removeSyncLocation(syncAttributes); - extensionMgr.onSyncRemoved(fileDesc, syncAttributes); + eventMgr.onSyncRemoved(fileDesc, syncAttributes); return; } var localContent = fileDesc.content; @@ -194,13 +194,13 @@ define([ // Conflict detection if(fileContentChanged === true && localContentChanged === true && remoteContentChanged === true) { fileMgr.createFile(localTitle + " (backup)", localContent); - extensionMgr.onMessage('Conflict detected on "' + localTitle + '". A backup has been created locally.'); + eventMgr.onMessage('Conflict detected on "' + localTitle + '". A backup has been created locally.'); } // If file content changed if(fileContentChanged && remoteContentChanged === true) { fileDesc.content = file.content; - extensionMgr.onContentChanged(fileDesc); - extensionMgr.onMessage('"' + localTitle + '" has been updated from Dropbox.'); + eventMgr.onContentChanged(fileDesc); + eventMgr.onMessage('"' + localTitle + '" has been updated from Dropbox.'); if(fileMgr.currentFile === fileDesc) { fileMgr.selectFile(); // Refresh editor } diff --git a/js/providers/gdriveProvider.js b/js/providers/gdriveProvider.js index d85f6f80..de81a5dd 100644 --- a/js/providers/gdriveProvider.js +++ b/js/providers/gdriveProvider.js @@ -4,10 +4,10 @@ define([ "utils", "classes/Provider", "settings", - "extensionMgr", + "eventMgr", "fileMgr", "helpers/googleHelper" -], function(_, core, utils, Provider, settings, extensionMgr, fileMgr, googleHelper) { +], function(_, core, utils, Provider, settings, eventMgr, fileMgr, googleHelper) { var PROVIDER_GDRIVE = "gdrive"; @@ -52,7 +52,7 @@ define([ fileDescList.push(fileDesc); }); if(fileDesc !== undefined) { - extensionMgr.onSyncImportSuccess(fileDescList, gdriveProvider); + eventMgr.onSyncImportSuccess(fileDescList, gdriveProvider); fileMgr.selectFile(fileDesc); } }); @@ -69,7 +69,7 @@ define([ var syncIndex = createSyncIndex(doc.id); var fileDesc = fileMgr.getFileFromSyncIndex(syncIndex); if(fileDesc !== undefined) { - extensionMgr.onError('"' + fileDesc.title + '" was already imported.'); + eventMgr.onError('"' + fileDesc.title + '" was already imported.'); return; } importIds.push(doc.id); @@ -111,7 +111,7 @@ define([ var syncIndex = createSyncIndex(id); var fileDesc = fileMgr.getFileFromSyncIndex(syncIndex); if(fileDesc !== undefined) { - extensionMgr.onError('File ID is already synchronized with "' + fileDesc.title + '".'); + eventMgr.onError('File ID is already synchronized with "' + fileDesc.title + '".'); callback(true); return; } @@ -188,9 +188,9 @@ define([ var localTitle = fileDesc.title; // File deleted if(change.deleted === true) { - extensionMgr.onError('"' + localTitle + '" has been removed from Google Drive.'); + eventMgr.onError('"' + localTitle + '" has been removed from Google Drive.'); fileDesc.removeSyncLocation(syncAttributes); - extensionMgr.onSyncRemoved(fileDesc, syncAttributes); + eventMgr.onSyncRemoved(fileDesc, syncAttributes); if(syncAttributes.isRealtime === true && fileMgr.currentFile === fileDesc) { gdriveProvider.stopRealtimeSync(); } @@ -209,19 +209,19 @@ define([ // Conflict detection if((fileTitleChanged === true && localTitleChanged === true && remoteTitleChanged === true) || (!syncAttributes.isRealtime && fileContentChanged === true && localContentChanged === true && remoteContentChanged === true)) { fileMgr.createFile(localTitle + " (backup)", localContent); - extensionMgr.onMessage('Conflict detected on "' + localTitle + '". A backup has been created locally.'); + eventMgr.onMessage('Conflict detected on "' + localTitle + '". A backup has been created locally.'); } // If file title changed if(fileTitleChanged && remoteTitleChanged === true) { fileDesc.title = file.title; - extensionMgr.onTitleChanged(fileDesc); - extensionMgr.onMessage('"' + localTitle + '" has been renamed to "' + file.title + '" on Google Drive.'); + eventMgr.onTitleChanged(fileDesc); + eventMgr.onMessage('"' + localTitle + '" has been renamed to "' + file.title + '" on Google Drive.'); } // If file content changed if(!syncAttributes.isRealtime && fileContentChanged && remoteContentChanged === true) { fileDesc.content = file.content; - extensionMgr.onContentChanged(fileDesc); - extensionMgr.onMessage('"' + file.title + '" has been updated from Google Drive.'); + eventMgr.onContentChanged(fileDesc); + eventMgr.onMessage('"' + file.title + '" has been updated from Google Drive.'); if(fileMgr.currentFile === fileDesc) { fileMgr.selectFile(); // Refresh editor } @@ -263,7 +263,7 @@ define([ // Keep a link to the pagedown editor var editor = undefined; - extensionMgr.addHookCallback("onEditorConfigure", function(editorParam) { + eventMgr.addListener("onEditorConfigure", function(editorParam) { editor = editorParam; }); @@ -327,7 +327,7 @@ define([ if(remoteContentChanged === true) { // Conflict detected fileMgr.createFile(fileDesc.title + " (backup)", localContent); - extensionMgr.onMessage('Conflict detected on "' + fileDesc.title + '". A backup has been created locally.'); + eventMgr.onMessage('Conflict detected on "' + fileDesc.title + '". A backup has been created locally.'); } else { // Add local modifications if no collaborators change @@ -371,13 +371,13 @@ define([ googleHelper.forceAuthenticate(); } else if(err.type == "not_found") { - extensionMgr.onError('"' + fileDesc.title + '" has been removed from Google Drive.'); + eventMgr.onError('"' + fileDesc.title + '" has been removed from Google Drive.'); fileDesc.removeSyncLocation(syncAttributes); - extensionMgr.onSyncRemoved(fileDesc, syncAttributes); + eventMgr.onSyncRemoved(fileDesc, syncAttributes); gdriveProvider.stopRealtimeSync(); } else if(err.isFatal) { - extensionMgr.onError('An error has forced real time synchronization to stop.'); + eventMgr.onError('An error has forced real time synchronization to stop.'); gdriveProvider.stopRealtimeSync(); } }); @@ -417,7 +417,7 @@ define([ syncLocations[syncAttributes.syncIndex] = syncAttributes; var fileDesc = fileMgr.createFile(file.title, file.content, syncLocations); fileMgr.selectFile(fileDesc); - extensionMgr.onMessage('"' + file.title + '" created successfully on Google Drive.'); + eventMgr.onMessage('"' + file.title + '" created successfully on Google Drive.'); }); } else if(state.action == "open") { diff --git a/js/providers/gplusProvider.js b/js/providers/gplusProvider.js index 8483e73e..d236bea8 100644 --- a/js/providers/gplusProvider.js +++ b/js/providers/gplusProvider.js @@ -3,9 +3,9 @@ define([ "core", "utils", "classes/Provider", - "extensionMgr", + "eventMgr", "helpers/googleHelper" -], function(_, core, utils, Provider, extensionMgr, googleHelper) { +], function(_, core, utils, Provider, eventMgr, googleHelper) { var PROVIDER_GPLUS = "gplus"; @@ -28,7 +28,7 @@ define([ var importImagePreferences = utils.retrieveIgnoreError(PROVIDER_GPLUS + ".importImagePreferences"); function showImportImgDialog() { if(!imageDoc.thumbnails) { - extensionMgr.onError("Image " + imageDoc.name + " is not accessible."); + eventMgr.onError("Image " + imageDoc.name + " is not accessible."); callback(true); return; } diff --git a/js/publisher.js b/js/publisher.js index ca772aab..af77dc43 100644 --- a/js/publisher.js +++ b/js/publisher.js @@ -4,7 +4,7 @@ define([ "core", "utils", "settings", - "extensionMgr", + "eventMgr", "fileSystem", "fileMgr", "sharing", @@ -17,7 +17,7 @@ define([ "providers/sshProvider", "providers/tumblrProvider", "providers/wordpressProvider" -], function($, _, core, utils, settings, extensionMgr, fileSystem, fileMgr, sharing, Provider) { +], function($, _, core, utils, settings, eventMgr, fileSystem, fileMgr, sharing, Provider) { var publisher = {}; @@ -46,7 +46,7 @@ define([ } catch(e) { // localStorage can be corrupted - extensionMgr.onError(e); + eventMgr.onError(e); // Remove publish location utils.removeIndexFromArray(fileDesc.fileIndex + ".publish", publishIndex); localStorage.removeItem(publishIndex); @@ -65,7 +65,7 @@ define([ }); } catch(e) { - extensionMgr.onError(e); + eventMgr.onError(e); return e.message; } }; @@ -110,7 +110,7 @@ define([ var errorMsg = error.toString(); if(errorMsg.indexOf("|removePublish") !== -1) { publishFileDesc.removePublishLocation(publishAttributes); - extensionMgr.onPublishRemoved(publishFileDesc, publishAttributes); + eventMgr.onPublishRemoved(publishFileDesc, publishAttributes); } if(errorMsg.indexOf("|stopPublish") !== -1) { callback(error); @@ -123,7 +123,7 @@ define([ // Get the html from the onPreviewFinished callback var previewHtml = undefined; - extensionMgr.addHookCallback("onPreviewFinished", function(html) { + eventMgr.addListener("onPreviewFinished", function(html) { previewHtml = html; }); @@ -136,15 +136,15 @@ define([ } publishRunning = true; - extensionMgr.onPublishRunning(true); + eventMgr.onPublishRunning(true); publishFileDesc = fileMgr.currentFile; publishHTML = previewHtml; publishAttributesList = _.values(publishFileDesc.publishLocations); publishLocation(function(errorFlag) { publishRunning = false; - extensionMgr.onPublishRunning(false); + eventMgr.onPublishRunning(false); if(errorFlag === undefined) { - extensionMgr.onPublishSuccess(publishFileDesc); + eventMgr.onPublishSuccess(publishFileDesc); } }); }; @@ -157,7 +157,7 @@ define([ } while (_.has(localStorage, publishIndex)); publishAttributes.publishIndex = publishIndex; fileDesc.addPublishLocation(publishAttributes); - extensionMgr.onNewPublishSuccess(fileDesc, publishAttributes); + eventMgr.onNewPublishSuccess(fileDesc, publishAttributes); } // Initialize the "New publication" dialog @@ -251,6 +251,6 @@ define([ }); }); - extensionMgr.onPublisherCreated(publisher); + eventMgr.onPublisherCreated(publisher); return publisher; }); \ No newline at end of file diff --git a/js/sharing.js b/js/sharing.js index 119364da..1a49ede0 100644 --- a/js/sharing.js +++ b/js/sharing.js @@ -3,13 +3,13 @@ define([ "underscore", "core", "utils", - "extensionMgr", + "eventMgr", "fileMgr", "classes/AsyncTask", "classes/Provider", "providers/downloadProvider", "providers/gistProvider" -], function($, _, core, utils, extensionMgr, fileMgr, AsyncTask, Provider) { +], function($, _, core, utils, eventMgr, fileMgr, AsyncTask, Provider) { var sharing = {}; @@ -59,7 +59,7 @@ define([ attributes.sharingLink = shortUrl; } else { - extensionMgr.onError("An error occured while creating sharing link."); + eventMgr.onError("An error occured while creating sharing link."); attributes.sharingLink = url; } task.chain(); diff --git a/js/synchronizer.js b/js/synchronizer.js index b096e4c3..2b9c34ec 100644 --- a/js/synchronizer.js +++ b/js/synchronizer.js @@ -3,13 +3,13 @@ define([ "underscore", "core", "utils", - "extensionMgr", + "eventMgr", "fileSystem", "fileMgr", "classes/Provider", "providers/dropboxProvider", "providers/gdriveProvider" -], function($, _, core, utils, extensionMgr, fileSystem, fileMgr, Provider) { +], function($, _, core, utils, eventMgr, fileSystem, fileMgr, Provider) { var synchronizer = {}; @@ -38,7 +38,7 @@ define([ } catch(e) { // localStorage can be corrupted - extensionMgr.onError(e); + eventMgr.onError(e); // Remove sync location utils.removeIndexFromArray(fileDesc.fileIndex + ".sync", syncIndex); localStorage.removeItem(syncIndex); @@ -47,9 +47,11 @@ define([ }); // Returns true if at least one file has synchronized location - synchronizer.hasSync = function() { - return _.some(providerMap, function(provider) { - return fileMgr.hasSync(provider); + synchronizer.hasSync = function(provider) { + return _.some(fileSystem, function(fileDesc) { + return _.some(fileDesc.syncLocations, function(syncAttributes) { + return provider === undefined || syncAttributes.provider === provider; + }); }); }; @@ -148,7 +150,7 @@ define([ var provider = providerList.pop(); // Check that provider has files to sync - if(!fileMgr.hasSync(provider)) { + if(!synchronizer.hasSync(provider)) { providerDown(callback); return; } @@ -177,13 +179,13 @@ define([ return false; } syncRunning = true; - extensionMgr.onSyncRunning(true); + eventMgr.onSyncRunning(true); uploadCycle = true; function isError(error) { if(error !== undefined) { syncRunning = false; - extensionMgr.onSyncRunning(false); + eventMgr.onSyncRunning(false); return true; } return false; @@ -198,8 +200,8 @@ define([ return; } syncRunning = false; - extensionMgr.onSyncRunning(false); - extensionMgr.onSyncSuccess(); + eventMgr.onSyncRunning(false); + eventMgr.onSyncSuccess(); }); }); return true; @@ -251,11 +253,11 @@ define([ } }; - // Triggers realtime synchronization from extensionMgr events + // Triggers realtime synchronization from eventMgr events if(viewerMode === false) { - extensionMgr.addHookCallback("onFileOpen", onFileOpen); - extensionMgr.addHookCallback("onFileClosed", synchronizer.tryStopRealtimeSync); - extensionMgr.addHookCallback("onOfflineChanged", onOfflineChanged); + eventMgr.addListener("onFileOpen", onFileOpen); + eventMgr.addListener("onFileClosed", synchronizer.tryStopRealtimeSync); + eventMgr.addListener("onOfflineChanged", onOfflineChanged); } /*************************************************************************** @@ -297,7 +299,7 @@ define([ if(isRealtime) { if(_.size(fileDesc.syncLocations) > 0) { - extensionMgr.onError("Real time collaborative document can't be synchronized with multiple locations"); + eventMgr.onError("Real time collaborative document can't be synchronized with multiple locations"); return; } // Perform the provider's real time export @@ -307,7 +309,7 @@ define([ } syncAttributes.isRealtime = true; fileDesc.addSyncLocation(syncAttributes); - extensionMgr.onSyncExportSuccess(fileDesc, syncAttributes); + eventMgr.onSyncExportSuccess(fileDesc, syncAttributes); // Start the real time sync realtimeFileDesc = fileDesc; @@ -317,7 +319,7 @@ define([ } else { if(_.size(fileDesc.syncLocations) > 0 && _.first(_.values(fileDesc.syncLocations)).isRealtime) { - extensionMgr.onError("Real time collaborative document can't be synchronized with multiple locations"); + eventMgr.onError("Real time collaborative document can't be synchronized with multiple locations"); return; } // Perform the provider's standard export @@ -326,7 +328,7 @@ define([ return; } fileDesc.addSyncLocation(syncAttributes); - extensionMgr.onSyncExportSuccess(fileDesc, syncAttributes); + eventMgr.onSyncExportSuccess(fileDesc, syncAttributes); }); } @@ -342,7 +344,7 @@ define([ $(".action-sync-manual-" + provider.providerId).click(function(event) { var fileDesc = fileMgr.currentFile; if(_.size(fileDesc.syncLocations) > 0 && _.first(_.values(fileDesc.syncLocations)).isRealtime) { - extensionMgr.onError("Real time collaborative document can't be synchronized with multiple locations"); + eventMgr.onError("Real time collaborative document can't be synchronized with multiple locations"); return; } provider.exportManual(event, fileDesc.title, fileDesc.content, function(error, syncAttributes) { @@ -350,12 +352,12 @@ define([ return; } fileDesc.addSyncLocation(syncAttributes); - extensionMgr.onSyncExportSuccess(fileDesc, syncAttributes); + eventMgr.onSyncExportSuccess(fileDesc, syncAttributes); }); }); }); }); - extensionMgr.onSynchronizerCreated(synchronizer); + eventMgr.onSynchronizerCreated(synchronizer); return synchronizer; });