Skip to content

Commit

Permalink
Add option for closeCallback and openCallback to be either functions …
Browse files Browse the repository at this point in the history
…or stringified functions
  • Loading branch information
jtsage committed Dec 12, 2011
1 parent f4fbd58 commit f401ded
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
21 changes: 17 additions & 4 deletions js/jquery.mobile.datebox.js
Original file line number Diff line number Diff line change
Expand Up @@ -1823,8 +1823,15 @@
open: function() {
// Call the open callback if provided. Additionally, if this
// returns falsy then the open of the dialog will be canceled
if (this.options.openCallback !== false && !this.options.openCallback()) {
return false;
if (this.options.openCallback !== false ) {
if ( $.isFunction(this.options.openCallback()) && !this.options.openCallback()) {
return false;
} else {
callback = new Function(this.options.openCallback);
if ( !callback() ) {
return false;
}
}
}

var self = this,
Expand Down Expand Up @@ -1881,7 +1888,7 @@
$(activePage).append(self.pickerContent);
$(activePage).append(self.screen);
}
if ( o.useModal ) { // If model, fade the background screen
if ( o.useModal === true ) { // If model, fade the background screen
self.screen.fadeIn('slow');
} else { // Else just unhide it since it's transparent
self.screen.removeClass('ui-datebox-hidden');
Expand Down Expand Up @@ -1931,7 +1938,13 @@
}
self.focusedEl.removeClass('ui-focus');

if ( self.options.closeCallback !== false ) { callback = new Function(self.options.closeCallback); callback(self.theDate, self); }
if ( self.options.closeCallback !== false ) {
if ( $.isFunction(self.options.closeCallback) ) {
self.options.closeCallback(self.theDate, self);
} else {
callback = new Function(self.options.closeCallback); callback(self.theDate, self);
}
}
},
disable: function(){
// Disable the element
Expand Down
4 changes: 2 additions & 2 deletions tests/dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<script type="text/javascript">
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
//useModal: true
useModal: false
//forceInheritTheme: true
//useDialogForceTrue: true
});
Expand All @@ -32,7 +32,7 @@ <h1>jQueryMobile - Dev Page</h1>
<div data-role="content">
<div data-role="fieldcontain">
<label for="lang1">calbox</label>
<input name="lang1" type="text" data-role="datebox" data-options='{"mode": "calbox", "useModal": true}' id="lang1" />
<input name="lang1" type="text" data-role="datebox" data-options='{"mode": "calbox", "useModal": false}' id="lang1" />
</div>
<div data-role="fieldcontain">
<label for="aa1">text comparison</label>
Expand Down

0 comments on commit f401ded

Please sign in to comment.