From cd66fdb5699beefc0b332a953a06c7ac4c6b3f07 Mon Sep 17 00:00:00 2001 From: Bilal Cinarli Date: Fri, 27 Nov 2015 15:57:30 +0200 Subject: [PATCH] Dist v 1.4.0 --- bower.json | 7 +++- dist/uxrocket.modal.js | 81 +++++++++++-------------------------- dist/uxrocket.modal.min.css | 4 +- dist/uxrocket.modal.min.js | 6 +-- package.json | 2 +- 5 files changed, 35 insertions(+), 65 deletions(-) diff --git a/bower.json b/bower.json index e90e391..94718e2 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "uxrocket.modal", - "version": "1.3.3", + "version": "1.4.0", "homepage": "https://github.com/uxrocket/uxrocket.modal", "authors": [ "Bilal Çınarlı " @@ -10,10 +10,13 @@ "dependencies": { "jquery": ">=1.11.1" }, + "devDependencies": { + "uxrocket.factory": "1.0.0-alpha2" + }, "keywords": [ "jQuery", "javascript", - "modal", + "modal", "uxrocket" ], "license": "MIT", diff --git a/dist/uxrocket.modal.js b/dist/uxrocket.modal.js index b262e9c..5db00e6 100644 --- a/dist/uxrocket.modal.js +++ b/dist/uxrocket.modal.js @@ -22,12 +22,12 @@ instance = 1, overlay = '
', - content = '
' + - '
' + - '
' + - '
' + + content = '
' + + '
' + + '
' + + '
' + '
' + - ' ' + + ' ' + '
', openedInstances = {}, @@ -89,7 +89,9 @@ close: 'close', hide: 'hide' } - }; + }, + + utils = new uxrPluginUtils({ns: ns}); var Modal = function(el, options, selector) { this._name = rocketName; @@ -200,7 +202,17 @@ Modal.prototype.prepare = function() { var css = {}, $overlay = $('#uxr-modal-overlay'), - _content = content.replace('{{id}}', 'uxr-modal-instance-' + this._instance), + data = { + id: 'uxr-modal-instance-' + this._instance, + container: utils.getClassname('container'), + loading: utils.getClassname('loading'), + drag: utils.getClassname('drag'), + hide: utils.getClassname('hide'), + content: utils.getClassname('content'), + loadedContent: utils.getClassname('loadedContent'), + close: utils.getClassname('close') + }, + _content = utils.render(content, data), _appendTo = 'body'; this.emitEvent('start'); @@ -336,6 +348,10 @@ modal.close(this); + if(this._direct) { + this.removeContent(); + } + this.emitEvent('close'); }; @@ -542,55 +558,6 @@ } }; - var utils = { - callback: function(fn) { - // if callback string is function call it directly - if(typeof fn === 'function') { - fn.apply(this); - } - - // if callback defined via data-attribute, call it via new Function - else { - if(fn !== false) { - var func = new Function('return ' + fn); - func(); - } - } - }, - - escapeSelector: function(selector) { - var is_ID = selector.charAt(0) === '#', - re = /([ !"#$%&'()*+,.\/:;<=>?@[\\\]^`{|}~])/g; - - return is_ID ? '#' + selector.substring(1).replace(re, '\\$1') : selector; - }, - - getStringVariable: function(str) { - var val; - // check if it is chained - if(str.indexOf('.') > -1) { - var chain = str.split('.'), - chainVal = window[chain[0]]; - - for(var i = 1; i < chain.length; i++) { - chainVal = chainVal[chain[i]]; - } - - val = chainVal; - } - - else { - val = window[str]; - } - - return val; - }, - - getClassname: function(which) { - return ns.prefix + ns.name + '-' + ns.classes[which]; - } - }; - ux = $.fn.modal = $.fn.uxrmodal = $.uxrmodal = function(options) { var selector = this.selector; @@ -639,7 +606,7 @@ return openedInstances; }; - ux.version = '1.3.3'; + ux.version = '1.4.0'; ux.settings = defaults; })); \ No newline at end of file diff --git a/dist/uxrocket.modal.min.css b/dist/uxrocket.modal.min.css index 3ff6ed8..0fb6950 100644 --- a/dist/uxrocket.modal.min.css +++ b/dist/uxrocket.modal.min.css @@ -1,7 +1,7 @@ /*! UX Rocket Modal * Modal Plugin * @author Bilal Cinarli (http://bcinarli.com/) - * @version 1.3.3 - * @build Fri Oct 30 2015 21:38:01 GMT+0300 (EEST) + * @version 1.4.0 + * @build Fri Nov 27 2015 15:56:24 GMT+0200 (EET) */ #uxr-modal-overlay{position:fixed;top:0;left:0;width:100%;height:100%;z-index:9999;background-color:#000;opacity:.4}.uxr-modal-container{position:absolute;z-index:10000;top:50%;left:50%;-webkit-transform:translateY(-50%) translateX(-50%);-ms-transform:translateY(-50%) translateX(-50%);transform:translateY(-50%) translateX(-50%);min-width:50px;min-height:50px;padding:20px;border-radius:3px;background-color:#fff;box-sizing:border-box;box-shadow:0 0 2px rgba(0,0,0,0.5);transition:all ease .3s}.uxr-modal-drag{position:absolute;top:0;left:0;cursor:move;width:100%;height:24px}.uxr-modal-loaded-content,.uxr-modal-content{position:relative}.uxr-modal-content{width:100%;max-height:100%}.uxr-modal-loading:after{content:"";position:absolute;top:50%;left:50%;width:30px;height:30px;margin:-15px 0 0 -15px;border:2px dashed #777;border-radius:50%;box-sizing:border-box;-webkit-animation:uxr-modal-loading 2s infinite linear;animation:uxr-modal-loading 2s infinite linear}.uxr-modal-close{position:absolute;top:5px;right:5px;width:20px;height:20px;border-radius:50%;background-color:#ccc;color:#fff;font-family:sans-serif;text-align:center;text-decoration:none;cursor:pointer}.uxr-modal-close:before{content:"X";font-size:.8em;line-height:22px}.uxr-modal-hide{display:none}@-webkit-keyframes uxr-modal-loading{from{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes uxr-modal-loading{from{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(360deg);transform:rotate(360deg)}} diff --git a/dist/uxrocket.modal.min.js b/dist/uxrocket.modal.min.js index 65c97a4..09b39ba 100644 --- a/dist/uxrocket.modal.min.js +++ b/dist/uxrocket.modal.min.js @@ -1,7 +1,7 @@ /*! UX Rocket Modal * Modal Plugin * @author Bilal Cinarli (http://bcinarli.com/) - * @version 1.3.3 - * @build Fri Oct 30 2015 21:38:01 GMT+0300 (EEST) + * @version 1.4.0 + * @build Fri Nov 27 2015 15:56:25 GMT+0200 (EET) */ -!function(e){"use strict";"function"==typeof define&&define.amd?define(["jquery"],e):e("object"==typeof exports&&"function"==typeof require?jQuery:jQuery)}(function(e){var t,o="uxrModal",n=1,s='
',i='
',a={},c={className:"",href:"",width:"",height:"",maxWidth:"",maxHeight:"",appendTo:"body",allowMultiple:!1,blockUI:!0,overlayClose:!0,close:!0,iframe:!1,html:!1,fixed:!1,onReady:!1,onOpen:!1,onStart:!1,onLoad:!1,onClose:!1,onRemove:!1},l={click:"click."+o,wresize:"resize."+o,touchstart:"touchstart."+o,toucemove:"touchmove."+o,touchend:"touchend."+o,mousedown:"mousedown."+o,mousemove:"mousemove."+o,mouseup:"mouseup."+o,open:"uxropen."+o,start:"uxrstart."+o,load:"uxrload."+o,close:"uxrclose."+o,ready:"uxrready."+o,resize:"uxrresize."+o,remove:"uxrremove."+o},r={prefix:"uxr-",rocket:"uxRocket",data:o,name:"modal",classes:{ready:"ready",overlay:"overlay",container:"container",drag:"drag",content:"content",loadedContent:"loaded-content",loading:"loading",close:"close",hide:"hide"}},h=function(t,s,i){this._name=o,this._defaults=c,this._instance=n,this._direct=!1,null===t&&(t=document.createElement("a"),this._direct=!0),this.el=t,this.$el=e(t),this.$content=null,this.options=e.extend(!0,{},c,s,this.$el.data()),this.href=this.options.href||this.$el.attr("href")||!1,this.selector=i,n++,this.init()};h.prototype.init=function(){var e=this.$el.data(r.rocket)||{};e[r.data]={hasWrapper:!1,ready:p.getClassname("ready"),selector:this.selector,options:this.options},this.$el.data(r.rocket,e),this.bindUIActions(),this.$el.addClass(p.getClassname("ready")),this.emitEvent("ready"),this._direct===!0&&this.prepare()},h.prototype.bindUIActions=function(){var t=this;this.$el.on(l.click,function(e){e.preventDefault(),"undefined"==typeof a[t._instance]&&t.prepare()}).on(l.ready,function(){t.onReady()}).on(l.open,function(){t.onOpen()}).on(l.start,function(){t.onStart()}).on(l.load,function(){t.onLoad()}).on(l.close,function(){t.onClose()}).on(l.remove,function(){t.onRemove()}),e("body").on(l.click+" "+l.touchstart,"#uxr-modal-overlay",function(){d.closeFromOverlay()}).on(l.click+" "+l.touchstart,"#uxr-modal-instance-"+t._instance+" ."+p.getClassname("close"),function(e){e.preventDefault(),t.close()}).on(l.mousedown+" "+l.touchstart,"#uxr-modal-instance-"+t._instance+" ."+p.getClassname("drag"),function(e){e.preventDefault(),d.move.start(t,e)}),e(document).on(l.mousemove+" "+l.touchmove,function(e){d.move.drag(e)}).on(l.mouseup+" "+l.touchend,function(){d.move.stop()}),e(window).on(l.wresize,function(){void 0!==a[t._instance]&&t.resize()})},h.prototype.unbindUIActions=function(){this.emitEvent("remove"),this.$el.off("."+o)},h.prototype.prepare=function(){var t={},o=e("#uxr-modal-overlay"),n=i.replace("{{id}}","uxr-modal-instance-"+this._instance),a="body";this.emitEvent("start"),"body"!==this.options.appendTo&&(a=0===e(p.escapeSelector(this.options.appendTo)).length?"body":this.options.appendTo),!this.options.allowMultiple&&d.isOnlyInstance()&&d.closeFromOverlay(),this.options.blockUI&&(0===o.length?e(p.escapeSelector(a)).append(s):o.removeClass(p.getClassname("hide"))),null===this.$content?(this.$content=e(n),this.options.fixed&&(t.position="fixed"),""!==this.options.maxWidth&&(t.maxWidth=this.options.maxWidth),""!==this.options.maxHeight&&(t.maxHeight=this.options.maxHeight),Object.keys(t).length>0&&this.$content.css(t),e(p.escapeSelector(a)).append(this.$content)):this.$content.removeClass(p.getClassname("hide")),this.$content.addClass(p.getClassname("loading")).find("."+p.getClassname("loadedContent")).html(""),d.registerInstance(this),this.open()},h.prototype.open=function(){this.emitEvent("open"),this.get()},h.prototype.get=function(){var t,o=this;if(this.options.iframe)this.options.width=this.options.width||800,this.options.height=this.options.height||600,t='',this.html=t,o.emitEvent("load");else if(this.isInpage())if(this.href!==!1){var n=e(p.escapeSelector(this.href)),s=e("
").addClass("."+p.getClassname("hide")).insertBefore(n),i=null!==this.el?this.$el:e(document);i.one(l.close,function(){s.replaceWith(n)}),this.html=n,o.emitEvent("load")}else this.html=this.options.html,o.emitEvent("load");else e.get(this.href).done(function(e){o.html=e,setTimeout(function(){o.emitEvent("load")})})},h.prototype.load=function(){var e=this.$content.find("."+p.getClassname("loadedContent"));e.html(""),this.$content.removeClass(p.getClassname("loading")),this.options.close&&this.$content.find("."+p.getClassname("close")).removeClass(p.getClassname("hide")),this.options.allowMultiple&&this.$content.find("."+p.getClassname("drag")).removeClass(p.getClassname("hide")),e.append(this.html),this.resize()},h.prototype.close=function(){d.isOnlyInstance()&&e("#uxr-modal-overlay").addClass(p.getClassname("hide")),this.$content.addClass(p.getClassname("hide")).find("."+p.getClassname("close")).addClass(p.getClassname("hide")),d.close(this),this.emitEvent("close")},h.prototype.resize=function(){var e,t,o,n={},s=this.$content.find("."+p.getClassname("content")),i=this.$content.find("."+p.getClassname("loadedContent"));s.height("auto"),e=this.$content.height(),""!==this.options.width&&(n.width=this.options.width),""!==this.options.height&&(n.height=this.options.height),i.css(n),t=i.css("position","absolute").width(),o=i.height(),i.css("position","relative"),o>e&&s.width()e?(s.height(e),s.css("overflowY","scroll")):s.width()1},isOnlyInstance:function(){return Object.keys(a).length-1===1},move:{pos:{},selected:!1,previous:!1,start:function(e,t){var o=this.pointer(t);this.selected=e,this.selected.$content.css("zIndex",10001),this.pos.top=o.y-this.selected.$content[0].offsetTop,this.pos.left=o.x-this.selected.$content[0].offsetLeft,this.previous?this.previous.$content.css("zIndex",1e4):this.previous=e},drag:function(e){var t=this.pointer(e);this.selected&&(this.selected.$content[0].style.top=t.y+"px",this.selected.$content[0].style.left=t.x+"px")},stop:function(){this.selected&&(this.previous=this.selected,this.selected=!1)},pointer:function(e){var t={x:0,y:0};if("touchstart"===e.type||"touchmove"===e.type||"touchend"===e.type||"touchcancel"===e.type){var o=e.originalEvent.touches[0]||e.originalEvent.changedTouches[0];t.x=o.pageX,t.y=o.pageY}else("mousedown"===e.type||"mouseup"===e.type||"mousemove"===e.type||"mouseover"===e.type||"mouseout"===e.type||"mouseenter"===e.type||"mouseleave"===e.type)&&(t.x=e.pageX,t.y=e.pageY);return t}}},p={callback:function(e){if("function"==typeof e)e.apply(this);else if(e!==!1){var t=new Function("return "+e);t()}},escapeSelector:function(e){var t="#"===e.charAt(0),o=/([ !"#$%&'()*+,.\/:;<=>?@[\\\]^`{|}~])/g;return t?"#"+e.substring(1).replace(o,"\\$1"):e},getStringVariable:function(e){var t;if(e.indexOf(".")>-1){for(var o=e.split("."),n=window[o[0]],s=1;s
',i='
',a={},c={className:"",href:"",width:"",height:"",maxWidth:"",maxHeight:"",appendTo:"body",allowMultiple:!1,blockUI:!0,overlayClose:!0,close:!0,iframe:!1,html:!1,fixed:!1,onReady:!1,onOpen:!1,onStart:!1,onLoad:!1,onClose:!1,onRemove:!1},l={click:"click."+n,wresize:"resize."+n,touchstart:"touchstart."+n,toucemove:"touchmove."+n,touchend:"touchend."+n,mousedown:"mousedown."+n,mousemove:"mousemove."+n,mouseup:"mouseup."+n,open:"uxropen."+n,start:"uxrstart."+n,load:"uxrload."+n,close:"uxrclose."+n,ready:"uxrready."+n,resize:"uxrresize."+n,remove:"uxrremove."+n},r={prefix:"uxr-",rocket:"uxRocket",data:n,name:"modal",classes:{ready:"ready",overlay:"overlay",container:"container",drag:"drag",content:"content",loadedContent:"loaded-content",loading:"loading",close:"close",hide:"hide"}},h=new uxrPluginUtils({ns:r}),d=function(t,s,i){this._name=n,this._defaults=c,this._instance=o,this._direct=!1,null===t&&(t=document.createElement("a"),this._direct=!0),this.el=t,this.$el=e(t),this.$content=null,this.options=e.extend(!0,{},c,s,this.$el.data()),this.href=this.options.href||this.$el.attr("href")||!1,this.selector=i,o++,this.init()};d.prototype.init=function(){var e=this.$el.data(r.rocket)||{};e[r.data]={hasWrapper:!1,ready:h.getClassname("ready"),selector:this.selector,options:this.options},this.$el.data(r.rocket,e),this.bindUIActions(),this.$el.addClass(h.getClassname("ready")),this.emitEvent("ready"),this._direct===!0&&this.prepare()},d.prototype.bindUIActions=function(){var t=this;this.$el.on(l.click,function(e){e.preventDefault(),"undefined"==typeof a[t._instance]&&t.prepare()}).on(l.ready,function(){t.onReady()}).on(l.open,function(){t.onOpen()}).on(l.start,function(){t.onStart()}).on(l.load,function(){t.onLoad()}).on(l.close,function(){t.onClose()}).on(l.remove,function(){t.onRemove()}),e("body").on(l.click+" "+l.touchstart,"#uxr-modal-overlay",function(){p.closeFromOverlay()}).on(l.click+" "+l.touchstart,"#uxr-modal-instance-"+t._instance+" ."+h.getClassname("close"),function(e){e.preventDefault(),t.close()}).on(l.mousedown+" "+l.touchstart,"#uxr-modal-instance-"+t._instance+" ."+h.getClassname("drag"),function(e){e.preventDefault(),p.move.start(t,e)}),e(document).on(l.mousemove+" "+l.touchmove,function(e){p.move.drag(e)}).on(l.mouseup+" "+l.touchend,function(){p.move.stop()}),e(window).on(l.wresize,function(){void 0!==a[t._instance]&&t.resize()})},d.prototype.unbindUIActions=function(){this.emitEvent("remove"),this.$el.off("."+n)},d.prototype.prepare=function(){var t={},n=e("#uxr-modal-overlay"),o={id:"uxr-modal-instance-"+this._instance,container:h.getClassname("container"),loading:h.getClassname("loading"),drag:h.getClassname("drag"),hide:h.getClassname("hide"),content:h.getClassname("content"),loadedContent:h.getClassname("loadedContent"),close:h.getClassname("close")},a=h.render(i,o),c="body";this.emitEvent("start"),"body"!==this.options.appendTo&&(c=0===e(h.escapeSelector(this.options.appendTo)).length?"body":this.options.appendTo),!this.options.allowMultiple&&p.isOnlyInstance()&&p.closeFromOverlay(),this.options.blockUI&&(0===n.length?e(h.escapeSelector(c)).append(s):n.removeClass(h.getClassname("hide"))),null===this.$content?(this.$content=e(a),this.options.fixed&&(t.position="fixed"),""!==this.options.maxWidth&&(t.maxWidth=this.options.maxWidth),""!==this.options.maxHeight&&(t.maxHeight=this.options.maxHeight),Object.keys(t).length>0&&this.$content.css(t),e(h.escapeSelector(c)).append(this.$content)):this.$content.removeClass(h.getClassname("hide")),this.$content.addClass(h.getClassname("loading")).find("."+h.getClassname("loadedContent")).html(""),p.registerInstance(this),this.open()},d.prototype.open=function(){this.emitEvent("open"),this.get()},d.prototype.get=function(){var t,n=this;if(this.options.iframe)this.options.width=this.options.width||800,this.options.height=this.options.height||600,t='',this.html=t,n.emitEvent("load");else if(this.isInpage())if(this.href!==!1){var o=e(h.escapeSelector(this.href)),s=e("
").addClass("."+h.getClassname("hide")).insertBefore(o),i=null!==this.el?this.$el:e(document);i.one(l.close,function(){s.replaceWith(o)}),this.html=o,n.emitEvent("load")}else this.html=this.options.html,n.emitEvent("load");else e.get(this.href).done(function(e){n.html=e,setTimeout(function(){n.emitEvent("load")})})},d.prototype.load=function(){var e=this.$content.find("."+h.getClassname("loadedContent"));e.html(""),this.$content.removeClass(h.getClassname("loading")),this.options.close&&this.$content.find("."+h.getClassname("close")).removeClass(h.getClassname("hide")),this.options.allowMultiple&&this.$content.find("."+h.getClassname("drag")).removeClass(h.getClassname("hide")),e.append(this.html),this.resize()},d.prototype.close=function(){p.isOnlyInstance()&&e("#uxr-modal-overlay").addClass(h.getClassname("hide")),this.$content.addClass(h.getClassname("hide")).find("."+h.getClassname("close")).addClass(h.getClassname("hide")),p.close(this),this._direct&&this.removeContent(),this.emitEvent("close")},d.prototype.resize=function(){var e,t,n,o={},s=this.$content.find("."+h.getClassname("content")),i=this.$content.find("."+h.getClassname("loadedContent"));s.height("auto"),e=this.$content.height(),""!==this.options.width&&(o.width=this.options.width),""!==this.options.height&&(o.height=this.options.height),i.css(o),t=i.css("position","absolute").width(),n=i.height(),i.css("position","relative"),n>e&&s.width()e?(s.height(e),s.css("overflowY","scroll")):s.width()1},isOnlyInstance:function(){return Object.keys(a).length-1===1},move:{pos:{},selected:!1,previous:!1,start:function(e,t){var n=this.pointer(t);this.selected=e,this.selected.$content.css("zIndex",10001),this.pos.top=n.y-this.selected.$content[0].offsetTop,this.pos.left=n.x-this.selected.$content[0].offsetLeft,this.previous?this.previous.$content.css("zIndex",1e4):this.previous=e},drag:function(e){var t=this.pointer(e);this.selected&&(this.selected.$content[0].style.top=t.y+"px",this.selected.$content[0].style.left=t.x+"px")},stop:function(){this.selected&&(this.previous=this.selected,this.selected=!1)},pointer:function(e){var t={x:0,y:0};if("touchstart"===e.type||"touchmove"===e.type||"touchend"===e.type||"touchcancel"===e.type){var n=e.originalEvent.touches[0]||e.originalEvent.changedTouches[0];t.x=n.pageX,t.y=n.pageY}else("mousedown"===e.type||"mouseup"===e.type||"mousemove"===e.type||"mouseover"===e.type||"mouseout"===e.type||"mouseenter"===e.type||"mouseleave"===e.type)&&(t.x=e.pageX,t.y=e.pageY);return t}}};t=e.fn.modal=e.fn.uxrmodal=e.uxrmodal=function(t){var n=this.selector;return"function"==typeof this?new d(null,t,null):this.each(function(){e.data(this,r.data)||e.data(this,r.data,new d(this,t,n))})},t.remove=function(t){var n=e("undefined"==typeof t?"."+h.getClassname("ready"):t);n.each(function(){e(this).data(r.data).remove()})},t.resize=function(){var e=a.lastInstance;p.hasInstances()&&e.resize()},t.close=function(){var e=a.lastInstance;p.hasInstances()&&e.close()},t.getInstances=function(){return a},t.version="1.4.0",t.settings=c}); \ No newline at end of file diff --git a/package.json b/package.json index 2cfc3aa..9dea9c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "uxrocket.modal", - "version": "1.3.3", + "version": "1.4.0", "description": "Modal Plugin", "repository": { "type": "git",