forked from madmurphy/spell.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spell-min.js
7 lines (7 loc) · 2.08 KB
/
spell-min.js
1
2
3
4
5
6
7
/**
@source https://github.com/madmurphy/spell.js/
@author madmurphy
@copyright GNU Public License v3
@version 1.0.0
**/
"use strict";function Spell(e,t,n,o){return this&&this instanceof Spell?(e&&(this.content=e),t&&(this.ontype=t),n&&(this.reticent=!0),void(o||this.enable())):new Spell(e||null,t||null,Boolean(n),Boolean(o))}Spell.prototype=function(){function e(e){var o,l,r=!1,s=e||window.event,a=s.charCode,c=s.target.nodeName.toUpperCase(),p=s.target.isContentEditable||/^(?:TEXTAREA|INPUT|SELECT|BUTTON)$/.test(c);for(o=s.target,l=0;0===l&&o&&o.classList;o=o.parentNode)l=o.classList.contains(n)?2:o.classList.contains(t)?1:0;if(p&&!s.target.classList.contains(t)||0===a||2===l)return;for(var u,f=0;f<i.length;f++)o=i[f],"string"!=typeof o.content||o.reticent&&1!==l||(u=isFinite(o.INDEX)&&o.INDEX>=0?Math.floor(o.INDEX):0,o.INDEX=a===o.content.charCodeAt(u)?u+1:a===o.content.charCodeAt(0)?1:0,r=r||o.noticeable&&o.INDEX>(p&&1===u?1:0),o.INDEX===o.content.length&&("function"==typeof o.ontype&&o.ontype(s.target),o.INDEX=0));r&&(e.preventDefault?e.preventDefault():e.returnValue=!1)}var t="enchanted",n="cursed",o=Spell.prototype,l=Object.create(o),i=[],r=!0;return o.content=null,o.ontype=null,o.reticent=!1,o.noticeable=!0,o.INDEX=0,Spell.getStatus=function(){return r},Spell.setStatus=function(t){return 0===arguments.length||Boolean(t)===r?!1:(window[t?"addEventListener":"removeEventListener"]("keypress",e,!1),r=!r,!0)},Spell.pronounce=function(e,t){for(var n=0;n<i.length;n++)"function"==typeof i[n].ontype&&e===i[n].content&&i[n].ontype(t||window)},Spell.unspellAll=function(){for(var e=0;e<i.length;i[e++].INDEX=0);},Spell.makeSilence=function(){Spell.unspellAll(),i.length=0,r&&window.removeEventListener("keypress",e,!1)},Spell.activeList=function(){return i.slice()},l.enable=function(){var t=-1===i.indexOf(this);return r&&0===i.length&&window.addEventListener("keypress",e,!1),t&&i.push(this),t},l.disable=function(){var t=i.indexOf(this);return t>-1&&i.splice(t,1),this.INDEX=0,r&&0===i.length&&window.removeEventListener("keypress",e,!1),t>-1},l}(),Spell.prototype.unspell=function(){this.INDEX=0};