Skip to content

Commit

Permalink
fixed #279: call set method with muted listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
amsul committed Dec 1, 2013
1 parent f2c8d04 commit f4cbdad
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
9 changes: 6 additions & 3 deletions _raw/lib/picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
thingIsObject = $.isPlainObject( thing ),
thingObject = thingIsObject ? thing : {}

// Make sure we have usable options.
options = thingIsObject && $.isPlainObject( value )value : options || {}

if ( thing ) {

// If the thing isn’t an object, make it one.
Expand All @@ -494,7 +497,7 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {

// First, if the item exists and there’s a value, set it.
if ( P.component.item[ thingItem ] ) {
P.component.set( thingItem, thingValue, options || {} )
P.component.set( thingItem, thingValue, options )
}

// Then, check to update the element value and broadcast a change.
Expand All @@ -509,8 +512,8 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
P.render()
}

// Trigger queued “set” events and pass the `thingObject`.
return P.trigger( 'set', thingObject )
// When the method isn’t muted, trigger queued “set” events and pass the `thingObject`.
return options.muted ? P : P.trigger( 'set', thingObject )
}, //set


Expand Down
2 changes: 1 addition & 1 deletion lib/compressed/picker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions lib/picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
thingIsObject = $.isPlainObject( thing ),
thingObject = thingIsObject ? thing : {}

// Make sure we have usable options.
options = thingIsObject && $.isPlainObject( value )value : options || {}

if ( thing ) {

// If the thing isn’t an object, make it one.
Expand All @@ -494,7 +497,7 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {

// First, if the item exists and there’s a value, set it.
if ( P.component.item[ thingItem ] ) {
P.component.set( thingItem, thingValue, options || {} )
P.component.set( thingItem, thingValue, options )
}

// Then, check to update the element value and broadcast a change.
Expand All @@ -509,8 +512,8 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
P.render()
}

// Trigger queued “set” events and pass the `thingObject`.
return P.trigger( 'set', thingObject )
// When the method isn’t muted, trigger queued “set” events and pass the `thingObject`.
return options.muted ? P : P.trigger( 'set', thingObject )
}, //set


Expand Down
8 changes: 8 additions & 0 deletions tests/dev/date.htm
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ <h3><label for="input_01">Pick a date. Go ahead...</label></h3>

var picker = $input.pickadate('picker')

picker.on('set', function(selection) {
console.log( selection )
})

picker.set('select', new Date())
picker.set('select', new Date(), { muted: true })
picker.set({ select: new Date() }, { muted: true })

</script>


Expand Down
15 changes: 15 additions & 0 deletions tests/units/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,21 @@ test( 'As multiple methods', 6, function() {
trigger( 'set' )
})

test( 'As muted methods', 1, function() {

var picker = this.picker

// Bind the callback.
picker.on('set', function() {
ok( true, 'An outspoken method' )
})

// Do the selections.
picker.set('select', new Date())
picker.set('select', new Date(), { muted: true })
picker.set({ select: new Date() }, { muted: true })
})

test( 'Open/close alternate focus', function() {

var picker = this.picker,
Expand Down

0 comments on commit f4cbdad

Please sign in to comment.