1// ############################################################################# 2// EHAUS FUNCTIONS 3// ############################################################################# 4 5 6 7/******************************************************************************/ 8 function ldbLookUp(params){ 9 // Replaced by iLookUp() 10 11 var callback = function(response){ 12 list_product_response(response); 13 }; 14 15 iLookUp('', params, callback); 16 17 } 18/******************************************************************************/ 19 function list_product_response(response){ 20 21 // N.B. The ListProduct Ajax Response is formatted as XML 22 23 var errCode = $("errorcode", response).text(); 24 var errMsg = $("errormsg", response).text(); 25 var response = $("responsetext", response).text(); 26 var rID = $("rid", response).text(); 27 28 if(errCode == 0){ 29 30 if(!empty(rID)){ 31 32 $('#'+rID).html(response).fadeIn("slow"); 33 34 } else { 35 // IE no longer recognises the <listproducts> element (as it is non-standard) so you can't modify it in the dom 36 // you can only use it as a point of reference!! 37 $('#'+rID).after(response).fadeIn("slow"); 38 39 } 40 41 42 /* IF you need to re-initialise a carousel - here is the palce to do it :) */ /* 43 $owl = $('body').find('#oc-product'); 44 if($owl.length > 0){ 45 $owl.owlCarousel({ 46 //data-margin="30" data-pagi="false" data-autoplay="5000" data-items-xxs="1" data-items-sm="2" data-items-lg="4" 47 items: 5, 48 slideBy: 'page', 49 margin: 30, 50 nav: true, 51 dots: false, 52 autoPlay: 1000, 53 54 }).owlCarousel('update'); 55 //$owl.owlCarousel('refresh'); 56 } 57 */ 58 59 // Facets (via Ajax requests) 60 $(".facet-dropdown").each(function() { 61 62 if($(this).is(':empty')){ 63 $(this).siblings('a').css('cursor', 'not-allowed'); 64 //$(this).parent('li').addClass('hide'); 65 } 66 67 }); 68 69 // star rating uses /raty/ 70 $('.star').raty({ 71 score: function() { 72 return $(this).attr('data-score'); 73 } 74 }); 75 76 77 } else { 78 79 console.log(('error: list_product_response')) 80 81 } 82 83 } 84 85/******************************************************************************/ 86// ALL Infiniti Search & (ideally listproduct) calls pass through here.. 87 function iLookUp(load_url, params, callback){ 88 // assume params already serialized [&name=value etc.] 89 // requires jQuery Ajax Queue v0.1.1 | (c) 2013 Corey Frang | Licensed MIT */ see next 90 91 //console.log(load_url); 92 93 $.ajaxQueue({ 94 type: "POST", 95 url: give_me_a_baseref() + ((load_url) ? load_url : "include/xml.proxy.php"), 96 dataType: "xml", 97 data: params, 98 success: function(response){ 99 callback(response); 100 }, 101 error: function(xhr, opts, err) { 102 103 console.log(err); 104 105 } 106 107 108 }); 109 } 110/******************************************************************************/ 111/* Infiniti-Search - dependencies 112 113 ehaus.functions.js [ infinitiSearch(frm, data, query) - infinitiResults(response) - iLookUp(load_url, params, callback) - empty (mixedVar) - serializeObject() 114 115 custom.js 116 - next / previous 117 - trigger initial search params 118 119 WP_Infiniti_Results.tpl 120 121*/ 122 123 function infinitiSearch(frm, data, query){ 124 125 if(empty(data) ){ 126 data = $('#infiniti-results').data(); 127 } 128 129 $('.infiniti-waiting').fadeIn(400); 130 //console.log('infinitiSearch'); 131 //console.log('query: '+query); 132 console.log(data); 133 134 if(!empty(query)){ 135 // query must eh_encoded and '&' escaped as '{38}' 136 137 data.query = query; 138 139 } 140 141 if(!empty(frm)){ 142 // we need to construct it from the #i-search-form elements... 143 var myfrm = frm.serializeObject(); // see function below creates an associative javascript object :) 144 var sort = myfrm.sort; // so we can 'fit in' with standard ListProducts we need to extract the sort= param 145 delete myfrm.sort; // 146 data.sort = sort; // load up the data object 147 myquery = decodeURIComponent($.param(myfrm)); 148 data.query = myquery.replace(/:/g, '~').replace(/=/g, ':').replace(/&/g, '@'); 149 //data.next = ''; data.prev = ''; 150 151 } 152 153 // exceptionally we need to escape '&' if it appears in the search terms 154 data.query = data.query.replace(/&/, '{38}'); 155 //console.log(data); 156 157 var callback = function(response){ 158 infinitiResults(response); 159 }; 160 161 /* call the Ajax function[ iLookUp(url["include/xml.proxy.php"], $data, callback); ], sends response to callback function */ 162 iLookUp('', data, callback); 163 164 } 165 166/******************************************************************************/ 167// Infiniti search callback - display items 168 function infinitiResults(response, show){ 169 170 //console.log(response); 171 $('.infiniti-waiting').fadeOut(500); 172 173 var $rid = $('rid', response).text(); 174 var $res = $('responsetext', response).text(); 175 var $doc_count = $('documentcount', response).text(); 176 var $doc_start = $('documentstart', response).text(); 177 var $doc_end = $('documentend', response).text(); 178 179 $('#'+$rid).data('doc_count', $doc_count ); 180 $('#'+$rid).data('doc_end', $doc_end ); 181 console.log('infinitiResults: ' + $doc_start + ' - ' + $doc_end + ' / ' + $doc_count); 182 183 $('#'+$rid).data('next', $('next', response).text() ); 184 $('#'+$rid).data('prev', $('prev', response).text() ); 185 186 if(show == 'append' ){ 187 188 $('#'+$rid).append($res); 189 $('.'+$rid).fadeIn(2000); 190 191 } else { 192 193 $('#'+$rid).html($res); 194 $('.'+$rid).fadeIn(500); 195 196 } 197 198 if($doc_end == $doc_count){ 199 $('a[data-btn="next"]').fadeOut(200); 200 }else{ 201 $('a[data-btn="next"]').fadeIn(200); 202 } 203 204 205 } 206 207/******************************************************************************/ 208 209 $.fn.serializeObject = function () { 210 var o = {}; 211 var a = this.serializeArray(); 212 $.each(a, function () { 213 this.name = this.name.toLowerCase(); 214 if (o[this.name] !== undefined) { 215 if (!o[this.name].push) { 216 o[(this.name)] = [o[this.name]]; 217 } 218 o[this.name].push(this.value || ''); 219 } else { 220 o[this.name] = this.value || ''; 221 } 222 }); 223 return o; 224 }; 225 226 227/******************************************************************************/ 228/*! jQuery Ajax Queue v0.1.1 | (c) 2013 Corey Frang | Licensed MIT */ 229(function(e){var r=e({});e.ajaxQueue=function(n){function t(r){u=e.ajax(n).done(a.resolve).fail(a.reject).then(r,r)}var u,a=e.Deferred(),i=a.promise();
229return r.queue(t),i.abort=function(o){if(u)return u.abort(o);var c=r.queue(),f=e.inArray(t,c);return f>-1&&c.splice(f,1),a.rejectWith(n.context||n,[i,o,""]),i},i}})(jQuery); 230/******************************************************************************/ 231 232/******************************************************************************/ 233 function give_me_a_baseref() { 234 235 //Is the location path a script? 236 var _isScript = (location.pathname.split('/')[1]).match(/\./); 237 _isScript = !(_isScript == null); 238 var _barePath = (location.pathname.toString() == "/"); 239 240 return ((location.pathname.split('/')[1] == 'pid')||(location.pathname.split('/')[1] == 'page')||(_isScript)||(_barePath) ? '//' + location.hostname + '/' :'//' + location.hostname +'/' + location.pathname.split('/')[1] + '/'); 241 } 242 243/******************************************************************************/ 244 function GetISBNs(iTxt, retId){ 245 // 2009-02-15 uses Object instead of prototype for hash arrays 246 247 //console.log(iTxt); 248 var myhash = new Object(); 249 var blob = ""; 250 var commas = ""; 251 var reg = /[\t\r\n]+/g; 252 iTxt = iTxt.replace(reg, ","); 253 var reg = /[\s|\-]+/g; 254 iTxt = iTxt.replace(reg, ""); 255 //console.log(iTxt); 256 257 var reg = /(978\d{10}|979\d{10}|\d{13})/ig; 258 var parts = iTxt.match(reg, "$1"); 259 if(parts){ 260 for (var i=0; i<parts.length; i++) 261 { 262 myhash[parts[i]] = i; 263 iTxt = iTxt.replace(parts[i], ''); 264 } 265 } 266 267 var reg = /(\d{10}|\d{9}X)/ig; 268 var parts = iTxt.match(reg, "$1"); 269 if(parts){ 270 for (var i=0; i<parts.length; i++) 271 { 272 if(parts[i].substring(0,3) != ('978'||'979') ){ 273 myhash[parts[i]] = i; 274 } 275 } 276 } 277 278 for (var key in myhash) { 279 //blob += key + '=' + myhash[key] + '\n'; 280 blob += key + ",\n"; 281 commas += key + ','; 282 }; 283 284 $("#"+retId).val(blob); 285 return commas.replace(/,$/g, ''); 286 } 287 288/******************************************************************************/ 289// pad leading spaces with 000's 290 function padz(n, totalDigits){ 291 292 n = n.toString(); 293 var pd = ''; 294 if (totalDigits > n.length) 295 { 296 for (i=0; i < (totalDigits-n.length); i++) 297 { 298 pd += '0'; 299 } 300 } 301 return pd + n.toString(); 302 303 } 304 305/******************************************************************************/ 306 function paramsTohash(params){ 307 308 var myhash = new Object(); 309 var splitter = '&'; 310 var sep = '='; 311 312 if(typeof params != 'undefined' && params != ''){ 313 if(params.indexOf('|') > 0){splitter = '|';} 314 if(params.indexOf('@') > 0){splitter = '@';} 315 var parts = params.split(splitter); 316 317 for (var key in parts){ 318 //console.log('k: ' + parts[key]); 319 if(parts[key].indexOf('=') > 0 || parts[key].indexOf(':') > 0){ 320 if(parts[key].indexOf(':') > 0){sep = ':';} 321 var p = parts[key].split(sep); 322 myhash[p[0]] = p[1]; 323 } 324 } 325 } 326 327 return myhash; 328 329 } 330 331/******************************************************************************/ 332 function GetQueryStringParams(sParam){ 333 334 var sPageURL = window.location.search.substring(1); 335 var sURLVariables = sPageURL.split('&'); 336 var match = ''; 337 338 //console.log(sURLVariables.length); 339 for (var i = 0; i < sURLVariables.length; i++) { 340 341 var name = sURLVariables[i].split('=')[0]; 342 var val = sURLVariables[i].split('=')[1]; 343 //console.log('['+i+'] ' + name + ' [' + val + ']'); 344 if (name.toLowerCase() == sParam.toLowerCase()) { 345 match = val; 346 break; 347 } 348 } 349 350 return match; 351 } 352 353/******************************************************************************/ 354 function empty( val ) { 355 356 // test results 357 //--------------- 358 // [] true, empty array 359 // {} true, empty object 360 // null true 361 // undefined true 362 // "" true, empty string 363 // '' true, empty string 364 // 0 false, number 365 // true false, boolean 366 // false false, boolean 367 // Date false 368 // function false 369 370 if (val === undefined ) 371 return true; 372 373 if (typeof (val) == 'function' || typeof (val) == 'number' || typeof (val) == 'boolean' || Ob
373ject.prototype.toString.call(val) === '[object Date]') 374 return false; 375 376 if (val == null || val.length === 0) // null or 0 length array 377 return true; 378 379 if (typeof (val) == "object") { 380 // empty object 381 382 var r = true; 383 384 for (var f in val) 385 r = false; 386 387 return r; 388 } 389 390 return false; 391 } 392 393/******************************************************************************/ 394 function strip(html){ 395 396 var tmp = document.implementation.createHTMLDocument("New").body; 397 tmp.innerHTML = html; 398 return tmp.textContent || tmp.innerText || ""; 399 400 } 401 402/******************************************************************************/ 403/******************************************************************************/ 404 405 406
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.