Changeset 1904438
- Timestamp:
- 07/05/2018 09:41:14 AM (8 years ago)
- File:
-
- 1 edited
-
qibla-directory/trunk/assets/js/modal.min.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
qibla-directory/trunk/assets/js/modal.min.js
r1822649 r1904438 1 window.DL=window.DL||{};(function(_,$,ClassList,DL,dllocalized,dl LocalizedModal){"use strict";DL.Modal={id:"dlmodal",showCloseBtn:true,pageWrapperEl:document.querySelector("#dlpage-wrapper"),cache:{},addListeners:function(){DL.Utils.Events.addListener(window,"load",this.autoOpen);if(this.showCloseBtn){DL.Utils.Events.addListener(this.btnClose,"click",this.close);DL.Utils.Events.addListener(document.body,"click",function(evt){if(DL.Utils.Functions.classList(evt.target).contains(this.id+"-overlay")){this.close()}}.bind(this))}},isInUse:function(){return this.inUse},addCloseBtn:function(){var fragment=document.createDocumentFragment(),container=document.createElement("a"),text=document.createElement("span"),icon=document.createElement("i");DL.Utils.Functions.classList(container).add(this.id+"-close");DL.Utils.Functions.classList(text).add(this.id+"-close__text","screen-reader-text");text.classList.add(this.id+"-close__text");text.innerText=dlLocalizedModal.closeBtn;DL.Utils.Functions.classList(icon).add("la","la-times");fragment.appendChild(container);container.appendChild(icon);container.appendChild(text);this.modal.insertBefore(fragment,this.modal.firstElementChild);return this.modal.querySelector("."+this.id+"-close")},createOverlay:function(){if(!_.isUndefined(this.overaly)&&!_.isEmpty(this.overaly)){return this.overlay}var overlay=document.createElement("div");overlay.classList.add(this.id+"-overlay");overlay.style.display="none";this.template.appendChild(overlay);this.overlay=this.template.querySelector("."+this.id+"-overlay")},open:function(){if(this.inUse){return}this.modal.style.opacity=0;$(this.overlay).stop(true,true).fadeIn(275,function(){this.modal.classList.add("animated","slideInDown");setTimeout(function(){this.modal.style.opacity=1}.bind(this),0);document.querySelector("body").style.overflow="hidden";this.inUse=true;DL.Utils.Events.dispatchEvent("dl_modal_opened",window)}.bind(this))},canBeClosed:function(){return!_.isNull(this.modal.querySelector("."+this.id+"-close"))},close:function(){if(!this.inUse){return}if(!this.canBeClosed()){return}this.modal.classList.add("animated","slideOutUp");setTimeout(function(){this.modal.style.opacity=0;setTimeout(function(){$(this.overlay).fadeOut(275,function(){document.querySelector("body").style.overflow="auto";this.inUse=false;if("script"===this.context){this.template.remove()}DL.Utils.Events.dispatchEvent("dl_modal_closed",window)}.bind(this))}.bind(this),0)}.bind(this),0)},autoOpen:function(){if("html"===this.context){this.open()}},init:function(){var template=document.getElementById(this.id);if(!template){return}this.template=template;this.context=this.template.getAttribute("data-context");this.showCloseBtn=this.template.getAttribute("data-showclosebtn");this.inUse=false;this.modal=this.template.querySelector("."+this.id);this.createOverlay();this.overlay.appendChild(this.modal);if(this.showCloseBtn){this.btnClose=this.addCloseBtn()}this.addListeners()},construct:function(context,data,evt){_.bindAll(this,"addListeners","isInUse","addCloseBtn","createOverlay","open","canBeClosed","close","autoOpen","init");switch(context){case"html":this.init();break;case"script":this.constructViaAjax(data,evt);break}},constructViaAjax:function(data,evt){function insertModalMarkup(data){if(_.isUndefined(data.html)||""===data.html||"openByDefault"in data&&!data.openByDefault){return}if("openByDefault"in data&&!data.openByDefault){return}document.body.insertAdjacentHTML("beforeend",data.html);setTimeout(function(){this.init();this.open()}.bind(this),0)}var key=data.data.dlajax_action;if(!_.isUndefined(this.cache[key])&&!_.isEmpty(this.cache[key])){insertModalMarkup.call(this,this.cache[key])}else{var self=this;data=_.extend({method:"POST",beforeSend:function(jqXHR,settings){DL.Utils.UI.toggleLoader(evt.target)},success:function(response,textStatus,jqXHR){insertModalMarkup.call(self,response.data.data);self.cache[key]={html:response.data.data.html};setTimeout(function(){if(typeof data.onSuccessCallback==="function"){data.onSuccessCallback(response,jqXHR)}},0)},error:function(jqXHR,textStatus,errorThrown){console.error("DL Modal cannot be created: "+errorThrown)},complete:function(){DL.Utils.UI.toggleLoader(evt.target)}},data);$.ajax(data.url,data)}}};DL.Modal.LoginRegisterForm={isInUse:false,addListeners:function(){var addListener=DL.Utils.Events.addListener.bind(this);_.forEach(this.loginRegisterForm.querySelectorAll("a.dlmodal-form-toggler"),function(item){addListener(item,"click",this.toggleForms)}.bind(this));var lostPasswordForm=DL.Modal.modal.querySelector(".dllogin-register-form__lostpassword-link");if(lostPasswordForm){addListener(DL.Modal.modal.querySelector(".dllogin-register-form__lostpassword-link"),"click",this.toggleLostPassword)}_.forEach(this.forms,function(form){form=form.querySelector("form");addListener(form,"submit",this.submitFormViaAjax)}.bind(this));addListener(window,"dl_modal_closed",function(){DL.Modal.LoginRegisterForm.isInUse=false})},submitFormViaAjax:function(evt){evt.preventDefault();evt.stopImmediatePropagation();var form=DL.Form.getForm(evt.target,{ajaxAction:evt.target.querySelector("#dlaction").value,scrollOnTopAfterSubmit:false,ajaxSuccessCb:function(success){form.successResponseHandler(success);if(!_.isUndefined(success.data.data.redirect_to)&&success.data.data.redirect_to){setTimeout(function(){window.location=window.location.origin+success.data.data.redirect_to},2500)}}});form.init();form.submit(evt)},getForms:function(){return _.map(this.loginRegisterForm.querySelectorAll("form"),function(form){return form.parentNode})},createTogglers:function(){var signupLink=document.createElement("a"),signinLink=document.createElement("a"),lostpasswordLink=document.createElement("a"),goBack=document.createElement("a"),loginFormLabelsWrapper=document.createElement("p");loginFormLabelsWrapper.classList.add("dllogin-register-form__labels-wrapper");DL.Utils.Functions.classList(signupLink).add("dllogin-register-form__signup-link","dlmodal-form-toggler");signupLink.innerHTML=dlLocalizedModal.signupLabel;if(typeof this.forms[1]!=="undefined"&&0<parseInt(dllocalized.usersCanRegister)){var cloneLFlW=loginFormLabelsWrapper.cloneNode();cloneLFlW.appendChild(signupLink);this.forms[0].appendChild(cloneLFlW);DL.Utils.Functions.classList(signinLink).add("dllogin-register-form__signin-link","dlmodal-form-toggler");signinLink.innerHTML=dlLocalizedModal.signinLabel;cloneLFlW=loginFormLabelsWrapper.cloneNode();cloneLFlW.appendChild(signinLink);this.forms[1].appendChild(cloneLFlW)}if(typeof this.forms[2]!=="undefined"&&0<parseInt(dllocalized.usersCanRegister)){DL.Utils.Functions.classList(lostpasswordLink).add("dllogin-register-form__lostpassword-link","dlmodal-form-toggler");lostpasswordLink.innerHTML=dlLocalizedModal.lostPasswordLabel;DL.Utils.Functions.classList(goBack).add("dllogin-register-form__go-back","dlmodal-form-toggler");goBack.innerText=dlLocalizedModal.goBackLabel;cloneLFlW=loginFormLabelsWrapper.cloneNode();cloneLFlW.appendChild(goBack);if(typeof this.forms[2]!=="undefined"){this.forms[2].appendChild(cloneLFlW)}var lostPasswordWrapper=document.createElement("p");lostPasswordWrapper.classList.add("dllogin-register-form__lost-password-wrapper");lostPasswordWrapper.appendChild(lostpasswordLink);var lostPasswordTarget=this.loginRegisterForm.querySelector("#qibla_directory_login_form-remember");if(lostPasswordTarget){lostPasswordTarget.parentNode.appendChild(lostPasswordWrapper)}}},toggleForms:function(evt){evt.preventDefault();evt.stopPropagation();var from=0,to=2;if(evt.target.classList.contains("dllogin-register-form__go-back")){from=2;to=0}else if(evt.target.classList.contains("dllogin-register-form__signin-link")||evt.target.parentNode.classList.contains("dllogin-register-form__signin-link")){from=1;to=0}else if(evt.target.classList.contains("dllogin-register-form__signup-link")||evt.target.parentNode.classList.contains("dllogin-register-form__signup-link")){from=0;to=1}$(this.forms[from]).stop(true,true).fadeOut(function(){$(this.forms[to]).stop(true,true).fadeIn();var lostPasswordWrapper=DL.Modal.modal.querySelector(".dllogin-register-form__lost-password-wrapper");if(!$(lostPasswordWrapper).is("visible")){$(lostPasswordWrapper).stop(true,true).fadeIn()}}.bind(this))},toggleLostPassword:function(evt){evt.preventDefault();evt.stopPropagation();for(var counter=0;counter<2;++counter){$(this.forms[counter]).fadeOut(function(){if(2===counter){$(this.forms[2]).fadeIn()}}.bind(this))}},init:function(){_.bindAll(this,"addListeners","createTogglers","getForms","toggleForms","toggleLostPassword");if(_.isUndefined(DL.Modal.modal)){return}this.loginRegisterForm=DL.Modal.modal.querySelector(".dllogin-register-form");if(!this.loginRegisterForm){return}this.forms=this.getForms();if(_.isEmpty(this.forms)){return}if(typeof this.forms[1]!=="undefined"){$(this.forms[1]).hide()}if(typeof this.forms[2]!=="undefined"){$(this.forms[2]).hide()}this.createTogglers();this.addListeners();this.isInUse=true}};DL.Modal.construct("html");DL.Modal.LoginRegisterForm.init()})(_,window.jQuery,window.ClassList,window.DL,window.dllocalized,window.dlmodallocalized);1 window.DL=window.DL||{};(function(_,$,ClassList,DL,dllocalized,dlmodallocalized){"use strict";DL.Modal={id:"dlmodal",showCloseBtn:true,pageWrapperEl:document.querySelector("#dlpage-wrapper"),cache:{},addListeners:function(){DL.Utils.Events.addListener(window,"load",this.autoOpen);if(this.showCloseBtn){DL.Utils.Events.addListener(this.btnClose,"click",this.close);DL.Utils.Events.addListener(document.body,"click",function(evt){if(DL.Utils.Functions.classList(evt.target).contains(this.id+"-overlay")){this.close()}}.bind(this))}},isInUse:function(){return this.inUse},addCloseBtn:function(){var fragment=document.createDocumentFragment(),container=document.createElement("a"),text=document.createElement("span"),icon=document.createElement("i");DL.Utils.Functions.classList(container).add(this.id+"-close");DL.Utils.Functions.classList(text).add(this.id+"-close__text","screen-reader-text");text.classList.add(this.id+"-close__text");text.innerText=window.dlmodallocalized.closeBtn;DL.Utils.Functions.classList(icon).add("la","la-times");fragment.appendChild(container);container.appendChild(icon);container.appendChild(text);this.modal.insertBefore(fragment,this.modal.firstElementChild);return this.modal.querySelector("."+this.id+"-close")},createOverlay:function(){if(!_.isUndefined(this.overaly)&&!_.isEmpty(this.overaly)){return this.overlay}var overlay=document.createElement("div");overlay.classList.add(this.id+"-overlay");overlay.style.display="none";this.template.appendChild(overlay);this.overlay=this.template.querySelector("."+this.id+"-overlay")},open:function(){if(this.inUse){return}this.modal.style.opacity=0;$(this.overlay).stop(true,true).fadeIn(275,function(){this.modal.classList.add("animated","slideInDown");setTimeout(function(){this.modal.style.opacity=1}.bind(this),0);document.querySelector("body").style.overflow="hidden";this.inUse=true;DL.Utils.Events.dispatchEvent("dl_modal_opened",window)}.bind(this))},canBeClosed:function(){return!_.isNull(this.modal.querySelector("."+this.id+"-close"))},close:function(){if(!this.inUse){return}if(!this.canBeClosed()){return}this.modal.classList.add("animated","slideOutUp");setTimeout(function(){this.modal.style.opacity=0;setTimeout(function(){$(this.overlay).fadeOut(275,function(){document.querySelector("body").style.overflow="auto";this.inUse=false;if("script"===this.context){this.template.remove()}DL.Utils.Events.dispatchEvent("dl_modal_closed",window)}.bind(this))}.bind(this),0)}.bind(this),0)},autoOpen:function(){if("html"===this.context){this.open()}},init:function(){var template=document.getElementById(this.id);if(!template){return}this.template=template;this.context=this.template.getAttribute("data-context");this.showCloseBtn=this.template.getAttribute("data-showclosebtn");this.inUse=false;this.modal=this.template.querySelector("."+this.id);this.createOverlay();this.overlay.appendChild(this.modal);if(this.showCloseBtn){this.btnClose=this.addCloseBtn()}this.addListeners()},construct:function(context,data,evt){_.bindAll(this,"addListeners","isInUse","addCloseBtn","createOverlay","open","canBeClosed","close","autoOpen","init");switch(context){case"html":this.init();break;case"script":this.constructViaAjax(data,evt);break}},constructViaAjax:function(data,evt){function insertModalMarkup(data){if(_.isUndefined(data.html)||""===data.html||"openByDefault"in data&&!data.openByDefault){return}if("openByDefault"in data&&!data.openByDefault){return}document.body.insertAdjacentHTML("beforeend",data.html);setTimeout(function(){this.init();this.open()}.bind(this),0)}var key=data.data.dlajax_action;if(!_.isUndefined(this.cache[key])&&!_.isEmpty(this.cache[key])){insertModalMarkup.call(this,this.cache[key])}else{var self=this;data=_.extend({method:"POST",beforeSend:function(jqXHR,settings){DL.Utils.UI.toggleLoader(evt.target)},success:function(response,textStatus,jqXHR){insertModalMarkup.call(self,response.data.data);self.cache[key]={html:response.data.data.html};setTimeout(function(){if(typeof data.onSuccessCallback==="function"){data.onSuccessCallback(response,jqXHR)}},0)},error:function(jqXHR,textStatus,errorThrown){console.error("DL Modal cannot be created: "+errorThrown)},complete:function(){DL.Utils.UI.toggleLoader(evt.target)}},data);$.ajax(data.url,data)}}};DL.Modal.LoginRegisterForm={isInUse:false,addListeners:function(){var addListener=DL.Utils.Events.addListener.bind(this);_.forEach(this.loginRegisterForm.querySelectorAll("a.dlmodal-form-toggler"),function(item){addListener(item,"click",this.toggleForms)}.bind(this));var lostPasswordForm=DL.Modal.modal.querySelector(".dllogin-register-form__lostpassword-link");if(lostPasswordForm){addListener(DL.Modal.modal.querySelector(".dllogin-register-form__lostpassword-link"),"click",this.toggleLostPassword)}_.forEach(this.forms,function(form){form=form.querySelector("form");addListener(form,"submit",this.submitFormViaAjax)}.bind(this));addListener(window,"dl_modal_closed",function(){DL.Modal.LoginRegisterForm.isInUse=false})},submitFormViaAjax:function(evt){evt.preventDefault();evt.stopImmediatePropagation();var form=DL.Form.getForm(evt.target,{ajaxAction:evt.target.querySelector("#dlaction").value,scrollOnTopAfterSubmit:false,ajaxSuccessCb:function(success){form.successResponseHandler(success);if(!_.isUndefined(success.data.data.redirect_to)&&success.data.data.redirect_to){setTimeout(function(){window.location=window.location.origin+success.data.data.redirect_to},2500)}}});form.init();form.submit(evt)},getForms:function(){return _.map(this.loginRegisterForm.querySelectorAll("form"),function(form){return form.parentNode})},createTogglers:function(){var signupLink=document.createElement("a"),signinLink=document.createElement("a"),lostpasswordLink=document.createElement("a"),goBack=document.createElement("a"),loginFormLabelsWrapper=document.createElement("p");loginFormLabelsWrapper.classList.add("dllogin-register-form__labels-wrapper");DL.Utils.Functions.classList(signupLink).add("dllogin-register-form__signup-link","dlmodal-form-toggler");signupLink.innerHTML=window.dlmodallocalized.signupLabel;if(typeof this.forms[1]!=="undefined"&&0<parseInt(window.dllocalized.usersCanRegister)){var cloneLFlW=loginFormLabelsWrapper.cloneNode();cloneLFlW.appendChild(signupLink);this.forms[0].appendChild(cloneLFlW);DL.Utils.Functions.classList(signinLink).add("dllogin-register-form__signin-link","dlmodal-form-toggler");signinLink.innerHTML=window.dlmodallocalized.signinLabel;cloneLFlW=loginFormLabelsWrapper.cloneNode();cloneLFlW.appendChild(signinLink);this.forms[1].appendChild(cloneLFlW)}if(typeof this.forms[2]!=="undefined"&&0<parseInt(window.dllocalized.usersCanRegister)){DL.Utils.Functions.classList(lostpasswordLink).add("dllogin-register-form__lostpassword-link","dlmodal-form-toggler");lostpasswordLink.innerHTML=window.dlmodallocalized.lostPasswordLabel;DL.Utils.Functions.classList(goBack).add("dllogin-register-form__go-back","dlmodal-form-toggler");goBack.innerText=window.dlmodallocalized.goBackLabel;cloneLFlW=loginFormLabelsWrapper.cloneNode();cloneLFlW.appendChild(goBack);if(typeof this.forms[2]!=="undefined"){this.forms[2].appendChild(cloneLFlW)}var lostPasswordWrapper=document.createElement("p");lostPasswordWrapper.classList.add("dllogin-register-form__lost-password-wrapper");lostPasswordWrapper.appendChild(lostpasswordLink);var lostPasswordTarget=this.loginRegisterForm.querySelector("#qibla_directory_login_form-remember");if(lostPasswordTarget){lostPasswordTarget.parentNode.appendChild(lostPasswordWrapper)}}},toggleForms:function(evt){evt.preventDefault();evt.stopPropagation();var from=0,to=2;if(evt.target.classList.contains("dllogin-register-form__go-back")){from=2;to=0}else if(evt.target.classList.contains("dllogin-register-form__signin-link")||evt.target.parentNode.classList.contains("dllogin-register-form__signin-link")){from=1;to=0}else if(evt.target.classList.contains("dllogin-register-form__signup-link")||evt.target.parentNode.classList.contains("dllogin-register-form__signup-link")){from=0;to=1}$(this.forms[from]).stop(true,true).fadeOut(function(){$(this.forms[to]).stop(true,true).fadeIn();var lostPasswordWrapper=DL.Modal.modal.querySelector(".dllogin-register-form__lost-password-wrapper");if(!$(lostPasswordWrapper).is("visible")){$(lostPasswordWrapper).stop(true,true).fadeIn()}}.bind(this))},toggleLostPassword:function(evt){evt.preventDefault();evt.stopPropagation();for(var counter=0;counter<2;++counter){$(this.forms[counter]).fadeOut(function(){if(2===counter){$(this.forms[2]).fadeIn()}}.bind(this))}},init:function(){_.bindAll(this,"addListeners","createTogglers","getForms","toggleForms","toggleLostPassword");if(_.isUndefined(DL.Modal.modal)){return}this.loginRegisterForm=DL.Modal.modal.querySelector(".dllogin-register-form");if(!this.loginRegisterForm){return}this.forms=this.getForms();if(_.isEmpty(this.forms)){return}if(typeof this.forms[1]!=="undefined"){$(this.forms[1]).hide()}if(typeof this.forms[2]!=="undefined"){$(this.forms[2]).hide()}this.createTogglers();this.addListeners();this.isInUse=true}};DL.Modal.construct("html");DL.Modal.LoginRegisterForm.init()})(_,window.jQuery,window.ClassList,window.DL,window.dllocalized,window.dlmodallocalized);
Note: See TracChangeset
for help on using the changeset viewer.