Stackedit/js/extensions/buttonHtmlCode.js

62 lines
1.9 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-06-22 23:48:57 +00:00
var buttonHtmlCode = new Extension("buttonHtmlCode", 'Button "HTML code"', true);
buttonHtmlCode.settingsBlock = buttonHtmlCodeSettingsBlockHTML;
buttonHtmlCode.defaultConfig = {
template: "<%= documentHTML %>",
};
buttonHtmlCode.onLoadSettings = function() {
utils.setInputValue("#textarea-html-code-template", buttonHtmlCode.config.template);
};
buttonHtmlCode.onSaveSettings = function(newConfig, event) {
newConfig.template = utils.getInputValue("#textarea-html-code-template");
2013-06-19 20:33:46 +00:00
};
buttonHtmlCode.onCreatePreviewButton = function() {
return $(buttonHtmlCodeHTML);
};
2013-06-22 23:48:57 +00:00
var selectedFileDesc = undefined;
buttonHtmlCode.onFileSelected = function(fileDesc) {
selectedFileDesc = fileDesc;
};
2013-06-19 20:33:46 +00:00
buttonHtmlCode.onPreviewFinished = function() {
2013-06-22 23:48:57 +00:00
try {
var htmlCode = _.template(buttonHtmlCode.config.template, {
documentTitle: selectedFileDesc.title,
documentMarkdown: selectedFileDesc.content,
documentHTML: $("#wmd-preview").html()
});
$("#input-html-code").val(htmlCode);
}
catch(e) {
extensionMgr.onError(e);
return e.message;
}
2013-06-19 20:33:46 +00:00
};
buttonHtmlCode.onReady = function() {
$(".action-html-code").click(function() {
_.defer(function() {
$("#input-html-code").each(function() {
if($(this).is(":hidden"))
return;
$(this).get(0).select();
});
});
});
};
return buttonHtmlCode;
});