0

How can I set the positioning of jquery dialog box to be applied to all dialog calls instead of stating position:

{my: "center", at: "center", of: foo} 

in every instance?

1 Answer 1

0

I can't find any OOTB solution, but you can wrap your dialog creation in a function:

function myDialog(selector, target) {
  return $(selector).dialog("widget").position({
    my: 'center',
    at: 'center',
    of: target
  });
}

And then create it with myDialog("#dialog", foo). You might also want to make this be a simple jQuery plugin to avoid global function declaration.

3
  • Thank you. Please bear with me.. Not only will I have to call the new function on every page but also call myDialog("#dialog", foo) in every instance of jquery dialog call.
    – slmglc
    Commented Sep 27, 2014 at 16:08
  • Can you please update your question and give an example source code that would show exactly what you are trying to get rid of?
    – fracz
    Commented Sep 27, 2014 at 17:10
  • Hi again. Jquery dialog box is positioned at the center of "window" by default. I change it's position every time I call the widget as follows; { $(function(){ $( "#dialog-xxx" ).dialog({ modal:true, position: {my:"center",at:"center",of:foo}, buttons:{OK: function () { $(this).dialog("close");}} }); }); I was wondering if there is a way to set positioning to "foo" without having to repeat it in every dialog call instance and changing jquery code.
    – slmglc
    Commented Sep 29, 2014 at 7:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.