1 2var utils= 3{ 4debug:false 5} 6 7utils.array= 8{ 9 10inArray:function(needle,array) 11{ 12 for(var i in array) 13{ 14if(array[i]==needle)return true} 15 return false} 16} 17 18utils.cookies= 19{ 20 21isEnabled:function() 22{ 23 var cookiesEnabled=!!(navigator.cookieEnabled); 24 if(typeof navigator.cookieEnabled=='undefined'&&!cookiesEnabled) 25{ 26 document.cookie='testcookie'; 27cookiesEnabled=($.inArray('testcookie',document.cookie)!=-1)} 28 return cookiesEnabled}, 29 30readCookie:function(name) 31{ 32 var cookies=document.cookie.split(';'); 33name=name+'='; 34for(var i=0;i<cookies.length;i++) 35{ 36var cookie=cookies[i]; 37while(cookie.charAt(0)==' ')cookie=cookie.substring(1,cookie.length); 38if(cookie.indexOf(name)==0)return cookie.substring(name.length,cookie.length)} 39 return null}, 40setCookie:function(name,value,days) 41{ 42if(typeof days=='undefined')days=7; 43var expireDate=new Date(); 44expireDate.setDate(expireDate.getDate()+days); 45document.cookie=name+'='+escape(value)+';expires='+expireDate.toUTCString()+';path=/'} 46} 47 48utils.form= 49{ 50 51isChecked:function(element) 52{ 53return($('input[name="'+element.attr('name')+'"]:checked').length>=1)}, 54 55isEmail:function(element) 56{ 57var regexp=/^[a-z0-9!#\$%&'*+-\/=?^_`{|}\.~]+@([a-z0-9]+([\-]+[a-z0-9]+)*\.)+[a-z]{2,7}$/i; 58 return regexp.test(element.val()); 59 }, 60 61 /** 62 * Is the element filled 63 * 64 * @return bool 65 * @param object element 66 */ 67 isFilled: function(element) 68 { 69 return (utils.string.trim(element.val()) != ''); 70 }, 71 72 /** 73 * Is the value inside the element a valid number 74 * 75 * @return bool 76 * @param object element 77 */ 78 isNumber: function(element) 79 { 80 return (!isNaN(element.val()) && element.val() != ''); 81 }, 82 83 /** 84 * Is the value inside the element a valid URL 85 * 86 * @return bool 87 * @param object element 88 */ 89 isURL: function(element) 90 { 91 var regexp = /^((http|ftp|https):\/{2})?(([0-9a-zA-Z_-]+\.)+[0-9a-zA-Z]+)((:[0-9]+)?)((\/([~0-9a-zA-Z\#%@\.\/_-]+)?(\?[0-9a-zA-Z%@\/&=_-]+)?)?)$/i; 92 return regexp.test(element.val()); 93 } 94} 95 96/** 97 * Functions related to strings 98 * 99 * @author Tijs Verkoyen <[email protected]> 100 * @author Dieter Vanden Eynde <[email protected]> 101 * @author Matthias Mullie <[email protected]> 102 */ 103utils.string = 104{ 105 // data member 106 div: false, 107 108 /** 109 * Fix a HTML5-chunk, so IE can render it 110 * 111 * @return string 112 * @param string html 113 */ 114 html5: function(html) 115 { 116 var html5 = 'abbr article aside audio canvas datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video'.split(' '); 117 118 // create div if needed 119 if(utils.string.div === false) 120 { 121 utils.string.div = document.createElement('div'); 122 123 utils.string.div.innerHTML = '<nav></nav>'; 124 125 if(utils.string.div.childNodes.length !== 1) 126 { 127 var fragment = document.createDocumentFragment(); 128 var i = html5.length; 129 while(i--) fragment.createElement(html5[i]); 130 131 fragment.appendChild(utils.string.div); 132 } 133 } 134 135 html = html.replace(/^\s\s*/, '').replace(/\s\s*$/, '') 136 .replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, ''); 137 138 // fix for when in a table 139 var inTable = html.match(/^<(tbody|tr|td|th|col|colgroup|thead|tfoot)[\s\/>]/i); 140 141 if(inTable) utils.string.div.innerHTML = '<table>' + html + '</table>'; 142 else utils.string.div.innerHTML = html; 143 144 var scope; 145 if(inTable) scope = utils.string.div.getElementsByTagName(inTable[1])[0].parentNode; 146 else scope = utils.string.div; 147 148 var returnedFragment = document.createDocumentFragment(); 149 var i = scope.childNodes.length; 150 while(i--) returnedFragment.appendChild(scope.firstChild); 151 152 return returnedFragment; 153 }, 154 155 /** 156 * Encode the string as HTML 157 * 158 * @return string 159 * @param string value 160 */ 161 htmlEncode: function(value) 162 { 163 return $('<div/>').text(value).html(); 164 }, 165 166 /** 167 * Decode the string as HTML 168 * 169 * @return string 170 * @param string value 171 */ 172 htmlDecode: function(value) 173 { 174 return $('<div/>').html(value).text(); 175 }, 176 177 /** 178 * Replace all occurences of one string into a string 179 * 180 * @return string 181 * @param string value 182 * @param string needle 183 * @param string replacement 184 */ 185 replaceAll: function(value, needle, replacement) 186 { 187 if(value == undefined) return ''; 188 return value.replace(new RegExp(needle, 'g'), replacement); 189 }, 190 191 /** 192 * Sprintf replaces all arguments that occur in the string (%1$s, %2$s, ...) 193 * 194 * @return string 195 * @param string value 196 * @params string arguments 197 */ 198 sprintf: function(value) 199 { 200 if(arguments.length < 2) return value; 201 else 202 { 203 // replace $ symbol first, because our RegExp won't except this symbol 204value=value.replace(/\$s/g,'Ss'); 205 for(var i=1;i<arguments.length;i++) 206{ 207value=utils.string.replaceAll(value,'%'+i+'Ss',arguments[i])} 208} 209return value}, 210 211stripTags:function(value) 212{ 213return value.replace(/<[^>]*>/ig,'')}, 214 215trim:function(value,charList) 216{
217if(value==undefined)return ''; 218if(charList==undefined)charList=' '; 219var pattern=new RegExp('^['+charList+']*|['+charList+']*$','g'); 220return value.replace(pattern,'')}, 221 222urlEncode:function(value) 223{ 224return encodeURIComponent(value).replace(/\%20/g,'+').replace(/!/g,'%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/\~/g, '%7E'); 225 }, 226 227 /** 228 * PHP-like urlencode 229 * 230 * @see https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/encodeURIComponent#Description 231 * @return string 232 * @param string value 233 */ 234 urlDecode: function(value) 235 { 236 return decodeURIComponent(value.replace(/\+/g, '%20').replace(/\%21/g, '!').replace(/\%27/g, "'").replace(/\%28/g, '(').replace(/\%29/g, ')').replace(/\%2A/g, '*').replace(/\%7E/g, '~')); 237 }, 238 239 /** 240 * Urlise a string (cfr. SpoonFilter::urlise) 241 * 242 * @return string 243 * @param string value 244 */ 245 urlise: function(value) 246 { 247 // reserved characters (RFC 3986) 248 reservedCharacters = new Array( 249 '/', '?', ':', '@', '#', '[', ']', 250 '!', '$', '&', '\'', '(', ')', '*', 251 '+', ',', ';', '=' 252 ); 253 254 // remove reserved characters 255 for(i in reservedCharacters) value = value.replace(reservedCharacters[i], ' '); 256 257 // replace double quote, since this one might cause problems in html (e.g. <a href="double"quote">) 258value=utils.string.replaceAll(value,'"',' '); 259 value=utils.string.replaceAll(value,' ','-'); 260 if(utils.string.urlDecode(value)==value) 261{ 262 value=value.toLowerCase(); 263 value=utils.string.urlEncode(value)} 264 value=value.replace(/-+/,'-'); 265 return utils.string.trim(value,'-')}, 266 267ucfirst:function(value) 268{ 269return value.charAt(0).toUpperCase()+value.slice(1)}, 270 271xhtml:function(value) 272{ 273 value=value.replace(/<br>/g,'<br />'); 274value=value.replace(/<br?\/?>$/g,''); 275value=value.replace(/^<br?\/?>/g,''); 276 value=value.replace(/(<img[^>]+[^\/])>/gi,'$1 />'); 277 value=value.replace(/(<input[^>]+[^\/])>/gi,'$1 />'); 278 value=value.replace(/<b\b[^>]*>(.*?)<\/b[^>]*>/g,'<strong>$1</strong>'); 279value=value.replace(/<i\b[^>]*>(.*?)<\/i[^>]*>/g,'<em>$1</em>'); 280value=value.replace(/<u\b[^>]*>(.*?)<\/u[^>]*>/g,'<span style="text-decoration:underline">$1</span>'); 281 return value} 282} 283 284utils.url= 285{ 286extractParamFromUri:function(uri,paramName) 287{ 288if(!uri)return; 289var uri=uri.split('#')[0]; 290var parts=uri.split('?'); 291if(parts.length==1)return; 292var query=decodeURI(parts[1]); 293paramName+='='; 294var params=query.split('&'); 295for(var i=0,param;param=params[i];++i) 296{ 297if(param.indexOf(paramName)===0)return unescape(param.split('=')[1])} 298}, 299 300getGetValue:function(name) 301{ 302 var getValue=''; 303 var hashes=window.location.search.slice(window.location.search.indexOf('?')+1).split('&'); 304 $.each(hashes,function(index,value) 305{ 306 var chunks=value.split('='); 307 if(chunks[0]==name) 308{ 309 getValue=chunks[1]; 310 return false} 311}); 312 return getValue} 313}
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.