selectBoxIt 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +52 -0
  6. data/Rakefile +2 -0
  7. data/app/assets/javascripts/selectBoxIt/jquery.selectBoxIt.js +3259 -0
  8. data/app/assets/javascripts/selectBoxIt/modules/jquery.selectBoxIt.add.js +183 -0
  9. data/app/assets/javascripts/selectBoxIt/modules/jquery.selectBoxIt.ariaAccessibility.js +117 -0
  10. data/app/assets/javascripts/selectBoxIt/modules/jquery.selectBoxIt.copyAttributes.js +63 -0
  11. data/app/assets/javascripts/selectBoxIt/modules/jquery.selectBoxIt.core.js +1802 -0
  12. data/app/assets/javascripts/selectBoxIt/modules/jquery.selectBoxIt.destroy.js +58 -0
  13. data/app/assets/javascripts/selectBoxIt/modules/jquery.selectBoxIt.disable.js +137 -0
  14. data/app/assets/javascripts/selectBoxIt/modules/jquery.selectBoxIt.dynamicPositioning.js +102 -0
  15. data/app/assets/javascripts/selectBoxIt/modules/jquery.selectBoxIt.enable.js +76 -0
  16. data/app/assets/javascripts/selectBoxIt/modules/jquery.selectBoxIt.endClosure.js +1 -0
  17. data/app/assets/javascripts/selectBoxIt/modules/jquery.selectBoxIt.keyboardNavigation.js +143 -0
  18. data/app/assets/javascripts/selectBoxIt/modules/jquery.selectBoxIt.keyboardSearch.js +209 -0
  19. data/app/assets/javascripts/selectBoxIt/modules/jquery.selectBoxIt.mobile.js +158 -0
  20. data/app/assets/javascripts/selectBoxIt/modules/jquery.selectBoxIt.remove.js +90 -0
  21. data/app/assets/javascripts/selectBoxIt/modules/jquery.selectBoxIt.selectOption.js +36 -0
  22. data/app/assets/javascripts/selectBoxIt/modules/jquery.selectBoxIt.setOption.js +33 -0
  23. data/app/assets/javascripts/selectBoxIt/modules/jquery.selectBoxIt.setOptions.js +32 -0
  24. data/app/assets/javascripts/selectBoxIt/modules/jquery.selectBoxIt.wait.js +19 -0
  25. data/app/assets/stylesheets/selectBoxIt/jquery.selectBoxIt.css +278 -0
  26. data/lib/selectBoxIt.rb +6 -0
  27. data/lib/selectBoxIt/engine.rb +4 -0
  28. data/lib/selectBoxIt/version.rb +3 -0
  29. data/selectBoxIt.gemspec +23 -0
  30. metadata +100 -0
@@ -0,0 +1,183 @@
1
+
2
+ // Add Options Module
3
+ // ==================
4
+
5
+ // add
6
+ // ---
7
+ // Adds drop down options
8
+ // using JSON data, an array,
9
+ // a single object, or valid HTML string
10
+
11
+ selectBoxIt.add = function(data, callback) {
12
+
13
+ this._populate(data, function(data) {
14
+
15
+ var self = this,
16
+ dataType = $.type(data),
17
+ value,
18
+ x = 0,
19
+ dataLength,
20
+ elems = [],
21
+ isJSON = self._isJSON(data),
22
+ parsedJSON = isJSON && self._parseJSON(data);
23
+
24
+ // If the passed data is a local or JSON array
25
+ if(data && (dataType === "array" || (isJSON && parsedJSON.data && $.type(parsedJSON.data) === "array")) || (dataType === "object" && data.data && $.type(data.data) === "array")) {
26
+
27
+ // If the data is JSON
28
+ if(self._isJSON(data)) {
29
+
30
+ // Parses the JSON and stores it in the data local variable
31
+ data = parsedJSON;
32
+
33
+ }
34
+
35
+ // If there is an inner `data` property stored in the first level of the JSON array
36
+ if(data.data) {
37
+
38
+ // Set's the data to the inner `data` property
39
+ data = data.data;
40
+
41
+ }
42
+
43
+ // Loops through the array
44
+ for(dataLength = data.length; x <= dataLength - 1; x += 1) {
45
+
46
+ // Stores the currently traversed array item in the local `value` variable
47
+ value = data[x];
48
+
49
+ // If the currently traversed array item is an object literal
50
+ if($.isPlainObject(value)) {
51
+
52
+ // Adds an option to the elems array
53
+ elems.push($("<option/>", value));
54
+
55
+ }
56
+
57
+ // If the currently traversed array item is a string
58
+ else if($.type(value) === "string") {
59
+
60
+ // Adds an option to the elems array
61
+ elems.push($("<option/>", { text: value, value: value }));
62
+
63
+ }
64
+
65
+ }
66
+
67
+ // Appends all options to the drop down (with the correct object configurations)
68
+ self.selectBox.append(elems);
69
+
70
+ }
71
+
72
+ // if the passed data is an html string and not a JSON string
73
+ else if(data && dataType === "string" && !self._isJSON(data)) {
74
+
75
+ // Appends the html string options to the original select box
76
+ self.selectBox.append(data);
77
+
78
+ }
79
+
80
+ else if(data && dataType === "object") {
81
+
82
+ // Appends an option to the original select box (with the object configurations)
83
+ self.selectBox.append($("<option/>", data));
84
+
85
+ }
86
+
87
+ else if(data && self._isJSON(data) && $.isPlainObject(self._parseJSON(data))) {
88
+
89
+ // Appends an option to the original select box (with the object configurations)
90
+ self.selectBox.append($("<option/>", self._parseJSON(data)));
91
+
92
+ }
93
+
94
+ // If the dropdown property exists
95
+ if(self.dropdown) {
96
+
97
+ // Rebuilds the dropdown
98
+ self.refresh(function() {
99
+
100
+ // Provide callback function support
101
+ self._callbackSupport(callback);
102
+
103
+ }, true);
104
+
105
+ } else {
106
+
107
+ // Provide callback function support
108
+ self._callbackSupport(callback);
109
+
110
+ }
111
+
112
+ // Maintains chainability
113
+ return self;
114
+
115
+ });
116
+
117
+ };
118
+
119
+ // parseJSON
120
+ // ---------
121
+ // Detects JSON support and parses JSON data
122
+ selectBoxIt._parseJSON = function(data) {
123
+
124
+ return (JSON && JSON.parse && JSON.parse(data)) || $.parseJSON(data);
125
+
126
+ };
127
+
128
+ // isjSON
129
+ // ------
130
+ // Determines if a string is valid JSON
131
+
132
+ selectBoxIt._isJSON = function(data) {
133
+
134
+ var self = this,
135
+ json;
136
+
137
+ try {
138
+
139
+ json = self._parseJSON(data);
140
+
141
+ // Valid JSON
142
+ return true;
143
+
144
+ } catch (e) {
145
+
146
+ // Invalid JSON
147
+ return false;
148
+
149
+ }
150
+
151
+ };
152
+
153
+ // _populate
154
+ // --------
155
+ // Handles asynchronous and synchronous data
156
+ // to populate the select box
157
+
158
+ selectBoxIt._populate = function(data, callback) {
159
+
160
+ var self = this;
161
+
162
+ data = $.isFunction(data) ? data.call() : data;
163
+
164
+ if(self.isDeferred(data)) {
165
+
166
+ data.done(function(returnedData) {
167
+
168
+ callback.call(self, returnedData);
169
+
170
+ });
171
+
172
+ }
173
+
174
+ else {
175
+
176
+ callback.call(self, data);
177
+
178
+ }
179
+
180
+ // Maintains chainability
181
+ return self;
182
+
183
+ };
@@ -0,0 +1,117 @@
1
+
2
+ // Accessibility Module
3
+ // ====================
4
+
5
+ // _ARIA Accessibility
6
+ // ------------------
7
+ // Adds ARIA (Accessible Rich Internet Applications)
8
+ // Accessibility Tags to the Select Box
9
+
10
+ selectBoxIt._ariaAccessibility = function() {
11
+
12
+ var self = this,
13
+ dropdownLabel = $("label[for='" + self.originalElem.id + "']");
14
+
15
+ // Adds `ARIA attributes` to the dropdown list
16
+ self.dropdownContainer.attr({
17
+
18
+ // W3C `combobox` description: A presentation of a select; usually similar to a textbox where users can type ahead to select an option.
19
+ "role": "combobox",
20
+
21
+ //W3C `aria-autocomplete` description: Indicates whether user input completion suggestions are provided.
22
+ "aria-autocomplete": "list",
23
+
24
+ "aria-haspopup": "true",
25
+
26
+ // W3C `aria-expanded` description: Indicates whether the element, or another grouping element it controls, is currently expanded or collapsed.
27
+ "aria-expanded": "false",
28
+
29
+ // W3C `aria-owns` description: The value of the aria-owns attribute is a space-separated list of IDREFS that reference one or more elements in the document by ID. The reason for adding aria-owns is to expose a parent/child contextual relationship to assistive technologies that is otherwise impossible to infer from the DOM.
30
+ "aria-owns": self.list[0].id
31
+
32
+ });
33
+
34
+ self.dropdownText.attr({
35
+
36
+ "aria-live": "polite"
37
+
38
+ });
39
+
40
+ // Dynamically adds `ARIA attributes` if the new dropdown list is enabled or disabled
41
+ self.dropdown.on({
42
+
43
+ //Select box custom `disable` event with the `selectBoxIt` namespace
44
+ "disable.selectBoxIt" : function() {
45
+
46
+ // W3C `aria-disabled` description: Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable.
47
+ self.dropdownContainer.attr("aria-disabled", "true");
48
+
49
+ },
50
+
51
+ // Select box custom `enable` event with the `selectBoxIt` namespace
52
+ "enable.selectBoxIt" : function() {
53
+
54
+ // W3C `aria-disabled` description: Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable.
55
+ self.dropdownContainer.attr("aria-disabled", "false");
56
+
57
+ }
58
+
59
+ });
60
+
61
+ if(dropdownLabel.length) {
62
+
63
+ // MDN `aria-labelledby` description: Indicates the IDs of the elements that are the labels for the object.
64
+ self.dropdownContainer.attr("aria-labelledby", dropdownLabel[0].id);
65
+
66
+ }
67
+
68
+ // Adds ARIA attributes to the dropdown list options list
69
+ self.list.attr({
70
+
71
+ // W3C `listbox` description: A widget that allows the user to select one or more items from a list of choices.
72
+ "role": "listbox",
73
+
74
+ // Indicates that the dropdown list options list is currently hidden
75
+ "aria-hidden": "true"
76
+
77
+ });
78
+
79
+ // Adds `ARIA attributes` to the dropdown list options
80
+ self.listItems.attr({
81
+
82
+ // This must be set for each element when the container element role is set to `listbox`
83
+ "role": "option"
84
+
85
+ });
86
+
87
+ // Dynamically updates the new dropdown list `aria-label` attribute after the original dropdown list value changes
88
+ self.selectBox.on({
89
+
90
+ // Custom `open` event with the `selectBoxIt` namespace
91
+ "open.selectBoxIt": function() {
92
+
93
+ // Indicates that the dropdown list options list is currently visible
94
+ self.list.attr("aria-hidden", "false");
95
+
96
+ // Indicates that the dropdown list is currently expanded
97
+ self.dropdownContainer.attr("aria-expanded", "true");
98
+
99
+ },
100
+
101
+ // Custom `close` event with the `selectBoxIt` namespace
102
+ "close.selectBoxIt": function() {
103
+
104
+ // Indicates that the dropdown list options list is currently hidden
105
+ self.list.attr("aria-hidden", "true");
106
+
107
+ // Indicates that the dropdown list is currently collapsed
108
+ self.dropdownContainer.attr("aria-expanded", "false");
109
+
110
+ }
111
+
112
+ });
113
+
114
+ // Maintains chainability
115
+ return self;
116
+
117
+ };
@@ -0,0 +1,63 @@
1
+
2
+ // Copy Attributes Module
3
+ // ======================
4
+
5
+ // addSelectBoxAttributes
6
+ // ----------------------
7
+ // Add's all attributes (excluding id, class names, and the style attribute) from the default select box to the new drop down
8
+
9
+ selectBoxIt._addSelectBoxAttributes = function() {
10
+
11
+ // Stores the plugin context inside of the self variable
12
+ var self = this;
13
+
14
+ // Add's all attributes to the currently traversed drop down option
15
+ self._addAttributes(self.selectBox.prop("attributes"), self.dropdown);
16
+
17
+ // Add's all attributes to the drop down items list
18
+ self.selectItems.each(function(iterator) {
19
+
20
+ // Add's all attributes to the currently traversed drop down option
21
+ self._addAttributes($(this).prop("attributes"), self.listItems.eq(iterator));
22
+
23
+ });
24
+
25
+ // Maintains chainability
26
+ return self;
27
+
28
+ };
29
+
30
+ // addAttributes
31
+ // -------------
32
+ // Add's attributes to a DOM element
33
+ selectBoxIt._addAttributes = function(arr, elem) {
34
+
35
+ // Stores the plugin context inside of the self variable
36
+ var self = this,
37
+ whitelist = self.options["copyAttributes"];
38
+
39
+ // If there are array properties
40
+ if(arr.length) {
41
+
42
+ // Iterates over all of array properties
43
+ $.each(arr, function(iterator, property) {
44
+
45
+ // Get's the property name and property value of each property
46
+ var propName = (property.name).toLowerCase(), propValue = property.value;
47
+
48
+ // If the currently traversed property value is not "null", is on the whitelist, or is an HTML 5 data attribute
49
+ if(propValue !== "null" && ($.inArray(propName, whitelist) !== -1 || propName.indexOf("data") !== -1)) {
50
+
51
+ // Set's the currently traversed property on element
52
+ elem.attr(propName, propValue);
53
+
54
+ }
55
+
56
+ });
57
+
58
+ }
59
+
60
+ // Maintains chainability
61
+ return self;
62
+
63
+ };
@@ -0,0 +1,1802 @@
1
+ /*! jquery.selectBoxIt - v3.8.1 - 2013-10-17
2
+ * http://www.selectboxit.com
3
+ * Copyright (c) 2013 Greg Franko; Licensed MIT*/
4
+
5
+ // Immediately-Invoked Function Expression (IIFE) [Ben Alman Blog Post](http://benalman.com/news/2010/11/immediately-invoked-function-expression/) that calls another IIFE that contains all of the plugin logic. I used this pattern so that anyone viewing this code would not have to scroll to the bottom of the page to view the local parameters that were passed to the main IIFE.
6
+
7
+ ;(function (selectBoxIt) {
8
+
9
+ //ECMAScript 5 Strict Mode: [John Resig Blog Post](http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/)
10
+ "use strict";
11
+
12
+ // Calls the second IIFE and locally passes in the global jQuery, window, and document objects
13
+ selectBoxIt(window.jQuery, window, document);
14
+
15
+ }
16
+
17
+ // Locally passes in `jQuery`, the `window` object, the `document` object, and an `undefined` variable. The `jQuery`, `window` and `document` objects are passed in locally, to improve performance, since javascript first searches for a variable match within the local variables set before searching the global variables set. All of the global variables are also passed in locally to be minifier friendly. `undefined` can be passed in locally, because it is not a reserved word in JavaScript.
18
+
19
+ (function ($, window, document, undefined) {
20
+
21
+ // ECMAScript 5 Strict Mode: [John Resig Blog Post](http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/)
22
+ "use strict";
23
+
24
+ // Calling the jQueryUI Widget Factory Method
25
+ $.widget("selectBox.selectBoxIt", {
26
+
27
+ // Plugin version
28
+ VERSION: "3.8.1",
29
+
30
+ // These options will be used as defaults
31
+ options: {
32
+
33
+ // **showEffect**: Accepts String: "none", "fadeIn", "show", "slideDown", or any of the jQueryUI show effects (i.e. "bounce")
34
+ "showEffect": "none",
35
+
36
+ // **showEffectOptions**: Accepts an object literal. All of the available properties are based on the jqueryUI effect options
37
+ "showEffectOptions": {},
38
+
39
+ // **showEffectSpeed**: Accepts Number (milliseconds) or String: "slow", "medium", or "fast"
40
+ "showEffectSpeed": "medium",
41
+
42
+ // **hideEffect**: Accepts String: "none", "fadeOut", "hide", "slideUp", or any of the jQueryUI hide effects (i.e. "explode")
43
+ "hideEffect": "none",
44
+
45
+ // **hideEffectOptions**: Accepts an object literal. All of the available properties are based on the jqueryUI effect options
46
+ "hideEffectOptions": {},
47
+
48
+ // **hideEffectSpeed**: Accepts Number (milliseconds) or String: "slow", "medium", or "fast"
49
+ "hideEffectSpeed": "medium",
50
+
51
+ // **showFirstOption**: Shows the first dropdown list option within the dropdown list options list
52
+ "showFirstOption": true,
53
+
54
+ // **defaultText**: Overrides the text used by the dropdown list selected option to allow a user to specify custom text. Accepts a String.
55
+ "defaultText": "",
56
+
57
+ // **defaultIcon**: Overrides the icon used by the dropdown list selected option to allow a user to specify a custom icon. Accepts a String (CSS class name(s)).
58
+ "defaultIcon": "",
59
+
60
+ // **downArrowIcon**: Overrides the default down arrow used by the dropdown list to allow a user to specify a custom image. Accepts a String (CSS class name(s)).
61
+ "downArrowIcon": "",
62
+
63
+ // **theme**: Provides theming support for Twitter Bootstrap and jQueryUI
64
+ "theme": "default",
65
+
66
+ // **keydownOpen**: Opens the dropdown if the up or down key is pressed when the dropdown is focused
67
+ "keydownOpen": true,
68
+
69
+ // **isMobile**: Function to determine if a user's browser is a mobile browser
70
+ "isMobile": function() {
71
+
72
+ // Adapted from http://www.detectmobilebrowsers.com
73
+ var ua = navigator.userAgent || navigator.vendor || window.opera;
74
+
75
+ // Checks for iOs, Android, Blackberry, Opera Mini, and Windows mobile devices
76
+ return (/iPhone|iPod|iPad|Silk|Android|BlackBerry|Opera Mini|IEMobile/).test(ua);
77
+
78
+ },
79
+
80
+ // **native**: Triggers the native select box when a user interacts with the drop down
81
+ "native": false,
82
+
83
+ // **aggressiveChange**: Will select a drop down item (and trigger a change event) when a user navigates to the item via the keyboard (up and down arrow or search), before a user selects an option with a click or the enter key
84
+ "aggressiveChange": false,
85
+
86
+ // **selectWhenHidden: Will allow a user to select an option using the keyboard when the drop down list is hidden and focused
87
+ "selectWhenHidden": true,
88
+
89
+ // **viewport**: Allows for a custom domnode used for the viewport. Accepts a selector. Default is $(window).
90
+ "viewport": $(window),
91
+
92
+ // **similarSearch**: Optimizes the search for lists with many similar values (i.e. State lists) by making it easier to navigate through
93
+ "similarSearch": false,
94
+
95
+ // **copyAttributes**: HTML attributes that will be copied over to the new drop down
96
+ "copyAttributes": [
97
+
98
+ "title",
99
+
100
+ "rel"
101
+
102
+ ],
103
+
104
+ // **copyClasses**: HTML classes that will be copied over to the new drop down. The value indicates where the classes should be copied. The default value is 'button', but you can also use 'container' (recommended) or 'none'.
105
+ "copyClasses": "button",
106
+
107
+ // **nativeMousedown**: Mimics native firefox drop down behavior by opening the drop down on mousedown and selecting the currently hovered drop down option on mouseup
108
+ "nativeMousedown": false,
109
+
110
+ // **customShowHideEvent**: Prevents the drop down from opening on click or mousedown, which allows a user to open/close the drop down with a custom event handler.
111
+ "customShowHideEvent": false,
112
+
113
+ // **autoWidth**: Makes sure the width of the drop down is wide enough to fit all of the drop down options
114
+ "autoWidth": true,
115
+
116
+ // **html**: Determines whether or not option text is rendered as html or as text
117
+ "html": true,
118
+
119
+ // **populate**: Convenience option that accepts JSON data, an array, a single object, or valid HTML string to add options to the drop down list
120
+ "populate": "",
121
+
122
+ // **dynamicPositioning**: Determines whether or not the drop down list should fit inside it's viewport
123
+ "dynamicPositioning": true,
124
+
125
+ // **hideCurrent**: Determines whether or not the currently selected drop down option is hidden in the list
126
+ "hideCurrent": false
127
+
128
+ },
129
+
130
+ // Get Themes
131
+ // ----------
132
+ // Retrieves the active drop down theme and returns the theme object
133
+ "getThemes": function() {
134
+
135
+ var self = this,
136
+ theme = $(self.element).attr("data-theme") || "c";
137
+
138
+ return {
139
+
140
+ // Twitter Bootstrap Theme
141
+ "bootstrap": {
142
+
143
+ "focus": "active",
144
+
145
+ "hover": "",
146
+
147
+ "enabled": "enabled",
148
+
149
+ "disabled": "disabled",
150
+
151
+ "arrow": "caret",
152
+
153
+ "button": "btn",
154
+
155
+ "list": "dropdown-menu",
156
+
157
+ "container": "bootstrap",
158
+
159
+ "open": "open"
160
+
161
+ },
162
+
163
+ // jQueryUI Theme
164
+ "jqueryui": {
165
+
166
+ "focus": "ui-state-focus",
167
+
168
+ "hover": "ui-state-hover",
169
+
170
+ "enabled": "ui-state-enabled",
171
+
172
+ "disabled": "ui-state-disabled",
173
+
174
+ "arrow": "ui-icon ui-icon-triangle-1-s",
175
+
176
+ "button": "ui-widget ui-state-default",
177
+
178
+ "list": "ui-widget ui-widget-content",
179
+
180
+ "container": "jqueryui",
181
+
182
+ "open": "selectboxit-open"
183
+
184
+ },
185
+
186
+ // jQuery Mobile Theme
187
+ "jquerymobile": {
188
+
189
+ "focus": "ui-btn-down-" + theme,
190
+
191
+ "hover": "ui-btn-hover-" + theme,
192
+
193
+ "enabled": "ui-enabled",
194
+
195
+ "disabled": "ui-disabled",
196
+
197
+ "arrow": "ui-icon ui-icon-arrow-d ui-icon-shadow",
198
+
199
+ "button": "ui-btn ui-btn-icon-right ui-btn-corner-all ui-shadow ui-btn-up-" + theme,
200
+
201
+ "list": "ui-btn ui-btn-icon-right ui-btn-corner-all ui-shadow ui-btn-up-" + theme,
202
+
203
+ "container": "jquerymobile",
204
+
205
+ "open": "selectboxit-open"
206
+
207
+ },
208
+
209
+ "default": {
210
+
211
+ "focus": "selectboxit-focus",
212
+
213
+ "hover": "selectboxit-hover",
214
+
215
+ "enabled": "selectboxit-enabled",
216
+
217
+ "disabled": "selectboxit-disabled",
218
+
219
+ "arrow": "selectboxit-default-arrow",
220
+
221
+ "button": "selectboxit-btn",
222
+
223
+ "list": "selectboxit-list",
224
+
225
+ "container": "selectboxit-container",
226
+
227
+ "open": "selectboxit-open"
228
+
229
+ }
230
+
231
+ };
232
+
233
+ },
234
+
235
+ // isDeferred
236
+ // ----------
237
+ // Checks if parameter is a defered object
238
+ isDeferred: function(def) {
239
+ return $.isPlainObject(def) && def.promise && def.done;
240
+ },
241
+
242
+ // _Create
243
+ // -------
244
+ // Sets the Plugin Instance variables and
245
+ // constructs the plugin. Only called once.
246
+ _create: function(internal) {
247
+
248
+ var self = this,
249
+ populateOption = self.options["populate"],
250
+ userTheme = self.options["theme"];
251
+
252
+ // If the element calling SelectBoxIt is not a select box or is not visible
253
+ if(!self.element.is("select")) {
254
+
255
+ // Exits the plugin
256
+ return;
257
+
258
+ }
259
+
260
+ // Stores a reference to the parent Widget class
261
+ self.widgetProto = $.Widget.prototype;
262
+
263
+ // The original select box DOM element
264
+ self.originalElem = self.element[0];
265
+
266
+ // The original select box DOM element wrapped in a jQuery object
267
+ self.selectBox = self.element;
268
+
269
+ if(self.options["populate"] && self.add && !internal) {
270
+
271
+ self.add(populateOption);
272
+
273
+ }
274
+
275
+ // All of the original select box options
276
+ self.selectItems = self.element.find("option");
277
+
278
+ // The first option in the original select box
279
+ self.firstSelectItem = self.selectItems.slice(0, 1);
280
+
281
+ // The html document height
282
+ self.documentHeight = $(document).height();
283
+
284
+ self.theme = $.isPlainObject(userTheme) ? $.extend({}, self.getThemes()["default"], userTheme) : self.getThemes()[userTheme] ? self.getThemes()[userTheme] : self.getThemes()["default"];
285
+
286
+ // The index of the currently selected dropdown list option
287
+ self.currentFocus = 0;
288
+
289
+ // Keeps track of which blur events will hide the dropdown list options
290
+ self.blur = true;
291
+
292
+ // Array holding all of the original select box options text
293
+ self.textArray = [];
294
+
295
+ // Maintains search order in the `search` method
296
+ self.currentIndex = 0;
297
+
298
+ // Maintains the current search text in the `search` method
299
+ self.currentText = "";
300
+
301
+ // Whether or not the dropdown list opens up or down (depending on how much room is on the page)
302
+ self.flipped = false;
303
+
304
+ // If the create method is not called internally by the plugin
305
+ if(!internal) {
306
+
307
+ // Saves the original select box `style` attribute within the `selectBoxStyles` plugin instance property
308
+ self.selectBoxStyles = self.selectBox.attr("style");
309
+
310
+ }
311
+
312
+ // Creates the dropdown elements that will become the dropdown
313
+ // Creates the ul element that will become the dropdown options list
314
+ // Add's all attributes (excluding id, class names, and unselectable properties) to the drop down and drop down items list
315
+ // Hides the original select box and adds the new plugin DOM elements to the page
316
+ // Adds event handlers to the new dropdown list
317
+ self._createDropdownButton()._createUnorderedList()._copyAttributes()._replaceSelectBox()._addClasses(self.theme)._eventHandlers();
318
+
319
+ if(self.originalElem.disabled && self.disable) {
320
+
321
+ // Disables the dropdown list if the original dropdown list had the `disabled` attribute
322
+ self.disable();
323
+
324
+ }
325
+
326
+ // If the Aria Accessibility Module has been included
327
+ if(self._ariaAccessibility) {
328
+
329
+ // Adds ARIA accessibillity tags to the dropdown list
330
+ self._ariaAccessibility();
331
+
332
+ }
333
+
334
+ self.isMobile = self.options["isMobile"]();
335
+
336
+ if(self._mobile) {
337
+
338
+ // Adds mobile support
339
+ self._mobile();
340
+
341
+ }
342
+
343
+ // If the native option is set to true
344
+ if(self.options["native"]) {
345
+
346
+ // Triggers the native select box when a user is interacting with the drop down
347
+ this._applyNativeSelect();
348
+
349
+ }
350
+
351
+ // Triggers a custom `create` event on the original dropdown list
352
+ self.triggerEvent("create");
353
+
354
+ // Maintains chainability
355
+ return self;
356
+
357
+ },
358
+
359
+ // _Create dropdown button
360
+ // -----------------------
361
+ // Creates new dropdown and dropdown elements to replace
362
+ // the original select box with a dropdown list
363
+ _createDropdownButton: function() {
364
+
365
+ var self = this,
366
+ originalElemId = self.originalElemId = self.originalElem.id || "",
367
+ originalElemValue = self.originalElemValue = self.originalElem.value || "",
368
+ originalElemName = self.originalElemName = self.originalElem.name || "",
369
+ copyClasses = self.options["copyClasses"],
370
+ selectboxClasses = self.selectBox.attr("class") || "";
371
+
372
+ // Creates a dropdown element that contains the dropdown list text value
373
+ self.dropdownText = $("<span/>", {
374
+
375
+ // Dynamically sets the dropdown `id` attribute
376
+ "id": originalElemId && originalElemId + "SelectBoxItText",
377
+
378
+ "class": "selectboxit-text",
379
+
380
+ // IE specific attribute to not allow the element to be selected
381
+ "unselectable": "on",
382
+
383
+ // Sets the dropdown `text` to equal the original select box default value
384
+ "text": self.firstSelectItem.text()
385
+
386
+ }).
387
+
388
+ // Sets the HTML5 data attribute on the dropdownText `dropdown` element
389
+ attr("data-val", originalElemValue);
390
+
391
+ self.dropdownImageContainer = $("<span/>", {
392
+
393
+ "class": "selectboxit-option-icon-container"
394
+
395
+ });
396
+
397
+ // Creates a dropdown element that contains the dropdown list text value
398
+ self.dropdownImage = $("<i/>", {
399
+
400
+ // Dynamically sets the dropdown `id` attribute
401
+ "id": originalElemId && originalElemId + "SelectBoxItDefaultIcon",
402
+
403
+ "class": "selectboxit-default-icon",
404
+
405
+ // IE specific attribute to not allow the element to be selected
406
+ "unselectable": "on"
407
+
408
+ });
409
+
410
+ // Creates a dropdown to act as the new dropdown list
411
+ self.dropdown = $("<span/>", {
412
+
413
+ // Dynamically sets the dropdown `id` attribute
414
+ "id": originalElemId && originalElemId + "SelectBoxIt",
415
+
416
+ "class": "selectboxit " + (copyClasses === "button" ? selectboxClasses: "") + " " + (self.selectBox.prop("disabled") ? self.theme["disabled"]: self.theme["enabled"]),
417
+
418
+ // Sets the dropdown `name` attribute to be the same name as the original select box
419
+ "name": originalElemName,
420
+
421
+ // Sets the dropdown `tabindex` attribute to 0 to allow the dropdown to be focusable
422
+ "tabindex": self.selectBox.attr("tabindex") || "0",
423
+
424
+ // IE specific attribute to not allow the element to be selected
425
+ "unselectable": "on"
426
+
427
+ }).
428
+
429
+ // Appends the default text to the inner dropdown list dropdown element
430
+ append(self.dropdownImageContainer.append(self.dropdownImage)).append(self.dropdownText);
431
+
432
+ // Create the dropdown container that will hold all of the dropdown list dom elements
433
+ self.dropdownContainer = $("<span/>", {
434
+
435
+ "id": originalElemId && originalElemId + "SelectBoxItContainer",
436
+
437
+ "class": 'selectboxit-container ' + self.theme.container + ' ' + (copyClasses === "container" ? selectboxClasses: "")
438
+
439
+ }).
440
+
441
+ // Appends the inner dropdown list dropdown element to the dropdown list container dropdown element
442
+ append(self.dropdown);
443
+
444
+ // Maintains chainability
445
+ return self;
446
+
447
+ },
448
+
449
+ // _Create Unordered List
450
+ // ----------------------
451
+ // Creates an unordered list element to hold the
452
+ // new dropdown list options that directly match
453
+ // the values of the original select box options
454
+ _createUnorderedList: function() {
455
+
456
+ // Storing the context of the widget
457
+ var self = this,
458
+
459
+ dataDisabled,
460
+
461
+ optgroupClass,
462
+
463
+ optgroupElement,
464
+
465
+ iconClass,
466
+
467
+ iconUrl,
468
+
469
+ iconUrlClass,
470
+
471
+ iconUrlStyle,
472
+
473
+ // Declaring the variable that will hold all of the dropdown list option elements
474
+ currentItem = "",
475
+
476
+ originalElemId = self.originalElemId || "",
477
+
478
+ // Creates an unordered list element
479
+ createdList = $("<ul/>", {
480
+
481
+ // Sets the unordered list `id` attribute
482
+ "id": originalElemId && originalElemId + "SelectBoxItOptions",
483
+
484
+ "class": "selectboxit-options",
485
+
486
+ //Sets the unordered list `tabindex` attribute to -1 to prevent the unordered list from being focusable
487
+ "tabindex": -1
488
+
489
+ }),
490
+
491
+ currentDataSelectedText,
492
+
493
+ currentDataText,
494
+
495
+ currentDataSearch,
496
+
497
+ currentText,
498
+
499
+ currentOption,
500
+
501
+ parent;
502
+
503
+ // Checks the `showFirstOption` plugin option to determine if the first dropdown list option should be shown in the options list.
504
+ if (!self.options["showFirstOption"]) {
505
+
506
+ // Disables the first select box option
507
+ self.selectItems.first().attr("disabled", "disabled");
508
+
509
+ // Excludes the first dropdown list option from the options list
510
+ self.selectItems = self.selectBox.find("option").slice(1);
511
+
512
+ }
513
+
514
+ // Loops through the original select box options list and copies the text of each
515
+ // into new list item elements of the new dropdown list
516
+ self.selectItems.each(function(index) {
517
+
518
+ currentOption = $(this);
519
+
520
+ optgroupClass = "";
521
+
522
+ optgroupElement = "";
523
+
524
+ dataDisabled = currentOption.prop("disabled");
525
+
526
+ iconClass = currentOption.attr("data-icon") || "";
527
+
528
+ iconUrl = currentOption.attr("data-iconurl") || "";
529
+
530
+ iconUrlClass = iconUrl ? "selectboxit-option-icon-url": "";
531
+
532
+ iconUrlStyle = iconUrl ? 'style="background-image:url(\'' + iconUrl + '\');"': "";
533
+
534
+ currentDataSelectedText = currentOption.attr("data-selectedtext");
535
+
536
+ currentDataText = currentOption.attr("data-text");
537
+
538
+ currentText = currentDataText ? currentDataText: currentOption.text();
539
+
540
+ parent = currentOption.parent();
541
+
542
+ // If the current option being traversed is within an optgroup
543
+
544
+ if(parent.is("optgroup")) {
545
+
546
+ optgroupClass = "selectboxit-optgroup-option";
547
+
548
+ if(currentOption.index() === 0) {
549
+
550
+ optgroupElement = '<span class="selectboxit-optgroup-header ' + parent.first().attr("class") + '"data-disabled="true">' + parent.first().attr("label") + '</span>';
551
+
552
+ }
553
+
554
+ }
555
+
556
+ currentOption.attr("value", this.value);
557
+
558
+ // Uses string concatenation for speed (applies HTML attribute encoding)
559
+ currentItem += optgroupElement + '<li data-id="' + index + '" data-val="' + this.value + '" data-disabled="' + dataDisabled + '" class="' + optgroupClass + " selectboxit-option " + ($(this).attr("class") || "") + '"><a class="selectboxit-option-anchor"><span class="selectboxit-option-icon-container"><i class="selectboxit-option-icon ' + iconClass + ' ' + (iconUrlClass || self.theme["container"]) + '"' + iconUrlStyle + '></i></span>' + (self.options["html"] ? currentText: self.htmlEscape(currentText)) + '</a></li>';
560
+
561
+ currentDataSearch = currentOption.attr("data-search");
562
+
563
+ // Stores all of the original select box options text inside of an array
564
+ // (Used later in the `searchAlgorithm` method)
565
+ self.textArray[index] = dataDisabled ? "": currentDataSearch ? currentDataSearch: currentText;
566
+
567
+ // Checks the original select box option for the `selected` attribute
568
+ if (this.selected) {
569
+
570
+ // Replaces the default text with the selected option text
571
+ self._setText(self.dropdownText, currentDataSelectedText || currentText);
572
+
573
+ //Set the currently selected option
574
+ self.currentFocus = index;
575
+
576
+ }
577
+
578
+ });
579
+
580
+ // If the `defaultText` option is being used
581
+ if ((self.options["defaultText"] || self.selectBox.attr("data-text"))) {
582
+
583
+ var defaultedText = self.options["defaultText"] || self.selectBox.attr("data-text");
584
+
585
+ // Overrides the current dropdown default text with the value the user specifies in the `defaultText` option
586
+ self._setText(self.dropdownText, defaultedText);
587
+
588
+ self.options["defaultText"] = defaultedText;
589
+
590
+ }
591
+
592
+ // Append the list item to the unordered list
593
+ createdList.append(currentItem);
594
+
595
+ // Stores the dropdown list options list inside of the `list` instance variable
596
+ self.list = createdList;
597
+
598
+ // Append the dropdown list options list to the dropdown container element
599
+ self.dropdownContainer.append(self.list);
600
+
601
+ // Stores the individual dropdown list options inside of the `listItems` instance variable
602
+ self.listItems = self.list.children("li");
603
+
604
+ self.listAnchors = self.list.find("a");
605
+
606
+ // Sets the 'selectboxit-option-first' class name on the first drop down option
607
+ self.listItems.first().addClass("selectboxit-option-first");
608
+
609
+ // Sets the 'selectboxit-option-last' class name on the last drop down option
610
+ self.listItems.last().addClass("selectboxit-option-last");
611
+
612
+ // Set the disabled CSS class for select box options
613
+ self.list.find("li[data-disabled='true']").not(".optgroupHeader").addClass(self.theme["disabled"]);
614
+
615
+ self.dropdownImage.addClass(self.selectBox.attr("data-icon") || self.options["defaultIcon"] || self.listItems.eq(self.currentFocus).find("i").attr("class"));
616
+
617
+ self.dropdownImage.attr("style", self.listItems.eq(self.currentFocus).find("i").attr("style"));
618
+
619
+ //Maintains chainability
620
+ return self;
621
+
622
+ },
623
+
624
+ // _Replace Select Box
625
+ // -------------------
626
+ // Hides the original dropdown list and inserts
627
+ // the new DOM elements
628
+ _replaceSelectBox: function() {
629
+
630
+ var self = this,
631
+ height,
632
+ originalElemId = self.originalElem.id || "",
633
+ size = self.selectBox.attr("data-size"),
634
+ listSize = self.listSize = size === undefined ? "auto" : size === "0" || "size" === "auto" ? "auto" : +size,
635
+ downArrowContainerWidth,
636
+ dropdownImageWidth;
637
+
638
+ // Hides the original select box
639
+ self.selectBox.css("display", "none").
640
+
641
+ // Adds the new dropdown list to the page directly after the hidden original select box element
642
+ after(self.dropdownContainer);
643
+
644
+ self.dropdownContainer.appendTo('body').
645
+
646
+ addClass('selectboxit-rendering');
647
+
648
+ // The height of the dropdown list
649
+ height = self.dropdown.height();
650
+
651
+ // The down arrow element of the dropdown list
652
+ self.downArrow = $("<i/>", {
653
+
654
+ // Dynamically sets the dropdown `id` attribute of the dropdown list down arrow
655
+ "id": originalElemId && originalElemId + "SelectBoxItArrow",
656
+
657
+ "class": "selectboxit-arrow",
658
+
659
+ // IE specific attribute to not allow the dropdown list text to be selected
660
+ "unselectable": "on"
661
+
662
+ });
663
+
664
+ // The down arrow container element of the dropdown list
665
+ self.downArrowContainer = $("<span/>", {
666
+
667
+ // Dynamically sets the dropdown `id` attribute for the down arrow container element
668
+ "id": originalElemId && originalElemId + "SelectBoxItArrowContainer",
669
+
670
+ "class": "selectboxit-arrow-container",
671
+
672
+ // IE specific attribute to not allow the dropdown list text to be selected
673
+ "unselectable": "on"
674
+
675
+ }).
676
+
677
+ // Inserts the down arrow element inside of the down arrow container element
678
+ append(self.downArrow);
679
+
680
+ // Appends the down arrow element to the dropdown list
681
+ self.dropdown.append(self.downArrowContainer);
682
+
683
+ // Adds the `selectboxit-selected` class name to the currently selected drop down option
684
+ self.listItems.removeClass("selectboxit-selected").eq(self.currentFocus).addClass("selectboxit-selected");
685
+
686
+ // The full outer width of the down arrow container
687
+ downArrowContainerWidth = self.downArrowContainer.outerWidth(true);
688
+
689
+ // The full outer width of the dropdown image
690
+ dropdownImageWidth = self.dropdownImage.outerWidth(true);
691
+
692
+ // If the `autoWidth` option is true
693
+ if(self.options["autoWidth"]) {
694
+
695
+ // Sets the auto width of the drop down
696
+ self.dropdown.css({ "width": "auto" }).css({
697
+
698
+ "width": self.list.outerWidth(true) + downArrowContainerWidth + dropdownImageWidth
699
+
700
+ });
701
+
702
+ self.list.css({
703
+
704
+ "min-width": self.dropdown.width()
705
+
706
+ });
707
+
708
+ }
709
+
710
+ // Dynamically adds the `max-width` and `line-height` CSS styles of the dropdown list text element
711
+ self.dropdownText.css({
712
+
713
+ "max-width": self.dropdownContainer.outerWidth(true) - (downArrowContainerWidth + dropdownImageWidth)
714
+
715
+ });
716
+
717
+ // Adds the new dropdown list to the page directly after the hidden original select box element
718
+ self.selectBox.after(self.dropdownContainer);
719
+
720
+ self.dropdownContainer.removeClass('selectboxit-rendering');
721
+
722
+ if($.type(listSize) === "number") {
723
+
724
+ // Stores the new `max-height` for later
725
+ self.maxHeight = self.listAnchors.outerHeight(true) * listSize;
726
+
727
+ }
728
+
729
+ // Maintains chainability
730
+ return self;
731
+
732
+ },
733
+
734
+ // _Scroll-To-View
735
+ // ---------------
736
+ // Updates the dropdown list scrollTop value
737
+ _scrollToView: function(type) {
738
+
739
+ var self = this,
740
+
741
+ currentOption = self.listItems.eq(self.currentFocus),
742
+
743
+ // The current scroll positioning of the dropdown list options list
744
+ listScrollTop = self.list.scrollTop(),
745
+
746
+ // The height of the currently selected dropdown list option
747
+ currentItemHeight = currentOption.height(),
748
+
749
+ // The relative distance from the currently selected dropdown list option to the the top of the dropdown list options list
750
+ currentTopPosition = currentOption.position().top,
751
+
752
+ absCurrentTopPosition = Math.abs(currentTopPosition),
753
+
754
+ // The height of the dropdown list option list
755
+ listHeight = self.list.height(),
756
+
757
+ currentText;
758
+
759
+ // Scrolling logic for a text search
760
+ if (type === "search") {
761
+
762
+ // Increases the dropdown list options `scrollTop` if a user is searching for an option
763
+ // below the currently selected option that is not visible
764
+ if (listHeight - currentTopPosition < currentItemHeight) {
765
+
766
+ // The selected option will be shown at the very bottom of the visible options list
767
+ self.list.scrollTop(listScrollTop + (currentTopPosition - (listHeight - currentItemHeight)));
768
+
769
+ }
770
+
771
+ // Decreases the dropdown list options `scrollTop` if a user is searching for an option above the currently selected option that is not visible
772
+ else if (currentTopPosition < -1) {
773
+
774
+ self.list.scrollTop(currentTopPosition - currentItemHeight);
775
+
776
+ }
777
+ }
778
+
779
+ // Scrolling logic for the `up` keyboard navigation
780
+ else if (type === "up") {
781
+
782
+ // Decreases the dropdown list option list `scrollTop` if a user is navigating to an element that is not visible
783
+ if (currentTopPosition < -1) {
784
+
785
+ self.list.scrollTop(listScrollTop - absCurrentTopPosition);
786
+
787
+ }
788
+ }
789
+
790
+ // Scrolling logic for the `down` keyboard navigation
791
+ else if (type === "down") {
792
+
793
+ // Increases the dropdown list options `scrollTop` if a user is navigating to an element that is not fully visible
794
+ if (listHeight - currentTopPosition < currentItemHeight) {
795
+
796
+ // Increases the dropdown list options `scrollTop` by the height of the current option item.
797
+ self.list.scrollTop((listScrollTop + (absCurrentTopPosition - listHeight + currentItemHeight)));
798
+
799
+ }
800
+ }
801
+
802
+ // Maintains chainability
803
+ return self;
804
+
805
+ },
806
+
807
+ // _Callback
808
+ // ---------
809
+ // Call the function passed into the method
810
+ _callbackSupport: function(callback) {
811
+
812
+ var self = this;
813
+
814
+ // Checks to make sure the parameter passed in is a function
815
+ if ($.isFunction(callback)) {
816
+
817
+ // Calls the method passed in as a parameter and sets the current `SelectBoxIt` object that is stored in the jQuery data method as the context(allows for `this` to reference the SelectBoxIt API Methods in the callback function. The `dropdown` DOM element that acts as the new dropdown list is also passed as the only parameter to the callback
818
+ callback.call(self, self.dropdown);
819
+
820
+ }
821
+
822
+ // Maintains chainability
823
+ return self;
824
+
825
+ },
826
+
827
+ // _setText
828
+ // --------
829
+ // Set's the text or html for the drop down
830
+ _setText: function(elem, currentText) {
831
+
832
+ var self = this;
833
+
834
+ if(self.options["html"]) {
835
+
836
+ elem.html(currentText);
837
+
838
+ }
839
+
840
+ else {
841
+
842
+ elem.text(currentText);
843
+
844
+ }
845
+
846
+ return self;
847
+
848
+ },
849
+
850
+ // Open
851
+ // ----
852
+ // Opens the dropdown list options list
853
+ open: function(callback) {
854
+
855
+ var self = this,
856
+ showEffect = self.options["showEffect"],
857
+ showEffectSpeed = self.options["showEffectSpeed"],
858
+ showEffectOptions = self.options["showEffectOptions"],
859
+ isNative = self.options["native"],
860
+ isMobile = self.isMobile;
861
+
862
+ // If there are no select box options, do not try to open the select box
863
+ if(!self.listItems.length || self.dropdown.hasClass(self.theme["disabled"])) {
864
+
865
+ return self;
866
+
867
+ }
868
+
869
+ // If the new drop down is being used and is not visible
870
+ if((!isNative && !isMobile) && !this.list.is(":visible")) {
871
+
872
+ // Triggers a custom "open" event on the original select box
873
+ self.triggerEvent("open");
874
+
875
+ if (self._dynamicPositioning && self.options["dynamicPositioning"]) {
876
+
877
+ // Dynamically positions the dropdown list options list
878
+ self._dynamicPositioning();
879
+
880
+ }
881
+
882
+ // Uses `no effect`
883
+ if(showEffect === "none") {
884
+
885
+ // Does not require a callback function because this animation will complete before the call to `scrollToView`
886
+ self.list.show();
887
+
888
+ }
889
+
890
+ // Uses the jQuery `show` special effect
891
+ else if(showEffect === "show" || showEffect === "slideDown" || showEffect === "fadeIn") {
892
+
893
+ // Requires a callback function to determine when the `show` animation is complete
894
+ self.list[showEffect](showEffectSpeed);
895
+
896
+ }
897
+
898
+ // If none of the above options were passed, then a `jqueryUI show effect` is expected
899
+ else {
900
+
901
+ // Allows for custom show effects via the [jQueryUI core effects](http://http://jqueryui.com/demos/show/)
902
+ self.list.show(showEffect, showEffectOptions, showEffectSpeed);
903
+
904
+ }
905
+
906
+ self.list.promise().done(function() {
907
+
908
+ // Updates the list `scrollTop` attribute
909
+ self._scrollToView("search");
910
+
911
+ // Triggers a custom "opened" event when the drop down list is done animating
912
+ self.triggerEvent("opened");
913
+
914
+ });
915
+
916
+ }
917
+
918
+ // Provide callback function support
919
+ self._callbackSupport(callback);
920
+
921
+ // Maintains chainability
922
+ return self;
923
+
924
+ },
925
+
926
+ // Close
927
+ // -----
928
+ // Closes the dropdown list options list
929
+ close: function(callback) {
930
+
931
+ var self = this,
932
+ hideEffect = self.options["hideEffect"],
933
+ hideEffectSpeed = self.options["hideEffectSpeed"],
934
+ hideEffectOptions = self.options["hideEffectOptions"],
935
+ isNative = self.options["native"],
936
+ isMobile = self.isMobile;
937
+
938
+ // If the drop down is being used and is visible
939
+ if((!isNative && !isMobile) && self.list.is(":visible")) {
940
+
941
+ // Triggers a custom "close" event on the original select box
942
+ self.triggerEvent("close");
943
+
944
+ // Uses `no effect`
945
+ if(hideEffect === "none") {
946
+
947
+ // Does not require a callback function because this animation will complete before the call to `scrollToView`
948
+ self.list.hide();
949
+
950
+ }
951
+
952
+ // Uses the jQuery `hide` special effect
953
+ else if(hideEffect === "hide" || hideEffect === "slideUp" || hideEffect === "fadeOut") {
954
+
955
+ self.list[hideEffect](hideEffectSpeed);
956
+
957
+ }
958
+
959
+ // If none of the above options were passed, then a `jqueryUI hide effect` is expected
960
+ else {
961
+
962
+ // Allows for custom hide effects via the [jQueryUI core effects](http://http://jqueryui.com/demos/hide/)
963
+ self.list.hide(hideEffect, hideEffectOptions, hideEffectSpeed);
964
+
965
+ }
966
+
967
+ // After the drop down list is done animating
968
+ self.list.promise().done(function() {
969
+
970
+ // Triggers a custom "closed" event when the drop down list is done animating
971
+ self.triggerEvent("closed");
972
+
973
+ });
974
+
975
+ }
976
+
977
+ // Provide callback function support
978
+ self._callbackSupport(callback);
979
+
980
+ // Maintains chainability
981
+ return self;
982
+
983
+ },
984
+
985
+ toggle: function() {
986
+
987
+ var self = this,
988
+ listIsVisible = self.list.is(":visible");
989
+
990
+ if(listIsVisible) {
991
+
992
+ self.close();
993
+
994
+ }
995
+
996
+ else if(!listIsVisible) {
997
+
998
+ self.open();
999
+
1000
+ }
1001
+
1002
+ },
1003
+
1004
+ // _Key Mappings
1005
+ // -------------
1006
+ // Object literal holding the string representation of each key code
1007
+ _keyMappings: {
1008
+
1009
+ "38": "up",
1010
+
1011
+ "40": "down",
1012
+
1013
+ "13": "enter",
1014
+
1015
+ "8": "backspace",
1016
+
1017
+ "9": "tab",
1018
+
1019
+ "32": "space",
1020
+
1021
+ "27": "esc"
1022
+
1023
+ },
1024
+
1025
+ // _Key Down Methods
1026
+ // -----------------
1027
+ // Methods to use when the keydown event is triggered
1028
+ _keydownMethods: function() {
1029
+
1030
+ var self = this,
1031
+ moveToOption = self.list.is(":visible") || !self.options["keydownOpen"];
1032
+
1033
+ return {
1034
+
1035
+ "down": function() {
1036
+
1037
+ // If the plugin options allow keyboard navigation
1038
+ if (self.moveDown && moveToOption) {
1039
+
1040
+ self.moveDown();
1041
+
1042
+ }
1043
+
1044
+ },
1045
+
1046
+ "up": function() {
1047
+
1048
+ // If the plugin options allow keyboard navigation
1049
+ if (self.moveUp && moveToOption) {
1050
+
1051
+ self.moveUp();
1052
+
1053
+ }
1054
+
1055
+ },
1056
+
1057
+ "enter": function() {
1058
+
1059
+ var activeElem = self.listItems.eq(self.currentFocus);
1060
+
1061
+ // Updates the dropdown list value
1062
+ self._update(activeElem);
1063
+
1064
+ if (activeElem.attr("data-preventclose") !== "true") {
1065
+
1066
+ // Closes the drop down list options list
1067
+ self.close();
1068
+
1069
+ }
1070
+
1071
+ // Triggers the `enter` events on the original select box
1072
+ self.triggerEvent("enter");
1073
+
1074
+ },
1075
+
1076
+ "tab": function() {
1077
+
1078
+ // Triggers the custom `tab-blur` event on the original select box
1079
+ self.triggerEvent("tab-blur");
1080
+
1081
+ // Closes the drop down list
1082
+ self.close();
1083
+
1084
+ },
1085
+
1086
+ "backspace": function() {
1087
+
1088
+ // Triggers the custom `backspace` event on the original select box
1089
+ self.triggerEvent("backspace");
1090
+
1091
+ },
1092
+
1093
+ "esc": function() {
1094
+
1095
+ // Closes the dropdown options list
1096
+ self.close();
1097
+
1098
+ }
1099
+
1100
+ };
1101
+
1102
+ },
1103
+
1104
+
1105
+ // _Event Handlers
1106
+ // ---------------
1107
+ // Adds event handlers to the new dropdown and the original select box
1108
+ _eventHandlers: function() {
1109
+
1110
+ // LOCAL VARIABLES
1111
+ var self = this,
1112
+ nativeMousedown = self.options["nativeMousedown"],
1113
+ customShowHideEvent = self.options["customShowHideEvent"],
1114
+ currentDataText,
1115
+ currentText,
1116
+ focusClass = self.focusClass,
1117
+ hoverClass = self.hoverClass,
1118
+ openClass = self.openClass;
1119
+
1120
+ // Select Box events
1121
+ this.dropdown.on({
1122
+
1123
+ // `click` event with the `selectBoxIt` namespace
1124
+ "click.selectBoxIt": function() {
1125
+
1126
+ // Used to make sure the dropdown becomes focused (fixes IE issue)
1127
+ self.dropdown.trigger("focus", true);
1128
+
1129
+ // The `click` handler logic will only be applied if the dropdown list is enabled
1130
+ if (!self.originalElem.disabled) {
1131
+
1132
+ // Triggers the `click` event on the original select box
1133
+ self.triggerEvent("click");
1134
+
1135
+ if(!nativeMousedown && !customShowHideEvent) {
1136
+
1137
+ self.toggle();
1138
+
1139
+ }
1140
+
1141
+ }
1142
+
1143
+ },
1144
+
1145
+ // `mousedown` event with the `selectBoxIt` namespace
1146
+ "mousedown.selectBoxIt": function() {
1147
+
1148
+ // Stores data in the jQuery `data` method to help determine if the dropdown list gains focus from a click or tabstop. The mousedown event fires before the focus event.
1149
+ $(this).data("mdown", true);
1150
+
1151
+ self.triggerEvent("mousedown");
1152
+
1153
+ if(nativeMousedown && !customShowHideEvent) {
1154
+
1155
+ self.toggle();
1156
+
1157
+ }
1158
+
1159
+ },
1160
+
1161
+ // `mouseup` event with the `selectBoxIt` namespace
1162
+ "mouseup.selectBoxIt": function() {
1163
+
1164
+ self.triggerEvent("mouseup");
1165
+
1166
+ },
1167
+
1168
+ // `blur` event with the `selectBoxIt` namespace. Uses special blur logic to make sure the dropdown list closes correctly
1169
+ "blur.selectBoxIt": function() {
1170
+
1171
+ // If `self.blur` property is true
1172
+ if (self.blur) {
1173
+
1174
+ // Triggers both the `blur` and `focusout` events on the original select box.
1175
+ // The `focusout` event is also triggered because the event bubbles
1176
+ // This event has to be used when using event delegation (such as the jQuery `delegate` or `on` methods)
1177
+ // Popular open source projects such as Backbone.js utilize event delegation to bind events, so if you are using Backbone.js, use the `focusout` event instead of the `blur` event
1178
+ self.triggerEvent("blur");
1179
+
1180
+ // Closes the dropdown list options list
1181
+ self.close();
1182
+
1183
+ $(this).removeClass(focusClass);
1184
+
1185
+ }
1186
+
1187
+ },
1188
+
1189
+ "focus.selectBoxIt": function(event, internal) {
1190
+
1191
+ // Stores the data associated with the mousedown event inside of a local variable
1192
+ var mdown = $(this).data("mdown");
1193
+
1194
+ // Removes the jQuery data associated with the mousedown event
1195
+ $(this).removeData("mdown");
1196
+
1197
+ // If a mousedown event did not occur and no data was passed to the focus event (this correctly triggers the focus event), then the dropdown list gained focus from a tabstop
1198
+ if (!mdown && !internal) {
1199
+
1200
+ setTimeout(function() {
1201
+
1202
+ // Triggers the `tabFocus` custom event on the original select box
1203
+ self.triggerEvent("tab-focus");
1204
+
1205
+ }, 0);
1206
+
1207
+ }
1208
+
1209
+ // Only trigger the `focus` event on the original select box if the dropdown list is hidden (this verifies that only the correct `focus` events are used to trigger the event on the original select box
1210
+ if(!internal) {
1211
+
1212
+ if(!$(this).hasClass(self.theme["disabled"])) {
1213
+
1214
+ $(this).addClass(focusClass);
1215
+
1216
+ }
1217
+
1218
+ //Triggers the `focus` default event on the original select box
1219
+ self.triggerEvent("focus");
1220
+
1221
+ }
1222
+
1223
+ },
1224
+
1225
+ // `keydown` event with the `selectBoxIt` namespace. Catches all user keyboard navigations
1226
+ "keydown.selectBoxIt": function(e) {
1227
+
1228
+ // Stores the `keycode` value in a local variable
1229
+ var currentKey = self._keyMappings[e.keyCode],
1230
+
1231
+ keydownMethod = self._keydownMethods()[currentKey];
1232
+
1233
+ if(keydownMethod) {
1234
+
1235
+ keydownMethod();
1236
+
1237
+ if(self.options["keydownOpen"] && (currentKey === "up" || currentKey === "down")) {
1238
+
1239
+ self.open();
1240
+
1241
+ }
1242
+
1243
+ }
1244
+
1245
+ if(keydownMethod && currentKey !== "tab") {
1246
+
1247
+ e.preventDefault();
1248
+
1249
+ }
1250
+
1251
+ },
1252
+
1253
+ // `keypress` event with the `selectBoxIt` namespace. Catches all user keyboard text searches since you can only reliably get character codes using the `keypress` event
1254
+ "keypress.selectBoxIt": function(e) {
1255
+
1256
+ // Sets the current key to the `keyCode` value if `charCode` does not exist. Used for cross
1257
+ // browser support since IE uses `keyCode` instead of `charCode`.
1258
+ var currentKey = e.charCode || e.keyCode,
1259
+
1260
+ key = self._keyMappings[e.charCode || e.keyCode],
1261
+
1262
+ // Converts unicode values to characters
1263
+ alphaNumericKey = String.fromCharCode(currentKey);
1264
+
1265
+ // If the plugin options allow text searches
1266
+ if (self.search && (!key || (key && key === "space"))) {
1267
+
1268
+ // Calls `search` and passes the character value of the user's text search
1269
+ self.search(alphaNumericKey, true, true);
1270
+
1271
+ }
1272
+
1273
+ if(key === "space") {
1274
+
1275
+ e.preventDefault();
1276
+
1277
+ }
1278
+
1279
+ },
1280
+
1281
+ // `mousenter` event with the `selectBoxIt` namespace .The mouseenter JavaScript event is proprietary to Internet Explorer. Because of the event's general utility, jQuery simulates this event so that it can be used regardless of browser.
1282
+ "mouseenter.selectBoxIt": function() {
1283
+
1284
+ // Trigger the `mouseenter` event on the original select box
1285
+ self.triggerEvent("mouseenter");
1286
+
1287
+ },
1288
+
1289
+ // `mouseleave` event with the `selectBoxIt` namespace. The mouseleave JavaScript event is proprietary to Internet Explorer. Because of the event's general utility, jQuery simulates this event so that it can be used regardless of browser.
1290
+ "mouseleave.selectBoxIt": function() {
1291
+
1292
+ // Trigger the `mouseleave` event on the original select box
1293
+ self.triggerEvent("mouseleave");
1294
+
1295
+ }
1296
+
1297
+ });
1298
+
1299
+ // Select box options events that set the dropdown list blur logic (decides when the dropdown list gets
1300
+ // closed)
1301
+ self.list.on({
1302
+
1303
+ // `mouseover` event with the `selectBoxIt` namespace
1304
+ "mouseover.selectBoxIt": function() {
1305
+
1306
+ // Prevents the dropdown list options list from closing
1307
+ self.blur = false;
1308
+
1309
+ },
1310
+
1311
+ // `mouseout` event with the `selectBoxIt` namespace
1312
+ "mouseout.selectBoxIt": function() {
1313
+
1314
+ // Allows the dropdown list options list to close
1315
+ self.blur = true;
1316
+
1317
+ },
1318
+
1319
+ // `focusin` event with the `selectBoxIt` namespace
1320
+ "focusin.selectBoxIt": function() {
1321
+
1322
+ // Prevents the default browser outline border to flicker, which results because of the `blur` event
1323
+ self.dropdown.trigger("focus", true);
1324
+
1325
+ }
1326
+
1327
+ });
1328
+
1329
+ // Select box individual options events bound with the jQuery `delegate` method. `Delegate` was used because binding indropdownidual events to each list item (since we don't know how many there will be) would decrease performance. Instead, we bind each event to the unordered list, provide the list item context, and allow the list item events to bubble up (`event bubbling`). This greatly increases page performance because we only have to bind an event to one element instead of x number of elements. Delegates the `click` event with the `selectBoxIt` namespace to the list items
1330
+ self.list.on({
1331
+
1332
+ "mousedown.selectBoxIt": function() {
1333
+
1334
+ self._update($(this));
1335
+
1336
+ self.triggerEvent("option-click");
1337
+
1338
+ // If the current drop down option is not disabled
1339
+ if ($(this).attr("data-disabled") === "false" && $(this).attr("data-preventclose") !== "true") {
1340
+
1341
+ // Closes the drop down list
1342
+ self.close();
1343
+
1344
+ }
1345
+
1346
+ setTimeout(function() {
1347
+
1348
+ self.dropdown.trigger('focus', true);
1349
+
1350
+ }, 0);
1351
+
1352
+ },
1353
+
1354
+ // Delegates the `focusin` event with the `selectBoxIt` namespace to the list items
1355
+ "focusin.selectBoxIt": function() {
1356
+
1357
+ // Removes the hover class from the previous drop down option
1358
+ self.listItems.not($(this)).removeAttr("data-active");
1359
+
1360
+ $(this).attr("data-active", "");
1361
+
1362
+ var listIsHidden = self.list.is(":hidden");
1363
+
1364
+ if((self.options["searchWhenHidden"] && listIsHidden) || self.options["aggressiveChange"] || (listIsHidden && self.options["selectWhenHidden"])) {
1365
+
1366
+ self._update($(this));
1367
+
1368
+ }
1369
+
1370
+ // Adds the focus CSS class to the currently focused dropdown list option
1371
+ $(this).addClass(focusClass);
1372
+
1373
+ },
1374
+
1375
+ // Delegates the `focus` event with the `selectBoxIt` namespace to the list items
1376
+ "mouseup.selectBoxIt": function() {
1377
+
1378
+ if(nativeMousedown && !customShowHideEvent) {
1379
+
1380
+ self._update($(this));
1381
+
1382
+ self.triggerEvent("option-mouseup");
1383
+
1384
+ // If the current drop down option is not disabled
1385
+ if ($(this).attr("data-disabled") === "false" && $(this).attr("data-preventclose") !== "true") {
1386
+
1387
+ // Closes the drop down list
1388
+ self.close();
1389
+
1390
+ }
1391
+
1392
+ }
1393
+
1394
+ },
1395
+
1396
+ // Delegates the `mouseenter` event with the `selectBoxIt` namespace to the list items
1397
+ "mouseenter.selectBoxIt": function() {
1398
+
1399
+ // If the currently moused over drop down option is not disabled
1400
+ if($(this).attr("data-disabled") === "false") {
1401
+
1402
+ self.listItems.removeAttr("data-active");
1403
+
1404
+ $(this).addClass(focusClass).attr("data-active", "");
1405
+
1406
+ // Sets the dropdown list indropdownidual options back to the default state and sets the focus CSS class on the currently hovered option
1407
+ self.listItems.not($(this)).removeClass(focusClass);
1408
+
1409
+ $(this).addClass(focusClass);
1410
+
1411
+ self.currentFocus = +$(this).attr("data-id");
1412
+
1413
+ }
1414
+
1415
+ },
1416
+
1417
+ // Delegates the `mouseleave` event with the `selectBoxIt` namespace to the list items
1418
+ "mouseleave.selectBoxIt": function() {
1419
+
1420
+ // If the currently moused over drop down option is not disabled
1421
+ if($(this).attr("data-disabled") === "false") {
1422
+
1423
+ // Removes the focus class from the previous drop down option
1424
+ self.listItems.not($(this)).removeClass(focusClass).removeAttr("data-active");
1425
+
1426
+ $(this).addClass(focusClass);
1427
+
1428
+ self.currentFocus = +$(this).attr("data-id");
1429
+
1430
+ }
1431
+
1432
+ },
1433
+
1434
+ // Delegates the `blur` event with the `selectBoxIt` namespace to the list items
1435
+ "blur.selectBoxIt": function() {
1436
+
1437
+ // Removes the focus CSS class from the previously focused dropdown list option
1438
+ $(this).removeClass(focusClass);
1439
+
1440
+ }
1441
+
1442
+ }, ".selectboxit-option");
1443
+
1444
+ // Select box individual option anchor events bound with the jQuery `delegate` method. `Delegate` was used because binding indropdownidual events to each list item (since we don't know how many there will be) would decrease performance. Instead, we bind each event to the unordered list, provide the list item context, and allow the list item events to bubble up (`event bubbling`). This greatly increases page performance because we only have to bind an event to one element instead of x number of elements. Delegates the `click` event with the `selectBoxIt` namespace to the list items
1445
+ self.list.on({
1446
+
1447
+ "click.selectBoxIt": function(ev) {
1448
+
1449
+ // Prevents the internal anchor tag from doing anything funny
1450
+ ev.preventDefault();
1451
+
1452
+ }
1453
+
1454
+ }, "a");
1455
+
1456
+ // Original dropdown list events
1457
+ self.selectBox.on({
1458
+
1459
+ // `change` event handler with the `selectBoxIt` namespace
1460
+ "change.selectBoxIt, internal-change.selectBoxIt": function(event, internal) {
1461
+
1462
+ var currentOption,
1463
+ currentDataSelectedText;
1464
+
1465
+ // If the user called the change method
1466
+ if(!internal) {
1467
+
1468
+ currentOption = self.list.find('li[data-val="' + self.originalElem.value + '"]');
1469
+
1470
+ // If there is a dropdown option with the same value as the original select box element
1471
+ if(currentOption.length) {
1472
+
1473
+ self.listItems.eq(self.currentFocus).removeClass(self.focusClass);
1474
+
1475
+ self.currentFocus = +currentOption.attr("data-id");
1476
+
1477
+ }
1478
+
1479
+ }
1480
+
1481
+ currentOption = self.listItems.eq(self.currentFocus);
1482
+
1483
+ currentDataSelectedText = currentOption.attr("data-selectedtext");
1484
+
1485
+ currentDataText = currentOption.attr("data-text");
1486
+
1487
+ currentText = currentDataText ? currentDataText: currentOption.find("a").text();
1488
+
1489
+ // Sets the new dropdown list text to the value of the current option
1490
+ self._setText(self.dropdownText, currentDataSelectedText || currentText);
1491
+
1492
+ self.dropdownText.attr("data-val", self.originalElem.value);
1493
+
1494
+ if(currentOption.find("i").attr("class")) {
1495
+
1496
+ self.dropdownImage.attr("class", currentOption.find("i").attr("class")).addClass("selectboxit-default-icon");
1497
+
1498
+ self.dropdownImage.attr("style", currentOption.find("i").attr("style"));
1499
+ }
1500
+
1501
+ // Triggers a custom changed event on the original select box
1502
+ self.triggerEvent("changed");
1503
+
1504
+ },
1505
+
1506
+ // `disable` event with the `selectBoxIt` namespace
1507
+ "disable.selectBoxIt": function() {
1508
+
1509
+ // Adds the `disabled` CSS class to the new dropdown list to visually show that it is disabled
1510
+ self.dropdown.addClass(self.theme["disabled"]);
1511
+
1512
+ },
1513
+
1514
+ // `enable` event with the `selectBoxIt` namespace
1515
+ "enable.selectBoxIt": function() {
1516
+
1517
+ // Removes the `disabled` CSS class from the new dropdown list to visually show that it is enabled
1518
+ self.dropdown.removeClass(self.theme["disabled"]);
1519
+
1520
+ },
1521
+
1522
+ // `open` event with the `selectBoxIt` namespace
1523
+ "open.selectBoxIt": function() {
1524
+
1525
+ var currentElem = self.list.find("li[data-val='" + self.dropdownText.attr("data-val") + "']"),
1526
+ activeElem;
1527
+
1528
+ // If no current element can be found, then select the first drop down option
1529
+ if(!currentElem.length) {
1530
+
1531
+ // Sets the default value of the dropdown list to the first option that is not disabled
1532
+ currentElem = self.listItems.not("[data-disabled=true]").first();
1533
+
1534
+ }
1535
+
1536
+ self.currentFocus = +currentElem.attr("data-id");
1537
+
1538
+ activeElem = self.listItems.eq(self.currentFocus);
1539
+
1540
+ self.dropdown.addClass(openClass).
1541
+
1542
+ // Removes the focus class from the dropdown list and adds the library focus class for both the dropdown list and the currently selected dropdown list option
1543
+ removeClass(hoverClass).addClass(focusClass);
1544
+
1545
+ self.listItems.removeClass(self.selectedClass).
1546
+
1547
+ removeAttr("data-active").not(activeElem).removeClass(focusClass);
1548
+
1549
+ activeElem.addClass(self.selectedClass).addClass(focusClass);
1550
+
1551
+ if(self.options.hideCurrent) {
1552
+
1553
+ self.listItems.show();
1554
+
1555
+ activeElem.hide();
1556
+
1557
+ }
1558
+
1559
+ },
1560
+
1561
+ "close.selectBoxIt": function() {
1562
+
1563
+ // Removes the open class from the dropdown container
1564
+ self.dropdown.removeClass(openClass);
1565
+
1566
+ },
1567
+
1568
+ "blur.selectBoxIt": function() {
1569
+
1570
+ self.dropdown.removeClass(focusClass);
1571
+
1572
+ },
1573
+
1574
+ // `mousenter` event with the `selectBoxIt` namespace
1575
+ "mouseenter.selectBoxIt": function() {
1576
+
1577
+ if(!$(this).hasClass(self.theme["disabled"])) {
1578
+ self.dropdown.addClass(hoverClass);
1579
+ }
1580
+
1581
+ },
1582
+
1583
+ // `mouseleave` event with the `selectBoxIt` namespace
1584
+ "mouseleave.selectBoxIt": function() {
1585
+
1586
+ // Removes the hover CSS class on the previously hovered dropdown list option
1587
+ self.dropdown.removeClass(hoverClass);
1588
+
1589
+ },
1590
+
1591
+ // `destroy` event
1592
+ "destroy": function(ev) {
1593
+
1594
+ // Prevents the default action from happening
1595
+ ev.preventDefault();
1596
+
1597
+ // Prevents the destroy event from propagating
1598
+ ev.stopPropagation();
1599
+
1600
+ }
1601
+
1602
+ });
1603
+
1604
+ // Maintains chainability
1605
+ return self;
1606
+
1607
+ },
1608
+
1609
+ // _update
1610
+ // -------
1611
+ // Updates the drop down and select box with the current value
1612
+ _update: function(elem) {
1613
+
1614
+ var self = this,
1615
+ currentDataSelectedText,
1616
+ currentDataText,
1617
+ currentText,
1618
+ defaultText = self.options["defaultText"] || self.selectBox.attr("data-text"),
1619
+ currentElem = self.listItems.eq(self.currentFocus);
1620
+
1621
+ if (elem.attr("data-disabled") === "false") {
1622
+
1623
+ currentDataSelectedText = self.listItems.eq(self.currentFocus).attr("data-selectedtext");
1624
+
1625
+ currentDataText = currentElem.attr("data-text");
1626
+
1627
+ currentText = currentDataText ? currentDataText: currentElem.text();
1628
+
1629
+ // If the default text option is set and the current drop down option is not disabled
1630
+ if ((defaultText && self.options["html"] ? self.dropdownText.html() === defaultText: self.dropdownText.text() === defaultText) && self.selectBox.val() === elem.attr("data-val")) {
1631
+
1632
+ self.triggerEvent("change");
1633
+
1634
+ }
1635
+
1636
+ else {
1637
+
1638
+ // Sets the original dropdown list value and triggers the `change` event on the original select box
1639
+ self.selectBox.val(elem.attr("data-val"));
1640
+
1641
+ // Sets `currentFocus` to the currently focused dropdown list option.
1642
+ // The unary `+` operator casts the string to a number
1643
+ // [James Padolsey Blog Post](http://james.padolsey.com/javascript/terse-javascript-101-part-2/)
1644
+ self.currentFocus = +elem.attr("data-id");
1645
+
1646
+ // Triggers the dropdown list `change` event if a value change occurs
1647
+ if (self.originalElem.value !== self.dropdownText.attr("data-val")) {
1648
+
1649
+ self.triggerEvent("change");
1650
+
1651
+ }
1652
+
1653
+ }
1654
+
1655
+ }
1656
+
1657
+ },
1658
+
1659
+ // _addClasses
1660
+ // -----------
1661
+ // Adds SelectBoxIt CSS classes
1662
+ _addClasses: function(obj) {
1663
+
1664
+ var self = this,
1665
+
1666
+ focusClass = self.focusClass = obj.focus,
1667
+
1668
+ hoverClass = self.hoverClass = obj.hover,
1669
+
1670
+ buttonClass = obj.button,
1671
+
1672
+ listClass = obj.list,
1673
+
1674
+ arrowClass = obj.arrow,
1675
+
1676
+ containerClass = obj.container,
1677
+
1678
+ openClass = self.openClass = obj.open;
1679
+
1680
+ self.selectedClass = "selectboxit-selected";
1681
+
1682
+ self.downArrow.addClass(self.selectBox.attr("data-downarrow") || self.options["downArrowIcon"] || arrowClass);
1683
+
1684
+ // Adds the correct container class to the dropdown list
1685
+ self.dropdownContainer.addClass(containerClass);
1686
+
1687
+ // Adds the correct class to the dropdown list
1688
+ self.dropdown.addClass(buttonClass);
1689
+
1690
+ // Adds the default class to the dropdown list options
1691
+ self.list.addClass(listClass);
1692
+
1693
+ // Maintains chainability
1694
+ return self;
1695
+
1696
+ },
1697
+
1698
+ // Refresh
1699
+ // -------
1700
+ // The dropdown will rebuild itself. Useful for dynamic content.
1701
+ refresh: function(callback, internal) {
1702
+
1703
+ var self = this;
1704
+
1705
+ // Destroys the plugin and then recreates the plugin
1706
+ self._destroySelectBoxIt()._create(true);
1707
+
1708
+ if(!internal) {
1709
+ self.triggerEvent("refresh");
1710
+ }
1711
+
1712
+ self._callbackSupport(callback);
1713
+
1714
+ //Maintains chainability
1715
+ return self;
1716
+
1717
+ },
1718
+
1719
+ // HTML Escape
1720
+ // -----------
1721
+ // HTML encodes a string
1722
+ htmlEscape: function(str) {
1723
+
1724
+ return String(str)
1725
+ .replace(/&/g, "&amp;")
1726
+ .replace(/"/g, "&quot;")
1727
+ .replace(/'/g, "&#39;")
1728
+ .replace(/</g, "&lt;")
1729
+ .replace(/>/g, "&gt;");
1730
+
1731
+ },
1732
+
1733
+ // triggerEvent
1734
+ // ------------
1735
+ // Trigger's an external event on the original select box element
1736
+ triggerEvent: function(eventName) {
1737
+
1738
+ var self = this,
1739
+ // Finds the currently option index
1740
+ currentIndex = self.options["showFirstOption"] ? self.currentFocus : ((self.currentFocus - 1) >= 0 ? self.currentFocus: 0);
1741
+
1742
+ // Triggers the custom option-click event on the original select box and passes the select box option
1743
+ self.selectBox.trigger(eventName, { "selectbox": self.selectBox, "selectboxOption": self.selectItems.eq(currentIndex), "dropdown": self.dropdown, "dropdownOption": self.listItems.eq(self.currentFocus) });
1744
+
1745
+ // Maintains chainability
1746
+ return self;
1747
+
1748
+ },
1749
+
1750
+ // _copyAttributes
1751
+ // ---------------
1752
+ // Copies HTML attributes from the original select box to the new drop down
1753
+ _copyAttributes: function() {
1754
+
1755
+ var self = this;
1756
+
1757
+ if(self._addSelectBoxAttributes) {
1758
+
1759
+ self._addSelectBoxAttributes();
1760
+
1761
+ }
1762
+
1763
+ return self;
1764
+
1765
+ },
1766
+
1767
+ // _realOuterWidth
1768
+ // ---------------
1769
+ // Retrieves the true outerWidth dimensions of a hidden DOM element
1770
+ _realOuterWidth: function(elem) {
1771
+
1772
+ if(elem.is(":visible")) {
1773
+
1774
+ return elem.outerWidth(true);
1775
+
1776
+ }
1777
+
1778
+ var self = this,
1779
+ clonedElem = elem.clone(),
1780
+ outerWidth;
1781
+
1782
+ clonedElem.css({
1783
+
1784
+ "visibility": "hidden",
1785
+
1786
+ "display": "block",
1787
+
1788
+ "position": "absolute"
1789
+
1790
+ }).appendTo("body");
1791
+
1792
+ outerWidth = clonedElem.outerWidth(true);
1793
+
1794
+ clonedElem.remove();
1795
+
1796
+ return outerWidth;
1797
+ }
1798
+
1799
+ });
1800
+
1801
+ // Stores the plugin prototype object in a local variable
1802
+ var selectBoxIt = $.selectBox.selectBoxIt.prototype;