Custom buttons

This commit is contained in:
bartbutenaers 2021-02-21 22:55:19 +01:00 committed by GitHub
parent fbb7dd4c3f
commit 60c8a2c598
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 5 deletions

View File

@ -67,24 +67,53 @@
this.topContainer.addClass(this.options.class);
}
var buttons = this.options.buttons || [];
if (this.options.addButton !== false) {
var addLabel;
var addLabel, addTittle;
if (typeof this.options.addButton === 'string') {
addLabel = this.options.addButton
} else {
if (RED && RED._) {
addLabel = RED._("editableList.add");
addTitle = RED._("editableList.addTitle");
} else {
addLabel = 'add';
addTitle = 'add new item';
}
}
$('<a href="#" class="red-ui-button red-ui-button-small red-ui-editableList-addButton" style="margin-top: 4px;"><i class="fa fa-plus"></i> '+addLabel+'</a>')
.appendTo(this.topContainer)
buttons.unshift({
label: addLabel,
icon: "fa fa-plus",
click: function(evt) {
that.addItem({});
},
title: addTitle
});
}
buttons.forEach(function(button) {
var innerHtml = "";
var titleAttribute="";
if (button.icon) {
innerHtml = '<i class="'+button.icon+'"></i> ';
}
if (button.label) {
innerHtml += button.label;
}
if (button.title) {
titleAttribute = 'title="'+button.title+'"';
}
$('<a href="#" class="red-ui-button red-ui-button-small red-ui-editableList-addButton" style="margin-top: 4px; margin-right: 5px;" '+titleAttribute+'>'+innerHtml+'</a>')
.appendTo(that.topContainer)
.on("click", function(evt) {
evt.preventDefault();
that.addItem({});
if (button.click !== undefined) {
button.click();
}
});
}
});
if (this.element.css("position") === "absolute") {
["top","left","bottom","right"].forEach(function(s) {
var v = that.element.css(s);