Stackedit/public/res/extensions/buttonHtmlCode.js

73 lines
2.3 KiB
JavaScript
Raw Normal View History

2013-06-19 20:33:46 +00:00
define([
"jquery",
2013-06-22 23:48:57 +00:00
"underscore",
"utils",
"classes/Extension",
2013-06-19 20:33:46 +00:00
"text!html/buttonHtmlCode.html",
2013-06-22 23:48:57 +00:00
"text!html/buttonHtmlCodeSettingsBlock.html",
], function($, _, utils, Extension, buttonHtmlCodeHTML, buttonHtmlCodeSettingsBlockHTML) {
2013-06-19 20:33:46 +00:00
2013-07-29 00:03:19 +00:00
var buttonHtmlCode = new Extension("buttonHtmlCode", 'Button "HTML code"', true, true);
2013-06-22 23:48:57 +00:00
buttonHtmlCode.settingsBlock = buttonHtmlCodeSettingsBlockHTML;
buttonHtmlCode.defaultConfig = {
template: "<%= documentHTML %>",
};
buttonHtmlCode.onLoadSettings = function() {
utils.setInputValue("#textarea-html-code-template", buttonHtmlCode.config.template);
};
2013-11-07 23:10:38 +00:00
buttonHtmlCode.onSaveSettings = function(newConfig) {
2013-06-22 23:48:57 +00:00
newConfig.template = utils.getInputValue("#textarea-html-code-template");
2013-06-19 20:33:46 +00:00
};
2013-11-07 23:10:38 +00:00
var eventMgr;
2013-07-30 08:46:36 +00:00
buttonHtmlCode.onEventMgrCreated = function(eventMgrParameter) {
eventMgr = eventMgrParameter;
2013-07-29 00:03:19 +00:00
};
2013-06-19 20:33:46 +00:00
buttonHtmlCode.onCreatePreviewButton = function() {
2013-08-08 22:29:49 +00:00
return buttonHtmlCodeHTML;
2013-06-19 20:33:46 +00:00
};
2013-11-07 23:10:38 +00:00
var selectedFileDesc;
2013-06-22 23:48:57 +00:00
buttonHtmlCode.onFileSelected = function(fileDesc) {
selectedFileDesc = fileDesc;
};
2013-11-07 23:10:38 +00:00
var textareaElt;
2013-07-24 23:20:56 +00:00
buttonHtmlCode.onPreviewFinished = function(html) {
2013-06-22 23:48:57 +00:00
try {
var htmlCode = _.template(buttonHtmlCode.config.template, {
documentTitle: selectedFileDesc.title,
documentMarkdown: selectedFileDesc.content,
strippedDocumentMarkdown: selectedFileDesc.content.substring(selectedFileDesc.frontMatter ? selectedFileDesc.frontMatter._frontMatter.length : 0),
2013-10-06 14:34:40 +00:00
documentHTML: html,
frontMatter: selectedFileDesc.frontMatter,
publishAttributes: undefined,
2013-06-22 23:48:57 +00:00
});
2013-07-28 17:14:42 +00:00
textareaElt.value = htmlCode;
2013-06-22 23:48:57 +00:00
}
catch(e) {
2013-07-30 08:46:36 +00:00
eventMgr.onError(e);
2013-06-22 23:48:57 +00:00
return e.message;
}
2013-06-19 20:33:46 +00:00
};
buttonHtmlCode.onReady = function() {
2013-07-28 17:14:42 +00:00
textareaElt = document.getElementById('input-html-code');
2013-06-19 20:33:46 +00:00
$(".action-html-code").click(function() {
_.defer(function() {
$("#input-html-code").each(function() {
2013-11-07 23:10:38 +00:00
if($(this).is(":hidden")) {
2013-06-19 20:33:46 +00:00
return;
2013-11-07 23:10:38 +00:00
}
2013-08-22 00:19:59 +00:00
this.select();
2013-06-19 20:33:46 +00:00
});
});
});
};
return buttonHtmlCode;
});