//判断是否为函数 U.MS.IsYX = function (UCB) { if (this == null) { throw new Error("this is null or not defined"); } //不允许为空 else if ({}.toString.call(UCB) != "[object Function]") { throw new Error(UCB + " is not a function"); } //没有回调不成立 else { return true; }; return false; } //下一个节点 U.M.nextSibling = function (obj) { while (obj.nextSibling.nodeType != 1) { obj = obj.nextSibling; } return obj.nextSibling; } //前一个节点 U.M.previousSibling = function (obj) { while (obj.previousSibling.nodeType != 1) { obj = obj.previousSibling; } return obj.previousSibling; } //Error具有下面一些主要属性: //description: 错误描述 (仅IE可用). //fileName: 出错的文件名 (仅Mozilla可用). //lineNumber: 出错的行数 (仅Mozilla可用). //message: 错误信息 (在IE下同description) //name: 错误类型. //number: 错误代码 (仅IE可用). //stack: 像Java中的Stack Trace一样的错误堆栈信息 (仅Mozilla可用). //--------------------------------------统一try cache--------------------------------- U.MC.TC = {}; //保存前台错误的集合,暂时显示在前台,以后存入后台 U.MC.TCatch = function (f) { try { (typeof (f) == "string") ? eval(f) : f; } catch (e) { Add(U.MC.TC, { "类型": e.name, "错误信息": e.message, "时间": U.MT.formatDateToArray(new Date()) }); } } //兼容SetCapture函数 U.M.SetCapture = function (obj) { return document.all ? obj.setCapture() : window.captureEvents(Event.MOUSEMOVE); } //兼容releaseCapture函数 U.M.releaseCapture = function (obj) { document.all ? obj.releaseCapture() : window.releaseEvents(Event.MOUSEUP); } //兼容加载事件与脚本 func为函数 U.M.LoadEvent = function (func) { var oldonload = window.onload; //判断对象是否为一个事件,是则直接执行 if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function () { oldonload(); func(); } } } //函数功能:获取键盘码,兼容Onkeydown事件 U.M.getKeyCode = function (e) { e = e || window.event; keynum = e.keyCode ? e.keyCode : e.which; return keynum; } //事件代理机制,避免频繁添加事件操作。浪费代码,加大复杂度。 U.M.GetEventTarget = function (e) {//判断浏览器类型以兼容事件 e = e || window.event; return e.target || e.srcElement; } //Click()事件调用兼容 U.M.invokeClick = function (element) { if (element.click) element.click(); //判断是否支持click() 事件 else if (element.fireEvent) element.fireEvent('onclick'); //触发click() 事件 else if (document.createEvent) { var evt = document.createEvent("MouseEvents"); //创建click() 事件 evt.initEvent("click", true, true); //初始化click() 事件 element.dispatchEvent(evt); //分发click() 事件 } } //dblClick()事件调用兼容 U.M.dblClick = function (element) { if (element.ondblclick) element.ondblclick(); //判断是否支持dblClick() 事件 else if (element.fireEvent) element.fireEvent('ondblclick'); //触发dblClick() 事件 else if (document.createEvent) { var evt = document.createEvent("MouseEvents"); //创建ondblclick() 事件 evt.initEvent("dblclick", true, true); //初始化ondblclick() 事件 element.dispatchEvent(evt); //分发ondblclick() 事件 } } //------------------------------------------------------------------监听事件注册和取消区域--------------------------------------------------------------- //注意:只有被addEventListener方法添加的事件才可以使用removeEventListener来注销. //如果你直接使用onclick或onkeyup直接写在元素内的事件.将无法使用removeEventListener来删除. U.M.removeEvent = function (oTarget, sEventType, funName) { if (oTarget.removeEventListener) {//for DOM; oTarget.removeEventListener(sEventType, funName, false); } else if (oTarget.detachEvent) { oTarget.detachEvent("on" + sEventType, funName); } else { oTarget["on" + sEventType] = null; } } //函数作用:为元素添加事件 //oTarget:元素对象;sEventType:事件类型,例如点击则为click;funName:事件触发的函数名; U.AFB.AddEvent = function (oTarget, sEventType, funName) { if (oTarget.addEventListener) {//Dom浏览器触发 oTarget.addEventListener(sEventType, funName, false); } else if (oTarget.attachEvent) { //IE oTarget.attachEvent("on" + sEventType, funName); } else { oTarget["on" + sEventType] = funName; } } //屏蔽错误 U.M.killErrors = function (sMsg, sUrl, sLine) { //onerror函数的三个参数用于确定错误确切的信息,代表的意思依次为:错误信息;发生错误的文件;发生错误的行号。 // var oErrorLog = document.createElement("div"); // oErrorLog.innerHTML = "An error was thrown and caught.
";
// oErrorLog.innerHTML += "Error: " + sMsg + "
";
// oErrorLog.innerHTML += "Line: " + sLine + "
";
// oErrorLog.innerHTML += "URL: " + sUrl + "
";
return true;
}
//屏蔽按键操作。
U.M.forbiddenKey = function () {
if (event.keyCode == 116) { event.keyCode = 0; event.returnValue = false; } //屏蔽f5刷新
}
//屏蔽div右键
U.M.ForbiddenDivRightMouseClick = function (obj) {
obj.oncontextmenu = function () { return false; }
}
//规范插入的图片大小--杨嘉城
U.M.norm_img = function (SO) {
var _ISO = $("img", SO);
for (var i = 0; i < _ISO.length; i++) {
if (_ISO[i].clientWidth >= 1024) { _ISO[i].width = "900px"; }
}
}
//设置字体
U.M.setuserbackgroundfont = function (obj) {
if (obj != null) {
var allelments = parent.document.getElementsByTagName('*');
var i;
for (i = 0; i < allelments.length; i++) {
allelments[i].style.fontSize = obj + "px";
}
}
}
//去掉所有空格和标点符号
U.MS.dropSpaceAndDot = function (obj) {
str = obj.value;
var pattern = new RegExp("[`~!#$^&*()=|{}':;',\\[\\].<>/?~#……&*()&;—|{}‘;:”“'。,、]");
var newstr = "";
for (i = 0; i < str.length; i++) {
if (str.substr(i, 1) == " ") {
continue;
}
newstr += str.substr(i, 1).replace(pattern, "");
}
obj.innerText = newstr;
//U.M.textCompatibleandStr(obj, newstr)
}
//判断字符串类型是是否带有' '这样的字符
U.M.isBlank = function (szStr) {
for (i = 0; i < szStr.length; i++) {
if (szStr.substring(i, i + 1) == ' ') {
return false;
}
break;
}
return true;
}
// 检查序列号格式 目前的格式类似 GUID {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
U.MS.Checkguid = function (object_value) {
if (object_value.length == 0)
return false;
if (object_value.length != 38)
return false;
if (object_value.charAt(0) != "{")
return false;
if (object_value.charAt(37) != "}")
return false;
var hex_format = "0123456789abcdefABCDEF";
var check_char;
for (var i = 1; i < 37; i++) {
if ((i == 9) || (i == 14) || (i == 19) || (i == 24)) {
if (object_value.charAt(i) != "-")
return false;
} else {
check_char = hex_format.indexOf(object_value.charAt(i));
if (check_char < 0)
return false;
}
}
return true;
}
//跟进时间判定早中午时间,此函数未被使用
U.MT.GetNowTime = function () {
var time = new Date();
var TimePart = document.getElementById("TimePart");
var DataTime = time.getHours();
if (DataTime >= 0 && DataTime < 12) {
TimePart.innerHTML = "早上好!";
}
else if (DataTime >= 12 && DataTime < 18) {
TimePart.innerHTML = "下午好!";
}
else {
TimePart.innerHTML = "晚上好!";
}
}
//使用U.MT.currenttime函数时转换UTC() 方法可根据世界时返回 1970 年 1 月 1 日 到指定日期的毫秒数。
//Date.UTC(year,month,day,hours,minutes,seconds,ms)
U.MT.DateUTC = function (STime) {
STime = STime.split(" ");
var MY = STime[0].split("/");
var MS = STime[STime.length - 1].split(":");
return "/Date(" + Date.UTC(MY[0], MY[1], MY[2], MS[0], MS[1], MS[2], 0) + ")/";
}
////把json时间戳转为日期格式
U.MT.getLocalTime = function (nS) {
var _timeS = new Date(parseInt(nS.substring(6, nS.length - 2))).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
if (!top.browser.msie) _timeS = _timeS.substring(10, 25);
return _timeS;
}
//js获取当前的时间
U.MT.currenttime = function () {
var _currenttime = new Date();
var _year = U.MT.getYear()//获取当前的年数
var _month = _currenttime.getMonth() + 1; //获取当前的月份
var _date = _currenttime.getDate(); //获取当前的日期
var _houst = _currenttime.getHours(); //获取当前的小时
var _Minutes = _currenttime.getMinutes(); //获取当前的分钟
var _Seconds = _currenttime.getSeconds(); //获取当前的秒数
return _year + '/' + _month + '/' + _date + ' ' + _houst + ':' + _Minutes + ':' + _Seconds; //返回用户现在的时间段 且样式复合项目的需求
}
U.MT.getDate = function (D) {
if (D == null) { D = new Date(); }
// if (date == null || date == "" || date == "undefined") date = new Date();
// var yyyy = date.getFullYear();
// var m = date.getMonth() + 1;
// var mm = (m < 10) ? '0' + m : m;
// var d = date.getDate();
// var dd = (d < 10) ? '0' + d : d;
// var h = date.getHours();
// var hh = (h < 10) ? '0' + h : h;
// var n = date.getMinutes();
// var nn = (n < 10) ? '0' + n : n;
// var s = date.getSeconds();
// var ss = (s < 10) ? '0' + s : s;
// return yyyy + "-" + mm + "-" + dd + " " + hh + ":" + nn + ":" + ss;
}
//返回月份的方法
U.MT.GetMonth = function (month) {
switch (month) {
case "Jan":
return "1";
break;
case "Feb":
return "2";
break;
case "Mar":
return "3";
break;
case "Apr":
return "4";
break;
case "May":
return "5";
break;
case "Jun":
return "6";
break;
case "Jul":
return "7";
break;
case "Aug":
return "8";
break;
case "Sep":
return "9";
break;
case "Oct":
return "10";
break;
case "Nov":
return "11";
break;
case "Dec":
return "12";
break;
}
}
//转化星期
U.MT.Getweek = function (week) {
switch (week) {
case "Mon":
return "一";
break;
case "Tue":
return "二";
break;
case "Wed":
return "三";
break;
case "Thu":
return "四";
break;
case "Fri":
return "五";
break;
case "Sat":
return "六";
break;
case "Sun":
return "七";
break;
}
}
U.MT.DataTime = function (time) {
time = eval('new ' + eval(time).source) + "";
var strtime;
_strtime = time.split(" ");
_strtime[1] = U.MT.GetMonth(_strtime[1]); // 转化月份
_strtime[0] = U.MT.Getweek(_strtime[0]); //转化星期
return _strtime;
}
//用于blog的时间转换...转入2013-2-2 10:28:00 ...返回2013 2 2 10:28:00
U.MT.DateAnalyze = function (TD) {
TD = TD.split(" ");
var MT = TD[0].split("/");
MT = MT[0].split("-")
MT[3] = TD[TD.length - 1];
return MT;
}
//转换普通时间为Unix时间戳,返回的是US.userinfo中相同的类型-曾冠悦
U.MT.getUnixTime = function (str_time) {
var new_str = str_time.replace(/:/g, '-'); //替换冒号
new_str = new_str.replace(/ /g, '-'); //替换空格
var arr = new_str.split("-"); //转换成数组
arr.length = 5;
for (var i = 0; i < 6; i++) {
if (arr[i] == undefined) {
arr[i] = 0;
}
}
return "/Date(" + Date.UTC(arr[0], arr[1] - 1, arr[2], arr[3] - 8, arr[4], arr[5]) + ")/";
}
//闰年
U.MT.IsLeapYear = function (Y) {
if ((Y % 400 == 0 && Y % 100 == 0) || (Y % 4 == 0 && Y % 100 != 0)) { return true; }
else { return false; }
}
//函数作用,获取年份
//在IE中得到的日期是"2011",在Firefox中看到的日期是"111",主要是因为在 Firefox 里面 getYear 返回的是 "当前年份-1900" 的值。
U.MT.getYear = function () {
var year = new Date().getYear();
year = (year < 1900 ? (1900 + year) : year);
return year;
}
//获取当前月份
U.MT.getNowMonth = function () {
var month = new Date().getMonth() + 1;
return month;
}
//获取日期
U.MT.getNowDate = function () {
var date = new Date().getDate();
return date;
}
//获取月份的天数,2月需要年参数
U.MT.getDayOfMonth = function (month, year) {
if (month == 4 || month == 6 || month == 9 || month == 11) {
return 30;
}
if (month == 2) {
if (U.MT.IsLeapYear(year)) {
return 29;
}
else return 28;
}
return 31;
}
U.MS.PY = { 0xB0A1: "a", 0xB0A3: "ai", 0xB0B0: "an", 0xB0B9: "ang", 0xB0BC: "ao", 0xB0C5: "ba", 0xB0D7: "bai", 0xB0DF: "ban", 0xB0EE: "bang", 0xB0FA: "bao", 0xB1AD: "bei", 0xB1BC: "ben", 0xB1C0: "beng", 0xB1C6: "bi", 0xB1DE: "bian", 0xB1EA: "biao", 0xB1EE: "bie", 0xB1F2: "bin", 0xB1F8: "bing", 0xB2A3: "bo", 0xB2B8: "bu", 0xB2C1: "ca", 0xB2C2: "cai", 0xB2CD: "can", 0xB2D4: "cang", 0xB2D9: "cao", 0xB2DE: "ce", 0xB2E3: "ceng", 0xB2E5: "cha", 0xB2F0: "chai", 0xB2F3: "chan", 0xB2FD: "chang", 0xB3AC: "chao", 0xB3B5: "che", 0xB3BB: "chen", 0xB3C5: "cheng", 0xB3D4: "chi", 0xB3E4: "chong", 0xB3E9: "chou", 0xB3F5: "chu", 0xB4A7: "chuai", 0xB4A8: "chuan", 0xB4AF: "chuang", 0xB4B5: "chui", 0xB4BA: "chun", 0xB4C1: "chuo", 0xB4C3: "ci", 0xB4CF: "cong", 0xB4D5: "cou", 0xB4D6: "cu", 0xB4DA: "cuan", 0xB4DD: "cui", 0xB4E5: "cun", 0xB4E8: "cuo", 0xB4EE: "da", 0xB4F4: "dai", 0xB5A2: "dan", 0xB5B1: "dang", 0xB5B6: "dao", 0xB5C2: "de", 0xB5C5: "deng", 0xB5CC: "di", 0xB5DF: "dian", 0xB5EF: "diao", 0xB5F8: "die", 0xB6A1: "ding", 0xB6AA: "diu", 0xB6AB: "dong", 0xB6B5: "dou", 0xB6BC: "du", 0xB6CB: "duan", 0xB6D1: "dui", 0xB6D5: "dun", 0xB6DE: "duo", 0xB6EA: "e", 0xB6F7: "en", 0xB6F8: "er", 0xB7A2: "fa", 0xB7AA: "fan", 0xB7BB: "fang", 0xB7C6: "fei", 0xB7D2: "fen", 0xB7E1: "feng", 0xB7F0: "fo", 0xB7F1: "fou", 0xB7F2: "fu", 0xB8C1: "ga", 0xB8C3: "gai", 0xB8C9: "gan", 0xB8D4: "gang", 0xB8DD: "gao", 0xB8E7: "ge", 0xB8F8: "gei", 0xB8F9: "gen", 0xB8FB: "geng", 0xB9A4: "gong", 0xB9B3: "gou", 0xB9BC: "gu", 0xB9CE: "gua", 0xB9D4: "guai", 0xB9D7: "guan", 0xB9E2: "guang", 0xB9E5: "gui", 0xB9F5: "gun", 0xB9F8: "guo", 0xB9FE: "ha", 0xBAA1: "hai", 0xBAA8: "han", 0xBABB: "hang", 0xBABE: "hao", 0xBAC7: "he", 0xBAD9: "hei", 0xBADB: "hen", 0xBADF: "heng", 0xBAE4: "hong", 0xBAED: "hou", 0xBAF4: "hu", 0xBBA8: "hua", 0xBBB1: "huai", 0xBBB6: "huan", 0xBBC4: "huang", 0xBBD2: "hui", 0xBBE7: "hun", 0xBBED: "huo", 0xBBF7: "ji", 0xBCCE: "jia", 0xBCDF: "jian", 0xBDA9: "jiang", 0xBDB6: "jiao", 0xBDD2: "jie", 0xBDED: "jin", 0xBEA3: "jing", 0xBEBC: "jiong", 0xBEBE: "jiu", 0xBECF: "ju", 0xBEE8: "juan", 0xBEEF: "jue", 0xBEF9: "jun", 0xBFA6: "ka", 0xBFAA: "kai", 0xBFAF: "kan", 0xBFB5: "kang", 0xBFBC: "kao", 0xBFC0: "ke", 0xBFCF: "ken", 0xBFD3: "keng", 0xBFD5: "kong", 0xBFD9: "kou", 0xBFDD: "ku", 0xBFE4: "kua", 0xBFE9: "kuai", 0xBFED: "kuan", 0xBFEF: "kuang", 0xBFF7: "kui", 0xC0A4: "kun", 0xC0A8: "kuo", 0xC0AC: "la", 0xC0B3: "lai", 0xC0B6: "lan", 0xC0C5: "lang", 0xC0CC: "lao", 0xC0D5: "le", 0xC0D7: "lei", 0xC0E2: "leng", 0xC0E5: "li", 0xC1A9: "lia", 0xC1AA: "lian", 0xC1B8: "liang", 0xC1C3: "liao", 0xC1D0: "lie", 0xC1D5: "lin", 0xC1E1: "ling", 0xC1EF: "liu", 0xC1FA: "long", 0xC2A5: "lou", 0xC2AB: "lu", 0xC2BF: "lv", 0xC2CD: "luan", 0xC2D3: "lue", 0xC2D5: "lun", 0xC2DC: "luo", 0xC2E8: "ma", 0xC2F1: "mai", 0xC2F7: "man", 0xC3A2: "mang", 0xC3A8: "mao", 0xC3B4: "me", 0xC3B5: "mei", 0xC3C5: "men", 0xC3C8: "meng", 0xC3D0: "mi", 0xC3DE: "mian", 0xC3E7: "miao", 0xC3EF: "mie", 0xC3F1: "min", 0xC3F7: "ming", 0xC3FD: "miu", 0xC3FE: "mo", 0xC4B1: "mou", 0xC4B4: "mu", 0xC4C3: "na", 0xC4CA: "nai", 0xC4CF: "nan", 0xC4D2: "nang", 0xC4D3: "nao", 0xC4D8: "ne", 0xC4D9: "nei", 0xC4DB: "nen", 0xC4DC: "neng", 0xC4DD: "ni", 0xC4E8: "nian", 0xC4EF: "niang", 0xC4F1: "niao", 0xC4F3: "nie", 0xC4FA: "nin", 0xC4FB: "ning", 0xC5A3: "niu", 0xC5A7: "nong", 0xC5AB: "nu", 0xC5AE: "nv", 0xC5AF: "nuan", 0xC5B0: "nue", 0xC5B2: "nuo", 0xC5B6: "o", 0xC5B7: "ou", 0xC5BE: "pa", 0xC5C4: "pai", 0xC5CA: "pan", 0xC5D2: "pang", 0xC5D7: "pao", 0xC5DE: "pei", 0xC5E7: "pen", 0xC5E9: "peng", 0xC5F7: "pi", 0xC6AA: "pian", 0xC6AE: "piao", 0xC6B2: "pie", 0xC6B4: "pin", 0xC6B9: "ping", 0xC6C2: "po", 0xC6CB: "pu", 0xC6DA: "qi", 0xC6FE: "qia", 0xC7A3: "qian", 0xC7B9: "qiang", 0xC7C1: "qiao", 0xC7D0: "qie", 0xC7D5: "qin", 0xC7E0: "qing", 0xC7ED: "qiong", 0xC7EF: "qiu", 0xC7F7: "qu", 0xC8A6: "quan", 0xC8B1: "que", 0xC8B9: "qun", 0xC8BB: "ran", 0xC8BF: "rang", 0xC8C4: "rao", 0xC8C7: "re", 0xC8C9: "ren", 0xC8D3: "reng", 0xC8D5: "ri", 0xC8D6: "rong", 0xC8E0: "rou", 0xC8E3: "ru", 0xC8ED: "ruan", 0xC8EF: "rui", 0xC8F2: "run", 0xC8F4: "ruo", 0xC8F6: "sa", 0xC8F9: "sai", 0xC8FD: "san", 0xC9A3: "sang", 0xC9A6: "sao", 0xC9AA: "se", 0xC9AD: "sen", 0xC9AE: "seng", 0xC9AF: "sha", 0xC9B8: "shai", 0xC9BA: "shan", 0xC9CA: "shang", 0xC9D2: "shao", 0xC9DD: "she", 0xC9E9: "shen", 0xC9F9: "sheng", 0xCAA6: "shi", 0xCAD5: "shou", 0xCADF: "shu", 0xCBA2: "shua", 0xCBA4: "shuai", 0xCBA8: "shuan", 0xCBAA: "shuang", 0xCBAD: "shui", 0xCBB1: "shun", 0xCBB5: "shuo", 0xCBB9: "si", 0xCBC9: "song", 0xCBD1: "sou", 0xCBD4: "su", 0xCBE1: "suan", 0xCBE4: "sui", 0xCBEF: "sun", 0xCBF2: "suo", 0xCBFA: "ta", 0xCCA5: "tai", 0xCCAE: "tan", 0xCCC0: "tang", 0xCCCD: "tao", 0xCCD8: "te", 0xCCD9: "teng", 0xCCDD: "ti", 0xCCEC: "tian", 0xCCF4: "tiao", 0xCCF9: "tie", 0xCCFC: "ting", 0xCDA8: "tong", 0xCDB5: "tou", 0xCDB9: "tu", 0xCDC4: "tuan", 0xCDC6: "tui", 0xCDCC: "tun", 0xCDCF: "tuo", 0xCDDA: "wa", 0xCDE1: "wai", 0xCDE3: "wan", 0xCDF4: "wang", 0xCDFE: "wei", 0xCEC1: "wen", 0xCECB: "weng", 0xCECE: "wo", 0xCED7: "wu", 0xCEF4: "xi", 0xCFB9: "xia", 0xCFC6: "xian", 0xCFE0: "xiang", 0xCFF4: "xiao", 0xD0A8: "xie", 0xD0BD: "xin", 0xD0C7: "xing", 0xD0D6: "xiong", 0xD0DD: "xiu", 0xD0E6: "xu", 0xD0F9: "xuan", 0xD1A5: "xue", 0xD1AB: "xun", 0xD1B9: "ya", 0xD1C9: "yan", 0xD1EA: "yang", 0xD1FB: "yao", 0xD2AC: "ye", 0xD2BB: "yi", 0xD2F0: "yin", 0xD3A2: "ying", 0xD3B4: "yo", 0xD3B5: "yong", 0xD3C4: "you", 0xD3D9: "yu", 0xD4A7: "yuan", 0xD4BB: "yue", 0xD4C5: "yun", 0xD4D1: "za", 0xD4D4: "zai", 0xD4DB: "zan", 0xD4DF: "zang", 0xD4E2: "zao", 0xD4F0: "ze", 0xD4F4: "zei", 0xD4F5: "zen", 0xD4F6: "zeng", 0xD4FA: "zha", 0xD5AA: "zhai", 0xD5B0: "zhan", 0xD5C1: "zhang", 0xD5D0: "zhao", 0xD5DA: "zhe", 0xD5E4: "zhen", 0xD5F4: "zheng", 0xD6A5: "zhi", 0xD6D0: "zhong", 0xD6DB: "zhou", 0xD6E9: "zhu", 0xD7A5: "zhua", 0xD7A7: "zhuai", 0xD7A8: "zhuan", 0xD7AE: "zhuang", 0xD7B5: "zhui", 0xD7BB: "zhun", 0xD7BD: "zhuo", 0xD7C8: "zi", 0xD7D7: "zong", 0xD7DE: "zou", 0xD7E2: "zu", 0xD7EA: "zuan", 0xD7EC: "zui", 0xD7F0: "zun", 0xD7F2: "zuo" }
//获取中文拼音
U.MS.PYS = function (UST) {//U.MS.PY
var i, _UCT = UST.charCodeAt(0); //拼音编码
if (_UCT && (_UCT > 0xB0A0 && _UCT < 0xD7FC)) { for (i = _UCT; (!(_UCT = U.MS.PY[i]) && i > 0xB0A1); ) { i--; } } //如果为拼音
return _UCT;
}
U.MS.PYS("你");
Namespace.register("U.Imges"); //久的图片浏览器
USPhotoImgJson = null;
//图片预加载(摘自:http://www.planeart.cn/demo/imgReady/ )=========================================================================================================================
//使用方法ImgReady(图片URL,加载头文件成功执行函数(即获得图片长宽),加载图片成功执行函数,加载图片失败执行函数);
//imgReady('images/logo_cn.png', function () {alert('size ready: width=' + this.width + '; height=' + this.height);},function(){alert("加载成功")},function(){alert("加载失败")});
U.Imges.ImgReady = (function () {
var list = [], intervalId = null,
// 用来执行队列
tick = function () {
var i = 0;
for (; i < list.length; i++) {
list[i].end ? list.splice(i--, 1) : list[i]();
};
!list.length && stop();
},
//停止所有定时器队列
stop = function () {
clearInterval(intervalId);
intervalId = null;
};
return function (url, ready, load, error) {
var onready, width, height, newWidth, newHeight,
img = new Image();
img.src = url;
// 如果图片被缓存,则直接返回缓存数据
if (img.complete) {
ready.call(img);
load && load.call(img);
return;
};
width = img.width;
height = img.height;
// 加载错误后的事件
img.onerror = function () {
error && error.call(img);
//onready.end = true;
img = img.onload = img.onerror = null;
};
// 图片尺寸就绪
img.onreadystatechange = function () {
if (document.readyState == "complete") {
newWidth = img.width;
newHeight = img.height;
// 如果图片已经在其他地方加载可使用面积检测
if (newWidth !== width || newHeight !== height || newWidth * newHeight > 1024) {
ready.call(img);
//onready.end = true;
};
};
};
// onready = function () {
// newWidth = img.width;
// newHeight = img.height;
// // 如果图片已经在其他地方加载可使用面积检测
// if (newWidth !== width || newHeight !== height || newWidth * newHeight > 1024) {
// ready.call(img);
// onready.end = true;
// };
// };
// onready();
// 完全加载完毕的事件
img.onload = function () {
// onload在定时器时间差范围内可能比onready快
// 这里进行检查并保证onready优先执行
//!onready.end && onready();
load && load.call(img);
// IE gif动画会循环执行onload,置空onload即可
img = img.onload = img.onerror = null;
};
// 加入队列中定期执行
// if (!onready.end) {
// list.push(onready);
// // 无论何时只允许出现一个定时器,减少浏览器性能损耗
// if (intervalId === null) intervalId = setInterval(tick, 40);
// };
};
})();
//图片预加载(摘自:http://www.planeart.cn/demo/imgReady/ )=========================================================================================================================
//图片居中旋转(编写:郭仁)========================================================================================================================================================
//传入图片对象,与旋转方向(值:'left' or 'right')
//使用方法imgRoll(document.getElementById("ImgObj"),"left");
U.Imges.imgRoll = function (imgObj, SX, ArcSizeInt) {
var ArcSize = imgObj.alt == null ? 0 : parseInt(imgObj.alt); //通过图片对象中的alt属性进行储存现行角度(1=90度;2=180度;3=270度;4=360度=0度)
//判断SX进行角度增减
if (SX == "left") {
ArcSize += 1;
ArcSize = ArcSize > 4 ? 0 : ArcSize;
} else if (SX == "right") {
ArcSize -= 1;
ArcSize = ArcSize < 0 ? 3 : ArcSize;
} else if (SX == "int") {
ArcSize = ArcSizeInt;
}
//因为CSS旋转滤镜的实现方式不同~~需要进行不同的浏览判断给予定位
imgObj.parentNode.style.width = ArcSize % 2 == 0 ? imgObj.width + (2 * 7) + "px" : imgObj.height + (2 * 7) + "px";
imgObj.parentNode.style.height = ArcSize % 2 == 0 ? imgObj.height + (2 * 7) + "px" : imgObj.width + (2 * 7) + "px";
if (!browser.msie) {
if (ArcSize % 2 != 0) {
imgObj.style.left = Math.ceil((parseInt(imgObj.parentNode.style.width) - parseInt(imgObj.parentNode.style.height)) / 2) + "px";
imgObj.style.top = Math.ceil((parseInt(imgObj.parentNode.style.height) - parseInt(imgObj.parentNode.style.width)) / 2) + "px";
imgObj.parentNode.style.left = parseInt(imgObj.parentNode.style.left) - parseInt(imgObj.style.left) + "px";
imgObj.parentNode.style.top = parseInt(imgObj.parentNode.style.top) - parseInt(imgObj.style.top) + "px";
} else {
imgObj.parentNode.style.left = parseInt(imgObj.parentNode.style.left) + parseInt(imgObj.style.left) + "px";
imgObj.parentNode.style.top = parseInt(imgObj.parentNode.style.top) + parseInt(imgObj.style.top) + "px";
imgObj.style.left = "0px";
imgObj.style.top = "0px";
}
}
// else {
// imgObj.parentNode.style.left = parseInt(imgObj.parentNode.getBoundingClientRect().left) - Math.ceil((parseInt(imgObj.parentNode.style.width) - parseInt(imgObj.parentNode.style.height)) / 2) + "px";
// imgObj.parentNode.style.top = parseInt(imgObj.parentNode.getBoundingClientRect().top) - Math.ceil((parseInt(imgObj.parentNode.style.height) - parseInt(imgObj.parentNode.style.width)) / 2) + "px";
// }
imgObj.alt = ArcSize; //将角度值置于图片对象alt属性中
//css旋转滤镜兼容
imgObj.style.filter = 'Progid:DXImageTransform.Microsoft.BasicImage(Rotation=' + ArcSize + ')';
imgObj.style.WebkitTransform = 'rotate(' + ArcSize * 90 + 'deg)';
imgObj.style.MozTransform = 'rotate(' + ArcSize * 90 + 'deg)';
imgObj.style.OTransform = 'rotate(' + ArcSize * 90 + 'deg)';
}
//图片居中旋转(编写:郭仁)========================================================================================================================================================
//放大缩小【不影响于旋转后放大缩小的BUG~~】(编写:郭仁)============================================================================================================================
//传入(图片对象,原始宽,原始高)~~
U.Imges.Scale = function (ImgObj, nwidth, nheight) {
var event = arguments.callee.caller.arguments[0] || window.event; //消除浏览器差异
//滑动条位置
var x = event.clientX - 80;
var y = event.clientY - 20;
//缩放比例~~
var Scale = nwidth / nheight;
//现行角度
var ArcSize = ImgObj.alt == null ? 0 : parseInt(ImgObj.alt);
if (document.getElementById("SlideCase_" + ImgObj.id) == null) {//判断滑动条是否已存在
//创建滑动条
var SlideCase = new U.Imges.SliderContorl(ImgObj.id, 200, 50, x, y, function (percentage) {
ImgObj.style.width = nwidth * (percentage / 100) + "px";
ImgObj.style.height = parseInt(ImgObj.style.width) / Scale + "px";
if (ArcSize % 2 != 0) {
ImgObj.parentNode.style.width = parseInt(ImgObj.style.height) + (2 * 7) + "px";
ImgObj.parentNode.style.height = parseInt(ImgObj.style.width) + (2 * 7) + "px";
if (browser.chrome || browser.firefox) {
ImgObj.style.left = Math.ceil((parseInt(ImgObj.parentNode.style.width) - parseInt(ImgObj.parentNode.style.height)) / 2) + "px";
ImgObj.style.top = Math.ceil((parseInt(ImgObj.parentNode.style.height) - parseInt(ImgObj.parentNode.style.width)) / 2) + "px";
}
} else {
ImgObj.parentNode.style.width = parseInt(ImgObj.style.width) + (2 * 7) + "px";
ImgObj.parentNode.style.height = parseInt(ImgObj.style.height) + (2 * 7) + "px";
}
});
document.body.appendChild(SlideCase);
}
}
//放大缩小【不影响于旋转后放大缩小的BUG~~】(编写:郭仁)============================================================================================================================
//stackBlurImage(ImgStr, CanvasStr, percentage, false);
//滑动条创建(编写:郭仁)==========================================================================================================================================================
//通过传入[ID(为了避免多次创建同样功能滑动条);最大值;最小值;x;y;滑动块left改变后执行函数]
//使用方法
// if(document.getElementById("SlideCase_20")==null){
// var DemoSlider = SliderContorl("20",200, 50, x, y, function (percentage) {
// alert(percentage);
// });
// document.body.appendChild(DemoSlider);
// }
U.Imges.SliderContorl = function (id, max, min, left, top, callback) {
var fadeOut = null; //淡出计时器Interval
var removealertBar = null; //移除提示框计时器Timeout
var percentage = 0; //滑动所在百分比
//动态创建滑动框=====================================================================
var SlideCase = document.createElement("div");
SlideCase.id = "SlideCase_" + id; //每个滑动条都有自己的ID
SlideCase.className = "ImgViewer SlideCase";
SlideCase.style.left = left + "px";
SlideCase.style.top = top + "px";
//禁止选取
SlideCase.onmousedown = function () { return false; } //IE;
SlideCase.onselectstart = function () { return false; } //FireFox;Chorme
//滑动条--------------------------------------------------
var SlideBar = document.createElement("div");
SlideBar.id = "SlideBar"
SlideBar.className = "SlideBar";
//滑动块--------------------------------------------------
var SlidhingShoe = document.createElement("a");
SlidhingShoe.id = "SlidhingShoe";
SlidhingShoe.className = "ImgViewer SlidhingShoe";
//移除按钮------------------------------------------------
var CloseSlideButton = document.createElement("div");
CloseSlideButton.id = "Slidhing_CloseSlideButton"
CloseSlideButton.className = "Slidhing_CloseSlideButton";
CloseSlideButton.onclick = function () { SlideCase.parentNode.removeChild(SlideCase); }
//提示框--------------------------------------------------
var alertBar = document.createElement("div");
alertBar.id = "Slidhing_alertBar";
alertBar.style.display = "none";
alertBar.className = "ImgViewer Slidhing_alertBar";
//添加到各各节点-------------------------------------------
SlideBar.appendChild(SlidhingShoe);
SlideCase.appendChild(SlideBar);
SlideCase.appendChild(CloseSlideButton);
SlideCase.appendChild(alertBar);
//两个主要事件=====================================================================
//提示框淡出消失函数
var AlertFadeIn = function () {
//提示框样式重置
alertBar.style.filter = "alpha(opacity=100)";
alertBar.style.MozOpacity = "1";
alertBar.style.opacity = "1";
alertBar.style.display = "inline-block";
//再次清扫计时器防止内存溢出
clearInterval(fadeOut);
clearTimeout(removealertBar);
//特效开始
removealertBar = setTimeout(function () {
i = 100;
fadeOut = setInterval(function () {
alertBar.style.filter = "alpha(opacity=" + i + ")";
alertBar.style.MozOpacity = i * 0.01;
alertBar.style.opacity = i * 0.01;
i -= 2;
if (i == 0) {
alertBar.style.display = "none";
//清扫计时器防止内存溢出
clearInterval(fadeOut);
clearTimeout(removealertBar);
}
}, 1);
}, 800);
}
//滑动块移动或滑动条被点击后执行函数
var mouse_down_or_move = function () {
var pole = event.clientX - parseInt(SlideCase.style.left) - 25; //计算滑动块left
//限制最小left与最大left
pole = pole < 0 ? 0 : pole;
pole = pole > 120 ? 120 : pole;
SlidhingShoe.style.left = pole + "px";
//给提示框赋予left值;使提示框跟着滑动块移动
alertBar.style.left = pole - 20 + "px";
percentage = pole * ((max - min) / 120) + min; //计算滑动条现行百分比
alertBar.innerHTML = Math.round(percentage) + "%";
callback(percentage); //回调传入函数
}
//给滑动条与滑动块进行事件处理==========================================
SlideBar.onmousedown = function () {
mouse_down_or_move();
alertBar.style.display = "inline-block";
}
SlideBar.onmouseup = function () {
if (!browser.msie) {
AlertFadeIn();
} else {
clearTimeout(removealertBar);
removealertBar = setTimeout(function () {
alertBar.style.display = "none";
clearTimeout(removealertBar);
}, 800);
}
}
SlidhingShoe.onmousedown = function () {
var ismoveSlide = true;
document.body.onmousemove = function () {
if (ismoveSlide == true) {
mouse_down_or_move();
alertBar.style.display = "inline-block";
if (!browser.msie) {
alertBar.style.filter = "alpha(opacity=" + i + ")";
alertBar.style.MozOpacity = i * 0.01;
alertBar.style.opacity = i * 0.01;
}
}
}
document.body.onmouseup = function () {
if (document.all != undefined) SlidhingShoe.releaseCapture(); //鼠标事件制焦
ismoveSlide = false;
if (!browser.msie) {
AlertFadeIn();
} else {
clearTimeout(removealertBar);
removealertBar = setTimeout(function () {
alertBar.style.display = "none";
clearTimeout(removealertBar);
}, 800);
}
document.body.onmouseup = function () { return false; }
}
}
return SlideCase; //返回滑动条
}
//滑动条创建(编写:郭仁)==========================================================================================================================================================
//恢复1:1实际比例===================================================================================================================================================================
//传入图片对象,原宽,原高
U.Imges.ActuleScale = function (ImgObj, width, height) {
ImgObj.style.width = width + "px";
ImgObj.style.height = height + "px";
ImgObj.parentNode.style.width = parseInt(ImgObj.style.width) + (2 * 7) + "px";
ImgObj.parentNode.style.height = parseInt(ImgObj.style.height) + (2 * 7) + "px";
}
//创建图片框========================================================================================================================================================================
//传入图片ID(防止同时出现多个同ID导致网页出错),图片地址,JSON【KEY】(你懂的~~可为空~~)
U.Imges.CreatePhotoCase = function (imgid, url, key) {
var nwidth = 0; //原宽
var nheight = 0; //原高
// if (window.top.document.getElementById("ImgViewer_Div" + imgid) != null) {//如果已创建此相框则返回此相框
// return window.top.document.getElementById("ImgViewer_Div" + imgid);
// }
//var IV_Div = window.top.document.getElementById("ImgViewer_Div");
var IV_Div = window.top.$('#ImgViewer_Div')[0];
if (IV_Div != null) {//如果已创建过相框则只在更改图片及管理框 ——简炜杰
var img = $("Img", IV_Div)[0];
//更换图片ID
img.id = "ImgViewer_Img" + imgid;
//图片大小处理以及重新加载管理框
var _ready = function () {
return function () {
var nImg = new Image();
nImg.src = url;
var nwidth = nImg.width;
var nheight = nImg.height;
if (nImg.width > 800 || nImg.height > 600) {
if (nImg.width > nImg.height) {
nwidth = 800;
nheight = nwidth / (nImg.width / nImg.height);
} else {
nheight = 600;
nwidth = nheight * (nImg.width / nImg.height);
}
} else if (nImg.height < 200) {
nheight = 200;
nwidth = nheight * (nImg.width / nImg.height);
} else {
nwidth = nImg.width;
nheight = nImg.height;
}
img.style.height = nheight + "px";
img.style.width = nwidth + "px";
IV_Div.style.height = nheight + 14 + "px";
IV_Div.style.width = nwidth + 14 + "px";
var strCode = '';
strCode += '';
strCode += '';
strCode += '';
strCode += '';
strCode += '';
$('#ImgViewer_manager')[0].innerHTML = strCode;
U.Imges.ActuleScale(img, nwidth, nheight);
}
}
_ready = _ready();
//加载图片
U.Imges.ImgReady(url, _ready, function () { img.src = url; }, function () { alert("加载失败"); ImgDiv.parentNode.removeChild(ImgDiv); });
return;
}
//创建相框==============================================================
var ImgDiv = document.createElement("div");
//ImgDiv.id = "ImgViewer_Div" + imgid;
//相框只生成一次,ID改为唯一 ——简炜杰
ImgDiv.id = "ImgViewer_Div";
ImgDiv.className = "ImgViewer_Div ImgViewer_shadow";
//禁止选取
ImgDiv.onmousedown = function () { return false; } //IE;
ImgDiv.onselectstart = function () { return false; } //FireFox;Chorme
//创建管理框============================================================
var managerBar = document.createElement("div");
managerBar.id = "ImgViewer_managerBar";
managerBar.className = "ImgViewer ImgViewer_managerBar";
//创建管理对齐DIV=======================================================
var manager = document.createElement("div");
manager.id = "ImgViewer_manager";
manager.className = "ImgViewer_manager";
//创建图片元素==========================================================
var USPhotoImg = document.createElement("img");
USPhotoImg.id = "ImgViewer_Img" + imgid;
USPhotoImg.className = "ImgViewer_Img";
USPhotoImg.alt = "0";
USPhotoImg.src = "img/loading.png";
USPhotoImg.onmousedown = function () { U.D.DragMouseDown(ImgDiv, "ImgViewer"); }
if (key != null && key != "") {//如果KEY值为空则不显示上一张与下一张
//创建对齐框==========================================================
var gobackdiv = document.createElement("div");
gobackdiv.id = "ImgViewer_gobackdiv";
gobackdiv.className = "ImgViewer_gobackdiv";
//创建上一张按钮======================================================
var go = document.createElement("i");
go.id = "ImgViewer_go";
go.className = "ImgViewer ImgViewer_go";
go.onclick = function () {
goorback("g");
}
go.onmouseover = function () {
gobackdiv.style.display = "inline-block";
}
go.onmouseout = function () {
gobackdiv.style.display = "none";
}
//创建下一张按钮======================================================
var back = document.createElement("i");
back.id = "ImgViewer_back";
back.className = "ImgViewer ImgViewer_back";
back.onclick = function () {
goorback("b");
}
back.onmouseover = function () {
gobackdiv.style.display = "inline-block";
}
back.onmouseout = function () {
gobackdiv.style.display = "none";
}
USPhotoImg.onmouseover = function () {
gobackdiv.style.display = "inline-block";
}
USPhotoImg.onmouseout = function () {
gobackdiv.style.display = "none";
}
gobackdiv.appendChild(go);
gobackdiv.appendChild(back);
ImgDiv.appendChild(gobackdiv);
var goorback = function (gb) {
//如果滑动条存在为以防出错而将原图滑动条隐藏
if (document.getElementById("SlideCase_" + USPhotoImg.id) != null) document.getElementById("SlideCase_" + USPhotoImg.id).parentNode.removeChild(document.getElementById("SlideCase_" + USPhotoImg.id));
U.Imges.imgRoll(USPhotoImg, "int", 0); //恢复旋转角度
if (gb == "g") {
key--;
} else if (gb == "b") {
key++;
}
key = key < 0 ? USPhotoImgJson.length - 1 : key;
key = key > USPhotoImgJson.length - 1 ? 0 : key;
var Img = USPhotoImgJson[key]; //选择JSON
//更换ID
//相框只生成一次,ID改为唯一,无需更换 ——简炜杰
//ImgDiv.id = "ImgViewer_Div" + Img.imgid;
USPhotoImg.id = "ImgViewer_Img" + Img.imgid;
//执行图片预加载~~
var _e = function () {
return function () {
var nwidth = this.width;
var nheight = this.height;
if (this.width > 800 || this.height > 600) {
if (this.width > this.height) {
nwidth = 800;
nheight = nwidth / (this.width / this.height);
} else {
nheight = 600;
nwidth = nheight * (this.width / this.height);
}
} else if (this.height < 200) {
nheight = 200;
nwidth = nheight * (this.width / this.height);
} else {
nwidth = this.width;
nheight = this.height;
}
ImageReady(Img.imgid, nwidth, nheight);
gobackdiv.style.bottom = (nheight + (2 * 7)) / 2 - 15 + "px";
}
}
_e = _e();
U.Imges.ImgReady(Img.imgurl, _e, function () { USPhotoImg.src = this.src; }, function () { alert("加载失败"); ImgDiv.parentNode.removeChild(ImgDiv); });
}
}
managerBar.appendChild(manager);
ImgDiv.appendChild(USPhotoImg);
ImgDiv.appendChild(managerBar);
//图片加载成功后执行事件
var ImageReady = function (Imgid, width, height) {
var strCode = '';
strCode += '';
strCode += '';
strCode += '';
strCode += '';
strCode += '';
manager.innerHTML = strCode;
U.Imges.ActuleScale(USPhotoImg, width, height);
}
var _e = function () {
return function () {
var nwidth = this.width;
var nheight = this.height;
if (this.width > 800 || this.height > 600) {
if (this.width > this.height) {
nwidth = 800;
nheight = nwidth / (this.width / this.height);
} else {
nheight = 600;
nwidth = nheight * (this.width / this.height);
}
} else if (this.height < 200) {
nheight = 200;
nwidth = nheight * (this.width / this.height);
} else {
nwidth = this.width;
nheight = this.height;
}
ImageReady(imgid, nwidth, nheight);
if (key != null & key != "") gobackdiv.style.bottom = (nheight + (2 * 7)) / 2 - 15 + "px";
}
}
_e = _e();
U.Imges.ImgReady(url, _e, function () { USPhotoImg.src = this.src; }, function () { alert("加载失败"); ImgDiv.parentNode.removeChild(ImgDiv); });
document.body.appendChild(ImgDiv);
}
U.Imges.ThumbnailsCase = function (ImgJson) {
var fadeOut = null; //淡出计时器Interval
var removealertBar = null; //移除提示框计时器Timeout
var ThumbnailsArray = document.getElementById("ImgViewer_ThumbnailsArray");
var ThumbnailsSlideShoe = document.getElementById("ImgViewer_ThumbnailsSlideShoe");
var ThumbnailsSlideBar = document.getElementById("ImgViewer_ThumbnailsSlideBar");
var ThumbnailsAlertBar = document.getElementById("ImgViewer_ThumbnailsAlertBar");
var strCode = "";
var Json = eval('(' + ImgJson + ')');
USPhotoImgJson = Json;
for (var i in Json) {
var Img = Json[i]
strCode += '';
}
ThumbnailsArray.innerHTML = strCode;
ThumbnailsArray.style.width = (Json.length / 2) * 68 + "px";
ThumbnailsArray.parentNode.parentNode.style.display = "inline-block";
var mousemoveOrdown = function () {
pole = event.clientX - parseInt(ThumbnailsSlideShoe.parentNode.parentNode.getBoundingClientRect().left) - 35;
pole = pole < 0 ? 0 : pole;
pole = pole > 235 ? 235 : pole;
ThumbnailsSlideShoe.style.left = pole + "px";
ThumbnailsAlertBar.style.left = pole - 10 + "px";
var ThumbnailsArrayleft = Math.ceil(pole) * ((parseInt(ThumbnailsArray.style.width) - 278) / 235);
if (ThumbnailsArrayleft > 0) {
ThumbnailsAlertBar.innerHTML = Math.round(ThumbnailsArrayleft) + 35 + "%";
ThumbnailsArray.style.marginLeft = "-" + ThumbnailsArrayleft + "px";
} else {
ThumbnailsAlertBar.innerHTML = "小于范围值~~";
ThumbnailsArray.style.marginLeft = "0px";
}
}
var AlertFadeIn = function () {
//提示框样式重置
ThumbnailsAlertBar.style.filter = "alpha(opacity=100)";
ThumbnailsAlertBar.style.MozOpacity = "1";
ThumbnailsAlertBar.style.opacity = "1";
ThumbnailsAlertBar.style.display = "inline-block";
//再次清扫计时器防止内存溢出
clearInterval(fadeOut);
clearTimeout(removealertBar);
//特效开始
removealertBar = setTimeout(function () {
i = 100;
fadeOut = setInterval(function () {
ThumbnailsAlertBar.style.filter = "alpha(opacity=" + i + ")";
ThumbnailsAlertBar.style.MozOpacity = i * 0.01;
ThumbnailsAlertBar.style.opacity = i * 0.01;
i -= 2;
if (i == 0) {
ThumbnailsAlertBar.style.display = "none";
//清扫计时器防止内存溢出
clearInterval(fadeOut);
clearTimeout(removealertBar);
}
}, 1);
}, 800);
}
//事件控制
ThumbnailsSlideBar.onmousedown = function () {
mousemoveOrdown();
ThumbnailsAlertBar.style.display = "inline-block";
}
ThumbnailsSlideBar.onmouseup = function () {
if (!browser.msie) {
AlertFadeIn();
} else {
clearTimeout(removealertBar);
removealertBar = setTimeout(function () {
ThumbnailsAlertBar.style.display = "none";
clearTimeout(removealertBar);
}, 800);
}
}
ThumbnailsSlideShoe.onmousedown = function () {
var ismoveSlide = true;
document.body.onmousemove = function () {
if (ismoveSlide == true) {
mousemoveOrdown();
ThumbnailsAlertBar.style.display = "inline-block";
if (!browser.msie) {
ThumbnailsAlertBar.style.filter = "alpha(opacity=" + i + ")";
ThumbnailsAlertBar.style.MozOpacity = i * 0.01;
ThumbnailsAlertBar.style.opacity = i * 0.01;
}
}
}
document.body.onmouseup = function () {
if (document.all != undefined) ThumbnailsSlideShoe.releaseCapture();
ismoveSlide = false;
if (!browser.msie) {
AlertFadeIn();
} else {
clearTimeout(removealertBar);
removealertBar = setTimeout(function () {
ThumbnailsAlertBar.style.display = "none";
clearTimeout(removealertBar);
}, 800);
}
document.body.onmouseup = function () { return false; }
}
}
}
//设置换行
U.M.SEKP = function (IF, CB, TF) {
IF.onkeypress = function () { if (event.keyCode == 10 || event.keyCode == 13) { if (TF) { U.M.StopDefault(); } if (CB) { CB(); } } }
}
//由于需要大Div,小Div的loading,而现有的Loading函数有些复杂。需要逻辑再清晰,所以先独立,最后合并到一个loading中。
//加载Gif动画效果,小加载,区别于博客,论坛的大加载。
//此处需要异步装载,先装载文章(需要有加载动画),文章加载完毕再异步加载评论(需要有加载动画),否则会很慢。
//参数load为true,则为显示图片,参数load为false,则为卸载。因为每个项目都要用所以放在了主项目中。
U.MD.SMGif = function (_div, _load) {
if (_load == false) _div.removeChild(U.M.GetCById(_div, "U_SMLD"));
else $$("img", { "id": "U_SMLD", "className": "U_SMLDGif", "src": "/img/us_smlding.gif" }, _div); //追加loading
}
//设置text自适应
U.M.TeSize = function (UDOD, UMH) {
var i; //循环初始化
var _UDE = ["propertychange", "input", "focus"]; //定义需要用到的字符串
var _ = function () {
var _USH = UDOD.scrollHeight, _UDTD = $(UDOD);
if (_USH != UDOD.clientHeight && _USH != UDOD.currHeight) {
if (!UMH || _USH < UMH) { _UDTD.addAttrArray({ currHeight: _USH, style: { overflowY: "hidden", height: _USH + "px"} }); } //最小大小
else { _UDTD.addAttrArray({ style: { overflowY: "auto"} }); } //最大大小
}
}
for (i = 0; i < _UDE.length; i++) { U.M.AddEvent(_UDE[i], UDOD, _); }
}
//设置禁止刷新------------------没有任何地方用到
U.M.stopRefresh = function () {
U.M.keyfun = U.M.keyfun || function () { if (event.keyCode == 116) { event.keyCode = 0; U.M.StopBubble(); U.M.StopDefault(); return false; } }
var _UDE = { keydown: U.M.keyfun, keyup: U.M.keyfun }; $(document).unbind(_UDE).bind(_UDE);
}
//异步处理函数
U.M.AsynApply = function (UTE, UDE) {
var _ = U.M.apply(UTE, UDE); return function () { setTimeout(_, 0); } //异步加载处理
}
//js forEach循环
U.M.forEach = function (UDE, UFN, UC) {
for (var i in UDE) {
if (UDE.hasOwnProperty(i) && UFN.call(UC, UDE[i], i, UDE) === false) { break; }
}
}
//等比例缩放
U.M.ImageZoom = function (UI, UZ) {
var _TF, _UH, _UW; UI = UI || this;
if (UI.height != 0 && UI.width != 0) {
if (UZ["height"]) { if (UZ["height"] < UI.height) { _TF = UZ["height"] / UI.height; _UH = UZ["height"]; } else { _TF = 1; _UH = UI.height; }; _UW = UI.width * _TF; }
else if (UZ["width"]) { if (UZ["width"] < UI.width) { _TF = UZ["width"] / UI.width; _UW = UZ["width"]; } else { _TF = 1; _UW = UI.width; }; _UH = UI.height * _TF; }
$(UI).addAttrArray({ "style": { "width": _UW + "px", "height": _UH + "px"} });
}
}
//窗体是否可见
U.M.visi = function (UOE, UTE) {
var _, cb, i, j, _UTP, _UTF, _UCE = ["", "webkit", "moz", "ms", "o"], _UME = ["hidden", "visibilityState", "visibilitychange"];
for (i = 0; i < _UCE.length; i++) { for (j = 0; j < _UME.length; j++) { if ((_UTP = _UCE[i] + (_UCE[i] ? _UME[j].substr(0, 1).toUpperCase() + _UME[j].substr(1) : _UME[j])) in document) { _UME[j] = _UTP; _UTF = true; } } if (_UTF) { break; } }
if (_UTF) { U.M.AddEvent(_UME[2], U.M.apply(null, [[U.M.visi.cb, [UOE, UTE, _UME[1]]]])); }
else { U.M.IsActivity(UOE, UTE); }
}
U.M.visi.cb = function (UOE, UTE, UTP) {
(document[UTP] ? UOE : UTE)();
}
//是否启用cookie
U.M.Cookies.is = function () { return navigator.cookieEnabled; }
//新窗口写入数据
U.M.WOP = function (UHT) {
var _UDD, _UDW = window.open("javascript:void((function(){document.open();document.domain='" + document.domain + "';document.close()})())"); //"about:blank"
(UHT) && (_UDD = _UDW.document.open(), _UDD.write(UHT), _UDD.close());
return _UDW;
}
//异步添加元素
U.M.asyncInnerHTML = function (UH, UCB) {
var _UOD = $$("div", { "innerHTML": UH }), UOF = $$("frag");
if (_UOD.firstChild) { UOF.appendChild(_UOD.firstChild); setTimeout(arguments.callee, 0); } //然后一点点挪到文档碎片 //然后把插入内容的操作作为异步调用放到一个独立的堆栈中
else { UCB[UOF]; } //这里才是真正执行插入节点的操作
// (function () { })();
}
//设置浏览器首页 必须有按钮触发
U.M.setHome = function (UDOD, URL) {
UDOD = UDOD || event.srcElement;
try { UDOD.style.behavior = "url(#default#homepage)"; UDOD.setHomePage(URL); return true; }
catch (e) {
if (window.netscape) {
try {
if (netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect")) { //判断是否开启设置首页功能
Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch).setCharPref('browser.startup.homepage', URL); return true;
}
}
catch (e) { }
}
}
return false;
}
//加入收藏夹
U.M.Collec = function (UTI, URL) {
try { window.external.addFavorite(URL, UTI); return true; }
catch (e) { try { window.sidebar.addpanel(UTI, URL, ""); return true; } catch (e) { } }
return false;
}
//获取js路径
U.M.GetJsUrl = function (UDID) {
var i, _UIE, _UPE, _USE, _UDE = document.scripts;
if ((_UPE = document.currentScript)) { _UPE = _UPE.src; } else { try { throw Error(); } catch (e) { _UPE = e.stack || e.sourceURL || e.stacktrace; } } //获取链接
if (!_UPE) { for (i = _UDE.length; i > -1; i--) { _USE = _UDE[i].src.split("/"); _UPE = _USE[_USE.length - 1]; if ((_UDE[i].src == UDID) || (_UPE.indexOf(UDID) == 0 && ((_UPE = _UPE.substr(0, UDID.length).chatAt(0)) == "") || _UPE == "?")) { return [_USE.slice(-1), _USE[_USE.length - 1]]; } } } //非兼容全屏搜索
_UPE = [_UPE, _UPE.split("/")]; _UPE[1] = _UPE[1][_UPE[1].length - 1]; return _UPE;
}
//U.OU.TF = { "TF": "Excel" }
//U.OU.DivisionExcelWord = function (Judge) { U.OU.JudgeEW = Judge; } //判断是Excel还是Wrod
////----------------------------------------------菜单功能----------------------------------------------------------//
////文件下拉菜单功能
//U.OU.OpenFileMenu = function () {
// U.M.StopBubble(); //阻止冒泡
// var FileMenu = document.getElementById("U_E_OC");
// FileMenu.style.display = FileMenu.style.display == "none" ? "block" : "none";
//}
////切换菜单选项
//U.OU.SwitchOption = function (Option, Judge) {
// var OptionList = document.getElementById("U_E_MenuBar").getElementsByTagName("li");
// for (var i = 1; i < OptionList.length; i++) { OptionList[i].className = ""; }
// Option.className = "U_E_MenuButton";
// document.getElementById(Judge).style.display = "block";
// document.getElementById(Judge == "U_E_Tool" ? "U_OU_Nav" : "U_E_Tool").style.display = "none";
//}
////-----------------------------------------------工具-----------------------------------------------------------//
////显示或隐藏颜色框
//U.OU.DisplayColorFrame = function (FrameID) {
// var ColorFrame = document.getElementById(FrameID);
// ColorFrame.style.display = ColorFrame.style.display == "none" ? "block" : "none";
// var OtherID = FrameID == "U_E_TColorFrame" ? "U_E_BColorFrame" : "U_E_TColorFrame"; //隐藏另一个颜色框
// document.getElementById(OtherID).style.display = "none";
//}
////点击颜色Li
//U.OU.ColorLiOnClick = function (Li) {
// var Color = Li.style.backgroundColor; var Father = Li.parentNode;
// var BorderID = Father.id == "U_E_BColorFrame" ? "U_E_BColorBorder" : "U_E_TColorBorder";
// var StyleName = Father.id == "U_E_BColorFrame" ? "BackColor" : "ForeColor";
// document.getElementById(BorderID).style.backgroundColor = Color;
// U.OU.ChangeStyle(StyleName, Color);
// Father.style.display = "none"; //隐藏颜色框
//}
////-----------------------------------------------插入-----------------------------------------------------------//
//U.OU.InsertNowTime = function () {
// var NowTime = US.Admin.TimeNow["年", "月", "日"];
// if (U.OU.JudgeEW == "Word" || U.Excel.KeepEditblur()) { U.D.E.GetSelectionRange(window, $$("span")).Replace(NowTime); }
// else {
// var Compare = U.Excel.ComparePickOn(); var Small = Compare[0]; var Big = Compare[1];
// for (var i = Small[0]; i <= Big[0]; i++) {
// for (var j = Small[1]; j <= Big[1]; j++) { U.Excel.Cell[i][j].innerHTML = NowTime; }
// }
// }
//}
////-----------------------------------------------文本编辑器-----------------------------------------------------------//
//U.OU.ChangeStyle = function (SN, V, TF) {
// if (U.OU.TF["TF"] == "Excel") {
// var _UDFD = $("#U_E_EditFrame")[0], _UDED = $("div", _UDFD)[0];
// if (_UDFD.ondblclick == null) { U.D.E.FontSizeType(_UDED, SN, [V, V]); } //修改文字样式
// else {
// U.D.E.GetSelectionRange(window, U.Excel.SY["SEO"][0]).SetYPS(SN, V);
// U.Excel.SY["CE"]["Cell"][U.Excel.SY["SEO"][1]].style[SN] = V;
// }
// }
//}
//////改变单元格或选中文本的样式(Style)
////U.OU.ChangeStyle = function (StyleName, Param) {
//// var EJudge = U.OU.JudgeEW == "Word" || (U.Excel.KeepEditblur() && StyleName != "BackColor" && StyleName != "JustifyLeft" && StyleName != "JustifyCenter" && StyleName != "JustifyRight");
//// if (EJudge) {//判断是否处于编辑状态中,或者是否是Word
//// if (Param == null) { document.execCommand(StyleName) }
//// else { document.execCommand(StyleName, false, Param); }
//// }
//// else {
//// // var StyleList = { "Bold": "fontWeight", "Italic": "fontStyle", "Underline": "textDecoration", "StrikeThrough": "textDecoration", "": "backgroundColor", "": "", "": "", "": "", "": "", "": "", "": "", "": "", "": "", "": "" };
//// switch (StyleName) {
//// case "Bold": StyleName = "fontWeight"; Param = ['bold', 'normal']; break;
//// case "Italic": StyleName = "fontStyle"; Param = ['italic', 'normal']; break;
//// case "Underline": StyleName = "textDecoration"; Param = ['underline', 'none']; break;
//// case "StrikeThrough": StyleName = "textDecoration"; Param = ['line-through', 'none']; break;
//// case "BackColor": StyleName = "backgroundColor"; break;
//// case "ForeColor": StyleName = "color"; break;
//// case "JustifyLeft": StyleName = "textAlign"; Param = "left"; break;
//// case "JustifyCenter": StyleName = "textAlign"; Param = "center"; break;
//// case "JustifyRight": StyleName = "textAlign"; Param = "right"; break;
//// case "FontSize": StyleName = "fontSize"; Param = Param + "px"; break;
//// case "FontName": StyleName = "fontFamily"; break;
//// }
//// var TempParam = Param.concat();
//// var Compare = U.Excel.ComparePickOn(); var Small = Compare[0]; var Big = Compare[1]; var Cell;
//// for (var i = Small[0]; i <= Big[0]; i++) {
//// for (var j = Small[1]; j <= Big[1]; j++) {
//// Cell = U.Excel.Cell[i][j];
//// if (StyleName == "textDecoration") {//让删除线和下划线共存
//// var Decoration = Param[0] == "underline" ? "line-through" : "underline";
//// if (Cell.style[StyleName].indexOf(Decoration) > -1) { Param[0] = "underline line-through"; Param[1] = Decoration; }
//// }
//// if ((typeof (Param) == "string")) { Cell.style[StyleName] = Param; }
//// else { Cell.style[StyleName] = Cell.style[StyleName] == Param[0] ? Param[1] : Param[0]; }
//// if (StyleName == "textDecoration") { Param = TempParam.concat(); }
//// }
//// }
//// }
//// if (U.OU.JudgeEW == "Excel") { U.Excel.EditTextEdit("Cell"); }
////}
////获取选中文本在整篇文章内的位置
//U.OU.SelectedLocation = function () {
// //Chorme
// // var range = window.getSelection().getRangeAt(0);
// // var startRangeOffset = range.startOffset;
// // range.collapse(true);
// // range.setStart(range.startContainer, startRangeOffset - 1);
// // range.setEnd(range.startContainer, startRangeOffset - 1 + plenght);
// //IE
// // var EditFrame = document.getElementById("U_E_EditFrame");
// // var EditContent = EditFrame.getElementsByTagName("div")[0];
// var EditContent = document.getElementById("U_W_WordEdit");
// var range = document.selection.createRange();
// var stored_range = range.duplicate();
// stored_range.moveToElementText(EditContent);
// stored_range.setEndPoint('EndToEnd', range);
// EditContent.selectionStart = stored_range.text.length - range.text.length;
// EditContent.selectionEnd = EditContent.selectionStart + range.text.length;
// //U.Excel.setSelectText(EditContent, EditContent.selectionStart, EditContent.selectionEnd);
//}
////将InnerHTML拆分成数组
//U.OU.SpiltInnerHTML = function (InnerHTML) {
// var InnerFrame = $$("span", { "innerHTML": InnerHTML });
// InnerHTML = InnerFrame.innerHTML;
// var ElementList = U.M.GTCN(InnerFrame.childNodes); var SubStr = "";
// var NewArray = []; var Local; var ElementInner;
// for (var i = 0; i < ElementList.length; i++) {
// ElementInner = U.OU.OuterHTML(ElementList[i]);
// Local = InnerHTML.toLowerCase().indexOf(ElementInner.toLowerCase());
// SubStr = InnerHTML.substring(0, Local);
// if (SubStr.replace(/(^\s*)|(\s*$)/g, "") != "") { NewArray.push(SubStr); } //如果为空就不加入到数组中
// NewArray.push(ElementList[i]);
// InnerHTML = InnerHTML.substring(Local + ElementInner.length, InnerHTML.length);
// }
// if (InnerHTML.replace(/(^\s*)|(\s*$)/g, "") != "") { NewArray.push(InnerHTML); }
// return NewArray;
//}
//U.OU.OuterHTML = function (Element) {
// var HTMLFrame = $$("span", {}); HTMLFrame.appendChild(Element);
// return HTMLFrame.innerHTML;
//}
////文本编辑器(兼容IE,Chroem)Firefox未测试
//U.OU.Editplus = function (StyleName, Param) {
// var BrowserJudge = !(document.selection); //判断是哪个浏览器
// var range = BrowserJudge ? window.getSelection().getRangeAt(0) : document.selection.createRange();
// var TextFather = BrowserJudge ? range.commonAncestorContainer.parentNode : range.parentElement(); //获取文本的父窗口
// var InnerHTML = BrowserJudge ? document.createElement('span') : range.htmlText; //返回选中的InnerHTML
// if (BrowserJudge) { SpanFrame.appendChild(range.cloneContents()).innerHTML; }
// var ElementList = U.OU.SpiltInnerHTML(InnerHTML); //将InnerHTML分割成数组(根据标签进行分割)
// var NewStyle = TextFather.style[StyleName] == Param[0] ? Param[1] : Param[0]; var NextSpan;
// if (ElementList[0].nodeName) {//如果开头是标签就取标签相反的,如果是文本就取第一种样式
// for (var i = 0; i < ElementList.length; i++) {
// NewStyle = ElementList[i].style[StyleName]; NextSpan = ElementList[i + 1];
// if (NextSpan == null || NextSpan.nodeName == null || NextSpan.style[StyleName] == NewStyle) { NewStyle = NewStyle == Param[0] ? Param[1] : Param[0]; break; }
// }
// }
// var HTMLFrameB = $$("span", {}); var HTMLFrameS = $$("span", {}, HTMLFrameB);
// var str = ChildList = ""; HTMLFrameS.style[StyleName] = NewStyle; var ElementName = "";
// for (var i = 0; i < ElementList.length; i++) {
// ElementName = ElementList[i].nodeName;
// if (ElementName) {
// if (ElementList[i].innerHTML == "" && ElementName == "SPAN") { continue; }
// ChildList = ElementList[i].getElementsByTagName("*");
// for (var j = 0; j < ChildList.length; j++) { if (ChildList[j].nodeName != "BR") { ChildList[j].style[StyleName] = NewStyle; } }
// if (ElementName != "BR") {
// if (ElementName == "P" && (i == 0 || i == ElementList.length - 1)) {
// // if (i == ElementList.length - 1) { str += "
"; }
// HTMLFrameS.innerHTML = ElementList[i].innerHTML;
// str += HTMLFrameB.innerHTML;
// if (i == 0) { str += "
"; }
// continue;
// }
// ElementList[i].style[StyleName] = NewStyle;
// }
// str += U.OU.OuterHTML(ElementList[i]);
// }
// else { HTMLFrameS.innerHTML = ElementList[i]; str += HTMLFrameB.innerHTML; }
// }
// if (BrowserJudge) { var NewFrame = $$("span", { "innerHTML": str }); range.deleteContents(); range.insertNode(HTMLFrameS); }
// else { range.pasteHTML(str); }
//}
////文本编辑器(兼容IE,Chroem)Firefox未测试
////U.OU.Editplus = function (StyleName, Param) {
//// var BrowserJudge = !(document.selection); //判断是哪个浏览器
//// var range = BrowserJudge ? window.getSelection().getRangeAt(0) : document.selection.createRange();
//// var TextFather = BrowserJudge ? range.commonAncestorContainer.parentNode : range.parentElement(); //获取文本的父窗口
//// var SpanFrame = BrowserJudge ? document.createElement('span') : $$("span", { "innerHTML": range.htmlText }); //返回innerHTML为选中内容的span
//// if (BrowserJudge) { SpanFrame.appendChild(range.cloneContents()); } var SpanList = SpanFrame.getElementsByTagName("*");
//// var NewStyle = Param[0]; var NextSpan;
//// //如果开头是标签就取标签相反的,如果是文本就取第一种样式
//// if (!(SpanFrame.firstChild.nodeValue)) {
//// for (var i = 0; i < SpanList.length; i++) {
//// NewStyle = SpanList[i].style[StyleName]; NextSpan = SpanList[i + 1];
//// if (NextSpan == null || NextSpan.style[StyleName] == NewStyle) { NewStyle = NewStyle == Param[0] ? Param[1] : Param[0]; break; }
//// }
//// }
//// else { NewStyle = TextFather.style[StyleName] == Param[0] ? Param[1] : Param[0]; }
//// for (var i = 0; i < SpanList.length; i++) { SpanList[i].style[StyleName] = NewStyle }; //让内部所有标签都为该css
//// SpanFrame.style[StyleName] = NewStyle;
//// if (BrowserJudge) { range.deleteContents(); range.insertNode(SpanFrame); return; }
//// if (TextFather.contentEditable == "true" || U.OU.DivisionEW == "Word") { range.pasteHTML(SpanFrame.outerHTML); }
//// else {
//// TextFather.style[StyleName] = NewStyle; SpanList = TextFather.getElementsByTagName("*");
//// for (var i = 0; i < SpanList.length; i++) { SpanList[i].style[StyleName] = NewStyle };
//// }
////}
////让回车生成的