diff --git a/src/node/utils/Settings.js b/src/node/utils/Settings.js index 45f81aa5f..9990fea44 100644 --- a/src/node/utils/Settings.js +++ b/src/node/utils/Settings.js @@ -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 */ @@ -48,7 +48,7 @@ exports.faviconTimeslider = "../../" + exports.favicon; * The IP ep-lite should listen to */ exports.ip = "0.0.0.0"; - + /** * The Port ep-lite should listen to */ @@ -79,6 +79,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"; +/** + * 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 */ @@ -185,7 +202,7 @@ exports.reloadSettings = function reloadSettings() { console.warn("Unknown Setting: '" + i + "'. This setting doesn't exist or it was removed"); } } - + log4js.configure(exports.logconfig);//Configure the logging appenders log4js.setGlobalLogLevel(exports.loglevel);//set loglevel log4js.replaceConsole(); diff --git a/src/node/utils/toolbar.js b/src/node/utils/toolbar.js new file mode 100644 index 000000000..5bff6bb8b --- /dev/null +++ b/src/node/utils/toolbar.js @@ -0,0 +1,171 @@ +/** + * The Toolbar Module creates and renders the toolbars and buttons + */ + +var _ = require("underscore") + , tagAttributes + , tag + , defaultButtons + , Button + , ButtonsGroup + , Separator + , defaultButtonAttributes; + +defaultButtonAttributes = function (name, overrides) { + return { + key: name, + localizationId: "pad.toolbar." + name + ".title", + icon: "buttonicon-" + name + }; +}; + +tag = function (name, attributes, contents) { + var aStr = tagAttributes(attributes); + + if (contents) { + return '<' + name + aStr + '>' + contents + ''; + } + 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 = { + bold: defaultButtonAttributes("bold"), + italic: defaultButtonAttributes("italic"), + underline: defaultButtonAttributes("underline"), + strikethrough: defaultButtonAttributes("strikethrough"), + + orderedlist: { + key: "insertorderedlist", + localizationId: "pad.toolbar.ol.title", + icon: "buttonicon-insertorderedlist" + }, + + unorderedlist: { + key: "insertunorderedlist", + localizationId: "pad.toolbar.ul.title", + icon: "buttonicon-insertunorderedlist" + }, + + indent: defaultButtonAttributes("indent"), + outdent: { + key: "outdent", + localizationId: "pad.toolbar.unindent.title", + icon: "buttonicon-outdent" + }, + + undo: defaultButtonAttributes("undo"), + redo: defaultButtonAttributes("redo"), + + clearauthorship: { + key: "clearauthorship", + localizationId: "pad.toolbar.clearAuthorship.title", + 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 () { + this.buttons = []; +}; + +ButtonsGroup.fromArray = function (array) { + var btnGroup = new ButtonsGroup(); + _.each(array, function (btnName) { + var b = new Button(defaultButtons[btnName]); + btnGroup.addButton(b); + }); + return btnGroup; +}; + +ButtonsGroup.prototype.addButton = function (button) { + this.buttons.push(button); + return this; +}; + +ButtonsGroup.prototype.render = function () { + if (this.buttons.length == 1) { + this.buttons[0].grouping = ""; + } + else { + _.first(this.buttons).grouping = "grouped-left"; + _.last(this.buttons).grouping = "grouped-right"; + _.each(this.buttons.slice(1, -1), function (btn) { + btn.grouping = "grouped-middle" + }); + } + + return _.map(this.buttons, function (btn) { + return btn.render(); + }).join("\n"); +}; + +Button = function (attributes) { + this.attributes = attributes; + + +}; + +_.extend(Button.prototype, { + grouping: "", + + 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.prototype.render = function () { + return tag("li", { "class": "separator"}); +}; + +module.exports = { + separator: function () { + return (new Separator).render(); + }, + menu: function (buttons) { + var groups = _.map(buttons, function (group) { + return ButtonsGroup.fromArray(group).render(); + }); + return groups.join(this.separator()); + } +}; diff --git a/src/static/js/pad_editbar.js b/src/static/js/pad_editbar.js index cc9f8758c..25fc0011f 100644 --- a/src/static/js/pad_editbar.js +++ b/src/static/js/pad_editbar.js @@ -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. * TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED */ @@ -117,7 +117,7 @@ var padeditbar = (function() $("#editbar").addClass('disabledtoolbar').removeClass("enabledtoolbar"); }, toolbarClick: function(cmd) - { + { if (self.isEnabled()) { if(cmd == "showusers") @@ -186,7 +186,7 @@ var padeditbar = (function() toggleDropDown: function(moduleName, cb) { var modules = ["settings", "connectivity", "importexport", "embed", "users"]; - + // hide all modules and remove highlighting of all buttons if(moduleName == "none") { @@ -196,9 +196,9 @@ var padeditbar = (function() //skip the userlist if(modules[i] == "users") continue; - + var module = $("#" + modules[i]); - + if(module.css('display') != "none") { $("#" + modules[i] + "link").removeClass("selected"); @@ -208,14 +208,14 @@ var padeditbar = (function() } if(!returned && cb) return cb(); } - else + else { // hide all modules that are not selected and remove highlighting // respectively add highlighting to the corresponding button for(var i=0;i <% e.begin_block("htmlHead"); %> @@ -54,103 +55,15 @@
+ @@ -293,7 +206,7 @@ <% e.end_block(); %> - +