1/** 2 * æ¤æä»¶ç头鍿³¨é 3 */ 4 5/*global jQuery: false, window: false */ 6 7(function ($) { 8 'use strict'; 9 10 var pe, 11 tools; 12 13 pe = window.pe = {}; 14 15 tools = { 16 /** 17 * 夿è¦å ç龿¥ç¬¦æ¯?è¿æ¯& 18 * @param {} url 19 * @returns {} 20 */ 21 connect: function (url) { 22 var connect = "?"; 23 if (url.indexOf("?") > -1) { 24 connect = "&"; 25 } 26 return connect; 27 }, 28 /** 29 * ä¸åçæµè§å¨åå²hashç 30 * @param {} url 31 * @returns {} 32 */ 33 diffBrowserSplitHash: function (hash) { 34 var hashStr = ""; 35 if (hash.indexOf("#/") > -1) { 36 hashStr = hash.split("#/")[1]; 37 } else if (hash.indexOf("##") > -1) { 38 hashStr = hash.split("##")[1]; 39 } 40 return hashStr; 41 }, 42 /** 43 * ç¹æ®å¤çstateåæ° 44 45 * @param {} url 46 * @returns {} 47 */ 48 FilterStateSpecialChar: function (stateParam) { 49 if (stateParam.substring(0, 1) === "/") { 50 return stateParam.substring(1); 51 } 52 53 return stateParam; 54 }, 55 /** 56 * åå¹¶Urlçåæ°ã 57 * @param {string} url è¦åå¹¶åæ°çUrl 58 * @param {Object<string,object>} param åæ° ï¼ä½¿ç¨é®å¼å¯¹å¯¹è±¡ã 59 * @returns {string} å并宿åçjs 60 */ 61 connectUrl: function (url, param) { 62 var querystring = url.split('?')[1] || ''; 63 var params = []; 64 if (querystring) { 65 params = querystring.split('&'); 66 } 67 68 if (param) { 69 for (var item in param) { 70 if (param.hasOwnProperty(item)) { 71 params.push(item + '=' + param[item]); 72 } 73 } 74 } 75 76 return url.split('?')[0] + '?' + params.join('&'); 77 }, 78 79 /** 80 * çæä¸ç»éæºçIdå·ç 81 * @param len é¿åº¦ 82 * @param radix åæ° 83 * @returns {string} idå·ç 84 */ 85 uuid: function (len, radix) { 86 len = len || 8; 87 radix = radix || 2; 88 var CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' 89 .split(''); // UNDONE [2014-4-17] [] åéå°åå½åãè¿é为ä»ä¹è¦æCHARSåéèµå¼ç»charsï¼èä¸ç´æ¥ç¨CHARSã 90 var chars = CHARS, 91 uuid = [], 92 i; 93 radix = radix || chars.length; 94 if (len) { 95 for (i = 0; i < len; i++) { 96 uuid[i] = chars[0 | Math.random() * radix]; 97 } 98 } else { 99 var r; 100 uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; 101 uuid[14] = '4'; 102 for (i = 0; i < 36; i++) { 103 if (!uuid[i]) { 104 r = 0 | Math.random() * 16; 105 uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r]; 106 } 107 } 108 } 109 return uuid.join(''); 110 }, 111 errorResultHandler: { 112 'NotAuthenticated': function (result) { 113 window.top.location.href = result.LogOnUrl; 114 115 return ''; 116 }, 117 118 'NotAuthorized': function (result) { 119 return 'æ¨æ²¡ææéæ¥çæè¯·æ±çå 容'; 120 } 121 122 }, 123 RegexHelper: { 124 Url: /(http:\/)?\/[^\/]+/ 125 126 }, 127 /** 128 * è£åªå符串 129 * @param str {string} è¦åªè£çå符串 130 * @param n {Number} åªè£çé¿åº¦ 131 * @returns {string} åªè£å¥½çå符串ã 132 */ 133 truncateStr: function (str, n) { // UNDONE [2014-4-17] [] 彿°å½åä¸è¦ä½¿ç¨ç®åï¼åéå½åé®é¢ï¼åéç»ä¸å¨ä»£ç åå¼å¤´å½åï¼è¿æ¯å°±è¿å½åï¼åéiï¼ï¼ 134 var r = /[^\x00-\xff]/g; 135 var i; 136 if (str.replace(r, 'mm').length <= n) { 137 return str; 138 } 139 // n = n - 3; 140 var m = Math.floor(n / 2); 141 for (i = m; i < str.length; i++) { 142 if (str.substr(0, i).replace(r, 'mm').length >= n) { 143 return str.substr(0, i) + '...'; 144 } 145 } 146 147 return str; 148 }, 149 HTMLEncode: function (text) { 150 return $('<div/>').text(text).html(); 151 }, 152 HTMLDecode: function (text) { 153 return $('<div/>').html(text).text(); 154 }, 155 /* 156 * ç»urlå¢å å½åçhashå¼ 157 * @param url {string} è¦å¢å hashå¼çurl 158 * @return {string} å¢å äºhashå¼å¾url 159 */ 160 AddCurrentHash: function (url) { 161 if (!!url) { 162 var hash = 'state=' + window.location.hash.replace(/^#*/, ''); 163 hash = hash.replace("%20", "+"); 164 url += (/\?/.test(url) ? '&' : '?') + hash; 165 } 166 return url; 167 }, 168 169 /** 170 * è·¯å¾æä½å©æã 171 */ 172 PathHelperUtils: { 173 /** 174 * è·¯å¾ä¸ä¼ ç®å½æ¿æ¢ç¬¦è½¬æ¢ä¸ºä¸ä¼ ç®å½ï¼ å¤çå ¼å®¹æ åµã 175 * @param {string} path åè·¯å¾ã 176 * @param {string} symbol 177 * @param {string} uploadDirectory 178 * @return {string} è¿åç»æã 179 */ 180 ReplacePathSymbolForShow: function (path, symbol, uploadDirectory) { 181 if (!path) { 182 return ""; 183 } 184 185 symbol = symbol || "$/"; 186 uploadDirectory = uploadDirectory || "/upload/"; 187 path = path.TrimStartReplace("~"); 188 uploadDirectory = uploadDirectory.TrimStartReplace("~"); 189
190 if (path.indexOf(symbol) == 0) { 191 path = path.replace(symbol, uploadDirectory); 192 } 193 194 if (path.toLowerCase().indexOf(uploadDirectory.toLowerCase()) == 0) { 195 //// ä¸ä¼ ç®å½åç¼ï¼é»è®¤æ¯ç©ºå符串ã 196 var uploadPathPrefix = ''; 197 path = uploadPathPrefix + path.toLowerCase(); 198 } 199 200 return path; 201 }, 202 /** 203 * è·¯å¾ä¸ä¼ ç®å½æ¿æ¢ç¬¦è½¬æ¢ä¸ºä¸ä¼ ç®å½ï¼ å¤çå ¼å®¹æ åµã 204 * @param {string} path åè·¯å¾ã 205 * @param {string} symbol ä¸ä¼ ç®å½æ¿æ¢ç¬¦ã 206 * @param {string} uploadVirtualPath ä¸ä¼ èæè·¯å¾ã 207 * @param {object} regExp æ£å表达å¼RegExp对象ï¼å¦æä¼ å ¥å使ç¨ä¼ å ¥çï¼å¦å使ç¨å 鍿£å表达å¼çã 208 * @return {string} è¿åç»æã 209 */ 210 ReplaceContentSymbolForShow: function (path, symbol, uploadVirtualPath, regExp) { 211 var regexString = "((src|href)\\s*=\\s*(\"|\'))\\$?\\/(\\/|\\w|\\.|\\{|\\})*"; 212 if (path && symbol && uploadVirtualPath) { 213 path = path.TrimStartReplace("~"); 214 uploadVirtualPath = uploadVirtualPath.TrimStartReplace("~"); 215 216 if (!regExp) { 217 regExp = new RegExp(regexString, 'gi'); 218 } 219 220 path = path.replace(regExp, function (match, p1) { 221 var value = match; 222 if (match && p1 && match.indexOf(p1) == 0) { 223 var attributeValue = match.substring(p1.length); 224 attributeValue = attributeValue.ReplacePathSymbolForShow(symbol, uploadVirtualPath); 225 value = p1.concat(attributeValue); 226 } 227 228 return value; 229 }); 230 } 231 232 return path; 233 }, 234 TrimStartReplace: function (orignal, target) { 235 if (orignal && target && orignal.length >= target.length) { 236 while (orignal && orignal.indexOf(target) == 0) { 237 orignal = orignal.substring(target.length); 238 } 239 } 240 241 return orignal; 242 } 243 }, 244 EncryptBase64ForJs: function (original) { return window.btoa(window.encodeURIComponent(original)); }, 245 DecryptBase64ForJs: function (value) { return window.decodeURIComponent(window.atob(value)); } 246 }; 247 248 pe.tools = tools; 249 250 //object .create 251 if (typeof Object.create !== 'function') { 252 Object.create = function (o) { 253 var f = function () {}; 254 f.prototype = o; 255 256 return new f(); 257 }; 258 } 259 260 //Function method 261 262 if (typeof Function.method !== 'function') { 263 Function.prototype.method = function (name, func) { 264 this.prototype[name] = func; 265 return this; 266 }; 267 } 268 269 /** 270 * æ¿æ¢è·¯å¾ä¸çä¸ä¼ å ä½ç¬¦ã 271 * @param {string} symbol ç®å½æ¿æ¢ç¬¦ã 272 * @param {any} uploadDirectory ä¸ä¼ èæç®å½è·¯å¾ã 273 * @return {string} ç»æã 274 */ 275 String.prototype.ReplacePathSymbolForShow = function (symbol, uploadDirectory) { 276 var path = this; 277 return pe.tools.PathHelperUtils.ReplacePathSymbolForShow(path, symbol, uploadDirectory); 278 }; 279 280 /** 281 * æ¿æ¢å 容ä¸çä¸ä¼ ç«ä½ç¬¦ã 282 * @param {string} symbol ç®å½æ¿æ¢ç¬¦ã 283 * @param {string} uploadpath ä¸ä¼ èæç®å½è·¯å¾ã 284 * @param {object} regExp èªå®ä¹æ£åãå¦æä¼ å ¥å使ç¨ä¼ å ¥çï¼å¦ææ²¡æå使ç¨é»è®¤çã 285 * @return {string} ç»æã 286 */ 287 String.prototype.ReplaceContentSymbolForShow = function (symbol, uploadpath, regExp) { 288 var content = this; 289 return pe.tools.PathHelperUtils.ReplaceContentSymbolForShow(content, symbol, uploadpath, regExp); 290 }; 291 292 String.prototype.TrimStartReplace = function (target) { 293 var orignal = this; 294 return pe.tools.PathHelperUtils.TrimStartReplace(orignal, target); 295 }; 296}(jQuery));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.