Stackedit/public/res/extensions/buttonHtmlCode.js

78 lines
2.8 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",
2014-08-08 18:51:22 +00:00
"text!html/buttonHtmlCodeSettingsBlock.html"
2013-06-22 23:48:57 +00:00
], function($, _, utils, Extension, buttonHtmlCodeHTML, buttonHtmlCodeSettingsBlockHTML) {
2013-06-19 20:33:46 +00:00
2014-10-12 17:57:58 +00:00
var buttonHtmlCode = new Extension("buttonHtmlCode", 'Button "HTML code"', true);
2013-06-22 23:48:57 +00:00
buttonHtmlCode.settingsBlock = buttonHtmlCodeSettingsBlockHTML;
buttonHtmlCode.defaultConfig = {
2014-08-08 18:51:22 +00:00
template: "<%= documentHTML %>"
2013-06-22 23:48:57 +00:00
};
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() {
2014-04-08 23:20:48 +00:00
setTimeout(function() {
2013-06-19 20:33:46 +00:00
$("#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-04-08 23:20:48 +00:00
}, 10);
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,
documentHTMLWithFrontMatter: (selectedFileDesc.frontMatter ? selectedFileDesc.frontMatter._frontMatter : '') + htmlWithoutComments,
2014-03-30 01:44:51 +00:00
documentHTMLWithComments: htmlWithComments,
frontMatter: selectedFileDesc.frontMatter,
2014-08-08 18:51:22 +00:00
publishAttributes: undefined
2014-03-30 01:44:51 +00:00
});
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
});