$("#dialog").dialog({
bgiframe : true,
autoOpen: false,
position: [PosX, PosY], //alert comes out as: " , " (without double quotes), or an error is reported.
height: 300. ,
modal: true,
buttons: {
'Create new account': function() {
var bValid = true;
allFields.removeClass('ui-state-error') ;
bValid = bValid && checkLength(name, "username", 3, 16);
bValid = bValid && checkLength(email, "email", 6, 80);
bValid = bValid && checkLength(password, "password", 5, 16);
bValid = bValid && checkRegexp(name, /^[a-z]([0-9a-z_]) $/i, "Username may consist of a-z, 0-9, underscores, begin with a letter.");
// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
bValid = bValid && checkRegexp(email, /^((([a-z]|d|[!#$%&'* -/=?^_`{|}~]|[u00A0-uD7FFuF900-uFDCFuFDF0- uFFEF]) (.([a-z]|d|[!#$%&'* -/=?^_`{|}~]|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF]) )*)|((x22 )((((x20|x09)*(x0dx0a))?(x20|x09) )?(([x01-x08x0bx0cx0e-x1fx7f]|x21|[x23-x5b]|[x5d-x7e]|[u00A0-uD7FFuF900 -uFDCFuFDF0-uFFEF])|(\([x01-x09x0bx0cx0d-x7f]|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF]))))*(((x20|x09)*(x0dx0a))?(x20|x09) )?(x22)))@((([a-z]|d|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])|(([a-z]|d|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])([a-z] |d|-|.|_|~|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])*([a-z]|d|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF]))).) (([a-z]|[ u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])|(([a-z]|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])([a-z]|d|-|.|_|~|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF] )*([a-z]|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF]))).?$/i, "eg. ui@jquery.com");
bValid = bValid && checkRegexp(password, /^( [0-9a-zA-Z]) $/, "Password field only allow : a-z 0-9");
if (bValid) {
$('#users tbody').append ('
'
'' name.val() ' | '
'' email.val() ' | '
'' password.val() ' | '
'
');
$(this).dialog('close');
};
},
Cancel: function() {
$(this).dialog('close');
}
},
close: function( ) {
allFields.val('').removeClass('ui-state-error');
}
});
Later reference to "wind" is jquery.ui.dialog adds the function of "automatically remembering the position when closed". , under his suggestion, he wrote an overload method of jquery.ui.dialog exactly as it should be, to open the dialog at the current position of the mouse
The code is as follows
///////////////////// /////////////
//Specify the position when jquery.ui.dialog is opened
//////////////////// ////////////////
(function($) {
var originOpen = $.ui.dialog.prototype.open
$.ui.dialog.prototype .open = function() {
//var event= window.event || arguments.callee.caller.arguments[0];
//var event = event || window.event;
var event = getEvent();
//alert(event) // Under both ie and ff, "[object]" is displayed
var PosX = 0;
var PosY = 0;
if ( event.pageX || event.pageY) {
PosX = event.pageX;
PosY = event.pageY;
}
else {
PosX = event.clientX document.body.scrollLeft - document.body.clientLeft;
PosY = event.clientY document.body.scrollTop - document.body.clientTop;
};
this.options.position = [PosX, PosY];
//alert(this.options.position);
originOpen.apply(this, arguments);
};
function getEvent() { //Writing compatible with both ie and ff
if (document.all) return window.event;
func = getEvent.caller;
while (func != null) {
var arg0 = func.arguments[0];
if ( arg0) {
if ((arg0.constructor == Event || arg0.constructor == MouseEvent)
|| (typeof (arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) {
return arg0;
}
}
func = func.caller;
}
return null;
}
})(jQuery);
Thanks again "wind". Thanks jww for testing. (Compatible with ie7,8,firefox3.5,chrome4)