Skip to content

Instantly share code, notes, and snippets.

@punkmonday
Last active February 17, 2017 06:03
Show Gist options
  • Save punkmonday/4eb357f0b104f9b4f88487804663c0ea to your computer and use it in GitHub Desktop.
Save punkmonday/4eb357f0b104f9b4f88487804663c0ea to your computer and use it in GitHub Desktop.
centerAndShowDialog.js
function centerAndShowDialog(dialog) {
var c = Liferay.component(dialog);
//dialog show 之前设置一个固定高度,为了窗口居中
AUI().Do.before(function () {
c.set("centered", true);
c.set("height", "70%");
}, c, "show");
//dialog show 之后,把高度设置为auto
AUI().Do.after(function () {
console.log("after");
console.log(c.get("height"));
c.set("height", "auto");
}, c, "show");
c.show();
}
function centerAndShowDialog(dialog)
{
$(dialog).css("top",Math.max(0,(($(window).height() - $(dialog).outerHeight()) / 2) + $(window).scrollTop()) + "px");
$(dialog).css("left",Math.max(0, (($(window).width() - $(dialog).outerWidth()) / 2) + $(window).scrollLeft()) + "px");
dialog.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment