1/* 2 * (C) 2002-2014 ITC Internet-Trade-Center AG 3 * All rights reserved. 4 */ 5 6/** 7 * Escape "." and ":" in ids to that they can be used in jQuery selectors. 8 */ 9function jq(myid) 10{ 11 return '#' + myid.replace(/(:|\.)/g, '\\$1'); 12} 13 14/** 15 * Locale variable that indicates if a form is already submitted 16 */ 17var submitted = false; 18 19/** 20 * Check if a from have to be submitted. A form can only submitted once until the response is received. This function 21 * only works for button tags. 22 * 23 * @return <code>true</code> if the form have to be submitted, otherwise <code>false</code> 24 */ 25function submitFormRequired(elementId) 26{ 27 if (!submitted) 28 { 29 submitted = true; 30 return true; 31 } 32 var button = jQuery('#' + elementId); 33 var newButton = button.clone(); 34 var buttonId = button.attr('id'); 35 36 newButton.attr('type', 'button'); 37 newButton.attr('id', buttonId + 'new'); 38 newButton.insertBefore(button); 39 button.remove(); 40 newButton.attr('id', buttonId); 41 42 return false; 43} 44 45/** 46 * Preloads images for instant access. 47 * 48 * @param paths an array with all image paths that should be preloaded. 49 */ 50jQuery.preloadImages = function() 51{ 52 for ( var i = 0; i < arguments.length; i++) 53 { 54 $('<img />').attr('src', arguments[i]); 55 } 56} 57 58/** 59 * Fix that String trim() function is available in ie 60 */ 61if (typeof String.prototype.trim !== 'function') 62{ 63 String.prototype.trim = function() 64 { 65 return this.replace(/^\s+|\s+$/g, ''); 66 } 67} 68 69/** 70 * Format strings in MessageFormat style. 71 * 72 * i.e. 'Foo {0}'.format('Bar') -> 'Foo Bar' 73 * 74 * @return the formatet string 75 */ 76String.prototype.format = function() 77{ 78 var args = arguments; 79 return this.replace(/\{(\d+)\}/g, function() 80 { 81 return args[arguments[1]]; 82 }); 83}; 84 85/** 86 * Check if a string value is empty. 87 * 88 * @param str the string value to check 89 * @return <code>true</code> if the value is empty, otherwise <code>false</code> 90 */ 91function isEmpty(str) 92{ 93 return str == 'undefined' || s.trim(str) == ''; 94} 95 96/** 97 * Check if a string value is not empty. 98 * 99 * @param str the string value to check 100 * @return <code>true</code> if the value is not empty, otherwise <code>false</code> 101 */ 102function isNotEmpty(str) 103{ 104 return !isEmpty(str); 105} 106 107/** 108 * Nullsave string trim implementation. 109 * 110 * @param str the string to trim 111 * @return the trimmed string 112 */ 113function trim(str) 114{ 115 return s.trim(str); 116} 117 118/** 119 * Trim a string value to undefined if it is undefined or empty. 120 * 121 * @param str the string to trim 122 * @return 'undefined' if the string undefined or empty, otherwise the string 123 */ 124function trimToUndefined(str) 125{ 126 if (str != undefined && isEmpty(str)) 127 { 128 str = undefined; 129 } 130 return str; 131} 132 133/** 134 * Create a new date by milliseconds. 135 * 136 * @param millis milliseconds since 01.01.1970 137 * @returns the JavaScript date 138 */ 139function createDate(millis) 140{ 141 var min = -2208992400000; 142 var max = 8640000000000000; 143 if (millis < min) 144 { 145 return new Date(min); 146 } 147 else if (millis > max) 148 { 149 return new Date(max); 150 } 151 else 152 { 153 return new Date(millis); 154 } 155} 156/** 157 * 158 * @param array - source, all elements -> could be html-elements like inputs 159 * @param separator - this param will be used as separator in the result string 160 * @param attribute - optional -> when elements in the source array are html-objects this param will be used to define 161 * the value-attribute i.e. attribute = 'value' -> <input type='text' name='x' value'target' /> 162 * 163 * @returns string 164 */ 165function arrayToString(array, separator, attribute) 166{ 167 if (!attribute) 168 { 169 return array.join(separator); 170 } 171 else 172 { 173 var res = _.map(array, function(item) 174 { 175 return $(item).attr(attribute); 176 }); 177 return res.join(separator); 178 } 179} 180 181/** 182 * jQuery namespace inclusion. 183 */ 184(function($) 185{ 186 jQuery.fn.isEmpty = function() 187 { 188 return isEmpty($(this).val()); 189 } 190 191 jQuery.fn.isNotEmpty = function() 192 { 193 return isNotEmpty($(this).val()); 194 } 195})(jQuery); 196 197/** 198 * Reset inputs 199 */ 200(function($) 201{ 202 jQuery.fn.reset = function() 203 { 204 $(this).each(function() 205 { 206 var id = $(this).attr('id'); 207 var tagName = $(this).get(0).tagName; 208 if (tagName == 'INPUT') 209 { 210 if($(this).attr('type') == 'checkbox' || $(this).attr('type') == 'radio') 211 { 212 $(this).attr('checked', false); 213 } 214 else 215 { 216 $(this).val(''); 217 } 218 } 219 else if(tagName == 'SELECT') 220 { 221 $('#' + id + ' option:selected').removeAttr('selected'); 222 } 223 }); 224 } 225 226})(jQuery); 227 228/** 229 * Browser detection 230 */ 231var BrowserDetect = { 232 init: function () { 233 this.browser = this.searchString(this.dataBrowser) || "An unknown browser"; 234 this.version = this.searchVersion(navigator.userAgent) 235 || this.searchVersion(navigator.appVersion) 236 || "an unknown version"; 237 this.OS = this.searchString(this.dataOS) || "an unknown OS"; 238 }, 239 searchString: function (data) { 240 for (var i=0;i<data.length;i++) { 241 var dataString = data[i].string; 242 var dataProp = data[i].prop; 243 this.versionSearchString = data[i].versionSearch || data[i].identity; 244 if (dataString) { 245 if (dataString.indexOf(data[i].subString) != -1) 246 return data[i].identity; 247 } 248 else if (dataProp) 249 return data[i].identity; 250 } 251 }, 252 searchVersion: function (dataString) { 253 var index = dataString.indexOf(this.versionSearchString); 254 if (index == -1) return; 255 return parseFloat(dataString.substring(index+this.versionSearchString.length+1)); 256 }, 257 dataBrowser: [ 258 {
259 string: navigator.userAgent, 260 subString: "Chrome", 261 identity: "Chrome" 262 }, 263 { string: navigator.userAgent, 264 subString: "OmniWeb", 265 versionSearch: "OmniWeb/", 266 identity: "OmniWeb" 267 }, 268 { 269 string: navigator.vendor, 270 subString: "Apple", 271 identity: "Safari", 272 versionSearch: "Version" 273 }, 274 { 275 prop: window.opera, 276 identity: "Opera", 277 versionSearch: "Version" 278 }, 279 { 280 string: navigator.vendor, 281 subString: "iCab", 282 identity: "iCab" 283 }, 284 { 285 string: navigator.vendor, 286 subString: "KDE", 287 identity: "Konqueror" 288 }, 289 { 290 string: navigator.userAgent, 291 subString: "Firefox", 292 identity: "Firefox" 293 }, 294 { 295 string: navigator.vendor, 296 subString: "Camino", 297 identity: "Camino" 298 }, 299 { // for newer Netscapes (6+) 300 string: navigator.userAgent, 301 subString: "Netscape", 302 identity: "Netscape" 303 }, 304 { 305 string: navigator.userAgent, 306 subString: "MSIE", 307 identity: "Explorer", 308 versionSearch: "MSIE" 309 }, 310 { 311 string: navigator.userAgent, 312 subString: "Gecko", 313 identity: "Mozilla", 314 versionSearch: "rv" 315 }, 316 { // for older Netscapes (4-) 317 string: navigator.userAgent, 318 subString: "Mozilla", 319 identity: "Netscape", 320 versionSearch: "Mozilla" 321 } 322 ], 323 dataOS : [ 324 { 325 string: navigator.platform, 326 subString: "Win", 327 identity: "Windows" 328 }, 329 { 330 string: navigator.platform, 331 subString: "Mac", 332 identity: "Mac" 333 }, 334 { 335 string: navigator.userAgent, 336 subString: "iPhone", 337 identity: "iPhone/iPod" 338 }, 339 { 340 string: navigator.platform, 341 subString: "Linux", 342 identity: "Linux" 343 } 344 ] 345}; 346
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.