8e8f2ce042bb90aaa7920313225c6da1d3d35dfb
[framework/web/web-ui-fw.git] / libs / js / jquery.ui.position.git+dfe75e1.min.js
1 (function(a,b){a.ui=a.ui||{};var c=/left|center|right/,d=/top|center|bottom/,e=/[+-]\d+%?/,f=/^\w+/,g=/%$/,h="center",i=a.fn.position;a.position={scrollbarWidth:function(){var b,c,d=a("<div style='display:block;width:50px;height:50px;overflow:hidden;'><div style='height:100px;width:auto;'></div></div>"),e=d.children()[0];a("body").append(d);b=e.offsetWidth;d.css("overflow","scroll");c=e.offsetWidth;if(b===c){c=d[0].clientWidth}d.remove();return b-c},getScrollInfo:function(b){var c=b[0]!==window,d=c?b.css("overflow-x"):"",e=c?b.css("overflow-y"):"",f=d==="auto"||d==="scroll"?a.position.scrollbarWidth():0,g=e==="auto"||e==="scroll"?a.position.scrollbarWidth():0;return{height:b.height()<b[0].scrollHeight?g:0,width:b.width()<b[0].scrollWidth?f:0}}};a.fn.position=function(b){if(!b||!b.of){return i.apply(this,arguments)}b=a.extend({},b);var j=a(b.of),k=a(b.within||window),l=j[0],m=(b.collision||"flip").split(" "),n={},o,p,q,r;if(l.nodeType===9){p=j.width();q=j.height();r={top:0,left:0}}else if(a.isWindow(l)){p=j.width();q=j.height();r={top:j.scrollTop(),left:j.scrollLeft()}}else if(l.preventDefault){b.at="left top";p=q=0;r={top:b.of.pageY,left:b.of.pageX}}else{p=j.outerWidth();q=j.outerHeight();r=j.offset()}a.each(["my","at"],function(){var a=(b[this]||"").split(" "),g,i;if(a.length===1){a=c.test(a[0])?a.concat([h]):d.test(a[0])?[h].concat(a):[h,h]}a[0]=c.test(a[0])?a[0]:h;a[1]=d.test(a[1])?a[1]:h;g=e.exec(a[0]);i=e.exec(a[1]);n[this]=[g?g[0]:0,i?i[0]:0];b[this]=[f.exec(a[0])[0],f.exec(a[1])[0]]});if(m.length===1){m[1]=m[0]}if(b.at[0]==="right"){r.left+=p}else if(b.at[0]===h){r.left+=p/2}if(b.at[1]==="bottom"){r.top+=q}else if(b.at[1]===h){r.top+=q/2}o=[parseInt(n.at[0],10)*(g.test(n.at[0])?p/100:1),parseInt(n.at[1],10)*(g.test(n.at[1])?q/100:1)];r.left+=o[0];r.top+=o[1];return this.each(function(){var c=a(this),d=c.outerWidth(),e=c.outerHeight(),f=parseInt(a.curCSS(this,"marginLeft",true))||0,i=parseInt(a.curCSS(this,"marginTop",true))||0,j=a.position.getScrollInfo(k),l=d+f+(parseInt(a.curCSS(this,"marginRight",true))||0)+j.width,s=e+i+(parseInt(a.curCSS(this,"marginBottom",true))||0)+j.height,t=a.extend({},r),u=[parseInt(n.my[0],10)*(g.test(n.my[0])?c.outerWidth()/100:1),parseInt(n.my[1],10)*(g.test(n.my[1])?c.outerHeight()/100:1)],v;if(b.my[0]==="right"){t.left-=d}else if(b.my[0]===h){t.left-=d/2}if(b.my[1]==="bottom"){t.top-=e}else if(b.my[1]===h){t.top-=e/2}t.left+=u[0];t.top+=u[1];v={marginLeft:f,marginTop:i};a.each(["left","top"],function(f,g){if(a.ui.position[m[f]]){a.ui.position[m[f]][g](t,{targetWidth:p,targetHeight:q,elemWidth:d,elemHeight:e,collisionPosition:v,collisionWidth:l,collisionHeight:s,offset:[o[0]+u[0],o[1]+u[1]],my:b.my,at:b.at,within:k,elem:c})}});if(a.fn.bgiframe){c.bgiframe()}c.offset(a.extend(t,{using:b.using}))})};a.ui.position={fit:{left:function(b,c){var d=c.within,e=a(window),f=a.isWindow(c.within[0]),g=f?e.scrollLeft():d.offset().left,h=f?e.width():d.outerWidth(),i=b.left-c.collisionPosition.marginLeft,j=g-i,k=i+c.collisionWidth-h-g,l,m;if(c.collisionWidth>h){if(j>0&&k<=0){l=b.left+j+c.collisionWidth-h-g;b.left+=j-l}else if(k>0&&j<=0){b.left=g}else{if(j>k){b.left=g+h-c.collisionWidth}else{b.left=g}}}else if(j>0){b.left+=j}else if(k>0){b.left-=k}else{b.left=Math.max(b.left-i,b.left)}},top:function(b,c){var d=c.within,e=a(window),f=a.isWindow(c.within[0]),g=f?e.scrollTop():d.offset().top,h=f?e.height():d.outerHeight(),i=b.top-c.collisionPosition.marginTop,j=g-i,k=i+c.collisionHeight-h-g,l,m;if(c.collisionHeight>h){if(j>0&&k<=0){m=b.top+j+c.collisionHeight-h-g;b.top+=j-m}else if(k>0&&j<=0){b.top=g}else{if(j>k){b.top=g+h-c.collisionHeight}else{b.top=g}}}else if(j>0){b.top+=j}else if(k>0){b.top-=k}else{b.top=Math.max(b.top-i,b.top)}}},flip:{left:function(b,c){if(c.at[0]===h){return}c.elem.removeClass("ui-flipped-left ui-flipped-right");var d=c.within,e=a(window),f=a.isWindow(c.within[0]),g=(f?0:d.offset().left)+d.scrollLeft(),i=f?d.width():d.outerWidth(),j=b.left-c.collisionPosition.marginLeft,k=j-g,l=j+c.collisionWidth-i-g,m=c.my[0]==="left",n=c.my[0]==="left"?-c.elemWidth:c.my[0]==="right"?c.elemWidth:0,o=c.at[0]==="left"?c.targetWidth:-c.targetWidth,p=-2*c.offset[0],q,r;if(k<0){q=b.left+n+o+p+c.collisionWidth-i-g;if(q<0||q<Math.abs(k)){c.elem.addClass("ui-flipped-right");b.left+=n+o+p}}else if(l>0){r=b.left-c.collisionPosition.marginLeft+n+o+p-g;if(r>0||Math.abs(r)<l){c.elem.addClass("ui-flipped-left");b.left+=n+o+p}}},top:function(b,c){if(c.at[1]===h){return}c.elem.removeClass("ui-flipped-top ui-flipped-bottom");var d=c.within,e=a(window),f=a.isWindow(c.within[0]),g=(f?0:d.offset().top)+d.scrollTop(),i=f?d.height():d.outerHeight(),j=b.top-c.collisionPosition.marginTop,k=j-g,l=j+c.collisionHeight-i-g,m=c.my[1]==="top",n=m?-c.elemHeight:c.my[1]==="bottom"?c.elemHeight:0,o=c.at[1]==="top"?c.targetHeight:-c.targetHeight,p=-2*c.offset[1],q,r;if(k<0){r=b.top+n+o+p+c.collisionHeight-i-g;if(r<0||r<Math.abs(k)){c.elem.addClass("ui-flipped-bottom");b.top+=n+o+p}}else if(l>0){q=b.top-c.collisionPosition.marginTop+n+o+p-g;if(q>0||Math.abs(q)<l){c.elem.addClass("ui-flipped-top");b.top+=n+o+p}}}},flipfit:{left:function(){a.ui.position.flip.left.apply(this,arguments);a.ui.position.fit.left.apply(this,arguments)},top:function(){a.ui.position.flip.top.apply(this,arguments);a.ui.position.fit.top.apply(this,arguments)}}};if(a.uiBackCompat!==false){(function(a){var c=a.fn.position;a.fn.position=function(d){if(!d||!d.offset){return c.call(this,d)}var e=d.offset.split(" "),f=d.at.split(" ");if(e.length===1){e[1]=e[0]}if(/^\d/.test(e[0])){e[0]="+"+e[0]}if(/^\d/.test(e[1])){e[1]="+"+e[1]}if(f.length===1){if(/left|center|right/.test(f[0])){f[1]="center"}else{f[1]=f[0];f[0]="center"}}return c.call(this,a.extend(d,{at:f[0]+e[0]+" "+f[1]+e[1],offset:b}))}})(jQuery)}})(jQuery)