function getOs() { var OsObject = ""; if (navigator.userAgent.toLowerCase().indexOf("trident") > -1 && navigator.userAgent.indexOf("rv") > -1) { return "MSIE"; } if (navigator.userAgent.indexOf("MSIE") > 0) { return "MSIE"; } if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) { return "Firefox"; } if (isSafari = navigator.userAgent.indexOf("Safari") > 0) { return "Safari"; } if (isCamino = navigator.userAgent.indexOf("Camino") > 0) { return "Camino"; } if (isMozilla = navigator.userAgent.indexOf("Gecko/") > 0) { return "Gecko"; } } //自定义出错处理 var gOldOnError = window.onerror; window.onerror = function (msg, url, line) { //这里变态的判断是否msg里面包含了6个空格 //alert(msg.substring(msg.length - 6).length); //alert(msg+msg.length); if (gOldOnError) // Call previous handler. return gOldOnError(errorMsg, url, lineNumber); if (msg == "Global_Define_Error" || msg == "error" || msg.indexOf("Stack overflow at line") != -1) { return true; } else { try { console.warn("error:" + msg + "," + url + "," + line); } catch (ex) { return false; } var OsObject = getOs(); if (OsObject == "MSIE" || OsObject == "Firefox") { //alert("error:" + msg + "," + url + "," + line); } else { return true; } } }; // //声明全局通用类 // var Global = new Object(); // Global.Animation = new Object(); // /******************************************* // * 以下自定全局公共方法 // *******************************************/ // // //常用配置 // Global.Virtual = ""; //这个要自己设置,网站的虚拟目录如果没有不填,填写如"/web" // Global.RootDomain = "" //这个要自己设置,网站的cookie Domain // //声明全局Cookie // Global.Animation.Small = ""; // //声明网站地址 // Global.Site = ""; //这个要自己设置 网站地址 //停止JavaScript执行 Global.Stop = function () { // 这样子跟踪不了代码。 throw new Error("Global_Define_Error"); } //抛出自定义错误方法 Global.Error = function (msg) { //这里判断是否有错误跳转地址 if (msg == null) { return; } var lenindex = msg.indexOf("^$#$^"); if (lenindex != -1) { var message = msg.substring(0, lenindex).replace(/(^\s*)|(\s*$)/g, ""); if (message.length != 0) { alert(message); } //说明有要进行跳转的地址 var url = msg.substring(lenindex + 5); window.location.href = url; //Global.Stop(); } else { //这里变态的加上6个空格是给window.error中判断是否为自定义抛出错误用的 var msg = msg.replace(/(^\s*)|(\s*$)/g, ""); if (msg.length != 0) { alert(msg); } //Global.Stop(); } }; //将指定的容器里面的对像生成post数据 Global.GetFormValue = function (form) { var fields = form.find("[name]"); var data = ""; for (var i = 0; i <= fields.length - 1; i++) { var item = fields.eq(i); var objType = item.attr("type"); var name = encodeURIComponent(item.attr("name")); var val = encodeURIComponent(item.val()); //如果是input radio或check的时候 将on改为1 off改为0 if (objType == "radio") { if (typeof (item.prop) != "undefined") { if (item.prop("checked") != true) { //Jquery 1.6以后 continue; } } else { if (item.attr("checked") != true) { //Jquery 1.6以前 continue; } } } else if (objType == "checkbox") { //if (item.attr("checked") != true) {//Jquery 1.6以前 if (typeof (item.prop) != "undefined") { if (item.prop("checked") != true) {//Jquery 1.6以后 val = item.attr("unvalue"); if (typeof (val) == "undefined") { val = null; } } } else { if (item.attr("checked") != true) {//Jquery 1.6以前 val = item.attr("unvalue"); if (typeof (val) == "undefined") { val = null; } } } } else if (objType == "select-multiple") { if (item.length > 0) { var selectControl = item.get(0); for (var x = 0; x <= selectControl.options.length - 1; x++) { if (selectControl.options[x].selected == true) { if (data == "") { data += name + "=" + encodeURIComponent(selectControl.options[x].value); } else { data += "&" + name + "=" + encodeURIComponent(selectControl.options[x].value); } } } } continue; } if (data == "") { data += name + "=" + val; } else { data += "&" + name + "=" + val; } } return data; }; //将指定对像设置成禁用或可用 Global.Disabled = function (target, bool) { if (target != null) { try { $(target).attr("disabled", bool); } catch (ex) { } } }; //遮罩对像 Global.Mark = function (target, typeName, bool) { if (typeof (target) != "undefined" && typeof (typeName) != "undefined") { if (bool == true) { if (typeof (Global.Animation[typeName]) != "undefined") { if ($(target).find("[name=Animation" + typeName + "]").length > 0) { $(target).find("[name=Animation" + typeName + "]").fadeIn(); } else { target.append(Global.Animation[typeName]); $(target).find("[name=Animation" + typeName + "]").fadeIn(); } } } else { if (typeof (Global.Animation[typeName]) != "undefined") { $(target).find("[name=Animation" + typeName + "]").fadeOut(); } } } } //全局Ajax提交 Global.Ajax = function (options, send, target, html) { var setting = { ajaxCache: true, ajaxUrl: "", ajaxData: "", ajaxAsync: true, ajaxMark: true } $.extend(true, setting, options); var reVal; jQuery.support.cors = true; $.ajax( { cache: setting.ajaxCache, type: "POST", url: Global.Site + setting.ajaxUrl, data: setting.ajaxData, async: setting.ajaxAsync, dataType: 'json', crossDomain: true, success: function (result) { reVal = result; if (typeof (setting.ajaxFunSuccess) == "function") { setting.ajaxFunSuccess(result); } }, beforeSend: function () { //将提交对像禁用 Global.Disabled(send, true) //if (setting.ajaxMark == true) { // Global.Mark(target, html, true); // //显示提交当中 // if (window.top != null && window.top.frames[0] != null && window.top.frames[0].document.getElementById("dvLoadingMsg") != null) { // window.top.frames[0].document.getElementById("dvLoadingMsg").style.display = ""; // } // if (document.getElementById("dvLoadingMsg") != null) { // document.getElementById("dvLoadingMsg").style.display = "inline"; // } // $("#divloading").show(); //} }, complete: function () { //启用提交对像 Global.Disabled(send, false) //Global.Mark(target, html, false); //完成后停止显示“提交当中” //if (window.top != null && window.top.frames[0] != null && window.top.frames[0].document.getElementById("dvLoadingMsg") != null) { // window.top.frames[0].document.getElementById("dvLoadingMsg").style.display = "none"; //} //if (document.getElementById("dvLoadingMsg") != null) { // document.getElementById("dvLoadingMsg").style.display = "none"; //} //$("#divloading").hide(); }, error: function (XMLHttpRequest, textStatus, errorThrown) { //如果textStatus状态为error的话,XMLHttpRequest是没有message的 var message = XMLHttpRequest.responseText || XMLHttpRequest.statusText;//ie8 only statusText //默认出错长度不超过100个字符长度 // if (message.length > 100) // { // alert("服务器未知错误"); // } // else // { // alert(message); // } //alert(message); Global.Disabled(send, false) //Global.Mark(target, html, false); //更换验证码,因为后台已经删除了原来的验证码 //changeCheckCode(); //完成后停止显示“提交当中” //if (window.top != null && window.top.frames[0] != null && window.top.frames[0].document.getElementById("dvLoadingMsg") != null) { // window.top.frames[0].document.getElementById("dvLoadingMsg").style.display = "none"; //} //if (document.getElementById("dvLoadingMsg") != null) { // document.getElementById("dvLoadingMsg").style.display = "none"; //} //$("#divloading").hide(); if (typeof (options.ajaxFunError) != "undefined") { setting.ajaxFunError(XMLHttpRequest, textStatus, errorThrown); } else if (message.indexOf("Service Unavailable") == -1 && message != "error") { Global.Error(message); } } }); //当reVal为空和 setting.ajaxAsync == false (不异步) 时要判断是否有返回信息 // if (typeof (reVal) == "undefined" && setting.ajaxAsync == false) { // Global.Error("服务器返回错误"); // } return reVal; }; //传Jquery Input对像 Global.GetSearchURL = function (params) { var query = ""; for (var i = 0; i <= params.length - 1; i++) { var name = params[i].name; var value = encodeURIComponent($(params[i]).val()); if (query.length == 0) { query += "?" + name + "=" + value; } else { query += "&" + name + "=" + value; } } query = Global.Virtual + "/ajax.aspx" + query; return query; }; //传查询控件地址和参数 Global.UserControl = function (name, params, send, fun, async, mark, errFun) { var url = Global.Virtual + "/ajax.aspx"; if (typeof (fun) == "undefined") { alert("fun undefined"); return; } var data = "template=" + encodeURIComponent(name) + "&" + params; if (typeof (async) == "undefined") { async = true; } if (typeof (mark) == "undefined") { mark = true; } if (typeof (errFun) != "function") { errFun = null; } return Global.Ajax( { ajaxAsync: async, ajaxFunSuccess: fun, ajaxUrl: url, ajaxData: data, ajaxMark: mark, ajaxFunError: errFun }, send); }; //传用户控件地址和参数 Global.DataControl = function (name, params, send, fun, async, mark) { var url = Global.Virtual + "/ajax.aspx"; if (typeof (fun) == "undefined") { alert("fun undefined"); return; } var data = "templatedata=" + encodeURIComponent(name) + "&" + params; if (typeof (async) == "undefined") { async = true; } if (typeof (mark) == "undefined") { mark = true; } return Global.Ajax( { ajaxAsync: async, ajaxFunSuccess: fun, ajaxUrl: url, ajaxData: data, ajaxMark: mark }, send); }; //传用户控件地址和参数 Global.HtmlControl = function (name, params, send, fun, async, mark) { var url = Global.Virtual + "/ajax.aspx"; if (typeof (fun) == "undefined") { alert("fun undefined"); return; } var data = "templatedefine=" + encodeURIComponent(name) + "&" + params; if (typeof (async) == "undefined") { async = true; } if (typeof (mark) == "undefined") { mark = true; } return Global.Ajax( { ajaxAsync: async, ajaxFunSuccess: fun, ajaxUrl: url, ajaxData: data, ajaxMark: mark }, send); }; //文件上传 function UploadFile(valueControl, title, type, path, fileName, width, height, sizeControl) { $.fn.fancybox.show({ 'zoomSpeedIn': 600, 'zoomSpeedOut': 500, frameWidth: 500, frameHeight: 350, frameURL: Global.Site + "/tools/uploadform.aspx?title=" + encodeURIComponent(title) + "&type=" + encodeURIComponent(type) + "&path=" + encodeURIComponent(path) + "&fileName=" + encodeURIComponent(fileName) + "&height=" + encodeURIComponent(height) + "&width=" + encodeURIComponent(width) + "&valueControl=" + encodeURIComponent(valueControl) + "&sizeControl=" + encodeURIComponent(sizeControl), hideOnContentClick: false }); return false; } //文件上传 function UploadImage(valueControl, title, type, path, fileName, width, height, sizeControl) { $.fn.fancybox.show({ 'zoomSpeedIn': 700, 'zoomSpeedOut': 550, frameWidth: 700, frameHeight: 600, frameURL: Global.Site + "/tools/CreateVideoImage/Create.aspx?title=" + encodeURIComponent(title) + "&type=" + encodeURIComponent(type) + "&path=" + encodeURIComponent(path) + "&fileName=" + encodeURIComponent(fileName) + "&height=" + encodeURIComponent(height) + "&width=" + encodeURIComponent(width) + "&valueControl=" + encodeURIComponent(valueControl) + "&sizeControl=" + encodeURIComponent(sizeControl), hideOnContentClick: false }); return false; } //----------------------------------------------------------------------------------- var Helper = new Object(); Helper.SecondToTime = function (time) { var size = time; var result = ""; if (size < 60) { result = size.toString(); } else if (size < 60 * 60) { result = Math.floor((size / 60)).toString() + ":"; if (size % 60 != 0) { result += (size % 60).toString().padLeft(2, '0'); } else { result += "00"; } } else { result = Math.floor((size / (60 * 60))).toString() + ":"; size = size % (60 * 60); result += Math.floor((size / 60)).toString().padLeft(2, '0') + ":"; if (size % 60 != 0) { result += (size % 60).toString().padLeft(2, '0'); } else { result += "00"; } } return result; } String.prototype.padLeft = function (padChar, width) { var ret = this; while (ret.length < width) { if (ret.length + padChar.length < width) { ret = padChar + ret; } else { ret = padChar.substring(0, width - ret.length) + ret; } } return ret; }; String.prototype.padRight = function (padChar, width) { var ret = this; while (ret.length < width) { if (ret.length + padChar.length < width) { ret += padChar; } else { ret += padChar.substring(0, width - ret.length); } } return ret; }; String.prototype.trim = function () { return this.replace(/^\s+/, '').replace(/\s+$/, ''); }; String.prototype.trimLeft = function () { return this.replace(/^\s+/, ''); }; String.prototype.trimRight = function () { return this.replace(/\s+$/, ''); }; String.prototype.caption = function () { if (this) { return this.charAt(0).toUpperCase() + this.substr(1); } return this; }; String.prototype.reverse = function () { var ret = ''; for (var i = this.length - 1; i >= 0; i--) { ret += this.charAt(i); } return ret; }; String.prototype.startWith = function (compareValue, ignoreCase) { if (ignoreCase) { return this.toLowerCase().indexOf(compareValue.toLowerCase()) == 0; } return this.indexOf(compareValue) == 0 }; String.prototype.endWith = function (compareValue, ignoreCase) { if (ignoreCase) { return this.toLowerCase().lastIndexOf(compareValue.toLowerCase()) == this.length - compareValue.length; } return this.lastIndexOf(compareValue) == this.length - compareValue.length; }; Helper.resizeIFrame = function resizeIFrame(id, target) { //var targetParent = target ? (document.getElementById(target) ? document.getElementById(target) : document.body) : document.body; //var iframer = document.getElementById(id); Helper.setIframeHeight(id); //iframer.height = targetParent.offsetHeight - iframer.offsetTop ; } Helper.getDocHeight = function getDocHeight(doc) { doc = doc || document; // stackoverflow.com/questions/1145850/ var body = doc.body, html = doc.documentElement; var height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight); return height; } Helper.setIframeHeight = function setIframeHeight(id) { var ifrm = document.getElementById(id); var doc = ifrm.contentDocument ? ifrm.contentDocument : ifrm.contentWindow.document; ifrm.style.visibility = 'hidden'; ifrm.style.height = "10px"; // reset to minimal height ... // IE opt. for bing/msn needs a bit added or scrollbar appears ifrm.style.height = Helper.getDocHeight(doc) + 4 + "px"; ifrm.style.visibility = 'visible'; } Helper.getCurrentVideoPositionJWP = function () { if (typeof jwplayer !== "undefined") { var isFlash = (navigator.userAgent.indexOf("iPad") == -1 && navigator.userAgent.indexOf("iPhone") == -1) if (isFlash) { if (jwplayer("JWPlayerHTML4") !== null) { return jwplayer("JWPlayerHTML4").getPosition() || -1; } } else { if (jwplayer("JWPlayerHTML4") !== null) { return jwplayer("JWPlayerHTML5").getPosition() || -1; } } } }