Stackedit/public/res/extensions/buttonHtmlCode.js

77 lines
2.7 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 %>",
};
2014-03-30 01:44:51 +00:00
2013-06-22 23:48:57 +00:00
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;
};
2014-03-30 01:44:51 +00:00
var htmlWithComments, htmlWithoutComments;
buttonHtmlCode.onPreviewFinished = function(htmlWithCommentsParam, htmlWithoutCommentsParam) {
htmlWithComments = htmlWithCommentsParam;
htmlWithoutComments = htmlWithoutCommentsParam;
2013-06-19 20:33:46 +00:00
};
buttonHtmlCode.onReady = function() {
2014-03-30 01:44:51 +00:00
var 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
});
});
2014-03-30 01:44:51 +00:00
}).parent().on('show.bs.dropdown', function() {
try {
var htmlCode = _.template(buttonHtmlCode.config.template, {
documentTitle: selectedFileDesc.title,
documentMarkdown: selectedFileDesc.content,
strippedDocumentMarkdown: selectedFileDesc.content.substring(selectedFileDesc.frontMatter ? selectedFileDesc.frontMatter._frontMatter.length : 0),
documentHTML: htmlWithoutComments,
documentHTMLWithComments: htmlWithComments,
frontMatter: selectedFileDesc.frontMatter,
publishAttributes: undefined,
});
textareaElt.value = htmlCode;
}
catch(e) {
eventMgr.onError(e);
}
2013-06-19 20:33:46 +00:00
});
};
return buttonHtmlCode;
2014-03-30 01:44:51 +00:00
});