let util = { context_menu(target,opt,other_targets=[]){ /* opt = {"menu":[ {"name":string, "callback": function} , ... ],!"settings":{ x:int, y:int, height:int, width:int }} ! is optional */ function mm(){ target.oncontextmenu = ((ev)=>{ if(ev.target!=target&&other_targets.includes(ev.target)==false) return function clean(){ try{document.getElementById(target.id+"-menu").remove()}catch(e){} let nu = document.getElementsByClassName('context-menu-root') for(let i = nu.length -1;i>=0;i--){ nu.item(i).remove() } } if(!(window.contextm == null || window.contextm.tokill == null)){ for(let i in window.contextm.tokill){ window.contextm.tokill[i]() } window.contextm.tokill = null } document.body.addEventListener("click",function tem(){ clean() document.body.removeEventListener("click",tem) }) //console.log(ev) clean() //if(window.contextm == null || window.contextm.tokill == null){ window.contextm = {} if(opt.on_exit!=null) window.contextm.tokill = [opt.on_exit] //} else { //} let aa = "" for(let op of opt.menu){ if(op=="seper") aa+="
" else if(op.allow_if == undefined || op.allow_if()) aa+=` ` else aa+=` ` } appendHtml(target," ") for(let op of opt.menu){ if(op!="seper"&&(op.allow_if == undefined || op.allow_if())) document.getElementById(`${target.id}-menu-${opt.menu.indexOf(op)}`).onclick = (()=>{ op.callback() }) } return false }) }; mm() return ({append:function append(items){ opt.menu.push(items) mm() }}) }, scrollbar(uid,minor_uid,root,target){ (()=>{ //root is the base of the window, only used for measuring //-- //target is where the scrollbar will be placed, this element should be //larger than the root with scrollable overflow let scrolling = false //console.log(uid,minor_uid) //try{document.getElementById(uid + "-" + minor_uid + "-content-scrollbar").remove()}catch(e){console.log(e)} if(undefined==procs[uid]) procs[uid] = {} //console.log("'" + uid + "-" + minor_uid + "-content-scrollbar'") appendHtml(target," ") let thi_point = document.getElementById(uid + "-" + minor_uid + "-content-scrollbar-point") let thi_base = document.getElementById(uid + "-" + minor_uid + "-content-scrollbar") procs[uid].refresh = ()=>{ //console.log(root.clientHeight / (target.clientHeight / root.clientHeight) / root.clientHeight) thi_point.style.display = "block" thi_base.style.display = "block" thi_point.style.height = root.clientHeight / (target.clientHeight / root.clientHeight) if(root.clientHeight / (target.clientHeight / root.clientHeight) / root.clientHeight >= 1){ thi_point.style.display = "none" thi_base.style.display = "none" } if(thi_base.clientHeight![]() | |
${ inp.content == undefined ? "Alert" : inp.content } | ${buttons} |