/*
* jQuery Mobile Framework : plugin to provide a simple popup (modal) or jQMdialog (page) Dialog widget.
* Copyright (c) JTSage
* CC 3.0 Attribution. May be relicensed without permission/notifcation.
* https://github.com/jtsage/jquery-mobile-simpledialog
*/
(function($, undefined ) {
$.widget( "mobile.simpledialog", $.mobile.widget, {
options: {
version: '1.0.1-2012021300', // jQueryMobile-YrMoDaySerial
pickPageTheme: 'b',
pickPageInputTheme: 'e',
pickPageButtonTheme: 'a',
fullScreen: false,
fullScreenAlways: false,
disabled: false,
zindex: '500',
width: '280px',
prompt: 'Are you sure?', // or false.
mode: 'bool', // or 'string'
allowReopen: true,
useModal: true,
forceInput: true,
isOpen: false,
blankMode: false,
fullHTML: null,
subTitle: false,
inputPassword: false,
cleanOnClose: false,
animate: true,
transition: 'pop',
clickEvent: 'click',
left: undefined,
top: undefined,
useDialogForceTrue: false,
useDialogForceFalse: false,
useDialog: false,
isInit: false,
sawOnce: false,
enterToTrigger: 0,
escToTrigger: 1,
butObj: [],
debug: false,
selects: false,
selectparent: [],
onCreated:null,
onOpened:null,
onClosed:null,
onShown:null
},
_eventHandler: function(event, payload) {
// Handle all event triggers that have an internal effect
var widget = $(this).data('simpledialog'),
o = widget.options;
if ( ! event.isPropagationStopped() ) {
switch (payload.method) {
case 'close':
widget.close(payload.fromCloseButton);
break;
case 'open':
widget.open();
break;
case 'refresh':
widget.refresh();
break;
case 'button':
o.butObj[payload.index].trigger(o.clickEvent);
break;
}
}
},
_orientChange: function(e) {
var self = $(e.currentTarget).data('simpledialog'),
o = self.options,
docWinWidth = $.mobile.activePage.width(),
docWinHeightOffset = $(window).scrollTop(),
docWinHeight = $(window).height(),
pickWinHeight = self.pickerContent.outerHeight(),
pickWinWidth = self.pickerContent.innerWidth(),
pickWinTop = (parseFloat(o.top)+10000) ? parseFloat(o.top) : (docWinHeightOffset + ( docWinHeight / 2 )- ( pickWinHeight / 2)),
pickWinLeft = (parseFloat(o.left)+10000) ? parseFloat(o.left) : (( docWinWidth / 2) - ( pickWinWidth / 2));
if ( (pickWinHeight + pickWinTop) > $(document).height() ) {
pickWinTop = $(document).height() - (pickWinHeight + 2);
}
if ( pickWinTop < 45 ) { pickWinTop = 45; }
e.stopPropagation();
if ( ! self.pickerContent.is(':visible') || o.useDialog === true ) {
return false; // Not open, or in a dialog (let jQM do it)
} else {
self.pickerContent.css({'top': pickWinTop, 'left': pickWinLeft});
}
},
open: function() {
if ( this.pickPage.is(':visible') ) { return false; }
var self = this,
o = this.options,
docWinWidth = $.mobile.activePage.width(),
docWinHeightOffset = $(window).scrollTop(),
docWinHeight = $(window).height(),
pickWinHeight = self.pickerContent.outerHeight(),
pickWinWidth = self.pickerContent.innerWidth(),
fullTop = $(window).scrollTop(),
fullLeft = $(window).scrollLeft(),
pickWinTop = (parseFloat(o.top)+10000) ? parseFloat(o.top) : (docWinHeightOffset + ( docWinHeight / 2 )- ( pickWinHeight / 2)),
pickWinLeft = (parseFloat(o.left)+10000) ? parseFloat(o.left) : (( docWinWidth / 2) - ( pickWinWidth / 2));
if ( (pickWinHeight + pickWinTop) > $(document).height() ) {
pickWinTop = $(document).height() - (pickWinHeight + 2);
}
if ( pickWinTop < 45 ) { pickWinTop = 45; }
if ( o.prompt !== false ) {
self.pickerHeader.html(o.prompt);
self.pickPage.find('.ui-header').find('.ui-title').text(o.prompt);
}
self.pickerContent.find('.ui-btn-active').removeClass('ui-btn-active');
if ( o.mode === 'blank' ) {
self.pickerContent.delegate('[rel="close"]', o.clickEvent, function() {
self.close();
});
}
if ( !o.disabled ) {
if ( ( docWinWidth > 400 && !o.useDialogForceTrue ) || o.useDialogForceFalse || o.fullScreen ) {
o.useDialog = false;
if ( o.fullScreen === false ) {
if ( o.useModal === true ) {
if ( o.animate === true ) { self.screen.fadeIn('slow'); }
else { self.screen.show(); }
} else {
self.screen.removeClass('ui-simpledialog-hidden');
}
}
if ( o.mode === 'blank' ) {
o.selects = self.pickPage.find('.ui-selectmenu');
o.selects.each(function () {
o.selectparent.push($(this).closest('.ui-dialog'));
$(this).appendTo(self.thisPage);
});
}
self.pickerContent.addClass('ui-overlay-shadow').css('zIndex', self.options.zindex);
self.pickerHeader.show();
if ( o.fullScreenAlways || ( o.fullScreen && docWinWidth < 400 ) ) {
self.pickerContent.css({'border': '0px !important', 'position': 'absolute', 'top': fullTop, 'left': fullLeft, 'height': docWinHeight, 'width': docWinWidth, 'maxWidth': docWinWidth }).addClass('ui-overlay-shadow in').removeClass('ui-simpledialog-hidden');
} else {
self.pickerContent.css({'position': 'absolute', 'top': pickWinTop, 'left': pickWinLeft}).addClass('ui-overlay-shadow in').removeClass('ui-simpledialog-hidden');
}
} else {
// prevent the parent page from being removed from the DOM,
self.thisPage.unbind( "pagehide.remove" );
o.useDialog = true;
self.pickPageContent.append(self.pickerContent);
self.pickerHeader.hide();
self.pickerContent.removeClass('ui-overlay-shadow ui-simpledialog-hidden').css({'top': 'auto', 'left': 'auto', 'marginLeft': 'auto', 'marginRight': 'auto'}).css('zIndex', self.options.zindex);
$.mobile.changePage(self.pickPage, {'transition': (o.animate === true) ? o.transition : 'none' });
}
this.options.isOpen = true;
}
},
close: function(fromCloseButton) {
var self = this;
fromCloseButton = ( typeof(fromCloseButton) === 'undefined' ) ? false : fromCloseButton;
if ( self.options.useDialog ) {
if ( fromCloseButton === false ) {
$(self.pickPage).dialog('close');
}
if( (typeof self.thisPage.jqmData("page")) !== 'undefined' && ! self.thisPage.jqmData("page").options.domCache ){
self.thisPage.bind( "pagehide.remove", function() {
$(self).remove();
});
}
self.pickerContent.addClass('ui-simpledialog-hidden');
self.thisPage.append(self.pickerContent);
} else {
if ( self.options.useModal ) {
if ( self.options.animate === true ) {
self.screen.fadeOut('slow');
} else {
self.screen.hide();
}
} else {
self.screen.addClass('ui-simpledialog-hidden');
}
self.pickerContent.addClass('ui-simpledialog-hidden').removeClass('in');
}
self.caller.removeClass('ui-btn-active');
self.options.isOpen = false;
if ( self.options.cleanOnClose === true && self.options.useDialog === false ) {
self.clean();
}
if (self.options.onClosed && typeof(self.options.onClosed) === "function") {
self.options.onClosed(self);
}
},
clean: function() {
// Clean self out of the DOM
var self = this;
if ( self.options.selects !== false ) {
self.options.selects.each(function() {
$(this).remove();
});
$(self.options.selectparent).each(function() {
$(this).remove();
});
}
self.pickerContent.remove();
self.pickPage.remove();
self.screen.remove();
self.caller.removeData('simpledialog');
},
_create: function(){
var self = this,
o = $.extend(this.options, this.element.data('options')),
caller = this.element;
if ( o.isInit && o.allowReopen ) {
self.open();
} else {
var thisPage = caller.closest('.ui-page'),
pickPage = $("<div data-role='dialog' class='ui-simpledialog-dialog' data-theme='" + o.pickPageTheme + "' >" +
"<div data-role='header' data-backbtn='false' data-theme='a'>" +
"<div class='ui-title'>"+o.prompt+"</div>" +
"</div>"+
"<div data-role='content'></div>"+
"</div>"),
ct = null,
pickPageContent = null;
if (
- 1
- 2
前往页