bitsnote-assets 0.0.1 → 0.0.2

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