Fixed stats and toc

This commit is contained in:
benweet 2013-05-30 23:16:12 +01:00
parent 019ae6a3bf
commit 8ec72de663
10 changed files with 111 additions and 40 deletions

View File

@ -490,6 +490,14 @@ div.dropdown-menu i {
z-index: 1050 !important;
}
#modal-settings .modal-header {
padding-bottom: 0;
}
#modal-settings .form-horizontal {
margin-top: 10px;
}
#modal-settings textarea {
height: 80px;
max-width: 206px;
@ -526,19 +534,24 @@ div.dropdown-menu i {
margin: 0 10px;
}
.accordion-toggle {
cursor: help;
#modal-settings .accordion-toggle {
cursor: help;
}
#modal-settings .tab-pane-button-container {
width: 200px;
margin: 10px auto;
}
#modal-settings .nav-tabs {
border-bottom: 1px solid transparent;
margin: 20px 0 0;
}
.nav-tabs > .active > a, .nav-tabs > .active > a:hover, .nav-tabs > .active > a:focus {
color: #fff;
background-color: #777;
border-color: #777;
border-bottom-color: transparent;
}
.nav-tabs {
border-bottom-color: #eee;
}
.nav > li > a:hover,
@ -551,6 +564,11 @@ div.dropdown-menu i {
border-color: #eee;
}
.tooltip-inner {
text-align: left;
}
/* Table style */
table {
margin-bottom: 20px;
}

View File

@ -510,18 +510,18 @@
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">&times;</button>
<h3>Settings</h3>
<ul class="nav nav-tabs">
<li class="active"><a class="action-load-settings"
href="#tabpane-settings-editor" data-toggle="tab">Editor</a></li>
<li><a class="action-load-settings"
href="#tabpane-settings-publish" data-toggle="tab">Publish</a></li>
<li><a class="action-load-settings"
href="#tabpane-settings-extensions" data-toggle="tab">Extensions</a></li>
<li><a class="action-load-settings"
href="#tabpane-settings-utils" data-toggle="tab">Utils</a></li>
</ul>
</div>
<div class="modal-body">
<ul class="nav nav-tabs">
<li class="active"><a class="action-load-settings"
href="#tabpane-settings-editor" data-toggle="tab">Editor</a></li>
<li><a class="action-load-settings"
href="#tabpane-settings-publish" data-toggle="tab">Publish</a></li>
<li><a class="action-load-settings"
href="#tabpane-settings-extensions" data-toggle="tab">Extensions</a></li>
<li><a class="action-load-settings"
href="#tabpane-settings-utils" data-toggle="tab">Utils</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tabpane-settings-editor">
@ -608,7 +608,7 @@
your own extension...</a></span>
</div>
<div class="tab-pane" id="tabpane-settings-utils">
<div style="width: 200px; margin: 10px auto;">
<div class="tab-pane-button-container">
<a href="#" class="btn btn-block btn-primary action-welcome-file"
data-dismiss="modal">Welcome document</a> <a href="#"
class="btn btn-block btn-primary action-default-settings"

View File

@ -89,6 +89,7 @@ define([
addHook("onFileMgrCreated");
addHook("onSynchronizerCreated");
addHook("onPublisherCreated");
addHook("onExtensionMgrCreated");
// Operations on files
addHook("onFileCreated");
@ -177,5 +178,7 @@ define([
});
// For extensions that need to call other extensions
extensionMgr.onExtensionMgrCreated(extensionMgr);
return extensionMgr;
});

View File

@ -14,7 +14,7 @@ define([
name2: "Characters",
value2: "\\S",
name3: "Paragraphs",
value3: ".+",
value3: "\\S.*",
},
settingsBloc: [
'<p>Adds a "Document statistics" button in the navigation bar.</p>',
@ -35,18 +35,29 @@ define([
' <input id="input-stat-name3" type="text" class="input-small">',
' <label class="label-text" for="input-stat-value3">RegExp</label>',
' <input id="input-stat-value3" type="text" class="span2">',
'</div></p>'].join("")
'</div></p>'
].join("")
};
buttonStat.onLoadSettings = function() {
_.each(buttonStat.defaultConfig, function(value, key) {
utils.setInputValue("#input-stat-" + key, buttonStat.config[key]);
_.each([
1,
2,
3
], function(index) {
utils.setInputValue("#input-stat-name" + index, buttonStat.config["name" + index]);
utils.setInputValue("#input-stat-value" + index, buttonStat.config["value" + index]);
});
};
buttonStat.onSaveSettings = function(newConfig, event) {
_.each(buttonStat.defaultConfig, function(value, key) {
newConfig[key] = utils.getInputTextValue("#input-stat-" + key, event);
_.each([
1,
2,
3
], function(index) {
newConfig["name" + index] = utils.getInputTextValue("#input-stat-name" + index, event);
newConfig["value" + index] = utils.getInputRegExpValue("#input-stat-value" + index, event);
});
};
@ -67,10 +78,10 @@ define([
};
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);
var text = $("#wmd-preview").clone().find("script").remove().end().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;

View File

@ -4,7 +4,7 @@ define(function() {
extensionId: "emailConverter",
extensionName: "Email Converter",
optional: true,
settingsBloc: '<p>Converts email adresses in the form &lt;email@example.com&gt; into a clickable links.</p>'
settingsBloc: '<p>Converts email adresses in the form &lt;email@example.com&gt; into clickable links.</p>'
};
emailConverter.onEditorConfigure = function(editor) {

View File

@ -8,9 +8,30 @@ define([
extensionId: "toc",
extensionName: "Table of content",
optional: true,
settingsBloc: '<p>Generates a table of content when a [TOC] marker is found.</p>'
defaultConfig: {
marker: "\\[(TOC|toc)\\]"
},
settingsBloc: [
'<p>Generates a table of content when a [TOC] marker is found.</p>',
'<div class="form-horizontal">',
' <div class="control-group">',
' <label class="control-label" for="input-toc-marker">Marker RegExp</label>',
' <div class="controls">',
' <input type="text" id="input-toc-marker" class="span2">',
' </div>',
' </div>',
'</div>'
].join("")
};
toc.onLoadSettings = function() {
utils.setInputValue("#input-toc-marker", toc.config.marker);
};
toc.onSaveSettings = function(newConfig, event) {
newConfig.marker = utils.getInputRegExpValue("#input-toc-marker", event);
};
// TOC element description
function TocElement(tagName, anchor, text) {
this.tagName = tagName;
@ -97,9 +118,9 @@ define([
toc.onEditorConfigure = function(editor) {
// Run TOC generation when conversion is finished directly on HTML
editor.hooks.chain("onPreviewRefresh", function() {
var toc = buildToc();
var htmlToc = buildToc();
var html = $("#wmd-preview").html();
html = html.replace(/<p>\[TOC\]<\/p>/g, toc);
html = html.replace(new RegExp("<p>" + toc.config.marker + "<\\/p>", "g"), htmlToc);
$("#wmd-preview").html(html);
});
};

View File

@ -2,10 +2,11 @@ define([
"underscore",
"core",
"utils",
"settings",
"extension-manager",
"file-manager",
"google-helper"
], function(_, core, utils, extensionMgr, fileMgr, googleHelper) {
], function(_, core, utils, settings, extensionMgr, fileMgr, googleHelper) {
var PROVIDER_GDRIVE = "gdrive";
@ -250,7 +251,7 @@ define([
localStorage.removeItem(PROVIDER_GDRIVE + ".state");
state = JSON.parse(state);
if(state.action == "create") {
googleHelper.upload(undefined, state.folderId, GDRIVE_DEFAULT_FILE_TITLE, "", undefined, function(error, file) {
googleHelper.upload(undefined, state.folderId, GDRIVE_DEFAULT_FILE_TITLE, settings.defaultContent, undefined, function(error, file) {
if(error) {
return;
}

View File

@ -139,6 +139,7 @@ define([
if(response && response.id) {
// Upload success
result = response;
result.content = content;
task.chain();
return;
}

View File

@ -76,6 +76,23 @@ define([
}
return value;
};
// Return input value and check that it's a valid RegExp
utils.getInputRegExpValue = function(element, event) {
element = jqElt(element);
var value = utils.getInputTextValue(element, event);
if(value === undefined) {
return undefined;
}
try {
new RegExp(value);
}
catch(e) {
inputError(element, event);
return undefined;
}
return value;
};
// Return checkbox boolean value
utils.getInputChecked = function(element) {

View File

@ -23,7 +23,7 @@ input[readonly], select[readonly], textarea[readonly] {
background-color: #fff;
}
textarea, input, .dropdown-menu, .modal {
#wmd-input, input, .dropdown-menu, .modal {
background: #111;
color: #fff;
}
@ -176,15 +176,14 @@ input[type="color"]:focus,
box-shadow: inset 0 1px 1px rgba(255, 134, 97, 0), 0 0 8px rgba(255, 255, 255, 1) !important;
}
#modal-settings .accordion-group {
border-bottom-color: #222;
}
.nav-tabs > .active > a, .nav-tabs > .active > a:hover, .nav-tabs > .active > a:focus {
color: #fff;
background-color: #333;
border-color: #333;
border-bottom-color: transparent;
}
.nav-tabs {
border-bottom-color: #222;
}
.nav > li > a:hover,