Comparing version 1.1.1 to 1.1.2
@@ -70,44 +70,45 @@ ;(function (root, factory) { | ||
* @class PopupS | ||
* @param {Object} options | ||
*/ | ||
function PopupS(options) { | ||
//error catching | ||
if (typeof options.mode !== "string") throw new Error("mode must be a string"); | ||
if (typeof options.title !== "undefined" && typeof options.title !== "string") throw new Error("title must be a string"); | ||
if (typeof options.placeholder !== "undefined" && typeof options.placeholder !== "string") throw new Error("placeholder must be a string"); | ||
function PopupS() {} | ||
this.options = options = _extend({}, options); | ||
PopupS.prototype = { | ||
constructor: PopupS, | ||
// Set default options | ||
for (var name in _defaults) { | ||
!(name in options) && (options[name] = _defaults[name]); | ||
} | ||
_open: function(options) { | ||
//error catching | ||
if (typeof options.mode !== "string") throw new Error("mode must be a string"); | ||
if (typeof options.title !== "undefined" && typeof options.title !== "string") throw new Error("title must be a string"); | ||
if (typeof options.placeholder !== "undefined" && typeof options.placeholder !== "string") throw new Error("placeholder must be a string"); | ||
// trail all classes divided by periods | ||
_each(['additionalBaseClass', 'additionalButtonHolderClass', 'additionalButtonOkClass', 'additionalButtonCancelClass', 'additionalCloseBtnClass', 'additionalFormClass', 'additionalOverlayClass', 'additionalPopupClass'], function(option) { | ||
var string = options[option].split(' ').join('.'); | ||
options[option] = '.' + string; | ||
}); | ||
this.options = options = _extend({}, options); | ||
// Bind all private methods | ||
for (var fn in this) { | ||
if (fn.charAt(0) === '_') { | ||
this[fn] = _bind(this, this[fn]); | ||
// Set default options | ||
for (var name in _defaults) { | ||
!(name in options) && (options[name] = _defaults[name]); | ||
} | ||
} | ||
//initialize if it hasn't already been done | ||
this._init(); | ||
// trail all classes divided by periods | ||
_each(['additionalBaseClass', 'additionalButtonHolderClass', 'additionalButtonOkClass', 'additionalButtonCancelClass', 'additionalCloseBtnClass', 'additionalFormClass', 'additionalOverlayClass', 'additionalPopupClass'], function(option) { | ||
var string = options[option].split(' ').join('.'); | ||
options[option] = '.' + string; | ||
}); | ||
// if it is forced, close all others | ||
if(options.force === true) { | ||
while (queue.length > 0) queue.pop(); | ||
} | ||
queue.push(options); | ||
if(!isOpen) this._create(); | ||
} | ||
// Bind all private methods | ||
for (var fn in this) { | ||
if (fn.charAt(0) === '_') { | ||
this[fn] = _bind(this, this[fn]); | ||
} | ||
} | ||
PopupS.prototype = { | ||
constructor: PopupS, | ||
//initialize if it hasn't already been done | ||
this._init(); | ||
// if it is forced, close all others | ||
if(options.force === true) { | ||
while (queue.length > 0) queue.pop(); | ||
} | ||
queue.push(options); | ||
if(!isOpen || options.force === true) this._create(); | ||
}, | ||
_init: function() { | ||
@@ -848,32 +849,32 @@ // if i passed a opacity attribute to the layer onClose, remove it on initialization | ||
/** | ||
* Create popupS instance | ||
* @param {Object} params | ||
*/ | ||
PopupS.window = function(params) { | ||
return new PopupS(params); | ||
// Instantiate a PopupS Object | ||
var popupS = new PopupS(); | ||
// Public methods | ||
popupS.window = function(params) { | ||
this._open(params); | ||
}; | ||
PopupS.alert = function(params) { | ||
popupS.alert = function(params) { | ||
params = _extend(params, {mode: 'alert'}); | ||
return new PopupS(params); | ||
this._open(params); | ||
}; | ||
PopupS.confirm = function(params) { | ||
popupS.confirm = function(params) { | ||
params = _extend(params, {mode: 'confirm'}); | ||
return new PopupS(params); | ||
this._open(params); | ||
}; | ||
PopupS.prompt = function(params) { | ||
popupS.prompt = function(params) { | ||
params = _extend(params, {mode: 'prompt'}); | ||
return new PopupS(params); | ||
this._open(params); | ||
}; | ||
PopupS.modal = function(params) { | ||
popupS.modal = function(params) { | ||
params = _extend(params, {mode: 'modal'}); | ||
return new PopupS(params); | ||
this._open(params); | ||
}; | ||
PopupS.ajax = function(params) { | ||
popupS.ajax = function(params) { | ||
params = _extend(params, {mode: 'modal-ajax'}); | ||
return new PopupS(params); | ||
this._open(params); | ||
}; | ||
// Export | ||
return PopupS; | ||
return popupS; | ||
})); |
@@ -1,2 +0,2 @@ | ||
/*! popupS 1.1.0 - MIT | https://github.com/ChiefORZ/popupS.git */ | ||
!function(a,b){"function"==typeof define&&define.amd?define(b):"object"==typeof exports?module.exports=b():a.popupS=b()}(this,function(){"use strict";function a(a){if("string"!=typeof a.mode)throw new Error("mode must be a string");if("undefined"!=typeof a.title&&"string"!=typeof a.title)throw new Error("title must be a string");if("undefined"!=typeof a.placeholder&&"string"!=typeof a.placeholder)throw new Error("placeholder must be a string");this.options=a=d({},a);for(var e in p)!(e in a)&&(a[e]=p[e]);c(["additionalBaseClass","additionalButtonHolderClass","additionalButtonOkClass","additionalButtonCancelClass","additionalCloseBtnClass","additionalFormClass","additionalOverlayClass","additionalPopupClass"],function(b){var c=a[b].split(" ").join(".");a[b]="."+c});for(var f in this)"_"===f.charAt(0)&&(this[f]=b(this,this[f]));if(this._init(),a.force===!0)for(;n.length>0;)n.pop();n.push(a),m||this._create()}function b(a,b){var c=[].slice.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat([].slice.call(arguments)))}}function c(a,b){if(a)for(var c in a)a.hasOwnProperty(c)&&b(a[c],c,a)}function d(a){a=a||{};for(var b=1;b<arguments.length;b++)if(arguments[b])for(var c in arguments[b])arguments[b].hasOwnProperty(c)&&(a[c]=arguments[b][c]);return a}function e(a,b,c){"function"==typeof a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent&&a.attachEvent("on"+b,c)}function f(a,b,c){"function"==typeof a.removeEventListener?a.removeEventListener(b,c,!1):a.detachEvent&&a.detachEvent("on"+b,c)}function g(a,b,c){if(a&&a.style&&b)if(b instanceof Object)for(var d in b)g(a,d,b[d]);else a.style[b]=c}function h(a){null===a&&(a="div"),"string"==typeof a&&(a={tag:a});var b,d,e=document.createDocumentFragment(),f=a.children,j=r.exec(a.tag||"");return delete a.children,a.tag=j[1]||"div",a.id=a.id||(j[2]||"").substr(1),d=(j[3]||"").split("."),d[0]=a.className||"",a.className=d.join(" "),b=document.createElement(a.tag),i(e,b),delete a.tag,c(a,function(c,d){if("css"===d)g(b,a.css);else if("text"===d)null!==c&&i(b,document.createTextNode(c));else if("html"===d)null!==c&&(b.innerHTML=c);else if(d in b)try{b[d]=c}catch(e){b.setAttribute(d,c)}else/^data-/.test(d)&&b.setAttribute(d,c)}),f&&f.appendChild?i(b,f):f&&(f instanceof Array?c(f,function(a,c){a instanceof Object&&i(b,h(a))}):f instanceof Object&&i(b,h(f))),b}function i(a,b){try{a&&b&&a.appendChild(b)}catch(c){}}function j(a){for(var b,c,d=k(a,"input"),e=0,f=d.length;f>e;e++)if(b=d[e],"submit"===b.type)!c&&(c=b);else if(!/hidden|check|radio/.test(b.type)&&""===b.value){c=b;break}c||(c=k(a,"button")[0]);try{c.focus()}catch(g){}}function k(a,b){return a.getElementsByTagName(b)}function l(a){a&&a.parentNode&&a.parentNode.removeChild(a)}var m=!1,n=[],o=new RegExp(/([^\/\\]+)\.(jpg|jpeg|png|gif)$/i),p={additionalBaseClass:"",additionalButtonHolderClass:"",additionalButtonOkClass:"",additionalButtonCancelClass:"",additionalCloseBtnClass:"",additionalFormClass:"",additionalOverlayClass:"",additionalPopupClass:"",appendLocation:document.body||document.documentElement,baseClassName:"popupS",closeBtn:"×",flagBodyScroll:!1,flagButtonReverse:!1,flagCloseByEsc:!0,flagCloseByOverlay:!0,flagShowCloseBtn:!0,labelOk:"OK",labelCancel:"Cancel",loader:"spinner",zIndex:1e4},q=function(){var a,b,c=!1,d=document.createElement("fakeelement"),e={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"otransitionend",transition:"transitionend"};for(a in e)if(e.hasOwnProperty(a)&&void 0!==d.style[a]){b=e[a],c=!0;break}return{type:b,supported:c}}();a.prototype={constructor:a,_init:function(){this.$layerEl&&this.$layerEl.style.opacity&&(this.$layerEl.style.opacity=""),this.$wrapEl||(this.$wrapEl=h({tag:"div."+this.options.baseClassName+"-base"+(this.options.additionalBaseClass?this.options.additionalBaseClass:""),css:{top:0,left:0,right:0,bottom:0,position:"fixed",textAlign:"center",overflowX:"auto",overflowY:"auto",outline:0,whiteSpace:"nowrap",zIndex:this.options.zIndex},children:{css:{height:"100%",display:"inline-block",verticalAlign:"middle"}}}),i(this.$wrapEl,this._getOverlay()),i(this.$wrapEl,this._getLayer()))},_getOverlay:function(){return this.$overlayEl||(this.$overlayEl=h({tag:"#popupS-overlay."+this.options.baseClassName+"-overlay"+(this.options.additionalOverlayClass?this.options.additionalOverlayClass:""),css:{top:0,right:0,bottom:0,left:0,position:"fixed",overflowX:"hidden",userSelect:"none",webkitUserSelect:"none",MozUserSelect:"none"}})),this.$overlayEl.setAttribute("unselectable","on"),this.$overlayEl},_getLayer:function(){return this.$layerEl||(this.$layerEl=h({css:{display:"inline-block",position:"relative",textAlign:"left",whiteSpace:"normal",verticalAlign:"middle",transform:"translate3d(0,0,0)"},children:{tag:"."+this.options.baseClassName+"-layer"+(this.options.additionalPopupClass?this.options.additionalPopupClass:"")}})),this.$layerEl},_resetLayer:function(){this.$layerEl.childNodes[0].innerHTML=""},_create:function(){var a=this,c=n[0],d=c.mode;m=!0,"modal-ajax"!=d?this._createPopup(c):this._loadContents(c);var e=function(b){b.stopPropagation(),_unbind(a.$layerEl,q.type,e)};q.supported&&b(a.$layerEl,q.type,e)},_createPopup:function(a){var b,c,d,f=a.mode,g=a.title,k=a.content,l=a.className?"."+a.className:"",m=k instanceof Object?!0:!1;this.callbacks={onOpen:a.onOpen,onSubmit:a.onSubmit,onClose:a.onClose},b={tag:"button#popupS-button-ok."+this.options.baseClassName+"-button-ok"+(this.options.additionalButtonOkClass?this.options.additionalButtonOkClass:""),text:this.options.labelOk},c={tag:"button#popupS-button-cancel."+this.options.baseClassName+"-button-ok"+(this.options.additionalButtonCancelClass?this.options.additionalButtonCancelClass:""),text:this.options.labelCancel},d=[{html:k},"modal"!=f&&"modal-ajax"!=f&&"prompt"==f&&{tag:"form."+this.options.baseClassName+"-form"+(this.options.additionalFormClass?this.options.additionalFormClass:""),children:[a.placeholder&&{tag:"label",htmlFor:"popupS-input",text:a.placeholder},{tag:"input#popupS-input",type:"text"}]},"modal"!=f&&"modal-ajax"!=f&&{tag:"nav."+this.options.baseClassName+"-buttons"+(this.options.additionalButtonHolderClass?this.options.additionalButtonHolderClass:""),children:"prompt"==f||"confirm"==f?this.options.flagButtonReverse?[b,c]:[c,b]:[b]}],k=h({children:[{tag:"a#popupS-resetFocusBack."+this.options.baseClassName+"-resetFocus",href:"#",text:"Reset Focus"},this.options.flagShowCloseBtn&&{tag:"span#popupS-close."+this.options.baseClassName+"-close"+(this.options.additionalCloseBtnClass?this.options.additionalCloseBtnClass:""),html:this.options.closeBtn},g&&{tag:"h5."+this.options.baseClassName+"-title"+l,text:g},{tag:"."+this.options.baseClassName+"-content"+l,children:m&&k||d},{tag:"a#popupS-resetFocus."+this.options.baseClassName+"-resetFocus",href:"#",text:"Reset Focus"}]}),this._resetLayer(),i(this.$layerEl.childNodes[0],k),this._appendPopup(),this.$contentEl=this.$layerEl.getElementsByClassName(this.options.baseClassName+"-content")[0],this.$btnReset=document.getElementById("popupS-resetFocus"),this.$btnResetBack=document.getElementById("popupS-resetFocusBack"),e(this.$btnReset,"focus",this._resetEvent),e(this.$btnResetBack,"focus",this._resetEvent),j(this.$layerEl),this.$btnOK=document.getElementById("popupS-button-ok")||void 0,this.$btnCancel=document.getElementById("popupS-button-cancel")||void 0,this.$input=document.getElementById("popupS-input")||void 0,"undefined"!=typeof this.$btnOK&&e(this.$btnOK,"click",this._okEvent),"undefined"!=typeof this.$btnCancel&&e(this.$btnCancel,"click",this._cancelEvent),this.options.flagShowCloseBtn&&e(document.getElementById("popupS-close"),"click",this._cancelEvent),this.options.flagCloseByOverlay&&e(this.$overlayEl,"click",this._cancelEvent),this.options.flagCloseByEsc&&e(document.body,"keyup",this._keyEvent),"function"==typeof this.callbacks.onOpen&&this.callbacks.onOpen.call(this)},_appendPopup:function(){this.$targetEl=this.options.appendLocation,i(this.$targetEl,this.$wrapEl),this.$targetEl===(document.body||document.documentElement)&&this.options.flagBodyScroll===!1&&g(this.$targetEl,{overflow:"hidden"}),window.getComputedStyle&&window.getComputedStyle(this.$wrapEl,null).height;var a=function(a){return new RegExp("(|\\s+)"+a+"(\\s+|$)")};a(" "+this.options.baseClassName+"-open").test(this.$wrapEl.className)||(this.$wrapEl.className+=" "+this.options.baseClassName+"-open"),a(" "+this.options.baseClassName+"-open").test(this.$layerEl.childNodes[0].className)||(this.$layerEl.childNodes[0].className+=" "+this.options.baseClassName+"-open")},_hide:function(){var a=this;if(n.splice(0,1),n.length>0)this._create();else{m=!1;var b=function(){l(a.$wrapEl),a.$targetEl===(document.body||document.documentElement)&&a.options.flagBodyScroll===!1&&(a.$targetEl.style.removeProperty?a.$targetEl.style.removeProperty("overflow"):a.$targetEl.style.removeAttribute("overflow"))},c=function(d){d.stopPropagation(),f(a.$wrapEl,q.type,c),b()},d=function(b){b.stopPropagation(),f(a.$layerEl,q.type,c)};this.$wrapEl.className=this.$wrapEl.className.replace(" "+this.options.baseClassName+"-open",""),q.supported?e(a.$wrapEl,q.type,c):b(),this.$layerEl.childNodes[0].className=this.$layerEl.childNodes[0].className.replace(" "+this.options.baseClassName+"-open",""),q.supported&&e(a.$layerEl,q.type,d)}},_loading:function(a){this.$loadingEl=h({tag:"div."+this.options.baseClassName+"-loading."+this.options.loader}),a?(this._resetLayer(),g(this.$layerEl.childNodes[0],{height:"60px",width:"60px",borderRadius:"30px"}),i(this.$layerEl.childNodes[0],this.$loadingEl),this._appendPopup()):g(this.$layerEl.childNodes[0],{height:null,width:null,borderRadius:null})},_loadContents:function(a){var b=a.ajax.url,c="undefined"!=typeof a.ajax.str?a.ajax.str:"",d="undefined"!=typeof a.ajax.post?a.ajax.post:!0,e=this;if(b.match(o)){var f=h({children:{tag:"img",src:b}});this._loading(!0),this._preLoadImage(f,function(){e._loading(!1),a.content=f,e._createPopup(a)})}else this._ajax(b,c,d,function(b){var c=h({html:this});e._preLoadImage(c,function(){e._loading(!1),a.content=c,e._createPopup(a)})},function(){e._loading(!0)})},_preLoadImage:function(a,b){for(var c,d=k(a,"img"),g=d.length,h=g;g--;)c=d[g],c.complete?h--:(e(c,"load",i),e(c,"error",i));!h&&i();var i=function(){if(--h<=0){for(g=d.length;g--;)c=d[g],f(c,"load",i),f(c,"error",i);b()}}},_ajax:function(a,b,c,d,e){var f;if(window.XMLHttpRequest)f=new XMLHttpRequest;else if(ActiveXObject("Microsoft.XMLHTTP"))f=new ActiveXObject("Microsoft.XMLHTTP");else{if(!ActiveXObject("Msxml2.XMLHTTP"))return alert("Error: Your browser does not support AJAX."),!1;f=new ActiveXObject("Msxml2.XMLHTTP")}return f.onreadystatechange=function(){4==f.readyState&&200==f.status&&d&&d.call(f.responseText)},c===!1?(f.open("GET",a+b,!0),f.send(null)):(f.open("POST",a,!0),f.setRequestHeader("Content-type","application/x-www-form-urlencoded"),f.send(b)),e&&e.call(),f},_okEvent:function(a){"undefined"!=typeof a.preventDefault&&a.preventDefault(),"function"==typeof this.callbacks.onSubmit&&("undefined"!=typeof this.$input?this.callbacks.onSubmit.call(this,this.$input.value):this.callbacks.onSubmit.call(this)),this._commonEvent()},_cancelEvent:function(a){"undefined"!=typeof a.preventDefault&&a.preventDefault(),"function"==typeof this.callbacks.onClose&&this.callbacks.onClose.call(this),this._commonEvent()},_commonEvent:function(){"undefined"!=typeof this.$btnOK&&f(this.$btnOK,"click",this._okEvent),"undefined"!=typeof this.$btnCancel&&f(this.$btnCancel,"click",this._cancelEvent),this.options.flagShowCloseBtn&&f(document.getElementById("popupS-close"),"click",this._cancelEvent),this.options.flagCloseByOverlay&&f(this.$overlayEl,"click",this._cancelEvent),this.options.flagCloseByEsc&&f(document.body,"keyup",this._keyEvent),this._hide()},_resetEvent:function(a){j(this.$layerEl)},_keyEvent:function(a){var b=a.keyCode;"undefined"!=typeof this.$input&&13===b&&this._okEvent(a),27===b&&this._cancelEvent(a)}};var r=/^(\w+)?(#[\w_-]+)?((?:\.[\w_-]+)*)/i;return a.window=function(b){return new a(b)},a.alert=function(b){return b=d(b,{mode:"alert"}),new a(b)},a.confirm=function(b){return b=d(b,{mode:"confirm"}),new a(b)},a.prompt=function(b){return b=d(b,{mode:"prompt"}),new a(b)},a.modal=function(b){return b=d(b,{mode:"modal"}),new a(b)},a.ajax=function(b){return b=d(b,{mode:"modal-ajax"}),new a(b)},a}); | ||
/*! popups 1.1.2 - MIT | https://github.com/ChiefORZ/popupS.git */ | ||
!function(a,b){"function"==typeof define&&define.amd?define(b):"object"==typeof exports?module.exports=b():a.popupS=b()}(this,function(){"use strict";function a(){}function b(a,b){var c=[].slice.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat([].slice.call(arguments)))}}function c(a,b){if(a)for(var c in a)a.hasOwnProperty(c)&&b(a[c],c,a)}function d(a){a=a||{};for(var b=1;b<arguments.length;b++)if(arguments[b])for(var c in arguments[b])arguments[b].hasOwnProperty(c)&&(a[c]=arguments[b][c]);return a}function e(a,b,c){"function"==typeof a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent&&a.attachEvent("on"+b,c)}function f(a,b,c){"function"==typeof a.removeEventListener?a.removeEventListener(b,c,!1):a.detachEvent&&a.detachEvent("on"+b,c)}function g(a,b,c){if(a&&a.style&&b)if(b instanceof Object)for(var d in b)g(a,d,b[d]);else a.style[b]=c}function h(a){null===a&&(a="div"),"string"==typeof a&&(a={tag:a});var b,d,e=document.createDocumentFragment(),f=a.children,j=r.exec(a.tag||"");return delete a.children,a.tag=j[1]||"div",a.id=a.id||(j[2]||"").substr(1),d=(j[3]||"").split("."),d[0]=a.className||"",a.className=d.join(" "),b=document.createElement(a.tag),i(e,b),delete a.tag,c(a,function(c,d){if("css"===d)g(b,a.css);else if("text"===d)null!==c&&i(b,document.createTextNode(c));else if("html"===d)null!==c&&(b.innerHTML=c);else if(d in b)try{b[d]=c}catch(e){b.setAttribute(d,c)}else/^data-/.test(d)&&b.setAttribute(d,c)}),f&&f.appendChild?i(b,f):f&&(f instanceof Array?c(f,function(a,c){a instanceof Object&&i(b,h(a))}):f instanceof Object&&i(b,h(f))),b}function i(a,b){try{a&&b&&a.appendChild(b)}catch(c){}}function j(a){for(var b,c,d=k(a,"input"),e=0,f=d.length;f>e;e++)if(b=d[e],"submit"===b.type)!c&&(c=b);else if(!/hidden|check|radio/.test(b.type)&&""===b.value){c=b;break}c||(c=k(a,"button")[0]);try{c.focus()}catch(g){}}function k(a,b){return a.getElementsByTagName(b)}function l(a){a&&a.parentNode&&a.parentNode.removeChild(a)}var m=!1,n=[],o=new RegExp(/([^\/\\]+)\.(jpg|jpeg|png|gif)$/i),p={additionalBaseClass:"",additionalButtonHolderClass:"",additionalButtonOkClass:"",additionalButtonCancelClass:"",additionalCloseBtnClass:"",additionalFormClass:"",additionalOverlayClass:"",additionalPopupClass:"",appendLocation:document.body||document.documentElement,baseClassName:"popupS",closeBtn:"×",flagBodyScroll:!1,flagButtonReverse:!1,flagCloseByEsc:!0,flagCloseByOverlay:!0,flagShowCloseBtn:!0,labelOk:"OK",labelCancel:"Cancel",loader:"spinner",zIndex:1e4},q=function(){var a,b,c=!1,d=document.createElement("fakeelement"),e={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"otransitionend",transition:"transitionend"};for(a in e)if(e.hasOwnProperty(a)&&void 0!==d.style[a]){b=e[a],c=!0;break}return{type:b,supported:c}}();a.prototype={constructor:a,_open:function(a){if("string"!=typeof a.mode)throw new Error("mode must be a string");if("undefined"!=typeof a.title&&"string"!=typeof a.title)throw new Error("title must be a string");if("undefined"!=typeof a.placeholder&&"string"!=typeof a.placeholder)throw new Error("placeholder must be a string");this.options=a=d({},a);for(var e in p)!(e in a)&&(a[e]=p[e]);c(["additionalBaseClass","additionalButtonHolderClass","additionalButtonOkClass","additionalButtonCancelClass","additionalCloseBtnClass","additionalFormClass","additionalOverlayClass","additionalPopupClass"],function(b){var c=a[b].split(" ").join(".");a[b]="."+c});for(var f in this)"_"===f.charAt(0)&&(this[f]=b(this,this[f]));if(this._init(),a.force===!0)for(;n.length>0;)n.pop();n.push(a),m&&a.force!==!0||this._create()},_init:function(){this.$layerEl&&this.$layerEl.style.opacity&&(this.$layerEl.style.opacity=""),this.$wrapEl||(this.$wrapEl=h({tag:"div."+this.options.baseClassName+"-base"+(this.options.additionalBaseClass?this.options.additionalBaseClass:""),css:{top:0,left:0,right:0,bottom:0,position:"fixed",textAlign:"center",overflowX:"auto",overflowY:"auto",outline:0,whiteSpace:"nowrap",zIndex:this.options.zIndex},children:{css:{height:"100%",display:"inline-block",verticalAlign:"middle"}}}),i(this.$wrapEl,this._getOverlay()),i(this.$wrapEl,this._getLayer()))},_getOverlay:function(){return this.$overlayEl||(this.$overlayEl=h({tag:"#popupS-overlay."+this.options.baseClassName+"-overlay"+(this.options.additionalOverlayClass?this.options.additionalOverlayClass:""),css:{top:0,right:0,bottom:0,left:0,position:"fixed",overflowX:"hidden",userSelect:"none",webkitUserSelect:"none",MozUserSelect:"none"}})),this.$overlayEl.setAttribute("unselectable","on"),this.$overlayEl},_getLayer:function(){return this.$layerEl||(this.$layerEl=h({css:{display:"inline-block",position:"relative",textAlign:"left",whiteSpace:"normal",verticalAlign:"middle",transform:"translate3d(0,0,0)"},children:{tag:"."+this.options.baseClassName+"-layer"+(this.options.additionalPopupClass?this.options.additionalPopupClass:"")}})),this.$layerEl},_resetLayer:function(){this.$layerEl.childNodes[0].innerHTML=""},_create:function(){var a=this,c=n[0],d=c.mode;m=!0,"modal-ajax"!=d?this._createPopup(c):this._loadContents(c);var e=function(b){b.stopPropagation(),_unbind(a.$layerEl,q.type,e)};q.supported&&b(a.$layerEl,q.type,e)},_createPopup:function(a){var b,c,d,f=a.mode,g=a.title,k=a.content,l=a.className?"."+a.className:"",m=k instanceof Object?!0:!1;this.callbacks={onOpen:a.onOpen,onSubmit:a.onSubmit,onClose:a.onClose},b={tag:"button#popupS-button-ok."+this.options.baseClassName+"-button-ok"+(this.options.additionalButtonOkClass?this.options.additionalButtonOkClass:""),text:this.options.labelOk},c={tag:"button#popupS-button-cancel."+this.options.baseClassName+"-button-ok"+(this.options.additionalButtonCancelClass?this.options.additionalButtonCancelClass:""),text:this.options.labelCancel},d=[{html:k},"modal"!=f&&"modal-ajax"!=f&&"prompt"==f&&{tag:"form."+this.options.baseClassName+"-form"+(this.options.additionalFormClass?this.options.additionalFormClass:""),children:[a.placeholder&&{tag:"label",htmlFor:"popupS-input",text:a.placeholder},{tag:"input#popupS-input",type:"text"}]},"modal"!=f&&"modal-ajax"!=f&&{tag:"nav."+this.options.baseClassName+"-buttons"+(this.options.additionalButtonHolderClass?this.options.additionalButtonHolderClass:""),children:"prompt"==f||"confirm"==f?this.options.flagButtonReverse?[b,c]:[c,b]:[b]}],k=h({children:[{tag:"a#popupS-resetFocusBack."+this.options.baseClassName+"-resetFocus",href:"#",text:"Reset Focus"},this.options.flagShowCloseBtn&&{tag:"span#popupS-close."+this.options.baseClassName+"-close"+(this.options.additionalCloseBtnClass?this.options.additionalCloseBtnClass:""),html:this.options.closeBtn},g&&{tag:"h5."+this.options.baseClassName+"-title"+l,text:g},{tag:"."+this.options.baseClassName+"-content"+l,children:m&&k||d},{tag:"a#popupS-resetFocus."+this.options.baseClassName+"-resetFocus",href:"#",text:"Reset Focus"}]}),this._resetLayer(),i(this.$layerEl.childNodes[0],k),this._appendPopup(),this.$contentEl=this.$layerEl.getElementsByClassName(this.options.baseClassName+"-content")[0],this.$btnReset=document.getElementById("popupS-resetFocus"),this.$btnResetBack=document.getElementById("popupS-resetFocusBack"),e(this.$btnReset,"focus",this._resetEvent),e(this.$btnResetBack,"focus",this._resetEvent),j(this.$layerEl),this.$btnOK=document.getElementById("popupS-button-ok")||void 0,this.$btnCancel=document.getElementById("popupS-button-cancel")||void 0,this.$input=document.getElementById("popupS-input")||void 0,"undefined"!=typeof this.$btnOK&&e(this.$btnOK,"click",this._okEvent),"undefined"!=typeof this.$btnCancel&&e(this.$btnCancel,"click",this._cancelEvent),this.options.flagShowCloseBtn&&e(document.getElementById("popupS-close"),"click",this._cancelEvent),this.options.flagCloseByOverlay&&e(this.$overlayEl,"click",this._cancelEvent),this.options.flagCloseByEsc&&e(document.body,"keyup",this._keyEvent),"function"==typeof this.callbacks.onOpen&&this.callbacks.onOpen.call(this)},_appendPopup:function(){this.$targetEl=this.options.appendLocation,i(this.$targetEl,this.$wrapEl),this.$targetEl===(document.body||document.documentElement)&&this.options.flagBodyScroll===!1&&g(this.$targetEl,{overflow:"hidden"}),window.getComputedStyle&&window.getComputedStyle(this.$wrapEl,null).height;var a=function(a){return new RegExp("(|\\s+)"+a+"(\\s+|$)")};a(" "+this.options.baseClassName+"-open").test(this.$wrapEl.className)||(this.$wrapEl.className+=" "+this.options.baseClassName+"-open"),a(" "+this.options.baseClassName+"-open").test(this.$layerEl.childNodes[0].className)||(this.$layerEl.childNodes[0].className+=" "+this.options.baseClassName+"-open")},_hide:function(){var a=this;if(n.splice(0,1),n.length>0)this._create();else{m=!1;var b=function(){l(a.$wrapEl),a.$targetEl===(document.body||document.documentElement)&&a.options.flagBodyScroll===!1&&(a.$targetEl.style.removeProperty?a.$targetEl.style.removeProperty("overflow"):a.$targetEl.style.removeAttribute("overflow"))},c=function(d){d.stopPropagation(),f(a.$wrapEl,q.type,c),b()},d=function(b){b.stopPropagation(),f(a.$layerEl,q.type,c)};this.$wrapEl.className=this.$wrapEl.className.replace(" "+this.options.baseClassName+"-open",""),q.supported?e(a.$wrapEl,q.type,c):b(),this.$layerEl.childNodes[0].className=this.$layerEl.childNodes[0].className.replace(" "+this.options.baseClassName+"-open",""),q.supported&&e(a.$layerEl,q.type,d)}},_loading:function(a){this.$loadingEl=h({tag:"div."+this.options.baseClassName+"-loading."+this.options.loader}),a?(this._resetLayer(),g(this.$layerEl.childNodes[0],{height:"60px",width:"60px",borderRadius:"30px"}),i(this.$layerEl.childNodes[0],this.$loadingEl),this._appendPopup()):g(this.$layerEl.childNodes[0],{height:null,width:null,borderRadius:null})},_loadContents:function(a){var b=a.ajax.url,c="undefined"!=typeof a.ajax.str?a.ajax.str:"",d="undefined"!=typeof a.ajax.post?a.ajax.post:!0,e=this;if(b.match(o)){var f=h({children:{tag:"img",src:b}});this._loading(!0),this._preLoadImage(f,function(){e._loading(!1),a.content=f,e._createPopup(a)})}else this._ajax(b,c,d,function(b){var c=h({html:this});e._preLoadImage(c,function(){e._loading(!1),a.content=c,e._createPopup(a)})},function(){e._loading(!0)})},_preLoadImage:function(a,b){for(var c,d=k(a,"img"),g=d.length,h=g;g--;)c=d[g],c.complete?h--:(e(c,"load",i),e(c,"error",i));!h&&i();var i=function(){if(--h<=0){for(g=d.length;g--;)c=d[g],f(c,"load",i),f(c,"error",i);b()}}},_ajax:function(a,b,c,d,e){var f;if(window.XMLHttpRequest)f=new XMLHttpRequest;else if(ActiveXObject("Microsoft.XMLHTTP"))f=new ActiveXObject("Microsoft.XMLHTTP");else{if(!ActiveXObject("Msxml2.XMLHTTP"))return alert("Error: Your browser does not support AJAX."),!1;f=new ActiveXObject("Msxml2.XMLHTTP")}return f.onreadystatechange=function(){4==f.readyState&&200==f.status&&d&&d.call(f.responseText)},c===!1?(f.open("GET",a+b,!0),f.send(null)):(f.open("POST",a,!0),f.setRequestHeader("Content-type","application/x-www-form-urlencoded"),f.send(b)),e&&e.call(),f},_okEvent:function(a){"undefined"!=typeof a.preventDefault&&a.preventDefault(),"function"==typeof this.callbacks.onSubmit&&("undefined"!=typeof this.$input?this.callbacks.onSubmit.call(this,this.$input.value):this.callbacks.onSubmit.call(this)),this._commonEvent()},_cancelEvent:function(a){"undefined"!=typeof a.preventDefault&&a.preventDefault(),"function"==typeof this.callbacks.onClose&&this.callbacks.onClose.call(this),this._commonEvent()},_commonEvent:function(){"undefined"!=typeof this.$btnOK&&f(this.$btnOK,"click",this._okEvent),"undefined"!=typeof this.$btnCancel&&f(this.$btnCancel,"click",this._cancelEvent),this.options.flagShowCloseBtn&&f(document.getElementById("popupS-close"),"click",this._cancelEvent),this.options.flagCloseByOverlay&&f(this.$overlayEl,"click",this._cancelEvent),this.options.flagCloseByEsc&&f(document.body,"keyup",this._keyEvent),this._hide()},_resetEvent:function(a){j(this.$layerEl)},_keyEvent:function(a){var b=a.keyCode;"undefined"!=typeof this.$input&&13===b&&this._okEvent(a),27===b&&this._cancelEvent(a)}};var r=/^(\w+)?(#[\w_-]+)?((?:\.[\w_-]+)*)/i,s=new a;return s.window=function(a){this._open(a)},s.alert=function(a){a=d(a,{mode:"alert"}),this._open(a)},s.confirm=function(a){a=d(a,{mode:"confirm"}),this._open(a)},s.prompt=function(a){a=d(a,{mode:"prompt"}),this._open(a)},s.modal=function(a){a=d(a,{mode:"modal"}),this._open(a)},s.ajax=function(a){a=d(a,{mode:"modal-ajax"}),this._open(a)},s}); |
{ | ||
"name": "popups", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Native Javascript Modal/Popup system. With react support!", | ||
@@ -5,0 +5,0 @@ "main": "dist/popupS.js", |
@@ -68,9 +68,2 @@ # popupS | ||
```javascript | ||
var popup = new popupS({ | ||
mode: 'alert', | ||
content: 'Hi' | ||
}); | ||
// or | ||
popupS.window({ | ||
@@ -77,0 +70,0 @@ mode: 'alert', |
@@ -26,41 +26,5 @@ ;(function (root, factory) { | ||
* @class PopupS | ||
* @param {Object} options | ||
*/ | ||
function PopupS(options) { | ||
//error catching | ||
if (typeof options.mode !== "string") throw new Error("mode must be a string"); | ||
if (typeof options.title !== "undefined" && typeof options.title !== "string") throw new Error("title must be a string"); | ||
if (typeof options.placeholder !== "undefined" && typeof options.placeholder !== "string") throw new Error("placeholder must be a string"); | ||
function PopupS() {} | ||
this.options = options = _extend({}, options); | ||
// Set default options | ||
for (var name in _defaults) { | ||
!(name in options) && (options[name] = _defaults[name]); | ||
} | ||
// trail all classes divided by periods | ||
_each(['additionalBaseClass', 'additionalButtonHolderClass', 'additionalButtonOkClass', 'additionalButtonCancelClass', 'additionalCloseBtnClass', 'additionalFormClass', 'additionalOverlayClass', 'additionalPopupClass'], function(option) { | ||
var string = options[option].split(' ').join('.'); | ||
options[option] = '.' + string; | ||
}); | ||
// Bind all private methods | ||
for (var fn in this) { | ||
if (fn.charAt(0) === '_') { | ||
this[fn] = _bind(this, this[fn]); | ||
} | ||
} | ||
//initialize if it hasn't already been done | ||
this._init(); | ||
// if it is forced, close all others | ||
if(options.force === true) { | ||
while (queue.length > 0) queue.pop(); | ||
} | ||
queue.push(options); | ||
if(!isOpen) this._create(); | ||
} | ||
PopupS.prototype = require('./prototype'); | ||
@@ -72,32 +36,32 @@ | ||
/** | ||
* Create popupS instance | ||
* @param {Object} params | ||
*/ | ||
PopupS.window = function(params) { | ||
return new PopupS(params); | ||
// Instantiate a PopupS Object | ||
var popupS = new PopupS(); | ||
// Public methods | ||
popupS.window = function(params) { | ||
this._open(params); | ||
}; | ||
PopupS.alert = function(params) { | ||
popupS.alert = function(params) { | ||
params = _extend(params, {mode: 'alert'}); | ||
return new PopupS(params); | ||
this._open(params); | ||
}; | ||
PopupS.confirm = function(params) { | ||
popupS.confirm = function(params) { | ||
params = _extend(params, {mode: 'confirm'}); | ||
return new PopupS(params); | ||
this._open(params); | ||
}; | ||
PopupS.prompt = function(params) { | ||
popupS.prompt = function(params) { | ||
params = _extend(params, {mode: 'prompt'}); | ||
return new PopupS(params); | ||
this._open(params); | ||
}; | ||
PopupS.modal = function(params) { | ||
popupS.modal = function(params) { | ||
params = _extend(params, {mode: 'modal'}); | ||
return new PopupS(params); | ||
this._open(params); | ||
}; | ||
PopupS.ajax = function(params) { | ||
popupS.ajax = function(params) { | ||
params = _extend(params, {mode: 'modal-ajax'}); | ||
return new PopupS(params); | ||
this._open(params); | ||
}; | ||
// Export | ||
return PopupS; | ||
return popupS; | ||
})); |
module.exports = { | ||
constructor: PopupS, | ||
_open: function(options) { | ||
//error catching | ||
if (typeof options.mode !== "string") throw new Error("mode must be a string"); | ||
if (typeof options.title !== "undefined" && typeof options.title !== "string") throw new Error("title must be a string"); | ||
if (typeof options.placeholder !== "undefined" && typeof options.placeholder !== "string") throw new Error("placeholder must be a string"); | ||
this.options = options = _extend({}, options); | ||
// Set default options | ||
for (var name in _defaults) { | ||
!(name in options) && (options[name] = _defaults[name]); | ||
} | ||
// trail all classes divided by periods | ||
_each(['additionalBaseClass', 'additionalButtonHolderClass', 'additionalButtonOkClass', 'additionalButtonCancelClass', 'additionalCloseBtnClass', 'additionalFormClass', 'additionalOverlayClass', 'additionalPopupClass'], function(option) { | ||
var string = options[option].split(' ').join('.'); | ||
options[option] = '.' + string; | ||
}); | ||
// Bind all private methods | ||
for (var fn in this) { | ||
if (fn.charAt(0) === '_') { | ||
this[fn] = _bind(this, this[fn]); | ||
} | ||
} | ||
//initialize if it hasn't already been done | ||
this._init(); | ||
// if it is forced, close all others | ||
if(options.force === true) { | ||
while (queue.length > 0) queue.pop(); | ||
} | ||
queue.push(options); | ||
if(!isOpen || options.force === true) this._create(); | ||
}, | ||
_init: function() { | ||
@@ -5,0 +42,0 @@ // if i passed a opacity attribute to the layer onClose, remove it on initialization |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
156262
20
2035
258