pickadate-rails 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8bff9abfe44be28299cf0476db7df35d0f06a2eb
4
- data.tar.gz: aa22306029c2d465c55af70a43cd96c196c91adf
3
+ metadata.gz: ee040041eef6c517e68b6879b8a780c6bdedd8ac
4
+ data.tar.gz: fbc696df4935a0b63e33134e53735b186a9ff8f1
5
5
  SHA512:
6
- metadata.gz: 2875e44174b3f403691b2ad4e8988333b48523f484253b4a8ad97d590e4a9fb7f5aaaed49cdfbe486fddf6d4b68d31e36768ec5e42f9c3eaebf202aa25e91ee1
7
- data.tar.gz: 164be77a8e98e992f0f2779893c16737f6397c55b922fd71ccd2cce9b66b38bfb73f4fcd808e1c1a903d35910cac4fbdbe8f3ddd70c7d89f6aaf9376c00df004
6
+ metadata.gz: 83d3eee2474fdb0ec31f6c9f9b14b41d258dcd00235131c5569b26a1b2a6ba4dd18eaed2c7a9ee6a1f12308958e55d02e522f2b6bd75accedda2cd98e4cad9ee
7
+ data.tar.gz: 1666b78ee8359dcf46538f6ef0a475436dc62b166469157a8ecbd5125cd6e853b35845f2d449495c4ee671145a5fb7db48f597a07c634cb7494f7ad04acd888d
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.3.0
3
+ ## Pickadate Version: 3.3.1
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
 
@@ -1,3 +1,3 @@
1
1
  module PickadateRails
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.1"
3
3
  end
@@ -1,6 +1,6 @@
1
1
 
2
2
  /*!
3
- * Date picker for pickadate.js v3.3.0
3
+ * Date picker for pickadate.js v3.3.1
4
4
  * http://amsul.github.io/pickadate.js/date.htm
5
5
  */
6
6
 
@@ -185,7 +185,7 @@ DatePicker.prototype.create = function( type, value, options ) {
185
185
  }
186
186
 
187
187
  // If it’s an object, use the native date object.
188
- else if ( Picker._.isObject( value ) && Picker._.isInteger( value.pick ) ) {
188
+ else if ( $.isPlainObject( value ) && Picker._.isInteger( value.pick ) ) {
189
189
  value = value.obj
190
190
  }
191
191
 
@@ -235,7 +235,7 @@ DatePicker.prototype.now = function( type, value, options ) {
235
235
  */
236
236
  DatePicker.prototype.navigate = function( type, value, options ) {
237
237
 
238
- if ( Picker._.isObject( value ) ) {
238
+ if ( $.isPlainObject( value ) ) {
239
239
 
240
240
  var targetDateObject = new Date( value.year, value.month + ( options && options.nav ? options.nav : 0 ), 1 ),
241
241
  year = targetDateObject.getFullYear(),
@@ -307,7 +307,7 @@ DatePicker.prototype.validate = function( type, dateObject, options ) {
307
307
  interval = options && options.interval ? options.interval : 1,
308
308
 
309
309
  // Check if the calendar enabled dates are inverted.
310
- isInverted = calendar.item.enable === -1,
310
+ isFlippedBase = calendar.item.enable === -1,
311
311
 
312
312
  // Check if we have any enabled dates after/before now.
313
313
  hasEnabledBeforeTarget, hasEnabledAfterTarget,
@@ -320,7 +320,7 @@ DatePicker.prototype.validate = function( type, dateObject, options ) {
320
320
  reachedMin, reachedMax,
321
321
 
322
322
  // Check if the calendar is inverted and at least one weekday is enabled.
323
- hasEnabledWeekdays = isInverted && calendar.item.disable.filter( function( value ) {
323
+ hasEnabledWeekdays = isFlippedBase && calendar.item.disable.filter( function( value ) {
324
324
 
325
325
  // If there’s a date, check where it is relative to the target.
326
326
  if ( $.isArray( value ) ) {
@@ -346,15 +346,15 @@ DatePicker.prototype.validate = function( type, dateObject, options ) {
346
346
  // • Inverted and all dates disabled.
347
347
  // • ..and anything else.
348
348
  if ( !options.nav ) if (
349
- /* 1 */ ( !isInverted && calendar.disabled( dateObject ) ) ||
350
- /* 2 */ ( isInverted && calendar.disabled( dateObject ) && ( hasEnabledWeekdays || hasEnabledBeforeTarget || hasEnabledAfterTarget ) ) ||
349
+ /* 1 */ ( !isFlippedBase && calendar.disabled( dateObject ) ) ||
350
+ /* 2 */ ( isFlippedBase && calendar.disabled( dateObject ) && ( hasEnabledWeekdays || hasEnabledBeforeTarget || hasEnabledAfterTarget ) ) ||
351
351
  /* 3 */ ( dateObject.pick <= minLimitObject.pick || dateObject.pick >= maxLimitObject.pick )
352
352
  ) {
353
353
 
354
354
 
355
355
  // When inverted, flip the direction if there aren’t any enabled weekdays
356
356
  // and there are no enabled dates in the direction of the interval.
357
- if ( isInverted && !hasEnabledWeekdays && ( ( !hasEnabledAfterTarget && interval > 0 ) || ( !hasEnabledBeforeTarget && interval < 0 ) ) ) {
357
+ if ( isFlippedBase && !hasEnabledWeekdays && ( ( !hasEnabledAfterTarget && interval > 0 ) || ( !hasEnabledBeforeTarget && interval < 0 ) ) ) {
358
358
  interval *= -1
359
359
  }
360
360
 
@@ -407,7 +407,7 @@ DatePicker.prototype.disabled = function( dateObject ) {
407
407
  var calendar = this,
408
408
 
409
409
  // Filter through the disabled dates to check if this is one.
410
- isDisabledDate = !!calendar.item.disable.filter( function( dateToDisable ) {
410
+ isDisabledMatch = calendar.item.disable.filter( function( dateToDisable ) {
411
411
 
412
412
  // If the date is a number, match the weekday with 0index and `firstDay` check.
413
413
  if ( Picker._.isInteger( dateToDisable ) ) {
@@ -418,12 +418,16 @@ DatePicker.prototype.disabled = function( dateObject ) {
418
418
  if ( $.isArray( dateToDisable ) || Picker._.isDate( dateToDisable ) ) {
419
419
  return dateObject.pick === calendar.create( dateToDisable ).pick
420
420
  }
421
- }).length
421
+ })
422
422
 
423
+ // If this date matches a disabled date, confirm it’s not inverted.
424
+ isDisabledMatch = isDisabledMatch.length && !isDisabledMatch.filter(function( dateToDisable ) {
425
+ return $.isArray( dateToDisable ) && dateToDisable[3] == 'inverted'
426
+ }).length
423
427
 
424
428
  // Check the calendar “enabled” flag and respectively flip the
425
429
  // disabled state. Then also check if it’s beyond the min/max limits.
426
- return calendar.item.enable === -1 ? !isDisabledDate : isDisabledDate ||
430
+ return calendar.item.enable === -1 ? !isDisabledMatch : isDisabledMatch ||
427
431
  dateObject.pick < calendar.item.min.pick ||
428
432
  dateObject.pick > calendar.item.max.pick
429
433
 
@@ -438,7 +442,7 @@ DatePicker.prototype.parse = function( type, value, options ) {
438
442
  var calendar = this,
439
443
  parsingObject = {}
440
444
 
441
- if ( !value || Picker._.isInteger( value ) || $.isArray( value ) || Picker._.isDate( value ) || Picker._.isObject( value ) && Picker._.isInteger( value.pick ) ) {
445
+ if ( !value || Picker._.isInteger( value ) || $.isArray( value ) || Picker._.isDate( value ) || $.isPlainObject( value ) && Picker._.isInteger( value.pick ) ) {
442
446
  return value
443
447
  }
444
448
 
@@ -587,11 +591,11 @@ DatePicker.prototype.flipItem = function( type, value/*, options*/ ) {
587
591
 
588
592
  var calendar = this,
589
593
  collection = calendar.item.disable,
590
- isInverted = calendar.item.enable === -1
594
+ isFlippedBase = calendar.item.enable === -1
591
595
 
592
596
  // Flip the enabled and disabled dates.
593
597
  if ( value == 'flip' ) {
594
- calendar.item.enable = isInverted ? 1 : -1
598
+ calendar.item.enable = isFlippedBase ? 1 : -1
595
599
  }
596
600
 
597
601
  // Reset the collection and enable the base state.
@@ -610,28 +614,79 @@ DatePicker.prototype.flipItem = function( type, value/*, options*/ ) {
610
614
  else if ( $.isArray( value ) ) {
611
615
 
612
616
  // Check if we have to add/remove from collection.
613
- if ( !isInverted && type == 'enable' || isInverted && type == 'disable' ) {
614
- collection = calendar.removeDisabled( collection, value )
615
- }
616
- else if ( !isInverted && type == 'disable' || isInverted && type == 'enable' ) {
617
+ if ( isFlippedBase && type == 'enable' || !isFlippedBase && type == 'disable' ) {
617
618
  collection = calendar.addDisabled( collection, value )
618
619
  }
620
+ else if ( !isFlippedBase && type == 'enable' ) {
621
+ collection = calendar.addEnabled( collection, value )
622
+ }
623
+ else if ( isFlippedBase && type == 'disable' ) {
624
+ collection = calendar.removeDisabled( collection, value )
625
+ }
619
626
  }
620
627
 
621
628
  return collection
622
629
  } //DatePicker.prototype.flipItem
623
630
 
624
631
 
632
+ /**
633
+ * Add an enabled (inverted) item to the disabled collection.
634
+ */
635
+ DatePicker.prototype.addEnabled = function( collection, item ) {
636
+
637
+ var calendar = this
638
+
639
+ // Go through each item to enable.
640
+ item.map( function( timeUnit ) {
641
+
642
+ // Check if the time unit is already within the collection.
643
+ if ( calendar.filterDisabled( collection, timeUnit, 1 ).length ) {
644
+
645
+ // Remove the unit directly from the collection.
646
+ collection = calendar.removeDisabled( collection, [timeUnit] )
647
+
648
+ // If the unit is an array and it falls within a
649
+ // disabled weekday, invert it and then insert it.
650
+ if (
651
+ $.isArray( timeUnit ) &&
652
+ collection.filter( function( disabledDate ) {
653
+ return Picker._.isInteger( disabledDate ) && calendar.create( timeUnit ).day === disabledDate - 1
654
+ }).length
655
+ ) {
656
+ timeUnit = timeUnit.slice(0)
657
+ timeUnit.push( 'inverted' )
658
+ collection.push( timeUnit )
659
+ }
660
+ }
661
+ })
662
+
663
+ // Return the final collection.
664
+ return collection
665
+ } //DatePicker.prototype.addEnabled
666
+
667
+
625
668
  /**
626
669
  * Add an item to the disabled collection.
627
670
  */
628
671
  DatePicker.prototype.addDisabled = function( collection, item ) {
672
+
629
673
  var calendar = this
674
+
675
+ // Go through each item to disable.
630
676
  item.map( function( timeUnit ) {
677
+
678
+ // Add the time unit if it isn’t already within the collection.
631
679
  if ( !calendar.filterDisabled( collection, timeUnit ).length ) {
632
680
  collection.push( timeUnit )
633
681
  }
682
+
683
+ // If the time unit is an array and falls within the range, just remove it.
684
+ else if ( $.isArray( timeUnit ) && calendar.filterDisabled( collection, timeUnit, 1 ).length ) {
685
+ collection = calendar.removeDisabled( collection, [timeUnit] )
686
+ }
634
687
  })
688
+
689
+ // Return the final collection.
635
690
  return collection
636
691
  } //DatePicker.prototype.addDisabled
637
692
 
@@ -640,10 +695,17 @@ DatePicker.prototype.addDisabled = function( collection, item ) {
640
695
  * Remove an item from the disabled collection.
641
696
  */
642
697
  DatePicker.prototype.removeDisabled = function( collection, item ) {
698
+
643
699
  var calendar = this
700
+
701
+ // Go through each item to enable.
644
702
  item.map( function( timeUnit ) {
703
+
704
+ // Filter each item out of the collection.
645
705
  collection = calendar.filterDisabled( collection, timeUnit, 1 )
646
706
  })
707
+
708
+ // Return the final colleciton.
647
709
  return collection
648
710
  } //DatePicker.prototype.removeDisabled
649
711
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  /*!
3
- * pickadate.js v3.3.0, 2013/10/13
3
+ * pickadate.js v3.3.1, 2013/12/04
4
4
  * By Amsul, http://amsul.ca
5
5
  * Hosted on http://amsul.github.io/pickadate.js
6
6
  * Licensed under MIT
@@ -92,7 +92,7 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
92
92
  // and set as readonly to prevent keyboard popup.
93
93
  ELEMENT.autofocus = ELEMENT == document.activeElement
94
94
  ELEMENT.type = 'text'
95
- ELEMENT.readOnly = true
95
+ ELEMENT.readOnly = !SETTINGS.editable
96
96
 
97
97
 
98
98
  // Create a new picker component with the settings.
@@ -110,10 +110,28 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
110
110
  event.stopPropagation()
111
111
  },
112
112
 
113
- // If the click is not on the root holder, stop it from bubbling to the doc.
113
+ // When something within the root holder is clicked, stop it
114
+ // from bubbling to the doc.
114
115
  'mousedown click': function( event ) {
115
- if ( event.target != P.$root.children()[ 0 ] ) {
116
+
117
+ var target = event.target
118
+
119
+ // Make sure the target isn’t the root holder so it can bubble up.
120
+ if ( target != P.$root.children()[ 0 ] ) {
121
+
116
122
  event.stopPropagation()
123
+
124
+ // * For mousedown events, cancel the default action in order to
125
+ // prevent cases where focus is shifted onto external elements
126
+ // when using things like jQuery mobile or MagnificPopup (ref: #249 & #120).
127
+ if ( event.type == 'mousedown' && !$( target ).is( ':input' ) ) {
128
+
129
+ event.preventDefault()
130
+
131
+ // Re-focus onto the element so that users can click away
132
+ // from elements focused within the picker.
133
+ ELEMENT.focus()
134
+ }
117
135
  }
118
136
  }
119
137
  }).
@@ -131,7 +149,7 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
131
149
  activeElement = activeElement && ( activeElement.type || activeElement.href )
132
150
 
133
151
  // If it’s disabled or nothing inside is actively focused, re-focus the element.
134
- if ( targetDisabled || !$.contains( P.$root[0], activeElement ) ) {
152
+ if ( targetDisabled || activeElement && !$.contains( P.$root[0], activeElement ) ) {
135
153
  ELEMENT.focus()
136
154
  }
137
155
 
@@ -175,8 +193,20 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
175
193
  }
176
194
 
177
195
 
178
- // Add the class and bind the events on the element.
179
- $ELEMENT.addClass( CLASSES.input ).
196
+ // Prepare the input element.
197
+ $ELEMENT.
198
+
199
+ // Store the picker data by component name.
200
+ data( NAME, P ).
201
+
202
+ // Add the “input” class name.
203
+ addClass( CLASSES.input ).
204
+
205
+ // If there’s a `data-value`, update the value of the element.
206
+ val( $ELEMENT.data( 'value' ) ? PickerConstructor._.trigger( P.component.formats.toString, P.component, [ SETTINGS.format, P.component.item.select ] ) : ELEMENT.value ).
207
+
208
+ // Insert the hidden input after the element.
209
+ after( P._hidden ).
180
210
 
181
211
  // On focus/click, open the picker and adjust the root “focused” state.
182
212
  on( 'focus.P' + STATE.id + ' click.P' + STATE.id, focusToOpen ).
@@ -186,7 +216,10 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
186
216
  if ( P._hidden ) {
187
217
  P._hidden.value = ELEMENT.value ? PickerConstructor._.trigger( P.component.formats.toString, P.component, [ SETTINGS.formatSubmit, P.component.item.select ] ) : ''
188
218
  }
189
- }).
219
+ })
220
+
221
+ // Only bind keydown events if the element isn’t editable.
222
+ if ( !SETTINGS.editable ) $ELEMENT.
190
223
 
191
224
  // Handle keyboard event based on the picker being opened or not.
192
225
  on( 'keydown.P' + STATE.id, function( event ) {
@@ -214,16 +247,7 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
214
247
  if ( isKeycodeDelete ) { P.clear().close() }
215
248
  else { P.open() }
216
249
  }
217
- }).
218
-
219
- // If there’s a `data-value`, update the value of the element.
220
- val( $ELEMENT.data( 'value' ) ? PickerConstructor._.trigger( P.component.formats.toString, P.component, [ SETTINGS.format, P.component.item.select ] ) : ELEMENT.value ).
221
-
222
- // Insert the hidden input after the element.
223
- after( P._hidden ).
224
-
225
- // Store the picker data by component name.
226
- data( NAME, P )
250
+ })
227
251
 
228
252
 
229
253
  // Insert the root as specified in the settings.
@@ -337,11 +361,18 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
337
361
  // Bind the document events.
338
362
  $document.on( 'click.P' + STATE.id + ' focusin.P' + STATE.id, function( event ) {
339
363
 
364
+ var target = event.target
365
+
340
366
  // If the target of the event is not the element, close the picker picker.
341
367
  // * Don’t worry about clicks or focusins on the root because those don’t bubble up.
342
368
  // Also, for Firefox, a click on an `option` element bubbles up directly
343
369
  // to the doc. So make sure the target wasn't the doc.
344
- if ( event.target != ELEMENT && event.target != document ) P.close()
370
+ if ( target != ELEMENT && target != document ) {
371
+
372
+ // If the target was the holder that covers the screen,
373
+ // keep the element focused to maintain tabindex.
374
+ P.close( target === P.$root.children()[0] )
375
+ }
345
376
 
346
377
  }).on( 'keydown.P' + STATE.id, function( event ) {
347
378
 
@@ -445,9 +476,12 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
445
476
  set: function( thing, value, options ) {
446
477
 
447
478
  var thingItem, thingValue,
448
- thingIsObject = PickerConstructor._.isObject( thing ),
479
+ thingIsObject = $.isPlainObject( thing ),
449
480
  thingObject = thingIsObject ? thing : {}
450
481
 
482
+ // Make sure we have usable options.
483
+ options = thingIsObject && $.isPlainObject( value ) ? value : options || {}
484
+
451
485
  if ( thing ) {
452
486
 
453
487
  // If the thing isn’t an object, make it one.
@@ -463,7 +497,7 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
463
497
 
464
498
  // First, if the item exists and there’s a value, set it.
465
499
  if ( P.component.item[ thingItem ] ) {
466
- P.component.set( thingItem, thingValue, options || {} )
500
+ P.component.set( thingItem, thingValue, options )
467
501
  }
468
502
 
469
503
  // Then, check to update the element value and broadcast a change.
@@ -478,8 +512,8 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
478
512
  P.render()
479
513
  }
480
514
 
481
- // Trigger queued “set” events and pass the `thingObject`.
482
- return P.trigger( 'set', thingObject )
515
+ // When the method isn’t muted, trigger queued “set” events and pass the `thingObject`.
516
+ return options.muted ? P : P.trigger( 'set', thingObject )
483
517
  }, //set
484
518
 
485
519
 
@@ -518,7 +552,7 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
518
552
  on: function( thing, method ) {
519
553
 
520
554
  var thingName, thingMethod,
521
- thingIsObject = PickerConstructor._.isObject( thing ),
555
+ thingIsObject = $.isPlainObject( thing ),
522
556
  thingObject = thingIsObject ? thing : {}
523
557
 
524
558
  if ( thing ) {
@@ -740,14 +774,6 @@ PickerConstructor._ = {
740
774
  },
741
775
 
742
776
 
743
- /**
744
- * Tell if something is an object.
745
- */
746
- isObject: function( value ) {
747
- return {}.toString.call( value ).indexOf( 'Object' ) > -1
748
- },
749
-
750
-
751
777
  /**
752
778
  * Tell if something is a date object.
753
779
  */
@@ -1,6 +1,6 @@
1
1
 
2
2
  /*!
3
- * Time picker for pickadate.js v3.3.0
3
+ * Time picker for pickadate.js v3.3.1
4
4
  * http://amsul.github.io/pickadate.js/time.htm
5
5
  */
6
6
 
@@ -102,7 +102,7 @@ function TimePicker( picker, settings ) {
102
102
  var $pickerHolder = picker.$root.children(),
103
103
  $viewset = $pickerHolder.find( '.' + settings.klass.viewset )
104
104
  if ( $viewset.length ) {
105
- $pickerHolder[ 0 ].scrollTop += $viewset.position().top - ( $viewset[ 0 ].clientHeight * 2 )
105
+ $pickerHolder[ 0 ].scrollTop = ~~$viewset.position().top - ( $viewset[ 0 ].clientHeight * 2 )
106
106
  }
107
107
  }).
108
108
  on( 'open', function() {
@@ -170,30 +170,41 @@ TimePicker.prototype.create = function( type, value, options ) {
170
170
 
171
171
  var clock = this
172
172
 
173
- // If there's no value, use the type as the value.
173
+ // If theres no value, use the type as the value.
174
174
  value = value === undefined ? type : value
175
175
 
176
- // If it's an object, use the "pick" value.
177
- if ( Picker._.isObject( value ) && Picker._.isInteger( value.pick ) ) {
176
+ // If its a date object, convert it into an array.
177
+ if ( Picker._.isDate( value ) ) {
178
+ value = [ value.getHours(), value.getMinutes() ]
179
+ }
180
+
181
+ // If it’s an object, use the “pick” value.
182
+ if ( $.isPlainObject( value ) && Picker._.isInteger( value.pick ) ) {
178
183
  value = value.pick
179
184
  }
180
185
 
181
- // If it's an array, convert it into minutes.
186
+ // If its an array, convert it into minutes.
182
187
  else if ( $.isArray( value ) ) {
183
188
  value = +value[ 0 ] * MINUTES_IN_HOUR + (+value[ 1 ])
184
189
  }
185
190
 
186
- // If no valid value is passed, set it to "now".
191
+ // If no valid value is passed, set it to now”.
187
192
  else if ( !Picker._.isInteger( value ) ) {
188
193
  value = clock.now( type, value, options )
189
194
  }
190
195
 
191
- // If we're setting the max, make sure it's greater than the min.
196
+ // If were setting the max, make sure its greater than the min.
192
197
  if ( type == 'max' && value < clock.item.min.pick ) {
193
198
  value += MINUTES_IN_DAY
194
199
  }
195
200
 
196
- // Normalize it into a "reachable" interval.
201
+ // If the value doesn’t fall directly on the interval,
202
+ // add one interval to indicate it as “passed”.
203
+ if ( type != 'min' && type != 'max' && (value - clock.item.min.pick) % clock.item.interval !== 0 ) {
204
+ value += clock.item.interval
205
+ }
206
+
207
+ // Normalize it into a “reachable” interval.
197
208
  value = clock.normalize( type, value, options )
198
209
 
199
210
  // Return the compiled object.
@@ -208,7 +219,7 @@ TimePicker.prototype.create = function( type, value, options ) {
208
219
  // The time in total minutes.
209
220
  time: ( MINUTES_IN_DAY + value ) % MINUTES_IN_DAY,
210
221
 
211
- // Reference to the "relative" value to pick.
222
+ // Reference to the relative value to pick.
212
223
  pick: value
213
224
  }
214
225
  } //TimePicker.prototype.create
@@ -222,6 +233,9 @@ TimePicker.prototype.now = function( type, value/*, options*/ ) {
222
233
  var date = new Date(),
223
234
  dateMinutes = date.getHours() * MINUTES_IN_HOUR + date.getMinutes()
224
235
 
236
+ // Make sure “now” falls within the interval range.
237
+ dateMinutes -= dateMinutes % this.item.interval
238
+
225
239
  // If the value is a number, adjust by that many intervals because
226
240
  // the time has passed. In the case of “midnight” and a negative `min`,
227
241
  // increase the value by 2. Otherwise increase it by 1.
@@ -244,12 +258,12 @@ TimePicker.prototype.now = function( type, value/*, options*/ ) {
244
258
  */
245
259
  TimePicker.prototype.normalize = function( type, value/*, options*/ ) {
246
260
 
247
- var minObject = this.item.min, interval = this.item.interval,
261
+ var interval = this.item.interval,
248
262
 
249
- // If setting min and it doesn’t exist, don’t shift anything.
263
+ // If setting min time, don’t shift anything.
250
264
  // Otherwise get the value and min difference and then
251
265
  // normalize the difference with the interval.
252
- difference = type == 'min' && !minObject ? 0 : ( value - minObject.pick ) % interval
266
+ difference = type == 'min' ? 0 : ( value - this.item.min.pick ) % interval
253
267
 
254
268
  // If it’s a negative value, add one interval to keep it as “passed”.
255
269
  return value - ( difference + ( value < 0 ? interval : 0 ) )
@@ -263,18 +277,18 @@ TimePicker.prototype.measure = function( type, value, options ) {
263
277
 
264
278
  var clock = this
265
279
 
266
- // If it's anything false-y, set it to the default.
280
+ // If its anything false-y, set it to the default.
267
281
  if ( !value ) {
268
282
  value = type == 'min' ? [ 0, 0 ] : [ HOURS_IN_DAY - 1, MINUTES_IN_HOUR - 1 ]
269
283
  }
270
284
 
271
- // If it's a literal true, or an integer, make it relative to now.
285
+ // If its a literal true, or an integer, make it relative to now.
272
286
  else if ( value === true || Picker._.isInteger( value ) ) {
273
287
  value = clock.now( type, value, options )
274
288
  }
275
289
 
276
- // If it's an object already, just normalize it.
277
- else if ( Picker._.isObject( value ) && Picker._.isInteger( value.pick ) ) {
290
+ // If its an object already, just normalize it.
291
+ else if ( $.isPlainObject( value ) && Picker._.isInteger( value.pick ) ) {
278
292
  value = clock.normalize( type, value.pick, options )
279
293
  }
280
294
 
@@ -320,21 +334,28 @@ TimePicker.prototype.disabled = function( timeObject ) {
320
334
  clock = this,
321
335
 
322
336
  // Filter through the disabled times to check if this is one.
323
- isDisabledTime = clock.item.disable.filter( function( timeToDisable ) {
337
+ isDisabledMatch = clock.item.disable.filter( function( timeToDisable ) {
324
338
 
325
339
  // If the time is a number, match the hours.
326
340
  if ( Picker._.isInteger( timeToDisable ) ) {
327
341
  return timeObject.hour == timeToDisable
328
342
  }
329
343
 
330
- // If it's an array, create the object and match the times.
331
- if ( $.isArray( timeToDisable ) ) {
344
+ // If its an array, create the object and match the times.
345
+ if ( $.isArray( timeToDisable ) || Picker._.isDate( timeToDisable ) ) {
332
346
  return timeObject.pick == clock.create( timeToDisable ).pick
333
347
  }
334
- }).length
348
+ })
349
+
350
+ // If this time matches a disabled time, confirm it’s not inverted.
351
+ isDisabledMatch = isDisabledMatch.length && !isDisabledMatch.filter(function( timeToDisable ) {
352
+ return $.isArray( timeToDisable ) && timeToDisable[2] == 'inverted'
353
+ }).length
335
354
 
336
355
  // If the clock is "enabled" flag is flipped, flip the condition.
337
- return clock.item.enable === -1 ? !isDisabledTime : isDisabledTime
356
+ return clock.item.enable === -1 ? !isDisabledMatch : isDisabledMatch ||
357
+ timeObject.pick < clock.item.min.pick ||
358
+ timeObject.pick > clock.item.max.pick
338
359
  } //TimePicker.prototype.disabled
339
360
 
340
361
 
@@ -384,7 +405,7 @@ TimePicker.prototype.parse = function( type, value, options ) {
384
405
  var clock = this,
385
406
  parsingObject = {}
386
407
 
387
- if ( !value || Picker._.isInteger( value ) || $.isArray( value ) || Picker._.isDate( value ) || Picker._.isObject( value ) && Picker._.isInteger( value.pick ) ) {
408
+ if ( !value || Picker._.isInteger( value ) || $.isArray( value ) || Picker._.isDate( value ) || $.isPlainObject( value ) && Picker._.isInteger( value.pick ) ) {
388
409
  return value
389
410
  }
390
411
 
@@ -491,11 +512,11 @@ TimePicker.prototype.flipItem = function( type, value/*, options*/ ) {
491
512
 
492
513
  var clock = this,
493
514
  collection = clock.item.disable,
494
- isFlipped = clock.item.enable === -1
515
+ isFlippedBase = clock.item.enable === -1
495
516
 
496
517
  // Flip the enabled and disabled times.
497
518
  if ( value == 'flip' ) {
498
- clock.item.enable = isFlipped ? 1 : -1
519
+ clock.item.enable = isFlippedBase ? 1 : -1
499
520
  }
500
521
 
501
522
  // Reset the collection and enable the base state.
@@ -514,29 +535,79 @@ TimePicker.prototype.flipItem = function( type, value/*, options*/ ) {
514
535
  else if ( $.isArray( value ) ) {
515
536
 
516
537
  // Check if we have to add/remove from collection.
517
- if ( !isFlipped && type == 'enable' || isFlipped && type == 'disable' ) {
518
- collection = clock.removeDisabled( collection, value )
519
- }
520
- else if ( !isFlipped && type == 'disable' || isFlipped && type == 'enable' ) {
538
+ if ( isFlippedBase && type == 'enable' || !isFlippedBase && type == 'disable' ) {
521
539
  collection = clock.addDisabled( collection, value )
522
540
  }
541
+ else if ( !isFlippedBase && type == 'enable' ) {
542
+ collection = clock.addEnabled( collection, value )
543
+ }
544
+ else if ( isFlippedBase && type == 'disable' ) {
545
+ collection = clock.removeDisabled( collection, value )
546
+ }
523
547
  }
524
548
 
525
549
  return collection
526
550
  } //TimePicker.prototype.flipItem
527
551
 
528
552
 
553
+ /**
554
+ * Add an enabled (inverted) item to the disabled collection.
555
+ */
556
+ TimePicker.prototype.addEnabled = function( collection, item ) {
557
+
558
+ var clock = this
559
+
560
+ // Go through each item to enable.
561
+ item.map( function( timeUnit ) {
562
+
563
+ // Check if the time unit is already within the collection.
564
+ if ( clock.filterDisabled( collection, timeUnit, 1 ).length ) {
565
+
566
+ // Remove the unit directly from the collection.
567
+ collection = clock.removeDisabled( collection, [timeUnit] )
568
+
569
+ // If the unit is an array and it falls within a
570
+ // disabled weekday, invert it and then insert it.
571
+ if (
572
+ $.isArray( timeUnit ) &&
573
+ collection.filter( function( disabledHour ) {
574
+ return Picker._.isInteger( disabledHour ) && clock.create( timeUnit ).hour === disabledHour
575
+ }).length
576
+ ) {
577
+ timeUnit = timeUnit.slice(0)
578
+ timeUnit.push( 'inverted' )
579
+ collection.push( timeUnit )
580
+ }
581
+ }
582
+ })
583
+
584
+ // Return the final collection.
585
+ return collection
586
+ } //TimePicker.prototype.addEnabled
587
+
588
+
529
589
  /**
530
590
  * Add an item to the disabled collection.
531
591
  */
532
592
  TimePicker.prototype.addDisabled = function( collection, item ) {
593
+
533
594
  var clock = this
534
- if ( item === false ) collection = []
535
- else item.map( function( timeUnit ) {
595
+
596
+ // Go through each item to disable.
597
+ item.map( function( timeUnit ) {
598
+
599
+ // Add the time unit if it isn’t already within the collection.
536
600
  if ( !clock.filterDisabled( collection, timeUnit ).length ) {
537
601
  collection.push( timeUnit )
538
602
  }
603
+
604
+ // If the time unit is an array and falls within the range, just remove it.
605
+ else if ( $.isArray( timeUnit ) && clock.filterDisabled( collection, timeUnit, 1 ).length ) {
606
+ collection = clock.removeDisabled( collection, [timeUnit] )
607
+ }
539
608
  })
609
+
610
+ // Return the final collection.
540
611
  return collection
541
612
  } //TimePicker.prototype.addDisabled
542
613
 
@@ -545,10 +616,17 @@ TimePicker.prototype.addDisabled = function( collection, item ) {
545
616
  * Remove an item from the disabled collection.
546
617
  */
547
618
  TimePicker.prototype.removeDisabled = function( collection, item ) {
619
+
548
620
  var clock = this
621
+
622
+ // Go through each item to enable.
549
623
  item.map( function( timeUnit ) {
624
+
625
+ // Filter each item out of the collection.
550
626
  collection = clock.filterDisabled( collection, timeUnit, 1 )
551
627
  })
628
+
629
+ // Return the final colleciton.
552
630
  return collection
553
631
  } //TimePicker.prototype.removeDisabled
554
632
 
@@ -1,13 +1,13 @@
1
1
  // French
2
2
 
3
3
  jQuery.extend( jQuery.fn.pickadate.defaults, {
4
- monthsFull: [ 'janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre' ],
5
- monthsShort: [ 'jan', 'fev', 'mar', 'avr', 'mai', 'juin', 'juil', 'aou', 'sep', 'oct', 'nov', 'dec' ],
6
- weekdaysFull: [ 'dimanche', 'lundi', 'mardy', 'mercredi', 'jeudi', 'vendredi', 'samedi' ],
7
- weekdaysShort: [ 'dim', 'lun', 'mar', 'mer', 'jeu', 'ven', 'sam' ],
8
- today: 'aujourd\'hui',
9
- clear: 'effacer',
4
+ monthsFull: [ 'Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre' ],
5
+ monthsShort: [ 'Jan', 'Fev', 'Mar', 'Avr', 'Mai', 'Juin', 'Juil', 'Aou', 'Sep', 'Oct', 'Nov', 'Dec' ],
6
+ weekdaysFull: [ 'Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi' ],
7
+ weekdaysShort: [ 'Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam' ],
8
+ today: 'Aujourd\'hui',
9
+ clear: 'Effacer',
10
10
  firstDay: 1,
11
11
  format: 'dd mmmm yyyy',
12
12
  formatSubmit: 'yyyy/mm/dd'
13
- });
13
+ });
@@ -0,0 +1,13 @@
1
+ // Traditional Chinese
2
+
3
+ jQuery.extend( jQuery.fn.pickadate.defaults, {
4
+ monthsFull: [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月' ],
5
+ monthsShort: [ '一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二' ],
6
+ weekdaysFull: [ '星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六' ],
7
+ weekdaysShort: [ '日', '一', '二', '三', '四', '五', '六' ],
8
+ today: '今天',
9
+ clear: '清除',
10
+ firstDay: 1,
11
+ format: 'yyyy 年 mm 月 dd 日',
12
+ formatSubmit: 'yyyy/mm/dd'
13
+ });
@@ -2,8 +2,7 @@
2
2
  $BASE-PICKER
3
3
  ========================================================================== */
4
4
  /**
5
- * Note: the root picker element should __NOT__ be styled
6
- * more than what’s here. Style the `.picker__holder` instead.
5
+ * Note: the root picker element should *NOT* be styled more than what’s here.
7
6
  */
8
7
  .picker {
9
8
  font-size: 16px;
@@ -12,6 +11,10 @@
12
11
  color: #000000;
13
12
  position: absolute;
14
13
  z-index: 10000;
14
+ -webkit-user-select: none;
15
+ -moz-user-select: none;
16
+ -ms-user-select: none;
17
+ user-select: none;
15
18
  }
16
19
  /**
17
20
  * The picker input element.
@@ -39,8 +42,7 @@
39
42
  * Demo: http://amsul.github.io/pickadate.js
40
43
  */
41
44
  /**
42
- * Note: the root picker element should __NOT__ be styled
43
- * more than what’s here. Style the `.picker__holder` instead.
45
+ * Note: the root picker element should *NOT* be styled more than what’s here.
44
46
  */
45
47
  .picker {
46
48
  width: 100%;
@@ -52,14 +54,16 @@
52
54
  position: absolute;
53
55
  background: #ffffff;
54
56
  border: 1px solid #aaaaaa;
57
+ border-top-width: 0;
58
+ border-bottom-width: 0;
59
+ -webkit-border-radius: 0 0 5px 5px;
60
+ -moz-border-radius: 0 0 5px 5px;
61
+ border-radius: 0 0 5px 5px;
55
62
  -webkit-box-sizing: border-box;
56
63
  -moz-box-sizing: border-box;
57
64
  box-sizing: border-box;
58
65
  min-width: 176px;
59
66
  max-width: 466px;
60
- -webkit-border-radius: 0 0 5px 5px;
61
- -moz-border-radius: 0 0 5px 5px;
62
- border-radius: 0 0 5px 5px;
63
67
  max-height: 0;
64
68
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
65
69
  filter: alpha(opacity=0);
@@ -68,9 +72,19 @@
68
72
  -webkit-transform: translateY(-1em) perspective(600px) rotateX(10deg);
69
73
  -moz-transform: translateY(-1em) perspective(600px) rotateX(10deg);
70
74
  transform: translateY(-1em) perspective(600px) rotateX(10deg);
71
- -webkit-transition: all 0.15s ease-out, max-height 0 0.15s;
72
- -moz-transition: all 0.15s ease-out, max-height 0 0.15s;
73
- transition: all 0.15s ease-out, max-height 0 0.15s;
75
+ -webkit-transition: all 0.15s ease-out, max-height 0 0.15s, border-width 0 0.15s;
76
+ -moz-transition: all 0.15s ease-out, max-height 0 0.15s, border-width 0 0.15s;
77
+ transition: all 0.15s ease-out, max-height 0 0.15s, border-width 0 0.15s;
78
+ }
79
+ /**
80
+ * The frame and wrap work together to ensure that
81
+ * clicks within the picker don’t reach the holder.
82
+ */
83
+ .picker__frame {
84
+ padding: 1px;
85
+ }
86
+ .picker__wrap {
87
+ margin: -1px;
74
88
  }
75
89
  /**
76
90
  * When the picker opens...
@@ -81,12 +95,14 @@
81
95
  filter: alpha(opacity=100);
82
96
  -moz-opacity: 1;
83
97
  opacity: 1;
98
+ border-top-width: 1px;
99
+ border-bottom-width: 1px;
84
100
  -webkit-transform: translateY(0) perspective(600px) rotateX(0);
85
101
  -moz-transform: translateY(0) perspective(600px) rotateX(0);
86
102
  transform: translateY(0) perspective(600px) rotateX(0);
87
- -webkit-transition: all 0.15s ease-out, max-height 0;
88
- -moz-transition: all 0.15s ease-out, max-height 0;
89
- transition: all 0.15s ease-out, max-height 0;
103
+ -webkit-transition: all 0.15s ease-out, max-height 0, border-width 0;
104
+ -moz-transition: all 0.15s ease-out, max-height 0, border-width 0;
105
+ transition: all 0.15s ease-out, max-height 0, border-width 0;
90
106
  -webkit-box-shadow: 0 6px 18px 1px rgba(0, 0, 0, 0.12);
91
107
  -moz-box-shadow: 0 6px 18px 1px rgba(0, 0, 0, 0.12);
92
108
  box-shadow: 0 6px 18px 1px rgba(0, 0, 0, 0.12);
@@ -124,4 +124,5 @@
124
124
  */
125
125
  .picker--time .picker__box {
126
126
  padding: 0;
127
+ position: relative;
127
128
  }
@@ -2,8 +2,7 @@
2
2
  $BASE-PICKER
3
3
  ========================================================================== */
4
4
  /**
5
- * Note: the root picker element should __NOT__ be styled
6
- * more than what’s here. Style the `.picker__holder` instead.
5
+ * Note: the root picker element should *NOT* be styled more than what’s here.
7
6
  */
8
7
  .picker {
9
8
  font-size: 16px;
@@ -12,6 +11,10 @@
12
11
  color: #000000;
13
12
  position: absolute;
14
13
  z-index: 10000;
14
+ -webkit-user-select: none;
15
+ -moz-user-select: none;
16
+ -ms-user-select: none;
17
+ user-select: none;
15
18
  }
16
19
  /**
17
20
  * The picker input element.
@@ -38,6 +41,9 @@
38
41
  * Default mobile-first, responsive styling for pickadate.js
39
42
  * Demo: http://amsul.github.io/pickadate.js
40
43
  */
44
+ /**
45
+ * Note: the root picker element should *NOT* be styled more than what’s here.
46
+ */
41
47
  /**
42
48
  * Make the holder and frame fullscreen.
43
49
  */
@@ -0,0 +1,29 @@
1
+ /*!
2
+ * Styling for RTL (right-to-left) languages using pickadate.js
3
+ */
4
+ /**
5
+ * Switch the direction - only really necessary if
6
+ * it hasn’t already been applied higher up in the DOM.
7
+ */
8
+ .picker {
9
+ direction: rtl;
10
+ }
11
+ /**
12
+ * Flip around the “next” and “previous” buttons.
13
+ */
14
+ .picker__nav--next {
15
+ right: auto;
16
+ left: -1em;
17
+ }
18
+ .picker__nav--prev {
19
+ left: auto;
20
+ right: -1em;
21
+ }
22
+ .picker__nav--next:before {
23
+ border-left: 0;
24
+ border-right: 0.75em solid #000000;
25
+ }
26
+ .picker__nav--prev:before {
27
+ border-right: 0;
28
+ border-left: 0.75em solid #000000;
29
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pickadate-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Fraser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-15 00:00:00.000000000 Z
11
+ date: 2013-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -105,12 +105,14 @@ files:
105
105
  - vendor/assets/javascripts/pickadate/translations/tr_TR.js
106
106
  - vendor/assets/javascripts/pickadate/translations/uk_UA.js
107
107
  - vendor/assets/javascripts/pickadate/translations/zh_CN.js
108
+ - vendor/assets/javascripts/pickadate/translations/zh_TW.js
108
109
  - vendor/assets/stylesheets/pickadate/classic.css
109
110
  - vendor/assets/stylesheets/pickadate/classic.date.css
110
111
  - vendor/assets/stylesheets/pickadate/classic.time.css
111
112
  - vendor/assets/stylesheets/pickadate/default.css
112
113
  - vendor/assets/stylesheets/pickadate/default.date.css
113
114
  - vendor/assets/stylesheets/pickadate/default.time.css
115
+ - vendor/assets/stylesheets/pickadate/rtl.css
114
116
  homepage: https://github.com/veracross/pickadate-rails
115
117
  licenses:
116
118
  - MIT