1/* global jQuery */ 2 3(function() { 4 5 "use strict"; 6 7 var requestAnimationFrame = trx_addons_request_animation_frame(); 8 9 var mouseX = null, mouseY = null, 10 realX = null, realY = null, 11 destX = [0,0,0,0,0,0,0,0,0,0], // Allow up to 10 helper parts to move 12 destY = [0,0,0,0,0,0,0,0,0,0]; 13 14 var mouse_helper_timeout = 0, 15 mouse_helper_target = null, 16 mouse_helper_last_target = null, 17 mouse_helper_action = '', 18 mouse_helper_last_action = '', 19 mouse_helper_callback = '', 20 mouse_helper_axis = 'xy', 21 mouse_helper_delay = 1, 22 mouse_helper_smooth = true; 23 24 var mouse_helper_original_styles = [ {}, {}, {}, {}, {}, {}, {}, {}, {}, {} ]; 25 26 var $window = jQuery( window ), 27 $document = jQuery( document ), 28 $body = jQuery( 'body' ), 29 $mouse_helper = jQuery('.trx_addons_mouse_helper'); 30 31 if ( $mouse_helper.eq(0).hasClass( 'trx_addons_mouse_helper_smooth' ) ) { 32 mouse_helper_smooth = true; 33 } 34 35 var $mouse_helper_targets, 36 $mouse_helper_magnets; 37 38 // Update links and values after the new post added 39 $document.on( 'action.got_ajax_response', update_jquery_links ); 40 $document.on( 'action.init_hidden_elements', update_jquery_links ); 41 var first_run = true; 42 function update_jquery_links(e) { 43 if ( first_run && e && e.namespace == 'init_hidden_elements' ) { 44 first_run = false; 45 return; 46 } 47 $mouse_helper_targets = jQuery('[data-mouse-helper]'); 48 $mouse_helper_magnets = jQuery('[data-mouse-helper-magnet]:not([data-mouse-helper-magnet="0"])'); 49 } 50 update_jquery_links(); 51 52 53 // Init Mouse helper 54 $document.on('action.init_trx_addons', function() { 55 56 if ( TRX_ADDONS_STORAGE['mouse_helper'] > 0 && $mouse_helper.length > 0 && requestAnimationFrame ) { 57 58 $mouse_helper.each( function( idx ) { 59 mouse_helper_original_styles[ idx ] = { 60 blend_mode: $mouse_helper.eq(idx).css( 'mix-blend-mode' ), 61 color: $mouse_helper.eq(idx).css( 'color' ), 62 bg_color: $mouse_helper.eq(idx).css( 'background-color' ), 63 bd_color: $mouse_helper.eq(idx).css( 'border-color' ), 64 bd_width: $mouse_helper.eq(idx).css( 'border-width' ), 65 bd_style: $mouse_helper.eq(idx).css( 'border-style' ) 66 }; 67 } ); 68 69 mouse_helper_delay = TRX_ADDONS_STORAGE['mouse_helper_delay']; 70 71 var pointermove_allowed = false; 72 73 $document 74 .on( 'mousemove pointermove', function(e) { 75 if ( e.originalEvent.type == 'pointermove' ) { 76 pointermove_allowed = true; 77 } 78 if ( e.originalEvent.type == 'mousemove' && pointermove_allowed ) { 79 return; 80 } 81 trx_addons_mouse_helper_get_state(e); 82 if ( mouse_helper_callback && typeof window[mouse_helper_callback] == 'function' ) { 83 window[mouse_helper_callback]( 'mousemove', $mouse_helper, mouse_helper_target, e ); 84 } else if ( typeof window['trx_addons_mouse_helper_callback_' + mouse_helper_action] == 'function' ) { 85 window['trx_addons_mouse_helper_callback_' + mouse_helper_action]( 'mousemove', $mouse_helper, mouse_helper_target, e ); 86 } 87 if ( mouse_helper_action == 'highlight' && mouse_helper_target ) { 88 var targetOffset = mouse_helper_target.offset(), 89 targetX = targetOffset.left - trx_addons_window_scroll_left(), 90 targetY = targetOffset.top - trx_addons_window_scroll_top(), 91 size = parseFloat( mouse_helper_target.css('background-size').split(' ')[0] ) / 2; 92 mouse_helper_target.css( 'background-position', ( mouseX - targetX - size) + 'px ' + ( mouseY - targetY - size ) + 'px' ); 93 } 94 if ( trx_addons_window_width() >= TRX_ADDONS_STORAGE['mobile_breakpoint_mousehelper_off'] ) { 95 if ( mouse_helper_delay < 2 ) { 96 destX.fill( mouseX ); 97 destY.fill( mouseY ); 98 $mouse_helper.css("transform", "translate(" + destX[0] + "px," + destY[0] + "px)"); 99 } 100 if ( mouseX > trx_addons_window_width() - 100 ) { 101 if ( ! $mouse_helper.hasClass( 'trx_addons_mouse_helper_left' ) ) { 102 $mouse_helper.addClass( 'trx_addons_mouse_helper_left' ); 103 } 104 } else { 105 if ( $mouse_helper.hasClass( 'trx_addons_mouse_helper_left' ) ) { 106 $mouse_helper.removeClass( 'trx_addons_mouse_helper_left' ); 107 } 108 } 109 if ( mouseY > trx_addons_window_height() - 100 ) { 110 if ( ! $mouse_helper.hasClass( 'trx_addons_mouse_helper_top' ) ) { 111 $mouse_helper.addClass( 'trx_addons_mouse_helper_top' ); 112 } 113 } else { 114 if ( $mouse_helper.hasClass( 'trx_addons_mouse_helper_top' ) ) { 115 $mouse_helper.removeClass( 'trx_addons_mouse_helper_top' ); 116 } 117 } 118 // Check magnets 119 trx_addons_mouse_helper_check_magnets(); 120 } 121 } ) 122 123 .on( "mouseenter", '[data-mouse-helper]', function(e) { 124 e.stopPropagation(); 125 var $self = jQuery(this).addClass('trx_addons_mouse_helper_over'); 126 // Set new target 127 mouse_helper_target = mouse_helper_last_target = $self; 128 mouse_helper_action = mouse_helper_last_action = $self.data( 'mouse-helper' ); 129 if ( trx_addons_window_width() >= TRX_ADDONS_STORAGE['mobile_breakpoint_mousehelper_off'] ) { 130 mouse_helper_reset(); 131 if ( mouse_helper_timeout ) { 132 clearTimeout( mouse_helper_timeout ); 133 mouse_helper_timeout = 0; 134 } 135 } 136 mouse_helper_callback = $self.data( 'mouse-helper-callback' ); 137 if ( mouse_helper_callback === undefined ) { 138 mouse_helper_callback = ''; 139 } 140 if ( mouse_helper_callback && typeof window[mouse_helper_callback] == 'function' ) { 141 window[mouse_helper_callback]( 'mouseenter', $mouse_helper, $self, e ); 142 } else if ( typeof window['trx_addons_mouse_helper_callback_' + mouse_helper_action] == 'function' ) { 143 window['trx_addons_mouse_helper_callback_' + mouse_helper_action]( 'mouseenter', $mouse_helper, $self, e ); 144 } 145 mouse_helper_axis = $self.data( 'mouse-helper-axis' ); 146 if ( mouse_helper_axis === undefined ) { 147 mouse_helper_axis = 'xy'; 148 } 149 mouse_helper_delay = $self.data( 'mouse-helper-delay' ); 150 if ( mouse_helper_delay === undefined ) { 151 mouse_helper_delay = TRX_ADDONS_STORAGE['mouse_helper_delay']; 152 } 153 154 trx_addons_mouse_helper_get_state(e); 155 156 if ( trx_addons_window_width() >= TRX_ADDONS_STORAGE['mobile_breakpoint_mousehelper_off'] ) { 157 // Add a custom class to the helper 158 var classes = $self.data("mouse-helper-class") || ''; 159 if ( classes ) { 160 $mouse_helper.addClass( classes ); 161 } 162 // Hide helper 163 var hide = $self.data("mouse-helper-hide-helper") || ''; 164 if ( hide ) { 165 $mouse_helper.addClass( 'trx_addons_mouse_helper_hide' ); 166 } 167 // Centered 168 var pos = ( TRX_ADDONS_STORAGE['mouse_helper_centered'] > 0 && ( $self.data("mouse-helper-centered") === undefined || $self.data("mouse-helper-centered") === '' ) ) 169 || $self.data("mouse-helper-centered") > 0 170 || ''; 171 $mouse_helper.toggleClass( 'trx_addons_mouse_helper_centered', pos > 0 ); 172 // Overlay mode 173 var mode = $self.data("mouse-helper-mode") || ''; 174 if ( mode ) { 175 $mouse_helper.css( 'mix-blend-mode', mode ); 176 } 177 // Text color 178 var color = $self.data("mouse-helper-color") || ''; 179 if ( color ) { 180 $mouse_helper.css( 'color', color ); 181 }
182 // Background color 183 var bg_color = $self.data("mouse-helper-bg-color") || ''; 184 if ( bg_color ) { 185 $mouse_helper.css( 'background-color', bg_color ); 186 } 187 // Border color 188 var bd_color = $self.data("mouse-helper-bd-color") || ''; 189 if ( bd_color ) { 190 $mouse_helper.css( 'border-color', bd_color ); 191 } 192 // Border width 193 var bd_width = $self.data("mouse-helper-bd-width"); 194 if ( bd_width === undefined ) { 195 bd_width = ''; 196 } 197 if ( bd_width !== '' && bd_width >= 0 ) { 198 $mouse_helper.css( { 199 'border-width': bd_width + 'px', 200 'border-style': bd_width > 0 ? 'solid' : 'none' 201 } ); 202 } 203 // Add image 204 var img = $self.data("mouse-helper-image") || ''; 205 if ( img ) { 206 $mouse_helper.eq(0) 207 .find('.trx_addons_mouse_helper_image').remove(); 208 $mouse_helper.eq(0) 209 .append( '<span class="trx_addons_mouse_helper_image" style="background-image:url(' + img + ');"></span>' ) 210 .addClass( "trx_addons_mouse_helper_with_image"); 211 } 212 // Add icon 213 var icon = $self.data("mouse-helper-icon") || ''; 214 if ( icon && icon != 'none' ) { 215 var icon_color = $self.data("mouse-helper-icon-color") || '', 216 icon_size = $self.data("mouse-helper-icon-size") || ''; 217 $mouse_helper.eq(0) 218 .find('.trx_addons_mouse_helper_icon').remove().end() 219 .append( '<span class="trx_addons_mouse_helper_icon ' + icon + '"' 220 + ' style="' 221 + ( icon_color ? 'color: ' + icon_color + ';' : '' ) 222 + ( icon_size ? 'font-size: ' + icon_size + 'em;' : '' ) 223 + '"' 224 +'></span>' ) 225 .addClass( 'trx_addons_mouse_helper_with_icon' ); 226 } 227 // Add text 228 var text = $self.data("mouse-helper-text") || '', 229 text_round = $self.data("mouse-helper-text-round") > 0 || false, 230 text_size = $self.data("mouse-helper-text-size") || ''; 231 if ( text ) { 232 $mouse_helper.eq(0) 233 .find('.trx_addons_mouse_helper_text').remove().end() 234 .append( '<span class="trx_addons_mouse_helper_text' + ( text_round ? ' trx_addons_mouse_helper_text_round' : '' ) + '"' 235 + ( text_size ? ' style="font-size:' + text_size + 'em;"' : '' ) 236 + '>' 237 + ( text_round ? trx_addons_wrap_chars( text, '<span class="trx_addons_mouse_helper_text_round_item">', '</span>' ) : text ) 238 + '</span>' ) 239 .addClass( 'trx_addons_mouse_helper_with_text' + ( text_round ? ' trx_addons_mouse_helper_with_text_round' : '' ) ); 240 if ( text_round ) { 241 var rtl = $body.hasClass( 'rtl' ); 242 setTimeout( function() { 243 var text_wrap = $mouse_helper.eq(0).find( '.trx_addons_mouse_helper_text' ), 244 items = text_wrap.find( '.trx_addons_mouse_helper_text_round_item' ); 245 if ( items.length > 0) {
246 var r = Math.ceil( text_wrap.width() / 2 ), 247 a = 0, 248 hide = false; 249 items.each( function( idx ) { 250 if ( hide ) { 251 items.eq( idx ).hide(); 252 } else { 253 if ( a >= ( rtl ? 310 : 330 ) ) { // If fill whole round - hide rest chars and replace its with '...' 254 items.eq( idx ).html('…'); 255 hide = true; 256 } 257 var x = r + r * Math.sin( a / 180 * Math.PI ), 258 y = r - r * Math.cos( a / 180 * Math.PI ), 259 css = { 260 'transform': 'rotate(' + ( rtl ? -a : a ) + 'deg)', 261 'top': y + 'px' 262 }; 263 if ( rtl ) { 264 css.right = x + 'px'; 265 } else { 266 css.left = x + 'px'; 267 } 268 items.eq( idx ).css( css ); 269 a += 2 * Math.asin( ( items.eq( idx ).width() + ( rtl ? 3 : 3 ) ) / ( 2 * r ) ) * 180 / Math.PI; 270 } 271 } ); 272 } 273 }, 350); 274 } 275 } 276 // Add custom HTML code 277 var layout = $self.data("mouse-helper-layout") || ''; 278 if ( layout ) { 279 $mouse_helper.eq(0) 280 .find('.trx_addons_mouse_helper_layout').remove().end() 281 .append( '<span class="trx_addons_mouse_helper_layout">' + layout + '</span>' ) 282 .addClass( 'trx_addons_mouse_helper_with_layout' ); 283 } 284 // Add class to the mouse helper with type of the target 285 var obj_type = $self.data( 'element_type' ) || ''; 286 if ( obj_type === 'widget' ) { 287 obj_type = $self.data( 'widget_type' ) || ''; 288 } 289 if ( obj_type === '' ) { 290 if ( $self.hasClass( 'slider_container' ) ) { 291 obj_type = 'slider'; 292 } 293 } else { 294 obj_type = obj_type.split('.')[0]; 295 } 296 if ( obj_type !== '' ) { 297 $mouse_helper.eq(0).addClass( 'trx_addons_mouse_helper_over_element_' + obj_type ); 298 } 299 // Set 'active' and 'action' classes 300 $mouse_helper.addClass( "trx_addons_mouse_helper_active trx_addons_mouse_helper_action_" + mouse_helper_action); 301 } 302 } ) 303 304 .on( "mouseleave", '[data-mouse-helper]', function(e) { 305 e.stopPropagation(); 306 if ( mouse_helper_callback && typeof window[mouse_helper_callback] == 'function' ) { 307 window[mouse_helper_callback]( 'mouseleave', $mouse_helper, mouse_helper_target, e ); 308 mouse_helper_callback = ''; 309 } else if ( typeof window['trx_addons_mouse_helper_callback_' + mouse_helper_action] == 'function' ) { 310 window['trx_addons_mouse_helper_callback_' + mouse_helper_action]( 'mouseleave', $mouse_helper, mouse_helper_target, e ); 311 } 312 $mouse_helper.removeClass( 'trx_addons_mouse_helper_click' 313 + ' trx_addons_mouse_helper_action_' + mouse_helper_action 314 ); 315 if ( mouse_helper_target ) { 316 mouse_helper_target.removeClass('trx_addons_mouse_helper_over'); 317 // Remove a custom class from the helper 318 var classes = mouse_helper_target.data("mouse-helper-class") || ''; 319 if ( classes ) { 320 $mouse_helper.removeClass( classes ); 321 } 322 } 323 mouse_helper_target = null; 324 mouse_helper_action = ''; 325 mouse_helper_axis = 'xy'; 326 mouse_helper_delay = TRX_ADDONS_STORAGE['mouse_helper_delay']; 327 if ( trx_addons_window_width() >= TRX_ADDONS_STORAGE['mobile_breakpoint_mousehelper_off'] ) { 328 mouse_helper_timeout = setTimeout( function() { 329 mouse_helper_reset(); 330 }, mouse_helper_smooth ? 10 : 0 ); //300 331 } 332 if ( e.relatedTarget ) { 333 var newTarget = jQuery(e.relatedTarget); 334 if ( ! newTarget.data('mouse-helper') ) { 335 newTarget = newTarget.parents('[data-mouse-helper]').eq(0); 336 } 337 if ( newTarget.length > 0 && newTarget.data('mouse-helper') ) { 338 setTimeout( function() { 339 newTarget.trigger('mouseenter'); 340 }, 0 ); 341 } 342 } 343 } ) 344 345 .on( "mousedown swiper_touch_start", '[data-mouse-helper]', function(e) { 346 var $self = jQuery(this); 347 $mouse_helper.addClass('trx_addons_mouse_helper_click'); 348 mouse_helper_callback = $self.data( 'mouse-helper-callback' ); 349 if ( mouse_helper_callback === undefined ) { 350 mouse_helper_callback = ''; 351 } 352 if ( mouse_helper_callback && typeof window[mouse_helper_callback] == 'function' ) { 353 window[mouse_helper_callback]( 'mousedown', $mouse_helper, $self, e ); 354 } else if ( typeof window['trx_addons_mouse_helper_callback_' + mouse_helper_action] == 'function' ) { 355 window['trx_addons_mouse_helper_callback_' + mouse_helper_action]( 'mousedown', $mouse_helper, $self, e ); 356 } 357 } ) 358 359 .on( "mouseup swiper_touch_end", '[data-mouse-helper]', function(e) { 360 var $self = jQuery(this); 361 $mouse_helper.removeClass('trx_addons_mouse_helper_click'); 362 mouse_helper_callback = $self.data( 'mouse-helper-callback' ); 363 if ( mouse_helper_callback === undefined ) { 364 mouse_helper_callback = ''; 365 } 366 if ( mouse_helper_callback && typeof window[mouse_helper_callback] == 'function' ) { 367 window[mouse_helper_callback]( 'mouseup', $mouse_helper, $self, e ); 368 } else if ( typeof window['trx_addons_mouse_helper_callback_' + mouse_helper_action] == 'function' ) { 369 window['trx_addons_mouse_helper_callback_' + mouse_helper_action]( 'mouseup', $mouse_helper, $self, e ); 370 } 371 } ); 372 373 var mouse_helper_links = trx_addons_apply_filters( 374 'trx_addons_filter_mouse_helper_links', 375 'a,button,input[type="button"],input[type="submit"],input[type="reset"]' 376 ); 377 $document
378 .on( "mouseenter", mouse_helper_links, function(e) { 379 $mouse_helper.addClass( "trx_addons_mouse_helper_over_link" ); 380 381 } ) 382 .on( "mouseleave", mouse_helper_links, function(e) { 383 $mouse_helper.removeClass( "trx_addons_mouse_helper_over_link" ); 384 } ); 385 386 var mouse_helper_reset = function() { 387 $mouse_helper.eq(0).addClass('trx_addons_mouse_helper_reset'); 388 setTimeout( function() { 389 $mouse_helper.eq(0).removeClass('trx_addons_mouse_helper_reset'); 390 }, $mouse_helper.eq(0).hasClass( 'trx_addons_mouse_helper_with_icon' ) 391 || $mouse_helper.eq(0).hasClass( 'trx_addons_mouse_helper_with_text' ) 392 || $mouse_helper.eq(0).hasClass( 'trx_addons_mouse_helper_with_image' ) 393 || $mouse_helper.eq(0).hasClass( 'trx_addons_mouse_helper_with_layout' ) 394 || ( mouse_helper_target && ( 395 mouse_helper_target.data( 'mouse-helper-icon' ) 396 || mouse_helper_target.data( 'mouse-helper-text' ) 397 || mouse_helper_target.data( 'mouse-helper-image' ) 398 || mouse_helper_target.data( 'mouse-helper-layout' ) 399 ) ) 400 ? ( mouse_helper_smooth ? 500 : 0 ) 401 : ( mouse_helper_smooth ? 50 : 0 ) 402 ); 403 $mouse_helper.eq(0) 404 .attr( 'class', trx_addons_chg_class_by_prefix( $mouse_helper.attr( 'class' ), 'trx_addons_mouse_helper_over_element_', '' ) ); 405 var $inner_elements = $mouse_helper.eq(0).find('.trx_addons_mouse_helper_image,.trx_addons_mouse_helper_text,.trx_addons_mouse_helper_icon,.trx_addons_mouse_helper_layout'); 406 if ( $inner_elements.length > 0 ) { 407 if ( true ) { 408 // Abrupt remove of inner elements 409 $inner_elements.remove(); 410 } else { 411 // Smooth remove of inner elements 412 $inner_elements 413 .addClass('trx_addons_mouse_helper_reset_item') 414 .animate( { 415 opacity: 0, 416 height: 0, 417 width: 0 418 }, 419 mouse_helper_smooth ? 500 : 0, 420 function() { 421 var $self = jQuery(this); 422 if ( $self.hasClass('trx_addons_mouse_helper_reset_item') ) { 423 $self.remove(); 424 } 425 } ); 426 } 427 } 428 $mouse_helper 429 .removeClass( 430 'trx_addons_mouse_helper_active' 431 + ' trx_addons_mouse_helper_hide' 432 + ' trx_addons_mouse_helper_with_icon' 433 + ' trx_addons_mouse_helper_with_text' 434 + ' trx_addons_mouse_helper_with_text_round' 435 + ' trx_addons_mouse_helper_with_image' 436 + ' trx_addons_mouse_helper_with_layout' 437 ) 438 .toggleClass( 'trx_addons_mouse_helper_centered', TRX_ADDONS_STORAGE['mouse_helper_centered'] > 0 ); 439 $mouse_helper.each( function( idx ) { 440 $mouse_helper.eq(idx).css( { 441 'mix-blend-mode': mouse_helper_original_styles[idx].blend_mode, 442 'color': mouse_helper_original_styles[idx].color, 443 'background-color': mouse_helper_original_styles[idx].bg_color, 444 'border-color': mouse_helper_original_styles[idx].bd_color, 445 'border-width': mouse_helper_original_styles[idx].bd_width, 446 'border-style': mouse_helper_original_styles[idx].bd_style 447 } ); 448 } ); 449 if ( mouse_helper_callback && typeof window[mouse_helper_callback] == 'function' ) { 450 window[mouse_helper_callback]( 'reset', $mouse_helper, mouse_helper_last_target, null ); 451 mouse_helper_callback = ''; 452 } else if ( typeof window['trx_addons_mouse_helper_callback_' + mouse_helper_last_action] == 'function' ) { 453 window['trx_addons_mouse_helper_callback_' + mouse_helper_last_action]( 'reset', $mouse_helper, mouse_helper_last_target, e ); 454 } 455 }; 456 457 var mouse_helper_move = function() { 458 cancelAnimationFrame(mouse_helper_move); 459 if ( trx_addons_window_width() >= TRX_ADDONS_STORAGE['mobile_breakpoint_mousehelper_off'] && null !== mouseX && mouse_helper_delay > 1 ) { 460 $mouse_helper.each( function( idx ) { 461 if ( destX[idx] != mouseX || destY[idx] != mouseY ) { 462 if ( $mouse_helper.eq( idx ).hasClass( 'trx_addons_mouse_helper_permanent' ) || $mouse_helper.eq( idx ).hasClass( 'trx_addons_mouse_helper_active' ) ) { 463 var delay = ( $mouse_helper.eq( idx ).data( 'delay' ) || 0 ) * 1 + mouse_helper_delay * 1; 464 destX[idx] += ( mouseX - destX[idx] ) / delay; 465 destY[idx] += ( mouseY - destY[idx] ) / delay; 466 } else { 467 destX[idx] = mouseX; 468 destY[idx] = mouseY; 469 } 470 $mouse_helper.eq( idx ).css("transform", "translate(" + destX[idx] + "px," + destY[idx] + "px)"); 471 } 472 } ); 473 } 474 requestAnimationFrame(mouse_helper_move); 475 }; 476 requestAnimationFrame(mouse_helper_move); 477 478 479 // Get current state 480 function trx_addons_mouse_helper_get_state(e) { 481 if ( e.clientX === undefined ) return; 482 realX = e.clientX + trx_addons_window_scroll_left(); 483 realY = e.clientY + trx_addons_window_scroll_top(); 484 if ( mouse_helper_axis.indexOf('x') != -1 ) mouseX = e.clientX; 485 if ( mouse_helper_axis.indexOf('y') != -1 ) mouseY = e.clientY; 486 } 487 488 489 // Check magnets 490 function trx_addons_mouse_helper_check_magnets() { 491 492 $mouse_helper_magnets.each( function() { 493 494 var item = jQuery(this), 495 inner = item.children(), 496 koef = item.data('mouse-helper-magnet-velocity') ? item.data('mouse-helper-magnet-velocity') : 1, 497 delta = item.data('mouse-helper-magnet') * koef; 498 499 var data, cx, cy, iw, ih, ix, iy, near; //position variables 500 501 requestAnimationFrame(control_item); 502 503 function control_item() { 504 var off = item.offset(); 505 cx = realX; 506 cy = realY; 507 iw = item.width(); 508 ih = item.height(); 509 ix = off.left + iw / 2; 510 iy = off.top + ih / 2; 511 near = Math.abs(ix - cx) < iw * koef && Math.abs(iy - cy) < ih * koef; 512 513 if (near) { 514 ! item.hasClass('trx_addons_mouse_helper_near') && move_item(); 515 requestAnimationFrame(control_item); 516 } else { 517 item.hasClass('trx_addons_mouse_helper_near') && reset_item(); 518 } 519 } 520 521 function move_item() { 522 523 item.addClass('trx_addons_mouse_helper_near'); 524 525 var d = get_closest_position(), 526 dx = d.x, 527 dy = d.y, 528 nx = 0, 529 ny = 0; 530 531 transform_item(); 532 533 function transform_item() { 534 var d = get_closest_position(); 535 nx += (d.x - dx) / 5; 536 ny += (d.y - dy) / 5; 537 538 nx.toFixed(2) !== dx.toFixed(2) && 539 inner.css({ 540 'transition': 'none', 541 'transform': 'translate3d(' + nx + 'px, ' + ny + 'px, 0)' 542 }); 543 544 dx = nx; 545 dy = ny; 546 547 requestAnimationFrame(function () { 548 near && transform_item(); 549 }); 550 } 551 552 function get_closest_position() { 553 return { 554 x: Math.abs(cx - ix) < delta ? cx - ix : delta * (cx - ix) / Math.abs(cx - ix), 555 y: Math.abs(cy - iy) < delta ? cy - iy : delta * (cy - iy) / Math.abs(cy - iy) 556 }; 557 } 558 } 559 560 function reset_item() { 561 562 item.removeClass('trx_addons_mouse_helper_near'); 563 564 inner 565 .css({ 566 'transition': 'transform 0.5s', 567 'transform': 'translate3d(0px, 0px, 0px)' 568 }) 569 .one( typeof window.trx_addons_transition_end != 'undefined' ? trx_addons_transition_end() : 'transitionend', function () { 570 inner.css({ 571 'transition': 'none' 572 }); 573 }); 574 } 575 } ); 576 } 577 } 578 } ); 579 580 581 // Add Mouse helper to the TOC menu 582 $document.on( 'action.build_page_toc', function() { 583 jQuery( '#toc_menu .toc_menu_item' ).each( function() { 584 if ( trx_addons_apply_filters( 'trx_addons_filter_mouse_helper_on_toc', TRX_ADDONS_STORAGE['mouse_helper'] > 0 ) ) { 585 var $self = jQuery(this), 586 title = $self.attr( 'title' ) || $self.find('.toc_menu_description_title').text(); 587 $self.attr( { 588 'data-mouse-helper': 'hover', 589 'data-mouse-helper-axis': 'y', 590 'data-mouse-helper-text': TRX_ADDONS_STORAGE['msg_mouse_helper_anchor'] + ( title ? ' ' + title : '' ) 591 } ); 592 } 593 } ); 594 } ); 595 596})();
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.