Skip to content

Commit

Permalink
another fix for alongubkin#48
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Reisdorf committed Mar 24, 2015
1 parent 5ecadf8 commit 3f6d505
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build/angular-datepicker.js

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

20 changes: 9 additions & 11 deletions src/picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
if ( entireComponent ) P.$root.html( createWrappedComponent() )
else angular.element(P.$root[0].querySelectorAll( '.' + CLASSES.box )).html( P.component.nodes( STATE.open ) )

P.attachLiveEvents();
// Trigger the queued “render” events.
return P.trigger( 'render' )
}, //render
Expand Down Expand Up @@ -229,7 +230,7 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
$ELEMENT.triggerHandler( 'focus' )

// Bind the document events.
angular.element(document.querySelectorAll('#' + STATE.id)).on('click focusin', function( event ) {
angular.element(document.querySelectorAll('#' + STATE.id)).off('click focusin').on('click focusin', function( event ) {
var target = event.target;

// If the target of the event is not the element, close the picker picker.
Expand All @@ -248,8 +249,7 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {

});

angular.element(document.querySelectorAll('#' + STATE.id)).on( 'keydown', function( event ) {

angular.element(document.querySelectorAll('#' + STATE.id)).off('keydown').on('keydown', function( event ) {
var
// Get the keycode.
keycode = event.keyCode,
Expand Down Expand Up @@ -636,9 +636,9 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
}
});

function attachLiveEvents() {
P.attachLiveEvents = function() {
// If there’s a click on an actionable element, carry out the actions.
angular.element(P.$root[0].querySelectorAll('[data-pick], [data-nav], [data-clear], [data-close]')).on('click', function() {
angular.element(P.$root[0].querySelectorAll('[data-pick], [data-nav], [data-clear], [data-close]')).off('click').on('click', function() {
var $target = angular.element( this ),
targetDisabled = $target.hasClass( CLASSES.navDisabled ) || $target.hasClass( CLASSES.disabled ),

Expand All @@ -655,32 +655,30 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
// If something is superficially changed, update the `highlight` based on the `nav`.
if ( $target.attr('data-nav') && !targetDisabled ) {
P.set( 'highlight', P.component.item.highlight, { nav: parseInt($target.attr('data-nav')) } )
attachLiveEvents();
P.attachLiveEvents();
}

// If something is picked, set `select` then close with focus.
else if ( PickerConstructor._.isInteger( parseInt($target.attr('data-pick')) ) && !targetDisabled ) {
P.set( 'select', parseInt($target.attr('data-pick')) ).close( true )
attachLiveEvents();
P.attachLiveEvents();
}

// If a “clear” button is pressed, empty the values and close with focus.
else if ( $target.attr('data-clear') ) {
P.clear().close( true )
attachLiveEvents();
P.attachLiveEvents();
}

// If a "close" button is pressed, close with focus.
else if ( $target.attr('data-close') ) {
P.close( true );
attachLiveEvents();
P.attachLiveEvents();
}

});
}

attachLiveEvents();

aria( P.$root[0], 'hidden', true )
}

Expand Down

0 comments on commit 3f6d505

Please sign in to comment.