para 0.11.4 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (228) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/para/admin/main.scss +31 -0
  3. data/app/assets/stylesheets/para/admin/src/_affix.scss +7 -0
  4. data/app/assets/stylesheets/para/admin/src/_alert.scss +35 -0
  5. data/app/assets/stylesheets/para/admin/src/_base.scss +63 -0
  6. data/app/assets/stylesheets/para/admin/src/_bootstrap-variables.scss +766 -379
  7. data/app/assets/stylesheets/para/admin/src/_breadcrumb.scss +37 -0
  8. data/app/assets/stylesheets/para/admin/src/_buttons.scss +128 -0
  9. data/app/assets/stylesheets/para/admin/src/_checkable.scss +106 -0
  10. data/app/assets/stylesheets/para/admin/src/_common.scss +250 -0
  11. data/app/assets/stylesheets/para/admin/src/_dropdown.scss +52 -0
  12. data/app/assets/stylesheets/para/admin/src/_form.scss +359 -0
  13. data/app/assets/stylesheets/para/admin/src/_list.scss +96 -0
  14. data/app/assets/stylesheets/para/admin/src/_mixins.scss +109 -0
  15. data/app/assets/stylesheets/para/admin/src/_multi-select.scss +110 -0
  16. data/app/assets/stylesheets/para/admin/src/_navigation.scss +210 -0
  17. data/app/assets/stylesheets/para/admin/src/_navtabs.scss +68 -0
  18. data/app/assets/stylesheets/para/admin/src/_nested-many.scss +87 -0
  19. data/app/assets/stylesheets/para/admin/src/_nested_one.scss +26 -0
  20. data/app/assets/stylesheets/para/admin/src/_orderable.scss +48 -0
  21. data/app/assets/stylesheets/para/admin/src/_page-loading.scss +40 -0
  22. data/app/assets/stylesheets/para/admin/src/_pagination.scss +39 -0
  23. data/app/assets/stylesheets/para/admin/src/_panel.scss +61 -0
  24. data/app/assets/stylesheets/para/admin/src/_responsive.scss +133 -0
  25. data/app/assets/stylesheets/para/admin/src/_sorting.scss +43 -0
  26. data/app/assets/stylesheets/para/admin/src/_statcard.scss +46 -0
  27. data/app/assets/stylesheets/para/admin/src/_table.scss +36 -0
  28. data/app/assets/stylesheets/para/admin/src/_tree.scss +60 -0
  29. data/app/assets/stylesheets/para/admin/src/{_variables.sass → _variables.scss} +7 -7
  30. data/app/assets/stylesheets/para/admin/src/{_well.sass → _well.scss} +5 -4
  31. data/app/assets/stylesheets/para/admin.scss +15 -0
  32. data/app/assets/stylesheets/para/index.scss +1 -0
  33. data/app/assets/stylesheets/para/lib/datetimepicker.scss +15 -0
  34. data/app/assets/stylesheets/para/lib/fuelux.scss +46 -0
  35. data/app/assets/stylesheets/para/lib/jasny-bootstrap.scss +100 -0
  36. data/app/assets/stylesheets/para/lib/selectize.scss +129 -0
  37. data/app/assets/stylesheets/para/lib/slider.scss +14 -0
  38. data/app/controllers/para/admin/crud_resources_controller.rb +16 -9
  39. data/app/controllers/para/admin/imports_controller.rb +9 -9
  40. data/app/controllers/para/admin/jobs_controller.rb +7 -1
  41. data/app/controllers/para/admin/resources_controller.rb +17 -18
  42. data/app/controllers/para/admin/settings_component_controller.rb +2 -2
  43. data/app/helpers/para/admin/base_helper.rb +36 -25
  44. data/app/helpers/para/admin/page_helper.rb +8 -9
  45. data/app/helpers/para/flash_helper.rb +7 -28
  46. data/app/helpers/para/model_helper.rb +5 -8
  47. data/app/helpers/para/tree_helper.rb +4 -4
  48. data/app/javascripts/para/admin/async-progress.js +58 -0
  49. data/app/javascripts/para/admin/filters-form.js +12 -0
  50. data/app/javascripts/para/admin/job-tracker.js +33 -0
  51. data/app/javascripts/para/admin/table.js +58 -0
  52. data/app/javascripts/para/admin/tabs.js +110 -0
  53. data/app/javascripts/para/admin/theme_actions.js +39 -0
  54. data/app/javascripts/para/admin/tree.js +124 -0
  55. data/app/javascripts/para/application.js +2 -0
  56. data/app/javascripts/para/controllers/application.js +17 -0
  57. data/app/javascripts/para/controllers/index.js +10 -0
  58. data/app/javascripts/para/controllers/para_admin_flash_message_controller.js +48 -0
  59. data/app/javascripts/para/controllers/para_admin_modal_controller.js +43 -0
  60. data/app/javascripts/para/controllers/selectize_field_controller.js +142 -0
  61. data/app/javascripts/para/index.js +31 -0
  62. data/app/javascripts/para/inputs/material-input.js +7 -0
  63. data/app/javascripts/para/inputs/multi-select-input.js +343 -0
  64. data/app/javascripts/para/inputs/nested_many.js +151 -0
  65. data/app/javascripts/para/lib/fetch.js +41 -0
  66. data/app/javascripts/para/lib/page-loading.js +42 -0
  67. data/app/javascripts/para/simple_form_extension/colorpicker.js +30 -0
  68. data/app/javascripts/para/simple_form_extension/datetimepicker.js +115 -0
  69. data/app/javascripts/para/simple_form_extension/fileinput.js +57 -0
  70. data/app/javascripts/para/simple_form_extension/index.js +12 -0
  71. data/app/javascripts/para/simple_form_extension/selectize.js +160 -0
  72. data/app/javascripts/para/simple_form_extension/simple_form_extension_initialization.js +62 -0
  73. data/app/javascripts/para/simple_form_extension/slider.js +43 -0
  74. data/app/javascripts/para/simple_form_extension/spinbox.js +35 -0
  75. data/app/javascripts/para/vendor/bootstrap-colorpicker.js +1025 -0
  76. data/app/javascripts/para/vendor/bootstrap-slider.js +1610 -0
  77. data/app/javascripts/para/vendor/cocoon.js +150 -0
  78. data/app/javascripts/para/vendor/jquery.datetimepicker.js +2156 -0
  79. data/app/javascripts/para/vendor/jquery.js +3 -0
  80. data/app/javascripts/para/vendor/spinbox.js +438 -0
  81. data/app/javascripts/para/vendor/vertebra.js +224 -0
  82. data/app/views/admin/para/exporter/bases/_completed.html.haml +1 -1
  83. data/app/views/layouts/para/admin.html.haml +4 -2
  84. data/app/views/para/admin/imports/new.html.haml +12 -11
  85. data/app/views/para/admin/jobs/_completed.html.haml +1 -1
  86. data/app/views/para/admin/jobs/_failed.html.haml +1 -1
  87. data/app/views/para/admin/jobs/_job.html.haml +11 -0
  88. data/app/views/para/admin/jobs/show.html.haml +1 -10
  89. data/app/views/para/admin/resources/_add_button.html.haml +1 -1
  90. data/app/views/para/admin/resources/_exports_menu.html.haml +2 -2
  91. data/app/views/para/admin/resources/_filters.html.haml +1 -1
  92. data/app/views/para/admin/resources/_imports_menu.html.haml +2 -2
  93. data/app/views/para/admin/resources/_list.html.haml +27 -26
  94. data/app/views/para/admin/resources/_navigation.html.haml +10 -11
  95. data/app/views/para/admin/resources/_subclassable_add_button.html.haml +1 -1
  96. data/app/views/para/admin/shared/_flash.html.haml +18 -0
  97. data/app/views/para/admin/shared/_header.html.haml +1 -1
  98. data/app/views/para/form/_tabs.html.haml +1 -1
  99. data/app/views/para/inputs/_nested_many.html.haml +3 -3
  100. data/app/views/para/inputs/nested_many/_add.html.haml +1 -1
  101. data/app/views/para/inputs/nested_many/_add_with_subclasses.html.haml +2 -2
  102. data/app/views/para/inputs/nested_many/_container.html.haml +1 -1
  103. data/config/locales/fr.yml +1 -0
  104. data/lib/generators/para/install/install_generator.rb +10 -14
  105. data/lib/para/attribute_field/base.rb +3 -0
  106. data/lib/para/attribute_field/wysiwyg_editor.rb +15 -0
  107. data/lib/para/attribute_field.rb +1 -1
  108. data/lib/para/components_configuration.rb +1 -1
  109. data/lib/para/engine.rb +20 -22
  110. data/lib/para/ext/turbo_stream.rb +13 -0
  111. data/lib/para/ext.rb +1 -1
  112. data/lib/para/form_builder/containers.rb +33 -22
  113. data/lib/para/form_builder/nested_form.rb +6 -5
  114. data/lib/para/inputs/nested_many_input.rb +5 -0
  115. data/lib/para/markup/modal.rb +30 -15
  116. data/lib/para/markup/resources_buttons.rb +15 -11
  117. data/lib/para/model_field_parsers/wysiwyg_editor.rb +19 -0
  118. data/lib/para/model_field_parsers.rb +1 -1
  119. data/lib/para/version.rb +1 -1
  120. data/lib/para.rb +2 -8
  121. data/lib/simple_form_extension/components/icons.rb +13 -0
  122. data/lib/simple_form_extension/components/popovers.rb +46 -0
  123. data/lib/simple_form_extension/components.rb +8 -0
  124. data/lib/simple_form_extension/ext/form_builder.rb +20 -0
  125. data/lib/simple_form_extension/file_concern.rb +74 -0
  126. data/lib/simple_form_extension/inputs/boolean_input.rb +16 -0
  127. data/lib/simple_form_extension/inputs/collection_check_boxes_input.rb +15 -0
  128. data/lib/simple_form_extension/inputs/collection_radio_buttons_input.rb +15 -0
  129. data/lib/simple_form_extension/inputs/color_input.rb +37 -0
  130. data/lib/simple_form_extension/inputs/date_time_input.rb +48 -0
  131. data/lib/simple_form_extension/inputs/file_input.rb +41 -0
  132. data/lib/simple_form_extension/inputs/image_input.rb +110 -0
  133. data/lib/simple_form_extension/inputs/numeric_input.rb +27 -0
  134. data/lib/simple_form_extension/inputs/selectize_input.rb +210 -0
  135. data/lib/simple_form_extension/inputs/slider_input.rb +30 -0
  136. data/lib/simple_form_extension/inputs.rb +16 -0
  137. data/lib/simple_form_extension/railtie.rb +21 -0
  138. data/lib/simple_form_extension/resource_name_helper.rb +9 -0
  139. data/lib/simple_form_extension/translations.rb +7 -0
  140. data/lib/simple_form_extension/version.rb +3 -0
  141. data/lib/simple_form_extension.rb +30 -0
  142. data/vendor/assets/images/simple_form_extension/bootstrap-colorpicker/alpha-horizontal.png +0 -0
  143. data/vendor/assets/images/simple_form_extension/bootstrap-colorpicker/alpha.png +0 -0
  144. data/vendor/assets/images/simple_form_extension/bootstrap-colorpicker/hue-horizontal.png +0 -0
  145. data/vendor/assets/images/simple_form_extension/bootstrap-colorpicker/hue.png +0 -0
  146. data/vendor/assets/images/simple_form_extension/bootstrap-colorpicker/saturation.png +0 -0
  147. data/vendor/assets/stylesheets/bootstrap-colorpicker.scss +227 -0
  148. data/vendor/assets/stylesheets/bootstrap-slider.scss +246 -0
  149. data/vendor/assets/stylesheets/bootstrap.scss +6032 -0
  150. data/vendor/assets/stylesheets/jquery.datetimepicker.scss +568 -0
  151. metadata +120 -188
  152. data/app/assets/javascripts/admin/app.coffee +0 -1
  153. data/app/assets/javascripts/para/admin/async-progress.coffee +0 -29
  154. data/app/assets/javascripts/para/admin/filters-form.coffee +0 -11
  155. data/app/assets/javascripts/para/admin/job-tracker.coffee +0 -39
  156. data/app/assets/javascripts/para/admin/table.coffee +0 -44
  157. data/app/assets/javascripts/para/admin/tabs.coffee +0 -63
  158. data/app/assets/javascripts/para/admin/theme_actions.coffee +0 -25
  159. data/app/assets/javascripts/para/admin/tree.coffee +0 -105
  160. data/app/assets/javascripts/para/admin.coffee +0 -22
  161. data/app/assets/javascripts/para/application.js +0 -13
  162. data/app/assets/javascripts/para/inputs/material-input.coffee +0 -4
  163. data/app/assets/javascripts/para/inputs/multi-select-input.coffee +0 -174
  164. data/app/assets/javascripts/para/inputs/nested_many.coffee +0 -108
  165. data/app/assets/javascripts/para/lib/ajax.coffee +0 -11
  166. data/app/assets/javascripts/para/lib/remote-file-forms.coffee +0 -59
  167. data/app/assets/javascripts/para/lib/turbolinks-forms.coffee +0 -23
  168. data/app/assets/javascripts/para/lib/turbolinks-loading.coffee +0 -25
  169. data/app/assets/javascripts/para/lib/turbolinks-reloader.coffee +0 -19
  170. data/app/assets/stylesheets/para/admin/main.sass +0 -33
  171. data/app/assets/stylesheets/para/admin/src/_affix.sass +0 -4
  172. data/app/assets/stylesheets/para/admin/src/_alert.sass +0 -17
  173. data/app/assets/stylesheets/para/admin/src/_base.sass +0 -54
  174. data/app/assets/stylesheets/para/admin/src/_breadcrumb.sass +0 -32
  175. data/app/assets/stylesheets/para/admin/src/_buttons.sass +0 -107
  176. data/app/assets/stylesheets/para/admin/src/_checkable.sass +0 -94
  177. data/app/assets/stylesheets/para/admin/src/_common.sass +0 -202
  178. data/app/assets/stylesheets/para/admin/src/_dropdown.sass +0 -40
  179. data/app/assets/stylesheets/para/admin/src/_form.sass +0 -299
  180. data/app/assets/stylesheets/para/admin/src/_list.sass +0 -89
  181. data/app/assets/stylesheets/para/admin/src/_mixins.sass +0 -113
  182. data/app/assets/stylesheets/para/admin/src/_multi-select.sass +0 -91
  183. data/app/assets/stylesheets/para/admin/src/_navigation.sass +0 -171
  184. data/app/assets/stylesheets/para/admin/src/_navtabs.sass +0 -58
  185. data/app/assets/stylesheets/para/admin/src/_nested-many.sass +0 -75
  186. data/app/assets/stylesheets/para/admin/src/_nested_one.sass +0 -22
  187. data/app/assets/stylesheets/para/admin/src/_orderable.sass +0 -44
  188. data/app/assets/stylesheets/para/admin/src/_page-loading.sass +0 -39
  189. data/app/assets/stylesheets/para/admin/src/_pagination.sass +0 -34
  190. data/app/assets/stylesheets/para/admin/src/_panel.sass +0 -55
  191. data/app/assets/stylesheets/para/admin/src/_responsive.sass +0 -117
  192. data/app/assets/stylesheets/para/admin/src/_sorting.sass +0 -36
  193. data/app/assets/stylesheets/para/admin/src/_statcard.sass +0 -41
  194. data/app/assets/stylesheets/para/admin/src/_table.sass +0 -33
  195. data/app/assets/stylesheets/para/admin/src/_tree.sass +0 -52
  196. data/app/assets/stylesheets/para/admin.sass +0 -12
  197. data/app/assets/stylesheets/para/lib/compass/_support.scss +0 -447
  198. data/app/assets/stylesheets/para/lib/compass/css3/_box-shadow.scss +0 -88
  199. data/app/assets/stylesheets/para/lib/compass/css3/_images.scss +0 -152
  200. data/app/assets/stylesheets/para/lib/compass/css3/_inline-block.scss +0 -31
  201. data/app/assets/stylesheets/para/lib/compass/css3/_text-shadow.scss +0 -82
  202. data/app/assets/stylesheets/para/lib/compass/css3/_transform.scss +0 -590
  203. data/app/assets/stylesheets/para/lib/compass/css3/_transition.scss +0 -190
  204. data/app/assets/stylesheets/para/lib/compass/css3/_user-interface.scss +0 -71
  205. data/app/assets/stylesheets/para/lib/compass/utilities/general/_hacks.scss +0 -65
  206. data/app/assets/stylesheets/para/lib/datetimepicker.sass +0 -15
  207. data/app/assets/stylesheets/para/lib/fuelux.sass +0 -40
  208. data/app/assets/stylesheets/para/lib/jasny-bootstrap.sass +0 -97
  209. data/app/assets/stylesheets/para/lib/redactor.sass +0 -86
  210. data/app/assets/stylesheets/para/lib/selectize.sass +0 -111
  211. data/app/assets/stylesheets/para/lib/slider.sass +0 -12
  212. data/app/assets/stylesheets/para/plugins-includes.sass.erb +0 -1
  213. data/lib/para/attribute_field/redactor.rb +0 -22
  214. data/lib/para/ext/request_iframe_xhr.rb +0 -17
  215. data/lib/para/iframe_transport/middleware.rb +0 -58
  216. data/lib/para/iframe_transport.rb +0 -7
  217. data/lib/para/model_field_parsers/redactor.rb +0 -19
  218. data/vendor/assets/javascripts/jquery.iframe-transport.js +0 -260
  219. data/vendor/assets/javascripts/jquery.remote-modal-form.coffee +0 -145
  220. /data/app/assets/stylesheets/admin/{app.sass → app.scss} +0 -0
  221. /data/app/{assets/javascripts → javascripts}/para/plugins-includes.js.erb +0 -0
  222. /data/{vendor/assets/javascripts → app/javascripts/para/vendor}/Sortable.js +0 -0
  223. /data/{vendor/assets/javascripts → app/javascripts/para/vendor}/jasny-bootstrap.js +0 -0
  224. /data/{vendor/assets/javascripts → app/javascripts/para/vendor}/jquery.scrollto.js +0 -0
  225. /data/{vendor/assets/javascripts → app/javascripts/para/vendor}/jquery.sortable.js +0 -0
  226. /data/vendor/assets/stylesheets/{animate.css → animate.scss} +0 -0
  227. /data/vendor/assets/stylesheets/{hint.css → hint.scss} +0 -0
  228. /data/vendor/assets/stylesheets/{jasny-bootstrap.css → jasny-bootstrap.scss} +0 -0
@@ -0,0 +1,1610 @@
1
+ /*! =======================================================
2
+ VERSION 6.1.8
3
+ ========================================================= */
4
+ "use strict";
5
+
6
+ function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
7
+
8
+ /*! =========================================================
9
+ * bootstrap-slider.js
10
+ *
11
+ * Maintainers:
12
+ * Kyle Kemp
13
+ * - Twitter: @seiyria
14
+ * - Github: seiyria
15
+ * Rohit Kalkur
16
+ * - Twitter: @Rovolutionary
17
+ * - Github: rovolution
18
+ *
19
+ * =========================================================
20
+ *
21
+ * Licensed under the Apache License, Version 2.0 (the "License");
22
+ * you may not use this file except in compliance with the License.
23
+ * You may obtain a copy of the License at
24
+ *
25
+ * http://www.apache.org/licenses/LICENSE-2.0
26
+ *
27
+ * Unless required by applicable law or agreed to in writing, software
28
+ * distributed under the License is distributed on an "AS IS" BASIS,
29
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30
+ * See the License for the specific language governing permissions and
31
+ * limitations under the License.
32
+ * ========================================================= */
33
+
34
+ /**
35
+ * Bridget makes jQuery widgets
36
+ * v1.0.1
37
+ * MIT license
38
+ */
39
+
40
+ (function (factory) {
41
+ if (typeof define === "function" && define.amd) {
42
+ define(["jquery"], factory);
43
+ } else if ((typeof module === "undefined" ? "undefined" : _typeof(module)) === "object" && module.exports) {
44
+ var jQuery;
45
+ try {
46
+ jQuery = require("jquery");
47
+ } catch (err) {
48
+ jQuery = null;
49
+ }
50
+ module.exports = factory(jQuery);
51
+ } else if (window) {
52
+ window.Slider = factory(window.jQuery);
53
+ }
54
+ })(function ($) {
55
+ // Reference to Slider constructor
56
+ var Slider;
57
+
58
+ (function ($) {
59
+
60
+ 'use strict';
61
+
62
+ // -------------------------- utils -------------------------- //
63
+
64
+ var slice = Array.prototype.slice;
65
+
66
+ function noop() {}
67
+
68
+ // -------------------------- definition -------------------------- //
69
+
70
+ function defineBridget($) {
71
+
72
+ // bail if no jQuery
73
+ if (!$) {
74
+ return;
75
+ }
76
+
77
+ // -------------------------- addOptionMethod -------------------------- //
78
+
79
+ /**
80
+ * adds option method -> $().plugin('option', {...})
81
+ * @param {Function} PluginClass - constructor class
82
+ */
83
+ function addOptionMethod(PluginClass) {
84
+ // don't overwrite original option method
85
+ if (PluginClass.prototype.option) {
86
+ return;
87
+ }
88
+
89
+ // option setter
90
+ PluginClass.prototype.option = function (opts) {
91
+ // bail out if not an object
92
+ if (!$.isPlainObject(opts)) {
93
+ return;
94
+ }
95
+ this.options = $.extend(true, this.options, opts);
96
+ };
97
+ }
98
+
99
+ // -------------------------- plugin bridge -------------------------- //
100
+
101
+ // helper function for logging errors
102
+ // $.error breaks jQuery chaining
103
+ var logError = typeof console === 'undefined' ? noop : function (message) {
104
+ console.error(message);
105
+ };
106
+
107
+ /**
108
+ * jQuery plugin bridge, access methods like $elem.plugin('method')
109
+ * @param {String} namespace - plugin name
110
+ * @param {Function} PluginClass - constructor class
111
+ */
112
+ function bridge(namespace, PluginClass) {
113
+ // add to jQuery fn namespace
114
+ $.fn[namespace] = function (options) {
115
+ if (typeof options === 'string') {
116
+ // call plugin method when first argument is a string
117
+ // get arguments for method
118
+ var args = slice.call(arguments, 1);
119
+
120
+ for (var i = 0, len = this.length; i < len; i++) {
121
+ var elem = this[i];
122
+ var instance = $.data(elem, namespace);
123
+ if (!instance) {
124
+ logError("cannot call methods on " + namespace + " prior to initialization; " + "attempted to call '" + options + "'");
125
+ continue;
126
+ }
127
+ if (!$.isFunction(instance[options]) || options.charAt(0) === '_') {
128
+ logError("no such method '" + options + "' for " + namespace + " instance");
129
+ continue;
130
+ }
131
+
132
+ // trigger method with arguments
133
+ var returnValue = instance[options].apply(instance, args);
134
+
135
+ // break look and return first value if provided
136
+ if (returnValue !== undefined && returnValue !== instance) {
137
+ return returnValue;
138
+ }
139
+ }
140
+ // return this if no return value
141
+ return this;
142
+ } else {
143
+ var objects = this.map(function () {
144
+ var instance = $.data(this, namespace);
145
+ if (instance) {
146
+ // apply options & init
147
+ instance.option(options);
148
+ instance._init();
149
+ } else {
150
+ // initialize new instance
151
+ instance = new PluginClass(this, options);
152
+ $.data(this, namespace, instance);
153
+ }
154
+ return $(this);
155
+ });
156
+
157
+ if (!objects || objects.length > 1) {
158
+ return objects;
159
+ } else {
160
+ return objects[0];
161
+ }
162
+ }
163
+ };
164
+ }
165
+
166
+ // -------------------------- bridget -------------------------- //
167
+
168
+ /**
169
+ * converts a Prototypical class into a proper jQuery plugin
170
+ * the class must have a ._init method
171
+ * @param {String} namespace - plugin name, used in $().pluginName
172
+ * @param {Function} PluginClass - constructor class
173
+ */
174
+ $.bridget = function (namespace, PluginClass) {
175
+ addOptionMethod(PluginClass);
176
+ bridge(namespace, PluginClass);
177
+ };
178
+
179
+ return $.bridget;
180
+ }
181
+
182
+ // get jquery from browser global
183
+ defineBridget($);
184
+ })($);
185
+
186
+ /*************************************************
187
+ BOOTSTRAP-SLIDER SOURCE CODE
188
+ **************************************************/
189
+
190
+ (function ($) {
191
+
192
+ var ErrorMsgs = {
193
+ formatInvalidInputErrorMsg: function formatInvalidInputErrorMsg(input) {
194
+ return "Invalid input value '" + input + "' passed in";
195
+ },
196
+ callingContextNotSliderInstance: "Calling context element does not have instance of Slider bound to it. Check your code to make sure the JQuery object returned from the call to the slider() initializer is calling the method"
197
+ };
198
+
199
+ var SliderScale = {
200
+ linear: {
201
+ toValue: function toValue(percentage) {
202
+ var rawValue = percentage / 100 * (this.options.max - this.options.min);
203
+ var shouldAdjustWithBase = true;
204
+ if (this.options.ticks_positions.length > 0) {
205
+ var minv,
206
+ maxv,
207
+ minp,
208
+ maxp = 0;
209
+ for (var i = 1; i < this.options.ticks_positions.length; i++) {
210
+ if (percentage <= this.options.ticks_positions[i]) {
211
+ minv = this.options.ticks[i - 1];
212
+ minp = this.options.ticks_positions[i - 1];
213
+ maxv = this.options.ticks[i];
214
+ maxp = this.options.ticks_positions[i];
215
+
216
+ break;
217
+ }
218
+ }
219
+ var partialPercentage = (percentage - minp) / (maxp - minp);
220
+ rawValue = minv + partialPercentage * (maxv - minv);
221
+ shouldAdjustWithBase = false;
222
+ }
223
+
224
+ var adjustment = shouldAdjustWithBase ? this.options.min : 0;
225
+ var value = adjustment + Math.round(rawValue / this.options.step) * this.options.step;
226
+ if (value < this.options.min) {
227
+ return this.options.min;
228
+ } else if (value > this.options.max) {
229
+ return this.options.max;
230
+ } else {
231
+ return value;
232
+ }
233
+ },
234
+ toPercentage: function toPercentage(value) {
235
+ if (this.options.max === this.options.min) {
236
+ return 0;
237
+ }
238
+
239
+ if (this.options.ticks_positions.length > 0) {
240
+ var minv,
241
+ maxv,
242
+ minp,
243
+ maxp = 0;
244
+ for (var i = 0; i < this.options.ticks.length; i++) {
245
+ if (value <= this.options.ticks[i]) {
246
+ minv = i > 0 ? this.options.ticks[i - 1] : 0;
247
+ minp = i > 0 ? this.options.ticks_positions[i - 1] : 0;
248
+ maxv = this.options.ticks[i];
249
+ maxp = this.options.ticks_positions[i];
250
+
251
+ break;
252
+ }
253
+ }
254
+ if (i > 0) {
255
+ var partialPercentage = (value - minv) / (maxv - minv);
256
+ return minp + partialPercentage * (maxp - minp);
257
+ }
258
+ }
259
+
260
+ return 100 * (value - this.options.min) / (this.options.max - this.options.min);
261
+ }
262
+ },
263
+
264
+ logarithmic: {
265
+ /* Based on http://stackoverflow.com/questions/846221/logarithmic-slider */
266
+ toValue: function toValue(percentage) {
267
+ var min = this.options.min === 0 ? 0 : Math.log(this.options.min);
268
+ var max = Math.log(this.options.max);
269
+ var value = Math.exp(min + (max - min) * percentage / 100);
270
+ value = this.options.min + Math.round((value - this.options.min) / this.options.step) * this.options.step;
271
+ /* Rounding to the nearest step could exceed the min or
272
+ * max, so clip to those values. */
273
+ if (value < this.options.min) {
274
+ return this.options.min;
275
+ } else if (value > this.options.max) {
276
+ return this.options.max;
277
+ } else {
278
+ return value;
279
+ }
280
+ },
281
+ toPercentage: function toPercentage(value) {
282
+ if (this.options.max === this.options.min) {
283
+ return 0;
284
+ } else {
285
+ var max = Math.log(this.options.max);
286
+ var min = this.options.min === 0 ? 0 : Math.log(this.options.min);
287
+ var v = value === 0 ? 0 : Math.log(value);
288
+ return 100 * (v - min) / (max - min);
289
+ }
290
+ }
291
+ }
292
+ };
293
+
294
+ /*************************************************
295
+ CONSTRUCTOR
296
+ **************************************************/
297
+ Slider = function (element, options) {
298
+ createNewSlider.call(this, element, options);
299
+ return this;
300
+ };
301
+
302
+ function createNewSlider(element, options) {
303
+
304
+ /*
305
+ The internal state object is used to store data about the current 'state' of slider.
306
+ This includes values such as the `value`, `enabled`, etc...
307
+ */
308
+ this._state = {
309
+ value: null,
310
+ enabled: null,
311
+ offset: null,
312
+ size: null,
313
+ percentage: null,
314
+ inDrag: false,
315
+ over: false
316
+ };
317
+
318
+ if (typeof element === "string") {
319
+ this.element = document.querySelector(element);
320
+ } else if (element instanceof HTMLElement) {
321
+ this.element = element;
322
+ }
323
+
324
+ /*************************************************
325
+ Process Options
326
+ **************************************************/
327
+ options = options ? options : {};
328
+ var optionTypes = Object.keys(this.defaultOptions);
329
+
330
+ for (var i = 0; i < optionTypes.length; i++) {
331
+ var optName = optionTypes[i];
332
+
333
+ // First check if an option was passed in via the constructor
334
+ var val = options[optName];
335
+ // If no data attrib, then check data atrributes
336
+ val = typeof val !== 'undefined' ? val : getDataAttrib(this.element, optName);
337
+ // Finally, if nothing was specified, use the defaults
338
+ val = val !== null ? val : this.defaultOptions[optName];
339
+
340
+ // Set all options on the instance of the Slider
341
+ if (!this.options) {
342
+ this.options = {};
343
+ }
344
+ this.options[optName] = val;
345
+ }
346
+
347
+ /*
348
+ Validate `tooltip_position` against 'orientation`
349
+ - if `tooltip_position` is incompatible with orientation, swith it to a default compatible with specified `orientation`
350
+ -- default for "vertical" -> "right"
351
+ -- default for "horizontal" -> "left"
352
+ */
353
+ if (this.options.orientation === "vertical" && (this.options.tooltip_position === "top" || this.options.tooltip_position === "bottom")) {
354
+
355
+ this.options.tooltip_position = "right";
356
+ } else if (this.options.orientation === "horizontal" && (this.options.tooltip_position === "left" || this.options.tooltip_position === "right")) {
357
+
358
+ this.options.tooltip_position = "top";
359
+ }
360
+
361
+ function getDataAttrib(element, optName) {
362
+ var dataName = "data-slider-" + optName.replace(/_/g, '-');
363
+ var dataValString = element.getAttribute(dataName);
364
+
365
+ try {
366
+ return JSON.parse(dataValString);
367
+ } catch (err) {
368
+ return dataValString;
369
+ }
370
+ }
371
+
372
+ /*************************************************
373
+ Create Markup
374
+ **************************************************/
375
+
376
+ var origWidth = this.element.style.width;
377
+ var updateSlider = false;
378
+ var parent = this.element.parentNode;
379
+ var sliderTrackSelection;
380
+ var sliderTrackLow, sliderTrackHigh;
381
+ var sliderMinHandle;
382
+ var sliderMaxHandle;
383
+
384
+ if (this.sliderElem) {
385
+ updateSlider = true;
386
+ } else {
387
+ /* Create elements needed for slider */
388
+ this.sliderElem = document.createElement("div");
389
+ this.sliderElem.className = "slider";
390
+
391
+ /* Create slider track elements */
392
+ var sliderTrack = document.createElement("div");
393
+ sliderTrack.className = "slider-track";
394
+
395
+ sliderTrackLow = document.createElement("div");
396
+ sliderTrackLow.className = "slider-track-low";
397
+
398
+ sliderTrackSelection = document.createElement("div");
399
+ sliderTrackSelection.className = "slider-selection";
400
+
401
+ sliderTrackHigh = document.createElement("div");
402
+ sliderTrackHigh.className = "slider-track-high";
403
+
404
+ sliderMinHandle = document.createElement("div");
405
+ sliderMinHandle.className = "slider-handle min-slider-handle";
406
+ sliderMinHandle.setAttribute('role', 'slider');
407
+ sliderMinHandle.setAttribute('aria-valuemin', this.options.min);
408
+ sliderMinHandle.setAttribute('aria-valuemax', this.options.max);
409
+
410
+ sliderMaxHandle = document.createElement("div");
411
+ sliderMaxHandle.className = "slider-handle max-slider-handle";
412
+ sliderMaxHandle.setAttribute('role', 'slider');
413
+ sliderMaxHandle.setAttribute('aria-valuemin', this.options.min);
414
+ sliderMaxHandle.setAttribute('aria-valuemax', this.options.max);
415
+
416
+ sliderTrack.appendChild(sliderTrackLow);
417
+ sliderTrack.appendChild(sliderTrackSelection);
418
+ sliderTrack.appendChild(sliderTrackHigh);
419
+
420
+ /* Add aria-labelledby to handle's */
421
+ var isLabelledbyArray = Array.isArray(this.options.labelledby);
422
+ if (isLabelledbyArray && this.options.labelledby[0]) {
423
+ sliderMinHandle.setAttribute('aria-labelledby', this.options.labelledby[0]);
424
+ }
425
+ if (isLabelledbyArray && this.options.labelledby[1]) {
426
+ sliderMaxHandle.setAttribute('aria-labelledby', this.options.labelledby[1]);
427
+ }
428
+ if (!isLabelledbyArray && this.options.labelledby) {
429
+ sliderMinHandle.setAttribute('aria-labelledby', this.options.labelledby);
430
+ sliderMaxHandle.setAttribute('aria-labelledby', this.options.labelledby);
431
+ }
432
+
433
+ /* Create ticks */
434
+ this.ticks = [];
435
+ if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
436
+ for (i = 0; i < this.options.ticks.length; i++) {
437
+ var tick = document.createElement('div');
438
+ tick.className = 'slider-tick';
439
+
440
+ this.ticks.push(tick);
441
+ sliderTrack.appendChild(tick);
442
+ }
443
+
444
+ sliderTrackSelection.className += " tick-slider-selection";
445
+ }
446
+
447
+ sliderTrack.appendChild(sliderMinHandle);
448
+ sliderTrack.appendChild(sliderMaxHandle);
449
+
450
+ this.tickLabels = [];
451
+ if (Array.isArray(this.options.ticks_labels) && this.options.ticks_labels.length > 0) {
452
+ this.tickLabelContainer = document.createElement('div');
453
+ this.tickLabelContainer.className = 'slider-tick-label-container';
454
+
455
+ for (i = 0; i < this.options.ticks_labels.length; i++) {
456
+ var label = document.createElement('div');
457
+ var noTickPositionsSpecified = this.options.ticks_positions.length === 0;
458
+ var tickLabelsIndex = this.options.reversed && noTickPositionsSpecified ? this.options.ticks_labels.length - (i + 1) : i;
459
+ label.className = 'slider-tick-label';
460
+ label.innerHTML = this.options.ticks_labels[tickLabelsIndex];
461
+
462
+ this.tickLabels.push(label);
463
+ this.tickLabelContainer.appendChild(label);
464
+ }
465
+ }
466
+
467
+ var createAndAppendTooltipSubElements = function createAndAppendTooltipSubElements(tooltipElem) {
468
+ var arrow = document.createElement("div");
469
+ arrow.className = "tooltip-arrow";
470
+
471
+ var inner = document.createElement("div");
472
+ inner.className = "tooltip-inner";
473
+
474
+ tooltipElem.appendChild(arrow);
475
+ tooltipElem.appendChild(inner);
476
+ };
477
+
478
+ /* Create tooltip elements */
479
+ var sliderTooltip = document.createElement("div");
480
+ sliderTooltip.className = "tooltip tooltip-main";
481
+ sliderTooltip.setAttribute('role', 'presentation');
482
+ createAndAppendTooltipSubElements(sliderTooltip);
483
+
484
+ var sliderTooltipMin = document.createElement("div");
485
+ sliderTooltipMin.className = "tooltip tooltip-min";
486
+ sliderTooltipMin.setAttribute('role', 'presentation');
487
+ createAndAppendTooltipSubElements(sliderTooltipMin);
488
+
489
+ var sliderTooltipMax = document.createElement("div");
490
+ sliderTooltipMax.className = "tooltip tooltip-max";
491
+ sliderTooltipMax.setAttribute('role', 'presentation');
492
+ createAndAppendTooltipSubElements(sliderTooltipMax);
493
+
494
+ /* Append components to sliderElem */
495
+ this.sliderElem.appendChild(sliderTrack);
496
+ this.sliderElem.appendChild(sliderTooltip);
497
+ this.sliderElem.appendChild(sliderTooltipMin);
498
+ this.sliderElem.appendChild(sliderTooltipMax);
499
+
500
+ if (this.tickLabelContainer) {
501
+ this.sliderElem.appendChild(this.tickLabelContainer);
502
+ }
503
+
504
+ /* Append slider element to parent container, right before the original <input> element */
505
+ parent.insertBefore(this.sliderElem, this.element);
506
+
507
+ /* Hide original <input> element */
508
+ this.element.style.display = "none";
509
+ }
510
+ /* If JQuery exists, cache JQ references */
511
+ if ($) {
512
+ this.$element = $(this.element);
513
+ this.$sliderElem = $(this.sliderElem);
514
+ }
515
+
516
+ /*************************************************
517
+ Setup
518
+ **************************************************/
519
+ this.eventToCallbackMap = {};
520
+ this.sliderElem.id = this.options.id;
521
+
522
+ this.touchCapable = 'ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch;
523
+
524
+ this.touchX = 0;
525
+ this.touchY = 0;
526
+
527
+ this.tooltip = this.sliderElem.querySelector('.tooltip-main');
528
+ this.tooltipInner = this.tooltip.querySelector('.tooltip-inner');
529
+
530
+ this.tooltip_min = this.sliderElem.querySelector('.tooltip-min');
531
+ this.tooltipInner_min = this.tooltip_min.querySelector('.tooltip-inner');
532
+
533
+ this.tooltip_max = this.sliderElem.querySelector('.tooltip-max');
534
+ this.tooltipInner_max = this.tooltip_max.querySelector('.tooltip-inner');
535
+
536
+ if (SliderScale[this.options.scale]) {
537
+ this.options.scale = SliderScale[this.options.scale];
538
+ }
539
+
540
+ if (updateSlider === true) {
541
+ // Reset classes
542
+ this._removeClass(this.sliderElem, 'slider-horizontal');
543
+ this._removeClass(this.sliderElem, 'slider-vertical');
544
+ this._removeClass(this.tooltip, 'hide');
545
+ this._removeClass(this.tooltip_min, 'hide');
546
+ this._removeClass(this.tooltip_max, 'hide');
547
+
548
+ // Undo existing inline styles for track
549
+ ["left", "top", "width", "height"].forEach(function (prop) {
550
+ this._removeProperty(this.trackLow, prop);
551
+ this._removeProperty(this.trackSelection, prop);
552
+ this._removeProperty(this.trackHigh, prop);
553
+ }, this);
554
+
555
+ // Undo inline styles on handles
556
+ [this.handle1, this.handle2].forEach(function (handle) {
557
+ this._removeProperty(handle, 'left');
558
+ this._removeProperty(handle, 'top');
559
+ }, this);
560
+
561
+ // Undo inline styles and classes on tooltips
562
+ [this.tooltip, this.tooltip_min, this.tooltip_max].forEach(function (tooltip) {
563
+ this._removeProperty(tooltip, 'left');
564
+ this._removeProperty(tooltip, 'top');
565
+ this._removeProperty(tooltip, 'margin-left');
566
+ this._removeProperty(tooltip, 'margin-top');
567
+
568
+ this._removeClass(tooltip, 'right');
569
+ this._removeClass(tooltip, 'top');
570
+ }, this);
571
+ }
572
+
573
+ if (this.options.orientation === 'vertical') {
574
+ this._addClass(this.sliderElem, 'slider-vertical');
575
+ this.stylePos = 'top';
576
+ this.mousePos = 'pageY';
577
+ this.sizePos = 'offsetHeight';
578
+ } else {
579
+ this._addClass(this.sliderElem, 'slider-horizontal');
580
+ this.sliderElem.style.width = origWidth;
581
+ this.options.orientation = 'horizontal';
582
+ this.stylePos = 'left';
583
+ this.mousePos = 'pageX';
584
+ this.sizePos = 'offsetWidth';
585
+ }
586
+ this._setTooltipPosition();
587
+ /* In case ticks are specified, overwrite the min and max bounds */
588
+ if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
589
+ this.options.max = Math.max.apply(Math, this.options.ticks);
590
+ this.options.min = Math.min.apply(Math, this.options.ticks);
591
+ }
592
+
593
+ if (Array.isArray(this.options.value)) {
594
+ this.options.range = true;
595
+ this._state.value = this.options.value;
596
+ } else if (this.options.range) {
597
+ // User wants a range, but value is not an array
598
+ this._state.value = [this.options.value, this.options.max];
599
+ } else {
600
+ this._state.value = this.options.value;
601
+ }
602
+
603
+ this.trackLow = sliderTrackLow || this.trackLow;
604
+ this.trackSelection = sliderTrackSelection || this.trackSelection;
605
+ this.trackHigh = sliderTrackHigh || this.trackHigh;
606
+
607
+ if (this.options.selection === 'none') {
608
+ this._addClass(this.trackLow, 'hide');
609
+ this._addClass(this.trackSelection, 'hide');
610
+ this._addClass(this.trackHigh, 'hide');
611
+ }
612
+
613
+ this.handle1 = sliderMinHandle || this.handle1;
614
+ this.handle2 = sliderMaxHandle || this.handle2;
615
+
616
+ if (updateSlider === true) {
617
+ // Reset classes
618
+ this._removeClass(this.handle1, 'round triangle');
619
+ this._removeClass(this.handle2, 'round triangle hide');
620
+
621
+ for (i = 0; i < this.ticks.length; i++) {
622
+ this._removeClass(this.ticks[i], 'round triangle hide');
623
+ }
624
+ }
625
+
626
+ var availableHandleModifiers = ['round', 'triangle', 'custom'];
627
+ var isValidHandleType = availableHandleModifiers.indexOf(this.options.handle) !== -1;
628
+ if (isValidHandleType) {
629
+ this._addClass(this.handle1, this.options.handle);
630
+ this._addClass(this.handle2, this.options.handle);
631
+
632
+ for (i = 0; i < this.ticks.length; i++) {
633
+ this._addClass(this.ticks[i], this.options.handle);
634
+ }
635
+ }
636
+
637
+ this._state.offset = this._offset(this.sliderElem);
638
+ this._state.size = this.sliderElem[this.sizePos];
639
+ this.setValue(this._state.value);
640
+
641
+ /******************************************
642
+ Bind Event Listeners
643
+ ******************************************/
644
+
645
+ // Bind keyboard handlers
646
+ this.handle1Keydown = this._keydown.bind(this, 0);
647
+ this.handle1.addEventListener("keydown", this.handle1Keydown, false);
648
+
649
+ this.handle2Keydown = this._keydown.bind(this, 1);
650
+ this.handle2.addEventListener("keydown", this.handle2Keydown, false);
651
+
652
+ this.mousedown = this._mousedown.bind(this);
653
+ this.touchstart = this._touchstart.bind(this);
654
+ this.touchmove = this._touchmove.bind(this);
655
+
656
+ if (this.touchCapable) {
657
+ // Bind touch handlers
658
+ this.sliderElem.addEventListener("touchstart", this.touchstart, false);
659
+ this.sliderElem.addEventListener("touchmove", this.touchmove, false);
660
+ }
661
+ this.sliderElem.addEventListener("mousedown", this.mousedown, false);
662
+
663
+ // Bind window handlers
664
+ this.resize = this._resize.bind(this);
665
+ window.addEventListener("resize", this.resize, false);
666
+
667
+ // Bind tooltip-related handlers
668
+ if (this.options.tooltip === 'hide') {
669
+ this._addClass(this.tooltip, 'hide');
670
+ this._addClass(this.tooltip_min, 'hide');
671
+ this._addClass(this.tooltip_max, 'hide');
672
+ } else if (this.options.tooltip === 'always') {
673
+ this._showTooltip();
674
+ this._alwaysShowTooltip = true;
675
+ } else {
676
+ this.showTooltip = this._showTooltip.bind(this);
677
+ this.hideTooltip = this._hideTooltip.bind(this);
678
+
679
+ this.sliderElem.addEventListener("mouseenter", this.showTooltip, false);
680
+ this.sliderElem.addEventListener("mouseleave", this.hideTooltip, false);
681
+
682
+ this.handle1.addEventListener("focus", this.showTooltip, false);
683
+ this.handle1.addEventListener("blur", this.hideTooltip, false);
684
+
685
+ this.handle2.addEventListener("focus", this.showTooltip, false);
686
+ this.handle2.addEventListener("blur", this.hideTooltip, false);
687
+ }
688
+
689
+ if (this.options.enabled) {
690
+ this.enable();
691
+ } else {
692
+ this.disable();
693
+ }
694
+ }
695
+
696
+ /*************************************************
697
+ INSTANCE PROPERTIES/METHODS
698
+ - Any methods bound to the prototype are considered
699
+ part of the plugin's `public` interface
700
+ **************************************************/
701
+ Slider.prototype = {
702
+ _init: function _init() {}, // NOTE: Must exist to support bridget
703
+
704
+ constructor: Slider,
705
+
706
+ defaultOptions: {
707
+ id: "",
708
+ min: 0,
709
+ max: 10,
710
+ step: 1,
711
+ precision: 0,
712
+ orientation: 'horizontal',
713
+ value: 5,
714
+ range: false,
715
+ selection: 'before',
716
+ tooltip: 'show',
717
+ tooltip_split: false,
718
+ handle: 'round',
719
+ reversed: false,
720
+ enabled: true,
721
+ formatter: function formatter(val) {
722
+ if (Array.isArray(val)) {
723
+ return val[0] + " : " + val[1];
724
+ } else {
725
+ return val;
726
+ }
727
+ },
728
+ natural_arrow_keys: false,
729
+ ticks: [],
730
+ ticks_positions: [],
731
+ ticks_labels: [],
732
+ ticks_snap_bounds: 0,
733
+ scale: 'linear',
734
+ focus: false,
735
+ tooltip_position: null,
736
+ labelledby: null
737
+ },
738
+
739
+ getElement: function getElement() {
740
+ return this.sliderElem;
741
+ },
742
+
743
+ getValue: function getValue() {
744
+ if (this.options.range) {
745
+ return this._state.value;
746
+ } else {
747
+ return this._state.value[0];
748
+ }
749
+ },
750
+
751
+ setValue: function setValue(val, triggerSlideEvent, triggerChangeEvent) {
752
+ if (!val) {
753
+ val = 0;
754
+ }
755
+ var oldValue = this.getValue();
756
+ this._state.value = this._validateInputValue(val);
757
+ var applyPrecision = this._applyPrecision.bind(this);
758
+
759
+ if (this.options.range) {
760
+ this._state.value[0] = applyPrecision(this._state.value[0]);
761
+ this._state.value[1] = applyPrecision(this._state.value[1]);
762
+
763
+ this._state.value[0] = Math.max(this.options.min, Math.min(this.options.max, this._state.value[0]));
764
+ this._state.value[1] = Math.max(this.options.min, Math.min(this.options.max, this._state.value[1]));
765
+ } else {
766
+ this._state.value = applyPrecision(this._state.value);
767
+ this._state.value = [Math.max(this.options.min, Math.min(this.options.max, this._state.value))];
768
+ this._addClass(this.handle2, 'hide');
769
+ if (this.options.selection === 'after') {
770
+ this._state.value[1] = this.options.max;
771
+ } else {
772
+ this._state.value[1] = this.options.min;
773
+ }
774
+ }
775
+
776
+ if (this.options.max > this.options.min) {
777
+ this._state.percentage = [this._toPercentage(this._state.value[0]), this._toPercentage(this._state.value[1]), this.options.step * 100 / (this.options.max - this.options.min)];
778
+ } else {
779
+ this._state.percentage = [0, 0, 100];
780
+ }
781
+
782
+ this._layout();
783
+ var newValue = this.options.range ? this._state.value : this._state.value[0];
784
+
785
+ this._setDataVal(newValue);
786
+ if (triggerSlideEvent === true) {
787
+ this._trigger('slide', newValue);
788
+ }
789
+ if (oldValue !== newValue && triggerChangeEvent === true) {
790
+ this._trigger('change', {
791
+ oldValue: oldValue,
792
+ newValue: newValue
793
+ });
794
+ }
795
+
796
+ return this;
797
+ },
798
+
799
+ destroy: function destroy() {
800
+ // Remove event handlers on slider elements
801
+ this._removeSliderEventHandlers();
802
+
803
+ // Remove the slider from the DOM
804
+ this.sliderElem.parentNode.removeChild(this.sliderElem);
805
+ /* Show original <input> element */
806
+ this.element.style.display = "";
807
+
808
+ // Clear out custom event bindings
809
+ this._cleanUpEventCallbacksMap();
810
+
811
+ // Remove data values
812
+ this.element.removeAttribute("data");
813
+
814
+ // Remove JQuery handlers/data
815
+ if ($) {
816
+ this._unbindJQueryEventHandlers();
817
+ this.$element.removeData('slider');
818
+ }
819
+ },
820
+
821
+ disable: function disable() {
822
+ this._state.enabled = false;
823
+ this.handle1.removeAttribute("tabindex");
824
+ this.handle2.removeAttribute("tabindex");
825
+ this._addClass(this.sliderElem, 'slider-disabled');
826
+ this._trigger('slideDisabled');
827
+
828
+ return this;
829
+ },
830
+
831
+ enable: function enable() {
832
+ this._state.enabled = true;
833
+ this.handle1.setAttribute("tabindex", 0);
834
+ this.handle2.setAttribute("tabindex", 0);
835
+ this._removeClass(this.sliderElem, 'slider-disabled');
836
+ this._trigger('slideEnabled');
837
+
838
+ return this;
839
+ },
840
+
841
+ toggle: function toggle() {
842
+ if (this._state.enabled) {
843
+ this.disable();
844
+ } else {
845
+ this.enable();
846
+ }
847
+ return this;
848
+ },
849
+
850
+ isEnabled: function isEnabled() {
851
+ return this._state.enabled;
852
+ },
853
+
854
+ on: function on(evt, callback) {
855
+ this._bindNonQueryEventHandler(evt, callback);
856
+ return this;
857
+ },
858
+
859
+ off: function off(evt, callback) {
860
+ if ($) {
861
+ this.$element.off(evt, callback);
862
+ this.$sliderElem.off(evt, callback);
863
+ } else {
864
+ this._unbindNonQueryEventHandler(evt, callback);
865
+ }
866
+ },
867
+
868
+ getAttribute: function getAttribute(attribute) {
869
+ if (attribute) {
870
+ return this.options[attribute];
871
+ } else {
872
+ return this.options;
873
+ }
874
+ },
875
+
876
+ setAttribute: function setAttribute(attribute, value) {
877
+ this.options[attribute] = value;
878
+ return this;
879
+ },
880
+
881
+ refresh: function refresh() {
882
+ this._removeSliderEventHandlers();
883
+ createNewSlider.call(this, this.element, this.options);
884
+ if ($) {
885
+ // Bind new instance of slider to the element
886
+ $.data(this.element, 'slider', this);
887
+ }
888
+ return this;
889
+ },
890
+
891
+ relayout: function relayout() {
892
+ this._resize();
893
+ this._layout();
894
+ return this;
895
+ },
896
+
897
+ /******************************+
898
+ HELPERS
899
+ - Any method that is not part of the public interface.
900
+ - Place it underneath this comment block and write its signature like so:
901
+ _fnName : function() {...}
902
+ ********************************/
903
+ _removeSliderEventHandlers: function _removeSliderEventHandlers() {
904
+ // Remove keydown event listeners
905
+ this.handle1.removeEventListener("keydown", this.handle1Keydown, false);
906
+ this.handle2.removeEventListener("keydown", this.handle2Keydown, false);
907
+
908
+ if (this.showTooltip) {
909
+ this.handle1.removeEventListener("focus", this.showTooltip, false);
910
+ this.handle2.removeEventListener("focus", this.showTooltip, false);
911
+ }
912
+ if (this.hideTooltip) {
913
+ this.handle1.removeEventListener("blur", this.hideTooltip, false);
914
+ this.handle2.removeEventListener("blur", this.hideTooltip, false);
915
+ }
916
+
917
+ // Remove event listeners from sliderElem
918
+ if (this.showTooltip) {
919
+ this.sliderElem.removeEventListener("mouseenter", this.showTooltip, false);
920
+ }
921
+ if (this.hideTooltip) {
922
+ this.sliderElem.removeEventListener("mouseleave", this.hideTooltip, false);
923
+ }
924
+ this.sliderElem.removeEventListener("touchstart", this.touchstart, false);
925
+ this.sliderElem.removeEventListener("touchmove", this.touchmove, false);
926
+ this.sliderElem.removeEventListener("mousedown", this.mousedown, false);
927
+
928
+ // Remove window event listener
929
+ window.removeEventListener("resize", this.resize, false);
930
+ },
931
+ _bindNonQueryEventHandler: function _bindNonQueryEventHandler(evt, callback) {
932
+ if (this.eventToCallbackMap[evt] === undefined) {
933
+ this.eventToCallbackMap[evt] = [];
934
+ }
935
+ this.eventToCallbackMap[evt].push(callback);
936
+ },
937
+ _unbindNonQueryEventHandler: function _unbindNonQueryEventHandler(evt, callback) {
938
+ var callbacks = this.eventToCallbackMap[evt];
939
+ if (callbacks !== undefined) {
940
+ for (var i = 0; i < callbacks.length; i++) {
941
+ if (callbacks[i] === callback) {
942
+ callbacks.splice(i, 1);
943
+ break;
944
+ }
945
+ }
946
+ }
947
+ },
948
+ _cleanUpEventCallbacksMap: function _cleanUpEventCallbacksMap() {
949
+ var eventNames = Object.keys(this.eventToCallbackMap);
950
+ for (var i = 0; i < eventNames.length; i++) {
951
+ var eventName = eventNames[i];
952
+ this.eventToCallbackMap[eventName] = null;
953
+ }
954
+ },
955
+ _showTooltip: function _showTooltip() {
956
+ if (this.options.tooltip_split === false) {
957
+ this._addClass(this.tooltip, 'in');
958
+ this.tooltip_min.style.display = 'none';
959
+ this.tooltip_max.style.display = 'none';
960
+ } else {
961
+ this._addClass(this.tooltip_min, 'in');
962
+ this._addClass(this.tooltip_max, 'in');
963
+ this.tooltip.style.display = 'none';
964
+ }
965
+ this._state.over = true;
966
+ },
967
+ _hideTooltip: function _hideTooltip() {
968
+ if (this._state.inDrag === false && this.alwaysShowTooltip !== true) {
969
+ this._removeClass(this.tooltip, 'in');
970
+ this._removeClass(this.tooltip_min, 'in');
971
+ this._removeClass(this.tooltip_max, 'in');
972
+ }
973
+ this._state.over = false;
974
+ },
975
+ _layout: function _layout() {
976
+ var positionPercentages;
977
+
978
+ if (this.options.reversed) {
979
+ positionPercentages = [100 - this._state.percentage[0], this.options.range ? 100 - this._state.percentage[1] : this._state.percentage[1]];
980
+ } else {
981
+ positionPercentages = [this._state.percentage[0], this._state.percentage[1]];
982
+ }
983
+
984
+ this.handle1.style[this.stylePos] = positionPercentages[0] + '%';
985
+ this.handle1.setAttribute('aria-valuenow', this._state.value[0]);
986
+
987
+ this.handle2.style[this.stylePos] = positionPercentages[1] + '%';
988
+ this.handle2.setAttribute('aria-valuenow', this._state.value[1]);
989
+
990
+ /* Position ticks and labels */
991
+ if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
992
+
993
+ var styleSize = this.options.orientation === 'vertical' ? 'height' : 'width';
994
+ var styleMargin = this.options.orientation === 'vertical' ? 'marginTop' : 'marginLeft';
995
+ var labelSize = this._state.size / (this.options.ticks.length - 1);
996
+
997
+ if (this.tickLabelContainer) {
998
+ var extraMargin = 0;
999
+ if (this.options.ticks_positions.length === 0) {
1000
+ if (this.options.orientation !== 'vertical') {
1001
+ this.tickLabelContainer.style[styleMargin] = -labelSize / 2 + 'px';
1002
+ }
1003
+
1004
+ extraMargin = this.tickLabelContainer.offsetHeight;
1005
+ } else {
1006
+ /* Chidren are position absolute, calculate height by finding the max offsetHeight of a child */
1007
+ for (i = 0; i < this.tickLabelContainer.childNodes.length; i++) {
1008
+ if (this.tickLabelContainer.childNodes[i].offsetHeight > extraMargin) {
1009
+ extraMargin = this.tickLabelContainer.childNodes[i].offsetHeight;
1010
+ }
1011
+ }
1012
+ }
1013
+ if (this.options.orientation === 'horizontal') {
1014
+ this.sliderElem.style.marginBottom = extraMargin + 'px';
1015
+ }
1016
+ }
1017
+ for (var i = 0; i < this.options.ticks.length; i++) {
1018
+
1019
+ var percentage = this.options.ticks_positions[i] || this._toPercentage(this.options.ticks[i]);
1020
+
1021
+ if (this.options.reversed) {
1022
+ percentage = 100 - percentage;
1023
+ }
1024
+
1025
+ this.ticks[i].style[this.stylePos] = percentage + '%';
1026
+
1027
+ /* Set class labels to denote whether ticks are in the selection */
1028
+ this._removeClass(this.ticks[i], 'in-selection');
1029
+ if (!this.options.range) {
1030
+ if (this.options.selection === 'after' && percentage >= positionPercentages[0]) {
1031
+ this._addClass(this.ticks[i], 'in-selection');
1032
+ } else if (this.options.selection === 'before' && percentage <= positionPercentages[0]) {
1033
+ this._addClass(this.ticks[i], 'in-selection');
1034
+ }
1035
+ } else if (percentage >= positionPercentages[0] && percentage <= positionPercentages[1]) {
1036
+ this._addClass(this.ticks[i], 'in-selection');
1037
+ }
1038
+
1039
+ if (this.tickLabels[i]) {
1040
+ this.tickLabels[i].style[styleSize] = labelSize + 'px';
1041
+
1042
+ if (this.options.orientation !== 'vertical' && this.options.ticks_positions[i] !== undefined) {
1043
+ this.tickLabels[i].style.position = 'absolute';
1044
+ this.tickLabels[i].style[this.stylePos] = percentage + '%';
1045
+ this.tickLabels[i].style[styleMargin] = -labelSize / 2 + 'px';
1046
+ } else if (this.options.orientation === 'vertical') {
1047
+ this.tickLabels[i].style['marginLeft'] = this.sliderElem.offsetWidth + 'px';
1048
+ this.tickLabelContainer.style['marginTop'] = this.sliderElem.offsetWidth / 2 * -1 + 'px';
1049
+ }
1050
+ }
1051
+ }
1052
+ }
1053
+
1054
+ var formattedTooltipVal;
1055
+
1056
+ if (this.options.range) {
1057
+ formattedTooltipVal = this.options.formatter(this._state.value);
1058
+ this._setText(this.tooltipInner, formattedTooltipVal);
1059
+ this.tooltip.style[this.stylePos] = (positionPercentages[1] + positionPercentages[0]) / 2 + '%';
1060
+
1061
+ if (this.options.orientation === 'vertical') {
1062
+ this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
1063
+ } else {
1064
+ this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
1065
+ }
1066
+
1067
+ if (this.options.orientation === 'vertical') {
1068
+ this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
1069
+ } else {
1070
+ this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
1071
+ }
1072
+
1073
+ var innerTooltipMinText = this.options.formatter(this._state.value[0]);
1074
+ this._setText(this.tooltipInner_min, innerTooltipMinText);
1075
+
1076
+ var innerTooltipMaxText = this.options.formatter(this._state.value[1]);
1077
+ this._setText(this.tooltipInner_max, innerTooltipMaxText);
1078
+
1079
+ this.tooltip_min.style[this.stylePos] = positionPercentages[0] + '%';
1080
+
1081
+ if (this.options.orientation === 'vertical') {
1082
+ this._css(this.tooltip_min, 'margin-top', -this.tooltip_min.offsetHeight / 2 + 'px');
1083
+ } else {
1084
+ this._css(this.tooltip_min, 'margin-left', -this.tooltip_min.offsetWidth / 2 + 'px');
1085
+ }
1086
+
1087
+ this.tooltip_max.style[this.stylePos] = positionPercentages[1] + '%';
1088
+
1089
+ if (this.options.orientation === 'vertical') {
1090
+ this._css(this.tooltip_max, 'margin-top', -this.tooltip_max.offsetHeight / 2 + 'px');
1091
+ } else {
1092
+ this._css(this.tooltip_max, 'margin-left', -this.tooltip_max.offsetWidth / 2 + 'px');
1093
+ }
1094
+ } else {
1095
+ formattedTooltipVal = this.options.formatter(this._state.value[0]);
1096
+ this._setText(this.tooltipInner, formattedTooltipVal);
1097
+
1098
+ this.tooltip.style[this.stylePos] = positionPercentages[0] + '%';
1099
+ if (this.options.orientation === 'vertical') {
1100
+ this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
1101
+ } else {
1102
+ this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
1103
+ }
1104
+ }
1105
+
1106
+ if (this.options.orientation === 'vertical') {
1107
+ this.trackLow.style.top = '0';
1108
+ this.trackLow.style.height = Math.min(positionPercentages[0], positionPercentages[1]) + '%';
1109
+
1110
+ this.trackSelection.style.top = Math.min(positionPercentages[0], positionPercentages[1]) + '%';
1111
+ this.trackSelection.style.height = Math.abs(positionPercentages[0] - positionPercentages[1]) + '%';
1112
+
1113
+ this.trackHigh.style.bottom = '0';
1114
+ this.trackHigh.style.height = 100 - Math.min(positionPercentages[0], positionPercentages[1]) - Math.abs(positionPercentages[0] - positionPercentages[1]) + '%';
1115
+ } else {
1116
+ this.trackLow.style.left = '0';
1117
+ this.trackLow.style.width = Math.min(positionPercentages[0], positionPercentages[1]) + '%';
1118
+
1119
+ this.trackSelection.style.left = Math.min(positionPercentages[0], positionPercentages[1]) + '%';
1120
+ this.trackSelection.style.width = Math.abs(positionPercentages[0] - positionPercentages[1]) + '%';
1121
+
1122
+ this.trackHigh.style.right = '0';
1123
+ this.trackHigh.style.width = 100 - Math.min(positionPercentages[0], positionPercentages[1]) - Math.abs(positionPercentages[0] - positionPercentages[1]) + '%';
1124
+
1125
+ var offset_min = this.tooltip_min.getBoundingClientRect();
1126
+ var offset_max = this.tooltip_max.getBoundingClientRect();
1127
+
1128
+ if (this.options.tooltip_position === 'bottom') {
1129
+ if (offset_min.right > offset_max.left) {
1130
+ this._removeClass(this.tooltip_max, 'bottom');
1131
+ this._addClass(this.tooltip_max, 'top');
1132
+ this.tooltip_max.style.top = '';
1133
+ this.tooltip_max.style.bottom = 22 + 'px';
1134
+ } else {
1135
+ this._removeClass(this.tooltip_max, 'top');
1136
+ this._addClass(this.tooltip_max, 'bottom');
1137
+ this.tooltip_max.style.top = this.tooltip_min.style.top;
1138
+ this.tooltip_max.style.bottom = '';
1139
+ }
1140
+ } else {
1141
+ if (offset_min.right > offset_max.left) {
1142
+ this._removeClass(this.tooltip_max, 'top');
1143
+ this._addClass(this.tooltip_max, 'bottom');
1144
+ this.tooltip_max.style.top = 18 + 'px';
1145
+ } else {
1146
+ this._removeClass(this.tooltip_max, 'bottom');
1147
+ this._addClass(this.tooltip_max, 'top');
1148
+ this.tooltip_max.style.top = this.tooltip_min.style.top;
1149
+ }
1150
+ }
1151
+ }
1152
+ },
1153
+ _resize: function _resize(ev) {
1154
+ /*jshint unused:false*/
1155
+ this._state.offset = this._offset(this.sliderElem);
1156
+ this._state.size = this.sliderElem[this.sizePos];
1157
+ this._layout();
1158
+ },
1159
+ _removeProperty: function _removeProperty(element, prop) {
1160
+ if (element.style.removeProperty) {
1161
+ element.style.removeProperty(prop);
1162
+ } else {
1163
+ element.style.removeAttribute(prop);
1164
+ }
1165
+ },
1166
+ _mousedown: function _mousedown(ev) {
1167
+ if (!this._state.enabled) {
1168
+ return false;
1169
+ }
1170
+
1171
+ this._state.offset = this._offset(this.sliderElem);
1172
+ this._state.size = this.sliderElem[this.sizePos];
1173
+
1174
+ var percentage = this._getPercentage(ev);
1175
+
1176
+ if (this.options.range) {
1177
+ var diff1 = Math.abs(this._state.percentage[0] - percentage);
1178
+ var diff2 = Math.abs(this._state.percentage[1] - percentage);
1179
+ this._state.dragged = diff1 < diff2 ? 0 : 1;
1180
+ } else {
1181
+ this._state.dragged = 0;
1182
+ }
1183
+
1184
+ this._state.percentage[this._state.dragged] = percentage;
1185
+ this._layout();
1186
+
1187
+ if (this.touchCapable) {
1188
+ document.removeEventListener("touchmove", this.mousemove, false);
1189
+ document.removeEventListener("touchend", this.mouseup, false);
1190
+ }
1191
+
1192
+ if (this.mousemove) {
1193
+ document.removeEventListener("mousemove", this.mousemove, false);
1194
+ }
1195
+ if (this.mouseup) {
1196
+ document.removeEventListener("mouseup", this.mouseup, false);
1197
+ }
1198
+
1199
+ this.mousemove = this._mousemove.bind(this);
1200
+ this.mouseup = this._mouseup.bind(this);
1201
+
1202
+ if (this.touchCapable) {
1203
+ // Touch: Bind touch events:
1204
+ document.addEventListener("touchmove", this.mousemove, false);
1205
+ document.addEventListener("touchend", this.mouseup, false);
1206
+ }
1207
+ // Bind mouse events:
1208
+ document.addEventListener("mousemove", this.mousemove, false);
1209
+ document.addEventListener("mouseup", this.mouseup, false);
1210
+
1211
+ this._state.inDrag = true;
1212
+ var newValue = this._calculateValue();
1213
+
1214
+ this._trigger('slideStart', newValue);
1215
+
1216
+ this._setDataVal(newValue);
1217
+ this.setValue(newValue, false, true);
1218
+
1219
+ this._pauseEvent(ev);
1220
+
1221
+ if (this.options.focus) {
1222
+ this._triggerFocusOnHandle(this._state.dragged);
1223
+ }
1224
+
1225
+ return true;
1226
+ },
1227
+ _touchstart: function _touchstart(ev) {
1228
+ if (ev.changedTouches === undefined) {
1229
+ this._mousedown(ev);
1230
+ return;
1231
+ }
1232
+
1233
+ var touch = ev.changedTouches[0];
1234
+ this.touchX = touch.pageX;
1235
+ this.touchY = touch.pageY;
1236
+ },
1237
+ _triggerFocusOnHandle: function _triggerFocusOnHandle(handleIdx) {
1238
+ if (handleIdx === 0) {
1239
+ this.handle1.focus();
1240
+ }
1241
+ if (handleIdx === 1) {
1242
+ this.handle2.focus();
1243
+ }
1244
+ },
1245
+ _keydown: function _keydown(handleIdx, ev) {
1246
+ if (!this._state.enabled) {
1247
+ return false;
1248
+ }
1249
+
1250
+ var dir;
1251
+ switch (ev.keyCode) {
1252
+ case 37: // left
1253
+ case 40:
1254
+ // down
1255
+ dir = -1;
1256
+ break;
1257
+ case 39: // right
1258
+ case 38:
1259
+ // up
1260
+ dir = 1;
1261
+ break;
1262
+ }
1263
+ if (!dir) {
1264
+ return;
1265
+ }
1266
+
1267
+ // use natural arrow keys instead of from min to max
1268
+ if (this.options.natural_arrow_keys) {
1269
+ var ifVerticalAndNotReversed = this.options.orientation === 'vertical' && !this.options.reversed;
1270
+ var ifHorizontalAndReversed = this.options.orientation === 'horizontal' && this.options.reversed;
1271
+
1272
+ if (ifVerticalAndNotReversed || ifHorizontalAndReversed) {
1273
+ dir = -dir;
1274
+ }
1275
+ }
1276
+
1277
+ var val = this._state.value[handleIdx] + dir * this.options.step;
1278
+ if (this.options.range) {
1279
+ val = [!handleIdx ? val : this._state.value[0], handleIdx ? val : this._state.value[1]];
1280
+ }
1281
+
1282
+ this._trigger('slideStart', val);
1283
+ this._setDataVal(val);
1284
+ this.setValue(val, true, true);
1285
+
1286
+ this._setDataVal(val);
1287
+ this._trigger('slideStop', val);
1288
+ this._layout();
1289
+
1290
+ this._pauseEvent(ev);
1291
+
1292
+ return false;
1293
+ },
1294
+ _pauseEvent: function _pauseEvent(ev) {
1295
+ if (ev.stopPropagation) {
1296
+ ev.stopPropagation();
1297
+ }
1298
+ if (ev.preventDefault) {
1299
+ ev.preventDefault();
1300
+ }
1301
+ ev.cancelBubble = true;
1302
+ ev.returnValue = false;
1303
+ },
1304
+ _mousemove: function _mousemove(ev) {
1305
+ if (!this._state.enabled) {
1306
+ return false;
1307
+ }
1308
+
1309
+ var percentage = this._getPercentage(ev);
1310
+ this._adjustPercentageForRangeSliders(percentage);
1311
+ this._state.percentage[this._state.dragged] = percentage;
1312
+ this._layout();
1313
+
1314
+ var val = this._calculateValue(true);
1315
+ this.setValue(val, true, true);
1316
+
1317
+ return false;
1318
+ },
1319
+ _touchmove: function _touchmove(ev) {
1320
+ if (ev.changedTouches === undefined) {
1321
+ return;
1322
+ }
1323
+
1324
+ var touch = ev.changedTouches[0];
1325
+
1326
+ var xDiff = touch.pageX - this.touchX;
1327
+ var yDiff = touch.pageY - this.touchY;
1328
+
1329
+ if (!this._state.inDrag) {
1330
+ // Vertical Slider
1331
+ if (this.options.orientation === 'vertical' && xDiff <= 5 && xDiff >= -5 && (yDiff >= 15 || yDiff <= -15)) {
1332
+ this._mousedown(ev);
1333
+ }
1334
+ // Horizontal slider.
1335
+ else if (yDiff <= 5 && yDiff >= -5 && (xDiff >= 15 || xDiff <= -15)) {
1336
+ this._mousedown(ev);
1337
+ }
1338
+ }
1339
+ },
1340
+ _adjustPercentageForRangeSliders: function _adjustPercentageForRangeSliders(percentage) {
1341
+ if (this.options.range) {
1342
+ var precision = this._getNumDigitsAfterDecimalPlace(percentage);
1343
+ precision = precision ? precision - 1 : 0;
1344
+ var percentageWithAdjustedPrecision = this._applyToFixedAndParseFloat(percentage, precision);
1345
+ if (this._state.dragged === 0 && this._applyToFixedAndParseFloat(this._state.percentage[1], precision) < percentageWithAdjustedPrecision) {
1346
+ this._state.percentage[0] = this._state.percentage[1];
1347
+ this._state.dragged = 1;
1348
+ } else if (this._state.dragged === 1 && this._applyToFixedAndParseFloat(this._state.percentage[0], precision) > percentageWithAdjustedPrecision) {
1349
+ this._state.percentage[1] = this._state.percentage[0];
1350
+ this._state.dragged = 0;
1351
+ }
1352
+ }
1353
+ },
1354
+ _mouseup: function _mouseup() {
1355
+ if (!this._state.enabled) {
1356
+ return false;
1357
+ }
1358
+ if (this.touchCapable) {
1359
+ // Touch: Unbind touch event handlers:
1360
+ document.removeEventListener("touchmove", this.mousemove, false);
1361
+ document.removeEventListener("touchend", this.mouseup, false);
1362
+ }
1363
+ // Unbind mouse event handlers:
1364
+ document.removeEventListener("mousemove", this.mousemove, false);
1365
+ document.removeEventListener("mouseup", this.mouseup, false);
1366
+
1367
+ this._state.inDrag = false;
1368
+ if (this._state.over === false) {
1369
+ this._hideTooltip();
1370
+ }
1371
+ var val = this._calculateValue(true);
1372
+
1373
+ this._layout();
1374
+ this._setDataVal(val);
1375
+ this._trigger('slideStop', val);
1376
+
1377
+ return false;
1378
+ },
1379
+ _calculateValue: function _calculateValue(snapToClosestTick) {
1380
+ var val;
1381
+ if (this.options.range) {
1382
+ val = [this.options.min, this.options.max];
1383
+ if (this._state.percentage[0] !== 0) {
1384
+ val[0] = this._toValue(this._state.percentage[0]);
1385
+ val[0] = this._applyPrecision(val[0]);
1386
+ }
1387
+ if (this._state.percentage[1] !== 100) {
1388
+ val[1] = this._toValue(this._state.percentage[1]);
1389
+ val[1] = this._applyPrecision(val[1]);
1390
+ }
1391
+ } else {
1392
+ val = this._toValue(this._state.percentage[0]);
1393
+ val = parseFloat(val);
1394
+ val = this._applyPrecision(val);
1395
+ }
1396
+
1397
+ if (snapToClosestTick) {
1398
+ var min = [val, Infinity];
1399
+ for (var i = 0; i < this.options.ticks.length; i++) {
1400
+ var diff = Math.abs(this.options.ticks[i] - val);
1401
+ if (diff <= min[1]) {
1402
+ min = [this.options.ticks[i], diff];
1403
+ }
1404
+ }
1405
+ if (min[1] <= this.options.ticks_snap_bounds) {
1406
+ return min[0];
1407
+ }
1408
+ }
1409
+
1410
+ return val;
1411
+ },
1412
+ _applyPrecision: function _applyPrecision(val) {
1413
+ var precision = this.options.precision || this._getNumDigitsAfterDecimalPlace(this.options.step);
1414
+ return this._applyToFixedAndParseFloat(val, precision);
1415
+ },
1416
+ _getNumDigitsAfterDecimalPlace: function _getNumDigitsAfterDecimalPlace(num) {
1417
+ var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
1418
+ if (!match) {
1419
+ return 0;
1420
+ }
1421
+ return Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0));
1422
+ },
1423
+ _applyToFixedAndParseFloat: function _applyToFixedAndParseFloat(num, toFixedInput) {
1424
+ var truncatedNum = num.toFixed(toFixedInput);
1425
+ return parseFloat(truncatedNum);
1426
+ },
1427
+ /*
1428
+ Credits to Mike Samuel for the following method!
1429
+ Source: http://stackoverflow.com/questions/10454518/javascript-how-to-retrieve-the-number-of-decimals-of-a-string-number
1430
+ */
1431
+ _getPercentage: function _getPercentage(ev) {
1432
+ if (this.touchCapable && (ev.type === 'touchstart' || ev.type === 'touchmove')) {
1433
+ ev = ev.touches[0];
1434
+ }
1435
+
1436
+ var eventPosition = ev[this.mousePos];
1437
+ var sliderOffset = this._state.offset[this.stylePos];
1438
+ var distanceToSlide = eventPosition - sliderOffset;
1439
+ // Calculate what percent of the length the slider handle has slid
1440
+ var percentage = distanceToSlide / this._state.size * 100;
1441
+ percentage = Math.round(percentage / this._state.percentage[2]) * this._state.percentage[2];
1442
+ if (this.options.reversed) {
1443
+ percentage = 100 - percentage;
1444
+ }
1445
+
1446
+ // Make sure the percent is within the bounds of the slider.
1447
+ // 0% corresponds to the 'min' value of the slide
1448
+ // 100% corresponds to the 'max' value of the slide
1449
+ return Math.max(0, Math.min(100, percentage));
1450
+ },
1451
+ _validateInputValue: function _validateInputValue(val) {
1452
+ if (typeof val === 'number') {
1453
+ return val;
1454
+ } else if (Array.isArray(val)) {
1455
+ this._validateArray(val);
1456
+ return val;
1457
+ } else {
1458
+ throw new Error(ErrorMsgs.formatInvalidInputErrorMsg(val));
1459
+ }
1460
+ },
1461
+ _validateArray: function _validateArray(val) {
1462
+ for (var i = 0; i < val.length; i++) {
1463
+ var input = val[i];
1464
+ if (typeof input !== 'number') {
1465
+ throw new Error(ErrorMsgs.formatInvalidInputErrorMsg(input));
1466
+ }
1467
+ }
1468
+ },
1469
+ _setDataVal: function _setDataVal(val) {
1470
+ this.element.setAttribute('data-value', val);
1471
+ this.element.setAttribute('value', val);
1472
+ this.element.value = val;
1473
+ },
1474
+ _trigger: function _trigger(evt, val) {
1475
+ val = val || val === 0 ? val : undefined;
1476
+
1477
+ var callbackFnArray = this.eventToCallbackMap[evt];
1478
+ if (callbackFnArray && callbackFnArray.length) {
1479
+ for (var i = 0; i < callbackFnArray.length; i++) {
1480
+ var callbackFn = callbackFnArray[i];
1481
+ callbackFn(val);
1482
+ }
1483
+ }
1484
+
1485
+ /* If JQuery exists, trigger JQuery events */
1486
+ if ($) {
1487
+ this._triggerJQueryEvent(evt, val);
1488
+ }
1489
+ },
1490
+ _triggerJQueryEvent: function _triggerJQueryEvent(evt, val) {
1491
+ var eventData = {
1492
+ type: evt,
1493
+ value: val
1494
+ };
1495
+ this.$element.trigger(eventData);
1496
+ this.$sliderElem.trigger(eventData);
1497
+ },
1498
+ _unbindJQueryEventHandlers: function _unbindJQueryEventHandlers() {
1499
+ this.$element.off();
1500
+ this.$sliderElem.off();
1501
+ },
1502
+ _setText: function _setText(element, text) {
1503
+ if (typeof element.textContent !== "undefined") {
1504
+ element.textContent = text;
1505
+ } else if (typeof element.innerText !== "undefined") {
1506
+ element.innerText = text;
1507
+ }
1508
+ },
1509
+ _removeClass: function _removeClass(element, classString) {
1510
+ var classes = classString.split(" ");
1511
+ var newClasses = element.className;
1512
+
1513
+ for (var i = 0; i < classes.length; i++) {
1514
+ var classTag = classes[i];
1515
+ var regex = new RegExp("(?:\\s|^)" + classTag + "(?:\\s|$)");
1516
+ newClasses = newClasses.replace(regex, " ");
1517
+ }
1518
+
1519
+ element.className = newClasses.trim();
1520
+ },
1521
+ _addClass: function _addClass(element, classString) {
1522
+ var classes = classString.split(" ");
1523
+ var newClasses = element.className;
1524
+
1525
+ for (var i = 0; i < classes.length; i++) {
1526
+ var classTag = classes[i];
1527
+ var regex = new RegExp("(?:\\s|^)" + classTag + "(?:\\s|$)");
1528
+ var ifClassExists = regex.test(newClasses);
1529
+
1530
+ if (!ifClassExists) {
1531
+ newClasses += " " + classTag;
1532
+ }
1533
+ }
1534
+
1535
+ element.className = newClasses.trim();
1536
+ },
1537
+ _offsetLeft: function _offsetLeft(obj) {
1538
+ return obj.getBoundingClientRect().left;
1539
+ },
1540
+ _offsetTop: function _offsetTop(obj) {
1541
+ var offsetTop = obj.offsetTop;
1542
+ while ((obj = obj.offsetParent) && !isNaN(obj.offsetTop)) {
1543
+ offsetTop += obj.offsetTop;
1544
+ if (obj.tagName !== 'BODY') {
1545
+ offsetTop -= obj.scrollTop;
1546
+ }
1547
+ }
1548
+ return offsetTop;
1549
+ },
1550
+ _offset: function _offset(obj) {
1551
+ return {
1552
+ left: this._offsetLeft(obj),
1553
+ top: this._offsetTop(obj)
1554
+ };
1555
+ },
1556
+ _css: function _css(elementRef, styleName, value) {
1557
+ if ($) {
1558
+ $.style(elementRef, styleName, value);
1559
+ } else {
1560
+ var style = styleName.replace(/^-ms-/, "ms-").replace(/-([\da-z])/gi, function (all, letter) {
1561
+ return letter.toUpperCase();
1562
+ });
1563
+ elementRef.style[style] = value;
1564
+ }
1565
+ },
1566
+ _toValue: function _toValue(percentage) {
1567
+ return this.options.scale.toValue.apply(this, [percentage]);
1568
+ },
1569
+ _toPercentage: function _toPercentage(value) {
1570
+ return this.options.scale.toPercentage.apply(this, [value]);
1571
+ },
1572
+ _setTooltipPosition: function _setTooltipPosition() {
1573
+ var tooltips = [this.tooltip, this.tooltip_min, this.tooltip_max];
1574
+ if (this.options.orientation === 'vertical') {
1575
+ var tooltipPos = this.options.tooltip_position || 'right';
1576
+ var oppositeSide = tooltipPos === 'left' ? 'right' : 'left';
1577
+ tooltips.forEach((function (tooltip) {
1578
+ this._addClass(tooltip, tooltipPos);
1579
+ tooltip.style[oppositeSide] = '100%';
1580
+ }).bind(this));
1581
+ } else if (this.options.tooltip_position === 'bottom') {
1582
+ tooltips.forEach((function (tooltip) {
1583
+ this._addClass(tooltip, 'bottom');
1584
+ tooltip.style.top = 22 + 'px';
1585
+ }).bind(this));
1586
+ } else {
1587
+ tooltips.forEach((function (tooltip) {
1588
+ this._addClass(tooltip, 'top');
1589
+ tooltip.style.top = -this.tooltip.outerHeight - 14 + 'px';
1590
+ }).bind(this));
1591
+ }
1592
+ }
1593
+ };
1594
+
1595
+ /*********************************
1596
+ Attach to global namespace
1597
+ *********************************/
1598
+ if ($) {
1599
+ var namespace = $.fn.slider ? 'bootstrapSlider' : 'slider';
1600
+ $.bridget(namespace, Slider);
1601
+
1602
+ // Auto-Register data-provide="slider" Elements
1603
+ $(function () {
1604
+ $("input[data-provide=slider]")[namespace]();
1605
+ });
1606
+ }
1607
+ })($);
1608
+
1609
+ return Slider;
1610
+ });