62,041
社区成员
发帖
与我相关
我的任务
分享
},
loadinfo: function(infoFont, options) {
options = $.extend({
flag: true,
offset: 'right',
width: 100,
color: '#fff',
backgroundcolor: '#000',
opacity: 0.8
}, options);
if (!options.flag) {
$('#loadinfo').fadeOut('slow', function() { $(this).remove(); });
} else {
$('body').append('<div id="loadinfo"></div>');
var info = $('#loadinfo').hide().css({
'background': options.backgroundcolor,
'position': 'fixed',
'overflow': 'hidden',
'z-index': '999999',
'padding': '10px 10px 10px 10px',
'font-size': '12px',
'color': options.color,
'opacity': options.opacity,
'width': options.width
}).html(infoFont).corner();
var offset = pack.getPageScroll();
var offwh = pack.getPageSize();
var top;
var left;
switch (options.offset) {
case 'right':
top = offset[0] + 10;
left = !$.browser.msie ? offwh[0] - $(info).width() - 40 : offwh[0] - $(info).width() - 30;
break;
case 'left':
top = 10;
left = 10;
break;
case 'center':
top = $.browser.msie && ($.browser.version < 7) ? (offwh[1] - $(info).height()) / 2 + offset[1] : (offwh[1] - $(info).height()) / 2;
left = $.browser.msie && ($.browser.version < 7) ? (offwh[0] - $(info).width()) / 2 : (offwh[0] - $(info).width()) / 2;
break;
}
if ($.browser.msie && ($.browser.version < 7)) {
$(info).css({
'position': 'absolute'
})
}
$(info).css({
'top': top,
'left': left
}).fadeIn('slow');
}
},
insertAtText: function(textObj, textFeildValue) {
if ($.browser.msie) {
if (document.selection) {
textObj.focus();
textObj = document.selection.createRange();
textObj.text = textFeildValue;
}
} else {
if (document.all && textObj.createTextRange && textObj.caretPos) {
var caretPos = textObj.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? textFeildValue + '' : textFeildValue;
} else if (textObj.setSelectionRange) {
var rangeStart = textObj.selectionStart;
var rangeEnd = textObj.selectionEnd;
var tempStr1 = textObj.value.substring(0, rangeStart);
var tempStr2 = textObj.value.substring(rangeEnd);
textObj.value = tempStr1 + textFeildValue + tempStr2;
textObj.focus();
var len = textFeildValue.length;
textObj.setSelectionRange(rangeStart + len, rangeStart + len);
textObj.blur();
} else {
textObj.value += textFeildValue;
}
}
}
};
var pack = {
urlParameters: function(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
},
htmlEncode: function(value) {
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/\"/g, """).replace(/\'/g, "'");
},
htmlDecode: function(value) {
return value.replace(/\&\;/g, '\&').replace(/\>\;/g, '\>').replace(/\<\;/g, '\<').replace(/\"\;/g, '\'').replace(/\&\#39\;/g, '\'');
},
checkIsNumber: function(value) {
var regexp = /^[0-9]+$/;
if (regexp.test(obj)) {
return true;
} else {
return false;
}
},
format: function(value, arguments) {
if (arguments.length == 0)
return null;
var str = value;
for (var i = 0; i < arguments.length; i++) {
var re = new RegExp('\\{' + (i) + '\\}', 'gm');
str = str.replace(re, arguments[i]);
}
return str;
},
resizeImg: function(wContainer, hContainer, boxId) {
var imgs = document.getElementById(boxId).getElementsByTagName("img");
for (var i = 0; i < imgs.length; i++) {
var $w, $h;
$w = imgs[i].width;
$h = imgs[i].height;
imgs[i].removeAttribute('width');
imgs[i].removeAttribute('height');
imgs[i].removeAttribute('style');
if ($w > wContainer) {
$h = $h * (wContainer / $w);
$w = wContainer;
if ($h > wContainer) {
$w = $w * (hContainer / $h);
$h = hContainer;
}
} else if ($h > hContainer) {
$w = $w * (hContainer / $h);
$h = hContainer;
if ($w > wContainer) {
$h = $h * (wContainer / $w);
$w = wContainer;
}
}
imgs[i].width = $w;
imgs[i].height = $h;
imgs[i].style.cursor = "hand";
imgs[i].onclick = function() {
window.open(this.src);
}
}
},
getPageScroll: function() {
var xScroll, yScroll;
if (self.pageYOffset) {
yScroll = self.pageYOffset;
xScroll = self.pageXOffset;
} else if (document.documentElement && document.documentElement.scrollTop) {
yScroll = document.documentElement.scrollTop;
xScroll = document.documentElement.scrollLeft;
} else if (document.body) {
yScroll = document.body.scrollTop;
xScroll = document.body.scrollLeft;
}
return new Array(xScroll, yScroll)
},
getPageSize: function() {
var windowHeight, windowWidth;
if (self.innerHeight) {
windowHeight = self.innerHeight;
windowWidth = self.innerWidth;
} else if (document.documentElement && document.documentElement.clientHeight) {
windowHeight = document.documentElement.clientHeight;
windowWidth = document.documentElement.clientWidth;
} else if (document.body) {
windowHeight = document.body.clientHeight;
windowWidth = document.body.clientWidth;
}
return new Array(windowWidth, windowHeight);
},
addBookmark: function(title, url) {
if (window.sidebar) {
window.sidebar.addPanel(title, url, "");
} else if (document.all) {
window.external.AddFavorite(url, title);
} else if (window.opera && window.print) {
return true;
}
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
gap,
indent,
meta = {'\b': '\\b','\t': '\\t','\n': '\\n','\f': '\\f','\r': '\\r','"': '\\"','\\': '\\\\'},
rep;
$.extend({
parseJson: function(value, reviver) {
function parse(text, reviver) {
var j;
function walk(holder, key) {
var k, v, value = holder[key];
if (value && typeof value === 'object') {
for (k in value) {
if (Object.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if (v !== undefined) {
value[k] = v;
} else {
delete value[k];
}
}
}
}
return reviver.call(holder, key, value);
}
cx.lastIndex = 0;
if (cx.test(text)) {
text = text.replace(cx, function(a) {
return '\\u' +
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
});
}
if (/^[\],:{}\s]*$/.
test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
j = eval('(' + text + ')');
return typeof reviver === 'function' ?
walk({ '': j }, '') : j;
}
};
return parse(value, reviver);
},
toJsonString: function(value, replacer, space) {
var i;
gap = '';
indent = '';
if (typeof space === 'number') {
for (i = 0; i < space; i += 1) {
indent += ' ';
}
} else if (typeof space === 'string') {
indent = space;
}
rep = replacer;
if (replacer && typeof replacer !== 'function' &&
(typeof replacer !== 'object' ||
typeof replacer.length !== 'number')) {
throw new Error('JSON.stringify');
}
function f(n) {
return n < 10 ? '0' + n : n;
}
if (typeof Date.prototype.toJSON !== 'function') {
Date.prototype.toJSON = function(key) {
return this.getUTCFullYear() + '-' +
f(this.getUTCMonth() + 1) + '-' +
f(this.getUTCDate()) + 'T' +
f(this.getUTCHours()) + ':' +
f(this.getUTCMinutes()) + ':' +
f(this.getUTCSeconds()) + 'Z';
};
String.prototype.toJSON =
Number.prototype.toJSON =
Boolean.prototype.toJSON = function(key) {
return this.valueOf();
};
}
function quote(string) {
escapable.lastIndex = 0;
return escapable.test(string) ?
'"' + string.replace(escapable, function(a) {
var c = meta[a];
return typeof c === 'string' ? c :
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
}) + '"' :
'"' + string + '"';
}
function str(key, holder) {
var i,
k,
v,
length,
mind = gap,
partial,
value = holder[key];
if (value && typeof value === 'object' &&
typeof value.toJSON === 'function') {
value = value.toJSON(key);
}
if (typeof rep === 'function') {
value = rep.call(holder, key, value);
}
switch (typeof value) {
case 'string':
return quote(value);
case 'number':
return isFinite(value) ? String(value) : 'null';
case 'boolean':
case 'null':
return String(value);
case 'object':
if (!value) {
return 'null';
}
gap += indent;
partial = [];
if (Object.prototype.toString.apply(value) === '[object Array]') {
length = value.length;
for (i = 0; i < length; i += 1) {
partial[i] = str(i, value) || 'null';
}
v = partial.length === 0 ? '[]' :
gap ? '[\n' + gap +
partial.join(',\n' + gap) + '\n' +
mind + ']' :
'[' + partial.join(',') + ']';
gap = mind;
return v;
}
if (rep && typeof rep === 'object') {
length = rep.length;
for (i = 0; i < length; i += 1) {
k = rep[i];
if (typeof k === 'string') {
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
}
}
}
} else {
for (k in value) {
if (Object.hasOwnProperty.call(value, k)) {
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
}
}
}
}
v = partial.length === 0 ? '{}' :
gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
mind + '}' : '{' + partial.join(',') + '}';
gap = mind;
return v;
}
}
return str('', { '': value });
}
});