|
1 | | -/*! Select.js v0.2.3 | (c) Bunoon | MIT License */ |
| 1 | +/*! Select.js v0.3.0 | (c) Bunoon | MIT License */ |
2 | 2 | (function() { |
3 | 3 | function render() { |
4 | 4 | var tagTypes = _configuration.domElementTypes; |
|
87 | 87 | showDropDownMenu(control, dropDown, element, bindingOptions); |
88 | 88 | }; |
89 | 89 | } |
90 | | - return {control:control, dropDown:dropDown, select:element, bindingOptions:bindingOptions, multiSelectEnabled:element.hasAttribute("multiple")}; |
| 90 | + var controlElements = {control:control, dropDown:dropDown, select:element, bindingOptions:bindingOptions, multiSelectEnabled:element.hasAttribute("multiple")}; |
| 91 | + _control_Elements.push(controlElements); |
| 92 | + return controlElements; |
91 | 93 | } |
92 | 94 | function renderControlButton(controlElements) { |
93 | 95 | if (controlElements.bindingOptions.showDropDownButton) { |
|
195 | 197 | controlElements.dropDown.style.display = "block"; |
196 | 198 | renderDropDownItems(controlElements); |
197 | 199 | renderSelectedItems(controlElements, false); |
| 200 | + fireCustomTrigger(controlElements.bindingOptions.onDropDownShow); |
198 | 201 | }, controlElements.bindingOptions.dropDownShowDelay); |
199 | 202 | } else { |
200 | 203 | hideDropDownMenu(controlElements); |
|
204 | 207 | if (controlElements.dropDown !== null && controlElements.dropDown.style.display !== "none") { |
205 | 208 | controlElements.dropDown.style.display = "none"; |
206 | 209 | renderSelectedItems(controlElements, false); |
| 210 | + fireCustomTrigger(controlElements.bindingOptions.onDropDownHide); |
207 | 211 | } |
208 | 212 | } |
209 | 213 | function isDropDownMenuVisible(controlElements) { |
|
238 | 242 | function buildAttributeOptionCustomTriggers(options) { |
239 | 243 | options.onRenderComplete = getDefaultFunction(options.onRenderComplete, null); |
240 | 244 | options.onSelectedItemsChanged = getDefaultFunction(options.onSelectedItemsChanged, null); |
| 245 | + options.onDropDownShow = getDefaultFunction(options.onDropDownShow, null); |
| 246 | + options.onDropDownHide = getDefaultFunction(options.onDropDownHide, null); |
241 | 247 | return options; |
242 | 248 | } |
| 249 | + function buildGlobalDocumentEvents(addEvents) { |
| 250 | + addEvents = isDefined(addEvents) ? addEvents : true; |
| 251 | + var documentFunc = addEvents ? _parameter_Document.addEventListener : _parameter_Document.removeEventListener; |
| 252 | + documentFunc("keydown", onWindowKeyDown); |
| 253 | + } |
| 254 | + function onWindowKeyDown(e) { |
| 255 | + if (e.keyCode === _enum_KeyCodes.escape) { |
| 256 | + e.preventDefault(); |
| 257 | + hideDropDownMenus(); |
| 258 | + } |
| 259 | + } |
| 260 | + function hideDropDownMenus() { |
| 261 | + var controlElementsLength = _control_Elements.length; |
| 262 | + var controlElementIndex = 0; |
| 263 | + for (; controlElementIndex < controlElementsLength; controlElementIndex++) { |
| 264 | + hideDropDownMenu(_control_Elements[controlElementIndex]); |
| 265 | + } |
| 266 | + } |
243 | 267 | function isDefined(value) { |
244 | 268 | return value !== null && value !== undefined && value !== _string.empty; |
245 | 269 | } |
|
341 | 365 | var _parameter_Document = null; |
342 | 366 | var _parameter_Window = null; |
343 | 367 | var _configuration = {}; |
| 368 | + var _enum_KeyCodes = {escape:27}; |
344 | 369 | var _string = {empty:"", space:" "}; |
345 | 370 | var _elements_Type = {}; |
| 371 | + var _control_Elements = []; |
346 | 372 | var _attribute_Name_Options = "data-select-options"; |
347 | 373 | this.setConfiguration = function(newOptions) { |
348 | 374 | _configuration = !isDefinedObject(newOptions) ? {} : newOptions; |
349 | 375 | buildDefaultConfiguration(); |
350 | 376 | return this; |
351 | 377 | }; |
352 | 378 | this.getVersion = function() { |
353 | | - return "0.2.3"; |
| 379 | + return "0.3.0"; |
354 | 380 | }; |
355 | 381 | (function(documentObject, windowObject) { |
356 | 382 | _parameter_Document = documentObject; |
357 | 383 | _parameter_Window = windowObject; |
358 | 384 | buildDefaultConfiguration(); |
359 | 385 | _parameter_Document.addEventListener("DOMContentLoaded", function() { |
360 | 386 | render(); |
| 387 | + buildGlobalDocumentEvents(); |
361 | 388 | }); |
362 | 389 | if (!isDefined(_parameter_Window.$select)) { |
363 | 390 | _parameter_Window.$select = this; |
|
0 commit comments