PageSourceSearch

https://www.rwsmithco.com/includes/javascriptmin/ajax_sc.js

js rwsmithco.com collected 2026-10-08 18:14:05 UTC 18,944 bytes, 509 lines download raw bytes

1SHOW_ADDED = 1; // set 0 if you no need show
2Offset_X = -10;
3Offset_Y = -30;
4/**
5 * Subsys_JsHttpRequest_Js: JavaScript DHTML data loader.
6 * (C) 2005 Dmitry Koterov, http://forum.dklab.ru/users/DmitryKoterov/
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 * See http://www.gnu.org/copyleft/lesser.html
13 *
14 * Do not remove this comment if you want to use script!
15 * Íå óäàëÿéòå äàííûé êîììåíòàðèé, åñëè âû õîòèòå èñïîëüçîâàòü ñêðèïò!
16 *
17 * This library tries to use XMLHttpRequest (if available), and on
18 * failure - use dynamically created <script> elements. Backend code
19 * is the same for both cases.
20 *
21 * @author Dmitry Koterov
22 * @version 3.29
23 */
24
25function Subsys_JsHttpRequest_Js() { this._construct() }
26(function() { // to create local-scope variables
27    var COUNT       = 0;
28    var PENDING     = {};
29    var CACHE       = {};
30
31    // Called by server script on data load.
32    Subsys_JsHttpRequest_Js.dataReady = function(id, text, js) {
33        var undef;
34        var th = PENDING[id];
35        delete PENDING[id];
36        if (th) {
37            delete th._xmlReq;
38            if (th.caching) CACHE[th.hash] = [text, js];
39            th._dataReady(text, js);
40        } else if (typeof(th) != typeof(undef)) {
41            alert("ScriptLoader: unknown pending id: "+id);
42        }
43    }
44
45    Subsys_JsHttpRequest_Js.prototype = {
46        // Standard properties.
47        onreadystatechange: null,
48        readyState:         0,
49        responseText:       null,
50        responseXML:        null,
51        status:             200,
52        statusText:         "OK",
53
54        // Additional properties.
55        session_name:       "ecosid",  // set to SID cookie or GET parameter name
56        responseJS:         null,         // JavaScript response array/hash
57        caching:            false,        // need to use caching?
58
59        // Internals.
60        _span:              null,
61        _id:                null,
62        _xmlReq:            null,
63        _openArg:           null,
64        _reqHeaders:        null,
65
66        dummy: function() {}, // empty function
67
68        abort: function() {
69            if (this._xmlReq) return this._xmlReq.abort();
70            if (this._span) {
71                this.readyState = 0;
72                if (this.onreadystatechange) this.onreadystatechange();
73                this._cleanupScript();
74            }
75        },
76
77        open: function(method, url, asyncFlag, username, password) {
78            this._openArg = {
79                'method':    method,
80                'url':       url,
81                'asyncFlag': asyncFlag,
82                'username':  username,
83                'password':  password
84            };
85            this._id = null;
86            this._xmlReq = null;
87            this._reqHeaders = [];
88            return true;
89        },
90
91        send: function(content) {
92            var id = (new Date().getTime()) + "" + COUNT++;
93
94            // Build QUERY_STRING from query hash.
95            var query = this._hash2query(content);
96
97            // Append SID to original URL now.
98            var url = this._openArg.url;
99            var sid = this._getSid();
100            if (sid) url += (url.indexOf('?')>=0? '&' : '?') + this.session_name + "=" + this.escape(sid);
101
102            // Solve hash BEFORE appending ID.
103            var hash = this.hash = url + '?' + query;
104            if (this.caching && CACHE[hash]) {
105                var c = CACHE[hash];
106                this._dataReady(c[0], c[1]);
107                return false;
108            }
109
110            // Try to use XMLHttpRequest.
111            this._xmlReq = this._obtainXmlReq(id, url);
112
113            // Pass data in URL (GET, HEAD etc.) or in request body (POST)?
114            var hasSetHeader = this._xmlReq && (window.ActiveXObject || this._xmlReq.setRequestHeader);
115            var href, body;
116            if (this._xmlReq && hasSetHeader && (""+this._openArg.method).toUpperCase() == "POST") {
117                // Use POST method. Pass query in request body.
118                // Opera 8.01 does not support setRequestHeader, so no POST method.
119                this._openArg.method = "POST";
120                href = url;
121                body = query;
122            } else {
123                this._openArg.method = "GET";
124                href = url + (url.indexOf('?')>=0? '&' : '?') + query;
125                body = null;
126            }
127
128            // Append ID: a=aaa&b=bbb&<id>
129            href = href + (href.indexOf('?')>=0? '&' : '?') + id;
130
131            // Save loading script.
132            PENDING[id] = this;
133
134            if (this._xmlReq) {
135                // Open request now & send it.
136                // In XMLHttpRequest mode request URL MUST be ended with "<id>-xml".
137                var a = this._openArg;
138                this._xmlReq.open(a.method, href+"-xml", a.asyncFlag, a.username, a.password);
139                if (hasSetHeader) {
140                    // Pass pending headers.
141                    for (var i=0; i<this._reqHeaders.length; i++)
142                        this._xmlReq.setRequestHeader(this._reqHeaders[i][0], this._reqHeaders[i][1]);
143                    // Set non-default Content-type. We cannot use
144                    // "application/x-www-form-urlencoded" here, because
145                    // in PHP variable HTTP_RAW_POST_DATA is accessible only when
146                    // enctype is not default (e.g., "application/octet-stream"
147                    // is a good start). We parse POST data manually in backend
148                    // library code.
149                    this._xmlReq.setRequestHeader('Content-Type', 'application/octet-stream');
150                }
151                // Send the request.
152                return this._xmlReq.send(body);
153            } else {
154                // Create <script> element and run it.
155                this._obtainScript(id, href);
156                return true;
157            }
158        },
159
160        getAllResponseHeaders: function() {
161            if (this._xmlReq) return this._xmlReq.getAllResponseHeaders();
162            return '';
163        },
164
165        getResponseHeader: function(label) {
166            if (this._xmlReq) return this._xmlReq.getResponseHeader(label);
167            return '';
168        },
169
170        setRequestHeader: function(label, value) {
171            // Collect headers.
172            this._reqHeaders[this._reqHeaders.length] = [label, value];
173        },
174
175
176        //
177        // Internal functions.
178        //
179
180        // Constructor.
181        _construct: function() {},
182
183        // Do all work when data is ready.
184        _dataReady: function(text, js) { with (this) {
185            if (text !== null || js !== null) {
186                readyState = 4;
187                responseText = responseXML = text;
188                responseJS = js;
189            } else {
190                readyState = 0;
191                responseText = responseXML = responseJS = null;
192            }
193            if (onreadystatechange) onreadystatechange();
194            _cleanupScript();
195        }},
196
197        // Create new XMLHttpRequest object.
198        _obtainXmlReq: function(id, url) {
199            // If url.domain specified, cannot use XMLHttpRequest!
200            // XMLHttpRequest (and MS ActiveX'es) cannot work with different domains.
201            if (url.match(new RegExp('^[a-z]+://', 'i'))) return null;
202
203            // Try to use built-in loaders.
204            var req = null;
205            if (window.XMLHttpRequest) {
206                try { req = new XMLHttpRequest() } catch(e) {}
207            } else if (window.ActiveXObject) {
208                try { req = new ActiveXObject("Microsoft.XMLHTTP") } catch(e) {}
209                if (!req) try { req = new ActiveXObject("Msxml2.XMLHTTP") } catch (e) {}
210            }
211            if (req) {
212                var th = this;
213                req.onreadystatechange = function() {
214                    var s = req.readyState;
215                    if (s == 4) {
216                        // Avoid memory leak by removing closure.
217                        req.onreadystatechange = th.dummy;
218                        // Remove possible junk from response.
219                        var responseText = req.responseText;
220                        try {
221                            // Call associated dataReady().
222                            eval(responseText);
223                        } catch (e) {
224                           /* Subsys_JsHttpRequest_Js.dataReady(id, "JavaScript code generated by backend is invali
224d!\n"+responseText, null);*/
225                            Subsys_JsHttpRequest_Js.dataReady(id, responseText, null);
226                        }
227                    } else {
228                        th.readyState = s;
229                        if (th.onreadystatechange) th.onreadystatechange()
230                    }
231                };
232                this._id = id;
233            }
234            return req;
235        },
236
237        // Create new script element and start loading.
238        _obtainScript: function(id, href) { with (document) {
239            var span = null;
240            // Oh shit! Damned stupid fucked Opera 7.23 does not allow to create SCRIPT
241            // element over createElement (in HEAD or BODY section or in nested SPAN -
242            // no matter): it is created deadly, and does not respons on href assignment.
243            // So - always create SPAN.
244            span = body.appendChild(createElement("SPAN"));
245            span.style.display = 'none';
246            span.innerHTML = 'Text for stupid IE.<s'+'cript></' + 'script>';
247            setTimeout(function() {
248                var s = span.getElementsByTagName("script")[0];
249                s.language = "JavaScript";
250                if (s.setAttribute) s.setAttribute('src', href); else s.src = href;
251            }, 10);
252            this._id = id;
253            this._span = span;
254        }},
255
256        // Remove last used script element (clean memory).
257        _cleanupScript: function() {
258            var span = this._span;
259            if (span) {
260                this._span = null;
261                setTimeout(function() {
262                    // without setTimeout - crash in IE 5.0!
263                    span.parentNode.removeChild(span);
264                }, 50);
265            }
266            return false;
267        },
268
269        // Convert hash to QUERY_STRING.
270        _hash2query: function(content, prefix) {
271            if (prefix == null) prefix = "";
272            var query = [];
273            if (content instanceof Object) {
274                for (var k in content) {
275                    var v = content[k];
276                    if (v == null || ((v.constructor||{}).prototype||{})[k]) continue;
277                    var curPrefix = prefix? prefix+'['+this.escape(k)+']' : this.escape(k);
278                    if (v instanceof Object)
279                        query[query.length] = this._hash2query(v, curPrefix);
280                    else
281                        query[query.length] = curPrefix + "=" + this.escape(v);
282                }
283            } else {
284                query = [content];
285            }
286            return query.join('&');
287        },
288
289        // Return value of SID based on QUERY_STRING or cookie
290        // (PHP compatible sessions).
291        _getSid: function() {
292            var m = document.location.search.match(new RegExp('[&?]'+this.session_name+'=([^&?]*)'));
293            var sid = null;
294            if (m) {
295                sid = m[1];
296            } else {
297                var m = document.cookie.match(new RegExp(s='(;|^)\\s*'+this.session_name+'=([^;]*)'));
298                if (m) sid = m[2];
299            }
300            return sid;
301        },
302
303        // Stupid JS escape() does not quote '+'.
304        escape: function(s) {
305            return escape(s).replace(new RegExp('\\+','g'), '%2B');
306        }
307    }
308})();
309function addHandler(object, event, handler) { // Thanks xpoint.ru!
310  if (typeof object.addEventListener != 'undefined')
311    object.addEventListener(event, handler, false);
312  else if (typeof object.attachEvent != 'undefined')
313    object.attachEvent('on' + event, handler);
314  else {
315    var handlersProp = '_handlerStack_' + event;
316    var eventProp = 'on' + event;
317    if (typeof object[handlersProp] == 'undefined') {
318      object[handlersProp] = [];
319      if (typeof object[eventProp] != 'undefined')
320        object[handlersProp].push(object[eventProp]);
321      object[eventProp] = function(e) {
322        var ret = true;
323        for (var i = 0; ret != false && i < object[handlersProp].length; i++)
324          ret = object[handlersProp][i](e);
325        return ret;
326    } }
327    object[handlersProp].push(handler);
328} }
329function removeHandler(object, event, handler) { // Thanks xpoint.ru!
330  if (typeof object.removeEventListener != 'undefined')
331    object.removeEventListener(event, handler, false);
332  else if (typeof object.detachEvent != 'undefined')
333    object.detachEvent('on' + event, handler);
334  else {
335    var handlersProp = '_handlerStack_' + event;
336    if (typeof object[handlersProp] != 'undefined') {
337      for (var i = 0; i < object[handlersProp].length; i++) {
338        if (object[handlersProp][i] == handler) {
339          object[handlersProp].splice(i, 1);
340          return;
341} } } } }
342/**
343  AJAXBuyNow v2.0
344
345  author Weretennikoff Andrew aka Medreces [email protected]
346
347  Released under the GNU General Public License
348*/
349var x, y;
350var loadingImage = new Image();
351var okImage = new Image();
352loadingImage.src = "images/pixel_trans.gif"; //"images/icons/ajax-cart-loader.gif";
353okImage.src = "images/pixel_trans.gif"; //"images/icons/ajax-added-cart.gif";
354
355if (window.opera || (navigator.userAgent.indexOf('MSIE') > -1))
356{ // following checks for document.body.scrollTop vs document.documentElement.scrollTop 
357
358getM_x = function ()
359{ Xadder = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft; 
360return event.clientX + Xadder;}
361
362getM_y = function ()
363{ Yadder = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
364return event.clientY + Yadder;
365}
366
367} else { // Mozilla
368  addHandler(document, 'mousemove', function(e) {
369    x = e.pageX;
370    y = e.pageY;
371  });
372  getM_x = function () { return x; }
373  getM_y = function () { return y; }
374}
375
376
377function showOk() {
378  var imgLoading = document.getElementById("_loading_");
379  with (imgLoading) {
380    src = okImage.src;
381    style.visibility = "visible";
382} }
383
384function hideOk() {
385  if(document.getElementById("_loading_")) document.getElementById('_loading_').style.visibility = "hidden";
386  removeHandler(document, 'mousemove', hideOk);
387}
388function showLoading() {
389  var imgLoading = document.getElementById("_loading_");
390  if(!imgLoading) {
391    imgLoading = document.createElement("img");
392    with(imgLoading) {
393      id = "_loading_";
394      style.position = "absolute";
395      style.visibility = "hidden";
396    }
397    document.body.appendChild(imgLoading);
398  }
399  with(imgLoading) {
400    src = loadingImage.src;
401    style.left = (getM_x() + Offset_X) + "px";
402    style.top = (getM_y() + Offset_Y) + "px";
403    style.visibility = "visible";
404} }
405function hideLoading() {
406  if(document.getElementById("_loading_")) document.getElementById("_loading_").style.visibility = "hidden";
407}
408
409function doBuyNowGet( link ) {
410  showLoading();
411  var reqAddCart = new Subsys_JsHttpRequest_Js();
412  document.getElementById('quickViewLoader').style.display = "block";
413  reqAddCart.onreadystatechange = function() {       
414    if (reqAddCart.readyState == 4) {
415      if (reqAddCart.responseJS) {
416        document.location.href = reqAddCart.responseJS.ajax_redirect;
417        return;
418      }
419      else {
420        document.getElementById('divShoppingCart').innerHTML = ''+(reqAddCart.responseText||'')+'';
421        setTimeout(function(){
422            document.getElementById('quickViewLoader').style.display = "none";
423        }, 2 * 1000);
424        hideLoading();
425        if ( SHOW_ADDED ) {
426          showOk();
427          timerID = setTimeout( "addHandler(document, \'mousemove\', hideOk)", 500);
428        }
429      }
430    }
431  }
432  reqAddCart.caching = false;
433  reqAddCart.open('GET', link, true);
434  reqAddCart.send(null);
435
436  window.scroll(0,0);
437}
438COUNT = 0
439function doAddProduct(form) {
440  window.scroll(0,0);
441  var reqAddCart = new Subsys_JsHttpRequest_Js();
442  
443// ñîáèðàåì âñå ýëåìåíòû ôîðìû:
444  var senddata = new Object();
445  var fe = form.elements;
446  for(var i=0 ; i<fe.length ; i++) {
447    if ( fe[i].type=="radio" || fe[i].type=="checkbox" ) {
448      if ( fe[i].checked ) senddata[fe[i].name] = fe[i].value;
449    } else {
450      senddata[fe[i].name] = fe[i].value;
451    }
452  }
453  // reqAddCart.onreadystatechange = function() {
454  //   if (reqAddCart.readyState == 4) {
455  //     if (reqAddCart.responseJS) {
456  //       document.location.href = reqAddCart.responseJS.ajax_redirect;
457  //       return;
458  //     }
459  //     else {
460  //      document.getElementById('divShoppingCart').innerHTML = 
461	 //       ''+(reqAddCart.responseText||'')+'';
462	 //       //alert(reqAddCart.responseText||'');
463  //       if ( SHOW_ADDED ) {
464  //         showOk();
465  //         timerID = setTimeout( "addHandler(document, \'mousemove\', hideOk)", 500);
466  //       }
467  //     }
468  //   }
469  // }
470
471  var id = (new Date().getTime()) + "" + COUNT++;
472
473  var url = 'ajax_shopping_cart.php?' + ( senddata.products_id ? 'products_id='+senddata.products_id+'&' : "" ) + 'action=add_product&cart_quantity='+senddata.cart_quantity;
474  reqAddCart.caching = false;
475  reqAddCart.open( form.method, url, true);  
476  document.getElementById('quickViewLoader').style.display = "block";
477  reqAddCart.send( senddata ); 
478	  reqAddCart.onreadystatechange = function() { 
479        if (reqAddCart.readyState == 4) {         
480            if (reqAddCart.responseJS) {
481                document.location.href = reqAddCart.responseJS.ajax_redirect;
482                return;
483            }
484            else {      
485                window.scroll(0,0);              
486                document.getElementById('divShoppingCart').innerHTML = 
487                   ''+(reqAddCart.responseText||'')+'';        		      
488                if ( SHOW_ADDED ) {
489                  //showOk();                      
490                  timerID = setTimeout( "addHandler(document, \'mousemove\', hideOk)", 500);
491                }
492                //setTimeout(function(){ console.log('hideLoading c
492alled!');hideLoading(); }, 5 * 1000);
493            }
494            setTimeout(function(){
495                document.getElementById('quickViewLoader').style.display = "none";
496            }, 2 * 1000);
497	    }
498	  }
499    
500      
501  //for(var j=0 ; j<document.cart_quantity.elements.length ; j++) {
502  //  if (document.cart_quantity[j].type=="select-one") document.cart_quantity[j].selectedIndex = 0;
503  //}
504  /*
505
506  */
507
508  return false;
509}

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.