kero
Version:
<img src="http://tinper.org/assets/images/kero.png" width="120" style="max-width:100%;"/>
1,942 lines (1,744 loc) • 498 kB
JavaScript
+function(){
var U_LANGUAGES = "i_languages";
var U_THEME = "u_theme";
var U_LOCALE = "u_locale";
var U_USERCODE = "usercode";
var enumerables = true,enumerablesTest = {toString: 1},toString = Object.prototype.toString;
for (var i in enumerablesTest) {
enumerables = null;
}
if (enumerables) {
enumerables = ['hasOwnProperty', 'valueOf', 'isPrototypeOf', 'propertyIsEnumerable',
'toLocaleString', 'toString', 'constructor'];
}
window.u = window.u || {};
//window.$ = {}
var u = window.u;
//var $ = u;
u.enumerables = enumerables;
/**
* 复制对象属性
*
* @param {Object} 目标对象
* @param {config} 源对象
*/
u.extend = function(object, config) {
var args = arguments,options;
if(args.length > 1){
for(var len=1; len<args.length; len++){
options = args[len];
if (object && options && typeof options === 'object') {
var i, j, k;
for (i in options) {
object[i] = options[i];
}
if (enumerables) {
for (j = enumerables.length; j--;) {
k = enumerables[j];
if (options.hasOwnProperty && options.hasOwnProperty(k)) {
object[k] = options[k];
}
}
}
}
}
}
return object;
};
u.extend(u, {
setCookie: function (sName, sValue, oExpires, sPath, sDomain, bSecure) {
var sCookie = sName + "=" + encodeURIComponent(sValue);
if (oExpires)
sCookie += "; expires=" + oExpires.toGMTString();
if (sPath)
sCookie += "; path=" + sPath;
if (sDomain)
sCookie += "; domain=" + sDomain;
if (bSecure)
sCookie += "; secure=" + bSecure;
document.cookie = sCookie;
},
getCookie: function (sName) {
var sRE = "(?:; )?" + sName + "=([^;]*);?";
var oRE = new RegExp(sRE);
if (oRE.test(document.cookie)) {
return decodeURIComponent(RegExp["$1"]);
} else
return null;
},
/**
* 创建一个带壳的对象,防止外部修改
* @param {Object} proto
*/
createShellObject: function (proto) {
var exf = function () {
}
exf.prototype = proto;
return new exf();
},
execIgnoreError: function (a, b, c) {
try {
a.call(b, c);
} catch (e) {
}
},
on: function (element, eventName,child,listener) {
if(!element)
return;
if(arguments.length < 4){
listener = child;
child = undefined;
}else{
var childlistener = function(e){
if(!e){
return;
}
var tmpchildren = element.querySelectorAll(child)
tmpchildren.forEach(function(node){
if(node == e.target){
listener.call(e.target,e)
}
})
}
}
//capture = capture || false;
if(!element["uEvent"]){
//在dom上添加记录区
element["uEvent"] = {}
}
//判断是否元素上是否用通过on方法填加进去的事件
if(!element["uEvent"][eventName]){
element["uEvent"][eventName] = [child?childlistener:listener]
if(u.event && u.event[eventName] && u.event[eventName].setup){
u.event[eventName].setup.call(element);
}
element["uEvent"][eventName+'fn'] = function(e){
//火狐下有问题修改判断
if(!e)
e = typeof event != 'undefined' && event?event:window.event;
element["uEvent"][eventName].forEach(function(fn){
e.target = e.target || e.srcElement;//兼容IE8
if(fn)
fn.call(element,e)
})
}
if (element.addEventListener) { // 用于支持DOM的浏览器
element.addEventListener(eventName, element["uEvent"][eventName+'fn']);
} else if (element.attachEvent) { // 用于IE浏览器
element.attachEvent("on" + eventName,element["uEvent"][eventName+'fn'] );
} else { // 用于其它浏览器
element["on" + eventName] = element["uEvent"][eventName+'fn']
}
}else{
//如果有就直接往元素的记录区添加事件
var lis = child?childlistener:listener;
var hasLis = false;
element["uEvent"][eventName].forEach(function(fn){
if(fn == lis){
hasLis = true;
}
});
if(!hasLis){
element["uEvent"][eventName].push(child?childlistener:listener)
}
}
},
off: function(element, eventName, listener){
//删除事件数组
if(listener){
if(element && element["uEvent"] && element["uEvent"][eventName]){
element["uEvent"][eventName].forEach(function(fn,i){
if(fn == listener){
element["uEvent"][eventName].splice(i,1);
}
});
}
return;
}
var eventfn = element["uEvent"][eventName+'fn']
if (element.removeEventListener) { // 用于支持DOM的浏览器
element.removeEventListener(eventName,eventfn );
} else if (element.removeEvent) { // 用于IE浏览器
element.removeEvent("on" + eventName, eventfn);
} else { // 用于其它浏览器
delete element["on" + eventName]
}
if(u.event && u.event[eventName] && u.event[eventName].teardown){
u.event[eventName].teardown.call(element);
}
element["uEvent"][eventName] = undefined
element["uEvent"][eventName+'fn'] = undefined
},
trigger:function(element,eventName){
if(element["uEvent"] && element["uEvent"][eventName]){
element["uEvent"][eventName+'fn']()
}
},
/**
* 增加样式
* @param value
* @returns {*}
*/
addClass: function (element, value) {
if (typeof element.classList === 'undefined') {
u._addClass(element, value);
} else {
element.classList.add(value);
}
return u;
},
removeClass: function (element, value) {
if (typeof element.classList === 'undefined') {
u._removeClass(element, value);
} else {
element.classList.remove(value);
}
return u;
},
hasClass: function(element, value){
if (!element) return false;
if (element.nodeName && (element.nodeName === '#text'||element.nodeName === '#comment')) return false;
if (typeof element.classList === 'undefined') {
return u._hasClass(element,value);
}else{
return element.classList.contains(value);
}
},
toggleClass: function(element,value){
if (typeof element.classList === 'undefined') {
return u._toggleClass(element,value);
}else{
return element.classList.toggle(value);
}
},
closest: function(element, selector) {
var tmp = element;
while(tmp != null &&!u.hasClass(tmp, selector) && tmp != document.body ) {
tmp = tmp.parentNode;
}
if(tmp == document.body) return null;
return tmp;
},
css:function(element,csstext,val){
if(csstext instanceof Object){
for(var k in csstext){
var tmpcss = csstext[k]
if(["width","height","top","bottom","left","right"].indexOf(k) > -1 && u.isNumber(tmpcss) ){
tmpcss = tmpcss + "px"
}
element.style[k] = tmpcss
}
}else{
if(arguments.length > 2){
element.style[csstext] = val
}else{
u.getStyle(element,csstext)
}
}
},
wrap:function(element,parent){
var p = u.makeDOM(parent)
element.parentNode.insertBefore(p,element)
p.appendChild(element)
},
getStyle:function(element,key){
//不要在循环里用
var allCSS
if(window.getComputedStyle){
allCSS = window.getComputedStyle(element)
}else{
allCSS = element.currentStyle
}
if(allCSS[key] !== undefined){
return allCSS[key]
}else{
return ""
}
},
/**
* 统一zindex值, 不同控件每次显示时都取最大的zindex,防止显示错乱
*/
getZIndex: function(){
if (!u.globalZIndex){
u.globalZIndex = 2000;
}
return u.globalZIndex ++;
},
makeDOM: function(htmlString){
var tempDiv = document.createElement("div");
tempDiv.innerHTML = htmlString;
var _dom = tempDiv.children[0];
return _dom;
},
makeModal : function(element){
var overlayDiv = document.createElement('div');
u.addClass(overlayDiv, 'u-overlay');
overlayDiv.style.zIndex = u.getZIndex();
document.body.appendChild(overlayDiv)
element.style.zIndex = u.getZIndex();
u.on(overlayDiv, 'click', function(e){
u.stopEvent(e);
})
return overlayDiv;
},
getOffset : function(Node, offset){
if (!offset) {
offset = {};
offset.top = 0;
offset.left = 0;
}
if (Node == document.body) {
return offset;
}
offset.top += Node.offsetTop;
offset.left += Node.offsetLeft;
if(Node.offsetParent)
return u.getOffset(Node.offsetParent, offset);
else
return offset;
},
showPanelByEle:function(ele,panel){
var off = u.getOffset(ele);
var left = off.left;
var inputHeight = ele.offsetHeight;
var top = off.top + inputHeight;
var oH = panel.offsetHeight;
var oW = panel.offsetWidth;
var sH = document.body.clientHeight;
var sW = document.body.clientWidth;
var scrollTop = document.body.scrollTop;
var scrollLeft = document.body.scrollLeft;
left = left - scrollLeft;
top = top - scrollTop;
if((left + oW) > sW)
left = sW - oW;
if(left < 0)
left = 0;
if((top + oH) > sH)
top = sH - oH;
if(top < 0)
top = 0;
panel.style.left = left + 'px';
panel.style.top = top + 'px';
},
/**
* 阻止冒泡
*/
stopEvent: function(e){
if(typeof(e) != "undefined") {
if (e.stopPropagation)
e.stopPropagation();
else {
e.cancelBubble = true;
}
//阻止默认浏览器动作(W3C)
if (e && e.preventDefault)
e.preventDefault();
//IE中阻止函数器默认动作的方式
else
window.event.returnValue = false;
}
},
getFunction: function(target, val){
if (!val || typeof val == 'function') return val
if (typeof target[val] == 'function')
return target[val]
else if (typeof window[val] == 'function')
return window[val]
else if (val.indexOf('.') != -1){
var func = u.getJSObject(target, val)
if (typeof func == 'function') return func
func = u.getJSObject(window, val)
if (typeof func == 'function') return func
}
return val
},
getJSObject: function(target, names) {
if(!names) {
return;
}
if (typeof names == 'object')
return names
var nameArr = names.split('.')
var obj = target
for (var i = 0; i < nameArr.length; i++) {
obj = obj[nameArr[i]]
if (!obj) return null
}
return obj
},
isDate: function(input){
return Object.prototype.toString.call(input) === '[object Date]' ||
input instanceof Date;
},
isNumber : function(obj){
//return obj === +obj
return (obj - parseFloat( obj ) + 1) >= 0;
},
isArray: Array.isArray || function (val) {
return Object.prototype.toString.call(val) === '[object Array]';
},
isEmptyObject: function( obj ) {
var name;
for ( name in obj ) {
return false;
}
return true;
},
inArray :function(node,arr){
if(!arr instanceof Array){
throw "arguments is not Array";
}
for(var i=0,k=arr.length;i<k;i++){
if(node==arr[i]){
return true;
}
}
return false;
},
each: function(obj,callback){
if(obj.forEach){
obj.forEach(function(v,k){callback(k,v)})
}else if(obj instanceof Object){
for(var k in obj){
callback(k,obj[k])
}
}else{
return
}
}
});
//core context
(function() {
var environment = {};
/**
* client attributes
*/
var clientAttributes = {};
var sessionAttributes = {};
var fn = {};
var maskerMeta = {
'float': {
precision: 2
},
'datetime': {
format: 'YYYY-MM-DD HH:mm:ss',
metaType: 'DateTimeFormatMeta',
speratorSymbol: '-'
},
'time':{
format:'HH:mm'
},
'date':{
format:'YYYY-MM-DD'
},
'currency':{
precision: 2,
curSymbol: '¥'
},
'percent':{
}
};
/**
* 获取环境信息
* @return {environment}
*/
fn.getEnvironment = function() {
return u.createShellObject(environment);
};
/**
* 获取客户端参数对象
* @return {clientAttributes}
*/
fn.getClientAttributes = function() {
var exf = function() {}
return u.createShellObject(clientAttributes);
}
fn.setContextPath = function(contextPath) {
return environment[IWEB_CONTEXT_PATH] = contextPath
}
fn.getContextPath = function(contextPath) {
return environment[IWEB_CONTEXT_PATH]
}
/**
* 设置客户端参数对象
* @param {Object} k 对象名称
* @param {Object} v 对象值(建议使用简单类型)
*/
fn.setClientAttribute = function(k, v) {
clientAttributes[k] = v;
}
/**
* 获取会话级参数对象
* @return {clientAttributes}
*/
fn.getSessionAttributes = function() {
var exf = function() {}
return u.createShellObject(sessionAttributes);
}
/**
* 设置会话级参数对象
* @param {Object} k 对象名称
* @param {Object} v 对象值(建议使用简单类型)
*/
fn.setSessionAttribute = function(k, v) {
sessionAttributes[k] = v;
setCookie("ISES_" + k, v);
}
/**
* 移除客户端参数
* @param {Object} k 对象名称
*/
fn.removeClientAttribute = function(k) {
clientAttributes[k] = null;
execIgnoreError(function() {
delete clientAttributes[k];
})
}
/**
* 获取地区信息编码
*/
fn.getLocale = function() {
return this.getEnvironment().locale
}
/**
* 获取多语信息
*/
fn.getLanguages = function(){
return this.getEnvironment().languages
};
/**
* 收集环境信息(包括客户端参数)
* @return {Object}
*/
fn.collectEnvironment = function() {
var _env = this.getEnvironment();
var _ses = this.getSessionAttributes();
for (var i in clientAttributes) {
_ses[i] = clientAttributes[i];
}
_env.clientAttributes = _ses;
return _env
}
/**
* 设置数据格式信息
* @param {String} type
* @param {Object} meta
*/
fn.setMaskerMeta = function(type, meta) {
if (typeof type == 'function'){
getMetaFunc = type;
}else{
if (!maskerMeta[type])
maskerMeta[type] = meta;
else{
if (typeof meta != 'object')
maskerMeta[type] = meta;
else
for (var key in meta){
maskerMeta[type][key] = meta[key];
}
}
}
};
fn.getMaskerMeta = function(type) {
if (typeof getMetaFunc == 'function'){
var meta = getMetaFunc.call(this);
return meta[type];
}else
return u.extend({}, maskerMeta[type]);
};
environment.languages = u.getCookie(U_LANGUAGES) ? u.getCookie(U_LANGUAGES).split(',') : navigator.language ? navigator.language : 'zh-CN';
if(environment.languages == 'zh-cn')
environment.languages = 'zh-CN'
if(environment.languages == 'en-us')
environment.languages = 'en-US'
environment.theme = u.getCookie(U_THEME);
environment.locale = u.getCookie(U_LOCALE);
//environment.timezoneOffset = (new Date()).getTimezoneOffset()
environment.usercode = u.getCookie(U_USERCODE);
//init session attribute
document.cookie.replace(/ISES_(\w*)=([^;]*);?/ig, function(a, b, c) {
sessionAttributes[b] = c;
});
var Core = function() {};
Core.prototype = fn;
u.core = new Core();
})();
u.extend(u, {
isIE: false,
isFF: false,
isOpera: false,
isChrome: false,
isSafari: false,
isWebkit: false,
isIE8_BEFORE: false,
isIE8: false,
isIE8_CORE: false,
isIE9: false,
isIE9_CORE: false,
isIE10: false,
isIE10_ABOVE: false,
isIE11: false,
isIOS: false,
isIphone: false,
isIPAD: false,
isStandard: false,
version: 0,
isWin: false,
isUnix: false,
isLinux: false,
isAndroid: false,
isMac: false,
hasTouch: false,
isMobile: false
});
(function(){
var userAgent = navigator.userAgent,
rMsie = /(msie\s|trident.*rv:)([\w.]+)/,
rFirefox = /(firefox)\/([\w.]+)/,
rOpera = /(opera).+version\/([\w.]+)/,
rChrome = /(chrome)\/([\w.]+)/,
rSafari = /version\/([\w.]+).*(safari)/,
version,
ua = userAgent.toLowerCase(),
s,
browserMatch = { browser : "", version : ''},
match = rMsie.exec(ua);
if (match != null) {
browserMatch = { browser : "IE", version : match[2] || "0" };
}
match = rFirefox.exec(ua);
if (match != null) {
browserMatch = { browser : match[1] || "", version : match[2] || "0" };
}
match = rOpera.exec(ua);
if (match != null) {
browserMatch = { browser : match[1] || "", version : match[2] || "0" };
}
match = rChrome.exec(ua);
if (match != null) {
browserMatch = { browser : match[1] || "", version : match[2] || "0" };
}
match = rSafari.exec(ua);
if (match != null) {
browserMatch = { browser : match[2] || "", version : match[1] || "0" };
}
if (match != null) {
browserMatch = { browser : "", version : "0" };
}
if (s=ua.match(/opera.([\d.]+)/)) {
u.isOpera = true;
}else if(browserMatch.browser=="IE"&&browserMatch.version==11){
u.isIE11 = true;
u.isIE = true;
}else if (s=ua.match(/chrome\/([\d.]+)/)) {
u.isChrome = true;
u.isStandard = true;
} else if (s=ua.match(/version\/([\d.]+).*safari/)) {
u.isSafari = true;
u.isStandard = true;
} else if (s=ua.match(/gecko/)) {
//add by licza : support XULRunner
u.isFF = true;
u.isStandard = true;
} else if (s=ua.match(/msie ([\d.]+)/)) {
u.isIE = true;
}
else if (s=ua.match(/firefox\/([\d.]+)/)) {
u.isFF = true;
u.isStandard = true;
}
if (ua.match(/webkit\/([\d.]+)/)) {
u.isWebkit = true;
}
if (ua.match(/ipad/i)){
u.isIOS = true;
u.isIPAD = true;
u.isStandard = true;
}
if (ua.match(/iphone/i)){
u.isIOS = true;
u.isIphone = true;
}
if((navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel")){
//u.isIOS = true;
u.isMac = true;
}
if((navigator.platform == "Win32") || (navigator.platform == "Windows") || (navigator.platform == "Win64")){
u.isWin = true;
}
if((navigator.platform == "X11") && !u.isWin && !u.isMac){
u.isUnix = true;
}
if((String(navigator.platform).indexOf("Linux") > -1)){
u.isLinux = true;
}
if(ua.indexOf('Android') > -1 || ua.indexOf('android') > -1 || ua.indexOf('Adr') > -1 || ua.indexOf('adr') > -1){
u.isAndroid = true;
}
u.version = version ? (browserMatch.version ? browserMatch.version : 0) : 0;
if (u.isIE) {
var intVersion = parseInt(u.version);
var mode = document.documentMode;
if(mode == null){
if (intVersion == 6 || intVersion == 7) {
u.isIE8_BEFORE = true;
}
}
else{
if(mode == 7){
u.isIE8_BEFORE = true;
}
else if (mode == 8) {
u.isIE8 = true;
}
else if (mode == 9) {
u.isIE9 = true;
u.isSTANDARD = true;
}
else if (mode == 10) {
u.isIE10 = true;
u.isSTANDARD = true;
u.isIE10_ABOVE = true;
}
else{
u.isSTANDARD = true;
}
if (intVersion == 8) {
u.isIE8_CORE = true;
}
else if (intVersion == 9) {
u.isIE9_CORE = true;
}
else if(browserMatch.version==11){
u.isIE11 = true;
}
else{
}
}
}
if("ontouchend" in document) {
u.hasTouch = true;
}
if(u.isIOS || u.isAndroid)
u.isMobile = true;
})();
if (u.isIE8_BEFORE){
alert('uui 不支持IE8以前的浏览器版本,请更新IE浏览器或使用其它浏览器!')
throw new Error('uui 不支持IE8以前的浏览器版本,请更新IE浏览器或使用其它浏览器!');
}
if (u.isIE8 && !u.polyfill){
alert('IE8浏览器中使用uui 必须在u.js之前引入u-polyfill.js!');
throw new Error('IE8浏览器中使用uui 必须在uui之前引入u-polyfill.js!');
}
//TODO 兼容 后面去掉
//u.Core = u.core;
window.iweb = {};
window.iweb.Core = u.core;
window.iweb.browser = {
isIE: u.isIE,
isFF: u.isFF,
isOpera: u.isOpera,
isChrome: u.isChrome,
isSafari: u.isSafari,
isWebkit: u.isWebkit,
isIE8_BEFORE: u.isIE8_BEFORE,
isIE8: u.isIE8,
isIE8_CORE: u.isIE8_CORE,
isIE9: u.isIE9,
isIE9_CORE: u.isIE9_CORE,
isIE10: u.isIE10,
isIE10_ABOVE: u.isIE10_ABOVE,
isIE11: u.isIE11,
isIOS: u.isIOS,
isIphone: u.isIphone,
isIPAD: u.isIPAD,
isStandard: u.isStandard,
version: 0,
isWin: u.isWin,
isUnix: u.isUnix,
isLinux: u.isLinux,
isAndroid: u.isAndroid,
isMac: u.isMac,
hasTouch: u.hasTouch
};
u.isDomElement = function(obj) {
if (window['HTMLElement']) {
return obj instanceof HTMLElement;
} else {
return obj && obj.tagName && obj.nodeType === 1;
}
}
u.event = {};
var touchStartEvent = u.hasTouch ? "touchstart" : "mousedown",
touchStopEvent = u.hasTouch ? "touchend" : "mouseup",
touchMoveEvent = u.hasTouch ? "touchmove" : "mousemove";
// tap和taphold
u.event.tap = {
tapholdThreshold: 750,
emitTapOnTaphold: true,
touchstartFun:function(){
u.trigger(this,'vmousedown');
},
touchendFun:function(){
u.trigger(this,'vmouseup');
u.trigger(this,'vclick');
},
setup: function() {
var thisObject = this,
isTaphold = false;
u.on(thisObject, "vmousedown", function( event ) {
isTaphold = false;
if ( event.which && event.which !== 1 ) {
return false;
}
var origTarget = event.target,
timer;
function clearTapTimer() {
clearTimeout( timer );
}
function clearTapHandlers() {
clearTapTimer();
u.off(thisObject,'vclick');
u.off(thisObject,'vmouseup');
u.off(document,'vmousecancel');
}
function clickHandler( event ) {
clearTapHandlers();
// ONLY trigger a 'tap' event if the start target is
// the same as the stop target.
if ( !isTaphold && origTarget === event.target ) {
u.trigger(thisObject,'tap');
} else if ( isTaphold ) {
event.preventDefault();
}
}
u.on(thisObject, 'vmouseup',clearTapTimer);
u.on(thisObject, 'vclick',clickHandler);
u.on(document, 'vmousecancel',clearTapHandlers);
timer = setTimeout( function() {
if ( !u.event.tap.emitTapOnTaphold ) {
isTaphold = true;
}
u.trigger(thisObject, "taphold");
clearTapHandlers();
}, u.event.tap.tapholdThreshold );
});
u.on(thisObject,'touchstart',u.event.tap.touchstartFun);
u.on(thisObject,'touchend',u.event.tap.touchendFun);
},
teardown: function() {
u.off(thisObject,'vmousedown');
u.off(thisObject,'vclick');
u.off(thisObject,'vmouseup');
u.off(document,'vmousecancel');
}
};
u.event.taphold = u.event.tap;
u.event.swipe = {
// More than this horizontal displacement, and we will suppress scrolling.
scrollSupressionThreshold: 30,
// More time than this, and it isn't a swipe.
durationThreshold: 1000,
// Swipe horizontal displacement must be more than this.
horizontalDistanceThreshold: 30,
// Swipe vertical displacement must be less than this.
verticalDistanceThreshold: 30,
getLocation: function ( event ) {
var winPageX = window.pageXOffset,
winPageY = window.pageYOffset,
x = event.clientX,
y = event.clientY;
if ( event.pageY === 0 && Math.floor( y ) > Math.floor( event.pageY ) ||
event.pageX === 0 && Math.floor( x ) > Math.floor( event.pageX ) ) {
// iOS4 clientX/clientY have the value that should have been
// in pageX/pageY. While pageX/page/ have the value 0
x = x - winPageX;
y = y - winPageY;
} else if ( y < ( event.pageY - winPageY) || x < ( event.pageX - winPageX ) ) {
// Some Android browsers have totally bogus values for clientX/Y
// when scrolling/zooming a page. Detectable since clientX/clientY
// should never be smaller than pageX/pageY minus page scroll
x = event.pageX - winPageX;
y = event.pageY - winPageY;
}
return {
x: x,
y: y
};
},
start: function( event ) {
var data = event.touches ?
event.touches[ 0 ] : event,
location = u.event.swipe.getLocation( data );
return {
time: ( new Date() ).getTime(),
coords: [ location.x, location.y ],
origin: event.target
};
},
stop: function( event ) {
var data = event.touches ?
event.touches[ 0 ] : event,
location = u.event.swipe.getLocation( data );
return {
time: ( new Date() ).getTime(),
coords: [ location.x, location.y ]
};
},
handleSwipe: function( start, stop, thisObject, origTarget ) {
if ( stop.time - start.time < u.event.swipe.durationThreshold &&
Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > u.event.swipe.horizontalDistanceThreshold &&
Math.abs( start.coords[ 1 ] - stop.coords[ 1 ] ) < u.event.swipe.verticalDistanceThreshold ) {
var direction = start.coords[0] > stop.coords[ 0 ] ? "swipeleft" : "swiperight";
u.trigger( thisObject, "swipe");
u.trigger( thisObject, direction);
return true;
}
return false;
},
// This serves as a flag to ensure that at most one swipe event event is
// in work at any given time
eventInProgress: false,
setup: function() {
var events,
thisObject = this,
context = {};
// Retrieve the events data for this element and add the swipe context
events = thisObject["mobile-events"];
if ( !events ) {
events = { length: 0 };
thisObject["mobile-events"] = events;
}
events.length++;
events.swipe = context;
context.start = function( event ) {
// Bail if we're already working on a swipe event
if ( u.event.swipe.eventInProgress ) {
return;
}
u.event.swipe.eventInProgress = true;
var stop,
start = u.event.swipe.start( event ),
origTarget = event.target,
emitted = false;
context.move = function( event ) {
// if ( !start || event.isDefaultPrevented() ) {
if ( !start ) {
return;
}
stop = u.event.swipe.stop( event );
if ( !emitted ) {
emitted = u.event.swipe.handleSwipe( start, stop, thisObject, origTarget );
if ( emitted ) {
// Reset the context to make way for the next swipe event
u.event.swipe.eventInProgress = false;
}
}
// prevent scrolling
if ( Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > u.event.swipe.scrollSupressionThreshold ) {
event.preventDefault();
}
};
context.stop = function() {
emitted = true;
// Reset the context to make way for the next swipe event
u.event.swipe.eventInProgress = false;
u.off(document, touchMoveEvent, context.move);
context.move = null;
};
u.on(document, touchMoveEvent, context.move);
u.on(document, touchStopEvent, context.stop);
};
u.on(thisObject, touchStartEvent, context.start );
},
teardown: function() {
var events, context;
events = thisObject["mobile-events"];
if ( events ) {
context = events.swipe;
delete events.swipe;
events.length--;
if ( events.length === 0 ) {
thisObject["mobile-events"] = null;
}
}
if ( context ) {
if ( context.start ) {
u.off(thisObject, touchStartEvent, context.start);
}
if ( context.move ) {
u.off(document, touchMoveEvent, context.move);
}
if ( context.stop ) {
u.off(document, touchStopEvent, context.stop);
}
}
}
};
u.event.swipeleft = u.event.swipe;
u.event.swiperight = u.event.swipe;
NodeList.prototype.forEach = Array.prototype.forEach;
/**
* 获得字符串的字节长度
*/
String.prototype.lengthb = function() {
// var str = this.replace(/[^\x800-\x10000]/g, "***");
var str = this.replace(/[^\x00-\xff]/g, "**");
return str.length;
};
/**
* 将AFindText全部替换为ARepText
*/
String.prototype.replaceAll = function(AFindText, ARepText) {
//自定义String对象的方法
var raRegExp = new RegExp(AFindText, "g");
return this.replace(raRegExp, ARepText);
};
var XmlHttp = {
get : "get",
post : "post",
reqCount : 4,
createXhr : function() {
var xmlhttp = null;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
},
ajax : function(_json) {
var url = _json["url"];
var callback = _json["success"];
var async = (_json["async"] == undefined ? true : _json["async"]);
var error = _json["error"];
var params = _json["data"] || {};
var method = (_json["type"] == undefined ? XmlHttp.post : _json["type"]).toLowerCase();
var gzipFlag = params.compressType;
url = XmlHttp.serializeUrl(url);
params = XmlHttp.serializeParams(params);
if (method == XmlHttp.get && params != null) {
url += ("&" + params);
params = null; //如果是get请求,保证最终会执行send(null)
}
var xmlhttp = XmlHttp.createXhr();
xmlhttp.open(method, url, async);
if (method == XmlHttp.post) {
xmlhttp.setRequestHeader("Content-type",
"application/x-www-form-urlencoded;charset=UTF-8");
}
var execount = 0;
// 异步
if (async) {
// readyState 从 1~4发生4次变化
xmlhttp.onreadystatechange = function() {
execount++;
// 等待readyState状态不再变化之后,再执行回调函数
//if (execount == XmlHttp.reqCount) {// 火狐下存在问题,修改判断方式
if(this.readyState == XmlHttp.reqCount){
XmlHttp.execBack(xmlhttp, callback, error);
}
};
// send方法要在在回调函数之后执行
xmlhttp.send(params);
} else {
// 同步 readyState 直接变为 4
// 并且 send 方法要在回调函数之前执行
xmlhttp.send(params);
XmlHttp.execBack(xmlhttp, callback, error);
}
},
execBack : function(xmlhttp, callback, error) {
//if (xmlhttp.readyState == 4
if (xmlhttp.status == 200 || xmlhttp.status == 304) {
callback(xmlhttp.responseText,xmlhttp.status, xmlhttp);
} else {
if (error) {
error(xmlhttp.responseText,xmlhttp.status, xmlhttp);
} else {
var errorMsg = "no error callback function!";
if(xmlhttp.responseText) {
errorMsg = xmlhttp.responseText;
}
alert(errorMsg);
// throw errorMsg;
}
}
},
serializeUrl : function(url) {
var cache = "cache=" + Math.random();
if (url.indexOf("?") > 0) {
url += ("&" + cache);
} else {
url += ("?" + cache);
}
return url;
},
serializeParams : function(params) {
var ud = undefined;
if (ud == params || params == null || params == "") {
return null;
}
if (params.constructor == Object) {
var result = "";
for ( var p in params) {
result += (p + "=" + encodeURIComponent(params[p]) + "&");
}
return result.substring(0, result.length - 1);
}
return params;
}
};
//if ($ && $.ajax)
// u.ajax = $.ajax;
//else
u.ajax = XmlHttp.ajax;
var Class = function (o) {
if (!(this instanceof Class) && isFunction(o)) {
return classify(o)
}
}
// Create a new Class.
//
// var SuperPig = Class.create({
// Extends: Animal,
// Implements: Flyable,
// initialize: function() {
// SuperPig.superclass.initialize.apply(this, arguments)
// },
// Statics: {
// COLOR: 'red'
// }
// })
//
Class.create = function (parent, properties) {
if (!isFunction(parent)) {
properties = parent
parent = null
}
properties || (properties = {})
parent || (parent = properties.Extends || Class)
properties.Extends = parent
// The created class constructor
function SubClass() {
// Call the parent constructor.
parent.apply(this, arguments)
// Only call initialize in self constructor.
if (this.constructor === SubClass && this.initialize) {
this.initialize.apply(this, arguments)
}
}
// Inherit class (static) properties from parent.
if (parent !== Class) {
mix(SubClass, parent, parent.StaticsWhiteList)
}
// Add instance properties to the subclass.
implement.call(SubClass, properties)
// Make subclass extendable.
return classify(SubClass)
}
function implement(properties) {
var key, value
for (key in properties) {
value = properties[key]
if (Class.Mutators.hasOwnProperty(key)) {
Class.Mutators[key].call(this, value)
} else {
this.prototype[key] = value
}
}
}
// Create a sub Class based on `Class`.
Class.extend = function (properties) {
properties || (properties = {})
properties.Extends = this
return Class.create(properties)
}
function classify(cls) {
cls.extend = Class.extend
cls.implement = implement
return cls
}
// Mutators define special properties.
Class.Mutators = {
'Extends': function (parent) {
var existed = this.prototype
var proto = createProto(parent.prototype)
// Keep existed properties.
mix(proto, existed)
// Enforce the constructor to be what we expect.
proto.constructor = this
// Set the prototype chain to inherit from `parent`.
this.prototype = proto
// Set a convenience property in case the parent's prototype is
// needed later.
this.superclass = parent.prototype
},
'Implements': function (items) {
isArray(items) || (items = [items])
var proto = this.prototype,
item
while (item = items.shift()) {
mix(proto, item.prototype || item)
}
},
'Statics': function (staticProperties) {
mix(this, staticProperties)
}
}
// Shared empty constructor function to aid in prototype-chain creation.
function Ctor() {
}
// See: http://jsperf.com/object-create-vs-new-ctor
var createProto = Object.__proto__ ?
function (proto) {
return {
__proto__: proto
}
} :
function (proto) {
Ctor.prototype = proto
return new Ctor()
}
// Helpers
// ------------
function mix(r, s, wl) {
// Copy "all" properties including inherited ones.
for (var p in s) {
if (s.hasOwnProperty(p)) {
if (wl && indexOf(wl, p) === -1) continue
// 在 iPhone 1 代等设备的 Safari 中,prototype 也会被枚举出来,需排除
if (p !== 'prototype') {
r[p] = s[p]
}
}
}
}
var toString = Object.prototype.toString
var isArray = Array.isArray || function (val) {
return toString.call(val) === '[object Array]'
}
var isFunction = function (val) {
return toString.call(val) === '[object Function]'
}
var indexOf = function(arr, item){
if (Array.prototype.indexOf && arr.indexOf){
return arr.indexOf(item);
}else{
for (var i = 0, len = arr.length; i < len; i++) {
if (arr[i] === item) {
return i
}
}
return -1
}
}
u.Class = Class
function _findRegisteredClass(name, optReplace) {
for (var i = 0; i < CompMgr.registeredControls.length; i++) {
if (CompMgr.registeredControls[i].className === name) {
if (typeof optReplace !== 'undefined') {
CompMgr.registeredControls[i] = optReplace;
}
return CompMgr.registeredControls[i];
}
}
return false;
}
function _getUpgradedListOfElement(element) {
var dataUpgraded = element.getAttribute('data-upgraded');
// Use `['']` as default value to conform the `,name,name...` style.
return dataUpgraded === null ? [''] : dataUpgraded.split(',');
}
function _isElementUpgraded(element, jsClass) {
var upgradedList = _getUpgradedListOfElement(element);
return upgradedList.indexOf(jsClass) != -1;
}
function _upgradeElement(element, optJsClass) {
if (!(typeof element === 'object' && element instanceof Element)) {
throw new Error('Invalid argument provided to upgrade MDL element.');
}
var upgradedList = _getUpgradedListOfElement(element);
var classesToUpgrade = [];
if (!optJsClass) {
var className = element.className;
for(var i=0; i< CompMgr.registeredControls.length; i++){
var component = CompMgr.registeredControls[i]
if (className.indexOf(component.cssClass) > -1 && classesToUpgrade.indexOf(component) === -1 &&
!_isElementUpgraded(element, component.className)) {
classesToUpgrade.push(component);
}
}
} else if (!_isElementUpgraded(element, optJsClass)) {
classesToUpgrade.push(_findRegisteredClass(optJsClass));
}
// Upgrade the element for each classes.
for (var i = 0, n = classesToUpgrade.length, registeredClass; i < n; i++) {
registeredClass = classesToUpgrade[i];
if (registeredClass) {
if (element[registeredClass.className]){
continue;
}
// Mark element as upgraded.
upgradedList.push(registeredClass.className);
element.setAttribute('data-upgraded', upgradedList.join(','));
var instance = new registeredClass.classConstructor(element);
CompMgr.createdControls.push(instance);
// Call any callbacks the user has registered with this component type.
for (var j = 0, m = registeredClass.callbacks.length; j < m; j++) {
registeredClass.callbacks[j](element);
}
element[registeredClass.className] = instance;
} else {
throw new Error('Unable to find a registered component for the given class.');
}
}
}
function _upgradeDomInternal(optJsClass, optCssClass, ele) {
if (typeof optJsClass === 'undefined' && typeof optCssClass === 'undefined') {
for (var i = 0; i < CompMgr.registeredControls.length; i++) {
_upgradeDomInternal(CompMgr.registeredControls[i].className, registeredControls[i].cssClass, ele);
}
} else {
var jsClass = (optJsClass);
if (!optCssClass) {
var registeredClass = _findRegisteredClass(jsClass);
if (registeredClass) {
optCssClass = registeredClass.cssClass;
}
}
var _ele = ele ? ele : document;
var elements = _ele.querySelectorAll('.' + optCssClass);
for (var n = 0; n < elements.length; n++) {
_upgradeElement(elements[n], jsClass);
}
}
}
var CompMgr = {
plugs: {},
dataAdapters:{},
/** 注册的控件*/
registeredControls: [],
createdControls: [],
/**
*
* @param options {el:'#content', model:{}}
*/
apply: function (options) {
if(options){
var _el = options.el||document.body;
var model = options.model;
}
if (typeof _el == 'string'){
_el = document.body.querySelector(_el);
}
if (_el == null || typeof _el != 'object')
_el = document.body;
var comps =_el.querySelectorAll('[u-meta]');
comps.forEach(function(element){
if (element['comp']) return;
var options = JSON.parse(element.getAttribute('u-meta'));
if (options && options['type']) {
//var comp = CompMgr._createComp({el:element,options:options,model:model});
var comp = CompMgr.createDataAdapter({el:element,options:options,model:model});
if (comp){
element['adpt'] = comp;
element['u-meta'] = comp;
}
}
});
},
addPlug: function (config) {
var plug = config['plug'],
name = config['name'];
this.plugs || (this.plugs = {});
if (this.plugs[name]) {
throw new Error('plug has exist:' + name);
}
plug.compType = name;
this.plugs[name] = plug
},
addDataAdapter: function(config){
var adapter = config['adapter'],
name = config['name'];
//dataType = config['dataType'] || ''
//var key = dataType ? name + '.' + dataType : name;
this.dataAdapters || (dataAdapters = {});
if(this.dataAdapters[name]){
throw new Error('dataAdapter has exist:' + name);
}
this.dataAdapters[name] = adapter;
},
getDataAdapter: function(name){
if (!name) return;
this.dataAdapters || (dataAdapters = {});
//var key = dataType ? name + '.' + dataType : name;
return this.dataAdapters[name];
},
createDataAdapter: function(options){
var opt = options['options'];
var type = opt['type'],
id = opt['id'];
var adpt = this.dataAdapters[type];
if (!adpt) return null;
var comp = new adpt(options);
comp.type = type;
comp.id = id;
return comp;
},
_createComp: function (options) {
var opt = options['options'];
var type = opt['type'];
var plug = this.plugs[type];
if (!plug) return null;
var comp = new plug(options);
comp.type = type;
return comp;
},
/**
* 注册UI控件
*/
regComp: function(config){
var newConfig = {
classConstructor: config.comp,
className: config.compAsString || config['compAsString'],
cssClass: config.css || config['css'],
callbacks: []
};
config.comp.prototype.compType = config.compAsString;
for(var i=0; i< this.registeredControls.length; i++){
var item = this.registeredControls[i];
//registeredControls.forEach(function(item) {
if (item.cssClass === newConfig.cssClass) {
throw new Error('The provided cssClass has already been registered: ' + item.cssClass);
}
if (item.className === newConfig.className) {
throw new Error('The provided className has already been registered');
}
};
this.registeredControls.push(newConfig);
},
updateComp: function(ele){
for (var n = 0; n < this.registeredControls.length; n++) {
_upgradeDomInternal(this.registeredControls[n].className,null ,ele);
}
}
};
u.compMgr = CompMgr;
///**
// * 加载控件
// */
//
//if (document.readyState && document.readyState === 'complete'){
// u.compMgr.updateComp();
//}else{
// u.on(window, 'load', function() {
//
// //扫描并生成控件
// u.compMgr.updateComp();
// });
//}
if (window.i18n) {
var scriptPath = getCurrentJsPath(),
_temp = scriptPath.substr(0, scriptPath.lastIndexOf('/')),
__FOLDER__ = _temp.substr(0, _temp.lastIndexOf('/'))
u.uuii18n = u.extend({}, window.i18n)
u.uuii18n.init({
postAsync: false,
getAsync: false,
fallbackLng: false,
ns: {namespaces: ['uui-trans']},
resGetPath: __FOLDER__ + '/locales/__lng__/__ns__.json'
})
}
window.trans = u.trans = function (key, dftValue) {
return u.uuii18n ? u.uuii18n.t('uui-trans:' + key) : dftValue
}
/* ========================================================================
* UUI: rsautils.js v 1.0.0
*
* ========================================================================
* Copyright 2015 yonyou, Inc.
* Licensed under MIT ()
* ======================================================================== */
/*
* u.RSAUtils.encryptedString({exponent: 'xxxxx', modulus: 'xxxxx', text: 'xxxxx'})
* u.RSAUtils.decryptedString({exponent: 'xxxxx', modulus: 'xxxxx', text: 'xxxxx'})
*/
if (typeof u.RSAUtils === 'undefined')
u.RSAUtils = {};
var RSAUtils = u.RSAUtils;
var biRadixBase = 2;
var biRadixBits = 16;
var bitsPerDigit = biRadixBits;
var biRadix = 1 << 16; // = 2^16 = 65536
var biHalfRadix = biRadix >>> 1;
var biRadixSquared = biRadix * biRadix;
var maxDigitVal = biRadix - 1;
var maxInteger = 9999999999999998;
//maxDigits:
//Change this to accommodate your largest number size. Use setMaxDigits()
//to change it!
//
//In general, if you're working with numbers of size N bits, you'll need 2*N
//bits of storage. Each digit holds 16 bits. So, a 1024-bit key will need
//
//1024 * 2 / 16 = 128 digits of storage.
//
var maxDigits;
var ZERO_ARRAY;
var bigZero, bigOne;
var BigInt = u.BigInt = function (flag) {
if (typeof flag == "boolean" && flag == true) {
this.digits = null;
} else {
this.digits = ZERO_ARRAY.slice(0);
}
this.isNeg = false;
};
RSAUtils.setMaxDigits = function (value) {
maxDigits = value;
ZERO_ARRAY = new Array(maxDigits);
for (var iza = 0; iza < ZERO_ARRAY.length; iza++) ZERO_ARRAY[iza] = 0;
bigZero = new BigInt();
bigOne = new BigInt();
bigOne.digits[0] = 1;
};
RSAUtils.setMaxDigits(20);
//The maximum number of digits in base 10 you can convert to an
//integer without JavaScript throwing up on you.
var dpl10 = 15;
RSAUtils.biFromNumber = function (i) {
var result = new BigInt();
result.isNeg = i < 0;
i = Math.abs(i);
var j = 0;
while (i > 0) {
result.digits[j++] = i & maxDigitVal;
i = Math.floor(i / biRadix);
}
return result;
};
//lr10 = 10 ^ dpl10
var lr10 = RSAUtils.biFromNumber(1000000000000000);
RSAUtils.biFromDecimal = function (s) {
var isNeg = s.charAt(0) == '-';
var i = isNeg ? 1 : 0;
var result;
// Skip leading zeros.
while (i < s.length && s.charAt(i) == '0') ++i;
if (i == s.length) {
result = new BigInt();
}
else {
var digitCount = s.length - i;
var fgl = digitCount % dpl10;
if (fgl == 0) fgl = dpl10;
result = RSAUtils.biFromNumber(Number(s.substr(i, fgl)));
i += fgl;
while (i < s.length) {
result = RSAUtils.biAdd(RSAUtils.biMultiply(result, lr10),
RSAUtils.biFromNumber(Number(s.substr(i, dpl10))));
i += dpl10;
}
result.isNeg = isNeg;
}
return result;
};
RSAUtils.biCopy = function (bi) {
var result = new BigInt(true);
result.digits = bi.digits.slice(0);
result.isNeg = bi.isNeg;
return result;
};
RSAUtils.reverseStr = function (s) {
var result = "";
for (var i = s.length - 1; i > -1; --i) {
result += s.charAt(i);
}
return result;
};
var hexatrigesimalToChar = [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z'
];
RSAUtils.biToString = function (x, radix) { // 2 <= radix <= 36
var b = new BigInt();
b.digits[0] = radix;
var qr = RSAUtils.biDivideModulo(x, b);
var result = hexatrigesimalToChar[qr[1].digits[0]];
while (RSAUtils.biCompare(qr[0], bigZero) == 1) {
qr = RSAUtils.biDivideModulo(qr[0], b);
digit = qr[1].digits[0];
result += hexatrigesimalToChar[qr[1].digits[0]];
}
return (x.isNeg ? "-" : "") + RSAUtils.reverseStr(result);
};
RSAUtils.biToDecimal = function (x) {
var b = new BigInt();
b.digits[0] = 10;
var qr = RSAUtils.biDivideModulo(x, b);
var result = String(qr[1].digits[0]);
while (RSAUtils.biCompare(qr[0], bigZero) == 1) {
qr = RSAUtils.biDivideModulo(qr[0], b);
result += String(qr[1].digits[0]);
}
return (x.isNeg ? "-" : "") + RSAUtils.reverseStr(result);
};
var hexToChar = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'];
RSAUtils.digitToHex = function (n) {
var mask = 0xf;
var result = "";
for (var i = 0; i < 4; ++i) {
result += hexToChar[n & mask];
n >>>= 4;
}
return RSAUtils.reverseStr(result);
};
RSAUtils.biToHex = function (x) {
var result = "";
var n = RSAUtils.biHighIndex(x);
for (var i = RSAUtils.biHighIndex(x); i > -1; --i) {
result += RSAUtils.digitToHex(x.digits[i]);
}
return result;
};
RSAUtils.charToHex = function (c) {
var ZERO = 48;
var NINE = ZERO + 9;
var littleA = 97;
var littleZ = littleA + 25;
var bigA = 65;
var bigZ = 65 + 25;
var result;
if (c >= ZERO && c <= NINE) {
result = c - ZERO;
} else if (c >= bigA && c <= bigZ) {
result = 10 + c - bigA;
} else if (c >= littleA && c <= littleZ) {
result = 10 + c - littleA;
} else {
result = 0;
}
return result;
};
RSAUtils.hexToDigit = function (s) {
var result = 0;
var sl = Math.min(s.length, 4);
for (var i = 0; i < sl; ++i) {
result <<= 4;
result |= RSAUtils.charToHex(s.charCodeAt(i));
}
return result;
};
RSAUtils.biFromHex = function (s) {
var result = new BigInt();
var sl = s.length;
for (var i = sl, j = 0; i > 0; i -= 4, ++j) {
result.digits[j] = RSAUtils.hexToDigit(s.substr(Math.max(i - 4, 0), Math.min(i, 4)));
}
return result;
};
RSAUtils.biFromString = function (s, radix) {
var isNeg = s.charAt(0) == '-';
var istop = isNeg ? 1 : 0;
var result = new BigInt();
var place = new BigInt();
place.digits[0] = 1; // radix^0
for (var i = s.length - 1; i >= istop; i--) {
var c = s.charCodeAt(i);
var digit = RSAUtils.charToHex(c);
var biDigit = RSAUtils.biMultiplyDigit(place, digit);
result = RSAUtils.biAdd(result, biDigit);
place = RSAUtils.biMultiplyDigit(place, radix);
}
result.isNeg = isNeg;
return result;
};
RSAUtils.biDump = function (b) {
return (b.isNeg ? "-" : "") + b.digits.join(" ");
};
RSAUtils.biAdd = function (x, y) {
var result;
if (x.isNeg != y.isNeg) {
y.isNeg = !y.isNeg;
result = RSAUtils.biSubtract(x, y);
y.isNeg = !y.isNeg;
}
else {
result = new BigInt();
var c = 0;
var n;
for (var i = 0; i < x.digits.length; ++i) {
n = x.digits[i] + y.digits[i] + c;
result.digits[i] = n % biRadix;
c = Number(n >= biRadix);
}
result.isNeg = x.isNeg;
}
return result;
};
RSAUtils.biSubtract = function (x, y) {
var result;
if (x.isNeg != y.isNeg) {
y.isNeg = !y.isNeg;
result = RSAUtils.biAdd(x, y);
y.isNeg = !y.isNeg;
} else {
result = new BigInt();
var n, c;
c = 0;
for (var i = 0; i < x.digits.length; ++i) {
n = x.digits[i] - y.digits[i] + c;
result.digits[i] = n % biRadix;
// Stupid non-conforming modulus operation.
if (result.digits[i] < 0) result.digits[i] += biRadix;
c = 0 - Number(n < 0);
}
// Fix up the negative sign, if any.
if (c == -1) {
c = 0;
for (var i = 0; i < x.digits.length; ++i) {
n = 0 - result.digits[i] + c;
result.digits[i] = n % biRadix;
// Stupid non-conforming modulus operation.
if (result.digits[i] < 0) result.digits[i] += biRadix;
c = 0 - Number(n < 0);
}
// Result is opposite sign of arguments.
result.isNeg = !x.isNeg;
} else {
// Result is same sign.
result.isNeg = x.isNeg;
}
}
return result;
};
RSAUtils.biHighIndex = function (x) {
var result = x.digits.length - 1;
while (result > 0 && x.digits[result] == 0) --result;
return result;
};
RSAUtils.biNumBits = function (x) {
var n = RSAUtils.biHighIndex(x);
var d = x.digits[n];
var m = (n + 1) * bitsPerDigit;
var result;
for (result = m; result > m - bitsPerDigit; --result) {
if ((d & 0x8000) != 0) break;
d <<= 1;
}
return result;
};
RSAUtils.biMultiply = function (x, y) {
var result = new BigInt();
var c;
var n = RSAUtils.biHighIndex(x);
var t = RSAUtils.biHighIndex(y);
var u, uv, k;
for (var i = 0; i <= t; ++i) {