mirror of https://github.com/IoTcat/Ushio-js.git
Compare commits
2 Commits
84fafe8e34
...
98afc81d38
Author | SHA1 | Date |
---|---|---|
iotcat | 98afc81d38 | 4 years ago |
iotcat | 0b7a24cb98 | 4 years ago |
15 changed files with 687 additions and 22 deletions
@ -1,10 +1,11 @@ |
|||||||
npm i -g uglify-js |
#npm i -g uglify-js |
||||||
npm i -g uglifycss |
#npm i -g uglifycss |
||||||
cp *.css dist/ |
cp *.css dist/ |
||||||
cp *.js dist/ |
cp *.js dist/ |
||||||
terser dist/ushio-footer.js -m -o dist/ushio-footer.min.js --source-map url='dist/ushio-footer.min.js.map' |
cd dist/ |
||||||
uglifyjs dist/ushio-head.js -m -o dist/ushio-head.min.js --source-map url='dist/ushio-head.min.js.map' |
terser ./ushio-footer.js -m -o ./ushio-footer.min.js --source-map url='/ushio-footer.min.js.map' |
||||||
uglifyjs dist/jquery.md5.js -m -o dist/jquery.md5.min.js --source-map url='dist/jquery.md5.min.js.map' |
uglifyjs ./ushio-head.js -m -o ./ushio-head.min.js --source-map url='/ushio-head.min.js.map' |
||||||
uglifycss dist/ushio-js.css > dist/ushio-js.min.css |
uglifyjs ./jquery.md5.js -m -o ./jquery.md5.min.js --source-map url='/jquery.md5.min.js.map' |
||||||
uglifycss dist/ushio-js.mobile.css > dist/ushio-js.mobile.min.css |
uglifycss ./ushio-js.css > ./ushio-js.min.css |
||||||
uglifycss dist/ushio-js.tips.css > dist/ushio-js.tips.min.css |
uglifycss ./ushio-js.mobile.css > ./ushio-js.mobile.min.css |
||||||
|
uglifycss ./ushio-js.tips.css > ./ushio-js.tips.min.css |
||||||
|
@ -1,2 +1,2 @@ |
|||||||
(function(r){var v=function(r,n){return r<<n|r>>>32-n};var k=function(r,n){var t,a,e,o,u;e=r&2147483648;o=n&2147483648;t=r&1073741824;a=n&1073741824;u=(r&1073741823)+(n&1073741823);if(t&a)return u^2147483648^e^o;if(t|a){if(u&1073741824)return u^3221225472^e^o;else return u^1073741824^e^o}else{return u^e^o}};var f=function(r,n,t){return r&n|~r&t};var i=function(r,n,t){return r&t|n&~t};var c=function(r,n,t){return r^n^t};var C=function(r,n,t){return n^(r|~t)};var q=function(r,n,t,a,e,o,u){r=k(r,k(k(f(n,t,a),e),u));return k(v(r,o),n)};var z=function(r,n,t,a,e,o,u){r=k(r,k(k(i(n,t,a),e),u));return k(v(r,o),n)};var B=function(r,n,t,a,e,o,u){r=k(r,k(k(c(n,t,a),e),u));return k(v(r,o),n)};var D=function(r,n,t,a,e,o,u){r=k(r,k(k(C(n,t,a),e),u));return k(v(r,o),n)};var E=function(r){var n;var t=r.length;var a=t+8;var e=(a-a%64)/64;var o=(e+1)*16;var u=Array(o-1);var v=0;var f=0;while(f<t){n=(f-f%4)/4;v=f%4*8;u[n]=u[n]|r.charCodeAt(f)<<v;f++}n=(f-f%4)/4;v=f%4*8;u[n]=u[n]|128<<v;u[o-2]=t<<3;u[o-1]=t>>>29;return u};var F=function(r){var n="",t="",a,e;for(e=0;e<=3;e++){a=r>>>e*8&255;t="0"+a.toString(16);n=n+t.substr(t.length-2,2)}return n};var G=function(r){r=r.replace(/\x0d\x0a/g,"\n");var n="";for(var t=0;t<r.length;t++){var a=r.charCodeAt(t);if(a<128){n+=String.fromCharCode(a)}else if(a>127&&a<2048){n+=String.fromCharCode(a>>6|192);n+=String.fromCharCode(a&63|128)}else{n+=String.fromCharCode(a>>12|224);n+=String.fromCharCode(a>>6&63|128);n+=String.fromCharCode(a&63|128)}}return n};r.extend({md5:function(r){var n=Array();var t,a,e,o,u,v,f,i,c;var C=7,h=12,g=17,d=22;var l=5,m=9,s=14,S=20;var A=4,x=11,y=16,w=23;var b=6,j=10,p=15,L=21;r=G(r);n=E(r);v=1732584193;f=4023233417;i=2562383102;c=271733878;for(t=0;t<n.length;t+=16){a=v;e=f;o=i;u=c;v=q(v,f,i,c,n[t+0],C,3614090360);c=q(c,v,f,i,n[t+1],h,3905402710);i=q(i,c,v,f,n[t+2],g,606105819);f=q(f,i,c,v,n[t+3],d,3250441966);v=q(v,f,i,c,n[t+4],C,4118548399);c=q(c,v,f,i,n[t+5],h,1200080426);i=q(i,c,v,f,n[t+6],g,2821735955);f=q(f,i,c,v,n[t+7],d,4249261313);v=q(v,f,i,c,n[t+8],C,1770035416);c=q(c,v,f,i,n[t+9],h,2336552879);i=q(i,c,v,f,n[t+10],g,4294925233);f=q(f,i,c,v,n[t+11],d,2304563134);v=q(v,f,i,c,n[t+12],C,1804603682);c=q(c,v,f,i,n[t+13],h,4254626195);i=q(i,c,v,f,n[t+14],g,2792965006);f=q(f,i,c,v,n[t+15],d,1236535329);v=z(v,f,i,c,n[t+1],l,4129170786);c=z(c,v,f,i,n[t+6],m,3225465664);i=z(i,c,v,f,n[t+11],s,643717713);f=z(f,i,c,v,n[t+0],S,3921069994);v=z(v,f,i,c,n[t+5],l,3593408605);c=z(c,v,f,i,n[t+10],m,38016083);i=z(i,c,v,f,n[t+15],s,3634488961);f=z(f,i,c,v,n[t+4],S,3889429448);v=z(v,f,i,c,n[t+9],l,568446438);c=z(c,v,f,i,n[t+14],m,3275163606);i=z(i,c,v,f,n[t+3],s,4107603335);f=z(f,i,c,v,n[t+8],S,1163531501);v=z(v,f,i,c,n[t+13],l,2850285829);c=z(c,v,f,i,n[t+2],m,4243563512);i=z(i,c,v,f,n[t+7],s,1735328473);f=z(f,i,c,v,n[t+12],S,2368359562);v=B(v,f,i,c,n[t+5],A,4294588738);c=B(c,v,f,i,n[t+8],x,2272392833);i=B(i,c,v,f,n[t+11],y,1839030562);f=B(f,i,c,v,n[t+14],w,4259657740);v=B(v,f,i,c,n[t+1],A,2763975236);c=B(c,v,f,i,n[t+4],x,1272893353);i=B(i,c,v,f,n[t+7],y,4139469664);f=B(f,i,c,v,n[t+10],w,3200236656);v=B(v,f,i,c,n[t+13],A,681279174);c=B(c,v,f,i,n[t+0],x,3936430074);i=B(i,c,v,f,n[t+3],y,3572445317);f=B(f,i,c,v,n[t+6],w,76029189);v=B(v,f,i,c,n[t+9],A,3654602809);c=B(c,v,f,i,n[t+12],x,3873151461);i=B(i,c,v,f,n[t+15],y,530742520);f=B(f,i,c,v,n[t+2],w,3299628645);v=D(v,f,i,c,n[t+0],b,4096336452);c=D(c,v,f,i,n[t+7],j,1126891415);i=D(i,c,v,f,n[t+14],p,2878612391);f=D(f,i,c,v,n[t+5],L,4237533241);v=D(v,f,i,c,n[t+12],b,1700485571);c=D(c,v,f,i,n[t+3],j,2399980690);i=D(i,c,v,f,n[t+10],p,4293915773);f=D(f,i,c,v,n[t+1],L,2240044497);v=D(v,f,i,c,n[t+8],b,1873313359);c=D(c,v,f,i,n[t+15],j,4264355552);i=D(i,c,v,f,n[t+6],p,2734768916);f=D(f,i,c,v,n[t+13],L,1309151649);v=D(v,f,i,c,n[t+4],b,4149444226);c=D(c,v,f,i,n[t+11],j,3174756917);i=D(i,c,v,f,n[t+2],p,718787259);f=D(f,i,c,v,n[t+9],L,3951481745);v=k(v,a);f=k(f,e);i=k(i,o);c=k(c,u)}var Q=F(v)+F(f)+F(i)+F(c);return Q.toLowerCase()}})})(jQuery); |
(function(r){var v=function(r,n){return r<<n|r>>>32-n};var k=function(r,n){var t,a,e,o,u;e=r&2147483648;o=n&2147483648;t=r&1073741824;a=n&1073741824;u=(r&1073741823)+(n&1073741823);if(t&a)return u^2147483648^e^o;if(t|a){if(u&1073741824)return u^3221225472^e^o;else return u^1073741824^e^o}else{return u^e^o}};var f=function(r,n,t){return r&n|~r&t};var i=function(r,n,t){return r&t|n&~t};var c=function(r,n,t){return r^n^t};var C=function(r,n,t){return n^(r|~t)};var q=function(r,n,t,a,e,o,u){r=k(r,k(k(f(n,t,a),e),u));return k(v(r,o),n)};var z=function(r,n,t,a,e,o,u){r=k(r,k(k(i(n,t,a),e),u));return k(v(r,o),n)};var B=function(r,n,t,a,e,o,u){r=k(r,k(k(c(n,t,a),e),u));return k(v(r,o),n)};var D=function(r,n,t,a,e,o,u){r=k(r,k(k(C(n,t,a),e),u));return k(v(r,o),n)};var E=function(r){var n;var t=r.length;var a=t+8;var e=(a-a%64)/64;var o=(e+1)*16;var u=Array(o-1);var v=0;var f=0;while(f<t){n=(f-f%4)/4;v=f%4*8;u[n]=u[n]|r.charCodeAt(f)<<v;f++}n=(f-f%4)/4;v=f%4*8;u[n]=u[n]|128<<v;u[o-2]=t<<3;u[o-1]=t>>>29;return u};var F=function(r){var n="",t="",a,e;for(e=0;e<=3;e++){a=r>>>e*8&255;t="0"+a.toString(16);n=n+t.substr(t.length-2,2)}return n};var G=function(r){r=r.replace(/\x0d\x0a/g,"\n");var n="";for(var t=0;t<r.length;t++){var a=r.charCodeAt(t);if(a<128){n+=String.fromCharCode(a)}else if(a>127&&a<2048){n+=String.fromCharCode(a>>6|192);n+=String.fromCharCode(a&63|128)}else{n+=String.fromCharCode(a>>12|224);n+=String.fromCharCode(a>>6&63|128);n+=String.fromCharCode(a&63|128)}}return n};r.extend({md5:function(r){var n=Array();var t,a,e,o,u,v,f,i,c;var C=7,h=12,g=17,d=22;var l=5,m=9,s=14,S=20;var A=4,x=11,y=16,w=23;var b=6,j=10,p=15,L=21;r=G(r);n=E(r);v=1732584193;f=4023233417;i=2562383102;c=271733878;for(t=0;t<n.length;t+=16){a=v;e=f;o=i;u=c;v=q(v,f,i,c,n[t+0],C,3614090360);c=q(c,v,f,i,n[t+1],h,3905402710);i=q(i,c,v,f,n[t+2],g,606105819);f=q(f,i,c,v,n[t+3],d,3250441966);v=q(v,f,i,c,n[t+4],C,4118548399);c=q(c,v,f,i,n[t+5],h,1200080426);i=q(i,c,v,f,n[t+6],g,2821735955);f=q(f,i,c,v,n[t+7],d,4249261313);v=q(v,f,i,c,n[t+8],C,1770035416);c=q(c,v,f,i,n[t+9],h,2336552879);i=q(i,c,v,f,n[t+10],g,4294925233);f=q(f,i,c,v,n[t+11],d,2304563134);v=q(v,f,i,c,n[t+12],C,1804603682);c=q(c,v,f,i,n[t+13],h,4254626195);i=q(i,c,v,f,n[t+14],g,2792965006);f=q(f,i,c,v,n[t+15],d,1236535329);v=z(v,f,i,c,n[t+1],l,4129170786);c=z(c,v,f,i,n[t+6],m,3225465664);i=z(i,c,v,f,n[t+11],s,643717713);f=z(f,i,c,v,n[t+0],S,3921069994);v=z(v,f,i,c,n[t+5],l,3593408605);c=z(c,v,f,i,n[t+10],m,38016083);i=z(i,c,v,f,n[t+15],s,3634488961);f=z(f,i,c,v,n[t+4],S,3889429448);v=z(v,f,i,c,n[t+9],l,568446438);c=z(c,v,f,i,n[t+14],m,3275163606);i=z(i,c,v,f,n[t+3],s,4107603335);f=z(f,i,c,v,n[t+8],S,1163531501);v=z(v,f,i,c,n[t+13],l,2850285829);c=z(c,v,f,i,n[t+2],m,4243563512);i=z(i,c,v,f,n[t+7],s,1735328473);f=z(f,i,c,v,n[t+12],S,2368359562);v=B(v,f,i,c,n[t+5],A,4294588738);c=B(c,v,f,i,n[t+8],x,2272392833);i=B(i,c,v,f,n[t+11],y,1839030562);f=B(f,i,c,v,n[t+14],w,4259657740);v=B(v,f,i,c,n[t+1],A,2763975236);c=B(c,v,f,i,n[t+4],x,1272893353);i=B(i,c,v,f,n[t+7],y,4139469664);f=B(f,i,c,v,n[t+10],w,3200236656);v=B(v,f,i,c,n[t+13],A,681279174);c=B(c,v,f,i,n[t+0],x,3936430074);i=B(i,c,v,f,n[t+3],y,3572445317);f=B(f,i,c,v,n[t+6],w,76029189);v=B(v,f,i,c,n[t+9],A,3654602809);c=B(c,v,f,i,n[t+12],x,3873151461);i=B(i,c,v,f,n[t+15],y,530742520);f=B(f,i,c,v,n[t+2],w,3299628645);v=D(v,f,i,c,n[t+0],b,4096336452);c=D(c,v,f,i,n[t+7],j,1126891415);i=D(i,c,v,f,n[t+14],p,2878612391);f=D(f,i,c,v,n[t+5],L,4237533241);v=D(v,f,i,c,n[t+12],b,1700485571);c=D(c,v,f,i,n[t+3],j,2399980690);i=D(i,c,v,f,n[t+10],p,4293915773);f=D(f,i,c,v,n[t+1],L,2240044497);v=D(v,f,i,c,n[t+8],b,1873313359);c=D(c,v,f,i,n[t+15],j,4264355552);i=D(i,c,v,f,n[t+6],p,2734768916);f=D(f,i,c,v,n[t+13],L,1309151649);v=D(v,f,i,c,n[t+4],b,4149444226);c=D(c,v,f,i,n[t+11],j,3174756917);i=D(i,c,v,f,n[t+2],p,718787259);f=D(f,i,c,v,n[t+9],L,3951481745);v=k(v,a);f=k(f,e);i=k(i,o);c=k(c,u)}var Q=F(v)+F(f)+F(i)+F(c);return Q.toLowerCase()}})})(jQuery); |
||||||
//# sourceMappingURL=dist/jquery.md5.min.js.map
|
//# sourceMappingURL=C
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,263 @@ |
|||||||
|
/*! |
||||||
|
* translater.js v1.0.12 |
||||||
|
* Simple translation tools. |
||||||
|
*
|
||||||
|
* Copyright (c) 2018 kenny wong <wowohoo@qq.com> |
||||||
|
* http://jaywcjlove.github.io/translater.js/
|
||||||
|
*
|
||||||
|
* Licensed under the MIT license. |
||||||
|
*/ |
||||||
|
(function(f) { |
||||||
|
if (typeof exports === "object" && typeof module !== "undefined") { |
||||||
|
module.exports = f(); |
||||||
|
} else if (typeof define === "function" && define.amd) { |
||||||
|
define([], f); |
||||||
|
} else { |
||||||
|
var g; |
||||||
|
if (typeof window !== "undefined") { |
||||||
|
g = window; |
||||||
|
} else if (typeof global !== "undefined") { |
||||||
|
g = global; |
||||||
|
} else if (typeof self !== "undefined") { |
||||||
|
g = self; |
||||||
|
} else { |
||||||
|
g = this; |
||||||
|
} |
||||||
|
g.Translater = f(); |
||||||
|
} |
||||||
|
})(function() { |
||||||
|
var define, module, exports; |
||||||
|
var Translater = function(option, callback) { |
||||||
|
// 默认给URL参数 ?lang=en
|
||||||
|
option = option || {}; |
||||||
|
if (getUrlParam("lang")) { |
||||||
|
option.lang = getUrlParam("lang"); |
||||||
|
} |
||||||
|
if (option.lang) { |
||||||
|
setCookie("t-lang", option.lang, 24); |
||||||
|
this.lang_name = option.lang; |
||||||
|
} else { |
||||||
|
this.lang_name = "default"; |
||||||
|
} |
||||||
|
// 回调函数
|
||||||
|
this.callback = callback || function() {}; |
||||||
|
this.langs = getElems() || []; |
||||||
|
if (this.lang_name !== "default") this.setLang(option.lang); |
||||||
|
var lang = getCookie("t-lang"); |
||||||
|
lang && lang !== "default" && this.setLang(lang); |
||||||
|
}; |
||||||
|
Translater.prototype = { |
||||||
|
setLang: function(name, elms) { |
||||||
|
var langs = elms || this.langs, method = ""; |
||||||
|
this.lang_name = name; |
||||||
|
for (var i = 0; i < langs.length; i++) { |
||||||
|
if (langs[i]["lang-" + name] || langs[i][name]) { |
||||||
|
if (langs[i].element.tagName === "TITLE") { |
||||||
|
method = "innerHTML"; |
||||||
|
} else if (langs[i].element.tagName === "IMG") { |
||||||
|
method = langs[i]["type"]; |
||||||
|
} else if (langs[i].element.tagName === "INPUT") { |
||||||
|
method = langs[i]["type"]; |
||||||
|
} else { |
||||||
|
method = "nodeValue"; |
||||||
|
} |
||||||
|
langs[i].element[method] = langs[i]["lang-" + name] || langs[i][name]; |
||||||
|
} else { |
||||||
|
this.setLang(name, langs[i]); |
||||||
|
} |
||||||
|
} |
||||||
|
setCookie("t-lang", name, 24); |
||||||
|
}, |
||||||
|
getLang: function() { |
||||||
|
return this.lang_name; |
||||||
|
} |
||||||
|
}; |
||||||
|
//获取 COOKIE
|
||||||
|
function getCookie(name) { |
||||||
|
var nameEQ = name + "="; |
||||||
|
var ca = document.cookie.split(";"); |
||||||
|
//把cookie分割成组
|
||||||
|
for (var i = 0; i < ca.length; i++) { |
||||||
|
var c = ca[i]; |
||||||
|
//取得字符串
|
||||||
|
while (c.charAt(0) == " ") { |
||||||
|
//判断一下字符串有没有前导空格
|
||||||
|
c = c.substring(1, c.length); |
||||||
|
} |
||||||
|
if (c.indexOf(nameEQ) == 0) { |
||||||
|
//如果含有我们要的name
|
||||||
|
return unescape(c.substring(nameEQ.length, c.length)); |
||||||
|
} |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
//设置 COOKIE
|
||||||
|
function setCookie(name, value, hours) { |
||||||
|
var date = new Date(); |
||||||
|
date.setTime(date.getTime() + Number(hours) * 3600 * 1e3); |
||||||
|
document.cookie = name + "=" + value + "; path=/;expires = " + date.toGMTString(); |
||||||
|
} |
||||||
|
// 获取所有节点里面的注释信息
|
||||||
|
// 返回一个数组
|
||||||
|
function getElems() { |
||||||
|
// var str = document.getElementById("box").innerHTML;
|
||||||
|
// var str1 = str.replace(/<.*>(.*)<.*>/i,"$1");
|
||||||
|
// var str2 = str.replace(/^.*<!--(.*)-->.*$/,"$1");
|
||||||
|
var elems = Array.prototype.concat(getTextNodes(document), getNodes(document, "IMG"), getNodes(document, "INPUT")); |
||||||
|
var emptyArray = []; |
||||||
|
var translateData = new Object(); |
||||||
|
for (var i = 0; i < elems.length; i++) { |
||||||
|
translateData = translater(elems[i]); |
||||||
|
var mTran = Object.getOwnPropertyNames(translateData); |
||||||
|
if (mTran.length >= 2 && mTran[0] == "0" || mTran.length > 2) { |
||||||
|
emptyArray.push(translateData); |
||||||
|
} |
||||||
|
} |
||||||
|
return emptyArray; |
||||||
|
} |
||||||
|
// 处理title里面的语言切换情况
|
||||||
|
function serializeTitle(elm) { |
||||||
|
var data = {}, value = elm.nodeValue, i = 0; |
||||||
|
data.element = elm.parentElement; |
||||||
|
data["lang-default"] = value.replace(/<!--(.*)-->.*/, ""); |
||||||
|
value && (value = elm.nodeValue.match(/<!--\{\w+\}[\s\S]*?-->/gi)); |
||||||
|
if (value && value.length > 0) { |
||||||
|
for (;i < value.length; i++) { |
||||||
|
var name = value[i].match(/\{([^\ ]*)\}/)[0]; |
||||||
|
name = name.replace(/\{([^\ ]*)\}/g, "$1"); |
||||||
|
data["lang-" + name] = value[i].replace(/<!--\{\w+\}(.*)-->/g, "$1"); |
||||||
|
} |
||||||
|
} |
||||||
|
elm.parentElement.innerHTML = data["lang-default"]; |
||||||
|
return data; |
||||||
|
} |
||||||
|
// 处理 IMG
|
||||||
|
function serializeIMG(elm) { |
||||||
|
var i = 0, trans = []; |
||||||
|
var htmlstr = elm.outerHTML; |
||||||
|
var imgurl = htmlstr.match(/src=\"(.*?)\"/); |
||||||
|
var alt = htmlstr.match(/alt=\"(.*?)\"/); |
||||||
|
var title = htmlstr.match(/title=\"(.*?)\"/); |
||||||
|
var placeholder = htmlstr.match(/placeholder=\"(.*?)\"/); |
||||||
|
var value = htmlstr.match(/value=\"(.*?)\"/); |
||||||
|
var processing = function(proce, _type, _mark) { |
||||||
|
var data = {}; |
||||||
|
var regm = new RegExp(_mark + '.(\\w+).\\".*?\\"', "g"); |
||||||
|
var regname = new RegExp(_mark + "(.*?)="); |
||||||
|
var regval = new RegExp(_mark + '(.*?)=\\"(.*?)\\"'); |
||||||
|
data.element = elm; |
||||||
|
data["default"] = proce.length === 2 ? proce[1] : ""; |
||||||
|
proce = htmlstr.match(regm); |
||||||
|
if (proce && proce.length > 0) { |
||||||
|
for (i = 0; i < proce.length; i++) { |
||||||
|
data[proce[i].match(regname, "$1")[1]] = proce[i].match(regval, "$1")[2]; |
||||||
|
data["type"] = _type; |
||||||
|
} |
||||||
|
} |
||||||
|
return data; |
||||||
|
}; |
||||||
|
if (imgurl) { |
||||||
|
trans.push(processing(imgurl, "src", "data-lang-")); |
||||||
|
} |
||||||
|
if (alt) { |
||||||
|
trans.push(processing(alt, "alt", "alt-")); |
||||||
|
} |
||||||
|
if (title) { |
||||||
|
trans.push(processing(title, "title", "title-")); |
||||||
|
} |
||||||
|
if (placeholder) { |
||||||
|
trans.push(processing(placeholder, "placeholder", "placeholder-")); |
||||||
|
} |
||||||
|
if (value) { |
||||||
|
trans.push(processing(value, "value", "value-")); |
||||||
|
} |
||||||
|
return trans; |
||||||
|
} |
||||||
|
// 序列化翻译数据
|
||||||
|
function translater(elm, langData) { |
||||||
|
langData = langData || {}; |
||||||
|
if (elm.parentElement && elm.parentElement.tagName === "TITLE") { |
||||||
|
// 处理title里面的语言切换情况
|
||||||
|
return serializeTitle(elm); |
||||||
|
} else if (elm.tagName === "IMG" && elm.nodeType === 1) { |
||||||
|
// 处理 IMG
|
||||||
|
return serializeIMG(elm); |
||||||
|
} else if (elm.tagName === "INPUT" && elm.nodeType === 1) { |
||||||
|
// 处理 INPUT
|
||||||
|
return serializeIMG(elm); |
||||||
|
} |
||||||
|
var name = "lang-default", value = elm.nodeValue, fragmentRE = /^\{\w+\}/; |
||||||
|
if (elm.nodeType === 8 && fragmentRE.test(value)) { |
||||||
|
// 获取花括号内容
|
||||||
|
name = value.match(fragmentRE)[0]; |
||||||
|
// 去掉花括号
|
||||||
|
name = "lang-" + (name ? name.replace(/\{([^\ ]*)\}/g, "$1") : ""); |
||||||
|
// 获取好括号后面的内容
|
||||||
|
value = value.replace(fragmentRE, ""); |
||||||
|
if (trim(value) !== "") langData[name] = value; |
||||||
|
} |
||||||
|
if (trim(value) !== "" && !langData["lang-default"]) { |
||||||
|
langData[name] = value; |
||||||
|
langData.element = elm; |
||||||
|
} |
||||||
|
var nextElm = elm.nextSibling; |
||||||
|
if (nextElm && nextElm.nodeType !== 1) { |
||||||
|
translater(nextElm, langData); |
||||||
|
} |
||||||
|
return langData; |
||||||
|
} |
||||||
|
//过滤左右的空格以及换行符
|
||||||
|
function trim(text) { |
||||||
|
return "" + (null == text ? "" : (text + "").replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "").replace(/[\r\n]+/g, "")); |
||||||
|
} |
||||||
|
function getUrlParam(name, searchStr) { |
||||||
|
// 兼容 ?id=22&name=%E4%B8%AD%E6%96%87&DEBUG 处理
|
||||||
|
var url = searchStr || location.search; |
||||||
|
var params = {}; |
||||||
|
if (url.indexOf("?") != -1) { |
||||||
|
var arr = url.substr(1).split("&"); |
||||||
|
for (var i = 0, l = arr.length; i < l; i++) { |
||||||
|
var kv = arr[i].split("="); |
||||||
|
params[kv[0]] = kv[1] && decodeURIComponent(kv[1]); |
||||||
|
} |
||||||
|
} |
||||||
|
return name ? params[name] : params; |
||||||
|
} |
||||||
|
function getNodes(e, _tagName) { |
||||||
|
var i = 0, result = [], doms = e.getElementsByTagName(_tagName); |
||||||
|
for (;i < doms.length; i++) result.push(doms[i]); |
||||||
|
return result; |
||||||
|
} |
||||||
|
//兼容的获取文本节点的简单方案
|
||||||
|
var getTextNodes = window.NodeFilter ? function(e) { |
||||||
|
//支持TreeWalker的浏览器
|
||||||
|
var r = [], o, s; |
||||||
|
s = document.createTreeWalker(e, NodeFilter.SHOW_TEXT, null, null); |
||||||
|
while (o = s.nextNode()) { |
||||||
|
if (o.parentElement.tagName !== "SCRIPT" && o.parentElement.tagName !== "STYLE" && o.parentElement.tagName !== "CODE" && trim(o.nodeValue) !== "") { |
||||||
|
r.push(o); |
||||||
|
} |
||||||
|
} |
||||||
|
return r; |
||||||
|
} : function(e) { |
||||||
|
//不支持的需要遍历
|
||||||
|
switch (e.nodeType) { |
||||||
|
//注释节点直接返回
|
||||||
|
case 3: |
||||||
|
return [ e ]; |
||||||
|
|
||||||
|
case 1: |
||||||
|
; |
||||||
|
|
||||||
|
case 9: |
||||||
|
//文档或元素需要遍历子节点
|
||||||
|
var i, s = e.childNodes, result = []; |
||||||
|
if (e.tagName !== "SCRIPT" && e.tagName !== "STYLE" && e.tagName !== "CODE" && trim(o.nodeValue) !== "") { |
||||||
|
for (i = 0; i < s.length; i++) getTextNodes(s[i]) && result.push(getTextNodes(s[i])); |
||||||
|
//合并子数组
|
||||||
|
return Array.prototype.concat.apply([], result); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
||||||
|
return Translater; |
||||||
|
}); |
Loading…
Reference in new issue