forked from Pagawa/PgwModal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpgwmodal.min.js
9 lines (9 loc) · 3.1 KB
/
pgwmodal.min.js
1
2
3
4
5
6
7
8
9
/**
* PgwModal - Version 1.4
*
* Copyright 2014, Jonathan M. Piat
* http://pgwjs.com - http://pagawa.com
*
* Released under the GNU GPLv3 license - http://opensource.org/licenses/gpl-3.0
*/
(function(a){a.pgwModal=function(h){var c={};var f={close:true,maxWidth:500,loading:"Loading in progress...",error:"An error has occured. Please try again in a few moments."};if(typeof window.pgwModalObject!="undefined"){c=window.pgwModalObject}if((typeof h=="object")&&(!h.pushContent)){if(!h.url&&!h.target&&!h.content){throw new Error('PgwModal - There is no content to display, please provide a config parameter : "url", "target" or "content"')}c.config={};c.config=a.extend({},f,h);window.pgwModalObject=c}var j=function(){var n='<div id="pgwModalWrapper"></div><div id="pgwModal"><div class="pm-container"><div class="pm-body"><a href="javascript:void(0)" class="pm-close" onclick="$.pgwModal(\'close\')"></a><div class="pm-title"></div><div class="pm-content cntr"></div></div></div></div>';a("body").append(n);a(document).trigger("PgwModal::Create");return true};var k=function(){a("#pgwModal .pm-title, #pgwModal .pm-content").html("");return true};var e=function(){angular.element('body').injector().invoke(function($compile){var scope=angular.element($('#pgwModal .pm-content')).scope();$compile($('#pgwModal .pm-content'))(scope);scope.$digest()});return true};var d=function(n){a("#pgwModal .pm-content").html(n);if(c.config.angular){e()}l();a(document).trigger("PgwModal::PushContent");return true};var l=function(){var p=a(window).height();var o=a("#pgwModal .pm-body").height();var n=Math.round((p-o)/3);if(n<=0){n=10}a("#pgwModal .pm-body").css("margin-top",n);return true};var g=function(){return c.config.modalData};var b=function(){return a("body").hasClass("pgwModal")};var m=function(){a("#pgwModal, #pgwModalWrapper").hide();a("body").removeClass("pgwModal");k();try{delete window.pgwModalObject}catch(n){window.pgwModalObject=undefined}a(document).trigger("PgwModal::Close");return true};var i=function(){if(a("#pgwModal").length==0){j()}else{k()}if(!c.config.close){a("#pgwModal .pm-close").hide()}else{a("#pgwModal .pm-close").show()}if(c.config.title){a("#pgwModal .pm-title").text(c.config.title)}if(c.config.maxWidth){a("#pgwModal .pm-body").css("max-width",c.config.maxWidth)}if(c.config.url){if(c.config.loading){a("#pgwModal .pm-content").html(c.config.loading)}var n={url:h.url,success:function(o){d(o)},error:function(){a("#pgwModal .pm-content").html(c.config.error)}};if(c.config.ajaxOptions){n=a.extend({},n,c.config.ajaxOptions)}a.ajax(n)}else{if(c.config.target){d(a(c.config.target).html())}else{if(c.config.content){d(c.config.content)}}}a("#pgwModal, #pgwModalWrapper").show();a("body").addClass("pgwModal");a(document).trigger("PgwModal::Open");return true};if((typeof h=="string")&&(h=="close")){return m()}else{if((typeof h=="string")&&(h=="reposition")){return l()}else{if((typeof h=="string")&&(h=="getData")){return g()}else{if((typeof h=="string")&&(h=="isOpen")){return b()}else{if((typeof h=="object")&&(h.pushContent)){return d(h.pushContent)}else{if(typeof h=="object"){return i()}}}}}}}})(window.Zepto||window.jQuery);