/** * * utilities * author: stefan petre www.eyecon.ro * */ (function($) { eye.extend({ getposition : function(e, forceit) { var x = 0; var y = 0; var es = e.style; var restorestyles = false; if (forceit && jquery.curcss(e,'display') == 'none') { var oldvisibility = es.visibility; var oldposition = es.position; restorestyles = true; es.visibility = 'hidden'; es.display = 'block'; es.position = 'absolute'; } var el = e; if (el.getboundingclientrect) { // ie var box = el.getboundingclientrect(); x = box.left + math.max(document.documentelement.scrollleft, document.body.scrollleft) - 2; y = box.top + math.max(document.documentelement.scrolltop, document.body.scrolltop) - 2; } else { x = el.offsetleft; y = el.offsettop; el = el.offsetparent; if (e != el) { while (el) { x += el.offsetleft; y += el.offsettop; el = el.offsetparent; } } if (jquery.browser.safari && jquery.curcss(e, 'position') == 'absolute' ) { x -= document.body.offsetleft; y -= document.body.offsettop; } el = e.parentnode; while (el && el.tagname.touppercase() != 'body' && el.tagname.touppercase() != 'html') { if (jquery.curcss(el, 'display') != 'inline') { x -= el.scrollleft; y -= el.scrolltop; } el = el.parentnode; } } if (restorestyles == true) { es.display = 'none'; es.position = oldposition; es.visibility = oldvisibility; } return {x:x, y:y}; }, getsize : function(e) { var w = parseint(jquery.curcss(e,'width'), 10); var h = parseint(jquery.curcss(e,'height'), 10); var wb = 0; var hb = 0; if (jquery.curcss(e, 'display') != 'none') { wb = e.offsetwidth; hb = e.offsetheight; } else { var es = e.style; var oldvisibility = es.visibility; var oldposition = es.position; es.visibility = 'hidden'; es.display = 'block'; es.position = 'absolute'; wb = e.offsetwidth; hb = e.offsetheight; es.display = 'none'; es.position = oldposition; es.visibility = oldvisibility; } return {w:w, h:h, wb:wb, hb:hb}; }, getclient : function(e) { var h, w; if (e) { w = e.clientwidth; h = e.clientheight; } else { var de = document.documentelement; w = window.innerwidth || self.innerwidth || (de&&de.clientwidth) || document.body.clientwidth; h = window.innerheight || self.innerheight || (de&&de.clientheight) || document.body.clientheight; } return {w:w,h:h}; }, getscroll : function (e) { var t=0, l=0, w=0, h=0, iw=0, ih=0; if (e && e.nodename.tolowercase() != 'body') { t = e.scrolltop; l = e.scrollleft; w = e.scrollwidth; h = e.scrollheight; } else { if (document.documentelement) { t = document.documentelement.scrolltop; l = document.documentelement.scrollleft; w = document.documentelement.scrollwidth; h = document.documentelement.scrollheight; } else if (document.body) { t = document.body.scrolltop; l = document.body.scrollleft; w = document.body.scrollwidth; h = document.body.scrollheight; } if (typeof pageyoffset != 'undefined') { t = pageyoffset; l = pagexoffset; } iw = self.innerwidth||document.documentelement.clientwidth||document.body.clientwidth||0; ih = self.innerheight||document.documentelement.clientheight||document.body.clientheight||0; } return { t: t, l: l, w: w, h: h, iw: iw, ih: ih }; }, getmargins : function(e, tointeger) { var t = jquery.curcss(e,'margintop') || ''; var r = jquery.curcss(e,'marginright') || ''; var b = jquery.curcss(e,'marginbottom') || ''; var l = jquery.curcss(e,'marginleft') || ''; if (tointeger) return { t: parseint(t, 10)||0, r: parseint(r, 10)||0, b: parseint(b, 10)||0, l: parseint(l, 10) }; else return {t: t, r: r, b: b, l: l}; }, getpadding : function(e, tointeger) { var t = jquery.curcss(e,'paddingtop') || ''; var r = jquery.curcss(e,'paddingright') || ''; var b = jquery.curcss(e,'paddingbottom') || ''; var l = jquery.curcss(e,'paddingleft') || ''; if (tointeger) return { t: parseint(t, 10)||0, r: parseint(r, 10)||0, b: parseint(b, 10)||0, l: parseint(l, 10) }; else return {t: t, r: r, b: b, l: l}; }, getborder : function(e, tointeger) { var t = jquery.curcss(e,'bordertopwidth') || ''; var r = jquery.curcss(e,'borderrightwidth') || ''; var b = jquery.curcss(e,'borderbottomwidth') || ''; var l = jquery.curcss(e,'borderleftwidth') || ''; if (tointeger) return { t: parseint(t, 10)||0, r: parseint(r, 10)||0, b: parseint(b, 10)||0, l: parseint(l, 10)||0 }; else return {t: t, r: r, b: b, l: l}; }, traversedom : function(nodeel, func) { func(nodeel); nodeel = nodeel.firstchild; while(nodeel){ eye.traversedom(nodeel, func); nodeel = nodeel.nextsibling; } }, getinnerwidth : function(el, scroll) { var offsetw = el.offsetwidth; return scroll ? math.max(el.scrollwidth,offsetw) - offsetw + el.clientwidth:el.clientwidth; }, getinnerheight : function(el, scroll) { var offseth = el.offsetheight; return scroll ? math.max(el.scrollheight,offseth) - offseth + el.clientheight:el.clientheight; }, getextrawidth : function(el) { if($.boxmodel) return (parseint($.curcss(el, 'paddingleft'))||0) + (parseint($.curcss(el, 'paddingright'))||0) + (parseint($.curcss(el, 'borderleftwidth'))||0) + (parseint($.curcss(el, 'borderrightwidth'))||0); return 0; }, getextraheight : function(el) { if($.boxmodel) return (parseint($.curcss(el, 'paddingtop'))||0) + (parseint($.curcss(el, 'paddingbottom'))||0) + (parseint($.curcss(el, 'bordertopwidth'))||0) + (parseint($.curcss(el, 'borderbottomwidth'))||0); return 0; }, ischildof: function(parentel, el, container) { if (parentel == el) { return true; } if (!el || !el.nodetype || el.nodetype != 1) { return false; } if (parentel.contains && !$.browser.safari) { return parentel.contains(el); } if ( parentel.comparedocumentposition ) { return !!(parentel.comparedocumentposition(el) & 16); } var prel = el.parentnode; while(prel && prel != container) { if (prel == parentel) return true; prel = prel.parentnode; } return false; }, centerel : function(el, axis) { var clientscroll = eye.getscroll(); var size = eye.getsize(el); if (!axis || axis == 'vertically') $(el).css( { top: clientscroll.t + ((math.min(clientscroll.h,clientscroll.ih) - size.hb)/2) + 'px' } ); if (!axis || axis == 'horizontally') $(el).css( { left: clientscroll.l + ((math.min(clientscroll.w,clientscroll.iw) - size.wb)/2) + 'px' } ); } }); if (!$.easing.easeout) { $.easing.easeout = function(p, n, firstnum, delta, duration) { return -delta * ((n=n/duration-1)*n*n*n - 1) + firstnum; }; } })(jquery);