From ec1388fb3f93370d72e9b9110cfd544a9338936e Mon Sep 17 00:00:00 2001 From: benweet Date: Sun, 7 Jul 2013 21:07:11 +0100 Subject: [PATCH] Added user custom extension --- css/jgrowl.css | 2 +- js/core.js | 17 ++++- js/extensionMgr.js | 8 ++- js/extensions/userCustom.js | 63 +++++++++++++++++++ js/html/settingsTemplateTooltip.html | 2 +- .../settingsUserCustomExtensionTooltip.html | 16 +++++ js/html/userCustomSettingsBlock.html | 12 ++++ run_deploy | 0 8 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 js/extensions/userCustom.js create mode 100644 js/html/settingsUserCustomExtensionTooltip.html create mode 100644 js/html/userCustomSettingsBlock.html mode change 100644 => 100755 run_deploy diff --git a/css/jgrowl.css b/css/jgrowl.css index af8c108b..078c1175 100644 --- a/css/jgrowl.css +++ b/css/jgrowl.css @@ -1,6 +1,6 @@ div.jGrowl { - z-index: 1000; + z-index: 1050; color: #fff; } diff --git a/js/core.js b/js/core.js index 338ce194..6f11e0f0 100644 --- a/js/core.js +++ b/js/core.js @@ -6,12 +6,13 @@ define([ "extensionMgr", "mousetrap", "text!html/settingsTemplateTooltip.html", + "text!html/settingsUserCustomExtensionTooltip.html", "storage", "config", "libs/bootstrap", "libs/layout", "libs/Markdown.Editor" -], function($, _, utils, settings, extensionMgr, mousetrap, settingsTemplateTooltipHTML) { +], function($, _, utils, settings, extensionMgr, mousetrap, settingsTemplateTooltipHTML, settingsUserCustomExtensionTooltipHTML) { var core = {}; @@ -536,6 +537,20 @@ define([ trigger: 'hover', title: 'Thanks for supporting StackEdit by adding a backlink in your documents!' }); + $(".tooltip-usercustom-extension").tooltip({ + html: true, + container: '#modal-settings', + placement: 'right', + trigger: 'manual', + title: settingsUserCustomExtensionTooltipHTML + }).click(function(e) { + $(this).tooltip('show'); + $(document).on("click.tooltip-usercustom-extension", function(e) { + $(".tooltip-usercustom-extension").tooltip('hide'); + $(document).off("click.tooltip-usercustom-extension"); + }); + e.stopPropagation(); + }); $(".tooltip-template").tooltip({ html: true, container: '#modal-settings', diff --git a/js/extensionMgr.js b/js/extensionMgr.js index 64ec4f82..2f1a2e5c 100644 --- a/js/extensionMgr.js +++ b/js/extensionMgr.js @@ -26,6 +26,7 @@ define([ "extensions/buttonHtmlCode", "extensions/buttonMarkdownSyntax", "extensions/buttonViewer", + "extensions/userCustom", "libs/bootstrap", "libs/jquery.waitforimages" ], function($, _, utils, Extension, settings, settingsExtensionsAccordionHTML) { @@ -37,14 +38,14 @@ define([ return argument instanceof Extension && argument; }).compact().value(); - // Return every named callbacks implemented in extensions + // 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 from extensions + // Return a function that calls every callbacks with the specified name from all extensions function createHook(hookName, noLog) { var callbackList = getExtensionCallbackList(hookName); return function() { @@ -69,6 +70,9 @@ define([ extension.config = _.extend({}, extension.defaultConfig, extensionSettings[extension.extensionId]); extension.config.enabled = !extension.isOptional || extension.config.enabled === undefined || extension.config.enabled === true; }); + + // Call every onInit callbacks + createHook("onInit")(); // Load/Save extension config from/to settings extensionMgr["onLoadSettings"] = function() { diff --git a/js/extensions/userCustom.js b/js/extensions/userCustom.js new file mode 100644 index 00000000..8370f54a --- /dev/null +++ b/js/extensions/userCustom.js @@ -0,0 +1,63 @@ +define([ + "jquery", + "underscore", + "utils", + "classes/Extension", + "fileSystem", + "settings", + "text!html/userCustomSettingsBlock.html", +], function($, _, utils, Extension, fileSystem, settings, userCustomSettingsBlockHTML) { + + var userCustom = new Extension("userCustom", "UserCustom extension", true); + userCustom.settingsBlock = userCustomSettingsBlockHTML; + userCustom.defaultConfig = { + code: "", + }; + + var fileMgr = undefined; + userCustom.onFileMgrCreated = function(fileMgrParameter) { + fileMgr = fileMgrParameter; + }; + + var synchronizer = undefined; + userCustom.onSynchronizerCreated = function(synchronizerParameter) { + synchronizer = synchronizerParameter; + }; + + var publisher = undefined; + userCustom.onPublisherCreated = function(publisherParameter) { + publisher = publisherParameter; + }; + + var extensionMgr = undefined; + userCustom.onExtensionMgrCreated = function(extensionMgrParameter) { + extensionMgr = extensionMgrParameter; + }; + + userCustom.onLoadSettings = function() { + utils.setInputValue("#textarea-usercustom-code", userCustom.config.code); + }; + + userCustom.onSaveSettings = function(newConfig, event) { + newConfig.code = utils.getInputValue("#textarea-usercustom-code"); + try { + eval(newConfig.code); + } + catch(e) { + extensionMgr.onError(e); + // Mark the textarea as error + utils.getInputTextValue("#textarea-usercustom-code", event, /^$/); + } + }; + + userCustom.onInit = function() { + try { + eval(userCustom.config.code); + } + catch(e) { + console.error(e); + } + }; + + return userCustom; +}); \ No newline at end of file diff --git a/js/html/settingsTemplateTooltip.html b/js/html/settingsTemplateTooltip.html index c586eb64..8d4746df 100644 --- a/js/html/settingsTemplateTooltip.html +++ b/js/html/settingsTemplateTooltip.html @@ -7,7 +7,7 @@ Available variables:
  • publishAttributes: attributes of the publish location (undefined if not publishing)
  • -Examples: +Examples:
    <title><%= documentTitle %></title>
    diff --git a/js/html/settingsUserCustomExtensionTooltip.html b/js/html/settingsUserCustomExtensionTooltip.html new file mode 100644 index 00000000..2dfd1833 --- /dev/null +++ b/js/html/settingsUserCustomExtensionTooltip.html @@ -0,0 +1,16 @@ +Extension variable name: +userCustom +
    +
    +Example: +
    +userCustom.onPreviewFinished = function() { +
    +  extensionMgr.onMessage("Finished!"); +
    +}; +
    +
    +More + info \ No newline at end of file diff --git a/js/html/userCustomSettingsBlock.html b/js/html/userCustomSettingsBlock.html new file mode 100644 index 00000000..c2c257c0 --- /dev/null +++ b/js/html/userCustomSettingsBlock.html @@ -0,0 +1,12 @@ +

    Allows users to implement their own extension.

    +
    +
    + +
    + +
    +
    +
    +More info \ No newline at end of file diff --git a/run_deploy b/run_deploy old mode 100644 new mode 100755