Newer
Older
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* Created by gavorhes on 5/13/2016.
*/
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var makeGuid_1 = require("../util/makeGuid");
var provide_1 = require("../util/provide");
var nm = provide_1.default('domUtil');
var SelectBoxBase = (function () {
/**
*
* @param {jQuery} parent - parent container
* @param {string} labelContent
* @param {contentGenerator} [contentGen=undefined]
*/
function SelectBoxBase(parent, labelContent, contentGen) {
var _this = this;
var guidTop = makeGuid_1.default();
var guid = makeGuid_1.default();
var htmlString = "<div id=\"" + guidTop + "\">";
htmlString += "<label for=\"" + guid + "\">" + labelContent + "</label>";
if (contentGen) {
htmlString += contentGen(guid);
}
else {
htmlString += "<select id=\"" + guid + "\"></select>";
}
htmlString += '</div>';
parent.append(htmlString);
this._$container = parent.find('#' + guidTop);
this.$label = this._$container.find('label');
/**
*
* @type {Array<selectChangeCallback>}
* @private
*/
this._changeListeners = [];
this._box = parent.find("#" + guid);
if (!this._box) {
throw 'the select box was not found';
}
this._box.change(function () {
_this.changed();
});
}
Object.defineProperty(SelectBoxBase.prototype, "box", {
/**
*
* @returns {jQuery}
*/
get: function () {
return this._box;
},
enumerable: true,
configurable: true
});
SelectBoxBase.prototype.changed = function () {
var v = this._box.val();
for (var _i = 0, _a = this._changeListeners; _i < _a.length; _i++) {
var f = _a[_i];
f(v);
}
};
/**
*
* @param {selectChangeCallback} func
*/
SelectBoxBase.prototype.addChangeListener = function (func) {
this._changeListeners.push(func);
};
Object.defineProperty(SelectBoxBase.prototype, "selectedValue", {
get: function () {
var theVal = this.box.val();
if (theVal == null || typeof theVal == 'undefined') {
return null;
}
else if (isNaN(theVal)) {
return theVal;
}
else {
if (theVal.indexOf('.') > -1) {
return parseFloat(theVal);
}
else {
return parseInt(theVal);
}
}
},
/**
*
* @param {string|number} v
*/
set: function (v) {
this.box.val(v);
},
enumerable: true,
configurable: true
});
Object.defineProperty(SelectBoxBase.prototype, "selectedIndex", {
get: function () {
return this._box[0].selectedIndex;
},
enumerable: true,
configurable: true
});
Object.defineProperty(SelectBoxBase.prototype, "selectedText", {
get: function () {
return this.box.find('option:selected').text();
},
enumerable: true,
configurable: true
});
return SelectBoxBase;
}());
exports.SelectBoxBase = SelectBoxBase;
nm.SelectBoxBase = SelectBoxBase;
exports.default = SelectBoxBase;
//# sourceMappingURL=SelectBoxBase.js.map