define([
"jquery",
"underscore",
"utils"
], function($, _, utils) {
var buttonStat = {
extensionId: "buttonStat",
extensionName: 'Button "Statistics"',
optional: true,
defaultConfig: {
name1: "Words",
value1: "\\S+",
name2: "Characters",
value2: "\\S",
name3: "Paragraphs",
value3: ".+",
},
settingsBloc: [
'
Adds a "Document statistics" button in the navigation bar.
',
'',
' ',
' ',
' ',
' ',
'
',
'',
' ',
' ',
' ',
' ',
'
',
'',
' ',
' ',
' ',
' ',
'
'].join("")
};
buttonStat.onLoadSettings = function() {
_.each(buttonStat.defaultConfig, function(value, key) {
utils.setInputValue("#input-stat-" + key, buttonStat.config[key]);
});
};
buttonStat.onSaveSettings = function(newConfig, event) {
_.each(buttonStat.defaultConfig, function(value, key) {
newConfig[key] = utils.getInputTextValue("#input-stat-" + key, event);
});
};
buttonStat.onCreateButton = function() {
return $([
'',
''
].join(""));
};
buttonStat.onPreviewFinished = function() {
var text = $("#wmd-preview").text();
$("#span-stat-value1").text(text.match(new RegExp(buttonStat.config.value1, "g")).length);
$("#span-stat-value2").text(text.match(new RegExp(buttonStat.config.value2, "g")).length);
$("#span-stat-value3").text(text.match(new RegExp(buttonStat.config.value3, "g")).length);
};
return buttonStat;
});