Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow enabling of disabled dates. closes #248 #269

Merged
merged 1 commit into from
Dec 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ There are currently two pickers: **date** and **time**.
File | Contents | Size (min & gzip)
----------------------- | ------------------------ | ----------------------
`picker.js` | __Base *__ | 1.33kb
`picker.date.js` | Date picker | 2.05kb
`picker.date.js` | Date picker | 2.10kb
`picker.time.js` | Time picker | 1.38kb

__*__ The base script is **required** for any of the pickers to function.
Expand Down
42 changes: 38 additions & 4 deletions _raw/lib/picker.date.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ DatePicker.prototype.get = function( type ) {
DatePicker.prototype.create = function( type, value, options ) {

var isInfiniteValue,
isInverted = false,
calendar = this

// If there’s no value, use the type as the value.
Expand All @@ -192,6 +193,8 @@ DatePicker.prototype.create = function( type, value, options ) {
// If it’s an array, convert it into a date and make sure
// that it’s a valid date – otherwise default to today.
else if ( $.isArray( value ) ) {
isInverted = value[ 3 ] === 'inverted'

value = new Date( value[ 0 ], value[ 1 ], value[ 2 ] )
value = Picker._.isDate( value ) ? value : calendar.create().obj
}
Expand All @@ -213,7 +216,8 @@ DatePicker.prototype.create = function( type, value, options ) {
date: isInfiniteValue || value.getDate(),
day: isInfiniteValue || value.getDay(),
obj: isInfiniteValue || value,
pick: isInfiniteValue || value.getTime()
pick: isInfiniteValue || value.getTime(),
isInverted: isInverted
}
} //DatePicker.prototype.create

Expand Down Expand Up @@ -407,7 +411,7 @@ DatePicker.prototype.disabled = function( dateObject ) {
var calendar = this,

// Filter through the disabled dates to check if this is one.
isDisabledDate = !!calendar.item.disable.filter( function( dateToDisable ) {
disabledRules = calendar.item.disable.filter( function( dateToDisable ) {

// If the date is a number, match the weekday with 0index and `firstDay` check.
if ( Picker._.isInteger( dateToDisable ) ) {
Expand All @@ -418,7 +422,11 @@ DatePicker.prototype.disabled = function( dateObject ) {
if ( $.isArray( dateToDisable ) || Picker._.isDate( dateToDisable ) ) {
return dateObject.pick === calendar.create( dateToDisable ).pick
}
}).length
}),

isDisabledDate = !!disabledRules.length && !disabledRules.filter( function( rule ) {
return $.isArray(rule) && rule[3] === 'inverted'
} ).length


// Check the calendar “enabled” flag and respectively flip the
Expand Down Expand Up @@ -610,7 +618,10 @@ DatePicker.prototype.flipItem = function( type, value/*, options*/ ) {
else if ( $.isArray( value ) ) {

// Check if we have to add/remove from collection.
if ( !isInverted && type == 'enable' || isInverted && type == 'disable' ) {
if ( !isInverted && type == 'enable') {
collection = calendar.addEnabled( collection, value )
}
else if (isInverted && type == 'disable' ) {
collection = calendar.removeDisabled( collection, value )
}
else if ( !isInverted && type == 'disable' || isInverted && type == 'enable' ) {
Expand All @@ -622,6 +633,29 @@ DatePicker.prototype.flipItem = function( type, value/*, options*/ ) {
} //DatePicker.prototype.flipItem


/**
* Add an enabled (inverted) item to the disabled collection.
*/
DatePicker.prototype.addEnabled = function( collection, item ) {
var calendar = this

collection = calendar.removeDisabled( collection, item )

item.map( function( timeUnit ) {
if ( !timeUnit.push ) {
return
}

timeUnit.push('inverted')

if ( !calendar.filterDisabled( collection, timeUnit ).length ) {
collection.push( timeUnit )
}
})
return collection
} //DatePicker.prototype.addEnabled


/**
* Add an item to the disabled collection.
*/
Expand Down
24 changes: 12 additions & 12 deletions api.htm
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ <h2 class="heading heading--divide"><span class="heading__text">Clear<a class="h

<pre class="pre--demo"><code data-language="javascript">picker.clear()</code></pre>

<fieldset class="fieldset fieldset--demo js__fieldset"><div class="fieldset__wrapper"><button id=button__api-clear class="fieldset__button button button--small">Clear</button><input id="demo__api-clear" class="fieldset__input " type=text value="13 October, 2013" placeholder="Try me&hellip;"></div></fieldset>
<fieldset class="fieldset fieldset--demo js__fieldset"><div class="fieldset__wrapper"><button id=button__api-clear class="fieldset__button button button--small">Clear</button><input id="demo__api-clear" class="fieldset__input " type=text value="8 November, 2013" placeholder="Try me&hellip;"></div></fieldset>

<p>This is a shorthand that uses <a href="#method-set">the <code class="function">set</code> method</a> behind the scenes.</p>

Expand Down Expand Up @@ -309,10 +309,10 @@ <h3 class="heading heading--divide"><span class="heading__text"><b>*</b> Item Ob
day: 6,

// The underlying JavaScript Date object.
obj: { 'Sat Apr 20 2013 00:00:00 GMT-0400 (EDT)' },
obj: { 'Sat Apr 20 2013 00:00:00 GMT+0200 (CEST)' },

// The “pick” value used for comparisons.
pick: 1366430400000
pick: 1366408800000
}</code></pre>

<p>Here’s a <b>time picker item object</b> for <u>4:20 PM</u>:</p>
Expand Down Expand Up @@ -342,7 +342,7 @@ <h2 class="heading heading--divide"><span class="heading__text">Get <code class=

<pre class="pre--demo"><code data-language="javascript">picker.get() // Short for `picker.get('value')`.</code></pre>

<fieldset class="fieldset fieldset--demo js__fieldset"><div class="fieldset__wrapper"><button id=button__api-get--value class="fieldset__button button button--small">Log the value</button><input id="demo__api-get--value" class="fieldset__input " type=text value="13 October, 2013" placeholder="Open your console and try me&hellip;"></div></fieldset>
<fieldset class="fieldset fieldset--demo js__fieldset"><div class="fieldset__wrapper"><button id=button__api-get--value class="fieldset__button button button--small">Log the value</button><input id="demo__api-get--value" class="fieldset__input " type=text value="8 November, 2013" placeholder="Open your console and try me&hellip;"></div></fieldset>

</div> <!-- .section__block -->

Expand Down Expand Up @@ -527,7 +527,7 @@ <h2 class="heading heading--divide"><span class="heading__text">Set <code class=

<pre class="pre--demo"><code data-language="javascript">picker.set('clear')</code></pre>

<fieldset class="fieldset fieldset--demo js__fieldset"><div class="fieldset__wrapper"><button id=button__api-set-clear class="fieldset__button button button--small">Clear</button><input id="demo__api-set-clear" class="fieldset__input " type=text value="13 October, 2013" placeholder="Try me&hellip;"></div></fieldset>
<fieldset class="fieldset fieldset--demo js__fieldset"><div class="fieldset__wrapper"><button id=button__api-set-clear class="fieldset__button button button--small">Clear</button><input id="demo__api-set-clear" class="fieldset__input " type=text value="8 November, 2013" placeholder="Try me&hellip;"></div></fieldset>

<p>This is the full form of <a href="#method-clear">the <code class="function">clear</code> method</a>.</p>

Expand All @@ -549,10 +549,10 @@ <h3 class="heading heading--divide"><span class="heading__text">Select a date <a
picker.set('select', [2013,3,20])

// Using JavaScript Date objects.
picker.set('select', { 'Tue Apr 30 2013 00:00:00 GMT-0400 (EDT)' })
picker.set('select', { 'Tue Apr 30 2013 00:00:00 GMT+0200 (CEST)' })

// Using positive integers as UNIX timestamps.
picker.set('select', 1365961912346)</code></pre>
picker.set('select', 1365940312346)</code></pre>

<fieldset class="fieldset fieldset--demo js__fieldset"><div class="fieldset__wrapper"><button id=button__api-set--select-date-array class="fieldset__button button button--small">Select using an array</button><button id=button__api-set--select-date-js class="fieldset__button button button--small">Select using a JS Date</button><button id=button__api-set--select-date-integer class="fieldset__button button button--small">Select using an integer</button><input id="demo__api-set--select-date" class="fieldset__input " type=text value="" placeholder="Try me&hellip;"></div></fieldset>

Expand Down Expand Up @@ -584,10 +584,10 @@ <h3 class="heading heading--divide"><span class="heading__text">Highlight a date
picker.set('highlight', [2013,3,20])

// Using JavaScript Date objects.
picker.set('highlight', { 'Tue Apr 30 2013 00:00:00 GMT-0400 (EDT)' })
picker.set('highlight', { 'Tue Apr 30 2013 00:00:00 GMT+0200 (CEST)' })

// Using positive integers as UNIX timestamps.
picker.set('highlight', 1365961912346)</code></pre>
picker.set('highlight', 1365940312346)</code></pre>

<fieldset class="fieldset fieldset--demo js__fieldset"><div class="fieldset__wrapper"><button id=button__api-set--highlight-date-array class="fieldset__button button button--small">Highlight using an array</button><button id=button__api-set--highlight-date-js class="fieldset__button button button--small">Highlight using a JS Date</button><button id=button__api-set--highlight-date-integer class="fieldset__button button button--small">Highlight using an integer</button><input id="demo__api-set--highlight-date" class="fieldset__input " type=text value="" placeholder="Try me&hellip;"></div></fieldset>

Expand Down Expand Up @@ -621,7 +621,7 @@ <h3 class="heading heading--divide"><span class="heading__text">Viewset a date <
picker.set('view', [2000,3,20])

// Using JavaScript Date objects.
picker.set('view', { 'Sun Aug 14 1988 00:00:00 GMT-0400 (EDT)' })
picker.set('view', { 'Sun Aug 14 1988 00:00:00 GMT+0200 (CEST)' })

// Using positive integers as UNIX timestamps.
picker.set('view', 1587355200000)</code></pre>
Expand Down Expand Up @@ -656,7 +656,7 @@ <h3 class="heading heading--divide"><span class="heading__text">Limit the min da
picker.set('min', [2013,3,20])

// Using JavaScript Date objects.
picker.set('min', { 'Wed Aug 14 2013 00:00:00 GMT-0400 (EDT)' })
picker.set('min', { 'Wed Aug 14 2013 00:00:00 GMT+0200 (CEST)' })

// Using integers as days relative to today.
picker.set('min', -4)
Expand Down Expand Up @@ -703,7 +703,7 @@ <h3 class="heading heading--divide"><span class="heading__text">Limit the max da
picker.set('max', [2013,3,20])

// Using JavaScript Date objects.
picker.set('max', { 'Wed Aug 14 2013 00:00:00 GMT-0400 (EDT)' })
picker.set('max', { 'Wed Aug 14 2013 00:00:00 GMT+0200 (CEST)' })

// Using integers as days relative to today.
picker.set('max', 4)
Expand Down
2 changes: 1 addition & 1 deletion lib/compressed/picker.date.js

Large diffs are not rendered by default.

Loading