materialize-sass 0.100.2.1 → 1.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +18 -42
  3. data/Rakefile +17 -17
  4. data/{app/assets → assets}/javascripts/materialize-sprockets.js +8 -12
  5. data/assets/javascripts/materialize.js +11877 -0
  6. data/assets/javascripts/materialize/autocomplete.js +420 -0
  7. data/assets/javascripts/materialize/buttons.js +388 -0
  8. data/assets/javascripts/materialize/cards.js +28 -0
  9. data/assets/javascripts/materialize/carousel.js +791 -0
  10. data/assets/javascripts/materialize/cash.js +992 -0
  11. data/assets/javascripts/materialize/characterCounter.js +180 -0
  12. data/assets/javascripts/materialize/chips.js +555 -0
  13. data/assets/javascripts/materialize/collapsible.js +275 -0
  14. data/assets/javascripts/materialize/datepicker.js +898 -0
  15. data/assets/javascripts/materialize/dropdown.js +530 -0
  16. data/{app/assets → assets}/javascripts/materialize/extras/nouislider.js +1 -1
  17. data/{app/assets → assets}/javascripts/materialize/extras/nouislider.min.js +1 -1
  18. data/assets/javascripts/materialize/forms.js +223 -0
  19. data/assets/javascripts/materialize/global.js +353 -0
  20. data/assets/javascripts/materialize/materialbox.js +432 -0
  21. data/{app/assets → assets}/javascripts/materialize/modal.js +82 -113
  22. data/assets/javascripts/materialize/parallax.js +135 -0
  23. data/assets/javascripts/materialize/pushpin.js +158 -0
  24. data/assets/javascripts/materialize/range.js +305 -0
  25. data/assets/javascripts/materialize/scrollspy.js +322 -0
  26. data/assets/javascripts/materialize/select.js +426 -0
  27. data/assets/javascripts/materialize/sidenav.js +584 -0
  28. data/assets/javascripts/materialize/slider.js +383 -0
  29. data/assets/javascripts/materialize/tabs.js +460 -0
  30. data/assets/javascripts/materialize/tapTarget.js +347 -0
  31. data/assets/javascripts/materialize/timepicker.js +616 -0
  32. data/{app/assets → assets}/javascripts/materialize/toasts.js +42 -46
  33. data/assets/javascripts/materialize/tooltip.js +325 -0
  34. data/assets/javascripts/materialize/velocity.min.js +782 -0
  35. data/{app/assets → assets}/javascripts/materialize/waves.js +0 -0
  36. data/{app/assets → assets}/stylesheets/materialize.scss +5 -6
  37. data/{app/assets → assets}/stylesheets/materialize/components/_badges.scss +1 -1
  38. data/{app/assets → assets}/stylesheets/materialize/components/_buttons.scss +34 -2
  39. data/{app/assets → assets}/stylesheets/materialize/components/_cards.scss +0 -0
  40. data/{app/assets → assets}/stylesheets/materialize/components/_carousel.scss +1 -1
  41. data/{app/assets → assets}/stylesheets/materialize/components/_chips.scss +6 -5
  42. data/{app/assets → assets}/stylesheets/materialize/components/_collapsible.scss +3 -3
  43. data/{app/assets → assets}/stylesheets/materialize/components/_color.scss +0 -0
  44. data/assets/stylesheets/materialize/components/_datepicker.scss +180 -0
  45. data/{app/assets → assets}/stylesheets/materialize/components/_dropdown.scss +16 -15
  46. data/{app/assets → assets}/stylesheets/materialize/components/_global.scss +49 -14
  47. data/{app/assets → assets}/stylesheets/materialize/components/_grid.scss +1 -1
  48. data/{app/assets → assets}/stylesheets/materialize/components/_icons-material-design.scss +0 -0
  49. data/{app/assets → assets}/stylesheets/materialize/components/_materialbox.scss +0 -0
  50. data/assets/stylesheets/materialize/components/_mixins.scss +5 -0
  51. data/{app/assets → assets}/stylesheets/materialize/components/_modal.scss +1 -1
  52. data/{app/assets → assets}/stylesheets/materialize/components/_navbar.scss +0 -0
  53. data/assets/stylesheets/materialize/components/_normalize.scss +447 -0
  54. data/{app/assets → assets}/stylesheets/materialize/components/_preloader.scss +0 -0
  55. data/{app/assets → assets}/stylesheets/materialize/components/_pulse.scss +0 -0
  56. data/{app/assets/stylesheets/materialize/components/_sideNav.scss → assets/stylesheets/materialize/components/_sidenav.scss} +23 -21
  57. data/{app/assets → assets}/stylesheets/materialize/components/_slider.scss +0 -0
  58. data/{app/assets → assets}/stylesheets/materialize/components/_table_of_contents.scss +3 -3
  59. data/{app/assets → assets}/stylesheets/materialize/components/_tabs.scss +2 -2
  60. data/{app/assets → assets}/stylesheets/materialize/components/_tapTarget.scss +0 -0
  61. data/assets/stylesheets/materialize/components/_timepicker.scss +182 -0
  62. data/{app/assets → assets}/stylesheets/materialize/components/_toast.scss +0 -0
  63. data/{app/assets → assets}/stylesheets/materialize/components/_tooltip.scss +1 -0
  64. data/{app/assets → assets}/stylesheets/materialize/components/_transitions.scss +0 -0
  65. data/{app/assets → assets}/stylesheets/materialize/components/_typography.scss +8 -8
  66. data/{app/assets → assets}/stylesheets/materialize/components/_variables.scss +42 -44
  67. data/{app/assets → assets}/stylesheets/materialize/components/_waves.scss +0 -0
  68. data/{app/assets → assets}/stylesheets/materialize/components/forms/_checkboxes.scss +24 -24
  69. data/{app/assets → assets}/stylesheets/materialize/components/forms/_file-input.scss +0 -0
  70. data/{app/assets → assets}/stylesheets/materialize/components/forms/_forms.scss +0 -0
  71. data/{app/assets → assets}/stylesheets/materialize/components/forms/_input-fields.scss +49 -35
  72. data/{app/assets → assets}/stylesheets/materialize/components/forms/_radio-buttons.scss +29 -29
  73. data/{app/assets → assets}/stylesheets/materialize/components/forms/_range.scss +32 -31
  74. data/{app/assets → assets}/stylesheets/materialize/components/forms/_select.scss +20 -11
  75. data/{app/assets → assets}/stylesheets/materialize/components/forms/_switches.scss +0 -0
  76. data/{app/assets → assets}/stylesheets/materialize/extras/nouislider.css +1 -1
  77. data/lib/materialize-sass.rb +13 -23
  78. data/lib/materialize-sass/engine.rb +6 -9
  79. data/lib/materialize-sass/version.rb +1 -1
  80. data/materialize-sass.gemspec +2 -1
  81. metadata +97 -97
  82. data/app/assets/fonts/roboto/Roboto-Bold.woff +0 -0
  83. data/app/assets/fonts/roboto/Roboto-Bold.woff2 +0 -0
  84. data/app/assets/fonts/roboto/Roboto-Light.woff +0 -0
  85. data/app/assets/fonts/roboto/Roboto-Light.woff2 +0 -0
  86. data/app/assets/fonts/roboto/Roboto-Medium.woff +0 -0
  87. data/app/assets/fonts/roboto/Roboto-Medium.woff2 +0 -0
  88. data/app/assets/fonts/roboto/Roboto-Regular.woff +0 -0
  89. data/app/assets/fonts/roboto/Roboto-Regular.woff2 +0 -0
  90. data/app/assets/fonts/roboto/Roboto-Thin.woff +0 -0
  91. data/app/assets/fonts/roboto/Roboto-Thin.woff2 +0 -0
  92. data/app/assets/javascripts/materialize.js +0 -10021
  93. data/app/assets/javascripts/materialize/animation.js +0 -7
  94. data/app/assets/javascripts/materialize/buttons.js +0 -253
  95. data/app/assets/javascripts/materialize/cards.js +0 -28
  96. data/app/assets/javascripts/materialize/carousel.js +0 -543
  97. data/app/assets/javascripts/materialize/character_counter.js +0 -64
  98. data/app/assets/javascripts/materialize/chips.js +0 -315
  99. data/app/assets/javascripts/materialize/collapsible.js +0 -178
  100. data/app/assets/javascripts/materialize/date_picker/picker.date.js +0 -1399
  101. data/app/assets/javascripts/materialize/date_picker/picker.js +0 -1196
  102. data/app/assets/javascripts/materialize/date_picker/picker.time.js +0 -646
  103. data/app/assets/javascripts/materialize/dropdown.js +0 -257
  104. data/app/assets/javascripts/materialize/forms.js +0 -806
  105. data/app/assets/javascripts/materialize/global.js +0 -170
  106. data/app/assets/javascripts/materialize/hammer.min.js +0 -424
  107. data/app/assets/javascripts/materialize/initial.js +0 -10
  108. data/app/assets/javascripts/materialize/jquery.easing.1.4.js +0 -144
  109. data/app/assets/javascripts/materialize/jquery.hammer.js +0 -33
  110. data/app/assets/javascripts/materialize/materialbox.js +0 -263
  111. data/app/assets/javascripts/materialize/parallax.js +0 -54
  112. data/app/assets/javascripts/materialize/pushpin.js +0 -68
  113. data/app/assets/javascripts/materialize/scrollFire.js +0 -49
  114. data/app/assets/javascripts/materialize/scrollspy.js +0 -230
  115. data/app/assets/javascripts/materialize/sideNav.js +0 -395
  116. data/app/assets/javascripts/materialize/slider.js +0 -295
  117. data/app/assets/javascripts/materialize/tabs.js +0 -244
  118. data/app/assets/javascripts/materialize/tapTarget.js +0 -184
  119. data/app/assets/javascripts/materialize/tooltip.js +0 -227
  120. data/app/assets/javascripts/materialize/transitions.js +0 -163
  121. data/app/assets/javascripts/materialize/velocity.min.js +0 -626
  122. data/app/assets/stylesheets/materialize/components/_normalize.scss +0 -424
  123. data/app/assets/stylesheets/materialize/components/_roboto.scss +0 -39
  124. data/app/assets/stylesheets/materialize/components/date_picker/_default.date.scss +0 -469
  125. data/app/assets/stylesheets/materialize/components/date_picker/_default.scss +0 -216
  126. data/app/assets/stylesheets/materialize/components/date_picker/_default.time.scss +0 -267
@@ -1,1196 +0,0 @@
1
- /*!
2
- * pickadate.js v3.6.1, 2019/03/15
3
- * By Amsul, http://amsul.ca
4
- * Hosted on http://amsul.github.io/pickadate.js
5
- * Licensed under MIT
6
- */
7
-
8
- (function ( factory ) {
9
-
10
- Materialize.Picker = factory( jQuery )
11
- })(function( $ ) {
12
-
13
- var $window = $( window )
14
- var $document = $( document )
15
- var $html = $( document.documentElement )
16
- var supportsTransitions = document.documentElement.style.transition != null
17
-
18
-
19
- /**
20
- * The picker constructor that creates a blank picker.
21
- */
22
- function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
23
-
24
- // If there’s no element, return the picker constructor.
25
- if ( !ELEMENT ) return PickerConstructor
26
-
27
-
28
- var
29
- IS_DEFAULT_THEME = false,
30
-
31
-
32
- // The state of the picker.
33
- STATE = {
34
- id: ELEMENT.id || 'P' + Math.abs( ~~(Math.random() * new Date()) )
35
- },
36
-
37
-
38
- // Merge the defaults and options passed.
39
- SETTINGS = COMPONENT ? $.extend( true, {}, COMPONENT.defaults, OPTIONS ) : OPTIONS || {},
40
-
41
-
42
- // Merge the default classes with the settings classes.
43
- CLASSES = $.extend( {}, PickerConstructor.klasses(), SETTINGS.klass ),
44
-
45
-
46
- // The element node wrapper into a jQuery object.
47
- $ELEMENT = $( ELEMENT ),
48
-
49
-
50
- // Pseudo picker constructor.
51
- PickerInstance = function() {
52
- return this.start()
53
- },
54
-
55
-
56
- // The picker prototype.
57
- P = PickerInstance.prototype = {
58
-
59
- constructor: PickerInstance,
60
-
61
- $node: $ELEMENT,
62
-
63
-
64
- /**
65
- * Initialize everything
66
- */
67
- start: function() {
68
-
69
- // If it’s already started, do nothing.
70
- if ( STATE && STATE.start ) return P
71
-
72
-
73
- // Update the picker states.
74
- STATE.methods = {}
75
- STATE.start = true
76
- STATE.open = false
77
- STATE.type = ELEMENT.type
78
-
79
-
80
- // Confirm focus state, convert into text input to remove UA stylings,
81
- // and set as readonly to prevent keyboard popup.
82
- ELEMENT.autofocus = ELEMENT == getActiveElement()
83
- ELEMENT.readOnly = !SETTINGS.editable
84
- ELEMENT.id = ELEMENT.id || STATE.id
85
- if ( ELEMENT.type != 'text' ) {
86
- ELEMENT.type = 'text'
87
- }
88
-
89
-
90
- // Create a new picker component with the settings.
91
- P.component = new COMPONENT(P, SETTINGS)
92
-
93
-
94
- // Create the picker root and then prepare it.
95
- P.$root = $( '<div class="' + CLASSES.picker + '" id="' + ELEMENT.id + '_root" />' )
96
- prepareElementRoot()
97
-
98
-
99
- // Create the picker holder and then prepare it.
100
- P.$holder = $( createWrappedComponent() ).appendTo( P.$root )
101
- prepareElementHolder()
102
-
103
-
104
- // If there’s a format for the hidden input element, create the element.
105
- if ( SETTINGS.formatSubmit ) {
106
- prepareElementHidden()
107
- }
108
-
109
-
110
- // Prepare the input element.
111
- prepareElement()
112
-
113
-
114
- // Insert the hidden input as specified in the settings.
115
- if ( SETTINGS.containerHidden ) $( SETTINGS.containerHidden ).append( P._hidden )
116
- else $ELEMENT.after( P._hidden )
117
-
118
-
119
- // Insert the root as specified in the settings.
120
- if ( SETTINGS.container ) $( SETTINGS.container ).append( P.$root )
121
- else $ELEMENT.after( P.$root )
122
-
123
-
124
- // Bind the default component and settings events.
125
- P.on({
126
- start: P.component.onStart,
127
- render: P.component.onRender,
128
- stop: P.component.onStop,
129
- open: P.component.onOpen,
130
- close: P.component.onClose,
131
- set: P.component.onSet
132
- }).on({
133
- start: SETTINGS.onStart,
134
- render: SETTINGS.onRender,
135
- stop: SETTINGS.onStop,
136
- open: SETTINGS.onOpen,
137
- close: SETTINGS.onClose,
138
- set: SETTINGS.onSet
139
- })
140
-
141
-
142
- // Once we’re all set, check the theme in use.
143
- IS_DEFAULT_THEME = isUsingDefaultTheme( P.$holder[0] )
144
-
145
-
146
- // If the element has autofocus, open the picker.
147
- if ( ELEMENT.autofocus ) {
148
- P.open()
149
- }
150
-
151
-
152
- // Trigger queued the “start” and “render” events.
153
- return P.trigger( 'start' ).trigger( 'render' )
154
- }, //start
155
-
156
-
157
- /**
158
- * Render a new picker
159
- */
160
- render: function( entireComponent ) {
161
-
162
- // Insert a new component holder in the root or box.
163
- if ( entireComponent ) {
164
- P.$holder = $( createWrappedComponent() )
165
- prepareElementHolder()
166
- P.$root.html( P.$holder )
167
- }
168
- else P.$root.find( '.' + CLASSES.box ).html( P.component.nodes( STATE.open ) )
169
-
170
- // Trigger the queued “render” events.
171
- return P.trigger( 'render' )
172
- }, //render
173
-
174
-
175
- /**
176
- * Destroy everything
177
- */
178
- stop: function() {
179
-
180
- // If it’s already stopped, do nothing.
181
- if ( !STATE.start ) return P
182
-
183
- // Then close the picker.
184
- P.close()
185
-
186
- // Remove the hidden field.
187
- if ( P._hidden ) {
188
- P._hidden.parentNode.removeChild( P._hidden )
189
- }
190
-
191
- // Remove the root.
192
- P.$root.remove()
193
-
194
- // Remove the input class, remove the stored data, and unbind
195
- // the events (after a tick for IE - see `P.close`).
196
- $ELEMENT.removeClass( CLASSES.input ).removeData( NAME )
197
- setTimeout( function() {
198
- $ELEMENT.off( '.' + STATE.id )
199
- }, 0)
200
-
201
- // Restore the element state
202
- ELEMENT.type = STATE.type
203
- ELEMENT.readOnly = false
204
-
205
- // Trigger the queued “stop” events.
206
- P.trigger( 'stop' )
207
-
208
- // Reset the picker states.
209
- STATE.methods = {}
210
- STATE.start = false
211
-
212
- return P
213
- }, //stop
214
-
215
-
216
- /**
217
- * Open up the picker
218
- */
219
- open: function( dontGiveFocus ) {
220
-
221
- // If it’s already open, do nothing.
222
- if ( STATE.open ) return P
223
-
224
- // Add the “active” class.
225
- $ELEMENT.addClass( CLASSES.active )
226
- aria( ELEMENT, 'expanded', true )
227
-
228
- // * A Firefox bug, when `html` has `overflow:hidden`, results in
229
- // killing transitions :(. So add the “opened” state on the next tick.
230
- // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=625289
231
- setTimeout( function() {
232
-
233
- // Add the “opened” class to the picker root.
234
- P.$root.addClass( CLASSES.opened )
235
- aria( P.$root[0], 'hidden', false )
236
-
237
- }, 0 )
238
-
239
- // If we have to give focus, bind the element and doc events.
240
- if ( dontGiveFocus !== false ) {
241
-
242
- // Set it as open.
243
- STATE.open = true
244
-
245
- // Prevent the page from scrolling.
246
- if ( IS_DEFAULT_THEME ) {
247
- $('body').
248
- css( 'overflow', 'hidden' ).
249
- css( 'padding-right', '+=' + getScrollbarWidth() )
250
- }
251
-
252
- // Pass focus to the root element’s jQuery object.
253
- focusPickerOnceOpened()
254
-
255
- // Bind the document events.
256
- $document.on( 'click.' + STATE.id + ' focusin.' + STATE.id, function( event ) {
257
-
258
- var target = getRealEventTarget( event, ELEMENT )
259
-
260
- // If the target of the event is not the element, close the picker picker.
261
- // * Don’t worry about clicks or focusins on the root because those don’t bubble up.
262
- // Also, for Firefox, a click on an `option` element bubbles up directly
263
- // to the doc. So make sure the target wasn't the doc.
264
- // * In Firefox stopPropagation() doesn’t prevent right-click events from bubbling,
265
- // which causes the picker to unexpectedly close when right-clicking it. So make
266
- // sure the event wasn’t a right-click.
267
- // * In Chrome 62 and up, password autofill causes a simulated focusin event which
268
- // closes the picker.
269
- if ( ! event.isSimulated && target != ELEMENT && target != document && event.which != 3 ) {
270
-
271
- // If the target was the holder that covers the screen,
272
- // keep the element focused to maintain tabindex.
273
- P.close( target === P.$holder[0] )
274
- }
275
-
276
- }).on( 'keydown.' + STATE.id, function( event ) {
277
-
278
- var
279
- // Get the keycode.
280
- keycode = event.keyCode,
281
-
282
- // Translate that to a selection change.
283
- keycodeToMove = P.component.key[ keycode ],
284
-
285
- // Grab the target.
286
- target = getRealEventTarget( event, ELEMENT )
287
-
288
-
289
- // On escape, close the picker and give focus.
290
- if ( keycode == 27 ) {
291
- P.close( true )
292
- }
293
-
294
-
295
- // Check if there is a key movement or “enter” keypress on the element.
296
- else if ( target == P.$holder[0] && ( keycodeToMove || keycode == 13 ) ) {
297
-
298
- // Prevent the default action to stop page movement.
299
- event.preventDefault()
300
-
301
- // Trigger the key movement action.
302
- if ( keycodeToMove ) {
303
- PickerConstructor._.trigger( P.component.key.go, P, [ PickerConstructor._.trigger( keycodeToMove ) ] )
304
- }
305
-
306
- // On “enter”, if the highlighted item isn’t disabled, set the value and close.
307
- else if ( !P.$root.find( '.' + CLASSES.highlighted ).hasClass( CLASSES.disabled ) ) {
308
- P.set( 'select', P.component.item.highlight )
309
- if ( SETTINGS.closeOnSelect ) {
310
- P.close( true )
311
- }
312
- }
313
- }
314
-
315
-
316
- // If the target is within the root and “enter” is pressed,
317
- // prevent the default action and trigger a click on the target instead.
318
- else if ( $.contains( P.$root[0], target ) && keycode == 13 ) {
319
- event.preventDefault()
320
- target.click()
321
- }
322
- })
323
- }
324
-
325
- // Trigger the queued “open” events.
326
- return P.trigger( 'open' )
327
- }, //open
328
-
329
-
330
- /**
331
- * Close the picker
332
- */
333
- close: function( giveFocus ) {
334
-
335
- // If we need to give focus, do it before changing states.
336
- if ( giveFocus ) {
337
- if ( SETTINGS.editable ) {
338
- ELEMENT.focus()
339
- }
340
- else {
341
- // ....ah yes! It would’ve been incomplete without a crazy workaround for IE :|
342
- // The focus is triggered *after* the close has completed - causing it
343
- // to open again. So unbind and rebind the event at the next tick.
344
- P.$holder.off( 'focus.toOpen' ).focus()
345
- setTimeout( function() {
346
- P.$holder.on( 'focus.toOpen', handleFocusToOpenEvent )
347
- }, 0 )
348
- }
349
- }
350
-
351
- // Remove the “active” class.
352
- $ELEMENT.removeClass( CLASSES.active )
353
- aria( ELEMENT, 'expanded', false )
354
-
355
- // * A Firefox bug, when `html` has `overflow:hidden`, results in
356
- // killing transitions :(. So remove the “opened” state on the next tick.
357
- // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=625289
358
- setTimeout( function() {
359
-
360
- // Remove the “opened” and “focused” class from the picker root.
361
- P.$root.removeClass( CLASSES.opened + ' ' + CLASSES.focused )
362
- aria( P.$root[0], 'hidden', true )
363
-
364
- }, 0 )
365
-
366
- // If it’s already closed, do nothing more.
367
- if ( !STATE.open ) return P
368
-
369
- // Set it as closed.
370
- STATE.open = false
371
-
372
- // Allow the page to scroll.
373
- if ( IS_DEFAULT_THEME ) {
374
- $('body').
375
- css( 'overflow', '' ).
376
- css( 'padding-right', '-=' + getScrollbarWidth() )
377
- }
378
-
379
- // Unbind the document events.
380
- $document.off( '.' + STATE.id )
381
-
382
- // Trigger the queued “close” events.
383
- return P.trigger( 'close' )
384
- }, //close
385
-
386
-
387
- /**
388
- * Clear the values
389
- */
390
- clear: function( options ) {
391
- return P.set( 'clear', null, options )
392
- }, //clear
393
-
394
-
395
- /**
396
- * Set something
397
- */
398
- set: function( thing, value, options ) {
399
-
400
- var thingItem, thingValue,
401
- thingIsObject = $.isPlainObject( thing ),
402
- thingObject = thingIsObject ? thing : {}
403
-
404
- // Make sure we have usable options.
405
- options = thingIsObject && $.isPlainObject( value ) ? value : options || {}
406
-
407
- if ( thing ) {
408
-
409
- // If the thing isn’t an object, make it one.
410
- if ( !thingIsObject ) {
411
- thingObject[ thing ] = value
412
- }
413
-
414
- // Go through the things of items to set.
415
- for ( thingItem in thingObject ) {
416
-
417
- // Grab the value of the thing.
418
- thingValue = thingObject[ thingItem ]
419
-
420
- // First, if the item exists and there’s a value, set it.
421
- if ( thingItem in P.component.item ) {
422
- if ( thingValue === undefined ) thingValue = null
423
- P.component.set( thingItem, thingValue, options )
424
- }
425
-
426
- // Then, check to update the element value and broadcast a change.
427
- if ( ( thingItem == 'select' || thingItem == 'clear' ) && SETTINGS.updateInput ) {
428
- $ELEMENT.
429
- val( thingItem == 'clear' ? '' : P.get( thingItem, SETTINGS.format ) ).
430
- trigger( 'change' )
431
- }
432
- }
433
-
434
- // Render a new picker.
435
- P.render()
436
- }
437
-
438
- // When the method isn’t muted, trigger queued “set” events and pass the `thingObject`.
439
- return options.muted ? P : P.trigger( 'set', thingObject )
440
- }, //set
441
-
442
-
443
- /**
444
- * Get something
445
- */
446
- get: function( thing, format ) {
447
-
448
- // Make sure there’s something to get.
449
- thing = thing || 'value'
450
-
451
- // If a picker state exists, return that.
452
- if ( STATE[ thing ] != null ) {
453
- return STATE[ thing ]
454
- }
455
-
456
- // Return the submission value, if that.
457
- if ( thing == 'valueSubmit' ) {
458
- if ( P._hidden ) {
459
- return P._hidden.value
460
- }
461
- thing = 'value'
462
- }
463
-
464
- // Return the value, if that.
465
- if ( thing == 'value' ) {
466
- return ELEMENT.value
467
- }
468
-
469
- // Check if a component item exists, return that.
470
- if ( thing in P.component.item ) {
471
- if ( typeof format == 'string' ) {
472
- var thingValue = P.component.get( thing )
473
- return thingValue ?
474
- PickerConstructor._.trigger(
475
- P.component.formats.toString,
476
- P.component,
477
- [ format, thingValue ]
478
- ) : ''
479
- }
480
- return P.component.get( thing )
481
- }
482
- }, //get
483
-
484
-
485
-
486
- /**
487
- * Bind events on the things.
488
- */
489
- on: function( thing, method, internal ) {
490
-
491
- var thingName, thingMethod,
492
- thingIsObject = $.isPlainObject( thing ),
493
- thingObject = thingIsObject ? thing : {}
494
-
495
- if ( thing ) {
496
-
497
- // If the thing isn’t an object, make it one.
498
- if ( !thingIsObject ) {
499
- thingObject[ thing ] = method
500
- }
501
-
502
- // Go through the things to bind to.
503
- for ( thingName in thingObject ) {
504
-
505
- // Grab the method of the thing.
506
- thingMethod = thingObject[ thingName ]
507
-
508
- // If it was an internal binding, prefix it.
509
- if ( internal ) {
510
- thingName = '_' + thingName
511
- }
512
-
513
- // Make sure the thing methods collection exists.
514
- STATE.methods[ thingName ] = STATE.methods[ thingName ] || []
515
-
516
- // Add the method to the relative method collection.
517
- STATE.methods[ thingName ].push( thingMethod )
518
- }
519
- }
520
-
521
- return P
522
- }, //on
523
-
524
-
525
-
526
- /**
527
- * Unbind events on the things.
528
- */
529
- off: function() {
530
- var i, thingName,
531
- names = arguments;
532
- for ( i = 0, namesCount = names.length; i < namesCount; i += 1 ) {
533
- thingName = names[i]
534
- if ( thingName in STATE.methods ) {
535
- delete STATE.methods[thingName]
536
- }
537
- }
538
- return P
539
- },
540
-
541
-
542
- /**
543
- * Fire off method events.
544
- */
545
- trigger: function( name, data ) {
546
- var _trigger = function( name ) {
547
- var methodList = STATE.methods[ name ]
548
- if ( methodList ) {
549
- methodList.map( function( method ) {
550
- PickerConstructor._.trigger( method, P, [ data ] )
551
- })
552
- }
553
- }
554
- _trigger( '_' + name )
555
- _trigger( name )
556
- return P
557
- } //trigger
558
- } //PickerInstance.prototype
559
-
560
-
561
- /**
562
- * Wrap the picker holder components together.
563
- */
564
- function createWrappedComponent() {
565
-
566
- // Create a picker wrapper holder
567
- return PickerConstructor._.node( 'div',
568
-
569
- // Create a picker wrapper node
570
- PickerConstructor._.node( 'div',
571
-
572
- // Create a picker frame
573
- PickerConstructor._.node( 'div',
574
-
575
- // Create a picker box node
576
- PickerConstructor._.node( 'div',
577
-
578
- // Create the components nodes.
579
- P.component.nodes( STATE.open ),
580
-
581
- // The picker box class
582
- CLASSES.box
583
- ),
584
-
585
- // Picker wrap class
586
- CLASSES.wrap
587
- ),
588
-
589
- // Picker frame class
590
- CLASSES.frame
591
- ),
592
-
593
- // Picker holder class
594
- CLASSES.holder,
595
-
596
- 'tabindex="-1"'
597
- ) //endreturn
598
- } //createWrappedComponent
599
-
600
- /**
601
- * Prepare the input element with all bindings.
602
- */
603
- function prepareElement() {
604
-
605
- $ELEMENT.
606
-
607
- // Store the picker data by component name.
608
- data(NAME, P).
609
-
610
- // Add the “input” class name.
611
- addClass(CLASSES.input).
612
-
613
- // If there’s a `data-value`, update the value of the element.
614
- val( $ELEMENT.data('value') ?
615
- P.get('select', SETTINGS.format) :
616
- ELEMENT.value
617
- ).
618
-
619
- // On focus/click, open the picker.
620
- on( 'focus.' + STATE.id + ' click.' + STATE.id,
621
- debounce(function(event) {
622
- event.preventDefault()
623
- P.open()
624
- }, 50))
625
-
626
- // Only bind keydown events if the element isn’t editable.
627
- if ( !SETTINGS.editable ) {
628
-
629
- $ELEMENT.
630
-
631
- // Handle keyboard event based on the picker being opened or not.
632
- on( 'keydown.' + STATE.id, handleKeydownEvent )
633
- }
634
-
635
-
636
- // Update the aria attributes.
637
- aria(ELEMENT, {
638
- haspopup: true,
639
- expanded: false,
640
- readonly: false,
641
- owns: ELEMENT.id + '_root'
642
- })
643
- }
644
-
645
-
646
- /**
647
- * Prepare the root picker element with all bindings.
648
- */
649
- function prepareElementRoot() {
650
- aria( P.$root[0], 'hidden', true )
651
- }
652
-
653
-
654
- /**
655
- * Prepare the holder picker element with all bindings.
656
- */
657
- function prepareElementHolder() {
658
-
659
- P.$holder.
660
-
661
- on({
662
-
663
- // For iOS8.
664
- keydown: handleKeydownEvent,
665
-
666
- 'focus.toOpen': handleFocusToOpenEvent,
667
-
668
- blur: function() {
669
- // Remove the “target” class.
670
- $ELEMENT.removeClass( CLASSES.target )
671
- },
672
-
673
- // When something within the holder is focused, stop from bubbling
674
- // to the doc and remove the “focused” state from the root.
675
- focusin: function( event ) {
676
- P.$root.removeClass( CLASSES.focused )
677
- event.stopPropagation()
678
- },
679
-
680
- // When something within the holder is clicked, stop it
681
- // from bubbling to the doc.
682
- 'mousedown click': function( event ) {
683
-
684
- var target = getRealEventTarget( event, ELEMENT )
685
-
686
- // Make sure the target isn’t the root holder so it can bubble up.
687
- if ( target != P.$holder[0] ) {
688
-
689
- event.stopPropagation()
690
-
691
- // * For mousedown events, cancel the default action in order to
692
- // prevent cases where focus is shifted onto external elements
693
- // when using things like jQuery mobile or MagnificPopup (ref: #249 & #120).
694
- // Also, for Firefox, don’t prevent action on the `option` element.
695
- if ( event.type == 'mousedown' && !$( target ).is( 'input, select, textarea, button, option' )) {
696
-
697
- event.preventDefault()
698
-
699
- // Re-focus onto the holder so that users can click away
700
- // from elements focused within the picker.
701
- P.$holder.eq(0).focus()
702
- }
703
- }
704
- }
705
-
706
- }).
707
-
708
- // If there’s a click on an actionable element, carry out the actions.
709
- on( 'click', '[data-pick], [data-nav], [data-clear], [data-close]', function() {
710
-
711
- var $target = $( this ),
712
- targetData = $target.data(),
713
- targetDisabled = $target.hasClass( CLASSES.navDisabled ) || $target.hasClass( CLASSES.disabled ),
714
-
715
- // * For IE, non-focusable elements can be active elements as well
716
- // (http://stackoverflow.com/a/2684561).
717
- activeElement = getActiveElement()
718
- activeElement = activeElement && ( (activeElement.type || activeElement.href ) ? activeElement : null);
719
-
720
- // If it’s disabled or nothing inside is actively focused, re-focus the element.
721
- if ( targetDisabled || activeElement && !$.contains( P.$root[0], activeElement ) ) {
722
- P.$holder.eq(0).focus()
723
- }
724
-
725
- // If something is superficially changed, update the `highlight` based on the `nav`.
726
- if ( !targetDisabled && targetData.nav ) {
727
- P.set( 'highlight', P.component.item.highlight, { nav: targetData.nav } )
728
- }
729
-
730
- // If something is picked, set `select` then close with focus.
731
- else if ( !targetDisabled && 'pick' in targetData ) {
732
- P.set( 'select', targetData.pick )
733
- if ( SETTINGS.closeOnSelect ) {
734
- P.close( true )
735
- }
736
- }
737
-
738
- // If a “clear” button is pressed, empty the values and close with focus.
739
- else if ( targetData.clear ) {
740
- P.clear()
741
- if ( SETTINGS.closeOnClear ) {
742
- P.close( true )
743
- }
744
- }
745
-
746
- else if ( targetData.close ) {
747
- P.close( true )
748
- }
749
-
750
- }) //P.$holder
751
-
752
- }
753
-
754
-
755
- /**
756
- * Prepare the hidden input element along with all bindings.
757
- */
758
- function prepareElementHidden() {
759
-
760
- var name
761
-
762
- if ( SETTINGS.hiddenName === true ) {
763
- name = ELEMENT.name
764
- ELEMENT.name = ''
765
- }
766
- else {
767
- name = [
768
- typeof SETTINGS.hiddenPrefix == 'string' ? SETTINGS.hiddenPrefix : '',
769
- typeof SETTINGS.hiddenSuffix == 'string' ? SETTINGS.hiddenSuffix : '_submit'
770
- ]
771
- name = name[0] + ELEMENT.name + name[1]
772
- }
773
-
774
- P._hidden = $(
775
- '<input ' +
776
- 'type=hidden ' +
777
-
778
- // Create the name using the original input’s with a prefix and suffix.
779
- 'name="' + name + '"' +
780
-
781
- // If the element has a value, set the hidden value as well.
782
- (
783
- $ELEMENT.data('value') || ELEMENT.value ?
784
- ' value="' + P.get('select', SETTINGS.formatSubmit) + '"' :
785
- ''
786
- ) +
787
- '>'
788
- )[0]
789
-
790
- $ELEMENT.
791
-
792
- // If the value changes, update the hidden input with the correct format.
793
- on('change.' + STATE.id, function() {
794
- P._hidden.value = ELEMENT.value ?
795
- P.get('select', SETTINGS.formatSubmit) :
796
- ''
797
- })
798
- }
799
-
800
-
801
- // Wait for transitions to end before focusing the holder. Otherwise, while
802
- // using the `container` option, the view jumps to the container.
803
- function focusPickerOnceOpened() {
804
-
805
- if (IS_DEFAULT_THEME && supportsTransitions) {
806
- P.$holder.find('.' + CLASSES.frame).one('transitionend', function() {
807
- P.$holder.eq(0).focus()
808
- })
809
- }
810
- else {
811
- setTimeout(function() {
812
- P.$holder.eq(0).focus()
813
- }, 0)
814
- }
815
- }
816
-
817
-
818
- function handleFocusToOpenEvent(event) {
819
-
820
- // Stop the event from propagating to the doc.
821
- event.stopPropagation()
822
-
823
- // Add the “target” class.
824
- $ELEMENT.addClass( CLASSES.target )
825
-
826
- // Add the “focused” class to the root.
827
- P.$root.addClass( CLASSES.focused )
828
-
829
- // And then finally open the picker.
830
- P.open()
831
- }
832
-
833
-
834
- // For iOS8.
835
- function handleKeydownEvent( event ) {
836
-
837
- var keycode = event.keyCode,
838
-
839
- // Check if one of the delete keys was pressed.
840
- isKeycodeDelete = /^(8|46)$/.test(keycode)
841
-
842
- // For some reason IE clears the input value on “escape”.
843
- if ( keycode == 27 ) {
844
- P.close( true )
845
- return false
846
- }
847
-
848
- // Check if `space` or `delete` was pressed or the picker is closed with a key movement.
849
- if ( keycode == 32 || isKeycodeDelete || !STATE.open && P.component.key[keycode] ) {
850
-
851
- // Prevent it from moving the page and bubbling to doc.
852
- event.preventDefault()
853
- event.stopPropagation()
854
-
855
- // If `delete` was pressed, clear the values and close the picker.
856
- // Otherwise open the picker.
857
- if ( isKeycodeDelete ) { P.clear().close() }
858
- else { P.open() }
859
- }
860
- }
861
-
862
-
863
- // Return a new picker instance.
864
- return new PickerInstance()
865
- } //PickerConstructor
866
-
867
-
868
-
869
- /**
870
- * The default classes and prefix to use for the HTML classes.
871
- */
872
- PickerConstructor.klasses = function( prefix ) {
873
- prefix = prefix || 'picker'
874
- return {
875
-
876
- picker: prefix,
877
- opened: prefix + '--opened',
878
- focused: prefix + '--focused',
879
-
880
- input: prefix + '__input',
881
- active: prefix + '__input--active',
882
- target: prefix + '__input--target',
883
-
884
- holder: prefix + '__holder',
885
-
886
- frame: prefix + '__frame',
887
- wrap: prefix + '__wrap',
888
-
889
- box: prefix + '__box'
890
- }
891
- } //PickerConstructor.klasses
892
-
893
-
894
-
895
- /**
896
- * Check if the default theme is being used.
897
- */
898
- function isUsingDefaultTheme( element ) {
899
-
900
- var theme,
901
- prop = 'position'
902
-
903
- // For IE.
904
- if ( element.currentStyle ) {
905
- theme = element.currentStyle[prop]
906
- }
907
-
908
- // For normal browsers.
909
- else if ( window.getComputedStyle ) {
910
- theme = getComputedStyle( element )[prop]
911
- }
912
-
913
- return theme == 'fixed'
914
- }
915
-
916
-
917
-
918
- /**
919
- * Get the width of the browser’s scrollbar.
920
- * Taken from: https://github.com/VodkaBears/Remodal/blob/master/src/jquery.remodal.js
921
- */
922
- function getScrollbarWidth() {
923
-
924
- if ( $html.height() <= $window.height() ) {
925
- return 0
926
- }
927
-
928
- var $outer = $( '<div style="visibility:hidden;width:100px" />' ).
929
- appendTo( 'body' )
930
-
931
- // Get the width without scrollbars.
932
- var widthWithoutScroll = $outer[0].offsetWidth
933
-
934
- // Force adding scrollbars.
935
- $outer.css( 'overflow', 'scroll' )
936
-
937
- // Add the inner div.
938
- var $inner = $( '<div style="width:100%" />' ).appendTo( $outer )
939
-
940
- // Get the width with scrollbars.
941
- var widthWithScroll = $inner[0].offsetWidth
942
-
943
- // Remove the divs.
944
- $outer.remove()
945
-
946
- // Return the difference between the widths.
947
- return widthWithoutScroll - widthWithScroll
948
- }
949
-
950
-
951
-
952
- /**
953
- * Get the target element from the event.
954
- * If ELEMENT is supplied and present in the event path (ELEMENT is ancestor of the target),
955
- * returns ELEMENT instead
956
- */
957
- function getRealEventTarget( event, ELEMENT ) {
958
-
959
- var path = []
960
-
961
- if ( event.path ) {
962
- path = event.path
963
- }
964
-
965
- if ( event.originalEvent && event.originalEvent.path ) {
966
- path = event.originalEvent.path
967
- }
968
-
969
- if ( path && path.length > 0 ) {
970
- if ( ELEMENT && path.indexOf( ELEMENT ) >= 0 ) {
971
- return ELEMENT
972
- } else {
973
- return path[0]
974
- }
975
- }
976
-
977
- return event.target
978
- }
979
-
980
- // taken from https://davidwalsh.name/javascript-debounce-function
981
- function debounce(func, wait, immediate) {
982
- var timeout;
983
- return function() {
984
- var context = this, args = arguments;
985
- var later = function() {
986
- timeout = null;
987
- if (!immediate) func.apply(context, args);
988
- };
989
- var callNow = immediate && !timeout;
990
- clearTimeout(timeout);
991
- timeout = setTimeout(later, wait);
992
- if (callNow) func.apply(context, args);
993
- };
994
- }
995
-
996
- /**
997
- * PickerConstructor helper methods.
998
- */
999
- PickerConstructor._ = {
1000
-
1001
- /**
1002
- * Create a group of nodes. Expects:
1003
- * `
1004
- {
1005
- min: {Integer},
1006
- max: {Integer},
1007
- i: {Integer},
1008
- node: {String},
1009
- item: {Function}
1010
- }
1011
- * `
1012
- */
1013
- group: function( groupObject ) {
1014
-
1015
- var
1016
- // Scope for the looped object
1017
- loopObjectScope,
1018
-
1019
- // Create the nodes list
1020
- nodesList = '',
1021
-
1022
- // The counter starts from the `min`
1023
- counter = PickerConstructor._.trigger( groupObject.min, groupObject )
1024
-
1025
-
1026
- // Loop from the `min` to `max`, incrementing by `i`
1027
- for ( ; counter <= PickerConstructor._.trigger( groupObject.max, groupObject, [ counter ] ); counter += groupObject.i ) {
1028
-
1029
- // Trigger the `item` function within scope of the object
1030
- loopObjectScope = PickerConstructor._.trigger( groupObject.item, groupObject, [ counter ] )
1031
-
1032
- // Splice the subgroup and create nodes out of the sub nodes
1033
- nodesList += PickerConstructor._.node(
1034
- groupObject.node,
1035
- loopObjectScope[ 0 ], // the node
1036
- loopObjectScope[ 1 ], // the classes
1037
- loopObjectScope[ 2 ] // the attributes
1038
- )
1039
- }
1040
-
1041
- // Return the list of nodes
1042
- return nodesList
1043
- }, //group
1044
-
1045
-
1046
- /**
1047
- * Create a dom node string
1048
- */
1049
- node: function( wrapper, item, klass, attribute ) {
1050
-
1051
- // If the item is false-y, just return an empty string
1052
- if ( !item ) return ''
1053
-
1054
- // If the item is an array, do a join
1055
- item = $.isArray( item ) ? item.join( '' ) : item
1056
-
1057
- // Check for the class
1058
- klass = klass ? ' class="' + klass + '"' : ''
1059
-
1060
- // Check for any attributes
1061
- attribute = attribute ? ' ' + attribute : ''
1062
-
1063
- // Return the wrapped item
1064
- return '<' + wrapper + klass + attribute + '>' + item + '</' + wrapper + '>'
1065
- }, //node
1066
-
1067
-
1068
- /**
1069
- * Lead numbers below 10 with a zero.
1070
- */
1071
- lead: function( number ) {
1072
- return ( number < 10 ? '0': '' ) + number
1073
- },
1074
-
1075
-
1076
- /**
1077
- * Trigger a function otherwise return the value.
1078
- */
1079
- trigger: function( callback, scope, args ) {
1080
- return typeof callback == 'function' ? callback.apply( scope, args || [] ) : callback
1081
- },
1082
-
1083
-
1084
- /**
1085
- * If the second character is a digit, length is 2 otherwise 1.
1086
- */
1087
- digits: function( string ) {
1088
- return ( /\d/ ).test( string[ 1 ] ) ? 2 : 1
1089
- },
1090
-
1091
-
1092
- /**
1093
- * Tell if something is a date object.
1094
- */
1095
- isDate: function( value ) {
1096
- return {}.toString.call( value ).indexOf( 'Date' ) > -1 && this.isInteger( value.getDate() )
1097
- },
1098
-
1099
-
1100
- /**
1101
- * Tell if something is an integer.
1102
- */
1103
- isInteger: function( value ) {
1104
- return {}.toString.call( value ).indexOf( 'Number' ) > -1 && value % 1 === 0
1105
- },
1106
-
1107
-
1108
- /**
1109
- * Create ARIA attribute strings.
1110
- */
1111
- ariaAttr: ariaAttr
1112
- } //PickerConstructor._
1113
-
1114
-
1115
-
1116
- /**
1117
- * Extend the picker with a component and defaults.
1118
- */
1119
- PickerConstructor.extend = function( name, Component ) {
1120
-
1121
- // Extend jQuery.
1122
- $.fn[ name ] = function( options, action ) {
1123
-
1124
- // Grab the component data.
1125
- var componentData = this.data( name )
1126
-
1127
- // If the picker is requested, return the data object.
1128
- if ( options == 'picker' ) {
1129
- return componentData
1130
- }
1131
-
1132
- // If the component data exists and `options` is a string, carry out the action.
1133
- if ( componentData && typeof options == 'string' ) {
1134
- return PickerConstructor._.trigger( componentData[ options ], componentData, [ action ] )
1135
- }
1136
-
1137
- // Otherwise go through each matched element and if the component
1138
- // doesn’t exist, create a new picker using `this` element
1139
- // and merging the defaults and options with a deep copy.
1140
- return this.each( function() {
1141
- var $this = $( this )
1142
- if ( !$this.data( name ) ) {
1143
- new PickerConstructor( this, name, Component, options )
1144
- }
1145
- })
1146
- }
1147
-
1148
- // Set the defaults.
1149
- $.fn[ name ].defaults = Component.defaults
1150
- } //PickerConstructor.extend
1151
-
1152
-
1153
-
1154
- function aria(element, attribute, value) {
1155
- if ( $.isPlainObject(attribute) ) {
1156
- for ( var key in attribute ) {
1157
- ariaSet(element, key, attribute[key])
1158
- }
1159
- }
1160
- else {
1161
- ariaSet(element, attribute, value)
1162
- }
1163
- }
1164
- function ariaSet(element, attribute, value) {
1165
- element.setAttribute(
1166
- (attribute == 'role' ? '' : 'aria-') + attribute,
1167
- value
1168
- )
1169
- }
1170
- function ariaAttr(attribute, data) {
1171
- if ( !$.isPlainObject(attribute) ) {
1172
- attribute = { attribute: data }
1173
- }
1174
- data = ''
1175
- for ( var key in attribute ) {
1176
- var attr = (key == 'role' ? '' : 'aria-') + key,
1177
- attrVal = attribute[key]
1178
- data += attrVal == null ? '' : attr + '="' + attribute[key] + '"'
1179
- }
1180
- return data
1181
- }
1182
-
1183
- // IE8 bug throws an error for activeElements within iframes.
1184
- function getActiveElement() {
1185
- try {
1186
- return document.activeElement
1187
- } catch ( err ) { }
1188
- }
1189
-
1190
-
1191
-
1192
- // Expose the picker constructor.
1193
- return PickerConstructor
1194
-
1195
-
1196
- });