(function(win, doc, docEl) {
function setRem() {
var width = docEl.getBoundingClientRect().width;
var rem = width / 10;css
win.rem = rem;
docEl.style.fontSize = rem + 'px';
}
setRem();html
var remTimer;
win.addEventListener('resize', function() {
clearTimeout(remTimer);
remTimer = setTimeout(setRem, 300);
}, false);
})(window, document, document.documentElement)git
Number.prototype.formatMoney = function (places, thousand, decimal) {
places = !isNaN(places = Math.abs(places)) ? places : 2;
thousand = thousand || ",";
decimal = decimal || ".";
var number = this,
negative = number < 0 ? "-" : "",
i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return negative + (j ? i.substr(0, j) + thousand : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : "");
};github
/** * 獲取字符串的真實長度 * @method getStrLeng * @param string str 目標字符串 * @return int 真實的長度值 */ function getStrLeng(str){ var realLength = 0; var len = str.length; var charCode = -1; var cn=en=0; for(var i = 0; i < len; i++){ charCode = str.charCodeAt(i); if (charCode >= 0 && charCode <= 128) { realLength += 1; en+=1; }else{ realLength += 2; cn+=1; } } return realLength; } /** * 判斷指定字符或數字是否存在於目標數組中 * @method in_array * @param needle str|number 目標字符串 * @param haystack str|int 目標數組 * @return bool bool true,false */ function inArray(needle, haystack) { if(typeof needle == 'string' || typeof needle == 'number'){ for(var i in haystack){ if(haystack[i] == needle){ return true; } } } return false; } /** * 獲取文本中的html指定字符替換成字符實體 * @method htmlEncode * @param string text 目標文本 * @return text 返回替換後的文本 */ function htmlEncode(text) { return !text ? text : String(text).replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, """); } /** * 獲取文本中的html指定字符實體替換成字符 * @method htmlDecode * @param string text 目標文本 * @return text 返回替換後的文本 */ function htmlDecode(text) { return !text ? text : String(text).replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, '"'); } /** * 對字符串進行去空格處理 * @method utilsTrim * @param string text 目標文本 * @return text 返回去空格後的文本 */ function utilsTrim(text) { if (typeof(text) == "string") { return text.replace(/^\s*|\s*$/g, ""); } else { return text; } } /** * 判斷指定值是否爲空 * @method utilsIsEmpty * @param string val 目標值 * @return bool bool true,false */ function utilsIsEmpty(val) { switch (typeof(val)) { case 'string': return utilsTrim(val).length == 0 ? true : false; break; case 'number': return val == 0; break; case 'object': return val == null; break; case 'array': return val.length == 0; break; default: return true; } } /** * 判斷指定值是不是數值 * @method utilsIsNumber * @param string val 目標值 * @return bool bool true,false */ function utilsIsNumber(val) { var reg = /^[\d|\.|,]+$/; return reg.test(val); } /** * 判斷指定值是不是數字整型 * @method utilsIsInt * @param string val 目標值 * @return bool bool true,false */ function utilsIsInt(val) { if (val == "") { return false; } var reg = /\D+/; return !reg.test(val); } /** * 判斷指定值是不是郵箱格式 * @method utilsIsEmail * @param string email 目標郵箱 * @return bool bool true,false */ function utilsIsEmail(email) { var reg = /([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/; return reg.test(email); } /** * 判斷指定值是不是手機號格式 * @method utilsIsMobile * @param string mobile 目標手機號碼 * @return bool bool true,false */ function utilsIsMobile(mobile) { var reg = /^1[2|3|4|5|6|7|8|9][0-9]{9}$/; return reg.test(mobile); } /** * 判斷指定值是不是身份證號格式 * @method utilsIsIdNumber * @param string idnumber 目標身份證號 * @return bool bool true,false */ function utilsIsIdNumber(idnumber) { var reg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/; return reg.test(idnumber); } /** * 判斷指定值是不是銀行卡卡號格式 * @method utilsIsBankCardNumber * @param string bankcardnumber 目標卡號 * @return bool bool true,false */ function utilsIsBankCardNumber(bankcardnumber) { var reg = /^(\d{16}|\d{18}|\d{19})$/; return reg.test(bankcardnumber); } /** * 判斷指定值是不是漢字格式 * @method utilsIsChineseCharacters * @param string str 目標字符 * @return bool bool true,false */ function utilsIsChineseCharacters(str) { var reg = /^([\u4e00-\u9fa5]){2,20}$/; return reg.test(str); } /** * 銀行卡格式輸出,每4個字符進行空格 * @method bankCardNumberFormat * @param string value 目標卡號 * @return string 轉換格式後的卡號 */ function bankCardNumberFormat(value) { var v = value.replace(/\s+/g, '').replace(/[^0-9]/gi, ''); var matches = v.match(/\d{4,19}/g); var match = matches && matches[0] || ''; var parts = []; for (i=0, len=match.length; i<len; i+=4) { parts.push(match.substring(i, i+4)); } if (parts.length) { return parts.join(' '); } else { return value; } } /** * 點擊按鈕觸發秒數倒計時 * @method countDownSecondClickBtn * @param int secondtime 倒計時的描述 * @param string btnId 按鈕的id屬性 * @param string beforeBtnClickStr 按鈕初始話內容 * @param string allowClickClass 容許從新觸發的class * @param string forbidClickClass 禁止從新觸發的class * @return null */ function countDownSecondClickBtn(secondtime, btnId, beforeBtnClickStr, allowClickClass, forbidClickClass ) { var btn = $('#'+btnId); var hander = setInterval(function () { if (time <= 0) { btn.attr("class",allowClickClass); btn.html(beforeClickStr); clearInterval(hander); }else{ btn.attr("class",forbidClickClass); btn.html(time--); } }, 1000); } /** * 判斷是不是微信瀏覽器 * @method isWeixinBrowser * @return bool bool true,false */ function isWeixinBrowser() { var ua = navigator.userAgent.toLowerCase(); if ( ua.indexOf('micromessenger') != -1 ) { return true; }else{ return false; } } /** * 當前頁面刷新 * @method refreshPage * @param int secondtime 倒計時的描述 * @param string btnId 按鈕的id屬性 * @param string beforeBtnClickStr 按鈕初始話內容 * @param string allowClickClass 容許從新觸發的class * @param string forbidClickClass 禁止從新觸發的class * @return null */ function refreshPage() { var cur_url = window.location.href; var url_arr = cur_url.split('?'); if( isWeixinBrowser() ){ //微信內部的瀏覽器刷新 window.location.href = url_arr+"?j="+10000 * Math.random(); }else{ window.location.reload(); } return false; }
// "true" => true 392 // "false" => false 393 // "null" => null 394 // "42" => 42 395 // "42.5" => 42.5 396 // JSON => parse if valid 397 // String => self 398 399 function deserializeValue(value) { 400 var num 401 try { 402 return value ? value == "true" || (value == "false" ? false : value == "null" ? null : !isNaN(num = Number(value)) ? num : /^[\[\{]/.test(value) ? $.parseJSON(value) : value) : value 403 } catch (e) { 404 return value 405 } 406 }
@media only screen and (max-width:640px){html{font-size:100px;}} @media only screen and (max-width:414px){html{font-size:64.6875px;}} @media only screen and (max-width:375px){html{font-size:58.5938px;}} @media only screen and (max-width:360px){html{font-size:56.25px;}} @media only screen and (max-width:320px){html{font-size:50px;}}
/*! normalize.css v4.1.1 | MIT License | github.com/necolas/normalize.css */html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,main,menu,nav,section,summary{display:block} audio,canvas,progress,video{display:inline-block}audio:not([controls]){display:none;height:0}progress{vertical-align:baseline}template,[hidden]{display:none} a{background-color:transparent;-webkit-text-decoration-skip:objects}a:active,a:hover{outline-width:0}abbr[title]{border-bottom:0;text-decoration:underline;text-decoration:underline dotted} b,strong{font-weight:inherit}b,strong{font-weight:bolder}dfn{font-style:italic}h1{font-size:2em;margin:.67em 0}mark{background-color:#ff0;color:#000}small{font-size:80%} sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-0.25em}sup{top:-0.5em}img{border-style:none}svg:not(:root){overflow:hidden} code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}figure{margin:1em 40px}hr{box-sizing:content-box;height:0;overflow:visible}button,input,select,textarea{font:inherit;margin:0} optgroup{font-weight:bold}button,input{overflow:visible}button,select{text-transform:none}button,html [type="button"],[type="reset"],[type="submit"]{-webkit-appearance:button} button::-moz-focus-inner,[type="button"]::-moz-focus-inner,[type="reset"]::-moz-focus-inner,[type="submit"]::-moz-focus-inner{border-style:none;padding:0} button:-moz-focusring,[type="button"]:-moz-focusring,[type="reset"]:-moz-focusring,[type="submit"]:-moz-focusring{outline:1px dotted ButtonText} fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:.35em .625em .75em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal} textarea{overflow:auto}[type="checkbox"],[type="radio"]{box-sizing:border-box;padding:0}[type="number"]::-webkit-inner-spin-button,[type="number"]::-webkit-outer-spin-button{height:auto} [type="search"]{-webkit-appearance:textfield;outline-offset:-2px}[type="search"]::-webkit-search-cancel-button,[type="search"]::-webkit-search-decoration{-webkit-appearance:none} ::-webkit-input-placeholder{color:inherit;opacity:.54}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline}
// 根據屏幕寬度控制字體大小 (function(doc, win) { var docEl = doc.documentElement, resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', recalc = function() { var clientWidth = docEl.clientWidth; if (!clientWidth) return; docEl.style.fontSize = 26 * (clientWidth / 750) + 'px'; }; if (!doc.addEventListener) return; win.addEventListener(resizeEvt, recalc, false); doc.addEventListener('DOMContentLoaded', recalc, false); })(document, window);
//根據瀏覽器的寬自動分配body的字號 var clientWidth; (function (doc, win) { var docEl = doc.documentElement, resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', recalc = function () { // if (docEl.style.fontSize) return; clientWidth = docEl.clientWidth; //alert(clientWidth); clientWidth = clientWidth>750?750:clientWidth; clientWidth = clientWidth<320?320:clientWidth; if (!clientWidth) return; docEl.style.fontSize =100 * (clientWidth / 750) + 'px'; if (document.body) { document.body.style.fontSize = docEl.style.fontSize; } }; recalc(); if (!doc.addEventListener) return; win.addEventListener(resizeEvt, recalc, false); doc.addEventListener('DOMContentLoaded', recalc, false); })(document, window);
(function (doc, win) { //取得html的引用 var docEl = doc.documentElement, resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', recalc = function () { var clientWidth = docEl.clientWidth; if (!clientWidth) return; clientWidth = (clientWidth > 768 ) ? 768 : clientWidth ; docEl.style.fontSize = 100 * (clientWidth / 375 ) + 'px'; }; if (!doc.addEventListener) return; win.addEventListener(resizeEvt, recalc, false); recalc(); })(document, window);
//designWidth:設計稿的實際寬度值,須要根據實際設置 //maxWidth:製做稿的最大寬度值,須要根據實際設置 //這段js的最後面有兩個參數記得要設置,一個爲設計稿實際寬度,一個爲製做稿最大寬度,例如設計稿爲750,最大寬度爲750,則爲(750,750) (function(designWidth, maxWidth) { var doc = document, win = window, docEl = doc.documentElement, remStyle = document.createElement("style"), tid; function refreshRem() { var width = docEl.getBoundingClientRect().width; maxWidth = maxWidth || 540; width>maxWidth && (width=maxWidth); var rem = width * 100 / designWidth; remStyle.innerHTML = 'html{font-size:' + rem + 'px !important;}'; } if (docEl.firstElementChild) { docEl.firstElementChild.appendChild(remStyle); } else { var wrap = doc.createElement("div"); wrap.appendChild(remStyle); doc.write(wrap.innerHTML); wrap = null; } //要等 wiewport 設置好後才能執行 refreshRem,否則 refreshRem 會執行2次; refreshRem(); win.addEventListener("resize", function() { clearTimeout(tid); //防止執行兩次 tid = setTimeout(refreshRem, 300); }, false); win.addEventListener("pageshow", function(e) { if (e.persisted) { // 瀏覽器後退的時候從新計算 clearTimeout(tid); tid = setTimeout(refreshRem, 300); } }, false); if (doc.readyState === "complete") { doc.body.style.fontSize = "16px"; } else { doc.addEventListener("DOMContentLoaded", function(e) { doc.body.style.fontSize = "16px"; }, false); } })(750, 750);
(function(){ var newFont = function(){ // alert(window.innerWidth); var win = window.innerWidth > 640 ? 640 : window.innerWidth; var num = win/320; document.documentElement.style.fontSize = 16*num+'px'; } newFont(); window.onresize = newFont; window.jsAct = ''; var pressX = 0, pressY = 0; document.addEventListener('touchmove',function(e){ if (e.targetTouches.length == 1) { var touch = event.targetTouches[0]; var spanY = touch.pageY - pressY; // alert(spanY); if (spanY > 0 && document.body.scrollTop <= 0) { e.preventDefault(); // location.reload(); return false; } } }); document.addEventListener('touchstart', function(event) { // 若是這個元素的位置內只有一個手指的話 if (event.targetTouches.length == 1) { var touch = event.targetTouches[0]; // 把元素放在手指所在的位置 pressX = touch.pageX; pressY = touch.pageY; // touchStart.value = pressX + ';' + pressY; } }, false); })();
(function flexible (window, document) { var docEl = document.documentElement var dpr = window.devicePixelRatio || 1 // adjust body font size function setBodyFontSize () { if (document.body) { document.body.style.fontSize = '16px' } else { document.addEventListener('DOMContentLoaded', setBodyFontSize) } } setBodyFontSize() // set 1rem = viewWidth / 10 function setRemUnit () { var rem = docEl.clientWidth / 10 docEl.style.fontSize = rem + 'px' } setRemUnit() // reset rem unit on page resize window.addEventListener('resize', setRemUnit) window.addEventListener('pageshow', function (e) { if (e.persisted) { setRemUnit() } }) // detect 0.5px supports if (dpr >= 2) { var fakeBody = document.createElement('body') var testElement = document.createElement('div') testElement.style.border = '.5px solid transparent' fakeBody.appendChild(testElement) docEl.appendChild(fakeBody) if (testElement.offsetHeight === 1) { docEl.classList.add('hairlines') } docEl.removeChild(fakeBody) } }(window, document))
(function($) { /** * 對Jquery擴展方法 */ $.extend(jQuery,{ /** * 從c參數中複製全部配置屬性到o參數中 * * @param o 被複制的對象 * @param c 要複製的對象 * @param defaults 若是存在不一樣對象是,將該對象也複製到o參數中 */ apply:function(o, c, defaults) { if(defaults){ $.apply(o, defaults); } if(o && c && typeof c === 'object'){ for(var p in c){ o[p] = c[p]; } } return o; }, /** * 若是o參數對象沒有該屬性時,從c參數中複製全部配置屬性到o參數中。 * * @param o 被複制的對象 * @param c 要複製的對象 */ applyIf:function(o, c){ if(o){ for(var p in c){ if(!$.isDefined(o[p])){ o[p] = c[p]; } } } return o; }, /** * 在一個數組中遍歷調用方法,返回調用方法後的新數組, * <pre> * $.invoke(Ext.query("p"), "getAttribute", "id"); * 返回 [el1.getAttribute("id"), el2.getAttribute("id"), ..., elN.getAttribute("id")] * </pre> * * @param arr 待調用方法的數組 * @param methodName 要執行的方法名稱 */ invoke : function(arr, methodName){ var ret = [], args = Array.prototype.slice.call(arguments, 2); $.each(arr, function(i,v) { if (v && typeof v[methodName] == 'function') { ret.push(v[methodName].apply(v, args)); } else { ret.push(undefined); } }); return ret; }, escapeRe : function(s) { return s.replace(/([-.*+?^${}()|[\]\/\\])/g, "\\$1"); }, /** * 重寫某個類,當方法名相同時候會覆蓋當前類的方法,當方法名不存在時,將會添加到類中,屬性也同樣 * * <pre> * $.override(MyClass, { * newMethod1: function(){ * // etc. * }, * newMethod2: function(foo){ * // etc. * } * }); * </pre> * * @param origclass 要重寫的類 * @param overrides 重寫方法或者屬性的對象 */ override : function(origclass, overrides){ if(overrides){ var p = origclass.prototype; $.apply(p, overrides); if(overrides.hasOwnProperty('toString')){ p.toString = overrides.toString; } } }, /** * 判斷一個值或對象是否爲空 * * @param v 要判斷的值 * @param allowBlank true 爲容許字符串爲''值 */ isEmpty: function(v, allowBlank){ return v === null || v === undefined || (($.isArray(v) && !v.length)) || (!allowBlank ? v === '' : false); }, /** * 判斷一個值或對象是否不爲空 * * @param v 要判斷的值 * @param allowBlank true 爲容許字符串爲''值 */ isNotEmpty : function(v, allowBlank){ return !$.isEmpty(v, allowBlank); }, /** * 判斷一個值是否日期類(Date)型 * * @param v 要判斷的值 */ isDate : function(v){ return toString.apply(v) === '[object Date]'; }, /** * 判斷一個值是否對象([object:object])類型 * * @param v 要判斷的值 */ isObject : function(v){ return !!v && Object.prototype.toString.call(v) === '[object Object]'; }, /** * 判斷一個值是否String類型 * * @param v 要判斷的值 */ isString : function(v){ return typeof v === 'string'; }, /** * 判斷一個值是否Boolean類型 * * @param v 要判斷的值 */ isBoolean : function(v) { return typeof v === 'boolean'; }, /** * 判斷一個值是否HTML元素 * * @param v 要判斷的值 */ isElement : function(v) { return v ? !!v.tagName : false; }, /** * 判斷一個值是否已經定義 * * @param v 要判斷的值 */ isDefined : function(v){ return typeof v !== 'undefined'; }, /** * 判斷一個HTML是否爲隱藏狀態 * * @param v 要判斷的值 */ isHide:function(el){ return $(el).css("display") === "none" || $(el).css("visibility") === "hidden"; }, /** * 判斷一個值是不是整型,若是是返回當前值,若是不是返回defaultValue參數的值 * * @param v 要判斷的值 * @param defaultValue 若是不是整型將要返回的值, * @param replaceStr 要刪除某些String類型的字符 */ number:function(v,defaultValue,replaceStr){ if (v == "auto") { v = 0; } if ($.isString(v) && v.length > 0) { v = v.replaces(replaceStr,"").replace(" ",""); } if ($.isEmpty(v) || $.isArray(v) || $.isBoolean(v)) { v = NaN; } v = Number(v); return isNaN(v) ? defaultValue : v; }, /** * 若是v參數值爲空,返回defaultValue參數值。 * * @param v 值 * @param defaultValue 若是值爲空將要返回的值 * @param allowBlank true表示容許值爲''值 */ value : function(v, defaultValue, allowBlank){ return $.isEmpty(v, allowBlank) ? defaultValue : v; }, /** * 若是value參數值超過指定長度,截斷字符串並添加一個省略號("…")到結束的位置中 * * <pre> * $.ellipsis("123456789",5) * 返回:12345... * </pre> * * @param value 值 * @param len 要截取的長度 * @param word 省略字符,默認爲... * * @return String */ ellipsis : function(value, len, word) { if (value && value.length > len) { if (word) { var vs = value.substr(0, len - 2), index = Math.max(vs.lastIndexOf(' '), vs.lastIndexOf('.'), vs.lastIndexOf('!'), vs.lastIndexOf('?')); if (index == -1 || index < (len - 15)) { return value.substr(0, len - 3) + "..."; } else { return vs.substr(0, index) + "..."; } } else { return value.substr(0, len - 3) + "..."; } } return value; }, /** * 將json符串轉換爲json 對象 * * @param json json 字符串 * @param useNative 是否使用瀏覽器常規的轉換方式,true表示是,false表示不是,默認爲:false * * @returns Object */ parseJSON:function(json,useNative) { if ($.isObject(json)) { return json; } if (useNative) { return JSON.parse(json); } return eval("(" + json + ')'); }, /** * 空方法 */ emptyFn:function () {} }); /** * 對JS Function類擴展 */ $.applyIf(Function.prototype, { /** * 對某個參數建立一個攔截器方法,若是攔截器方法返回false時,將不會調用要執行的方法,若是返回true時調用要執行的方法 * <pre> * var sayHi = function(name){ * alert('Hi, ' + name); * } * * sayHi('Fred'); // alerts "Hi, Fred" * * // 建立攔截器 * // 若是name==Brian後在執行sayHi方法 * var sayHiToFriend = sayHi.createInterceptor(function(name){ * return name == 'Brian'; * }); * * sayHiToFriend('Fred'); // no alert * sayHiToFriend('Brian'); alerts "Hi, Brian" * </pre> * * @param fcn 攔截器方法 * @param scope 攔截器方法的做用域 */ createInterceptor : function(fcn, scope){ var method = this; return !$.isFunction(fcn) ? this : function() { var me = this, args = arguments; fcn.target = me; fcn.method = method; return (fcn.apply(scope || $ , args) !== false) ? method.apply(me, args) : null; }; }, /** * 經過arguments[0], arguments[1], arguments[2],建立一個callback方法來將參數傳遞到要執行的方法中 * * <pre> * var sayHi = function(name){ * alert('Hi, ' + name); * } * * * sayHi.createCallback('Fred') //alerts "Hi, Fred" * </pre> */ createCallback : function(){ var args = arguments, method = this; return function() { return method.apply($, args); }; }, /** * 建立一個委託回調,將obj做爲當前方法的做用域去執行方法體裏的代碼,能夠經過args參數來對該方法的要接受的參數進行傳遞 * * <pre> * var sayHi = function(name){ * alert('Hi, ' + name); * } * * * sayHi.createDelegate(window,["Fred"]) //alerts "Hi, Fred" * </pre> * * @param obj 做用域 * @param args 傳遞的參數 * @param appendArgs 若是爲true args參數將不會覆蓋原有方法的參數值 */ createDelegate : function(obj, args, appendArgs){ var method = this,slice = Array.prototype.slice; return function() { var callArgs = args || arguments; if (appendArgs === true){ callArgs = slice.call(arguments, 0); callArgs = callArgs.concat(args); }else if ($.isNumeric(appendArgs)){ callArgs = slice.call(arguments, 0); var applyArgs = [appendArgs, 0].concat(args); slice.apply(callArgs, applyArgs); } return method.apply(obj || $, callArgs); }; }, /** * 相似setTimeout方法,該方法執行時間的同時,能夠把方法的做用域以及參數傳遞的方法體中 * * <pre> * var sayHi = function(name){ * alert('Hi, ' + name); * } * * // 執行方法: * sayHi('Fred'); * * // 兩秒中後執行方法: * sayHi.defer(2000, this, ['Fred']); * </pre> * * @param millis 等待多用毫秒執行該方法 * @param obj 做用域 * @param args 要傳遞的參數 * @param appendArgs 若是爲true args參數將不會覆蓋原有方法的參數值 * */ defer : function(millis, obj, args, appendArgs){ var fn = this.createDelegate(obj, args, appendArgs); if(millis > 0){ return setTimeout(fn, millis); } fn(); return 0; } }); /** * 重寫String類屬性 */ $.applyIf(String.prototype, { /** * 去除空格 * @returns string */ trim : function () { return this.replace(/(^\s*)|(\s*$)/g, ""); }, /** * 經過佔位符格式化字符串 * <pre> * "1{0}3{1}5".messageFormat("2","4"); * 返回:12345 * </pre> * */ messageFormat : function(){ var args = []; for(var i = 0 ; i < arguments.length ; i++){ args.push(arguments[i]); } return this.replace(/\{(\d+)\}/g, function(m, i){ return args[i]; }); }, /** * * 經過字符串數組替換字符串,返回替換後的字符串, * * @param array 替換字符串數組 * @param arg 要替換的值 * * @return String **/ replaces:function(array,arg) { var temp = this.toString(); if ($.isNotEmpty(array) && $.isArray(array)) { for (var i = 0; i < array.length; i++) { var str = array[i]; if ($.isString(str)) { temp = temp.replace(array[i],arg); } } } return temp; }, /** * 若是value等於當前值,返回當前值,反則返回other參數的值 */ toggle:function(value, other){ return this.toString() == value ? other : value; }, /** * 若是當前值的長度小於size參數的長度是,將當前值從左邊開始補位. * * <pre> * "123".leftPad(5,"00"); * 返回:"00123" * </pre> * * @param size 要判斷的長度 * @param ch 要不爲的字符 */ leftPad : function (size, ch) { var val = this.toString(); var result = String(val); if(!ch) { ch = " "; } while (result.length < size) { result = ch + result; } return result; }, /** * 若是當前值超過指定長度,截斷字符串並添加一個省略號("…")到結束的位置中 * * <pre> * "123456789".ellipsis(5) * 返回:12345... * </pre> * * @param len 要截取的長度 * @param word 省略號,默認爲 "..." */ ellipsis:function(len, word){ return $.ellipsis(this.toString(),len,word); }, /** * 將當前值轉換爲boolean類型 * * <pre> * "1".booleanValue() 返回:true * "0".booleanValue() 返回false * "true".booleanValue() 返回 true * "false".booleanValue() 返回 false * "abc".booleanValue("abc") 返回 true * "abc".booleanValue("aaa") 返回 false * </pre> * * @param compareValue 自定義比對值 */ booleanValue:function(compareValue){ var value = this.toString(); return $.isNotEmpty(value) && (value === "true" || value === "1" || ($.isNotEmpty(compareValue) || value == compareValue)); }, /** * 將當前值轉換爲數字類型 * * @returns number */ numberValue:function() { var value = this.toString(); return $.isNotEmpty(value) ? value * 1 : value; } }); /** * 重寫 Date 對象, 添加 format 函數 */ $.applyIf(Date.prototype,{ /** * * 格式化日誌 * * @param format 格式化字符串 * * @returns string */ format : function (format) { //author: meizz var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小時 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 }; if (/(y+)/.test(format)) format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(format)) format = format.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return format; } }); /** * 擴張數組屬性 */ $.applyIf(Array.prototype, { /** * 在當前數組中遍歷尋找o對象,若是相等返回當前所在數組的未知,返回返回-1 * * @o 要遍歷尋找的對象 * @from 從第幾位開始遍歷 */ indexOf : function(o, from){ var len = this.length; from = from || 0; from += (from < 0) ? len : 0; for (; from < len; ++from){ if(this[from] === o){ return from; } } return -1; }, /** * 從當前數組中刪除對象 * * @param o 要刪除的對象 */ remove : function(o){ var index = this.indexOf(o); if(index != -1){ this.splice(index, 1); } return this; }, /** * 將數組添加到本數組中 * * @param o 數組 */ addAll:function(o) { if ($.isEmpty(o) && !$.isArray(o) && o.length < 0) { return ; } for(var i = 0; i < o.length; i++) { this.push(o[i]); } } });
if (!NeuF) var NeuF = {}; NeuF.ScrollPage = function (obj, options, callback) { var _defaultOptions = { delay: 500, marginBottom: 100 }; //默認配置:延遲時間delay和滾動條距離底部距離marginBottom options = $.extend(_defaultOptions, options); this.isScrolling = false; //是否在滾動 this.oriPos = 0; //原始位置 this.curPos = 0; //當前位置 var me = this; //頂層 var $obj = (typeof obj == "string") ? $("#" + obj) : $(obj); //綁定滾動事件 $obj.scroll(function (ev) { me.curPos = $obj.scrollTop(); if ($(window).height() + $(window).scrollTop() >= $(document.body).height() - options.marginBottom) { if (me.isScrolling == true) return; me.isScrolling = true; setTimeout(function () { me.isScrolling = false; }, options.delay); //重複觸發間隔毫秒 if (typeof callback == "function") callback.call(null, me.curPos - me.oriPos); }; me.oriPos = me.curPos; }); };
下載通用代碼js:
downloadFile(filePath: any) { this.meetingService.downloadFile(filePath, rtv => { if (rtv) { let _blob = new Blob([rtv]); let _filename = filePath.substring(filePath.lastIndexOf('_') + 1); if (window.navigator && window.navigator.msSaveOrOpenBlob) { window.navigator.msSaveOrOpenBlob(_blob, _filename); } else { let _link = document.createElement('a'); let _url = window.URL.createObjectURL(_blob); document.body.appendChild(_link); _link.setAttribute('style', 'display:none'); _link.href = _url; _link.download = _filename; _link.click(); window.URL.revokeObjectURL(_url); _link.remove(); } } else { alert('下載失敗,請稍後重試!'); } }); }