-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmtgtooltip.min.js
1 lines (1 loc) · 6.69 KB
/
mtgtooltip.min.js
1
"use strict";var mtgTooltip=function(e){arguments.length&&(this._settings=Object.assign({},this._settings,e)),this._settings.log&&console.log("mtgtooltip loaded"),this._settings.start&&this.start()};mtgTooltip.prototype={start:function(){var e=this;if(this._settings.mobile&&window.innerWidth<=800)return!1;this._alltogether(),this._settings.log&&console.log("mtgtooltip started");var t=this._settings.myclass,s=document.querySelector(this._settings.element);this.mymousemove(s);var n=s.querySelectorAll("."+t+":not(."+t+"mtgloaded)");this._settings.log&&console.log("Cards to tooltip found:",n),n.forEach(function(t){var s=t.dataset.name,n=t.dataset.set,a=t.dataset.multiverseid,o=t.dataset.specialimg,i=t.innerHTML,l="http://gatherer.wizards.com/Handlers/Image.ashx?type=card",d="",r="",p="";if(!a&&!o){d=void 0!==s&&s.length>0?"&name="+encodeURI(s):"&name="+encodeURI(i),void 0!==n&&n.length>0&&(r="&set="+n);var c=void 0!==s&&s.length>0?e.getSetLands(s):e.getSetLands(i);c&&(r="&set="+c)}void 0!==a&&a.length>0&&(p="&multiverseid="+a),void 0!==o&&o.length>0&&(l=e._settings.specialImage+o),l+=d+r+p,e.run(t,l)}),this._settings.log&&console.log("Created cards tooltips, starting creating the tooltips")},run:function(e,t){var s=this._settings.myclass,n=this._settings.id,a=document.querySelector(this._settings.element);e.id=s+"_p"+n;var o=document.createElement("span");o.classList.add(s+"hover"),o.id=s+"_c"+n;var i="src";this._settings.lazyload&&(i="data-src");var l=this._settings.wrap_in,d=this._settings.wrap_out;o.innerHTML="".concat(l,"<img ").concat(i,"='").concat(t,"' alt='mtgtooltip image' >").concat(d),e.dataset.tooltipid=n,o.dataset.tooltipid=n,e.style.whiteSpace="nowrap",a.appendChild(o),o.style.display="none",o.style.opacity="0",o.classList.add(s+"tooltipstarted"),this._settings.id=n+1;var r=this;e.addEventListener("mouseover",function(e){r.mouseenter(e)}),e.addEventListener("mouseleave",function(e){r.mouseleave(e)})},mouseleave:function(e){var t=e.target.dataset.tooltipid;if(!t)return!1;var s=this._settings.myclass,n=document.getElementById(s+"_c"+t);if(this._settings.log&&console.log(e),this._settings.fadetime>0){var a=this._settings.fadetime;n.style.transition="all "+a+"ms ease-out",n.style.opacity=0,setTimeout(function(){n.style.display="none",n.style.transition=""},a)}else n.style.display="none"},mouseenter:function(e){var t=e.target.dataset.tooltipid;if(!t)return!1;var s=this._settings.myclass,n=document.getElementById(s+"_c"+t);if(this._settings.lazyload){var a=n.querySelector("img"),o=a.dataset.src;a.setAttribute("src",o)}n.style.position="absolute",n.style.opacity=this._settings.opacity,n.style.zIndex="100",n.style.display="inline-block";var i=e.pageY,l=e.pageX,d=window.innerWidth,r=window.innerHeight,p=window.scrollY,c=window.scrollX,g=0,h=0;h=l+50,l+270>d+c&&(h=c+d-270),(g=i-50)+376>r+p&&(g=i-376+25),n.style.left=h+"px",n.style.top=g+"px"},mymousemove:function(e){var t=this;e.addEventListener("mousemove",function(e){t._settings.mousex=e.pageX,t._settings.mousey=e.pageY})},kill:function(){var e=this._settings.myclass;document.querySelector(this._settings.element).querySelectorAll("."+e).forEach(function(t){t.removeEventListener("mouseover",function(e){that.mouseenter(e)}),t.removeEventListener("mouseleave",function(e){that.mouseleave(e)}),t.classList.remove(e),t.classList.remove("mtgloaded");var s=t.dataset.tooltipid,n=document.getElementById(e+"_c"+s);n.parentNode.removeChild(n),t.removeAttribute("data-tooltipid"),t.removeAttribute("id")}),this._settings.log&&console.log(this._settings.name,"removed all instances of mtgtooltips")},_settings:{name:"MTG Tooltip js",version:"1.0",element:"body",myclass:"mtgtooltip",lazyload:!0,fadetime:250,opacity:1,mousex:0,mousey:0,id:0,log:!1,start:!1,wrap_in:"",wrap_out:"",specialImage:"",mobile:!0,basiclands:"ust",shocklands:"exp",fetchlands:"exp",painlands:"exp"},getSetLands:function(e){var t=e.toLowerCase();if(this._lands[t]){var s=this._lands[t].type.toLowerCase(),n=this._settings[s].toLowerCase(),a=this._lands[t][n];if(n&&a)return a.toUpperCase();var o="";Object.values(this._lands[t]).forEach(function(e){e!=s&&(o+=e+" ")}),console.log("MTG TOOLTIP: ERROR: Incorrect option on ".concat(s,"!! options available are: ").concat(o))}return null},_shocklands:[{"blood crypt":{type:"shocklands",old:"dis",new:"rtr",exp:"exp"}},{"breeding pool":{type:"shocklands",old:"dis",new:"gtc",exp:"exp"}},{"godless shrine":{type:"shocklands",old:"gpt",new:"gtc",exp:"exp"}},{"hallowed fountain":{type:"shocklands",old:"dis",new:"rtr",exp:"exp"}},{"overgrown tomb":{type:"shocklands",old:"rav",new:"rtr",exp:"exp"}},{"sacred foundry":{type:"shocklands",old:"rav",new:"gtc",exp:"exp"}},{"steam vents":{type:"shocklands",old:"gpt",new:"rtr",exp:"exp"}},{"stomping ground":{type:"shocklands",old:"gpt",new:"gtc",exp:"exp"}},{"temple garden":{type:"shocklands",old:"rav",new:"rtr",exp:"exp"}},{"watery grave":{type:"shocklands",old:"rav",new:"gtc",exp:"exp"}}],_fetchlands:[{"arid mesa":{type:"fetchlands",old:"zen",new:"mm3",exp:"exp"}},{"bloodstained mire":{type:"fetchlands",old:"ons",new:"ktk",exp:"exp"}},{"flooded strand":{type:"fetchlands",old:"ons",new:"ktk",exp:"exp"}},{"marsh flats":{type:"fetchlands",old:"zen",new:"mm3",exp:"exp"}},{"misty rainforest":{type:"fetchlands",old:"zen",new:"mm3",exp:"exp"}},{"polluted delta":{type:"fetchlands",old:"ons",new:"ktk",exp:"exp"}},{"scalding tarn":{type:"fetchlands",old:"zen",new:"mm3",exp:"exp"}},{"verdant catacombs":{type:"fetchlands",old:"zen",new:"mm3",exp:"exp"}},{"windswept heath":{type:"fetchlands",old:"ons",new:"ktk",exp:"exp"}},{"wooded foothills":{type:"fetchlands",old:"ons",new:"ktk",exp:"exp"}}],_painlands:[{"adarkar wastes":{type:"painlands",old:"ie",new:"10e",exp:"6e"}},{"battlefield forge":{type:"painlands",old:"ap",new:"ori",exp:"10e"}},{brushland:{type:"painlands",old:"ie",new:"10e",exp:"6e"}},{"caves of koilos":{type:"painlands",old:"ap",new:"ori",exp:"10e"}},{"karplusan forest":{type:"painlands",old:"ap",new:"ori",exp:"10e"}},{"llanowar wastes":{type:"painlands",old:"ap",new:"ori",exp:"10e"}},{"shivan reef":{type:"painlands",old:"ap",new:"ori",exp:"10e"}},{"yavimaya coast":{type:"painlands",old:"ap",new:"ori",exp:"10e"}},{"underground river":{type:"painlands",old:"ap",new:"ori",exp:"10e"}},{"sulfurous springs":{type:"painlands",old:"ap",new:"ori",exp:"10e"}}],_basiclands:[{mountain:{type:"basiclands",uhn:"unh",ust:"ust",ugl:"ug"}},{plains:{type:"basiclands",uhn:"unh",ust:"ust",ugl:"ug"}},{forest:{type:"basiclands",uhn:"unh",ust:"ust",ugl:"ug"}},{swamp:{type:"basiclands",uhn:"unh",ust:"ust",ugl:"ug"}},{island:{type:"basiclands",uhn:"unh",ust:"ust",ugl:"ug"}}],_alltogether:function(){var e=this;[this._shocklands,this._fetchlands,this._painlands,this._basiclands].forEach(function(t){t.forEach(function(s,n){Object.assign(e._lands,t[n])})})},_lands:{}};