Setting up the right toolbar.

This commit is contained in:
cohitre 2013-03-09 14:57:42 -08:00
parent c57bc444cd
commit 292a3bd7b7
4 changed files with 97 additions and 78 deletions

View File

@ -1,5 +1,5 @@
/** /**
* The Settings Modul reads the settings out of settings.json and provides * The Settings Modul reads the settings out of settings.json and provides
* this information to the other modules * this information to the other modules
*/ */
@ -46,7 +46,7 @@ exports.faviconTimeslider = "../../" + exports.favicon;
* The IP ep-lite should listen to * The IP ep-lite should listen to
*/ */
exports.ip = "0.0.0.0"; exports.ip = "0.0.0.0";
/** /**
* The Port ep-lite should listen to * The Port ep-lite should listen to
*/ */
@ -77,6 +77,23 @@ exports.dbSettings = { "filename" : path.join(exports.root, "dirty.db") };
*/ */
exports.defaultPadText = "Welcome to Etherpad Lite!\n\nThis pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!\n\nEtherpad Lite on Github: http:\/\/j.mp/ep-lite\n"; exports.defaultPadText = "Welcome to Etherpad Lite!\n\nThis pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!\n\nEtherpad Lite on Github: http:\/\/j.mp/ep-lite\n";
/**
* The toolbar buttons and order.
*/
exports.toolbar = {
left: [
["bold", "italic", "underline", "strikethrough"],
["orderedlist", "unorderedlist", "indent", "outdent"],
["undo", "redo"],
["clearauthorship"]
],
right: [
["importexport", "timeslider", "savedrevision"],
["settings", "embed"],
["showusers"]
]
}
/** /**
* A flag that requires any user to have a valid session (via the api) before accessing a pad * A flag that requires any user to have a valid session (via the api) before accessing a pad
*/ */
@ -179,7 +196,7 @@ exports.reloadSettings = function reloadSettings() {
console.warn("Unknown Setting: '" + i + "'. This setting doesn't exist or it was removed"); console.warn("Unknown Setting: '" + i + "'. This setting doesn't exist or it was removed");
} }
} }
log4js.configure(exports.logconfig);//Configure the logging appenders log4js.configure(exports.logconfig);//Configure the logging appenders
log4js.setGlobalLogLevel(exports.loglevel);//set loglevel log4js.setGlobalLogLevel(exports.loglevel);//set loglevel
log4js.replaceConsole(); log4js.replaceConsole();

View File

@ -3,26 +3,47 @@
*/ */
var _ = require("underscore") var _ = require("underscore")
, tagAttributes
, tag
, defaultButtons , defaultButtons
, Button , Button
, ButtonsGroup , ButtonsGroup
, Separator , Separator
, defaultButtonAttributes , defaultButtonAttributes;
, buttonTemplate;
buttonTemplate = _.template(
'<li class="acl-write" id="<%= attributes.id %>" data-key="<%= attributes.key %>"><a class="<%= grouping %>" data-l10n-id="<%= attributes.localizationId %>"><span class="buttonicon <%= attributes.icon %>"></span></a></li>'
);
defaultButtonAttributes = function (name, overrides) { defaultButtonAttributes = function (name, overrides) {
return { return {
id: name,
key: name, key: name,
localizationId: "pad.toolbar." + name + ".title", localizationId: "pad.toolbar." + name + ".title",
icon: "buttonicon-" + name icon: "buttonicon-" + name
}; };
}; };
tag = function (name, attributes, contents) {
var aStr = tagAttributes(attributes);
if (contents) {
return '<' + name + aStr + '>' + contents + '</' + name + '>';
}
else {
return '<' + name + aStr + '/>';
}
};
tagAttributes = function (attributes) {
attributes = attributes || {};
attributes = _.reduce(attributes, function (o, val, name) {
if (!_.isUndefined(val)) {
o[name] = val;
}
return o;
}, {});
return " " + _.map(attributes, function (val, name) {
return "" + name + '="' + _.escape(val) + '"';
}, " ");
};
defaultButtons = { defaultButtons = {
bold: defaultButtonAttributes("bold"), bold: defaultButtonAttributes("bold"),
italic: defaultButtonAttributes("italic"), italic: defaultButtonAttributes("italic"),
@ -30,14 +51,12 @@ defaultButtons = {
strikethrough: defaultButtonAttributes("strikethrough"), strikethrough: defaultButtonAttributes("strikethrough"),
orderedlist: { orderedlist: {
id: "orderedlist",
key: "insertorderedlist", key: "insertorderedlist",
localizationId: "pad.toolbar.ol.title", localizationId: "pad.toolbar.ol.title",
icon: "buttonicon-insertorderedlist" icon: "buttonicon-insertorderedlist"
}, },
unorderedlist: { unorderedlist: {
id: "unorderedlist",
key: "insertunorderedlist", key: "insertunorderedlist",
localizationId: "pad.toolbar.ul.title", localizationId: "pad.toolbar.ul.title",
icon: "buttonicon-insertunorderedlist" icon: "buttonicon-insertunorderedlist"
@ -45,7 +64,6 @@ defaultButtons = {
indent: defaultButtonAttributes("indent"), indent: defaultButtonAttributes("indent"),
outdent: { outdent: {
id: "outdent",
key: "outdent", key: "outdent",
localizationId: "pad.toolbar.unindent.title", localizationId: "pad.toolbar.unindent.title",
icon: "buttonicon-outdent" icon: "buttonicon-outdent"
@ -55,12 +73,27 @@ defaultButtons = {
redo: defaultButtonAttributes("redo"), redo: defaultButtonAttributes("redo"),
clearauthorship: { clearauthorship: {
id: "clearAuthorship",
key: "clearauthorship", key: "clearauthorship",
localizationId: "pad.toolbar.clearAuthorship.title", localizationId: "pad.toolbar.clearAuthorship.title",
icon: "buttonicon-clearauthorship" icon: "buttonicon-clearauthorship"
} },
importexport: {
key: "import_export",
localizationId: "pad.toolbar.import_export.title",
icon: "buttonicon-import_export"
},
timeslider: {
onclick: "document.location = document.location.pathname + '/timeslider'",
localizationId: "pad.toolbar.timeslider.title",
icon: "buttonicon-history"
},
savedrevision: defaultButtonAttributes("savedRevision"),
settings: defaultButtonAttributes("settings"),
embed: defaultButtonAttributes("embed"),
showusers: defaultButtonAttributes("showusers")
}; };
ButtonsGroup = function () { ButtonsGroup = function () {
@ -100,23 +133,39 @@ ButtonsGroup.prototype.render = function () {
Button = function (attributes) { Button = function (attributes) {
this.attributes = attributes; this.attributes = attributes;
}; };
Button.prototype.grouping = ""; _.extend(Button.prototype, {
Button.prototype.render = function () { grouping: "",
return buttonTemplate(this);
}; render: function () {
var liAttributes = {
"data-key": this.attributes.key,
"onclick": this.attributes.onclick
};
return tag("li", liAttributes,
tag("a", { "class": this.grouping, "data-l10n-id": this.attributes.localizationId },
tag("span", { "class": "buttonicon " + this.attributes.icon })
)
);
}
});
Separator = function () {}; Separator = function () {};
Separator.prototype.render = function () { Separator.prototype.render = function () {
return '<li class="acl-write separator"></li>'; return tag("li", { "class": "separator"});
}; };
module.exports = { module.exports = {
separator: function () {
return (new Separator).render();
},
menu: function (buttons) { menu: function (buttons) {
var groups = _.map(buttons, function (group) { var groups = _.map(buttons, function (group) {
return ButtonsGroup.fromArray(group).render(); return ButtonsGroup.fromArray(group).render();
}); });
return groups.join(new Separator().render()); return groups.join(this.separator());
} }
}; };

View File

@ -1,5 +1,5 @@
/** /**
* This code is mostly from the old Etherpad. Please help us to comment this code. * This code is mostly from the old Etherpad. Please help us to comment this code.
* This helps other people to understand this code better and helps them to improve it. * This helps other people to understand this code better and helps them to improve it.
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED * TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
*/ */
@ -117,7 +117,7 @@ var padeditbar = (function()
$("#editbar").addClass('disabledtoolbar').removeClass("enabledtoolbar"); $("#editbar").addClass('disabledtoolbar').removeClass("enabledtoolbar");
}, },
toolbarClick: function(cmd) toolbarClick: function(cmd)
{ {
if (self.isEnabled()) if (self.isEnabled())
{ {
if(cmd == "showusers") if(cmd == "showusers")
@ -189,7 +189,7 @@ var padeditbar = (function()
toggleDropDown: function(moduleName, cb) toggleDropDown: function(moduleName, cb)
{ {
var modules = ["settings", "connectivity", "importexport", "embed", "users"]; var modules = ["settings", "connectivity", "importexport", "embed", "users"];
// hide all modules and remove highlighting of all buttons // hide all modules and remove highlighting of all buttons
if(moduleName == "none") if(moduleName == "none")
{ {
@ -199,9 +199,9 @@ var padeditbar = (function()
//skip the userlist //skip the userlist
if(modules[i] == "users") if(modules[i] == "users")
continue; continue;
var module = $("#" + modules[i]); var module = $("#" + modules[i]);
if(module.css('display') != "none") if(module.css('display') != "none")
{ {
$("#" + modules[i] + "link").removeClass("selected"); $("#" + modules[i] + "link").removeClass("selected");
@ -211,14 +211,14 @@ var padeditbar = (function()
} }
if(!returned && cb) return cb(); if(!returned && cb) return cb();
} }
else else
{ {
// hide all modules that are not selected and remove highlighting // hide all modules that are not selected and remove highlighting
// respectively add highlighting to the corresponding button // respectively add highlighting to the corresponding button
for(var i=0;i<modules.length;i++) for(var i=0;i<modules.length;i++)
{ {
var module = $("#" + modules[i]); var module = $("#" + modules[i]);
if(module.css('display') != "none") if(module.css('display') != "none")
{ {
$("#" + modules[i] + "link").removeClass("selected"); $("#" + modules[i] + "link").removeClass("selected");

View File

@ -1,22 +1,7 @@
<% <%
var settings = require("ep_etherpad-lite/node/utils/Settings") var settings = require("ep_etherpad-lite/node/utils/Settings")
, langs = require("ep_etherpad-lite/node/hooks/i18n").availableLangs , langs = require("ep_etherpad-lite/node/hooks/i18n").availableLangs
, toolbar = require("ep_etherpad-lite/node/utils/toolbar") , toolbar = require("ep_etherpad-lite/node/utils/toolbar");
, leftToolbar
, rightToolbar;
if (settings.ep_toolbar && settings.ep_toolbar.left) {
leftToolbar = settings.ep_toolbar.left;
}
else {
leftToolbar = [
["bold", "italic", "underline", "strikethrough"],
["orderedlist", "unorderedlist", "indent", "outdent"],
["undo", "redo"],
["clearauthorship"]
];
}
%> %>
<!doctype html> <!doctype html>
<% e.begin_block("htmlHead"); %> <% e.begin_block("htmlHead"); %>
@ -73,44 +58,12 @@
<ul class="menu_left"> <ul class="menu_left">
<% e.begin_block("editbarMenuLeft"); %> <% e.begin_block("editbarMenuLeft"); %>
<%- toolbar.menu(leftToolbar) %> <%- toolbar.menu(settings.toolbar.left) %>
<% e.end_block(); %> <% e.end_block(); %>
</ul> </ul>
<ul class="menu_right"> <ul class="menu_right">
<% e.begin_block("editbarMenuRight"); %> <% e.begin_block("editbarMenuRight"); %>
<li data-key="import_export"> <%- toolbar.menu(settings.toolbar.right) %>
<a class="grouped-left" id="importexportlink" data-l10n-id="pad.toolbar.import_export.title">
<span class="buttonicon buttonicon-import_export"></span>
</a>
</li>
<li onClick="document.location = document.location.pathname+ '/timeslider'">
<a id="timesliderlink" class="grouped-middle" data-l10n-id="pad.toolbar.timeslider.title">
<span class="buttonicon buttonicon-history"></span>
</a>
</li>
<li class="acl-write" data-key="savedRevision">
<a class="grouped-right" id="revisionlink" data-l10n-id="pad.toolbar.savedRevision.title">
<span class="buttonicon buttonicon-savedRevision"></span>
</a>
</li>
<li class="acl-write separator"></li>
<li class="acl-write" data-key="settings">
<a class="grouped-left" id="settingslink" data-l10n-id="pad.toolbar.settings.title">
<span class="buttonicon buttonicon-settings"></span>
</a>
</li>
<li data-key="embed">
<a class="grouped-right" id="embedlink" data-l10n-id="pad.toolbar.embed.title">
<span class="grouped-right buttonicon buttonicon-embed"></span>
</a>
</li>
<li class="separator"></li>
<li id="usericon" data-key="showusers">
<a data-l10n-id="pad.toolbar.showusers.title">
<span class="buttonicon buttonicon-showusers"></span>
<span id="online_count">1</span>
</a>
</li>
<% e.end_block(); %> <% e.end_block(); %>
</ul> </ul>
</div> </div>