Responsive jQuery UI Dialog ( and a fix for maxWidth bug ) -
with many sites leveraging jquery ui, there major shortcomings have overcome because jquery ui not support responsive design , there's longstanding bug when maxwidth
used in conjunction width:'auto'
.
so question remains, how make jquery ui dialog responsive?
below how achieved responsive jquery ui dialog.
to this, added new option config - fluid: true
, says make dialog responsive.
i catch resize , dialog open events, change max-width of dialog on fly, , reposition dialog.
you can see in action here: http://codepen.io/jasonday/pen/amlqz
please review , post edits or improvements.
// demo: http://codepen.io/jasonday/pen/amlqz // movemaine@gmail.com $("#content").dialog({ width: 'auto', // overcomes width:'auto' , maxwidth bug maxwidth: 600, height: 'auto', modal: true, fluid: true, //new option resizable: false }); // on window resize run function $(window).resize(function () { fluiddialog(); }); // catch dialog if opened within viewport smaller dialog width $(document).on("dialogopen", ".ui-dialog", function (event, ui) { fluiddialog(); }); function fluiddialog() { var $visible = $(".ui-dialog:visible"); // each open dialog $visible.each(function () { var $this = $(this); var dialog = $this.find(".ui-dialog-content").data("ui-dialog"); // if fluid option == true if (dialog.options.fluid) { var wwidth = $(window).width(); // check window width against dialog width if (wwidth < (parseint(dialog.options.maxwidth) + 50)) { // keep dialog filling entire screen $this.css("max-width", "90%"); } else { // fix maxwidth bug $this.css("max-width", dialog.options.maxwidth + "px"); } //reposition dialog dialog.option("position", dialog.options.position); } }); }
edit
updated approach: https://github.com/jasonday/jquery-ui-dialog-extended
the repository above includes options for:
- click outside of dialog close
- hide title bar
- hide close button
- responsive (to address above)
- scale width & height responsive (ex: 80% of window width)
Comments
Post a Comment