forked from cite-sa/es2-service-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect-panel.js
67 lines (63 loc) · 2.8 KB
/
select-panel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
$(function () {
$.widget("panel.selectPanel", $.dock.panel, {
options: {
panelType: "select",
buttonId: undefined,
buttonContent: undefined
},
_create: function () {
this._super();
this.panelBody
.append(
$("<div>", {class: "dropdown selector"})
.append(
$("<button>", {
id: this.options.buttonId,
class: "btn btn-default dropdown-toggle selector-btn",
type: "button",
"data-toggle": "dropdown",
"aria-haspopup": "true",
"aria-expanded": "false"
}).append($("<span>", {class: "selector-btn-wrapper"})
.append(
$("<span>", {class: "selector-btn-content"}).append(this.options.buttonContent))
.append(
$("<span>", {class: "glyphicon glyphicon-chevron-down"})
)
)
).append(
$("<ul>", {class: "dropdown-menu", "aria-labelledby": "buttonId"})
.append($("<div>", {class: "triangle"}))
)
).appendTo(this.dock);
/*if (options != undefined && options.isArray()) {
var optionsContainer = select.find(".dropdown-menu");
$.each(options, function (index, option) {
$("<li>").append(
$("<a>", {href: "#" + option.id})
.append(option.content)
).appendTo($(button.siblings(".dropdown-menu")));
});
}*/
return this;
},
addSelectOption: function (optionId, optionContent, callback) {
var self = this;
$("<li>").append(
$("<a>", {href: "#" + optionId})
.append(optionContent)
.click(function() {
var buttonContent = self.panelBody.find(".selector-btn-content");
buttonContent.empty();
buttonContent.append($(this).text());
if (callback != undefined) {
callback($(this));
}
})).appendTo(this.panelBody.find(".dropdown-menu"));
return this;
},
setButtonContent: function(content) {
this.panelBody.find(".selector-btn-content").append(content);
}
})
});