From 602380abb7e99febfaf9f574da32ae3cc5064458 Mon Sep 17 00:00:00 2001 From: cohitre Date: Mon, 15 Apr 2013 16:06:32 -0700 Subject: [PATCH] passing the ToolbarItem to the callback --- src/node/utils/toolbar.js | 4 ++-- src/static/js/pad_editbar.js | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/node/utils/toolbar.js b/src/node/utils/toolbar.js index 966e81a0d..a0a4fe013 100644 --- a/src/node/utils/toolbar.js +++ b/src/node/utils/toolbar.js @@ -138,10 +138,10 @@ _.extend(SelectButton.prototype, Button.prototype, { render: function () { var attributes = { id: this.attributes.id, - "data-key": "", + "data-key": this.attributes.command, "data-type": "select" }; - return this.li(attributes, + return tag("li", attributes, this.select({ id: this.attributes.selectId }) ); } diff --git a/src/static/js/pad_editbar.js b/src/static/js/pad_editbar.js index afd0ad06c..f4fda27c5 100644 --- a/src/static/js/pad_editbar.js +++ b/src/static/js/pad_editbar.js @@ -39,6 +39,13 @@ ToolbarItem.prototype.getValue = function () { } }; +ToolbarItem.prototype.setValue = function (val) { + if (this.isSelect()) { + return this.$el.find("select").val(val); + } +}; + + ToolbarItem.prototype.getType = function () { return this.$el.attr("data-type"); }; @@ -53,15 +60,16 @@ ToolbarItem.prototype.isButton = function () { ToolbarItem.prototype.bind = function (callback) { var self = this; + if (self.isButton()) { self.$el.click(function (event) { - callback(self.getCommand()); + callback(self.getCommand(), self); event.preventDefault(); }); } else if (self.isSelect()) { self.$el.find("select").change(function () { - callback(self.getCommand(), self.getValue()); + callback(self.getCommand(), self); }); } }; @@ -134,8 +142,8 @@ var padeditbar = (function() $("#editbar .editbarbutton").attr("unselectable", "on"); // for IE $("#editbar").removeClass("disabledtoolbar").addClass("enabledtoolbar"); $("#editbar [data-key]").each(function () { - (new ToolbarItem($(this))).bind(function (command, value) { - self.triggerCommand(command, value); + (new ToolbarItem($(this))).bind(function (command, item) { + self.triggerCommand(command, item); }); }); @@ -173,9 +181,9 @@ var padeditbar = (function() }, cmd, true); }); }, - triggerCommand: function (cmd, value) { + triggerCommand: function (cmd, item) { if (self.isEnabled() && this.commands[cmd]) { - this.commands[cmd](cmd, padeditor.ace, value); + this.commands[cmd](cmd, padeditor.ace, item); } if(padeditor.ace) padeditor.ace.focus(); },