pickadate-rails 3.5.5.0 → 3.5.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/Rakefile +2 -2
  4. data/lib/pickadate-rails/version.rb +1 -1
  5. data/vendor/assets/javascripts/pickadate/picker.date.js +18 -13
  6. data/vendor/assets/javascripts/pickadate/picker.js +165 -80
  7. data/vendor/assets/javascripts/pickadate/picker.time.js +20 -21
  8. data/vendor/assets/javascripts/pickadate/translations/ar.js +5 -1
  9. data/vendor/assets/javascripts/pickadate/translations/bg_BG.js +5 -1
  10. data/vendor/assets/javascripts/pickadate/translations/bs_BA.js +5 -1
  11. data/vendor/assets/javascripts/pickadate/translations/ca_ES.js +6 -1
  12. data/vendor/assets/javascripts/pickadate/translations/cs_CZ.js +5 -1
  13. data/vendor/assets/javascripts/pickadate/translations/da_DK.js +6 -1
  14. data/vendor/assets/javascripts/pickadate/translations/de_DE.js +6 -1
  15. data/vendor/assets/javascripts/pickadate/translations/el_GR.js +5 -1
  16. data/vendor/assets/javascripts/pickadate/translations/es_ES.js +6 -1
  17. data/vendor/assets/javascripts/pickadate/translations/et_EE.js +5 -1
  18. data/vendor/assets/javascripts/pickadate/translations/eu_ES.js +5 -1
  19. data/vendor/assets/javascripts/pickadate/translations/fa_ir.js +19 -0
  20. data/vendor/assets/javascripts/pickadate/translations/fi_FI.js +5 -1
  21. data/vendor/assets/javascripts/pickadate/translations/fr_FR.js +9 -4
  22. data/vendor/assets/javascripts/pickadate/translations/gl_ES.js +4 -0
  23. data/vendor/assets/javascripts/pickadate/translations/he_IL.js +5 -1
  24. data/vendor/assets/javascripts/pickadate/translations/hi_IN.js +20 -0
  25. data/vendor/assets/javascripts/pickadate/translations/hr_HR.js +5 -1
  26. data/vendor/assets/javascripts/pickadate/translations/hu_HU.js +5 -1
  27. data/vendor/assets/javascripts/pickadate/translations/id_ID.js +5 -1
  28. data/vendor/assets/javascripts/pickadate/translations/is_IS.js +5 -1
  29. data/vendor/assets/javascripts/pickadate/translations/it_IT.js +16 -5
  30. data/vendor/assets/javascripts/pickadate/translations/ja_JP.js +6 -2
  31. data/vendor/assets/javascripts/pickadate/translations/ko_KR.js +5 -1
  32. data/vendor/assets/javascripts/pickadate/translations/lt_LT.js +24 -0
  33. data/vendor/assets/javascripts/pickadate/translations/lv_LV.js +13 -0
  34. data/vendor/assets/javascripts/pickadate/translations/nb_NO.js +18 -0
  35. data/vendor/assets/javascripts/pickadate/translations/ne_NP.js +4 -0
  36. data/vendor/assets/javascripts/pickadate/translations/nl_NL.js +6 -1
  37. data/vendor/assets/javascripts/pickadate/translations/pl_PL.js +9 -4
  38. data/vendor/assets/javascripts/pickadate/translations/pt_BR.js +7 -2
  39. data/vendor/assets/javascripts/pickadate/translations/pt_PT.js +10 -5
  40. data/vendor/assets/javascripts/pickadate/translations/ro_RO.js +5 -1
  41. data/vendor/assets/javascripts/pickadate/translations/ru_RU.js +7 -2
  42. data/vendor/assets/javascripts/pickadate/translations/sk_SK.js +8 -3
  43. data/vendor/assets/javascripts/pickadate/translations/sl_SI.js +6 -1
  44. data/vendor/assets/javascripts/pickadate/translations/sv_SE.js +14 -5
  45. data/vendor/assets/javascripts/pickadate/translations/th_TH.js +5 -1
  46. data/vendor/assets/javascripts/pickadate/translations/tr_TR.js +7 -2
  47. data/vendor/assets/javascripts/pickadate/translations/uk_UA.js +5 -1
  48. data/vendor/assets/javascripts/pickadate/translations/vi_VN.js +5 -1
  49. data/vendor/assets/javascripts/pickadate/translations/zh_CN.js +7 -2
  50. data/vendor/assets/javascripts/pickadate/translations/zh_TW.js +6 -1
  51. data/vendor/assets/stylesheets/pickadate/classic.css +7 -17
  52. data/vendor/assets/stylesheets/pickadate/classic.time.css +1 -0
  53. data/vendor/assets/stylesheets/pickadate/default.css +15 -22
  54. data/vendor/assets/stylesheets/pickadate/default.time.css +1 -0
  55. metadata +8 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71f85c73882c8868e11fc979a535a49ed0e9cf51
4
- data.tar.gz: 887c27301050e47bc7e418e715ab36741d8b6632
3
+ metadata.gz: 626412aa4359c35536619a75f5f7a509f9e8d7d8
4
+ data.tar.gz: 6fd5434cd2149b3a9c525df1902f53e8cd2f0b30
5
5
  SHA512:
6
- metadata.gz: 58bb5aa19b5e32deabc967af127498d3f77ce64911328dd1ffb107445d8fa3d93d1c8e49d178af48e9d88e4f2ff4c3424777428d80c895c80bff4117a5a9e399
7
- data.tar.gz: 8db797f6ad25dd499d114578d4fa7780fa83137196cc05328032f2aa6bd2e12f6b5adbb765d4b2514f5def11021e85e2729753d39da33c4dc7e1ba11dadfe715
6
+ metadata.gz: f8f23d4dbda1213459ed90ecd294e7a4b167ee5c54e136ff0a018e6d683fda390fc2b694b1ea3b761d4e2ec8fcb2031b7b058569d48eb0a407c81e4790ba7e5a
7
+ data.tar.gz: 73ba6b8af4acc5da8e86f7b241a031f308422f1d87147328bc9b664a84e6ee051128c0bc4ccfacac815eecceba365baeaf884a4a025f5d57986dc478bbf0b411
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Pickadate-Rails [![Gem Version](https://badge.fury.io/rb/pickadate-rails.png)](http://badge.fury.io/rb/pickadate-rails)
2
2
 
3
- ## Pickadate Version: 3.5.5
3
+ ## Pickadate Version: 3.5.6
4
4
 
5
5
  Easily add [pickadate.js](https://github.com/amsul/pickadate.js) to your Rails 3.1+ application using the asset pipeline.
6
6
 
data/Rakefile CHANGED
@@ -5,8 +5,8 @@ namespace :pickadate do
5
5
  task :download do
6
6
  require 'fileutils'
7
7
 
8
- system "curl https://github.com/amsul/pickadate.js/archive/gh-pages.zip -f -L --create-dirs -o tmp/pickadate.zip"
9
- system "unzip tmp/pickadate.zip -d tmp/"
8
+ system "curl https://github.com/amsul/pickadate.js/archive/master.zip -f -L --create-dirs -o tmp/pickadate.zip"
9
+ system "unzip -o tmp/pickadate.zip -d tmp/"
10
10
  system "rm tmp/pickadate.zip"
11
11
 
12
12
  Dir["tmp/pickadate*/lib/picker*.js"].each do |file|
@@ -1,3 +1,3 @@
1
1
  module PickadateRails
2
- VERSION = "3.5.5.0"
2
+ VERSION = "3.5.6.0"
3
3
  end
@@ -1,6 +1,5 @@
1
-
2
1
  /*!
3
- * Date picker for pickadate.js v3.5.3
2
+ * Date picker for pickadate.js v3.5.6
4
3
  * http://amsul.github.io/pickadate.js/date.htm
5
4
  */
6
5
 
@@ -8,7 +7,7 @@
8
7
 
9
8
  // AMD.
10
9
  if ( typeof define == 'function' && define.amd )
11
- define( ['picker','jquery'], factory )
10
+ define( ['picker', 'jquery'], factory )
12
11
 
13
12
  // Node.js/browserify.
14
13
  else if ( typeof exports == 'object' )
@@ -83,7 +82,10 @@ function DatePicker( picker, settings ) {
83
82
  // When there’s a value, set the `select`, which in turn
84
83
  // also sets the `highlight` and `view`.
85
84
  if ( valueString ) {
86
- calendar.set( 'select', valueString, { format: formatString })
85
+ calendar.set( 'select', valueString, {
86
+ format: formatString,
87
+ defaultValue: true
88
+ })
87
89
  }
88
90
 
89
91
  // If there’s no value, default to highlighting “today”.
@@ -105,7 +107,7 @@ function DatePicker( picker, settings ) {
105
107
  targetDate = new Date( highlightedObject.year, highlightedObject.month, highlightedObject.date + timeChange )
106
108
  calendar.set(
107
109
  'highlight',
108
- [ targetDate.getFullYear(), targetDate.getMonth(), targetDate.getDate() ],
110
+ targetDate,
109
111
  { interval: timeChange }
110
112
  )
111
113
  this.render()
@@ -476,7 +478,7 @@ DatePicker.prototype.validate = function( type, dateObject, options ) {
476
478
  // • Not inverted and date enabled.
477
479
  // • Inverted and all dates disabled.
478
480
  // • ..and anything else.
479
- if ( !options || !options.nav ) if (
481
+ if ( !options || (!options.nav && !options.defaultValue) ) if (
480
482
  /* 1 */ ( !isFlippedBase && calendar.disabled( dateObject ) ) ||
481
483
  /* 2 */ ( isFlippedBase && calendar.disabled( dateObject ) && ( hasEnabledWeekdays || hasEnabledBeforeTarget || hasEnabledAfterTarget ) ) ||
482
484
  /* 3 */ ( !isFlippedBase && (dateObject.pick <= minLimitObject.pick || dateObject.pick >= maxLimitObject.pick) )
@@ -645,7 +647,8 @@ DatePicker.prototype.formats = (function() {
645
647
  function getWordLengthFromCollection( string, collection, dateObject ) {
646
648
 
647
649
  // Grab the first word from the string.
648
- var word = string.match( /\w+/ )[ 0 ]
650
+ // Regex pattern from http://stackoverflow.com/q/150033
651
+ var word = string.match( /[^\x00-\x7F]+|\w+/ )[ 0 ]
649
652
 
650
653
  // If there's no month index, add it to the date object
651
654
  if ( !dateObject.mm && !dateObject.m ) {
@@ -1185,7 +1188,8 @@ DatePicker.prototype.nodes = function( isOpen ) {
1185
1188
 
1186
1189
  var isSelected = selectedObject && selectedObject.pick == targetDate.pick,
1187
1190
  isHighlighted = highlightedObject && highlightedObject.pick == targetDate.pick,
1188
- isDisabled = disabledCollection && calendar.disabled( targetDate ) || targetDate.pick < minLimitObject.pick || targetDate.pick > maxLimitObject.pick
1191
+ isDisabled = disabledCollection && calendar.disabled( targetDate ) || targetDate.pick < minLimitObject.pick || targetDate.pick > maxLimitObject.pick,
1192
+ formattedDate = _.trigger( calendar.formats.toString, calendar, [ settings.format, targetDate ] )
1189
1193
 
1190
1194
  return [
1191
1195
  _.node(
@@ -1220,11 +1224,8 @@ DatePicker.prototype.nodes = function( isOpen ) {
1220
1224
  })([ settings.klass.day ]),
1221
1225
  'data-pick=' + targetDate.pick + ' ' + _.ariaAttr({
1222
1226
  role: 'gridcell',
1223
- selected: isSelected && calendar.$node.val() === _.trigger(
1224
- calendar.formats.toString,
1225
- calendar,
1226
- [ settings.format, targetDate ]
1227
- ) ? true : null,
1227
+ label: formattedDate,
1228
+ selected: isSelected && calendar.$node.val() === formattedDate ? true : null,
1228
1229
  activedescendant: isHighlighted ? true : null,
1229
1230
  disabled: isDisabled ? true : null
1230
1231
  })
@@ -1294,6 +1295,10 @@ DatePicker.defaults = (function( prefix ) {
1294
1295
  clear: 'Clear',
1295
1296
  close: 'Close',
1296
1297
 
1298
+ // Picker close behavior
1299
+ closeOnSelect: true,
1300
+ closeOnClear: true,
1301
+
1297
1302
  // The format to show on the `input` element
1298
1303
  format: 'd mmmm, yyyy',
1299
1304
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * pickadate.js v3.5.3, 2014/07/12
2
+ * pickadate.js v3.5.6, 2015/04/20
3
3
  * By Amsul, http://amsul.ca
4
4
  * Hosted on http://amsul.github.io/pickadate.js
5
5
  * Licensed under MIT
@@ -23,6 +23,7 @@
23
23
  var $window = $( window )
24
24
  var $document = $( document )
25
25
  var $html = $( document.documentElement )
26
+ var supportsTransitions = document.documentElement.style.transition != null
26
27
 
27
28
 
28
29
  /**
@@ -88,7 +89,7 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
88
89
 
89
90
  // Confirm focus state, convert into text input to remove UA stylings,
90
91
  // and set as readonly to prevent keyboard popup.
91
- ELEMENT.autofocus = ELEMENT == document.activeElement
92
+ ELEMENT.autofocus = ELEMENT == getActiveElement()
92
93
  ELEMENT.readOnly = !SETTINGS.editable
93
94
  ELEMENT.id = ELEMENT.id || STATE.id
94
95
  if ( ELEMENT.type != 'text' ) {
@@ -100,11 +101,16 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
100
101
  P.component = new COMPONENT(P, SETTINGS)
101
102
 
102
103
 
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"') )
104
+ // Create the picker root and then prepare it.
105
+ P.$root = $( '<div class="' + CLASSES.picker + '" id="' + ELEMENT.id + '_root" />' )
105
106
  prepareElementRoot()
106
107
 
107
108
 
109
+ // Create the picker holder and then prepare it.
110
+ P.$holder = $( createWrappedComponent() ).appendTo( P.$root )
111
+ prepareElementHolder()
112
+
113
+
108
114
  // If there’s a format for the hidden input element, create the element.
109
115
  if ( SETTINGS.formatSubmit ) {
110
116
  prepareElementHidden()
@@ -115,6 +121,11 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
115
121
  prepareElement()
116
122
 
117
123
 
124
+ // Insert the hidden input as specified in the settings.
125
+ if ( SETTINGS.containerHidden ) $( SETTINGS.containerHidden ).append( P._hidden )
126
+ else $ELEMENT.after( P._hidden )
127
+
128
+
118
129
  // Insert the root as specified in the settings.
119
130
  if ( SETTINGS.container ) $( SETTINGS.container ).append( P.$root )
120
131
  else $ELEMENT.after( P.$root )
@@ -139,7 +150,7 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
139
150
 
140
151
 
141
152
  // Once we’re all set, check the theme in use.
142
- IS_DEFAULT_THEME = isUsingDefaultTheme( P.$root.children()[ 0 ] )
153
+ IS_DEFAULT_THEME = isUsingDefaultTheme( P.$holder[0] )
143
154
 
144
155
 
145
156
  // If the element has autofocus, open the picker.
@@ -159,7 +170,11 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
159
170
  render: function( entireComponent ) {
160
171
 
161
172
  // Insert a new component holder in the root or box.
162
- if ( entireComponent ) P.$root.html( createWrappedComponent() )
173
+ if ( entireComponent ) {
174
+ P.$holder = $( createWrappedComponent() )
175
+ prepareElementHolder()
176
+ P.$root.html( P.$holder )
177
+ }
163
178
  else P.$root.find( '.' + CLASSES.box ).html( P.component.nodes( STATE.open ) )
164
179
 
165
180
  // Trigger the queued “render” events.
@@ -244,8 +259,8 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
244
259
  css( 'padding-right', '+=' + getScrollbarWidth() )
245
260
  }
246
261
 
247
- // Pass focus to the element’s jQuery object.
248
- $ELEMENT.trigger( 'focus' )
262
+ // Pass focus to the root element’s jQuery object.
263
+ focusPickerOnceOpened()
249
264
 
250
265
  // Bind the document events.
251
266
  $document.on( 'click.' + STATE.id + ' focusin.' + STATE.id, function( event ) {
@@ -263,7 +278,7 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
263
278
 
264
279
  // If the target was the holder that covers the screen,
265
280
  // keep the element focused to maintain tabindex.
266
- P.close( target === P.$root.children()[0] )
281
+ P.close( target === P.$holder[0] )
267
282
  }
268
283
 
269
284
  }).on( 'keydown.' + STATE.id, function( event ) {
@@ -286,7 +301,7 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
286
301
 
287
302
 
288
303
  // Check if there is a key movement or “enter” keypress on the element.
289
- else if ( target == ELEMENT && ( keycodeToMove || keycode == 13 ) ) {
304
+ else if ( target == P.$holder[0] && ( keycodeToMove || keycode == 13 ) ) {
290
305
 
291
306
  // Prevent the default action to stop page movement.
292
307
  event.preventDefault()
@@ -298,7 +313,10 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
298
313
 
299
314
  // On “enter”, if the highlighted item isn’t disabled, set the value and close.
300
315
  else if ( !P.$root.find( '.' + CLASSES.highlighted ).hasClass( CLASSES.disabled ) ) {
301
- P.set( 'select', P.component.item.highlight ).close()
316
+ P.set( 'select', P.component.item.highlight )
317
+ if ( SETTINGS.closeOnSelect ) {
318
+ P.close( true )
319
+ }
302
320
  }
303
321
  }
304
322
 
@@ -324,13 +342,18 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
324
342
 
325
343
  // If we need to give focus, do it before changing states.
326
344
  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 )
345
+ if ( SETTINGS.editable ) {
346
+ ELEMENT.focus()
347
+ }
348
+ else {
349
+ // ....ah yes! It would’ve been incomplete without a crazy workaround for IE :|
350
+ // The focus is triggered *after* the close has completed - causing it
351
+ // to open again. So unbind and rebind the event at the next tick.
352
+ P.$holder.off( 'focus.toOpen' ).focus()
353
+ setTimeout( function() {
354
+ P.$holder.on( 'focus.toOpen', handleFocusToOpenEvent )
355
+ }, 0 )
356
+ }
334
357
  }
335
358
 
336
359
  // Remove the “active” class.
@@ -438,6 +461,14 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
438
461
  return STATE[ thing ]
439
462
  }
440
463
 
464
+ // Return the submission value, if that.
465
+ if ( thing == 'valueSubmit' ) {
466
+ if ( P._hidden ) {
467
+ return P._hidden.value
468
+ }
469
+ thing = 'value'
470
+ }
471
+
441
472
  // Return the value, if that.
442
473
  if ( thing == 'value' ) {
443
474
  return ELEMENT.value
@@ -568,7 +599,9 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
568
599
  ),
569
600
 
570
601
  // Picker holder class
571
- CLASSES.holder
602
+ CLASSES.holder,
603
+
604
+ 'tabindex="-1"'
572
605
  ) //endreturn
573
606
  } //createWrappedComponent
574
607
 
@@ -591,42 +624,22 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
591
624
  val( $ELEMENT.data('value') ?
592
625
  P.get('select', SETTINGS.format) :
593
626
  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)
627
+ )
598
628
 
599
629
 
600
630
  // Only bind keydown events if the element isn’t editable.
601
631
  if ( !SETTINGS.editable ) {
602
632
 
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
- }
633
+ $ELEMENT.
616
634
 
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.
635
+ // On focus/click, open the picker.
636
+ on( 'focus.' + STATE.id + ' click.' + STATE.id, function(event) {
621
637
  event.preventDefault()
622
- event.stopPropagation()
638
+ P.open()
639
+ }).
623
640
 
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
- })
641
+ // Handle keyboard event based on the picker being opened or not.
642
+ on( 'keydown.' + STATE.id, handleKeydownEvent )
630
643
  }
631
644
 
632
645
 
@@ -635,7 +648,7 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
635
648
  haspopup: true,
636
649
  expanded: false,
637
650
  readonly: false,
638
- owns: ELEMENT.id + '_root' + (P._hidden ? ' ' + P._hidden.id : '')
651
+ owns: ELEMENT.id + '_root'
639
652
  })
640
653
  }
641
654
 
@@ -644,26 +657,44 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
644
657
  * Prepare the root picker element with all bindings.
645
658
  */
646
659
  function prepareElementRoot() {
660
+ aria( P.$root[0], 'hidden', true )
661
+ }
662
+
647
663
 
648
- P.$root.
664
+ /**
665
+ * Prepare the holder picker element with all bindings.
666
+ */
667
+ function prepareElementHolder() {
668
+
669
+ P.$holder.
649
670
 
650
671
  on({
651
672
 
652
- // When something within the root is focused, stop from bubbling
673
+ // For iOS8.
674
+ keydown: handleKeydownEvent,
675
+
676
+ 'focus.toOpen': handleFocusToOpenEvent,
677
+
678
+ blur: function() {
679
+ // Remove the “target” class.
680
+ $ELEMENT.removeClass( CLASSES.target )
681
+ },
682
+
683
+ // When something within the holder is focused, stop from bubbling
653
684
  // to the doc and remove the “focused” state from the root.
654
685
  focusin: function( event ) {
655
686
  P.$root.removeClass( CLASSES.focused )
656
687
  event.stopPropagation()
657
688
  },
658
689
 
659
- // When something within the root holder is clicked, stop it
690
+ // When something within the holder is clicked, stop it
660
691
  // from bubbling to the doc.
661
692
  'mousedown click': function( event ) {
662
693
 
663
694
  var target = event.target
664
695
 
665
696
  // Make sure the target isn’t the root holder so it can bubble up.
666
- if ( target != P.$root.children()[ 0 ] ) {
697
+ if ( target != P.$holder[0] ) {
667
698
 
668
699
  event.stopPropagation()
669
700
 
@@ -671,20 +702,21 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
671
702
  // prevent cases where focus is shifted onto external elements
672
703
  // when using things like jQuery mobile or MagnificPopup (ref: #249 & #120).
673
704
  // Also, for Firefox, don’t prevent action on the `option` element.
674
- if ( event.type == 'mousedown' && !$( target ).is( ':input' ) && target.nodeName != 'OPTION' ) {
705
+ if ( event.type == 'mousedown' && !$( target ).is( 'input, select, textarea, button, option' )) {
675
706
 
676
707
  event.preventDefault()
677
708
 
678
- // Re-focus onto the element so that users can click away
709
+ // Re-focus onto the holder so that users can click away
679
710
  // from elements focused within the picker.
680
- ELEMENT.focus()
711
+ P.$holder[0].focus()
681
712
  }
682
713
  }
683
714
  }
715
+
684
716
  }).
685
717
 
686
718
  // If there’s a click on an actionable element, carry out the actions.
687
- on( 'click', '[data-pick], [data-nav], [data-clear]', function() {
719
+ on( 'click', '[data-pick], [data-nav], [data-clear], [data-close]', function() {
688
720
 
689
721
  var $target = $( this ),
690
722
  targetData = $target.data(),
@@ -692,34 +724,41 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
692
724
 
693
725
  // * For IE, non-focusable elements can be active elements as well
694
726
  // (http://stackoverflow.com/a/2684561).
695
- activeElement = document.activeElement
696
- activeElement = activeElement && ( activeElement.type || activeElement.href ) && activeElement
727
+ activeElement = getActiveElement()
728
+ activeElement = activeElement && ( activeElement.type || activeElement.href )
697
729
 
698
730
  // If it’s disabled or nothing inside is actively focused, re-focus the element.
699
731
  if ( targetDisabled || activeElement && !$.contains( P.$root[0], activeElement ) ) {
700
- ELEMENT.focus()
732
+ P.$holder[0].focus()
701
733
  }
702
734
 
703
735
  // If something is superficially changed, update the `highlight` based on the `nav`.
704
- if ( targetData.nav && !targetDisabled ) {
736
+ if ( !targetDisabled && targetData.nav ) {
705
737
  P.set( 'highlight', P.component.item.highlight, { nav: targetData.nav } )
706
738
  }
707
739
 
708
740
  // 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 )
741
+ else if ( !targetDisabled && 'pick' in targetData ) {
742
+ P.set( 'select', targetData.pick )
743
+ if ( SETTINGS.closeOnSelect ) {
744
+ P.close( true )
745
+ }
711
746
  }
712
747
 
713
748
  // If a “clear” button is pressed, empty the values and close with focus.
714
749
  else if ( targetData.clear ) {
715
- P.clear().close( true )
750
+ P.clear()
751
+ if ( SETTINGS.closeOnClear ) {
752
+ P.close( true )
753
+ }
716
754
  }
717
- })
718
- .on('click', '[data-close]', function () {
719
- P.close(true);
720
- }) //P.$root
721
755
 
722
- aria( P.$root[0], 'hidden', true )
756
+ else if ( targetData.close ) {
757
+ P.close( true )
758
+ }
759
+
760
+ }) //P.$holder
761
+
723
762
  }
724
763
 
725
764
 
@@ -749,9 +788,6 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
749
788
  // Create the name using the original input’s with a prefix and suffix.
750
789
  'name="' + name + '"' +
751
790
 
752
- // Create the ID using the original input’s; only if it has one.
753
- (ELEMENT.id ? 'id="' + ELEMENT.id + '_hidden"' : '') +
754
-
755
791
  // If the element has a value, set the hidden value as well.
756
792
  (
757
793
  $ELEMENT.data('value') || ELEMENT.value ?
@@ -768,29 +804,70 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
768
804
  P._hidden.value = ELEMENT.value ?
769
805
  P.get('select', SETTINGS.formatSubmit) :
770
806
  ''
771
- }).
807
+ })
808
+ }
809
+
772
810
 
773
- // Insert the hidden input after the element.
774
- after(P._hidden)
811
+ // Wait for transitions to end before focusing the holder. Otherwise, while
812
+ // using the `container` option, the view jumps to the container.
813
+ function focusPickerOnceOpened() {
814
+
815
+ if (IS_DEFAULT_THEME && supportsTransitions) {
816
+ P.$holder.find('.' + CLASSES.frame).one('transitionend', function() {
817
+ P.$holder[0].focus()
818
+ })
819
+ }
820
+ else {
821
+ P.$holder[0].focus()
822
+ }
775
823
  }
776
824
 
777
825
 
778
- // Separated for IE
779
- function focusToOpen( event ) {
826
+ function handleFocusToOpenEvent(event) {
780
827
 
781
828
  // Stop the event from propagating to the doc.
782
829
  event.stopPropagation()
783
830
 
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
- }
831
+ // Add the “target” class.
832
+ $ELEMENT.addClass( CLASSES.target )
833
+
834
+ // Add the “focused” class to the root.
835
+ P.$root.addClass( CLASSES.focused )
788
836
 
789
837
  // And then finally open the picker.
790
838
  P.open()
791
839
  }
792
840
 
793
841
 
842
+ // For iOS8.
843
+ function handleKeydownEvent( event ) {
844
+
845
+ var keycode = event.keyCode,
846
+
847
+ // Check if one of the delete keys was pressed.
848
+ isKeycodeDelete = /^(8|46)$/.test(keycode)
849
+
850
+ // For some reason IE clears the input value on “escape”.
851
+ if ( keycode == 27 ) {
852
+ P.close( true )
853
+ return false
854
+ }
855
+
856
+ // Check if `space` or `delete` was pressed or the picker is closed with a key movement.
857
+ if ( keycode == 32 || isKeycodeDelete || !STATE.open && P.component.key[keycode] ) {
858
+
859
+ // Prevent it from moving the page and bubbling to doc.
860
+ event.preventDefault()
861
+ event.stopPropagation()
862
+
863
+ // If `delete` was pressed, clear the values and close the picker.
864
+ // Otherwise open the picker.
865
+ if ( isKeycodeDelete ) { P.clear().close() }
866
+ else { P.open() }
867
+ }
868
+ }
869
+
870
+
794
871
  // Return a new picker instance.
795
872
  return new PickerInstance()
796
873
  } //PickerConstructor
@@ -810,6 +887,7 @@ PickerConstructor.klasses = function( prefix ) {
810
887
 
811
888
  input: prefix + '__input',
812
889
  active: prefix + '__input--active',
890
+ target: prefix + '__input--target',
813
891
 
814
892
  holder: prefix + '__holder',
815
893
 
@@ -1066,6 +1144,13 @@ function ariaAttr(attribute, data) {
1066
1144
  return data
1067
1145
  }
1068
1146
 
1147
+ // IE8 bug throws an error for activeElements within iframes.
1148
+ function getActiveElement() {
1149
+ try {
1150
+ return document.activeElement
1151
+ } catch ( err ) { }
1152
+ }
1153
+
1069
1154
 
1070
1155
 
1071
1156
  // Expose the picker constructor.