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);
|
|
|
|
};
|
|
|
|
|
|
|
|
buttonHtmlCode.onSaveSettings = function(newConfig, event) {
|
|
|
|
newConfig.template = utils.getInputValue("#textarea-html-code-template");
|
2013-06-19 20:33:46 +00:00
|
|
|
};
|
|
|
|
|
2013-07-30 08:46:36 +00:00
|
|
|
var eventMgr = undefined;
|
|
|
|
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-06-22 23:48:57 +00:00
|
|
|
var selectedFileDesc = undefined;
|
|
|
|
buttonHtmlCode.onFileSelected = function(fileDesc) {
|
|
|
|
selectedFileDesc = fileDesc;
|
|
|
|
};
|
|
|
|
|
2013-07-28 17:14:42 +00:00
|
|
|
var textareaElt = undefined;
|
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,
|
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() {
|
|
|
|
if($(this).is(":hidden"))
|
|
|
|
return;
|
2013-08-22 00:19:59 +00:00
|
|
|
this.select();
|
2013-06-19 20:33:46 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return buttonHtmlCode;
|
|
|
|
|
|
|
|
});
|