|
1 | 1 | // GRID COMMON TYPE EXTENSIONS |
2 | 2 | // ============ |
3 | 3 |
|
4 | | -$.fn.extend({ |
5 | | - _bgAria: function (name, value) |
6 | | - { |
7 | | - return (value) ? this.attr("aria-" + name, value) : this.attr("aria-" + name); |
| 4 | +$.fn.extend( |
| 5 | + { |
| 6 | + _bgAria : function(name, value) { |
| 7 | + return (value) ? this.attr("aria-" + name, value) : this.attr("aria-" + name); |
8 | 8 | }, |
9 | | - |
10 | | - _bgBusyAria: function(busy) |
11 | | - { |
12 | | - return (busy == null || busy) ? |
13 | | - this._bgAria("busy", "true") : |
14 | | - this._bgAria("busy", "false"); |
| 9 | + |
| 10 | + _bgBusyAria : function(busy) { |
| 11 | + return (busy == null || busy) ? |
| 12 | + this._bgAria("busy", "true") : |
| 13 | + this._bgAria("busy", "false"); |
15 | 14 | }, |
16 | | - |
17 | | - _bgRemoveAria: function (name) |
18 | | - { |
19 | | - return this.removeAttr("aria-" + name); |
| 15 | + |
| 16 | + _bgRemoveAria : function(name) { |
| 17 | + return this.removeAttr("aria-" + name); |
20 | 18 | }, |
21 | | - |
22 | | - _bgEnableAria: function (enable) |
23 | | - { |
24 | | - return (enable == null || enable) ? |
25 | | - this.removeClass("disabled")._bgAria("disabled", "false") : |
26 | | - this.addClass("disabled")._bgAria("disabled", "true"); |
| 19 | + |
| 20 | + _bgEnableAria : function(enable) { |
| 21 | + return (enable == null || enable) ? |
| 22 | + this.removeClass("disabled")._bgAria("disabled", "false") : |
| 23 | + this.addClass("disabled")._bgAria("disabled", "true"); |
27 | 24 | }, |
28 | | - |
29 | | - _bgEnableField: function (enable) |
30 | | - { |
31 | | - return (enable == null || enable) ? |
32 | | - this.removeAttr("disabled") : |
33 | | - this.attr("disabled", "disable"); |
| 25 | + |
| 26 | + _bgEnableField : function(enable) { |
| 27 | + return (enable == null || enable) ? |
| 28 | + this.removeAttr("disabled") : |
| 29 | + this.attr("disabled", "disable"); |
34 | 30 | }, |
35 | | - |
36 | | - _bgShowAria: function (show) |
37 | | - { |
38 | | - return (show == null || show) ? |
39 | | - this.show()._bgAria("hidden", "false") : |
40 | | - this.hide()._bgAria("hidden", "true"); |
| 31 | + |
| 32 | + _bgShowAria : function(show) { |
| 33 | + return (show == null || show) ? |
| 34 | + this.show()._bgAria("hidden", "false") : |
| 35 | + this.hide()._bgAria("hidden", "true"); |
41 | 36 | }, |
42 | | - |
43 | | - _bgSelectAria: function (select) |
44 | | - { |
45 | | - return (select == null || select) ? |
46 | | - this.addClass("active")._bgAria("selected", "true") : |
47 | | - this.removeClass("active")._bgAria("selected", "false"); |
| 37 | + |
| 38 | + _bgSelectAria : function(select) { |
| 39 | + return (select == null || select) ? |
| 40 | + this.addClass("active")._bgAria("selected", "true") : |
| 41 | + this.removeClass("active")._bgAria("selected", "false"); |
48 | 42 | }, |
49 | | - |
50 | | - _bgId: function (id) |
51 | | - { |
52 | | - return (id) ? this.attr("id", id) : this.attr("id"); |
| 43 | + |
| 44 | + _bgId : function(id) { |
| 45 | + return (id) ? this.attr("id", id) : this.attr("id"); |
53 | 46 | } |
54 | | -}); |
55 | | - |
56 | | -if (!String.prototype.resolve) |
57 | | -{ |
58 | | - var formatter = { |
59 | | - "checked": function(value) |
60 | | - { |
61 | | - if (typeof value === "boolean") |
62 | | - { |
63 | | - return (value) ? "checked=\"checked\"" : ""; |
64 | | - } |
65 | | - return value; |
| 47 | + } |
| 48 | +); |
| 49 | + |
| 50 | +if (!String.prototype.resolve) { |
| 51 | + var formatter = { |
| 52 | + "checked" : function(value) { |
| 53 | + if (typeof value === "boolean") { |
| 54 | + return (value) ? "checked=\"checked\"" : ""; |
| 55 | + } |
| 56 | + return value; |
| 57 | + } |
| 58 | + }; |
| 59 | + |
| 60 | + var _templateCache = {}; |
| 61 | + var getTemplate = function(template) { |
| 62 | + if (!_templateCache.hasOwnProperty(template)) { |
| 63 | + var str = template.split(/{([^{}]+)}/g); |
| 64 | + |
| 65 | + for (var i = 0; i < str.length; i++) { |
| 66 | + var s = str[ i ]; |
| 67 | + var hasStart = (s.charAt(0) === "}"); |
| 68 | + var hasEnd = (s.charAt(s.length - 1) === "{"); |
| 69 | + if (hasStart) { |
| 70 | + s = s.substr(1); |
66 | 71 | } |
67 | | - }; |
68 | | - |
69 | | - var _templateCache = {}; |
70 | | - var getTemplate = function(template){ |
71 | | - if (!_templateCache.hasOwnProperty(template)){ |
72 | | - var str = template.split(/{([^{}]+)}/g); |
73 | | - |
74 | | - for (var i = 0; i < str.length; i++){ |
75 | | - var s = str[i]; |
76 | | - var hasStart = (s.charAt(0) === "}"); |
77 | | - var hasEnd = (s.charAt(s.length - 1) === "{"); |
78 | | - if (hasStart) |
79 | | - { |
80 | | - s = s.substr(1); |
81 | | - } |
82 | | - if (hasEnd) |
83 | | - { |
84 | | - s = s.substr(0, s.length - 1); |
85 | | - } |
86 | | - |
87 | | - if (hasStart || hasEnd) |
88 | | - { |
89 | | - str[i] = s; //plain old html |
90 | | - } else { |
91 | | - str[i] = { |
92 | | - token: str[i], |
93 | | - key: s.split(".") |
94 | | - }; |
95 | | - } |
96 | | - } |
97 | | - _templateCache[template] = str; |
| 72 | + if (hasEnd) { |
| 73 | + s = s.substr(0, s.length - 1); |
98 | 74 | } |
99 | | - return _templateCache[template]; |
100 | | - }; |
101 | | - |
102 | | - String.prototype.resolve = function (substitutes, prefixes) |
103 | | - { |
104 | | - var str = getTemplate(this); |
105 | | - var result = ""; |
106 | | - for (var i = 0; i < str.length; i++){ |
107 | | - if (typeof str[i] === "object"){ |
108 | | - var key = str[i].key; |
109 | | - var v = ""; |
110 | | - // now we have a variable to be substitued |
111 | | - if (substitutes.hasOwnProperty(key[0])) |
112 | | - { |
113 | | - v = substitutes[key[0]]; |
114 | | - } |
115 | | - else |
116 | | - { |
117 | | - continue; |
118 | | - } |
119 | | - |
120 | | - for (var k = 1; k < key.length; k++){ |
121 | | - if (v.hasOwnProperty(key[k])){ |
122 | | - v = v[key[k]]; |
123 | | - } else { |
124 | | - v = null; |
125 | | - break; |
126 | | - } |
127 | | - } |
128 | | - var formatter_key = key[key.length-1]; |
129 | | - if (formatter && formatter[formatter_key] && typeof formatter[formatter_key] === "function"){ |
130 | | - result += formatter[formatter_key](v); |
131 | | - } else { |
132 | | - result += v; |
133 | | - } |
134 | | - } else { |
135 | | - result += str[i]; // plain old html |
136 | | - } |
| 75 | + |
| 76 | + if (hasStart || hasEnd) { |
| 77 | + str[ i ] = s; //plain old html |
| 78 | + } else { |
| 79 | + str[ i ] = { |
| 80 | + token : str[ i ], |
| 81 | + key : s.split(".") |
| 82 | + }; |
| 83 | + } |
| 84 | + } |
| 85 | + _templateCache[ template ] = str; |
| 86 | + } |
| 87 | + return _templateCache[ template ]; |
| 88 | + }; |
| 89 | + |
| 90 | + String.prototype.resolve = function(substitutes, prefixes) { |
| 91 | + var str = getTemplate(this); |
| 92 | + var result = ""; |
| 93 | + for (var i = 0; i < str.length; i++) { |
| 94 | + if (typeof str[ i ] === "object") { |
| 95 | + var key = str[ i ].key; |
| 96 | + var v = ""; |
| 97 | + // now we have a variable to be substitued |
| 98 | + if (substitutes.hasOwnProperty(key[ 0 ])) { |
| 99 | + v = substitutes[ key[ 0 ] ]; |
137 | 100 | } |
138 | | - return result; |
139 | | - }; |
| 101 | + else { |
| 102 | + continue; |
| 103 | + } |
| 104 | + |
| 105 | + for (var k = 1; k < key.length; k++) { |
| 106 | + if (v.hasOwnProperty(key[ k ])) { |
| 107 | + v = v[ key[ k ] ]; |
| 108 | + } else { |
| 109 | + v = null; |
| 110 | + break; |
| 111 | + } |
| 112 | + } |
| 113 | + var formatter_key = key[ key.length - 1 ]; |
| 114 | + if (formatter && formatter[ formatter_key ] && typeof formatter[ formatter_key ] === "function") { |
| 115 | + result += formatter[ formatter_key ](v); |
| 116 | + } else { |
| 117 | + result += v; |
| 118 | + } |
| 119 | + } else { |
| 120 | + result += str[ i ]; // plain old html |
| 121 | + } |
| 122 | + } |
| 123 | + return result; |
| 124 | + }; |
140 | 125 | } |
141 | 126 |
|
142 | | -if (!Array.prototype.first) |
143 | | -{ |
144 | | - Array.prototype.first = function (condition) |
145 | | - { |
146 | | - for (var i = 0; i < this.length; i++) |
147 | | - { |
148 | | - var item = this[i]; |
149 | | - if (condition(item)) |
150 | | - { |
151 | | - return item; |
152 | | - } |
153 | | - } |
154 | | - return null; |
155 | | - }; |
| 127 | +if (!Array.prototype.first) { |
| 128 | + Array.prototype.first = function(condition) { |
| 129 | + for (var i = 0; i < this.length; i++) { |
| 130 | + var item = this[ i ]; |
| 131 | + if (condition(item)) { |
| 132 | + return item; |
| 133 | + } |
| 134 | + } |
| 135 | + return null; |
| 136 | + }; |
156 | 137 | } |
157 | 138 |
|
158 | | -if (!Array.prototype.contains) |
159 | | -{ |
160 | | - Array.prototype.contains = function (condition) |
161 | | - { |
162 | | - for (var i = 0; i < this.length; i++) |
163 | | - { |
164 | | - var item = this[i]; |
165 | | - if (condition(item)) |
166 | | - { |
167 | | - return true; |
168 | | - } |
169 | | - } |
170 | | - return false; |
171 | | - }; |
| 139 | +if (!Array.prototype.contains) { |
| 140 | + Array.prototype.contains = function(condition) { |
| 141 | + for (var i = 0; i < this.length; i++) { |
| 142 | + var item = this[ i ]; |
| 143 | + if (condition(item)) { |
| 144 | + return true; |
| 145 | + } |
| 146 | + } |
| 147 | + return false; |
| 148 | + }; |
172 | 149 | } |
173 | 150 |
|
174 | | -if (!Array.prototype.page) |
175 | | -{ |
176 | | - Array.prototype.page = function (page, size) |
177 | | - { |
178 | | - var skip = (page - 1) * size, |
179 | | - end = skip + size; |
180 | | - return (this.length > skip) ? |
181 | | - (this.length > end) ? this.slice(skip, end) : |
182 | | - this.slice(skip) : []; |
183 | | - }; |
| 151 | +if (!Array.prototype.page) { |
| 152 | + Array.prototype.page = function(page, size) { |
| 153 | + var skip = (page - 1) * size, |
| 154 | + end = skip + size; |
| 155 | + return (this.length > skip) ? |
| 156 | + (this.length > end) ? this.slice(skip, end) : |
| 157 | + this.slice(skip) : []; |
| 158 | + }; |
184 | 159 | } |
185 | 160 |
|
186 | | -if (!Array.prototype.where) |
187 | | -{ |
188 | | - Array.prototype.where = function (condition) |
189 | | - { |
190 | | - var result = []; |
191 | | - for (var i = 0; i < this.length; i++) |
192 | | - { |
193 | | - var item = this[i]; |
194 | | - if (condition(item)) |
195 | | - { |
196 | | - result.push(item); |
197 | | - } |
198 | | - } |
199 | | - return result; |
200 | | - }; |
| 161 | +if (!Array.prototype.where) { |
| 162 | + Array.prototype.where = function(condition) { |
| 163 | + var result = []; |
| 164 | + for (var i = 0; i < this.length; i++) { |
| 165 | + var item = this[ i ]; |
| 166 | + if (condition(item)) { |
| 167 | + result.push(item); |
| 168 | + } |
| 169 | + } |
| 170 | + return result; |
| 171 | + }; |
201 | 172 | } |
202 | 173 |
|
203 | | -if (!Array.prototype.propValues) |
204 | | -{ |
205 | | - Array.prototype.propValues = function (propName) |
206 | | - { |
207 | | - var result = []; |
208 | | - for (var i = 0; i < this.length; i++) |
209 | | - { |
210 | | - result.push(this[i][propName]); |
211 | | - } |
212 | | - return result; |
213 | | - }; |
| 174 | +if (!Array.prototype.propValues) { |
| 175 | + Array.prototype.propValues = function(propName) { |
| 176 | + var result = []; |
| 177 | + for (var i = 0; i < this.length; i++) { |
| 178 | + result.push(this[ i ][ propName ]); |
| 179 | + } |
| 180 | + return result; |
| 181 | + }; |
214 | 182 | } |
0 commit comments