/*! * dialog - jQuery Plugin * version: 1.0 * @requires jQuery v1.7 or later * * Examples at http://tornqvist.github.com/dialog/ * License: http://tornqvist.mit-license.org * * Copyright 2012 Carl Törnqvist - http://twitter.com/carltornqvist * */ (function(f,d,c){var e="dialog",g={content:null,url:null,speed:400,escape:true,role:"dialog",closeText:"Dismiss",loadText:"Loading",label:e+"-label",appearence:"top",applyClass:null,request:"GET",onOpen:f.noop,onLoad:f.noop,onClose:f.noop,animType:d.Modernizr&&d.Modernizr.csstransitions?"css":"animate",visualLoad:false,center:true},a={init:function(h){return this.each(function(){var i=f(this),j=f.extend({},g,h,f.data(i[0],e));i.attr({"aria-haspopup":"true",role:"button"}).off("click."+e).on("click."+e,function(k){a.show(i,j);k.preventDefault()})})},show:function(h,i){var j={anchor:h,dialog:f("#"+e),close:f("#"+e+"-close"),container:f("#"+e+"-container"),content:f("#"+e+"-content"),settings:i};if(!j.container.length){j.container=a.build("container",j).appendTo(f("body")).on("click",function(k){if(f(k.target).is(j.container)){f[e]("close")}})}else{j.container.css("height",f(c).height())}if(!j.dialog.length){j.dialog=a.build("dialog",j).appendTo(j.container).append(j.close=a.build("close",j).on("click."+e,function(){f[e]("close")}))}else{j.dialog.attr("aria-busy","true").addClass("loading");j.close.text(j.settings.closeText)}if(!j.content.length){j.content=a.build("content",j).prependTo(j.dialog)}else{j.content.empty().text(j.settings.loadText)}j.settings.onOpen(j);if(j.settings.visualLoad){a.animate("reveal",j,"dialog")}j.dialog.on(e+"_load",function(){j.anchor.removeClass("loading");if(!j.settings.visualLoad){a.animate("reveal",j,"dialog",function(){j.dialog.attr("aria-busy","false").find("a,input,button,select,textarea,[tabindex]").first().focus()})}var k;f(d).on("scroll."+e+" resize."+e,function(l){clearTimeout(k);k=setTimeout(function(){var n=f(d).scrollTop(),r=j.dialog.offset().top,m=j.dialog.outerHeight(true),q=j.dialog.outerHeight(true),p=a.calc("height"),o=a.calc("width");if((nr))&&n>-1){a.animate("align",j,"dialog")}else{if(((n+p)>(r+m))&&(m>p)&&n>-1){a.animate(n-(m-p),j,"dialog")}}},100)});j.settings.onLoad(j)});a.load(j.settings.url||h.attr("href"),j);j.dialog.on(e+"_close",function(){j.settings.onClose(j);j.dialog.off(e+"_load "+e+"_close")});if(j.settings.escape){f(c).on("keydown."+e,function(k){var l=k.keyCode||k.which;if(l===27){f[e]("close")}})}f.data(j.dialog[0],e,j)},load:function(h,j){if(!h&&!j.settings.content){f.error(e+"-error: Niether URL nor content was defined");return}j.anchor.addClass("loading");function i(l){var m="h1,h2,h3,h4,h5,h6,legend,label,p",k=f(l).is(m)?f(l):f(l).find(m).first();k.attr("id",k.attr("id")?j.settings.label=k.attr("id"):j.settings.label);j.dialog.attr("aria-labelledby",j.settings.label);return f(l).is(m)?k:f(l).length?f(l):l}if(j.settings.content){j.content.html(i(j.settings.content));j.dialog.removeClass("loading").triggerHandler(e+"_load")}else{if(h.substr(0,1)!=="#"){h=h.indexOf("#")>0?(h.split("#")[0]+" #"+h.split("#")[1]):h;if(j.settings.request==="POST"){j.settings.request={}}j.content.load(h,j.settings.request,function(k){i(j.content.show());j.dialog.removeClass("loading").triggerHandler(e+"_load")})}else{if(f(h).length){j.content.html(i(f(h).clone(true).show()));j.dialog.removeClass("loading").triggerHandler(e+"_load")}else{f.error(e+"-error: Invalid reference, element could not be found in document. Check you URL and "+e+" settings");return}}}},animate:function(j,i,h,k){switch(j){case"show":i[h].show();setTimeout(function(){i[h].addClass("show");if(f.type(k)==="function"){k()}},0);break;case"hide":i[h].removeClass("show");a.when_done(i[h],i.settings,function(){i[h].hide();if(f.type(k)==="function"){k()}});break;case"align":i[h].show();setTimeout(function(){var o,l=f(d).scrollTop(),n=i[h].outerHeight(true),m=a.calc("height");if((n",{id:e+"-close",text:h.settings.closeText,role:"button","aria-controls":e});case"container":return f("
",{id:e+"-container","class":h.settings.applyClass,css:{height:f(c).height()}});case"dialog":return f("
",{id:e,"class":"loading",css:{left:f(c).width()*-1,top:f(c).height()*-1},role:h.settings.role,"aria-busy":"true","aria-live":"assertive"});case"content":return f("
",{id:e+"-content",text:h.settings.loadText})}},when_done:function(h,j,l){var i,k=["webkit","ms","o",""];f.each(k,function(m,n){if(d.hasOwnProperty&&d.hasOwnProperty("on"+n+"transitionend")){i=((n)?n+"T":"t")+"ransitionEnd"}});a.when_done=function(m,n,o){if(i&&n.animType==="css"){m.one(i,o)}else{d.setTimeout(function(){o()},n.speed)}};a.when_done(h,j,l)}},b={close:function(){a.animate("hide",f.data(f("#"+e)[0],e),"container");a.animate("slideOut",f.data(f("#"+e)[0],e),"dialog");f(d).off("scroll."+e);f("#"+e).triggerHandler(e+"_close");if(f.data(f("#"+e)[0],e).settings.escape){f(c).off("keydown."+e)}},align:function(){a.animate("align",f.data(f("#"+e)[0],e),"dialog")},destroy:function(){f("#"+e+"-container").remove();if(f.data(f("#"+e)[0],e).settings.escape){f(c).off("keydown."+e)}},settings:function(h){var i=f.data(f("#"+e)[0],e).settings;f.data(f("#"+e)[0],e).settings=f.extend({},i,h)}};f.fn[e]=function(h){if(b[h]){return b[h].apply(this,Array.prototype.slice.call(arguments,1))}else{if(f.type(h)==="object"||!h){return a.init.apply(this,arguments)}else{f.error(e+"-error: Method "+h+" does not exist on jQuery."+e)}}};f[e]=function(h){if(b[h]){return b[h].apply(this,Array.prototype.slice.call(arguments,1))}else{if(f.type(h)==="object"||!h){a.show(f("body"),f.extend({},g,h))}else{f.error(e+"-error: Method "+h+" does not exist on jQuery."+e)}}}}(jQuery,window,document));