1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
| function explode(inputstring, separators, includeEmpties) { inputstring = new String(inputstring); separators = new String(separators); if (separators == "undefined") { separators = " :;"; } fixedExplode = new Array(1); currentElement = ""; count = 0; for (x = 0; x < inputstring.length; x++) { str = inputstring.charAt(x); if (separators.indexOf(str) != -1) { if (((includeEmpties <= 0) || (includeEmpties == false)) && (currentElement == "")) {} else { fixedExplode[count] = currentElement; count++; currentElement = ""; } } else { currentElement += str; } } if ((!(includeEmpties <= 0) && (includeEmpties != false)) || (currentElement != "")) { fixedExplode[count] = currentElement; } return fixedExplode; }
function getQueryStr(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return decodeURIComponent(r[2]); return null; }
function randBetween(Min, Max) { var Range = Max - Min; var Rand = Math.random(); var num = Min + Math.round(Rand * Range); return num; }
function getQueryStr(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return decodeURIComponent(r[2]); return null; }
function createBitmapByName(name: string) { let result = new egret.Bitmap(); let texture: egret.Texture = RES.getRes(name); if(!texture){ console.log("no image:"+name ); } result.texture = texture; return result; }
function doShot(obj:egret.DisplayObject,x:number=0,y=0,w=null,h=null){ let renderTexture = new egret.RenderTexture; renderTexture.drawToTexture(obj,new egret.Rectangle(x,y,w,h)); return renderTexture.toDataURL("image/jpeg",new egret.Rectangle(0,0,w,h)); }
function ajax({url,data,success,type="POST"}){ var xmlhttp = new XMLHttpRequest(); xmlhttp.withCredentials = false; xmlhttp.open(type, url, true); xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4){ if(xmlhttp.status == 200){ var res = xmlhttp.response success(JSON.parse(res)); }else{ success("error") console.log("ajax error"); } } } xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded;"); xmlhttp.send(buildForm(data,null)); }
function buildForm (data: any, query: any): string { let params: any = []; if (data) { for (let n in data) { params.push(encodeURIComponent(n) + "=" + encodeURIComponent(data[n])); } } if (query) { params = params.concat(query); } return params.join("&"); };
function setStyle(obj,style){ for (var key in style) { let val = style[key]; let sty = obj.style; sty[key] = val; } }
function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"]; var flag = true; for (var v = 0; v < Agents.length; v++) { if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; } } return flag; }
function getCookie(name) { var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)"); if(arr=document.cookie.match(reg)) return unescape(arr[2]); else return null; }
function getExtension(filename) { var index1 = filename.lastIndexOf("."); if(index1 < 0){ return null; } var index2 = filename.length; var postf = filename.substring(index1+1,index2); return postf; }
function strPad(str) { var pad = "00000" return pad.substring(0, pad.length - str.length) + str }
function getRootPath() { var pathName = window.location.pathname.substring(1); var webName = pathName == '' ? '' : pathName.substring(0, pathName.indexOf('/')); if (webName == "") { return window.location.protocol + '//' + window.location.host; } else { return window.location.protocol + '//' + window.location.host + '/' + webName; } }
function randomsort(a, b) { return Math.random()>.5 ? -1 : 1; } var arr = [1, 2, 3, 4, 5]; arr.sort(randomsort);
|