1(function( $, undefined ) { 2 3 /* 4 * HoverDir object. 5 */ 6 $.HoverDir = function( options, element ) { 7 8 this.$el = $( element ); 9 10 this._init( options ); 11 12 }; 13 14 $.HoverDir.defaults = { 15 hoverDelay : 0, 16 reverse : false 17 }; 18 19 $.HoverDir.prototype = { 20 _init : function( options ) { 21 22 this.options = $.extend( true, {}, $.HoverDir.defaults, options ); 23 24 // load the events 25 this._loadEvents(); 26 27 }, 28 _loadEvents : function() { 29 30 var _self = this; 31 32 this.$el.on( 'mouseenter.hoverdir, mouseleave.hoverdir', function( event ) { 33 34 var $el = $(this), 35 evType = event.type, 36 $hoverElem = $el.find( 'article' ), 37 direction = _self._getDir( $el, { x : event.pageX, y : event.pageY } ), 38 hoverClasses= _self._getClasses( direction ); 39 40 $hoverElem.removeClass(); 41 42 if( evType === 'mouseenter' ) { 43 44 $hoverElem.hide().addClass( hoverClasses.from ); 45 46 clearTimeout( _self.tmhover ); 47 48 _self.tmhover = setTimeout( function() { 49 50 $hoverElem.show( 0, function() { 51 $(this).addClass( 'da-animate' ).addClass( hoverClasses.to ); 52 } ); 53 54 55 }, _self.options.hoverDelay ); 56 57 } 58 else { 59 60 $hoverElem.addClass( 'da-animate' ); 61 62 clearTimeout( _self.tmhover ); 63 64 $hoverElem.addClass( hoverClasses.from ); 65 66 } 67 68 } ); 69 70 }, 71 // credits : http://stackoverflow.com/a/3647634 72 _getDir : function( $el, coordinates ) { 73 74 /** the width and height of the current div **/ 75 var w = $el.width(), 76 h = $el.height(), 77 78 /** calculate the x and y to get an angle to the center of the div from that x and y. **/ 79 /** gets the x value relative to the center of the DIV and "normalize" it **/ 80 x = ( coordinates.x - $el.offset().left - ( w/2 )) * ( w > h ? ( h/w ) : 1 ), 81 y = ( coordinates.y - $el.offset().top - ( h/2 )) * ( h > w ? ( w/h ) : 1 ), 82 83 /** the angle and the direction from where the mouse came in/went out clockwise (TRBL=0123);**/ 84 /** first calculate the angle of the point, 85 add 180 deg to get rid of the negative values 86 divide by 90 to get the quadrant 87 add 3 and do a modulo by 4 to shift the quadrants to a proper clockwise TRBL (top/right/bottom/left) **/ 88 direction = Math.round( ( ( ( Math.atan2(y, x) * (180 / Math.PI) ) + 180 ) / 90 ) + 3 ) % 4; 89 90 return direction; 91 92 }, 93 _getClasses : function( direction ) { 94 95 var fromClass, toClass; 96 97 switch( direction ) { 98 case 0: 99 // from top 100 ( !this.options.reverse ) ? fromClass = 'da-slideFromTop' : fromClass = 'da-slideFromBottom'; 101 toClass = 'da-slideTop'; 102 break; 103 case 1: 104 // from right 105 ( !this.options.reverse ) ? fromClass = 'da-slideFromRight' : fromClass = 'da-slideFromLeft'; 106 toClass = 'da-slideLeft'; 107 break; 108 case 2: 109 // from bottom 110 ( !this.options.reverse ) ? fromClass = 'da-slideFromBottom' : fromClass = 'da-slideFromTop'; 111 toClass = 'da-slideTop'; 112 break; 113 case 3: 114 // from left 115 ( !this.options.reverse ) ? fromClass = 'da-slideFromLeft' : fromClass = 'da-slideFromRight'; 116 toClass = 'da-slideLeft'; 117 break; 118 }; 119 120 return { from : fromClass, to: toClass }; 121 122 } 123 }; 124 125 var logError = function( message ) { 126 if ( this.console ) { 127 console.error( message ); 128 } 129 }; 130 131 $.fn.hoverdir = function( options ) { 132 133 if ( typeof options === 'string' ) { 134 135 var args = Array.prototype.slice.call( arguments, 1 ); 136 137 this.each(function() { 138 139 var instance = $.data( this, 'hoverdir' ); 140 141 if ( !instance ) { 142 logError( "cannot call methods on hoverdir prior to initialization; " + 143 "attempted to call method '" + options + "'" ); 144 return; 145 } 146 147 if ( !$.isFunction( instance[options] ) || options.charAt(0) === "_" ) { 148 logError( "no such method '" + options + "' for hoverdir instance" ); 149 return; 150 } 151 152 instance[ options ].apply( instance, args ); 153 154 }); 155 156 } 157 else { 158 159 this.each(function() { 160 161 var instance = $.data( this, 'hoverdir' ); 162 if ( !instance ) { 163 $.data( this, 'hoverdir', new $.HoverDir( options, this ) ); 164 } 165 }); 166 167 } 168 169 return this; 170
171 }; 172 173})( 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.