CommonUtil = function () {
},
CommonUtil.getPlatformPath = function () {
var c = window.document.location.href;
var e = window.document.location.pathname;
var d = c.indexOf(e);
var a = c.substring(0, d);
var b = e.substring(0, e.substr(1).indexOf('/') + 1);
return (a + b)
},
CommonUtil.getDomainPath = function () {
var b = window.document.location.href;
var d = window.document.location.pathname;
var c = b.indexOf(d);
var a = b.substring(0, c);
return a
},
CommonUtil.getPlatformDeployPath = function () {
var b = window.document.location.pathname;
var a = b.substring(0, b.substr(1).indexOf('/') + 1);
return a
},
CommonUtil.getOrigin = function () {
if (!window.location.origin) {
window.location.origin = window.location.protocol + '//' + window.location.hostname + (window.location.port ? ':' + window.location.port : '')
}
return window.location.origin
},
CommonUtil.getDomainByUrl = function (b) {
var d = null;
if (b != undefined && b != null) {
var c = /.*\:\/\/([^\/]*).*/;
var a = b.match(c);
if (typeof a != 'undefined' && null != a) {
d = a[1]
}
}
return d
},
CommonUtil.getUrlParams = function (a) {
var b = new RegExp('(^|\\?|&)' + a + '=([^&]*)(\\s|&|$)'\, 'i');
if (b.test(location.href)) {
return unescape(RegExp.$2.replace(/\+/g, ' '))
} else {
return ''
}
},
CommonUtil.urlAddRandom = function (a) {
var b = a;
if (b.indexOf('?') > - 1) {
if (b.indexOf('?') + 1 < b.length) {
if (b.lastIndexOf('&') + 1 < b.length) {
b += '&'
}
}
} else {
b += '?'
}
b += 'randomMath=' + Math.random();
return b
},
CommonUtil.dataToJson = function (d) {
var c = {
};
var a = d.split('&');
for (var b = 0; b < a.length; b++) {
var e = a[b].split('=');
c[e[0]] = e[1]
}
return c
},
CommonUtil.strToDate = function (b) {
if (b != null) {
var c = b.split('-');
if (c.length == 3) {
return new Date(parseInt(c[0], 10), parseInt(c[1], 10) - 1, parseInt(c[2], 10))
} else {
var a = b.split('/');
if (a.length == 3) {
return new Date(parseInt(a[0], 10), parseInt(a[1], 10) - 1, parseInt(a[2], 10))
}
}
}
return null
},
CommonUtil.strToDateTime = function (e) {
if (e != null) {
var g = e.split(' ');
var c = g[0];
var f = g[1];
var d = c.split('-');
var a = f.split(':');
if (d.length == 3 && a.length == 3) {
return new Date(parseInt(d[0]), parseInt(d[1]) - 1, parseInt(d[2]), parseInt(a[0]), parseInt(a[1]), parseInt(a[2]))
} else {
var b = c.split('/');
if (b.length == 3) {
return new Date(parseInt(b[0]), parseInt(b[1]) - 1, parseInt(b[2]), parseInt(a[0]), parseInt(a[1]), parseInt(a[2]))
}
}
}
return null
},
CommonUtil.setCookie = function (c, e, b) {
var d = c + '=' + escape(e);
if (b > 0) {
var a = new Date();
a.setTime(a.getTime() + b * 3600 * 1000);
d = d + ';expires=' + a.toGMTString() + ';path=' + CommonUtil.getPlatformDeployPath()
}
document.cookie = d
};
CommonUtil.clearCookie = function (a) {
var c = new Date();
c.setTime(c.getTime() - 1);
var b = CommonUtil.getCookie(a);
if (b != null) {
document.cookie = a + '=;expires=' + c.toGMTString() + ';path=' + CommonUtil.getPlatformDeployPath()
}
};
CommonUtil.getCookie = function (a) {
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(a + '=');
if (c_start != - 1) {
c_start = c_start + a.length + 1;
c_end = document.cookie.indexOf(';', c_start);
if (c_end == - 1) {
c_end = document.cookie.length
}
return unescape(document.cookie.substring(c_start, c_end))
}
}
return ''
},
CommonUtil.getUploadUrl = function (a) {
return a
},
CommonUtil.isNotEmpty = function (d, b, a) {
var c = true;
if (d == null || d == '' || d == 'undefined') {
c = false
} else {
if (d == b) {
c = false
}
}
if (a) {
return d
} else {
return c
}
},
CommonUtil.isEmpty = function (b) {
var a = false;
if (b == null || b == '' || b == 'undefined') {
a = true
}
return a
},
CommonUtil.getPercentVal = function (d, b, a) {
if (isNaN(d)) {
alert('‘除数’不是一个数字');
return
}
if (isNaN(b)) {
alert('‘被除数’不是一个数字');
return
}
if (d == 0) {
return 0
}
if (a == null || a == '' || a == 'undefined' || a < 0 || a > 100) {
a = 3
}
var c = (parseFloat(d) / parseFloat(b));
return (parseFloat(c) * 100).toFixed(a)
},
CommonUtil.setDefaultVal = function (a, b) {
if (a == null || a == '' || a == 'undefined') {
if (b == undefined) {
alert('为设置默认值参数!');
return
}
return b
} else {
return a
}
};
CommonUtil.convertUrlToObj = function (c) {
var g = new Object();
if (c.indexOf('?') > - 1) {
var f = c.split('?');
g.url = f[0];
var b = f[1];
if (b.indexOf('&') > - 1) {
var h = b.split('&');
for (var d = 0; d < h.length; d++) {
var a = h[d].split('=') [0];
var e = h[d].split('=') [1];
g[a] = unescape(e)
}
} else {
if (b) {
var a = b.split('=') [0];
var e = b.split('=') [1];
g[a] = unescape(e)
}
}
} else {
g.url = c
}
return g
};
CommonUtil.convertUrlObjToUrlStr = function (b) {
var c = b.url + '?';
delete b.url;
for (var a in b) {
c += a + '=' + b[a] + '&'
}
if (c.lastIndexOf('?') + 1 == c.length || c.lastIndexOf('&') + 1 == c.length) {
c = c.substring(0, c.length - 1)
}
return c
};
CommonUtil.convertTotalSecondsHMS = function (k) {
var g = (k % 60);
k -= g;
var e = (k % 3600);
k -= e;
g = Math.round(g * 100) / 100;
var a = new String(g);
var h = a;
var f = '';
if (a.indexOf('.') != - 1) {
h = a.substring(0, a.indexOf('.'));
f = a.substring(a.indexOf('.') + 1, a.length)
}
if (h.length < 2) {
h = '0' + h
}
a = h;
if ((k % 3600) != 0) {
var b = 0
} else {
var b = (k / 3600)
}
if ((e % 60) != 0) {
var c = 0
} else {
var c = (e / 60)
}
if ((new String(b)).length < 2) {
b = '0' + b
}
if ((new String(c)).length < 2) {
c = '0' + c
}
var d = c + ':' + a;
if (b != '00') {
d = b + ':' + c + ':' + a
}
return d
};
CommonUtil.millisecondToTime = function (a) {
if (a != null && !isNaN(a)) {
var b = parseFloat(a) / 1000;
if (b > 0) {
b = parseInt(b / 3600) + ':' + parseInt((parseFloat(b / 3600) - parseInt(b / 3600)) * 60) + ':' + parseInt((parseFloat((parseFloat(b / 3600) - parseInt(b / 3600)) * 60) - parseInt((parseFloat(b / 3600) - parseInt(b / 3600)) * 60)) * 60);
var c = CommonUtil.formatTime(b);
return c
} else {
return '00:00:00'
}
}
};
CommonUtil.secondsToTimeStr = function (d, b) {
var b = ':' || b;
if (typeof (d) == 'number') {
var a = Math.floor(d / 3600) + '';
var d = d % 3600;
var c = Math.floor(d / 60) + '';
d = parseInt(d % 60) + '';
if (a.length < 2) {
a = '0' + a
}
if (c.length < 2) {
c = '0' + c
}
if (d.length < 2) {
d = '0' + d
}
return a + b + c + b + d
} else {
return ''
}
};
CommonUtil.formatTime = function (b) {
var c = '';
var a = b.split(':');
if (a[0].length == 1) {
c += '0' + a[0] + ':'
} else {
c += a[0] + ':'
}
if (a[1].length == 1) {
c += '0' + a[1] + ':'
} else {
c += a[1] + ':'
}
if (a[2].length == 1) {
c += '0' + a[2]
} else {
c += a[2]
}
return c
};
CommonUtil.timeToSeconds = function (f) {
var b = f.split(':');
var d = parseInt(b[0]);
var a = parseInt(b[1]);
var c = parseInt(b[2]);
var e = d * 3600 + a * 60 + c;
return e
};
CommonUtil.convertTotalSeconds = function (k) {
var g = (k % 60);
k -= g;
var e = (k % 3600);
k -= e;
g = Math.round(g * 100) / 100;
var a = new String(g);
var h = a;
var f = '';
if (a.indexOf('.') != - 1) {
h = a.substring(0, a.indexOf('.'));
f = a.substring(a.indexOf('.') + 1, a.length)
}
if (h.length < 2) {
h = '0' + h
}
a = h;
if ((k % 3600) != 0) {
var b = 0
} else {
var b = (k / 3600)
}
if ((e % 60) != 0) {
var c = 0
} else {
var c = (e / 60)
}
if ((new String(b)).length < 2) {
b = '0' + b
}
if ((new String(c)).length < 2) {
c = '0' + c
}
var d = b + ':' + c + ':' + a;
return d
};
CommonUtil.formatStr = function (c, a) {
var l = '';
var k = (c + '').length;
if (k > 0) {
if (k + 2 > a) {
return c + ''
} else {
var g = a - k - 2;
var h = 1;
for (var e = 0; e < g; e++) {
h = h * 10
}
var b = parseInt(Math.random() * h);
var f = (b + '').length;
if (f < g) {
for (var d = f; d < g; d++) {
b = b * 10
}
}
if (k >= 10) {
l += k
} else {
l += '0' + k
}
l += c + (b + '')
}
} else {
return c + ''
}
return l
};
CommonUtil.getStrLen = function (h, g) {
var a = h.length,
e = 0,
d = null;
for (var b = 0; b < a; b++) {
var c = h.charCodeAt(b);
if (c > 0 && c < 128) {
e += 0.5
} else {
e++
}
if (parseInt(e) == g) {
d = b + 1
}
}
var f = {
length: e,
limitLenPostion: d
};
return f
};
CommonUtil.formatFileSize = function (c, a, b) {
var d;
b = b || [
'B',
'K',
'M',
'G',
'TB'
];
while ((d = b.shift()) && c > 1024) {
c = c / 1024
}
return (d === 'B' ? c : c.toFixed(a || 2)) + d
};
CommonUtil.delArrEle = function (d, c) {
if (!(d instanceof Array)) {
return
}
var a = d.length;
for (var b = a - 1; b > - 1; b--) {
if (d[b] == c) {
d.splice(b, 1);
break
}
}
};
CommonUtil.findArrEle = function (d, c) {
if (d instanceof Array) {
}
var a = d.length;
for (var b = 0; b < a; b++) {
if (d[b] == c) {
return b
}
}
return - 1
};
CommonUtil.moveToEnd = function (c) {
c.focus();
var a = c.value.length;
if (document.selection) {
var b = c.createTextRange();
b.moveStart('character', a);
b.collapse();
b.select()
} else {
if (typeof c.selectionStart == 'number' && typeof c.selectionEnd == 'number') {
c.selectionStart = c.selectionEnd = a
}
}
};
CommonUtil.numToChineseNum = function (d) {
if (!/^\d*(\.\d*)?$/.test(d)) {
alert('Number is wrong!');
return 'Number is wrong!'
}
var g = new Array('0', '一', '二', '三', '四', '五', '六', '七', '八', '九');
var h = new Array('', '十', '百', '千', '万', '亿', '点', '');
var b = ('' + d).replace(/(^0*)/g, '').split('.'),
c = 0,
f = '';
for (var e = b[0].length - 1; e >= 0; e--) {
switch (c) {
case 0:
f = h[7] + f;
break;
case 4:
if (!new RegExp('0{4}\\d{' + (b[0].length - e - 1) + '}$').test(b[0])) {
f = h[4] + f
}
break;
case 8:
f = h[5] + f;
h[7] = h[5];
c = 0;
break
}
if (c % 4 == 2 && b[0].charAt(e + 2) != 0 && b[0].charAt(e + 1) == 0) {
f = g[0] + f
}
if (b[0].charAt(e) != 0) {
if (b[0].length == 2 && e == 0 && b[0].charAt(e) == 1) {
f = h[c % 4] + f
} else {
f = g[b[0].charAt(e)] + h[c % 4] + f
}
}
c++
}
if (b.length > 1) {
f += h[6];
for (var e = 0; e < b[1].length; e++) {
f += g[b[1].charAt(e)]
}
}
return f
};
CommonUtil.isSupportFLash = function () {
var a = false;
try {
a = Boolean(new ActiveXObject('ShockwaveFlash.ShockwaveFlash'))
} catch (b) {
a = ('undefined' != typeof navigator.mimeTypes['application/x-shockwave-flash'])
}
return a
};
CommonUtil.isSupportHtml5 = function () {
var c = true;
var e = navigator.userAgent;
var b = e.indexOf('compatible') > - 1 && e.indexOf('MSIE') > - 1;
if (b) {
var a = new RegExp('MSIE (\\d+\.\\d+);');
a.test(e);
var d = parseFloat(RegExp['$1']);
if (d < 9) {
c = false
}
}
return c
};
CommonUtil.getIEVersion = function () {
var a = navigator.userAgent;
if (/msie/i.test(a)) {
return a.match(/msie (\d+\.\d+)/i) [1]
} else {
if (\~a.toLowerCase().indexOf('trident') && \~a.indexOf('rv')) {
return a.match(/rv:(\d+\.\d+)/) [1]
}
}
return false
};
CommonUtil.isIEBrowser = function () {
var b = window.navigator.userAgent.toLowerCase();
var a = b && /msie|trident/.test(b);
return a
};
CommonUtil.isIEBrowserNoIE11 = function () {
var b = window.navigator.userAgent.toLowerCase();
var a = b && /msie/.test(b);
return a
};
CommonUtil.isIpad = function () {
var c = window.navigator.userAgent.toLowerCase();
var b = new RegExp('pad');
var a = b.test(c);
if (a) {
return true
}
return false
};
CommonUtil.encrypt = function (e) {
var b = 'bGVhcm5zcGFjZWFlczEyMw==';
var a = new CommonUtil.Base64();
var c = a.decode(b);
var f = CryptoJS.enc.Utf8.parse(c);
var d = CryptoJS.AES.encrypt(e, f, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return d.toString()
};
CommonUtil.encryptByKey = function (c, a) {
var d = CryptoJS.enc.Utf8.parse(a);
var b = CryptoJS.AES.encrypt(c, d, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return b.toString()
};
CommonUtil.Base64 = function () {
_keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
this.decode = function (c) {
var a = '';
var l,
h,
f;
var k,
g,
e,
d;
var b = 0;
c = c.replace(/[^A-Za-z0-9\+\/\=]/g, '');
while (b < c.length) {
k = _keyStr.indexOf(c.charAt(b++));
g = _keyStr.indexOf(c.charAt(b++));
e = _keyStr.indexOf(c.charAt(b++));
d = _keyStr.indexOf(c.charAt(b++));
l = (k << 2) | (g >> 4);
h = ((g & 15) << 4) | (e >> 2);
f = ((e & 3) << 6) | d;
a = a + String.fromCharCode(l);
if (e != 64) {
a = a + String.fromCharCode(h)
}
if (d != 64) {
a = a + String.fromCharCode(f)
}
}
a = _utf8_decode(a);
return a
};
_utf8_decode = function (a) {
var b = '';
var d = 0;
var e = c1 = c2 = 0;
while (d < a.length) {
e = a.charCodeAt(d);
if (e < 128) {
b += String.fromCharCode(e);
d++
} else {
if ((e > 191) && (e < 224)) {
c2 = a.charCodeAt(d + 1);
b += String.fromCharCode(((e & 31) << 6) | (c2 & 63));
d += 2
} else {
c2 = a.charCodeAt(d + 1);
c3 = a.charCodeAt(d + 2);
b += String.fromCharCode(((e & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
d += 3
}
}
}
return b
}
};
CommonUtil.startWith = function (b, a) {
if (a === b.substring(0, a.length)) {
return true
}
return false
};
CommonUtil.getCookieKeys = function () {
var b = document.cookie;
var e = b.split(';');
if (e.length == 0) {
return null
}
var c = [
];
for (var d in e) {
var a = e[d].split('=');
c.push(a[0])
}
return c
};
CommonUtil.deleteCookieByExp = function (a) {
var b = CommonUtil.getCookieKeys();
if (b.length == 0) {
return
}
var d = new Date();
d.setTime(d.getTime() - 1);
for (j in b) {
var c = b[j].replace(/\s*/g, '');
if (c.indexOf(a) > - 1) {
document.cookie = c + '=;expires=' + d.toGMTString();
document.cookie = c + '=;expires=' + d.toGMTString() + ';path=' + CommonUtil.getPlatformDeployPath()
}
}
};
CommonUtil.getAliDefinition = function (b) {
var a = '';
switch (b) {
case '240p':
a = 'FD';
break;
case '360p':
a = 'LD';
break;
case '480p':
a = 'LD';
break;
case '720p':
a = 'SD';
break;
case '1080p':
a = 'HD';
break;
case '2K':
a = '2K';
break;
case '4K':
a = '4K';
break;
case 'ori':
a = 'OD';
break
}
return a
};
CommonUtil.getAliDefinitionText = function (b) {
var a = '';
switch (b) {
case 'FD':
a = '流畅';
break;
case 'LD':
a = '标清';
break;
case 'SD':
a = '高清';
break;
case 'HD':
a = '超清';
break;
case 'FHD':
a = '全高清';
break;
case '2K':
a = '2K';
break;
case '4K':
a = '4K';
break;
case 'OD':
a = '原画';
break
}
return a
};
CommonUtil.supportH5ForAli = function () {
var c = true;
var e = navigator.userAgent;
var b = e.indexOf('compatible') > - 1 && e.indexOf('MSIE') > - 1;
if (b) {
var a = new RegExp('MSIE (\\d+\.\\d+);');
a.test(e);
var d = parseFloat(RegExp['$1']);
if (d < 11) {
c = false
}
}
return c
};
CommonUtil.formatProtocol = function (c) {
if (CommonUtil.isEmpty(c)) {
return ''
}
var b = navigator.userAgent;
var a = b.indexOf('compatible') > - 1 && b.indexOf('MSIE') > - 1;
if (/^https:\/\//i.test(window.location.href || '')) {
c = CommonUtil.replaceAll(c, 'http:', window.location.protocol)
} else {
if (a) {
c = CommonUtil.replaceAll(c, 'https:', window.location.protocol)
}
}
return c
};
CommonUtil.replaceAll = function (e, d, c) {
var a;
var b = e.split(d);
a = b[0];
for (i = 1; i < b.length; i++) {
a += c + b[i]
}
return a
};
CommonUtil.dateToString = function (b, a) {
b = b == undefined ? new Date() : b;
b = typeof b == 'number' ? new Date(b) : b;
a = a || 'yyyy-MM-dd HH:mm:ss';
var e = {
y: b.getFullYear(),
M: b.getMonth() + 1,
d: b.getDate(),
q: Math.floor((b.getMonth() + 3) / 3),
w: b.getDay(),
H: b.getHours(),
h: b.getHours() % 12 == 0 ? 12 : b.getHours() % 12,
m: b.getMinutes(),
s: b.getSeconds(),
S: b.getMilliseconds()
};
var d = [
'天',
'一',
'二',
'三',
'四',
'五',
'六'
];
for (var c in e) {
a = a.replace(new RegExp(c + '+', 'g'), function (g) {
var k = e[c] + '';
if (c == 'w') {
return (g.length > 2 ? '星期' : '周') + d[k]
}
for (var h = 0, f = k.length; h < g.length - f; h++) {
k = '0' + k
}
return g.length == 1 ? k : k.substring(k.length - g.length)
})
}
return a
};
CommonUtil.replaceUrlProtocol = function (a) {
if (typeof (a) == 'undefined') {
return ''
}
return a.replace(/^(http|https):/\, window.location.protocol)
};
CommonUtil.getPluploadRuntimes = function () {
var a = 'html5,flash,silverlight,html4';
var b = CommonUtil.getIEVersion();
if (b && parseInt(b) <= 9) {
a = 'flash,html5,silverlight,html4'
}
return a
};
CommonUtil.getPlayerType = function (a) {
var b = a ? document.getElementById(a) : document;
var c = b.getElementsByTagName('video');
return c && c.length > 0 ? 'H5' : 'flash'
};
CommonUtil.isEmptyValue = function (a) {
return typeof (a) == 'undefined' || a == null
};
CommonUtil.browserCanPlayFlashVideo = function () {
var a = navigator.userAgent.toLowerCase();
return /windows nt 6.1/.test(a) && CommonUtil.isIEBrowserNoIE11()
};
CommonUtil.closeBrowserCurrTab = function () {
if (navigator.userAgent.indexOf('MSIE') > 0) {
if (navigator.userAgent.indexOf('MSIE 6.0') > 0) {
window.opener = null;
window.close()
} else {
window.open('', '_top');
window.top.close()
}
} else {
if (navigator.userAgent.indexOf('Firefox') > 0 || navigator.userAgent.indexOf('Chrome') > 0) {
window.location.href = 'about:blank';
window.close()
} else {
window.opener = null;
window.open('', '_self');
window.close()
}
}
};
CommonUtil.getCurrBrowserType = function () {
var a = navigator.userAgent;
if (a.indexOf('Opera') > - 1 || a.indexOf('OPR') > - 1) {
return 'Opera'
} else {
if (a.indexOf('compatible') > - 1 && a.indexOf('MSIE') > - 1) {
return 'IE'
} else {
if (a.indexOf('Edg') > - 1) {
return 'Edge'
} else {
if (a.indexOf('SE 2.X') > - 1) {
return 'Sougou'
} else {
if (a.indexOf('Firefox') > - 1) {
return 'Firefox'
} else {
if (a.indexOf('Safari') > - 1 && a.indexOf('Chrome') === - 1) {
return 'Safari'
} else {
if (a.indexOf('Chrome') > - 1 && a.indexOf('Safari') > - 1) {
return 'Chrome'
} else {
return 'Unknown'
}
}
}
}
}
}
}
};
CommonUtil.getVideoResourceByDefinition = function (d, c) {
var f = d;
var a = f.length;
if (f.indexOf('"' + CommonUtil.getAliDefinition(c) + '":') > 0 && f.indexOf('{' + CommonUtil.getAliDefinition(c) + ':') !== 0) {
f = f.substr(1, a - 2);
var e = f.split(',');
f = '{';
for (var b = 0; b < e.length; b++) {
if (e[b].indexOf('"' + CommonUtil.getAliDefinition(c) + '":') === 0) {
f = f.substr(0, 1) + e[b] + ',' + f.substr(1)
} else {
f = f.substr(0, f.length) + e[b] + ','
}
}
f = f.slice(0, f.length - 1) + '}'
}
return f
};
CommonUtil.gotoTop = function () {
if (window.MultiPageEventBus) {
window.MultiPageEventBus.emit('gotoTop')
}
};
CommonUtil.enableGotoTop = function () {
if (window.MultiPageEventBus) {
window.MultiPageEventBus.on('gotoTop', function () {
$('html, body').animate({
scrollTop: 0
}, 500)
})
}
};