skylark-utils
Version:
An Elegant HTML5 JavaScript Library.
10 lines (9 loc) • 4.8 kB
JavaScript
/**
* skylark-utils - An Elegant HTML5 JavaScript Library.
* @author Hudaokeji Co.,Ltd
* @version v0.9.3
* @link www.skylarkjs.org
* @license MIT
*/
define(["./skylark","./langx","./noder","./datax","./geom","./eventer","./styler"],function(e,t,o,r,n,a,i){function h(e,t,r,a){var i=o.ownerDoc(e),h=o.ownerWindow(i),d=n.size(h);d.left=0,d.top=0,e.parentNode&&"body"==String(e.parentNode.tagName).toLowerCase()||i.body.appendChild(e);var s=null;return u.apply(t,function(t){var o=t.corner,i=t.pos,h=0,c={w:{L:d.left+d.width-i.x,R:i.x-d.left,M:d.width}[o.charAt(1)],h:{T:d.top+d.height-i.y,B:i.y-d.top,M:d.height}[o.charAt(0)]};if(r){var l=r(e,t.aroundCorner,o,c,a);h="undefined"==typeof l?0:l}var u=n.size(e),f={L:i.x,R:i.x-u.width,M:Math.max(d.left,Math.min(d.left+d.width,i.x+(u.width>>1))-u.width)}[o.charAt(1)],m={T:i.y,B:i.y-u.height,M:Math.max(d.top,Math.min(d.top+d.height,i.y+(u.height>>1))-u.height)}[o.charAt(0)],p=Math.max(d.left,f),v=Math.max(d.top,m),y=Math.min(d.left+d.width,f+u.width),g=Math.min(d.top+d.height,m+u.height),w=y-p,x=g-v;return h+=u.width-w+(u.height-x),(null==s||h<s.overflow)&&(s={corner:o,aroundCorner:t.aroundCorner,left:p,top:v,width:w,height:x,overflow:h,spaceAvailable:c}),!h}),s.overflow&&r&&r(e,s.aroundCorner,s.corner,s.spaceAvailable,a),n.boundingPosition(e,s),s}function d(e,t,o,r,n){var a=f.apply(o,function(e){var o={corner:e,aroundCorner:reverse[e],pos:{x:t.x,y:t.y}};return r&&(o.pos.x+="L"==e.charAt(1)?r.x:-r.x,o.pos.y+="T"==e.charAt(0)?r.y:-r.y),o});return h(e,a,n)}function s(e,t,o,r,n){function a(e,t){M.push({aroundCorner:e,corner:t,pos:{x:{L:g,R:g+x,M:g+(x>>1)}[e.charAt(1)],y:{T:w,B:w+b,M:w+(b>>1)}[e.charAt(0)]}})}var i;if("string"==typeof t||"offsetWidth"in t||"ownerSVGElement"in t){if(i=domGeometry.position(t,!0),/^(above|below)/.test(o[0])){var d=domGeometry.getBorderExtents(t),s=t.firstChild?domGeometry.getBorderExtents(t.firstChild):{t:0,l:0,b:0,r:0},c=domGeometry.getBorderExtents(e),l=e.firstChild?domGeometry.getBorderExtents(e.firstChild):{t:0,l:0,b:0,r:0};i.y+=Math.min(d.t+s.t,c.t+l.t),i.h-=Math.min(d.t+s.t,c.t+l.t)+Math.min(d.b+s.b,c.b+l.b)}}else i=t;if(t.parentNode)for(var u="absolute"==domStyle.getComputedStyle(t).position,f=t.parentNode;f&&1==f.nodeType&&"BODY"!=f.nodeName;){var m=domGeometry.position(f,!0),p=domStyle.getComputedStyle(f);if(/relative|absolute/.test(p.position)&&(u=!1),!u&&/hidden|auto|scroll/.test(p.overflow)){var v=Math.min(i.y+i.h,m.y+m.h),y=Math.min(i.x+i.w,m.x+m.w);i.x=Math.max(i.x,m.x),i.y=Math.max(i.y,m.y),i.h=v-i.y,i.w=y-i.x}"absolute"==p.position&&(u=!0),f=f.parentNode}var g=i.x,w=i.y,x="w"in i?i.w:i.w=i.width,b="h"in i?i.h:(kernel.deprecated("place.around: dijit/place.__Rectangle: { x:"+g+", y:"+w+", height:"+i.height+", width:"+x+" } has been deprecated. Please use { x:"+g+", y:"+w+", h:"+i.height+", w:"+x+" }","","2.0"),i.h=i.height),M=[];array.forEach(o,function(e){var t=r;switch(e){case"above-centered":a("TM","BM");break;case"below-centered":a("BM","TM");break;case"after-centered":t=!t;case"before-centered":a(t?"ML":"MR",t?"MR":"ML");break;case"after":t=!t;case"before":a(t?"TL":"TR",t?"TR":"TL"),a(t?"BL":"BR",t?"BR":"BL");break;case"below-alt":t=!t;case"below":a(t?"BL":"BR",t?"TL":"TR"),a(t?"BR":"BL",t?"TR":"TL");break;case"above-alt":t=!t;case"above":a(t?"TL":"TR",t?"BL":"BR"),a(t?"TR":"TL",t?"BR":"BL");break;default:a(e.aroundCorner,e.corner)}});var B=h(e,M,n,{w:x,h:b});return B.aroundNodePos=i,B}function c(e,t){function r(e){var t,o;if(e.changedTouches)for(t="screenX screenY pageX pageY clientX clientY".split(" "),o=0;o<t.length;o++)e[t[o]]=e.changedTouches[0][t[o]]}t=t||{};var h,d,s,c,l,u,f,m,p=t.handle||e,v=t.constraints,y=t.document||document,g=t.started,w=t.moving,x=t.stopped,s=function(t){var s,v=n.getDocumentSize(y);r(t),t.preventDefault(),d=t.button,l=t.screenX,u=t.screenY,f=n.relativePosition(e),m=n.size(e),s=i.css(p,"curosr"),h=o.createElement("div"),i.css(h,{position:"absolute",top:0,left:0,width:v.width,height:v.height,zIndex:2147483647,opacity:1e-4,cursor:s}),o.append(y.body,h),a.on(y,"mousemove touchmove",b).on(y,"mouseup touchend",c),g&&g(t)},b=function(t){if(r(t),0!==t.button)return c(t);t.deltaX=t.screenX-l,t.deltaY=t.screenY-u;var o=f.left+t.deltaX,a=f.top+t.deltaY;v&&(o<v.minX&&(o=v.minX),o>v.maxX&&(o=v.maxX),a<v.minY&&(a=v.minY),a>v.maxY&&(a=v.maxY)),n.relativePosition(e,{left:o,top:a}),t.preventDefault(),w&&w(t)},c=function(e){r(e),a.off(y,"mousemove touchmove",b).off(y,"mouseup touchend",c),o.remove(h),x&&x(e)};return a.on(p,"mousedown touchstart",s),{remove:function(){a.off(p)}}}function l(){return l}var u=(a.on,a.off,r.attr,r.removeAttr,n.pagePosition,i.addClass,n.height,Array.prototype.some),f=Array.prototype.map;return t.mixin(l,{around:s,at:d,movable:c}),e.mover=l});
//# sourceMappingURL=sourcemaps/mover.js.map