锘?function (window, $) { var webApp = function () { /** * method _error 閿欒澶勭悊 * param * return null **/ var _error = function (mes) { alert(mes); }; var resizeCallback = new Array(); var onmousewheelUp = new Array(); var onmousewheelDown = new Array(); var _self = this; var wheelObject = new Array(); var isWheel = false; var resizeTimer = null; var keyCode = { "Esc": 27, "F2": 113, "Enter": 13, "F12": 123 }; var rightShielding = function (window) { if (document.captureEvents) document.captureEvents(Event.MOUSEUP); function nocontextmenu() { event.cancelBubble = true event.returnValue = false; return false; } function norightclick(e) { if (window.Event) { if (window.Event.which == 2 || window.Event.which == 3) return false; } else if (event.button == 2 || event.button == 3) { event.cancelBubble = true event.returnValue = false; return false; } } document.oncontextmenu = nocontextmenu; document.onmousedown = norightclick; }; var checkType = { "email": function (value) { return /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/.test(value); }, "isNotNull": function (value) { return value != "" && value != null; }, "validatemobile": function (value) { if (value.length == 0) { return false; }; if (value.length != 11) { return false; }; var myreg = /^(((13[0-9]{1})|159|189|188|187|186|185|180|153)+\d{8})$/; if (!myreg.test(value)) { return false; }; return true; }, "companyShortName": function (value) { var maxLength = 20; var minLength = 4; if (value.toString().getLength() < minLength) return false; else if (value.toString().getLength() > maxLength) return false; return true; }, "company": function (value) { var minLength = 10; return value.toString().getLength() >= minLength; }, "qq": function (value) { if (this.isNotNull(value)) { if (this.isNumber(value)) { var minLength = 6; return value.toString().length >= minLength; } else { return false; } } return true; }, "password": function (value) { var minLength = 6; return value.toString().length >= 6; }, "isNumber": function (value) { if (!isNaN(value)) { return true; } else { return false; } }, "isGreaterThanZero": function (value) { if (this.isNumber(value)) { if (value > 0) { return true; }; return false; }; return false; } }; var readFile = function (optionType, file, callback) { var reader = new FileReader(); if (optionType in reader) { reader[optionType](file); reader.onload = function (e) { callback && callback(this.result); }; reader.onerror = function (e) { _self.message(e.message); } } }; var readAsDataURL = function (file, callback) { readFile("readAsDataURL", file, callback); }; var readAsBinaryString = function (file, callback) { readFile("readAsBinaryString", file, callback); }; var readAsText = function (file, callback) { readFile("readAsText", file, callback); }; var keyDown = function (keyCode, callback) { document.onkeydown = function (event) { var e = event || window.event || arguments.callee.caller.arguments[0]; if (e && e.keyCode == keyCode) { if (typeof callback === "function") { callback(e); } } }; }; var resize = function () { window.onresize = function () { if (resizeTimer == null) { resizeTimer = window.setTimeout(function () { for (var i = 0; i < resizeCallback.length; i++) { resizeCallback[i](); } resizeTimer = null; }, 100) } }; }; var isBrowserRedirect = function () { var sUserAgent = navigator.userAgent.toLowerCase(); var bIsIpad = sUserAgent.match(/ipad/i) == "ipad"; var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os"; var bIsMidp = sUserAgent.match(/midp/i) == "midp"; var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4"; var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb"; var bIsAndroid = sUserAgent.match(/android/i) == "android"; var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce"; var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile"; if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) { return true; } else { return false; } }; var getBrowser = function () { var sys = {}; var ua = navigator.userAgent.toLowerCase(); var s; (s = ua.match(/msie ([\d.]+)/)) ? sys.ie = s[1] : (s = ua.match(/firefox\/([\d.]+)/)) ? sys.firefox = s[1] : (s = ua.match(/chrome\/([\d.]+)/)) ? sys.chrome = s[1] : (s = ua.match(/opera.([\d.]+)/)) ? sys.opera = s[1] : (s = ua.match(/version\/([\d.]+).*safari/)) ? sys.safari = s[1] : 0; return sys; }; var stopDefault = function (e) { if (e && e.preventDefault) e.preventDefault(); else window.event.returnValue = false; return false; }; //var fullscreen = function () { // elem = document.body; // if (elem.webkitRequestFullScreen) { // elem.webkitRequestFullScreen(); // } else if (elem.mozRequestFullScreen) { // elem.mozRequestFullScreen(); // } else if (elem.requestFullScreen) { // elem.requestFullscreen(); // } //}; /** * method init 鍒濆WebApp **/ (function init(window, $) { String.prototype.replaceAll = function (s1, s2) { return this.replace(new RegExp(s1, "gm"), s2); }; /** * 鍒ゆ柇涓枃 * @method isChinese **/ String.prototype.isChinese = function () { var pattern = /^([\\u4E00-\\u9FA5]|[\\uFE30-\\uFFA0])*$/gi; if (pattern.test(this)) return true; else return false; }; /** * 鎴彇涓嫳鏂囬暱搴﹀瓧绗 * @method subEnglihChineseString * @param {Int} length 闀垮害 **/ String.prototype.getEnglihChineseString = function (length) { var num = 0; var str = str || ""; for (var i = 0; i < this.length; i++) { if (this.charAt(i).isChinese()) num += 1; else num += 2; str += this.charAt(i); if (num == parseInt(length)) break; } return str; }; String.prototype.getLength = function () { var num = 0; for (var i = 0; i < this.length; i++) { if (this.charAt(i).isChinese()) num += 1; }; return num; }; /** * 鎴彇涓嫳鏂囬暱搴 * @method getLength **/ String.prototype.getCELength = function () { var num = 0; for (var i = 0; i < this.length; i++) { if (this.charAt(i).isChinese()) num += 1; else num += 2; }; return num; }; /** * String 浠ユ暟缁勭殑褰㈠紡鑾峰彇value 鍦⊿tring 涓殑浣嶇疆 * @method indexArray * @param {String} value 瀛楃 **/ String.prototype.indexArray = function (value) { var y = this.split(','); for (k in y) { if (y[k] == value) { return k; } } return null; }; /** * String 鎵╁睍绉婚櫎 * @method removeArray * @param {String} value 瀛楃 **/ String.prototype.removeArray = function (value) { var s = this.split(','); return s.constructor.removeItemByValueToString.call(s, value); }; /** * Array闈欐€佹墿灞 绉婚櫎鍏冪礌 * @method remove * @param {Int} n 鍏冪礌浣嶇疆 **/ Array.remove = function (n) { return n < 0 ? this : this.slice(0, n).concat(this.slice(n + 1, this.length)); }; /** * Array闈欐€佹墿灞曟寜鍊肩Щ闄ゅ厓绱 * @method removeItemByValueToString * @param {String} value 鍊 **/ Array.removeItemByValueToString = function (value) { return _self.removeItemByValue(value, this).join(','); }; resize(); //if (window.screen) { // window.moveTo(0, 0); // window.resizeTo(window.screen.availWidth, window.screen.availHeight); //} //rightShielding(window); //keyDown(keyCode.F12, function (e) { // stopDefault(e); //}); })(window, $); this.keyDown = function (keyCode, callback) { keyDown(keyCode, callback); }; this.getKeyCode = function () { return keyCode; }; /** * method getWindowSize 鑾峰彇娴忚鍣ㄩ珮搴 * param * return json **/ this.getWindowSize = function () { return { "width": $(window).width(), "height": $(window).height() }; }; this.message = function (mes) { try{ window.Message.tips(mes); } catch(e){ alert(mes); } //_error(mes); }; /** * method strToJson 瀛楃涓茶浆json * param paramStr json 瀛楃涓 * return json **/ this.strToJson = function (paramStr) { if (paramStr == "" || paramStr == null) return null; if (typeof paramStr == "object") return paramStr; var json = (new Function("return " + paramStr))(); return json; }; /** * method strToJson 瀛楃涓茶浆json * param paramStr json 瀛楃涓 * return json **/ this.getFileName = function (value) { var names = value.split("\\"); return names[names.length - 1]; }; /** * method getSuffixName 鑾峰彇鍚庣紑鍚 * param * return string **/ this.getSuffixName = function (value) { return /\.[^\.]+$/.exec(value).toString() }; /** * method isImage 鏄惁鏄浘鐗囨枃浠 * param * return true or false **/ this.isImage = function (value) { var suffix = [".jpg", ".png", ".bmp", ".gif", ".jpeg"]; for (var i = 0; i < suffix.length; i++) { if (value === suffix[i]) { return true; }; }; return false; } /** * method getDocumentSize 鑾峰彇鏂囨湰楂樺害 * param * return json **/ this.getDocumentSize = function () { return { "width": $(document).width(), "height": $(document).height() }; }; /** * method httpRequest 寮傛璇锋眰 * param url 璇锋眰璺緞 * param cmd 鎵ц鍛戒护 * param param 璇锋眰鍙傛暟 * return null **/ this.httpRequest = function (url, cmd, param) { var p = { url: url, type: "POST", data: param.data, dataType: "text", async: true, contentType: "application/x-www-form-urlencoded", error: function (e, s, d) { _error("EXEC [" + cmd + "] ERROR. MESSAGE IS [" + e.statusText + "]"); } }; $.extend(p, param); p.data = p.data || new Object(); p.data["cmd"] = cmd; $.ajax(p); }; // this.checkType = checkType; this.getQueryString = function (name) { var result = location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i")); if (result == null || result.length < 1) { return ""; } return result[1]; }; //鑾峰彇璇█ this.getLanguage = function () { var langQuery = this.getQueryString("lang"); if (langQuery == null || langQuery == "") { var langCoockie = $.cookie("c_language"); if (langCoockie == null || langCoockie == "") { return "cn"; } else { return langCoockie; } } else { return langQuery; } }; // this.translateUI = function (funcTran, async) { var lang = this.getLanguage(); if (lang != "en" && lang != "jp") return; if (typeof (async) == "undefined") async = true; $.ajax({ type: "get", cache: true, url: "../lang/TranslateHandler.ashx", //dataType: json, async: async, data: { lang: lang }, success: function (data, status) { data = jQuery.parseJSON(data); if (data.Status == "error") { return; } if (data.Status == "exception") { return; } //鍥炶皟 if (typeof funcTran === "function") { funcTran(data, lang); } }, error: function () { alert('閿欒浠g爜 298'); } }); }; // this.setCookieToLanguageCN = function () { this.setCookieToLanguage("cn"); }; this.setCookieToLanguageEN = function () { this.setCookieToLanguage("en"); }; this.setCookieToLanguageJP = function () { this.setCookieToLanguage("jp"); }; this.setCookieToLanguage = function (value) { $.cookie("c_language", value, { path: '/' }); //try { // var language = value; // if (language == "cn") { // var elm = $("[data-language]"); // for (var i = 0; i < elm.length; i++) { // var $this = $(elm[i]); // var val = ch[$this.attr("data-language")]; // $this.html(val).attr("title", val); // } // } else if (language == "en") { // var elm = $("[data-language]"); // for (var i = 0; i < elm.length; i++) { // var $this = $(elm[i]); // var val = en[$this.attr("data-language")]; // $this.html(val).attr("title", val); // } // } //} catch (e) { //} }; this.getLanguageFromCookie = function () { var lang = $.cookie("c_language"); if (lang == null || lang == "") return "cn"; else return lang; //try { // var language = value; // if (language == "cn") { // var elm = $("[data-language]"); // for (var i = 0; i < elm.length; i++) { // var $this = $(elm[i]); // var val = ch[$this.attr("data-language")]; // $this.html(val).attr("title", val); // } // } else if (language == "en") { // var elm = $("[data-language]"); // for (var i = 0; i < elm.length; i++) { // var $this = $(elm[i]); // var val = en[$this.attr("data-language")]; // $this.html(val).attr("title", val); // } // } //} catch (e) { //} }; /** * method verification 琛ㄥ崟楠岃瘉 * param * return false or true **/ this.verification = function (elm) { var errorClass = { "input": "verification-error", "span": "verification-meaage-error" }, verificationElm = elm || $("[data-verification]"), isFouce = true, isSucess = true; verificationElm.removeClass(errorClass.input); for (var i = 0; i < verificationElm.length; i++) { var $this = $(verificationElm[i]), funcName = $this.attr("data-verification"), span = $this.parent().find(".help-block"), sucess = true; if (!span.is("span")) { span = $this.parent().next().find(".help-block"); }; if (funcName in checkType) { sucess = checkType[funcName]($this.val()); }; if (!sucess) { if (isSucess) isSucess = sucess; $this.addClass(errorClass.input); span.html($this.attr("data-error")).addClass(errorClass.span); if (isFouce) { $this.focus(); isFouce = false; }; } else { var message = $this.attr("data-message") || ' '; if (checkType.isNotNull(message)) span.html(message).removeClass(errorClass.span); }; }; return isSucess; }; /** * method getPageName 鑾峰彇褰撳墠璇锋眰缃戦〉鍚嶇О * param * return string **/ this.getPageName = function () { var a = location.href, b = a.split("/"), c = b.slice(b.length - 1, b.length).toString(String).split("."); return c.slice(0, 1).toString(); }; /** * method isItemInArray 鍒ゆ柇闃熷垪涓槸鍚﹀寘娑佃鍊 * param 妫€娴嬪€ * param 妫€娴嬮槦鍒 * return string **/ this.isItemInArray = function (item, array) { for (var i = 0; i < array.length; i++) { if (array[i] == item) { return item; }; }; return null; }; this.removeItemByValue = function (item, array) { var copy = new Array(); for (var i = 0; i < array.length; i++) { if (array[i] == item) { continue; } copy.push(array[i]); } return copy; }; /** * method getQueryString 閿欒 * param name url 鍙傛暟 * return string or null **/ this.getQueryString = function (name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = decodeURI(window.location.search).substr(1).match(reg); if (r != null) return unescape(r[2]); return null; }; /** * method errorModel 閿欒 * param 閿欒娑堟伅 * return string **/ this.errorModel = function (message) { return '
' + '' + message + '
' }; this.isSucess = function (message, elm, callback) { var mes = this.getQueryString("isSucess"); this.submitMessage(mes, elm, "澶勭悊寮傚父璇疯仈绯荤鐞嗗憳", message, callback); }; /*榧犳爣鍏冪礌鐩搁偦鍒ゆ柇 * @method eventElement * @param {Object} e 榧犳爣瀵硅薄 * @param {Element} Elements 妫€娴嬪厓绱 **/ this.eventNeighboring = function (e, elements) { e = window.event || e; elements = typeof elements == "string" ? $("#" + elements) : elements; var x = e.clientX, y = e.clientY; w = elements.width(), h = elements.height(), t = elements.offset().top, l = elements.offset().left, ol = l + w, ot = h + t; if (x >= l && y >= t) { if (x <= ol && y <= ot) { return true; } } }; this.submitMessage = function (mes, elm, errorMessage, sucessMessage, callback) { if (!mes) return; var isSucess; elm = typeof elm == "string" ? $("#" + elm) : elm; if (this.toBool(mes)) { isSucess = true; elm.html(this.sucessModel(sucessMessage)); } else { isSucess = false; elm.html(this.errorModel(errorMessage)); } window.setTimeout(function () { elm.find("div").hide(300, function () { callback && callback(isSucess); }); }, 3000) } this.sucessModel = function (message) { return '
' + '' + message + '
' }; this.REG = { SRC: "<[^<>]*?\\ssrc=['\"]?(.*?)['\"].*?>" }; this.toBool = function (val) { if (val) { return true; } else if (val == "true") return true; else if (val == "false") { return false; } else { return false; } }; this.isBrowserRedirect = function () { return isBrowserRedirect(); }; this.readAsDataURL = function (file, callback) { readAsDataURL(file, callback); }; this.getFileImage = function (file, width, height, callback) { this.readAsDataURL(file, function (src) { _self.autoResizeImage(width, height, src, function (w, h, src) { callback && callback(w, h, src); }); }) }; /** * 鍒ゆ柇鏄惁鏈夋粴鍔ㄦ潯 * @method isScroll * @param {Object} el Element **/ this.isScroll = function (el, el2) { var elems = el ? [el] : [document.documentElement, document.body]; var scrollX = false, scrollY = false; if (el2) { if (el2.width() > el.width()) { scrollX = true; } if (el2.height() > el.height()) { scrollY = true; } } return { scrollX: scrollX, scrollY: scrollY }; }; this.browserRedirect = function () { if (this.isBrowserRedirect()) { window.location.href = "/mobilePage/CorporationList.aspx"; } else { // var browser = getBrowser(); // if (browser.ie) { // if (browser.ie == '8.0') { // window.location.href = "/error/Browser.aspx?version=8"; // } else if (browser.ie == '7.0') { // window.location.href = "/error/Browser.aspx?version=7"; // } else if (browser.ie == '6.0') { // window.location.href = "/error/Browser.aspx?version=6"; // } // } } }; this.getGuidGenerator = function () { var S4 = function () { return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); }; return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4()); }; this.setResizeCallback = function (func) { resizeCallback.push(func); }; this.mouseCollision = function (e, elm) { elm = $(elm); var w = elm.width(); var h = elm.height(); var t = elm.offset().top; var l = elm.offset().left; if (e.clientX >= l && e.clientX <= w + l && e.clientY >= t && e.clientY <= t + h) { return true; } return false; }; this.jqueryAutoResizeImage = function (maxWidth, maxHeight) { //var elm = this; var size = _self.autoResizeImageToObject.call(this, maxWidth, maxHeight); this.width(size.w).height(size.h); }; this.autoResizeImageToObject = function (maxWidth, maxHeight, width, height) { var hRatio; var wRatio; var Ratio = 1; var w = typeof this.width == "function" ? this.width() : this.width; var h = typeof this.height == "function" ? this.height() : this.height; wRatio = maxWidth / w; hRatio = maxHeight / h; if (maxWidth == 0 && maxHeight == 0) { Ratio = 1; } else if (maxWidth == 0) {// if (hRatio < 1) Ratio = hRatio; } else if (maxHeight == 0) { if (wRatio < 1) Ratio = wRatio; } else if (wRatio < 1 || hRatio < 1) { Ratio = (wRatio <= hRatio ? wRatio : hRatio); } if (Ratio < 1) { w = w * Ratio; h = h * Ratio; } return { "w": w, "h": h } }; this.autoResizeImage = function (maxWidth, maxHeight, src, callback) { this.imgReady(src, function () { var size = _self.autoResizeImageToObject.call(this, maxWidth, maxHeight); typeof callback === "function" && callback(size.w, size.h, src); }); }; this.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; }; 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 () { !onready.end && onready(); load && load.call(img); img = img.onload = img.onerror = null; }; if (!onready.end) { list.push(onready); if (intervalId === null) intervalId = setInterval(tick, 40); }; }; })(); this.stopPropagation = function (e) { e = e || window.event; if (e.stopPropagation) { e.stopPropagation(); } else { e.cancelBubble = true; } }; this.filePostion = function (btn, file) { btn = typeof btn === "string" ? $("#" + btn) : btn; file = typeof file === "string" ? $("#" + file) : file; var offset = btn.position(); file.css({ "top": offset.top + 5, "left": offset.left }); }; this.extendArrayInFirst = function (a, b) { for (var i = 0; i < b.length; i++) { if (b[i] == "") continue; if (this.isItemInArray(b[i], a)) continue; a.splice(0, 0, b[i]); } return a; }; this.setOnmousewheelCallback = function (up, down, object) { if (typeof up === "function") onmousewheelUp.push(up); if (typeof down === "function") onmousewheelDown.push(down); return this; }; this.removeOnmousewheelCallback = function () { if (arguments.length == 0) { onmousewheelUp = new Array(); onmousewheelDown = new Array(); } else if (arguments.length == 1) { onmousewheelDown.splice(arguments[0], 1); onmousewheelUp.splice(arguments[0], 1); } }; this.onmousewheel = function (callback) { if (isWheel) return; window.onmousewheel = document.onmousewheel = function (event) { var event = event || window.event; var delta = event.wheelDelta ? event.wheelDelta / 120 : event.detail ? -event.detail / 3 : null; if (delta == 1) { for (var i = 0; i < onmousewheelUp.length; i++) { onmousewheelUp[i](); } } else if (delta == -1) { for (var i = 0; i < onmousewheelDown.length; i++) { onmousewheelDown[i](); } } callback && callback(event); isWheel = true; } }; this.stopDefault = function (e) { stopDefault(e); }; }; window.WebApp = new webApp(); })(window, $);