Files
spyda/internal/static/js/spyda.min.js
Aoi Koizumi (古泉 あおい) a6d10baaf3 Now compiles under Go 1.17+
Signed-off-by: Aoi Koizumi (古泉 あおい) <novaburst@kalli.st>
2022-08-30 11:13:47 +10:00

36 lines
14 KiB
JavaScript

var u=function(parameter,context){if(!(this instanceof u)){return new u(parameter,context);}
if(parameter instanceof u){return parameter;}
if(typeof parameter==='string'){parameter=this.select(parameter,context);}
if(parameter&&parameter.nodeName){parameter=[parameter];}
this.nodes=this.slice(parameter);};u.prototype={get length(){return this.nodes.length;}};u.prototype.nodes=[];u.prototype.addClass=function(){return this.eacharg(arguments,function(el,name){el.classList.add(name);});};u.prototype.adjacent=function(html,data,callback){if(typeof data==='number'){if(data===0){data=[];}else{data=new Array(data).join().split(',').map(Number.call,Number);}}
return this.each(function(node,j){var fragment=document.createDocumentFragment();u(data||{}).map(function(el,i){var part=(typeof html==='function')?html.call(this,el,i,node,j):html;if(typeof part==='string'){return this.generate(part);}
return u(part);}).each(function(n){this.isInPage(n)?fragment.appendChild(u(n).clone().first()):fragment.appendChild(n);});callback.call(this,node,fragment);});};u.prototype.after=function(html,data){return this.adjacent(html,data,function(node,fragment){node.parentNode.insertBefore(fragment,node.nextSibling);});};u.prototype.append=function(html,data){return this.adjacent(html,data,function(node,fragment){node.appendChild(fragment);});};u.prototype.args=function(args,node,i){if(typeof args==='function'){args=args(node,i);}
if(typeof args!=='string'){args=this.slice(args).map(this.str(node,i));}
return args.toString().split(/[\s,]+/).filter(function(e){return e.length;});};u.prototype.array=function(callback){callback=callback;var self=this;return this.nodes.reduce(function(list,node,i){var val;if(callback){val=callback.call(self,node,i);if(!val)val=false;if(typeof val==='string')val=u(val);if(val instanceof u)val=val.nodes;}else{val=node.innerHTML;}
return list.concat(val!==false?val:[]);},[]);};u.prototype.attr=function(name,value,data){data=data?'data-':'';return this.pairs(name,value,function(node,name){return node.getAttribute(data+name);},function(node,name,value){node.setAttribute(data+name,value);});};u.prototype.before=function(html,data){return this.adjacent(html,data,function(node,fragment){node.parentNode.insertBefore(fragment,node);});};u.prototype.children=function(selector){return this.map(function(node){return this.slice(node.children);}).filter(selector);};u.prototype.clone=function(){return this.map(function(node,i){var clone=node.cloneNode(true);var dest=this.getAll(clone);this.getAll(node).each(function(src,i){for(var key in this.mirror){if(this.mirror[key]){this.mirror[key](src,dest.nodes[i]);}}});return clone;});};u.prototype.getAll=function getAll(context){return u([context].concat(u('*',context).nodes));};u.prototype.mirror={};u.prototype.mirror.events=function(src,dest){if(!src._e)return;for(var type in src._e){src._e[type].forEach(function(ref){u(dest).on(type,ref.callback);});}};u.prototype.mirror.select=function(src,dest){if(u(src).is('select')){dest.value=src.value;}};u.prototype.mirror.textarea=function(src,dest){if(u(src).is('textarea')){dest.value=src.value;}};u.prototype.closest=function(selector){return this.map(function(node){do{if(u(node).is(selector)){return node;}}while((node=node.parentNode)&&node!==document);});};u.prototype.data=function(name,value){return this.attr(name,value,true);};u.prototype.each=function(callback){this.nodes.forEach(callback.bind(this));return this;};u.prototype.eacharg=function(args,callback){return this.each(function(node,i){this.args(args,node,i).forEach(function(arg){callback.call(this,node,arg);},this);});};u.prototype.empty=function(){return this.each(function(node){while(node.firstChild){node.removeChild(node.firstChild);}});};u.prototype.filter=function(selector){var callback=function(node){node.matches=node.matches||node.msMatchesSelector||node.webkitMatchesSelector;return node.matches(selector||'*');};if(typeof selector==='function')callback=selector;if(selector instanceof u){callback=function(node){return(selector.nodes).indexOf(node)!==-1;};}
return u(this.nodes.filter(callback));};u.prototype.find=function(selector){return this.map(function(node){return u(selector||'*',node);});};u.prototype.first=function(){return this.nodes[0]||false;};u.prototype.generate=function(html){if(/^\s*<tr[> ]/.test(html)){return u(document.createElement('table')).html(html).children().children().nodes;}else if(/^\s*<t(h|d)[> ]/.test(html)){return u(document.createElement('table')).html(html).children().children().children().nodes;}else if(/^\s*</.test(html)){return u(document.createElement('div')).html(html).children().nodes;}else{return document.createTextNode(html);}};u.prototype.handle=function(){var args=this.slice(arguments).map(function(arg){if(typeof arg==='function'){return function(e){e.preventDefault();arg.apply(this,arguments);};}
return arg;},this);return this.on.apply(this,args);};u.prototype.hasClass=function(){return this.is('.'+this.args(arguments).join('.'));};u.prototype.html=function(text){if(text===undefined){return this.first().innerHTML||'';}
return this.each(function(node){node.innerHTML=text;});};u.prototype.is=function(selector){return this.filter(selector).length>0;};u.prototype.isInPage=function isInPage(node){return(node===document.body)?false:document.body.contains(node);};u.prototype.last=function(){return this.nodes[this.length-1]||false;};u.prototype.map=function(callback){return callback?u(this.array(callback)).unique():this;};u.prototype.not=function(filter){return this.filter(function(node){return!u(node).is(filter||true);});};u.prototype.off=function(events,cb,cb2){var cb_filter_off=(cb==null&&cb2==null);var sel=null;var cb_to_be_removed=cb;if(typeof cb==='string'){sel=cb;cb_to_be_removed=cb2;}
return this.eacharg(events,function(node,event){u(node._e?node._e[event]:[]).each(function(ref){if(cb_filter_off||(ref.orig_callback===cb_to_be_removed&&ref.selector===sel)){node.removeEventListener(event,ref.callback);}});});};u.prototype.on=function(events,cb,cb2){var sel=null;var orig_callback=cb;if(typeof cb==='string'){sel=cb;orig_callback=cb2;cb=function(e){var args=arguments;var targetFound=false;u(e.currentTarget).find(sel).each(function(target){if(target===e.target||target.contains(e.target)){targetFound=true;try{Object.defineProperty(e,'currentTarget',{get:function(){return target;}});}catch(err){}
cb2.apply(target,args);}});if(!targetFound&&e.currentTarget===e.target){cb2.apply(e.target,args);}};}
var callback=function(e){return cb.apply(this,[e].concat(e.detail||[]));};return this.eacharg(events,function(node,event){node.addEventListener(event,callback);node._e=node._e||{};node._e[event]=node._e[event]||[];node._e[event].push({callback:callback,orig_callback:orig_callback,selector:sel});});};u.prototype.pairs=function(name,value,get,set){if(typeof value!=='undefined'){var nm=name;name={};name[nm]=value;}
if(typeof name==='object'){return this.each(function(node){for(var key in name){set(node,key,name[key]);}});}
return this.length?get(this.first(),name):'';};u.prototype.param=function(obj){return Object.keys(obj).map(function(key){return this.uri(key)+'='+this.uri(obj[key]);}.bind(this)).join('&');};u.prototype.parent=function(selector){return this.map(function(node){return node.parentNode;}).filter(selector);};u.prototype.prepend=function(html,data){return this.adjacent(html,data,function(node,fragment){node.insertBefore(fragment,node.firstChild);});};u.prototype.remove=function(){return this.each(function(node){if(node.parentNode){node.parentNode.removeChild(node);}});};u.prototype.removeClass=function(){return this.eacharg(arguments,function(el,name){el.classList.remove(name);});};u.prototype.replace=function(html,data){var nodes=[];this.adjacent(html,data,function(node,fragment){nodes=nodes.concat(this.slice(fragment.children));node.parentNode.replaceChild(fragment,node);});return u(nodes);};u.prototype.scroll=function(){this.first().scrollIntoView({behavior:'smooth'});return this;};u.prototype.select=function(parameter,context){parameter=parameter.replace(/^\s*/,'').replace(/\s*$/,'');if(/^</.test(parameter)){return u().generate(parameter);}
return(context||document).querySelectorAll(parameter);};u.prototype.serialize=function(){var self=this;return this.slice(this.first().elements).reduce(function(query,el){if(!el.name||el.disabled||el.type==='file')return query;if(/(checkbox|radio)/.test(el.type)&&!el.checked)return query;if(el.type==='select-multiple'){u(el.options).each(function(opt){if(opt.selected){query+='&'+self.uri(el.name)+'='+self.uri(opt.value);}});return query;}
return query+'&'+self.uri(el.name)+'='+self.uri(el.value);},'').slice(1);};u.prototype.siblings=function(selector){return this.parent().children(selector).not(this);};u.prototype.size=function(){return this.first().getBoundingClientRect();};u.prototype.slice=function(pseudo){if(!pseudo||pseudo.length===0||typeof pseudo==='string'||pseudo.toString()==='[object Function]')return[];return pseudo.length?[].slice.call(pseudo.nodes||pseudo):[pseudo];};u.prototype.str=function(node,i){return function(arg){if(typeof arg==='function'){return arg.call(this,node,i);}
return arg.toString();};};u.prototype.text=function(text){if(text===undefined){return this.first().textContent||'';}
return this.each(function(node){node.textContent=text;});};u.prototype.toggleClass=function(classes,addOrRemove){if(!!addOrRemove===addOrRemove){return this[addOrRemove?'addClass':'removeClass'](classes);}
return this.eacharg(classes,function(el,name){el.classList.toggle(name);});};u.prototype.trigger=function(events){var data=this.slice(arguments).slice(1);return this.eacharg(events,function(node,event){var ev;var opts={bubbles:true,cancelable:true,detail:data};try{ev=new window.CustomEvent(event,opts);}catch(e){ev=document.createEvent('CustomEvent');ev.initCustomEvent(event,true,true,data);}
node.dispatchEvent(ev);});};u.prototype.unique=function(){return u(this.nodes.reduce(function(clean,node){var istruthy=node!==null&&node!==undefined&&node!==false;return(istruthy&&clean.indexOf(node)===-1)?clean.concat(node):clean;},[]));};u.prototype.uri=function(str){return encodeURIComponent(str).replace(/!/g,'%21').replace(/'/g,'%27').replace(/\(/g,'%28').replace(/\)/g,'%29').replace(/\*/g,'%2A').replace(/%20/g,'+');};u.prototype.wrap=function(selector){function findDeepestNode(node){while(node.firstElementChild){node=node.firstElementChild;}
return u(node);}
return this.map(function(node){return u(selector).each(function(n){findDeepestNode(n).append(node.cloneNode(true));node.parentNode.replaceChild(n,node);});});};if(typeof module==='object'&&module.exports){module.exports=u;module.exports.u=u;}
(function(){if(typeof window.Element==="undefined"||"classList"in document.documentElement)return;var prototype=Array.prototype,push=prototype.push,splice=prototype.splice,join=prototype.join;function DOMTokenList(el){this.el=el;var classes=el.className.replace(/^\s+|\s+$/g,'').split(/\s+/);for(var i=0;i<classes.length;i++){push.call(this,classes[i]);}};DOMTokenList.prototype={add:function(token){if(this.contains(token))return;push.call(this,token);this.el.className=this.toString();},contains:function(token){return this.el.className.indexOf(token)!=-1;},item:function(index){return this[index]||null;},remove:function(token){if(!this.contains(token))return;for(var i=0;i<this.length;i++){if(this[i]==token)break;}
splice.call(this,i,1);this.el.className=this.toString();},toString:function(){return join.call(this,' ');},toggle:function(token){if(!this.contains(token)){this.add(token);}else{this.remove(token);}
return this.contains(token);}};window.DOMTokenList=DOMTokenList;function defineElementGetter(obj,prop,getter){if(Object.defineProperty){Object.defineProperty(obj,prop,{get:getter});}else{obj.__defineGetter__(prop,getter);}}
defineElementGetter(Element.prototype,'classList',function(){return new DOMTokenList(this);});})();var Twix=(function(){function Twix(){}
Twix.ajax=function(options){options=options||{url:""};options.type=options.type.toUpperCase()||'GET';options.headers=options.headers||{};options.timeout=parseInt(options.timeout)||0;options.success=options.success||function(){};options.error=options.error||function(){};options.async=typeof options.async==='undefined'?true:options.async;var client=new XMLHttpRequest();if(options.timeout>0){client.timeout=options.timeout;client.ontimeout=function(){options.error('timeout','timeout',client);};}
client.open(options.type,options.url,options.async);for(var i in options.headers){if(options.headers.hasOwnProperty(i)){client.setRequestHeader(i,options.headers[i]);}}
client.send(options.data);client.onreadystatechange=function(){if(this.readyState==4&&((this.status>=200&&this.status<300)||this.status==304)){var data=this.responseText;var contentType=this.getResponseHeader('Content-Type');if(contentType&&contentType.match(/json/)){data=JSON.parse(this.responseText);}
options.success(data,this.statusText,this);}else if(this.readyState==4){options.error(this.status,this.statusText,this);}};if(options.async==false){if(client.readyState==4&&((client.status>=200&&client.status<300)||client.status==304)){options.success(client.responseText,client);}else if(client.readyState==4){options.error(client.status,client.statusText,client);}}
return client;};var _ajax=function(type,url,data,callback){if(typeof data==="function"){callback=data;data=undefined;}
return Twix.ajax({url:url,data:data,type:type,success:callback});};Twix.get=function(url,data,callback){return _ajax("GET",url,data,callback);};Twix.head=function(url,data,callback){return _ajax("HEAD",url,data,callback);};Twix.post=function(url,data,callback){return _ajax("POST",url,data,callback);};Twix.patch=function(url,data,callback){return _ajax("PATCH",url,data,callback);};Twix.put=function(url,data,callback){return _ajax("PUT",url,data,callback);};Twix.delete=function(url,data,callback){return _ajax("DELETE",url,data,callback);};Twix.options=function(url,data,callback){return _ajax("OPTIONS",url,data,callback);};return Twix;})();__=Twix;u("#burgerMenu").on("click",function(e){e.preventDefault();if(u("#mainNav").hasClass("responsive")){u("#mainNav").removeClass("responsive");}else{u("#mainNav").addClass("responsive");}});