I needed a modal box. You might too. You can have mine. I hope it helps.
The image in the HTML is the famfamfam cross.png from the silk icon set. See http://www.famfamfam.com
HTML
<div id="modal-window" class="ui-widget ui-corner-all">
<div id="modal-window-title" class="ui-widget-header ui-corner-tr ui-corner-tl"><span id="modal-window-title-body"></span>
<img id="modal-window-close" class="ui-icon" src="/img/cross.png" alt="Close" onclick="$().modalHide();" />
</div>
<div id="modal-window-content" class="ui-widget-content"><p id="modal-window-content-body"></p></div></div>CSS
div#modal-window { z-index:1000; display:none; width:50%; } div#modal-window > div { width:600px; } div#modal-window span { width:580px; line-height:25px; padding:3px 5px; font-weight:bold; } div#modal-window-title { height:25px; } img#modal-window-close { float:right; margin:4px; cursor:pointer; } div#modal-window-content { overflow:auto; } p#modal-window-content-body { margin:5px; padding:0px; }
JS
jQuery.fn.modalCenter = function () { this.css("position","absolute"); this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px"); this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px"); return this; } jQuery.fn.modalTitle = function(title){ $('span#modal-window-title-body').html(title); return this; } jQuery.fn.modalContent = function(content){ $('p#modal-window-content-body').html(content); return this; } jQuery.fn.modalShow = function(){ $('div#modal-window').modalCenter().show(); return this; } jQuery.fn.modalHide = function(){ $('div#modal-window').hide(); return this; } jQuery.fn.modalClose = function(){ $('div#modal-window').hide().modalTitle('').modalContent(''); } jQuery.fn.modalLoad = function(url, params, method){ if(!method) method = 'POST'; $.ajax(url, { data: params, type: method, dataType: 'json', success: function(obj){ $().modalTitle(obj['title']).modalContent(obj['content']).modalShow(); } }); }
Usage
<input type="button" value="Click Me!" onclick="$().modalLoad('/some/url', {id:123});" />Expected ajax return
{"title":"The title","content":"<p>The content</p>"}
