Added user custom extension

This commit is contained in:
benweet 2013-07-07 21:07:11 +01:00
parent 77f3324873
commit ec1388fb3f
8 changed files with 115 additions and 5 deletions

View File

@ -1,6 +1,6 @@
div.jGrowl {
z-index: 1000;
z-index: 1050;
color: #fff;
}

View File

@ -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',

View File

@ -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() {

View File

@ -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;
});

View File

@ -7,7 +7,7 @@ Available variables:
<li><b>publishAttributes</b>: attributes of the publish location
(undefined if not publishing)</li>
</ul>
Examples:
<b>Examples:</b>
<br />
&lt;title&gt;&lt;%= documentTitle %&gt;&lt;&#x2F;title&gt;
<br />

View File

@ -0,0 +1,16 @@
Extension variable name:
<b>userCustom</b>
<br>
<br>
<b>Example:</b>
<br />
userCustom.onPreviewFinished = function() {
<br />
&nbsp;&nbsp;extensionMgr.onMessage(&quot;Finished!&quot;);
<br />
};
<br />
<br />
<a target="_blank"
href="https://github.com/benweet/stackedit/blob/master/doc/developer-guide.md#architecture">More
info</a>

View File

@ -0,0 +1,12 @@
<p>Allows users to implement their own extension.</p>
<div class="form-horizontal">
<div class="control-group">
<label class="control-label" for="textarea-usercustom-code">JavaScript code
<a href="#" class="tooltip-usercustom-extension">(?)</a>
</label>
<div class="controls">
<textarea id="textarea-usercustom-code"></textarea>
</div>
</div>
</div>
<span class="help-block pull-right"><a target="_blank" href="https://github.com/benweet/stackedit/blob/master/doc/developer-guide.md#architecture">More info</a></span>

0
run_deploy Normal file → Executable file
View File