Normalizing how select and button commands are triggered.
parent
e1961d4353
commit
0c52fb5e30
|
@ -93,15 +93,12 @@ Button.load = function (btnName) {
|
||||||
_.extend(Button.prototype, {
|
_.extend(Button.prototype, {
|
||||||
grouping: "",
|
grouping: "",
|
||||||
|
|
||||||
li: function (attributes, contents) {
|
|
||||||
attributes = _.extend({
|
|
||||||
"data-key": this.attributes.key,
|
|
||||||
}, attributes);
|
|
||||||
return tag("li", attributes, contents);
|
|
||||||
},
|
|
||||||
|
|
||||||
render: function () {
|
render: function () {
|
||||||
return this.li({},
|
var liAttributes = {
|
||||||
|
"data-type": "button",
|
||||||
|
"data-key": this.attributes.key,
|
||||||
|
};
|
||||||
|
return tag("li", liAttributes,
|
||||||
tag("a", { "class": this.grouping, "data-l10n-id": this.attributes.localizationId },
|
tag("a", { "class": this.grouping, "data-l10n-id": this.attributes.localizationId },
|
||||||
tag("span", { "class": "buttonicon " + this.attributes.icon })
|
tag("span", { "class": "buttonicon " + this.attributes.icon })
|
||||||
)
|
)
|
||||||
|
@ -137,8 +134,14 @@ _.extend(SelectButton.prototype, Button.prototype, {
|
||||||
});
|
});
|
||||||
return tag("select", attributes, options.join(""));
|
return tag("select", attributes, options.join(""));
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function () {
|
render: function () {
|
||||||
return this.li({ id: this.attributes.id },
|
var attributes = {
|
||||||
|
id: this.attributes.id,
|
||||||
|
"data-key": "",
|
||||||
|
"data-type": "select"
|
||||||
|
};
|
||||||
|
return this.li(attributes,
|
||||||
this.select({ id: this.attributes.selectId })
|
this.select({ id: this.attributes.selectId })
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,53 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var hooks = require('./pluginfw/hooks');
|
||||||
var padutils = require('./pad_utils').padutils;
|
var padutils = require('./pad_utils').padutils;
|
||||||
var padeditor = require('./pad_editor').padeditor;
|
var padeditor = require('./pad_editor').padeditor;
|
||||||
var padsavedrevs = require('./pad_savedrevs');
|
var padsavedrevs = require('./pad_savedrevs');
|
||||||
|
|
||||||
|
var ToolbarItem = function (element) {
|
||||||
|
this.$el = element;
|
||||||
|
};
|
||||||
|
|
||||||
|
ToolbarItem.prototype.getCommand = function () {
|
||||||
|
return this.$el.attr("data-key");
|
||||||
|
};
|
||||||
|
|
||||||
|
ToolbarItem.prototype.getValue = function () {
|
||||||
|
if (this.isSelect()) {
|
||||||
|
return this.$el.find("select").val();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ToolbarItem.prototype.getType = function () {
|
||||||
|
return this.$el.attr("data-type");
|
||||||
|
};
|
||||||
|
|
||||||
|
ToolbarItem.prototype.isSelect = function () {
|
||||||
|
return this.getType() == "select";
|
||||||
|
};
|
||||||
|
|
||||||
|
ToolbarItem.prototype.isButton = function () {
|
||||||
|
return this.getType() == "button";
|
||||||
|
};
|
||||||
|
|
||||||
|
ToolbarItem.prototype.bind = function (callback) {
|
||||||
|
var self = this;
|
||||||
|
if (self.isButton()) {
|
||||||
|
self.$el.click(function (event) {
|
||||||
|
callback(self.getCommand());
|
||||||
|
event.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (self.isSelect()) {
|
||||||
|
self.$el.find("select").change(function () {
|
||||||
|
callback(self.getCommand(), self.getValue());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
var padeditbar = (function()
|
var padeditbar = (function()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -90,12 +133,18 @@ var padeditbar = (function()
|
||||||
var self = this;
|
var self = this;
|
||||||
$("#editbar .editbarbutton").attr("unselectable", "on"); // for IE
|
$("#editbar .editbarbutton").attr("unselectable", "on"); // for IE
|
||||||
$("#editbar").removeClass("disabledtoolbar").addClass("enabledtoolbar");
|
$("#editbar").removeClass("disabledtoolbar").addClass("enabledtoolbar");
|
||||||
$("#editbar [data-key]").each(function (i, e) {
|
$("#editbar [data-key]").each(function () {
|
||||||
$(e).click(function (event) {
|
(new ToolbarItem($(this))).bind(function (command, value) {
|
||||||
self.toolbarClick($(e).attr('data-key'));
|
self.triggerCommand(command, value);
|
||||||
event.preventDefault();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
registerDefaultCommands(self);
|
||||||
|
|
||||||
|
hooks.callAll("postToolbarInit", {
|
||||||
|
toolbar: self,
|
||||||
|
ace: padeditor.ace
|
||||||
|
});
|
||||||
},
|
},
|
||||||
isEnabled: function()
|
isEnabled: function()
|
||||||
{
|
{
|
||||||
|
@ -124,16 +173,9 @@ var padeditbar = (function()
|
||||||
}, cmd, true);
|
}, cmd, true);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
toolbarClick: function(cmd)
|
triggerCommand: function (cmd, value) {
|
||||||
{
|
if (self.isEnabled() && this.commands[cmd]) {
|
||||||
if (self.isEnabled())
|
this.commands[cmd](cmd, padeditor.ace, value);
|
||||||
{
|
|
||||||
if (this.commands[cmd]) {
|
|
||||||
this.commands[cmd](cmd, padeditor.ace);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.log("Command doesn't exist", cmd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(padeditor.ace) padeditor.ace.focus();
|
if(padeditor.ace) padeditor.ace.focus();
|
||||||
},
|
},
|
||||||
|
@ -212,61 +254,62 @@ var padeditbar = (function()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.registerDropdownCommand("showusers", "users");
|
function aceAttributeCommand(cmd, ace) {
|
||||||
self.registerDropdownCommand("settings");
|
|
||||||
self.registerDropdownCommand("connectivity");
|
|
||||||
self.registerDropdownCommand("import_export", "importexport");
|
|
||||||
|
|
||||||
self.registerCommand("embed", function () {
|
|
||||||
self.setEmbedLinks();
|
|
||||||
$('#linkinput').focus().select();
|
|
||||||
self.toggleDropDown("embed");
|
|
||||||
});
|
|
||||||
|
|
||||||
self.registerCommand("savedRevision", function () {
|
|
||||||
padsavedrevs.saveNow();
|
|
||||||
});
|
|
||||||
|
|
||||||
self.registerCommand("showTimeSlider", function () {
|
|
||||||
document.location = document.location + "/timeslider";
|
|
||||||
});
|
|
||||||
|
|
||||||
function aceAttributeCommand (cmd, ace) {
|
|
||||||
ace.ace_toggleAttributeOnSelection(cmd);
|
ace.ace_toggleAttributeOnSelection(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.registerAceCommand("bold", aceAttributeCommand);
|
function registerDefaultCommands(toolbar) {
|
||||||
self.registerAceCommand("italic", aceAttributeCommand);
|
toolbar.registerDropdownCommand("showusers", "users");
|
||||||
self.registerAceCommand("underline", aceAttributeCommand);
|
toolbar.registerDropdownCommand("settings");
|
||||||
self.registerAceCommand("strikethrough", aceAttributeCommand);
|
toolbar.registerDropdownCommand("connectivity");
|
||||||
|
toolbar.registerDropdownCommand("import_export", "importexport");
|
||||||
|
|
||||||
self.registerAceCommand("undo", function (cmd, ace) {
|
toolbar.registerCommand("embed", function () {
|
||||||
|
toolbar.setEmbedLinks();
|
||||||
|
$('#linkinput').focus().select();
|
||||||
|
toolbar.toggleDropDown("embed");
|
||||||
|
});
|
||||||
|
|
||||||
|
toolbar.registerCommand("savedRevision", function () {
|
||||||
|
padsavedrevs.saveNow();
|
||||||
|
});
|
||||||
|
|
||||||
|
toolbar.registerCommand("showTimeSlider", function () {
|
||||||
|
document.location = document.location + "/timeslider";
|
||||||
|
});
|
||||||
|
|
||||||
|
toolbar.registerAceCommand("bold", aceAttributeCommand);
|
||||||
|
toolbar.registerAceCommand("italic", aceAttributeCommand);
|
||||||
|
toolbar.registerAceCommand("underline", aceAttributeCommand);
|
||||||
|
toolbar.registerAceCommand("strikethrough", aceAttributeCommand);
|
||||||
|
|
||||||
|
toolbar.registerAceCommand("undo", function (cmd, ace) {
|
||||||
ace.ace_doUndoRedo(cmd);
|
ace.ace_doUndoRedo(cmd);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.registerAceCommand("redo", function (cmd) {
|
toolbar.registerAceCommand("redo", function (cmd) {
|
||||||
ace.ace_doUndoRedo(cmd);
|
ace.ace_doUndoRedo(cmd);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.registerAceCommand("insertunorderedlist", function (cmd, ace) {
|
toolbar.registerAceCommand("insertunorderedlist", function (cmd, ace) {
|
||||||
ace.ace_doInsertUnorderedList();
|
ace.ace_doInsertUnorderedList();
|
||||||
});
|
});
|
||||||
|
|
||||||
self.registerAceCommand("insertorderedlist", function (cmd, ace) {
|
toolbar.registerAceCommand("insertorderedlist", function (cmd, ace) {
|
||||||
ace.ace_doInsertOrderedList();
|
ace.ace_doInsertOrderedList();
|
||||||
});
|
});
|
||||||
|
|
||||||
self.registerAceCommand("indent", function (cmd, ace) {
|
toolbar.registerAceCommand("indent", function (cmd, ace) {
|
||||||
if (!ace.ace_doIndentOutdent(false)) {
|
if (!ace.ace_doIndentOutdent(false)) {
|
||||||
ace.ace_doInsertUnorderedList();
|
ace.ace_doInsertUnorderedList();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.registerAceCommand("outdent", function (cmd, ace) {
|
toolbar.registerAceCommand("outdent", function (cmd, ace) {
|
||||||
ace.ace_doIndentOutdent(true);
|
ace.ace_doIndentOutdent(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.registerAceCommand("clearauthorship", function (cmd, ace) {
|
toolbar.registerAceCommand("clearauthorship", function (cmd, ace) {
|
||||||
if ((!(ace.ace_getRep().selStart && ace.ace_getRep().selEnd)) || ace.ace_isCaret()) {
|
if ((!(ace.ace_getRep().selStart && ace.ace_getRep().selEnd)) || ace.ace_isCaret()) {
|
||||||
if (window.confirm(html10n.get("pad.editbar.clearcolors"))) {
|
if (window.confirm(html10n.get("pad.editbar.clearcolors"))) {
|
||||||
ace.ace_performDocumentApplyAttributesToCharRange(0, ace.ace_getRep().alltext.length, [
|
ace.ace_performDocumentApplyAttributesToCharRange(0, ace.ace_getRep().alltext.length, [
|
||||||
|
@ -278,6 +321,7 @@ var padeditbar = (function()
|
||||||
ace.ace_setAttributeOnSelection('author', '');
|
ace.ace_setAttributeOnSelection('author', '');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}());
|
}());
|
||||||
|
|
Loading…
Reference in New Issue