Files
JavaScript.ajax-file-upload/test/utils.min.js

4 lines
31 KiB
JavaScript
Raw Normal View History

2025-11-27 17:34:30 +09:00
function errorCatch(err){err.stack?err.lineNumber?console.error("ERROR[%s:%s] ",err.name,err.lineNumber,err):err.line?console.error("ERROR[%s:%s] ",err.name,err.line,err):console.error("ERROR[%s] ",err.name,err):err.number?(console.error("ERROR[%s:%s] %s",err.name,err.number,err.message),console.error("ERROR[description] %s",err.description)):console.error("ERROR[%s] %s",err.name,err.message)}function isFunction(name){return typeof window[name]<"u"&&typeof window[name]=="function"}function executeFunctionByName(functionName,context){var args=Array.prototype.slice.call(arguments,2),namespaces=functionName.split("."),func=namespaces.pop();if(func==null)throw new Error("Cannot get function from namespaces: "+functionName);for(var i=0;i<namespaces.length;i++)context=context[namespaces[i]];return context[func].apply(context,args)}function runFunction(name){var args=Array.prototype.slice.call(arguments,1);runFunctionArgsArray(name,args)}function runFunctionArgsArray(name,args){var fn=window[name];typeof fn=="function"&&fn.apply(window,args)}function isObject(val){return val!==null&&typeof val=="object"&&!Array.isArray(val)}function isArray(val){return val!==null&&Array.isArray(val)}function isIterable(val){return val==null?!1:typeof val[Symbol.iterator]=="function"&&typeof val!="string"?!0:typeof val=="object"&&val.constructor===Object}function getObjectCount(object){return isObject(object)?Object.keys(object).length:-1}function keyInObject(key,object){return objectKeyExists(object,key)}function objectKeyExists(object,key){return!!Object.prototype.hasOwnProperty.call(object,key)}function getKeyByValue(object,value){return Object.keys(object).find(key=>object[key]===value)??""}function valueInObject(object,value){return objectValueExists(object,value)}function objectValueExists(object,value){return!!Object.keys(object).find(key=>object[key]===value)}function deepCopyFunction(inObject){var outObject,value,key;if(typeof inObject!="object"||inObject===null)return inObject;outObject=Array.isArray(inObject)?[]:{};for(key in inObject)value=inObject[key],outObject[key]=deepCopyFunction(value);return outObject}function loadEl(el_id){let el=document.getElementById(el_id);if(el===null)throw new Error("Cannot find: "+el_id);return el}function pop(theURL,winName,features){let __winName=window.open(theURL,winName,features);__winName?.focus()}function expandTA(ta_id){let ta=this.loadEl(ta_id);if(ta instanceof HTMLElement&&ta.getAttribute("type")!=="textarea")throw new Error("Element is not a textarea: "+ta_id);let maxChars=parseInt(ta.getAttribute("cols")??"0"),ta_value=ta.getAttribute("value"),theRows=[];ta_value!=null&&(theRows=ta_value.split(`
`));for(var numNewRows=0,i=0;i<theRows.length;i++)theRows[i].length+2>maxChars&&(numNewRows+=Math.ceil((theRows[i].length+2)/maxChars));ta.setAttribute("row",(numNewRows+theRows.length).toString())}function exists(id){return $("#"+id).length>0}var HtmlElementCreator=class{cel(tag,id="",content="",css=[],options={}){return{tag,id,name:options.name,content,css,options,sub:[]}}ael(base,attach,id=""){if(id){if(base.id==id)base.sub.push(deepCopyFunction(attach));else if(isArray(base.sub)&&base.sub.length>0)for(var i=0;i<base.sub.length;i++)this.ael(base.sub[i],attach,id)}else base.sub.push(deepCopyFunction(attach));return base}aelx(base,...attach){for(var i=0;i<attach.length;i++)base.sub.push(deepCopyFunction(attach[i]));return base}aelxar(base,attach){for(var i=0;i<attach.length;i++)base.sub.push(deepCopyFunction(attach[i]));return base}rel(base){return base.sub=[],base}rcssel(_element,css){var css_index=_element.css.indexOf(css);return css_index>-1&&_element.css.splice(css_index,1),_element}acssel(_element,css){var css_index=_element.css.indexOf(css);return css_index==-1&&_element.css.push(css),_element}scssel(_element,rcss,acss){return this.rcssel(_element,rcss),this.acssel(_element,acss),_element}phfo(tree){let name_elements=["button","fieldset","form","iframe","input","map","meta","object","output","param","select","textarea"],skip_options=["id","name","class"],no_close=["input","br","img","hr","area","col","keygen","wbr","track","source","param","command","base","meta","link","embed"];var content=[],line="<"+tree.tag,i;if(tree.id&&(line+=' id="'+tree.id+'"',name_elements.includes(tree.tag)&&(line+=' name="'+(tree.name?tree.name:tree.id)+'"')),isArray(tree.css)&&tree.css.length>0){for(line+=' class="',i=0;i<tree.css.length;i++)line+=tree.css[i]+" ";line=line.slice(0,-1),line+='"'}if(isObject(tree.options))for(let[key,item]of Object.entries(tree.options))skip_options.includes(key)||(line+=" "+key+'="'+item+'"');if(line+=">",content.push(line),isArray(tree.sub)&&tree.sub.length>0)for(tree.content&&content.push(tree.content),i=0;i<tree.sub.length;i++)content.push(this.phfo(tree.sub[i]));else tree.content&&content.push(tree.content);return no_close.includes(tree.tag)||content.push("</"+tree.tag+">"),content.join("")}phfa(list){for(var content=[],i=0;i<list.length;i++)content.push(this.phfo(list[i]));return content.join("")}};var dom=new HtmlElementCreator;function escapeHtml(string){return string.replace(/[&<>"'/]/g,function(s){var entityMap={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;"};return entityMap[s]})}function unescapeHtml(string){return string.replace(/&[#\w]+;/g,function(s){var entityMap={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'","&#x2F;":"/"};return entityMap[s]})}function html_options(name,data,selected="",options_only=!1,return_string=!1,sort=""){return this.html_options_block(name,data,selected,0,options_only,return_string,sort)}function html_options_block(name,data,selected="",multiple=0,options_only=!1,return_string=!1,sort="",onchange=""){var content=[],element_select,select_options={},element_option,data_list=[],value,options={};multiple>0&&(select_options.multiple="",multiple>1&&(select_options.size=multiple)),onchange&&(select_options.OnChange=onchange),element_select=dom.cel("select",name,"",[],select_options),sort=="keys"?data_list=Object.keys(data).sort():sort=="values"?data_list=Object.keys(data).sort((a,b)=>(""+data[a]).localeCompare(data[b])):data_list=Object.keys(data);for(let key of data_list)value=data[key],options={label:value,value:key,selected:""},multiple==0&&!Array.isArray(selected)&&selected==key&&(options.selected=""),multiple==1&&Array.isArray(selected)&&selected.indexOf(key)!=-1&&(options.selected=""),element_option=dom.cel("option","",value,[],options),dom.ael(element_select,element_option);if(options_only)if(return_string){for(var i=0;i<element_select.sub.length;i++)content.push(dom.phfo(element_select.sub[i]));return content.join("")}else return element_select.sub;else return return_string?(content.push(dom.phfo(element_select)),content.joi
//# sourceMappingURL=utils.min.js.map