From cc01b5af4e0ab2f2ea1427c94f1e88e16376d7ce Mon Sep 17 00:00:00 2001 From: benweet Date: Tue, 28 May 2013 00:27:38 +0100 Subject: [PATCH] New extension pattern --- js/core.js | 7 ---- js/extension-manager.js | 55 ++++++++++++++----------- js/extensions/button-publish.js | 1 - js/extensions/button-sync.js | 1 - js/extensions/email-converter.js | 20 +++++++++ js/extensions/manage-publication.js | 2 +- js/extensions/manage-synchronization.js | 2 +- js/extensions/notifications.js | 28 +++++++++++-- js/extensions/toc.js | 4 +- js/file-manager.js | 15 ++++--- 10 files changed, 87 insertions(+), 48 deletions(-) create mode 100644 js/extensions/email-converter.js diff --git a/js/core.js b/js/core.js index 141c807f..67186203 100644 --- a/js/core.js +++ b/js/core.js @@ -264,13 +264,6 @@ define([ extensionMgr.onEditorConfigure(editor); editor.hooks.chain("onPreviewRefresh", extensionMgr.onAsyncPreview); - // Convert email addresses (not managed by pagedown) - converter.hooks.chain("postConversion", function(text) { - return text.replace(/<(mailto\:)?([^\s>]+@[^\s>]+\.\S+?)>/g, function(match, mailto, email) { - return '' + email + ''; - }); - }); - $("#wmd-input, #wmd-preview").scrollTop(0); $("#wmd-button-bar").empty(); editor.run(previewWrapper); diff --git a/js/extension-manager.js b/js/extension-manager.js index 52c7bb8c..51bc8210 100644 --- a/js/extension-manager.js +++ b/js/extension-manager.js @@ -15,6 +15,7 @@ define( [ "extensions/markdown-extra", "extensions/toc", "extensions/math-jax", + "extensions/email-converter", "extensions/scroll-link", "lib/bootstrap" ], function($, _, utils, settings) { @@ -54,30 +55,6 @@ define( [ extensionMgr[hookName] = createHook(hookName); } - var accordionTmpl = [ - '
', - '
', - '', - '', - '<%= extensionName %>', - '', - '
', - '
', - '
<%= settingsBloc %>
', - '
', - '
'].join(""); - - function createSettings(extension) { - $("#accordion-extensions").append($(_.template(accordionTmpl, { - extensionId: extension.extensionId, - extensionName: extension.extensionName, - optional: extension.optional, - settingsBloc: extension.settingsBloc - }))); - } - // Set extension config extensionSettings = settings.extensionSettings || {}; _.each(extensionList, function(extension) { @@ -164,9 +141,37 @@ define( [ tryFinished(); }; + var accordionTmpl = [ + '
', + '
', + '', + '', + '<%= extensionName %>', + '', + '
', + '
', + '
<%= settingsBloc %>
', + '
', + '
'].join(""); + + function createSettings(extension) { + $("#accordion-extensions").append($(_.template(accordionTmpl, { + extensionId: extension.extensionId, + extensionName: extension.extensionName, + optional: extension.optional, + settingsBloc: extension.settingsBloc + }))); + } + $(function() { // Create accordion in settings dialog - _.each(extensionList, createSettings); + _.chain( + extensionList + ).sortBy(function(extension) { + return extension.extensionName.toLowerCase(); + }).each(createSettings); }); return extensionMgr; diff --git a/js/extensions/button-publish.js b/js/extensions/button-publish.js index 60a9f45c..a2b93407 100644 --- a/js/extensions/button-publish.js +++ b/js/extensions/button-publish.js @@ -6,7 +6,6 @@ define([ var buttonPublish = { extensionId: "buttonPublish", extensionName: 'Button "Publish"', - optional: true, settingsBloc: '

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

' }; diff --git a/js/extensions/button-sync.js b/js/extensions/button-sync.js index c557e803..0f943d64 100644 --- a/js/extensions/button-sync.js +++ b/js/extensions/button-sync.js @@ -6,7 +6,6 @@ define([ var buttonSync = { extensionId: "buttonSync", extensionName: 'Button "Synchronize"', - optional: true, settingsBloc: '

Adds a "Synchronize documents" button in the navigation bar.

' }; diff --git a/js/extensions/email-converter.js b/js/extensions/email-converter.js new file mode 100644 index 00000000..f4223425 --- /dev/null +++ b/js/extensions/email-converter.js @@ -0,0 +1,20 @@ +define(function() { + + var emailConverter = { + extensionId: "emailConverter", + extensionName: "Email Converter", + optional: true, + settingsBloc: '

Converts email adresses in the form <email@example.com> into a clickable links.

' + }; + + emailConverter.onEditorConfigure = function(editor) { + editor.getConverter().hooks.chain("postConversion", function(text) { + return text.replace(/<(mailto\:)?([^\s>]+@[^\s>]+\.\S+?)>/g, function(match, mailto, email) { + return '' + email + ''; + }); + }); + }; + + return emailConverter; +}); + diff --git a/js/extensions/manage-publication.js b/js/extensions/manage-publication.js index 64427623..897f72d4 100644 --- a/js/extensions/manage-publication.js +++ b/js/extensions/manage-publication.js @@ -5,7 +5,7 @@ define([ var managePublication = { extensionId: "managePublication", - extensionName: "Manage Publication", + extensionName: "Manage publication", settingsBloc: '

Populates the "Manage publication" dialog box.

' }; diff --git a/js/extensions/manage-synchronization.js b/js/extensions/manage-synchronization.js index 67ac87e0..79e9bbba 100644 --- a/js/extensions/manage-synchronization.js +++ b/js/extensions/manage-synchronization.js @@ -5,7 +5,7 @@ define([ var manageSynchronization = { extensionId: "manageSynchronization", - extensionName: "Manage Synchronization", + extensionName: "Manage synchronization", settingsBloc: '

Populates the "Manage synchronization" dialog box.

' }; diff --git a/js/extensions/notifications.js b/js/extensions/notifications.js index 4642731b..cfe72a70 100644 --- a/js/extensions/notifications.js +++ b/js/extensions/notifications.js @@ -1,21 +1,41 @@ define([ "jquery", "underscore", + "utils", "jgrowl" -], function($, _, jGrowl) { +], function($, _, utils, jGrowl) { var notifications = { extensionId: "notifications", extensionName: "Notifications", defaultConfig: { - showingTime: 5000 + timeout: 5000 }, - settingsBloc: '

Shows notification messages in the bottom-right corner of the screen.

' + settingsBloc: [ + '

Shows notification messages in the bottom-right corner of the screen.

', + '
', + '
', + '', + '
', + '', + 'ms', + '
', + '
', + '
' + ].join("") }; + notifications.onLoadSettings = function() { + utils.setInputValue("#input-notifications-timeout", notifications.config.timeout); + }; + + notifications.onSaveSettings = function(newConfig, event) { + newConfig.timeout = utils.getInputIntValue("#input-notifications-timeout", event, 1, 60000); + }; + notifications.onReady = function() { // jGrowl configuration - jGrowl.defaults.life = notifications.config.showingTime; + jGrowl.defaults.life = notifications.config.timeout; jGrowl.defaults.closer = false; jGrowl.defaults.closeTemplate = ''; jGrowl.defaults.position = 'bottom-right'; diff --git a/js/extensions/toc.js b/js/extensions/toc.js index d4055c2f..dbac74a0 100644 --- a/js/extensions/toc.js +++ b/js/extensions/toc.js @@ -6,9 +6,9 @@ define([ var toc = { extensionId: "toc", - extensionName: "Table Of Content", + extensionName: "Table of content", optional: true, - settingsBloc: '

Generates a table of content and include it in your document using the marker [TOC].

' + settingsBloc: '

Generates a table of content when a [TOC] marker is found.

' }; // TOC element description diff --git a/js/file-manager.js b/js/file-manager.js index 53c9b8fb..70a3524d 100644 --- a/js/file-manager.js +++ b/js/file-manager.js @@ -36,15 +36,18 @@ define([ // Caution: this function recreate the editor (reset undo operations) fileMgr.selectFile = function(fileDesc) { - var fileSystemSize = _.size(fileSystem); - // If no file create one - if (_.size(fileSystem) === 0) { - fileDesc = fileMgr.createFile(WELCOME_DOCUMENT_TITLE, welcomeContent); - } + fileDesc = fileDesc || fileMgr.getCurrentFile(); if(fileDesc === undefined) { + var fileSystemSize = _.size(fileSystem); + // If fileSystem empty create one file + if (fileSystemSize === 0) { + fileDesc = fileMgr.createFile(WELCOME_DOCUMENT_TITLE, welcomeContent); + } // If no file is selected take the last created - fileDesc = fileSystem[_.keys(fileSystem)[fileSystemSize - 1]]; + else { + fileDesc = fileSystem[_.keys(fileSystem)[fileSystemSize - 1]]; + } } fileMgr.setCurrentFile(fileDesc);