| 285 | |
| 286 | // No Jquery hoverIntent v2.2.0 - https://github.com/tristen/hoverintent |
| 287 | var myHoverIntent = function(el, onOver, onOut) { |
| 288 | var x, y, pX, pY; |
| 289 | var mouseOver = false; |
| 290 | var focused = false; |
| 291 | var h = {}, |
| 292 | state = 0, |
| 293 | timer = 0; |
| 294 | |
| 295 | var options = { |
| 296 | sensitivity: 7, |
| 297 | interval: 100, |
| 298 | timeout: 0, |
| 299 | handleFocus: false |
| 300 | }; |
| 301 | |
| 302 | function delay(el, e) { |
| 303 | if (timer) timer = clearTimeout(timer); |
| 304 | state = 0; |
| 305 | return focused ? undefined : onOut.call(el, e); |
| 306 | } |
| 307 | |
| 308 | function tracker(e) { |
| 309 | x = e.clientX; |
| 310 | y = e.clientY; |
| 311 | } |
| 312 | |
| 313 | function compare(el, e) { |
| 314 | if (timer) timer = clearTimeout(timer); |
| 315 | if ((Math.abs(pX - x) + Math.abs(pY - y)) < options.sensitivity) { |
| 316 | state = 1; |
| 317 | return focused ? undefined : onOver.call(el, e); |
| 318 | } else { |
| 319 | pX = x; |
| 320 | pY = y; |
| 321 | timer = setTimeout(function() { |
| 322 | compare(el, e); |
| 323 | }, options.interval); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | // Public methods |
| 328 | h.options = function(opt) { |
| 329 | var focusOptionChanged = opt.handleFocus !== options.handleFocus; |
| 330 | options = Object.assign({}, options, opt); |
| 331 | if (focusOptionChanged) { |
| 332 | options.handleFocus ? addFocus() : removeFocus(); |
| 333 | } |
| 334 | return h; |
| 335 | }; |
| 336 | |
| 337 | function dispatchOver(e) { |
| 338 | mouseOver = true; |
| 339 | if (timer) timer = clearTimeout(timer); |
| 340 | el.removeEventListener('mousemove', tracker, false); |
| 341 | |
| 342 | if (state !== 1) { |
| 343 | pX = e.clientX; |
| 344 | pY = e.clientY; |
| 345 | |
| 346 | el.addEventListener('mousemove', tracker, false); |
| 347 | |
| 348 | timer = setTimeout(function() { |
| 349 | compare(el, e); |
| 350 | }, options.interval); |
| 351 | } |
| 352 | |
| 353 | return this; |
| 354 | } |
| 355 | |
| 356 | function dispatchOut(e) { |
| 357 | mouseOver = false; |
| 358 | if (timer) timer = clearTimeout(timer); |
| 359 | el.removeEventListener('mousemove', tracker, false); |
| 360 | |
| 361 | if (state === 1) { |
| 362 | timer = setTimeout(function() { |
| 363 | delay(el, e); |
| 364 | }, options.timeout); |
| 365 | } |
| 366 | |
| 367 | return this; |
| 368 | } |
| 369 | |
| 370 | function dispatchFocus(e) { |
| 371 | if (!mouseOver) { |
| 372 | focused = true; |
| 373 | onOver.call(el, e); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | function dispatchBlur(e) { |
| 378 | if (!mouseOver && focused) { |
| 379 | focused = false; |
| 380 | onOut.call(el, e); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | function addFocus() { |
| 385 | el.addEventListener('focus', dispatchFocus, false); |
| 386 | el.addEventListener('blur', dispatchBlur, false); |
| 387 | } |
| 388 | |
| 389 | function removeFocus() { |
| 390 | el.removeEventListener('focus', dispatchFocus, false); |
| 391 | el.removeEventListener('blur', dispatchBlur, false); |
| 392 | } |
| 393 | |
| 394 | h.remove = function() { |
| 395 | if (!el) return; |
| 396 | el.removeEventListener('mouseover', dispatchOver, false); |
| 397 | el.removeEventListener('mouseout', dispatchOut, false); |
| 398 | removeFocus(); |
| 399 | }; |
| 400 | |
| 401 | if (el) { |
| 402 | el.addEventListener('mouseover', dispatchOver, false); |
| 403 | el.addEventListener('mouseout', dispatchOut, false); |
| 404 | } |
| 405 | |
| 406 | return h; |
| 407 | }; |
| 408 | |