es6-menu-aim
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["es6-menu-aim"]=e():t["es6-menu-aim"]=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(o){if(i[o])return i[o].exports;var n=i[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,e),n.l=!0,n.exports}var i={};return e.m=t,e.c=i,e.d=function(t,i,o){e.o(t,i)||Object.defineProperty(t,i,{configurable:!1,enumerable:!0,get:o})},e.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(i,"a",i),i},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,i){"use strict";function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){for(var i=0;i<e.length;i++){var o=e[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function s(t,e,i){return e&&n(t.prototype,e),i&&n(t,i),t}Object.defineProperty(e,"__esModule",{value:!0});var u=i(1),a=[],l=0,c=function(){function t(e,i){o(this,t),this.activeRow=null,this.lastDelayLoc=null,this.timeoutId=null,this.exitTimeoutID=null,this.options=null,this.menu=null,this.attach=function(t){this.menu=t,this.options.isRoot&&this.menu.addEventListener("mouseleave",this.mouseleaveMenu),1==++l&&document.addEventListener("mousemove",r)};var n=function(){};i=i||{},this.options={rowSelector:i.rowSelector||"> li",exitDelay:i.exitDelay||null,submenuSelector:i.submenuSelector||"*",submenuDirection:i.submenuDirection||u.MenuDirection.right,tolerance:i.tolerance||75,isRoot:i.isRoot||!0,enter:i.enter||n,exit:i.exit||n,activate:i.activate||n,deactivate:i.deactivate||n,exitMenu:i.exitMenu||n,clickRow:i.clickRow||n},this.mouseenterRow=this.mouseenterRow.bind(this),this.mouseleaveRow=this.mouseleaveRow.bind(this),this.clickRow=this.clickRow.bind(this),this.mouseleaveMenu=this.mouseleaveMenu.bind(this),this.commitExit=this.commitExit.bind(this),this.attach(e)}return s(t,[{key:"mouseleaveMenu",value:function(t){this.timeoutId&&(window.clearTimeout(this.timeoutId),this.timeoutId=null),this.options.exitDelay?(this.exitTimeoutID&&(window.clearTimeout(this.exitTimeoutID),this.exitTimeoutID=null),this.exitTimeoutID=window.setTimeout(this.commitExit,this.options.exitDelay)):this.commitExit()}},{key:"forceExit",value:function(){this.exitTimeoutID&&window.clearTimeout(this.exitTimeoutID),this.commitExit()}},{key:"commitExit",value:function(){this.timeoutId=this.exitTimeoutID=null,this.options.exitMenu(this)&&(this.activeRow&&this.options.deactivate(this.activeRow),this.activeRow=null)}},{key:"mouseenterRow",value:function(t){this.exitTimeoutID&&(clearTimeout(this.exitTimeoutID),this.exitTimeoutID=null),this.timeoutId&&(clearTimeout(this.timeoutId),this.timeoutId=null),this.options.enter(t.target),this.possiblyActivate(t.target)}},{key:"mouseleaveRow",value:function(t){this.options.exit(t.target)}},{key:"clickRow",value:function(t){t.target!==this.activeRow&&this.activate(t.target),this.options.clickRow(t,t.target)}},{key:"activate",value:function(t){if(t!=this.activeRow){this.activeRow&&this.options.deactivate(this.activeRow);var e=this.options.activate(t);this.activeRow=e||t}}},{key:"possiblyActivate",value:function(t){var e=this.activationDelay(),i=this;e?this.timeoutId=setTimeout(function(){i.possiblyActivate(t)},e):this.activate(t)}},{key:"activationDelay",value:function(){var t=!1;if(this.activeRow)for(var e=this.activeRow.parentElement.querySelectorAll(this.options.submenuSelector),i=0,o=e.length;i<o;i++)if(e[i]===this.activeRow){t=!0;break}if(!t)return 0;var n=m(this.menu),s={x:n.left,y:n.top-this.options.tolerance},l={x:n.left+this.menu.offsetWidth,y:s.y},c={x:n.left,y:n.top+this.menu.offsetHeight+this.options.tolerance},r={x:n.left+this.menu.offsetWidth,y:c.y},v=a[a.length-1],f=a[0];if(!v)return 0;if(f||(f=v),f.x<n.left||f.x>r.x||f.y<n.top||f.y>r.y)return 0;if(this.lastDelayLoc&&v.x==this.lastDelayLoc.x&&v.y==this.lastDelayLoc.y)return 0;var d=l,p=r;this.options.submenuDirection==u.MenuDirection.left?(d=c,p=s):this.options.submenuDirection==u.MenuDirection.below?(d=r,p=c):this.options.submenuDirection==u.MenuDirection.above&&(d=s,p=l);var y=h(v,d),w=h(v,p),x=h(f,d),R=h(f,p);return y<x&&w>R?(this.lastDelayLoc=v,300):(this.lastDelayLoc=null,0)}},{key:"hookUp",value:function(t){t.addEventListener("mouseenter",this.mouseenterRow),t.addEventListener("mouseleave",this.mouseleaveRow),t.addEventListener("click",this.clickRow)}},{key:"setActiveRow",value:function(t){this.activeRow=t,this.timeoutId&&(window.clearTimeout(this.timeoutId),this.timeoutId=null),this.exitTimeoutID&&(window.clearTimeout(this.exitTimeoutID),this.exitTimeoutID=null)}},{key:"deactivateRow",value:function(){this.activeRow&&this.options.deactivate(this.activeRow),this.activeRow=null}},{key:"detach",value:function(){this.menu&&(this.timeoutId&&clearTimeout(this.timeoutId),0==--l&&document.removeEventListener("mousemove",r),this.options.isRoot&&this.menu.removeEventListener("mouseleave",this.mouseleaveMenu),this.timeoutId=this.lastDelayLoc=this.activeRow=this.menu=null)}}]),t}();e.MenuAim=c;var r=function(t){a.push({x:t.pageX,y:t.pageY}),a.length>3&&a.shift()},h=function(t,e){return(e.y-t.y)/(e.x-t.x)},m=function(t){var e=t.getBoundingClientRect(),i=t.ownerDocument.defaultView;return{top:e.top+i.pageYOffset,left:e.left+i.pageXOffset}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var o;!function(t){t.left="left",t.right="right",t.below="below",t.above="above"}(o||(o={})),e.MenuDirection=o}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["es6-menu-aim"]=e():t["es6-menu-aim"]=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(o){if(i[o])return i[o].exports;var n=i[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,e),n.l=!0,n.exports}var i={};return e.m=t,e.c=i,e.d=function(t,i,o){e.o(t,i)||Object.defineProperty(t,i,{configurable:!1,enumerable:!0,get:o})},e.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(i,"a",i),i},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,i){"use strict";function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){for(var i=0;i<e.length;i++){var o=e[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function s(t,e,i){return e&&n(t.prototype,e),i&&n(t,i),t}Object.defineProperty(e,"__esModule",{value:!0});var u=i(1),a=[],c=0,l=function(){function t(e,i){o(this,t),this.activeRow=null,this.lastDelayLoc=null,this.timeoutId=null,this.exitTimeoutID=null,this.options=null,this.menu=null,this.attach=function(t){this.menu=t,this.options.isRoot&&this.menu.addEventListener("mouseleave",this.mouseleaveMenu),1==++c&&document.addEventListener("mousemove",r)};var n=function(){};i=i||{},this.options={rowSelector:i.rowSelector||"> li",exitDelay:i.exitDelay||null,submenuSelector:i.submenuSelector||"*",submenuDirection:i.submenuDirection||u.MenuDirection.right,tolerance:i.tolerance||75,isRoot:i.isRoot||!0,enter:i.enter||n,exit:i.exit||n,activate:i.activate||n,deactivate:i.deactivate||n,exitMenu:i.exitMenu||n,clickRow:i.clickRow||n},this.mouseenterRow=this.mouseenterRow.bind(this),this.mouseleaveRow=this.mouseleaveRow.bind(this),this.clickRow=this.clickRow.bind(this),this.mouseleaveMenu=this.mouseleaveMenu.bind(this),this.commitExit=this.commitExit.bind(this),this.attach(e)}return s(t,[{key:"mouseleaveMenu",value:function(t){this.timeoutId&&(window.clearTimeout(this.timeoutId),this.timeoutId=null),this.options.exitDelay?(this.exitTimeoutID&&(window.clearTimeout(this.exitTimeoutID),this.exitTimeoutID=null),this.exitTimeoutID=window.setTimeout(this.commitExit,this.options.exitDelay)):this.commitExit()}},{key:"forceExit",value:function(){this.exitTimeoutID&&window.clearTimeout(this.exitTimeoutID),this.commitExit()}},{key:"commitExit",value:function(){this.timeoutId=this.exitTimeoutID=null,this.options.exitMenu(this)&&(this.activeRow&&this.options.deactivate(this.activeRow),this.activeRow=null)}},{key:"mouseenterRow",value:function(t){this.exitTimeoutID&&(clearTimeout(this.exitTimeoutID),this.exitTimeoutID=null),this.timeoutId&&(clearTimeout(this.timeoutId),this.timeoutId=null),this.options.enter(t.currentTarget),this.possiblyActivate(t.currentTarget)}},{key:"mouseleaveRow",value:function(t){this.options.exit(t.currentTarget)}},{key:"clickRow",value:function(t){t.currentTarget!==this.activeRow&&this.activate(t.currentTarget),this.options.clickRow(t,t.currentTarget)}},{key:"activate",value:function(t){if(t!=this.activeRow){this.activeRow&&this.options.deactivate(this.activeRow);var e=this.options.activate(t);this.activeRow=e||t}}},{key:"possiblyActivate",value:function(t){var e=this.activationDelay(),i=this;e?this.timeoutId=setTimeout(function(){i.possiblyActivate(t)},e):this.activate(t)}},{key:"activationDelay",value:function(){var t=!1;if(this.activeRow)for(var e=this.activeRow.parentElement.querySelectorAll(this.options.submenuSelector),i=0,o=e.length;i<o;i++)if(e[i]===this.activeRow){t=!0;break}if(!t)return 0;var n=m(this.menu),s={x:n.left,y:n.top-this.options.tolerance},c={x:n.left+this.menu.offsetWidth,y:s.y},l={x:n.left,y:n.top+this.menu.offsetHeight+this.options.tolerance},r={x:n.left+this.menu.offsetWidth,y:l.y},v=a[a.length-1],f=a[0];if(!v)return 0;if(f||(f=v),f.x<n.left||f.x>r.x||f.y<n.top||f.y>r.y)return 0;if(this.lastDelayLoc&&v.x==this.lastDelayLoc.x&&v.y==this.lastDelayLoc.y)return 0;var d=c,p=r;this.options.submenuDirection==u.MenuDirection.left?(d=l,p=s):this.options.submenuDirection==u.MenuDirection.below?(d=r,p=l):this.options.submenuDirection==u.MenuDirection.above&&(d=s,p=c);var y=h(v,d),w=h(v,p),x=h(f,d),R=h(f,p);return y<x&&w>R?(this.lastDelayLoc=v,300):(this.lastDelayLoc=null,0)}},{key:"hookUp",value:function(t){t.addEventListener("mouseenter",this.mouseenterRow),t.addEventListener("mouseleave",this.mouseleaveRow),t.addEventListener("click",this.clickRow)}},{key:"setActiveRow",value:function(t){this.activeRow=t,this.timeoutId&&(window.clearTimeout(this.timeoutId),this.timeoutId=null),this.exitTimeoutID&&(window.clearTimeout(this.exitTimeoutID),this.exitTimeoutID=null)}},{key:"deactivateRow",value:function(){this.activeRow&&this.options.deactivate(this.activeRow),this.activeRow=null}},{key:"detach",value:function(){this.menu&&(this.timeoutId&&clearTimeout(this.timeoutId),0==--c&&document.removeEventListener("mousemove",r),this.options.isRoot&&this.menu.removeEventListener("mouseleave",this.mouseleaveMenu),this.timeoutId=this.lastDelayLoc=this.activeRow=this.menu=null)}}]),t}();e.MenuAim=l;var r=function(t){a.push({x:t.pageX,y:t.pageY}),a.length>3&&a.shift()},h=function(t,e){return(e.y-t.y)/(e.x-t.x)},m=function(t){var e=t.getBoundingClientRect(),i=t.ownerDocument.defaultView;return{top:e.top+i.pageYOffset,left:e.left+i.pageXOffset}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var o;!function(t){t.left="left",t.right="right",t.below="below",t.above="above"}(o||(o={})),e.MenuDirection=o}])}); | ||
//# sourceMappingURL=es6-menu-aim.js.map |
{ | ||
"name": "es6-menu-aim", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "ES6 re-implementation of jQuery-menu-aim", | ||
@@ -5,0 +5,0 @@ "main": "dist/es6-menu-aim.js", |
@@ -5,3 +5,3 @@ # What's this? | ||
It has been written so that it can be used/imported as a regular ES6 module ... like so: | ||
It has been written so that it can be used/imported as a regular ES6 module ... like so (a more detailed example can be found at the end of this document): | ||
@@ -11,8 +11,14 @@ ```javascript | ||
let menuRoot = document.getElementById('menuRoot'); | ||
let menu_root = document.getElementById('menuRoot'); | ||
let menu_aim = new MenuAim(menuRoot); | ||
let menu_aim_config = { | ||
clickRow:function (mouseEvent, targetRow) { | ||
console.log('menu item was clicked!'); | ||
} | ||
}; | ||
let menu_aim = new MenuAim(menuRoot, menu_aim_config); | ||
``` | ||
Unlike the original *jQuery-menu-aim*, this one doesn't use jQuery ... in fact it has no dependencies. | ||
Unlike the original **jQuery-menu-aim**, this one doesn't use jQuery ... in fact it has no dependencies. | ||
@@ -19,0 +25,0 @@ ## Why would I want use this? |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
75685
259