active_frontend 13.3.0 → 14.0.0

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