Skip to content

Commit 14b51a9

Browse files
committed
Add hook for orientation change, Closes jtsage#95
1 parent 87226cf commit 14b51a9

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

js/jquery.mobile.datebox.js

+40-1
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,41 @@
440440
self.theDate.setTime( secs * 1000 );
441441
self._update();
442442
},
443+
_orientChange: function(e) {
444+
var self = $(e.currentTarget).data('datebox');
445+
o = self.options,
446+
inputOffset = self.focusedEl.offset(),
447+
pickWinHeight = self.pickerContent.outerHeight(),
448+
pickWinWidth = self.pickerContent.innerWidth(),
449+
pickWinTop = inputOffset.top + ( self.focusedEl.outerHeight() / 2 )- ( pickWinHeight / 2),
450+
pickWinLeft = inputOffset.left + ( self.focusedEl.outerWidth() / 2) - ( pickWinWidth / 2);
451+
452+
e.stopPropagation();
453+
if ( ! self.pickerContent.is(':visible') || o.useDialog === true ) {
454+
return false; // Not open, or in a dialog (let jQM do it)
455+
} else {
456+
// TOO FAR RIGHT TRAP
457+
if ( (pickWinLeft + pickWinWidth) > $(document).width() ) {
458+
pickWinLeft = $(document).width() - pickWinWidth - 1;
459+
}
460+
// TOO FAR LEFT TRAP
461+
if ( pickWinLeft < 0 ) {
462+
pickWinLeft = 0;
463+
}
464+
// Center popup on request - centered in document, not any containing div.
465+
if ( o.centerWindow ) {
466+
pickWinLeft = ( $(document).width() / 2 ) - ( pickWinWidth / 2 );
467+
}
468+
469+
if ( (pickWinHeight + pickWinTop) > $(document).height() ) {
470+
pickWinTop = $(document).height() - (pickWinHeight + 2);
471+
}
472+
if ( pickWinTop < 45 ) { pickWinTop = 45; }
473+
474+
self.pickerContent.css({'top': pickWinTop, 'left': pickWinLeft});
475+
}
476+
477+
},
443478
_update: function() {
444479
// Update the display on date change
445480
var self = this,
@@ -1100,7 +1135,7 @@
11001135
});
11011136

11021137
// Bind the master handler.
1103-
input.bind('datebox', self._dateboxHandler);
1138+
input.bind('datebox', self._dateboxHandler);
11041139

11051140
// Bind the close button on the DIALOG mode.
11061141
pickPage.find( ".ui-header a").bind('vclick', function(e) {
@@ -1214,6 +1249,10 @@
12141249
input.attr("readonly", true);
12151250
}
12161251

1252+
$(document).bind('orientationchange', function(e) { input.trigger('orientationchange'); });
1253+
1254+
input.bind('orientationchange', self._orientChange);
1255+
12171256
//Throw dateboxinit event
12181257
$( document ).trigger( "dateboxaftercreate" );
12191258
},

0 commit comments

Comments
 (0)