[Rt-commit] rt branch, 3.9-trunk, updated. rt-3.9.4-437-gbf12c25

Thomas Sibley trs at bestpractical.com
Tue Nov 9 13:17:31 EST 2010


The branch, 3.9-trunk has been updated
       via  bf12c250dc611bd4b1dffa609fa82bab0f55c58e (commit)
      from  4da5d6f89154e0374ff0016cc9873a3d12e51c9d (commit)

Summary of changes:
 etc/RT_Config.pm.in                            |    3 +-
 share/html/NoAuth/js/jquery.event.hover-1.0.js |   85 ++++++++++++++++++
 share/html/NoAuth/js/jquery.hoverIntent.js     |  111 ------------------------
 share/html/NoAuth/js/late.js                   |    2 +
 4 files changed, 89 insertions(+), 112 deletions(-)
 create mode 100644 share/html/NoAuth/js/jquery.event.hover-1.0.js
 delete mode 100644 share/html/NoAuth/js/jquery.hoverIntent.js
 create mode 100644 share/html/NoAuth/js/late.js

- Log -----------------------------------------------------------------
commit bf12c250dc611bd4b1dffa609fa82bab0f55c58e
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Tue Nov 9 13:16:47 2010 -0500

    Replace the Hover Intent plugin with event.special.hover
    
    Supposed to be better and it does seem like it is.

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 002f523..4631c11 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -2150,10 +2150,11 @@ Set(@JSFilesInHead, qw/
     titlebox-state.js
     util.js
     userautocomplete.js
-    jquery.hoverIntent.js
+    jquery.event.hover-1.0.js
     superfish.js
     supersubs.js
     history-folding.js
+    late.js
 /);
 
 =item C<$JSMinPath>
diff --git a/share/html/NoAuth/js/jquery.event.hover-1.0.js b/share/html/NoAuth/js/jquery.event.hover-1.0.js
new file mode 100644
index 0000000..6883ad2
--- /dev/null
+++ b/share/html/NoAuth/js/jquery.event.hover-1.0.js
@@ -0,0 +1,85 @@
+;(function($){ // secure $ jQuery alias
+/*******************************************************************************************/	
+// jquery.event.hover.js - rev 5 
+// Copyright (c) 2008, Three Dub Media (http://threedubmedia.com)
+// Liscensed under the MIT License (MIT-LICENSE.txt)
+// http://www.opensource.org/licenses/mit-license.php
+// Created: 2008-06-02 | Updated: 2008-07-30
+/*******************************************************************************************/
+
+//	USE THESE PROPERTIES TO CUSTOMIZE SETTINGS...
+
+//	$.event.special.hover.delay = 100; 
+//	Defines the delay (msec) while mouse is inside the element before checking the speed
+
+//	$.event.special.hover.speed = 100; 
+//	Defines the maximum speed (px/sec) the mouse may be moving to trigger the hover event
+
+// save the old jquery "hover" method
+$.fn._hover = $.fn.hover;
+
+// jquery method 
+$.fn.hover = function( fn1, fn2, fn3 ) {
+	if ( fn3 ) this.bind('hoverstart', fn1 ); // 3 args
+	if ( fn2 ) this.bind('hoverend', fn3 ? fn3 : fn2 ); // 2+ args
+	return !fn1 ? this.trigger('hover') // 0 args 
+		: this.bind('hover', fn3 ? fn2 : fn1 ); // 1+ args
+	};	
+
+// special event configuration
+var hover = $.event.special.hover = {
+	delay: 100, // milliseconds
+	speed: 100, // pixels per second
+	setup: function( data ){
+		data = $.extend({ speed: hover.speed, delay: hover.delay, hovered:0 }, data||{} );
+		$.event.add( this, "mouseenter mouseleave", hoverHandler, data );
+		},
+	teardown: function(){
+		$.event.remove( this, "mouseenter mouseleave", hoverHandler );
+		}
+	};
+
+// shared event handler
+function hoverHandler( event ){
+	var data = event.data || event;
+	switch ( event.type ){
+		case 'mouseenter': // mouseover
+			data.dist2 = 0; // init mouse distance²
+			data.event = event; // store the event
+			event.type = "hoverstart"; // hijack event
+			if ( $.event.handle.call( this, event ) !== false ){ // handle "hoverstart"
+				data.elem = this; // ref to the current element
+				$.event.add( this, "mousemove", hoverHandler, data ); // track the mouse
+				data.timer = setTimeout( compare, data.delay ); // start async compare
+				}
+			break;
+		case 'mousemove': // track the event, mouse distance² = x² + y²
+			data.dist2 += Math.pow( event.pageX-data.event.pageX, 2 ) 
+				+ Math.pow( event.pageY-data.event.pageY, 2 ); 
+			data.event = event; // store current event
+			break;
+		case 'mouseleave': // mouseout
+			clearTimeout( data.timer ); // uncompare
+			if ( data.hovered ){ 
+				event.type = "hoverend"; // hijack event
+				$.event.handle.call( this, event ); // handle "hoverend"
+				data.hovered--; // reset flag
+				}
+			else $.event.remove( data.elem, "mousemove", hoverHandler ); // untrack
+			break;
+		default: // timeout compare // distance² = x² + y²  = ( speed * time )²
+			if ( data.dist2 <= Math.pow( data.speed*( data.delay/1e3 ), 2 ) ){ // speed acceptable
+				$.event.remove( data.elem, "mousemove", hoverHandler ); // untrack
+				data.event.type = "hover"; // hijack event
+				if ( $.event.handle.call( data.elem, data.event ) !== false ) // handle "hover"
+					data.hovered++; // flag for "hoverend"
+				}
+			else data.timer = setTimeout( compare, data.delay ); // async recurse
+			data.dist2 = 0; // reset distance² for next compare
+			break;
+		}
+	function compare(){ hoverHandler( data ); }; // timeout/recursive function
+	};
+	
+/*******************************************************************************************/
+})(jQuery); // confine scope
\ No newline at end of file
diff --git a/share/html/NoAuth/js/jquery.hoverIntent.js b/share/html/NoAuth/js/jquery.hoverIntent.js
deleted file mode 100644
index bd11442..0000000
--- a/share/html/NoAuth/js/jquery.hoverIntent.js
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
-* hoverIntent is similar to jQuery's built-in "hover" function except that
-* instead of firing the onMouseOver event immediately, hoverIntent checks
-* to see if the user's mouse has slowed down (beneath the sensitivity
-* threshold) before firing the onMouseOver event.
-* 
-* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
-* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
-* 
-* hoverIntent is currently available for use in all personal or commercial 
-* projects under both MIT and GPL licenses. This means that you can choose 
-* the license that best suits your project, and use it accordingly.
-* 
-* // basic usage (just like .hover) receives onMouseOver and onMouseOut functions
-* $("ul li").hoverIntent( showNav , hideNav );
-* 
-* // advanced usage receives configuration object only
-* $("ul li").hoverIntent({
-*	sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
-*	interval: 100,   // number = milliseconds of polling interval
-*	over: showNav,  // function = onMouseOver callback (required)
-*	timeout: 0,   // number = milliseconds delay before onMouseOut function call
-*	out: hideNav    // function = onMouseOut callback (required)
-* });
-* 
-* @param  f  onMouseOver function || An object with configuration options
-* @param  g  onMouseOut function  || Nothing (use configuration options object)
-* @author    Brian Cherne <brian at cherne.net>
-*/
-(function($) {
-	$.fn.hoverIntent = function(f,g) {
-		// default configuration options
-		var cfg = {
-			sensitivity: 7,
-			interval: 100,
-			timeout: 0
-		};
-		// override configuration options with user supplied object
-		cfg = $.extend(cfg, g ? { over: f, out: g } : f );
-
-		// instantiate variables
-		// cX, cY = current X and Y position of mouse, updated by mousemove event
-		// pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
-		var cX, cY, pX, pY;
-
-		// A private function for getting mouse position
-		var track = function(ev) {
-			cX = ev.pageX;
-			cY = ev.pageY;
-		};
-
-		// A private function for comparing current and previous mouse position
-		var compare = function(ev,ob) {
-			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
-			// compare mouse positions to see if they've crossed the threshold
-			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
-				$(ob).unbind("mousemove",track);
-				// set hoverIntent state to true (so mouseOut can be called)
-				ob.hoverIntent_s = 1;
-				return cfg.over.apply(ob,[ev]);
-			} else {
-				// set previous coordinates for next time
-				pX = cX; pY = cY;
-				// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
-				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
-			}
-		};
-
-		// A private function for delaying the mouseOut function
-		var delay = function(ev,ob) {
-			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
-			ob.hoverIntent_s = 0;
-			return cfg.out.apply(ob,[ev]);
-		};
-
-		// A private function for handling mouse 'hovering'
-		var handleHover = function(e) {
-			// next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
-			var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
-			while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
-			if ( p == this ) { return false; }
-
-			// copy objects to be passed into t (required for event object to be passed in IE)
-			var ev = jQuery.extend({},e);
-			var ob = this;
-
-			// cancel hoverIntent timer if it exists
-			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }
-
-			// else e.type == "onmouseover"
-			if (e.type == "mouseover") {
-				// set "previous" X and Y position based on initial entry point
-				pX = ev.pageX; pY = ev.pageY;
-				// update "current" X and Y position based on mousemove
-				$(ob).bind("mousemove",track);
-				// start polling interval (self-calling timeout) to compare mouse coordinates over time
-				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}
-
-			// else e.type == "onmouseout"
-			} else {
-				// unbind expensive mousemove event
-				$(ob).unbind("mousemove",track);
-				// if hoverIntent state is true, then call the mouseOut function after the specified delay
-				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
-			}
-		};
-
-		// bind the function to the two event listeners
-		return this.mouseover(handleHover).mouseout(handleHover);
-	};
-})(jQuery);
\ No newline at end of file
diff --git a/share/html/NoAuth/js/late.js b/share/html/NoAuth/js/late.js
new file mode 100644
index 0000000..1d44e8f
--- /dev/null
+++ b/share/html/NoAuth/js/late.js
@@ -0,0 +1,2 @@
+// Lower the speed limit for hover intent event
+jQuery.event.special.hover.speed = 80; // pixels per second

-----------------------------------------------------------------------


More information about the Rt-commit mailing list