forked from beego/admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphpjs-min.js
executable file
·10 lines (10 loc) · 11.4 KB
/
phpjs-min.js
1
2
3
4
5
6
7
8
9
10
/**
* Created with JetBrains PhpStorm.
* User: liuzhiming
* Date: 12-11-9
* Time: 下午5:08
* To change this template use File | Settings | File Templates.
*/
(function(window,undefined){var phpjs=window.phpjs||{};phpjs.array_intersect=function(arr1){var retArr={},argl=arguments.length,arglm1=argl-1,k1="",arr={},i=0,k="";arr1keys:for(k1 in arr1){arrs:for(i=1;i<argl;i++){arr=arguments[i];for(k in arr){if(arr[k]===arr1[k1]){if(i===arglm1){retArr[k1]=arr1[k1]}continue arrs}}continue arr1keys}}return retArr};phpjs.array_diff_key=function(arr1){var argl=arguments.length,retArr={},k1="",i=1,k="",arr={};arr1keys:for(k1 in arr1){for(i=1;i<argl;i++){arr=arguments[i];for(k in arr){if(k===k1){continue arr1keys}}retArr[k1]=arr1[k1]}}return retArr};phpjs.array_merge=function(){var args=Array.prototype.slice.call(arguments),argl=args.length,arg,retObj={},k="",argil=0,j=0,i=0,ct=0,toStr=Object.prototype.toString,retArr=true;for(i=0;i<argl;i++){if(toStr.call(args[i])!=="[object Array]"){retArr=false;break}}if(retArr){retArr=[];for(i=0;i<argl;i++){retArr=retArr.concat(args[i])}return retArr}for(i=0,ct=0;i<argl;i++){arg=args[i];if(toStr.call(arg)==="[object Array]"){for(j=0,argil=arg.length;j<argil;j++){retObj[ct++]=arg[j]}}else{for(k in arg){if(arg.hasOwnProperty(k)){if(parseInt(k,10)+""===k){retObj[ct++]=arg[k]}else{retObj[k]=arg[k]}}}}}return retObj};phpjs.time=function(){return Math.floor(new Date().getTime()/1000)};phpjs.strtotime=function strtotime(str,now){var i,match,s,strTmp="",parse="";strTmp=str;strTmp=strTmp.replace(/\s{2,}|^\s|\s$/g," ");strTmp=strTmp.replace(/[\t\r\n]/g,"");if(strTmp=="now"){return(new Date()).getTime()/1000}else{if(!isNaN(parse=Date.parse(strTmp))){return(parse/1000)}else{if(now){now=new Date(now*1000)}else{now=new Date()}}}strTmp=strTmp.toLowerCase();var __is={day:{"sun":0,"mon":1,"tue":2,"wed":3,"thu":4,"fri":5,"sat":6},mon:{"jan":0,"feb":1,"mar":2,"apr":3,"may":4,"jun":5,"jul":6,"aug":7,"sep":8,"oct":9,"nov":10,"dec":11}};var process=function(m){var ago=(m[2]&&m[2]=="ago");var num=(num=m[0]=="last"?-1:1)*(ago?-1:1);switch(m[0]){case"last":case"next":switch(m[1].substring(0,3)){case"yea":now.setFullYear(now.getFullYear()+num);break;case"mon":now.setMonth(now.getMonth()+num);break;case"wee":now.setDate(now.getDate()+(num*7));break;case"day":now.setDate(now.getDate()+num);break;case"hou":now.setHours(now.getHours()+num);break;case"min":now.setMinutes(now.getMinutes()+num);break;case"sec":now.setSeconds(now.getSeconds()+num);break;default:var day;if(typeof(day=__is.day[m[1].substring(0,3)])!="undefined"){var diff=day-now.getDay();if(diff==0){diff=7*num}else{if(diff>0){if(m[0]=="last"){diff-=7}}else{if(m[0]=="next"){diff+=7}}}now.setDate(now.getDate()+diff)}}break;default:if(/\d+/.test(m[0])){num*=parseInt(m[0],10);switch(m[1].substring(0,3)){case"yea":now.setFullYear(now.getFullYear()+num);break;case"mon":now.setMonth(now.getMonth()+num);break;case"wee":now.setDate(now.getDate()+(num*7));break;case"day":now.setDate(now.getDate()+num);break;case"hou":now.setHours(now.getHours()+num);break;case"min":now.setMinutes(now.getMinutes()+num);break;case"sec":now.setSeconds(now.getSeconds()+num);break}}else{return false}break}return true};match=strTmp.match(/^(\d{2,4}-\d{2}-\d{2})(?:\s(\d{1,2}:\d{2}(:\d{2})?)?(?:\.(\d+))?)?$/);if(match!=null){if(!match[2]){match[2]="00:00:00"}else{if(!match[3]){match[2]+=":00"}}s=match[1].split(/-/g);for(i in __is.mon){if(__is.mon[i]==s[1]-1){s[1]=i}}s[0]=parseInt(s[0],10);s[0]=(s[0]>=0&&s[0]<=69)?"20"+(s[0]<10?"0"+s[0]:s[0]+""):(s[0]>=70&&s[0]<=99)?"19"+s[0]:s[0]+"";return parseInt(this.strtotime(s[2]+" "+s[1]+" "+s[0]+" "+match[2])+(match[4]?match[4]/1000:""),10)}var regex="([+-]?\\d+\\s"+"(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?"+"|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday"+"|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday)"+"|(last|next)\\s"+"(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?"+"|sun\\.?|sunday|mon\\.?|monday|tue\\.?|tuesday|wed\\.?|wednesday"+"|thu\\.?|thursday|fri\\.?|friday|sat\\.?|saturday))"+"(\\sago)?";match=strTmp.match(new RegExp(regex,"gi"));if(match==null){return false}for(i=0;i<match.length;i++){if(!process(match[i].split(" "))){return false}}return(now.getTime()/1000)};phpjs.date=function(format,timestamp){var that=this,jsdate,f,formatChr=/\\?([a-z])/gi,formatChrCb,_pad=function(n,c){if((n=n+"").length<c){return new Array((++c)-n.length).join("0")+n}return n},txt_words=["Sun","Mon","Tues","Wednes","Thurs","Fri","Satur","January","February","March","April","May","June","July","August","September","October","November","December"];formatChrCb=function(t,s){return f[t]?f[t]():s};f={d:function(){return _pad(f.j(),2)},D:function(){return f.l().slice(0,3)},j:function(){return jsdate.getDate()},l:function(){return txt_words[f.w()]+"day"},N:function(){return f.w()||7},S:function(){var j=f.j();return j>4&&j<21?"th":{1:"st",2:"nd",3:"rd"}[j%10]||"th"},w:function(){return jsdate.getDay()},z:function(){var a=new Date(f.Y(),f.n()-1,f.j()),b=new Date(f.Y(),0,1);return Math.round((a-b)/86400000)+1},W:function(){var a=new Date(f.Y(),f.n()-1,f.j()-f.N()+3),b=new Date(a.getFullYear(),0,4);
return _pad(1+Math.round((a-b)/86400000/7),2)},F:function(){return txt_words[6+f.n()]},m:function(){return _pad(f.n(),2)},M:function(){return f.F().slice(0,3)},n:function(){return jsdate.getMonth()+1},t:function(){return(new Date(f.Y(),f.n(),0)).getDate()},L:function(){return new Date(f.Y(),1,29).getMonth()===1|0},o:function(){var n=f.n(),W=f.W(),Y=f.Y();return Y+(n===12&&W<9?-1:n===1&&W>9)},Y:function(){return jsdate.getFullYear()},y:function(){return(f.Y()+"").slice(-2)},a:function(){return jsdate.getHours()>11?"pm":"am"},A:function(){return f.a().toUpperCase()},B:function(){var H=jsdate.getUTCHours()*3600,i=jsdate.getUTCMinutes()*60,s=jsdate.getUTCSeconds();return _pad(Math.floor((H+i+s+3600)/86.4)%1000,3)},g:function(){return f.G()%12||12},G:function(){return jsdate.getHours()},h:function(){return _pad(f.g(),2)},H:function(){return _pad(f.G(),2)},i:function(){return _pad(jsdate.getMinutes(),2)},s:function(){return _pad(jsdate.getSeconds(),2)},u:function(){return _pad(jsdate.getMilliseconds()*1000,6)},e:function(){throw"Not supported (see source code of date() for timezone on how to add support)"},I:function(){var a=new Date(f.Y(),0),c=Date.UTC(f.Y(),0),b=new Date(f.Y(),6),d=Date.UTC(f.Y(),6);return 0+((a-c)!==(b-d))},O:function(){var tzo=jsdate.getTimezoneOffset(),a=Math.abs(tzo);return(tzo>0?"-":"+")+_pad(Math.floor(a/60)*100+a%60,4)},P:function(){var O=f.O();return(O.substr(0,3)+":"+O.substr(3,2))},T:function(){return"UTC"},Z:function(){return -jsdate.getTimezoneOffset()*60},c:function(){return"Y-m-d\\Th:i:sP".replace(formatChr,formatChrCb)},r:function(){return"D, d M Y H:i:s O".replace(formatChr,formatChrCb)},U:function(){return jsdate.getTime()/1000|0}};this.date=function(format,timestamp){that=this;jsdate=((typeof timestamp==="undefined")?new Date():(timestamp instanceof Date)?new Date(timestamp):new Date(timestamp*1000));return format.replace(formatChr,formatChrCb)};return this.date(format,timestamp)};phpjs.impload=function implode(glue,pieces){var i="",retVal="",tGlue="";if(arguments.length===1){pieces=glue;glue=""}if(typeof(pieces)==="object"){if(Object.prototype.toString.call(pieces)==="[object Array]"){return pieces.join(glue)}for(i in pieces){retVal+=tGlue+pieces[i];tGlue=glue}return retVal}return pieces};phpjs.expload=function explode(delimiter,string,limit){if(arguments.length<2||typeof delimiter=="undefined"||typeof string=="undefined"){return null}if(delimiter===""||delimiter===false||delimiter===null){return false}if(typeof delimiter=="function"||typeof delimiter=="object"||typeof string=="function"||typeof string=="object"){return{0:""}}if(delimiter===true){delimiter="1"}delimiter+="";string+="";var s=string.split(delimiter);if(typeof limit==="undefined"){return s}if(limit===0){limit=1}if(limit>0){if(limit>=s.length){return s}return s.slice(0,limit-1).concat([s.slice(limit-1).join(delimiter)])}if(-limit>=s.length){return[]}s.splice(s.length+limit);return s};phpjs.sprintf=function(){var regex=/%%|%(\d+\$)?([-+\'#0 ]*)(\*\d+\$|\*|\d+)?(\.(\*\d+\$|\*|\d+))?([scboxXuideEfFgG])/g;var a=arguments,i=0,format=a[i++];var pad=function(str,len,chr,leftJustify){if(!chr){chr=" "}var padding=(str.length>=len)?"":Array(1+len-str.length>>>0).join(chr);return leftJustify?str+padding:padding+str};var justify=function(value,prefix,leftJustify,minWidth,zeroPad,customPadChar){var diff=minWidth-value.length;if(diff>0){if(leftJustify||!zeroPad){value=pad(value,minWidth,customPadChar,leftJustify)}else{value=value.slice(0,prefix.length)+pad("",diff,"0",true)+value.slice(prefix.length)}}return value};var formatBaseX=function(value,base,prefix,leftJustify,minWidth,precision,zeroPad){var number=value>>>0;prefix=prefix&&number&&{"2":"0b","8":"0","16":"0x"}[base]||"";value=prefix+pad(number.toString(base),precision||0,"0",false);return justify(value,prefix,leftJustify,minWidth,zeroPad)};var formatString=function(value,leftJustify,minWidth,precision,zeroPad,customPadChar){if(precision!=null){value=value.slice(0,precision)}return justify(value,"",leftJustify,minWidth,zeroPad,customPadChar)};var doFormat=function(substring,valueIndex,flags,minWidth,_,precision,type){var number;var prefix;var method;var textTransform;var value;if(substring=="%%"){return"%"}var leftJustify=false,positivePrefix="",zeroPad=false,prefixBaseX=false,customPadChar=" ";var flagsl=flags.length;for(var j=0;flags&&j<flagsl;j++){switch(flags.charAt(j)){case" ":positivePrefix=" ";break;case"+":positivePrefix="+";break;case"-":leftJustify=true;break;case"'":customPadChar=flags.charAt(j+1);break;case"0":zeroPad=true;break;case"#":prefixBaseX=true;break}}if(!minWidth){minWidth=0}else{if(minWidth=="*"){minWidth=+a[i++]}else{if(minWidth.charAt(0)=="*"){minWidth=+a[minWidth.slice(1,-1)]}else{minWidth=+minWidth}}}if(minWidth<0){minWidth=-minWidth;leftJustify=true}if(!isFinite(minWidth)){throw new Error("sprintf: (minimum-)width must be finite")}if(!precision){precision="fFeE".indexOf(type)>-1?6:(type=="d")?0:undefined}else{if(precision=="*"){precision=+a[i++]
}else{if(precision.charAt(0)=="*"){precision=+a[precision.slice(1,-1)]}else{precision=+precision}}}value=valueIndex?a[valueIndex.slice(0,-1)]:a[i++];switch(type){case"s":return formatString(String(value),leftJustify,minWidth,precision,zeroPad,customPadChar);case"c":return formatString(String.fromCharCode(+value),leftJustify,minWidth,precision,zeroPad);case"b":return formatBaseX(value,2,prefixBaseX,leftJustify,minWidth,precision,zeroPad);case"o":return formatBaseX(value,8,prefixBaseX,leftJustify,minWidth,precision,zeroPad);case"x":return formatBaseX(value,16,prefixBaseX,leftJustify,minWidth,precision,zeroPad);case"X":return formatBaseX(value,16,prefixBaseX,leftJustify,minWidth,precision,zeroPad).toUpperCase();case"u":return formatBaseX(value,10,prefixBaseX,leftJustify,minWidth,precision,zeroPad);case"i":case"d":number=+value||0;number=Math.round(number-number%1);prefix=number<0?"-":positivePrefix;value=prefix+pad(String(Math.abs(number)),precision,"0",false);return justify(value,prefix,leftJustify,minWidth,zeroPad);case"e":case"E":case"f":case"F":case"g":case"G":number=+value;prefix=number<0?"-":positivePrefix;method=["toExponential","toFixed","toPrecision"]["efg".indexOf(type.toLowerCase())];textTransform=["toString","toUpperCase"]["eEfFgG".indexOf(type)%2];value=prefix+Math.abs(number)[method](precision);return justify(value,prefix,leftJustify,minWidth,zeroPad)[textTransform]();default:return substring}};return format.replace(regex,doFormat)};window.phpjs=phpjs}(window));