From c57bc444cde7d634dd17e6d83c492f05f890ef10 Mon Sep 17 00:00:00 2001 From: cohitre Date: Sun, 3 Mar 2013 15:53:17 -0800 Subject: [PATCH 01/11] basic toolbar setup --- src/node/utils/toolbar.js | 122 ++++++++++++++++++++++++++++++++++++++ src/templates/pad.html | 86 +++++++-------------------- 2 files changed, 145 insertions(+), 63 deletions(-) create mode 100644 src/node/utils/toolbar.js diff --git a/src/node/utils/toolbar.js b/src/node/utils/toolbar.js new file mode 100644 index 00000000..1bfcda01 --- /dev/null +++ b/src/node/utils/toolbar.js @@ -0,0 +1,122 @@ +/** + * The Toolbar Module creates and renders the toolbars and buttons + */ + +var _ = require("underscore") + , defaultButtons + , Button + , ButtonsGroup + , Separator + , defaultButtonAttributes + , buttonTemplate; + +buttonTemplate = _.template( + '
  • ' +); + +defaultButtonAttributes = function (name, overrides) { + return { + id: name, + key: name, + localizationId: "pad.toolbar." + name + ".title", + icon: "buttonicon-" + name + }; +}; + +defaultButtons = { + bold: defaultButtonAttributes("bold"), + italic: defaultButtonAttributes("italic"), + underline: defaultButtonAttributes("underline"), + strikethrough: defaultButtonAttributes("strikethrough"), + + orderedlist: { + id: "orderedlist", + key: "insertorderedlist", + localizationId: "pad.toolbar.ol.title", + icon: "buttonicon-insertorderedlist" + }, + + unorderedlist: { + id: "unorderedlist", + key: "insertunorderedlist", + localizationId: "pad.toolbar.ul.title", + icon: "buttonicon-insertunorderedlist" + }, + + indent: defaultButtonAttributes("indent"), + outdent: { + id: "outdent", + key: "outdent", + localizationId: "pad.toolbar.unindent.title", + icon: "buttonicon-outdent" + }, + + undo: defaultButtonAttributes("undo"), + redo: defaultButtonAttributes("redo"), + + clearauthorship: { + id: "clearAuthorship", + key: "clearauthorship", + localizationId: "pad.toolbar.clearAuthorship.title", + icon: "buttonicon-clearauthorship" + } + +}; + +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; +}; + +Button.prototype.grouping = ""; +Button.prototype.render = function () { + return buttonTemplate(this); +}; + +Separator = function () {}; +Separator.prototype.render = function () { + return '
  • '; +}; + +module.exports = { + menu: function (buttons) { + var groups = _.map(buttons, function (group) { + return ButtonsGroup.fromArray(group).render(); + }); + return groups.join(new Separator().render()); + } +}; diff --git a/src/templates/pad.html b/src/templates/pad.html index 76df5133..bde1c7ee 100644 --- a/src/templates/pad.html +++ b/src/templates/pad.html @@ -1,6 +1,22 @@ <% var settings = require("ep_etherpad-lite/node/utils/Settings") , langs = require("ep_etherpad-lite/node/hooks/i18n").availableLangs + , 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"] + ]; + } %> <% e.begin_block("htmlHead"); %> @@ -54,66 +70,10 @@
    +