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