1 2(function($){ 3/*---------------------------------------------------------------------------------- 4Class: FloatObject 5-------------------------------------------------------------------------------------*/ 6 function FloatObject(jqObj, params) 7 { 8 this.jqObj = jqObj; 9 10 switch(params.speed) 11 { 12 case 'fast': this.steps = 5; break; 13 case 'normal': this.steps = 10; break; 14 case 'slow': this.steps = 20; break; 15 default: this.steps = 10; 16 }; 17 18 var offset = this.jqObj.offset(); 19 20 this.currentX = offset.left; 21 this.currentY = offset.top; 22 23 24 this.origX = typeof(params.x) == "string" ? this.currentX : params.x; 25 this.origY = typeof(params.y) == "string" ? this.currentY : params.y; 26 //if( params.y) this.origY = params.y; 27 28 29 //now we make sure the object is in absolute positions. 30 this.jqObj.css({'position':'absolute' , 'top':this.currentY ,'left':this.currentX}); 31 } 32 33 FloatObject.prototype.updateLocation = function() 34 { 35 this.updatedX = $(window).scrollLeft() + this.origX; 36 this.updatedY = $(window).scrollTop()+ this.origY; 37 38 this.dx = Math.abs(this.updatedX - this.currentX );
39 this.dy = Math.abs(this.updatedY - this.currentY ); 40 41 return this.dx || this.dy; 42 } 43 44 FloatObject.prototype.move = function() 45 { 46 if( this.jqObj.css("position") != "absolute" ) return; 47 var cx = 0; 48 var cy = 0; 49 50 if( this.dx > 0 ) 51 { 52 if( this.dx < this.steps / 2 ) 53 cx = (this.dx >= 1) ? 1 : 0; 54 else 55 cx = Math.round(this.dx/this.steps); 56 57 if( this.currentX < this.updatedX ) 58 this.currentX += cx; 59 else 60 this.currentX -= cx; 61 } 62 63 if( this.dy > 0 ) 64 { 65 if( this.dy < this.steps / 2 ) 66 cy = (this.dy >= 1) ? 1 : 0; 67 else 68 cy = Math.round(this.dy/this.steps); 69 70 if( this.currentY < this.updatedY ) 71 this.currentY += cy; 72 else 73 this.currentY -= cy; 74 } 75 76 this.jqObj.css({'left':this.currentX, 'top': this.currentY }); 77 } 78 79 80 81/*---------------------------------------------------------------------------------- 82Object: floatMgr 83-------------------------------------------------------------------------------------*/ 84 $.floatMgr = { 85 86 FOArray: new Array() , 87 88 timer: null , 89 90 initializeFO: function(jqObj,params) 91 { 92 var settings = $.extend({ 93 x: 0 , 94 y: 0 , 95 speed: 'normal' },params||{}); 96 var newFO = new FloatObject(jqObj,settings); 97 98 $.floatMgr.FOArray.push(newFO); 99 100 if( !$.floatMgr.timer ) $.floatMgr.adjustFO(); 101 102 //now making sure we are registered to all required window events 103 if( !$.floatMgr.registeredEvents ) 104 { 105 $(window).bind("resize", $.floatMgr.onChange); 106 $(window).bind("scroll", $.floatMgr.onChange); 107 $.floatMgr.registeredEvents = true; 108 } 109 } , 110 111 adjustFO: function() 112 { 113 $.floatMgr.timer = null; 114 115 var moveFO = false; 116 117 for( var i = 0 ; i < $.floatMgr.FOArray.length ; i++ ) 118 { 119 FO = $.floatMgr.FOArray[i]; 120 if( FO.updateLocation() ) moveFO = true; 121 } 122 123 if( moveFO ) 124 { 125 for( var i = 0 ; i < $.floatMgr.FOArray.length ; i++ ) 126 { 127 FO = $.floatMgr.FOArray[i]; 128 FO.move(); 129 } 130 131 if( !$.floatMgr.timer ) $.floatMgr.timer = setTimeout($.floatMgr.adjustFO,50); 132 } 133 } , 134 135 onChange: function() 136 { 137 if( !$.floatMgr.timer ) $.floatMgr.adjustFO(); 138 } 139 }; 140 141/*---------------------------------------------------------------------------------- 142Function: makeFloat 143-------------------------------------------------------------------------------------*/ 144 $.fn.makeFloat = function(params) { 145 var obj = this.eq(0); //we only operate on the first selected object; 146 $.floatMgr.initializeFO(obj,params); 147 if( $.floatMgr.timer == null ) $.floatMgr.adjustFO(); 148 return obj; 149 }; 150})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.