From 58d7f57379ca413dbce60a12db48d1d20ef62758 Mon Sep 17 00:00:00 2001 From: Thomas Jang Date: Tue, 7 Jun 2016 00:54:10 +0900 Subject: [PATCH] ax5modal@0.6.0 --- dist/ax5modal.js | 10 +++++----- dist/ax5modal.min.js | 2 +- src/ax5modal.js | 10 +++++----- test/index.html | 1 + 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/dist/ax5modal.js b/dist/ax5modal.js index 6d55027..d2963bd 100755 --- a/dist/ax5modal.js +++ b/dist/ax5modal.js @@ -6,7 +6,7 @@ /** * @class ax5modal * @alias ax5.ui.modal - * @version 0.5.6 + * @version 0.6.0 * @author tom@axisj.com * @example * ``` @@ -245,8 +245,8 @@ } return { - left: modalOffset.left + self.__dx, - top: modalOffset.top + self.__dy + left: modalOffset.left + self.__dx + $(document).scrollLeft(), + top: modalOffset.top + self.__dy + $(document).scrollTop() }; }; @@ -280,8 +280,8 @@ var setModalPosition = function setModalPosition() { //console.log(this.activeModal.offset(), this.__dx); var box = this.activeModal.offset(); - box.left += this.__dx; - box.top += this.__dy; + box.left += this.__dx - $(document).scrollLeft(); + box.top += this.__dy - $(document).scrollTop(); this.activeModal.css(box); }; diff --git a/dist/ax5modal.min.js b/dist/ax5modal.min.js index 0fbbb3e..6dd5c4b 100755 --- a/dist/ax5modal.min.js +++ b/dist/ax5modal.min.js @@ -1 +1 @@ -"use strict";!function(t,i){var e=ax5.util,a=function(){var t,a=this,o={mousedown:ax5.info.supportTouch?"touchstart":"mousedown",mousemove:ax5.info.supportTouch?"touchmove":"mousemove",mouseup:ax5.info.supportTouch?"touchend":"mouseup"},n=function(t){var i=t;return"changedTouches"in t&&(i=t.changedTouches[0]),{clientX:i.clientX,clientY:i.clientY}};i&&i.call(this),this.activeModal=null,this.$={},this.config={position:{left:"center",top:"middle",margin:10},minimizePosition:"bottom-right",clickEventName:"click",theme:"default",width:300,height:400,closeToEsc:!0,animateTime:250},t=this.config,t.id="ax5-modal-"+ax5.getGuid();var d=function(t,i){return t&&t.onStateChanged?t.onStateChanged.call(i,i):this.onStateChanged&&this.onStateChanged.call(i,i),!0},s=function(){return' \n
\n {{#header}}\n
\n {{{title}}}\n {{#btns}}\n
\n {{#@each}}\n {{{@value.label}}}\n {{/@each}}\n
\n {{/btns}}\n
\n {{/header}}\n
\n {{#iframe}}\n
\n \n
\n
\n \n {{#param}}\n {{#@each}}\n \n {{/@each}}\n {{/param}}\n
\n {{/iframe}}\n
\n
\n '},l=function(t,i){var e={modalId:t,theme:i.theme,header:i.header,fullScreen:i.fullScreen?"fullscreen":"",styles:[],iframe:i.iframe};return i.zIndex&&e.styles.push("z-index:"+i.zIndex),e.iframe&&"string"==typeof e.iframe.param&&(e.iframe.param=ax5.util.param(e.iframe.param)),ax5.mustache.render(s(),e)},h=function(i,s){var h;jQuery(document.body).append(l.call(this,i.id,i)),this.activeModal=jQuery("#"+i.id),this.$={root:this.activeModal.find('[data-modal-els="root"]'),header:this.activeModal.find('[data-modal-els="header"]'),body:this.activeModal.find('[data-modal-els="body"]')},i.iframe&&(this.$["iframe-wrap"]=this.activeModal.find('[data-modal-els="iframe-wrap"]'),this.$.iframe=this.activeModal.find('[data-modal-els="iframe"]'),this.$["iframe-form"]=this.activeModal.find('[data-modal-els="iframe-form"]')),this.align(),h={self:this,id:i.id,theme:i.theme,width:i.width,height:i.height,state:"open",$:this.$},i.iframe&&(this.$["iframe-wrap"].css({height:i.height}),this.$.iframe.css({height:i.height}),this.$["iframe-form"].attr({method:i.iframe.method}),this.$["iframe-form"].attr({target:i.id+"-frame"}),this.$["iframe-form"].attr({action:i.iframe.url}),this.$.iframe.on("load",function(){h.state="load",d.call(this,i,h)}.bind(this)),this.$["iframe-form"].submit()),s&&s.call(h),d.call(this,i,h),i.closeToEsc&&jQuery(window).bind("keydown.ax-modal",function(t){m.call(this,t||window.event)}.bind(this)),jQuery(window).bind("resize.ax-modal",function(t){this.align(null,t||window.event)}.bind(this)),this.activeModal.find("[data-modal-header-btn]").on(t.clickEventName,function(t){r.call(this,t||window.event,i)}.bind(this)),this.$.header.bind(o.mousedown,function(t){a.mousePosition=n(t),c.on.call(a)}).bind("dragstart",function(t){return e.stopEvent(t),!1})},r=function(t,i,a,o,n){var d;t.srcElement&&(t.target=t.srcElement),o=e.findParentNode(t.target,function(t){return t.getAttribute("data-modal-header-btn")?!0:void 0}),o&&(n=o.getAttribute("data-modal-header-btn"),d={self:this,key:n,value:i.header.btns[n],dialogId:i.id,btnTarget:o},i.header.btns[n].onClick&&i.header.btns[n].onClick.call(d,n)),d=null,i=null,a=null,o=null,n=null},m=function(t){t.keyCode==ax5.info.eventKeys.ESC&&this.close()},u={"top-left":function(){this.align({left:"left",top:"top"})},"top-right":function(){this.align({left:"right",top:"top"})},"bottom-left":function(){this.align({left:"left",top:"bottom"})},"bottom-right":function(){this.align({left:"right",top:"bottom"})},"center-middle":function(){this.align({left:"center",top:"middle"})}},c={on:function(){var i=this.activeModal.position(),e={width:this.activeModal.outerWidth(),height:this.activeModal.outerHeight()},n={width:jQuery(window).width(),height:jQuery(window).height()},d=function(t){a.__dx=t.clientX-a.mousePosition.clientX,a.__dy=t.clientY-a.mousePosition.clientY;var o=0,d=n.width-e.width,s=0,l=n.height-e.height;return o>i.left+a.__dx?a.__dx=-i.left:di.top+a.__dy?a.__dy=-i.top:l'),a.resizer=jQuery('
'),a.resizer.css({left:i.left,top:i.top,width:e.width,height:e.height}),jQuery(document.body).append(a.resizerBg).append(a.resizer),a.activeModal.addClass("draged")),a.resizer.css(d(t))}).bind(o.mouseup+".ax5layout-"+this.instanceId,function(t){c.off.call(a)}).bind("mouseleave.ax5layout-"+this.instanceId,function(t){c.off.call(a)}),jQuery(document.body).attr("unselectable","on").css("user-select","none").on("selectstart",!1)},off:function(){var i=function(){var t=this.activeModal.offset();t.left+=this.__dx,t.top+=this.__dy,this.activeModal.css(t)};this.resizer&&(this.activeModal.removeClass("draged"),this.resizer.remove(),this.resizer=null,this.resizerBg.remove(),this.resizerBg=null,i.call(this)),jQuery(document.body).unbind(o.mousemove+".ax5modal-"+t.id).unbind(o.mouseup+".ax5modal-"+t.id).unbind("mouseleave.ax5modal-"+t.id),jQuery(document.body).removeAttr("unselectable").css("user-select","auto").off("selectstart")}};this.init=function(){this.onStateChanged=t.onStateChanged},this.open=function(i,e){return i=a.modalConfig=jQuery.extend(!0,{},t,i),h.call(this,i,e),this},this.close=function(i){return this.activeModal&&(i=a.modalConfig,this.activeModal.addClass("destroy"),jQuery(window).unbind("keydown.ax-modal"),jQuery(window).unbind("resize.ax-modal"),setTimeout(function(){this.activeModal.remove(),this.activeModal=null,d.call(this,i,{self:this,state:"close"})}.bind(this),t.animateTime)),this},this.minimize=function(){return function(i){var e=a.modalConfig;return"undefined"==typeof i&&(i=t.minimizePosition),this.minimized=!0,this.$.body.hide(),a.modalConfig.originalHeight=e.height,a.modalConfig.height=0,u[i].call(this),d.call(this,e,{self:this,state:"minimize"}),this}}(),this.maximize=function(){var t=a.modalConfig;return this.minimized&&(this.minimized=!1,this.$.body.show(),a.modalConfig.height=a.modalConfig.originalHeight,a.modalConfig.originalHeight=void 0,this.align({left:"center",top:"middle"}),d.call(this,t,{self:this,state:"restore"})),this},this.css=function(t){return this.activeModal&&!a.fullScreen&&(this.activeModal.css(t),t.width&&(a.modalConfig.width=this.activeModal.width()),t.height&&(a.modalConfig.height=this.activeModal.height(),this.$.iframe&&(this.$["iframe-wrap"].css({height:a.modalConfig.height}),this.$.iframe.css({height:a.modalConfig.height})))),this},this.align=function(){return function(t,i){if(!this.activeModal)return this;var e=a.modalConfig,o={width:e.width,height:e.height};return e.fullScreen?(e.header&&this.$.header.hide(),o.width=jQuery(window).width(),o.height=jQuery(window).height(),o.left=0,o.top=0,e.iframe&&(this.$["iframe-wrap"].css({height:o.height}),this.$.iframe.css({height:o.height}))):(t&&jQuery.extend(!0,e.position,t),e.header&&(o.height+=this.$.header.outerHeight()),"left"==e.position.left?o.left=e.position.margin||0:"right"==e.position.left?o.left=jQuery(window).width()-o.width-(e.position.margin||0):"center"==e.position.left?o.left=jQuery(window).width()/2-o.width/2:o.left=e.position.left||0,"top"==e.position.top?o.top=e.position.margin||0:"bottom"==e.position.top?o.top=jQuery(window).height()-o.height-(e.position.margin||0):"middle"==e.position.top?o.top=jQuery(window).height()/2-o.height/2:o.top=e.position.top||0),this.activeModal.css(o),this}}(),this.main=function(){arguments&&e.isObject(arguments[0])&&this.setConfig(arguments[0])}.apply(this,arguments)};t.modal=function(){return e.isFunction(i)&&(a.prototype=new i),a}()}(ax5.ui,ax5.ui.root); \ No newline at end of file +"use strict";!function(t,e){var i=ax5.util,o=function(){var t,o=this,a={mousedown:ax5.info.supportTouch?"touchstart":"mousedown",mousemove:ax5.info.supportTouch?"touchmove":"mousemove",mouseup:ax5.info.supportTouch?"touchend":"mouseup"},n=function(t){var e=t;return"changedTouches"in t&&(e=t.changedTouches[0]),{clientX:e.clientX,clientY:e.clientY}};e&&e.call(this),this.activeModal=null,this.$={},this.config={position:{left:"center",top:"middle",margin:10},minimizePosition:"bottom-right",clickEventName:"click",theme:"default",width:300,height:400,closeToEsc:!0,animateTime:250},t=this.config,t.id="ax5-modal-"+ax5.getGuid();var d=function(t,e){return t&&t.onStateChanged?t.onStateChanged.call(e,e):this.onStateChanged&&this.onStateChanged.call(e,e),!0},s=function(){return' \n
\n {{#header}}\n
\n {{{title}}}\n {{#btns}}\n
\n {{#@each}}\n {{{@value.label}}}\n {{/@each}}\n
\n {{/btns}}\n
\n {{/header}}\n
\n {{#iframe}}\n
\n \n
\n
\n \n {{#param}}\n {{#@each}}\n \n {{/@each}}\n {{/param}}\n
\n {{/iframe}}\n
\n
\n '},l=function(t,e){var i={modalId:t,theme:e.theme,header:e.header,fullScreen:e.fullScreen?"fullscreen":"",styles:[],iframe:e.iframe};return e.zIndex&&i.styles.push("z-index:"+e.zIndex),i.iframe&&"string"==typeof i.iframe.param&&(i.iframe.param=ax5.util.param(i.iframe.param)),ax5.mustache.render(s(),i)},h=function(e,s){var h;jQuery(document.body).append(l.call(this,e.id,e)),this.activeModal=jQuery("#"+e.id),this.$={root:this.activeModal.find('[data-modal-els="root"]'),header:this.activeModal.find('[data-modal-els="header"]'),body:this.activeModal.find('[data-modal-els="body"]')},e.iframe&&(this.$["iframe-wrap"]=this.activeModal.find('[data-modal-els="iframe-wrap"]'),this.$.iframe=this.activeModal.find('[data-modal-els="iframe"]'),this.$["iframe-form"]=this.activeModal.find('[data-modal-els="iframe-form"]')),this.align(),h={self:this,id:e.id,theme:e.theme,width:e.width,height:e.height,state:"open",$:this.$},e.iframe&&(this.$["iframe-wrap"].css({height:e.height}),this.$.iframe.css({height:e.height}),this.$["iframe-form"].attr({method:e.iframe.method}),this.$["iframe-form"].attr({target:e.id+"-frame"}),this.$["iframe-form"].attr({action:e.iframe.url}),this.$.iframe.on("load",function(){h.state="load",d.call(this,e,h)}.bind(this)),this.$["iframe-form"].submit()),s&&s.call(h),d.call(this,e,h),e.closeToEsc&&jQuery(window).bind("keydown.ax-modal",function(t){m.call(this,t||window.event)}.bind(this)),jQuery(window).bind("resize.ax-modal",function(t){this.align(null,t||window.event)}.bind(this)),this.activeModal.find("[data-modal-header-btn]").on(t.clickEventName,function(t){r.call(this,t||window.event,e)}.bind(this)),this.$.header.bind(a.mousedown,function(t){o.mousePosition=n(t),u.on.call(o)}).bind("dragstart",function(t){return i.stopEvent(t),!1})},r=function(t,e,o,a,n){var d;t.srcElement&&(t.target=t.srcElement),a=i.findParentNode(t.target,function(t){return t.getAttribute("data-modal-header-btn")?!0:void 0}),a&&(n=a.getAttribute("data-modal-header-btn"),d={self:this,key:n,value:e.header.btns[n],dialogId:e.id,btnTarget:a},e.header.btns[n].onClick&&e.header.btns[n].onClick.call(d,n)),d=null,e=null,o=null,a=null,n=null},m=function(t){t.keyCode==ax5.info.eventKeys.ESC&&this.close()},c={"top-left":function(){this.align({left:"left",top:"top"})},"top-right":function(){this.align({left:"right",top:"top"})},"bottom-left":function(){this.align({left:"left",top:"bottom"})},"bottom-right":function(){this.align({left:"right",top:"bottom"})},"center-middle":function(){this.align({left:"center",top:"middle"})}},u={on:function(){var e=this.activeModal.position(),i={width:this.activeModal.outerWidth(),height:this.activeModal.outerHeight()},n={width:jQuery(window).width(),height:jQuery(window).height()},d=function(t){o.__dx=t.clientX-o.mousePosition.clientX,o.__dy=t.clientY-o.mousePosition.clientY;var a=0,d=n.width-i.width,s=0,l=n.height-i.height;return a>e.left+o.__dx?o.__dx=-e.left:de.top+o.__dy?o.__dy=-e.top:l'),o.resizer=jQuery('
'),o.resizer.css({left:e.left,top:e.top,width:i.width,height:i.height}),jQuery(document.body).append(o.resizerBg).append(o.resizer),o.activeModal.addClass("draged")),o.resizer.css(d(t))}).bind(a.mouseup+".ax5layout-"+this.instanceId,function(t){u.off.call(o)}).bind("mouseleave.ax5layout-"+this.instanceId,function(t){u.off.call(o)}),jQuery(document.body).attr("unselectable","on").css("user-select","none").on("selectstart",!1)},off:function(){var e=function(){var t=this.activeModal.offset();t.left+=this.__dx-$(document).scrollLeft(),t.top+=this.__dy-$(document).scrollTop(),this.activeModal.css(t)};this.resizer&&(this.activeModal.removeClass("draged"),this.resizer.remove(),this.resizer=null,this.resizerBg.remove(),this.resizerBg=null,e.call(this)),jQuery(document.body).unbind(a.mousemove+".ax5modal-"+t.id).unbind(a.mouseup+".ax5modal-"+t.id).unbind("mouseleave.ax5modal-"+t.id),jQuery(document.body).removeAttr("unselectable").css("user-select","auto").off("selectstart")}};this.init=function(){this.onStateChanged=t.onStateChanged},this.open=function(e,i){return e=o.modalConfig=jQuery.extend(!0,{},t,e),h.call(this,e,i),this},this.close=function(e){return this.activeModal&&(e=o.modalConfig,this.activeModal.addClass("destroy"),jQuery(window).unbind("keydown.ax-modal"),jQuery(window).unbind("resize.ax-modal"),setTimeout(function(){this.activeModal.remove(),this.activeModal=null,d.call(this,e,{self:this,state:"close"})}.bind(this),t.animateTime)),this},this.minimize=function(){return function(e){var i=o.modalConfig;return"undefined"==typeof e&&(e=t.minimizePosition),this.minimized=!0,this.$.body.hide(),o.modalConfig.originalHeight=i.height,o.modalConfig.height=0,c[e].call(this),d.call(this,i,{self:this,state:"minimize"}),this}}(),this.maximize=function(){var t=o.modalConfig;return this.minimized&&(this.minimized=!1,this.$.body.show(),o.modalConfig.height=o.modalConfig.originalHeight,o.modalConfig.originalHeight=void 0,this.align({left:"center",top:"middle"}),d.call(this,t,{self:this,state:"restore"})),this},this.css=function(t){return this.activeModal&&!o.fullScreen&&(this.activeModal.css(t),t.width&&(o.modalConfig.width=this.activeModal.width()),t.height&&(o.modalConfig.height=this.activeModal.height(),this.$.iframe&&(this.$["iframe-wrap"].css({height:o.modalConfig.height}),this.$.iframe.css({height:o.modalConfig.height})))),this},this.align=function(){return function(t,e){if(!this.activeModal)return this;var i=o.modalConfig,a={width:i.width,height:i.height};return i.fullScreen?(i.header&&this.$.header.hide(),a.width=jQuery(window).width(),a.height=jQuery(window).height(),a.left=0,a.top=0,i.iframe&&(this.$["iframe-wrap"].css({height:a.height}),this.$.iframe.css({height:a.height}))):(t&&jQuery.extend(!0,i.position,t),i.header&&(a.height+=this.$.header.outerHeight()),"left"==i.position.left?a.left=i.position.margin||0:"right"==i.position.left?a.left=jQuery(window).width()-a.width-(i.position.margin||0):"center"==i.position.left?a.left=jQuery(window).width()/2-a.width/2:a.left=i.position.left||0,"top"==i.position.top?a.top=i.position.margin||0:"bottom"==i.position.top?a.top=jQuery(window).height()-a.height-(i.position.margin||0):"middle"==i.position.top?a.top=jQuery(window).height()/2-a.height/2:a.top=i.position.top||0),this.activeModal.css(a),this}}(),this.main=function(){arguments&&i.isObject(arguments[0])&&this.setConfig(arguments[0])}.apply(this,arguments)};t.modal=function(){return i.isFunction(e)&&(o.prototype=new e),o}()}(ax5.ui,ax5.ui.root); \ No newline at end of file diff --git a/src/ax5modal.js b/src/ax5modal.js index 6dc65c0..5e8b154 100755 --- a/src/ax5modal.js +++ b/src/ax5modal.js @@ -4,7 +4,7 @@ /** * @class ax5modal * @alias ax5.ui.modal - * @version 0.5.6 + * @version 0.6.0 * @author tom@axisj.com * @example * ``` @@ -281,8 +281,8 @@ } return { - left: modalOffset.left + self.__dx, - top: modalOffset.top + self.__dy + left: modalOffset.left + self.__dx + $(document).scrollLeft(), + top: modalOffset.top + self.__dy + $(document).scrollTop() }; }; @@ -324,8 +324,8 @@ var setModalPosition = function () { //console.log(this.activeModal.offset(), this.__dx); var box = this.activeModal.offset(); - box.left += this.__dx; - box.top += this.__dy; + box.left += this.__dx - $(document).scrollLeft(); + box.top += this.__dy - $(document).scrollTop(); this.activeModal.css(box); }; diff --git a/test/index.html b/test/index.html index 9e627bd..4a1615f 100644 --- a/test/index.html +++ b/test/index.html @@ -18,6 +18,7 @@ +