PageSourceSearch

https://www.goldenstatemint.com/skin/common_files/modules/Customer_Reviews/ajax.rating.js?v=1790419155

js goldenstatemint.com collected 2026-09-26 10:39:53 UTC 8,337 bytes, 413 lines download raw bytes

1/* vim: set ts=2 sw=2 sts=2 et: */
2/**
3 * Rating bar widget
4 * 
5 * @category   X-Cart
6 * @package    X-Cart
7 * @subpackage JS Library
8 * @author     Ruslan R. Fazlyev <[email protected]> 
9 * @version    2a321c65d1ad1429f47434729de546ac23ecdfac, v6 (xcart_4_7_11), 2019-04-25 08:59:19, ajax.rating.js, aim
10 * @link       https://www.x-cart.com/
11 * @see        ____file_see____
12 */
13
14ajax.widgets.rating = function(elm) {
15  if (!elm) {
16    elm = $('.creviews-rating-box');
17
18  } else {
19    elm = $(elm);
20  }
21
22  elm.each(
23    function() {
24      if (!this.ratingWidget)
25        new ajax.widgets.rating.obj(this);
26    }
27  );
28
29  return true;
30}
31
32ajax.widgets.rating.obj = function(elm) {
33  this.elm = elm;
34  this.elm$ = $(elm);
35
36  elm.ratingWidget = this;
37
38  var s = this;
39
40  this._rate = function() {
41    return !s.rate(this);
42  }
43
44  this._callbackUB = function(responseText, textStatus, XMLHttpRequest) {
45    return s._callbackUpdateBar(responseText, textStatus, XMLHttpRequest);
46  }
47
48  this._callbackR = function(state, a, b, c, d) {
49    return s._callbackRate(state, a, b, c, d);
50  }
51
52  this._prepareWidget();
53
54  this.state = 1;
55}
56
57// Options
58ajax.widgets.rating.obj.prototype.ttl = 3000;
59
60// Property
61ajax.widgets.rating.obj.prototype.elm = false;
62
63ajax.widgets.rating.obj.prototype.productid = false;
64
65ajax.widgets.rating.obj.prototype.state = false;
66ajax.widgets.rating.obj.prototype.isRated = false;
67
68// Widget :: check widget status
69ajax.widgets.rating.obj.prototype.isReady = function() {
70  return this.productid;
71}
72
73// Widget :: do rate
74ajax.widgets.rating.obj.prototype.rate = function(item) {
75  if (!item || !this.isReady() || this.isRated)
76    return false;
77
78  this.changeState(2);
79
80  var s = this;
81  return ajax.query.add(
82    {
83      type: 'POST',
84      data: '',
85      url: $(item).attr('href'),
86      success: function(a, b, c, d) {
87        return s._callbackR(true, a, b, c, d);
88      },
89      error: function(a, b, c, d) {
90        return s._callbackR(false, a, b, c, d);
91      }
92    }
93  ) !== false;
94}
95
96// Widget :: update bar
97ajax.widgets.rating.obj.prototype.updateBar = function() {
98  if (!this.isReady())
99    return false;
100
101  if (this.state == 1)
102    this.changeState(2);
103
104  if (typeof(window.creviews_hover_loaded) && creviews_hover_loaded)
105    creviews_hover_loaded = false;
106
107  var data = {
108    productid: this.productid
109  };
110  if (this.pconf)
111    data.pconf = this.pconf;
112
113  return ajax.core.loadBlock(this.elm$, 'rating_bar', data, this._callbackUB);
114}
115
116// Widget :: changes widget state
117//  1 - idle
118//  2 - wait
119//  3 - success rated
120//  4 - error
121//  5 - cancel rate: already rated
122ajax.widgets.rating.obj.prototype.changeState = function(state, msg) {
123  if (this.state == state)
124    return true;
125
126  var res = false;
127
128  switch (this.state) {
129    case 2:
130      res = this._cleanWaitState();
131      break;
132
133    case 3:
134      res = this._cleanRatedState();
135      break;
136
137    case 4:
138      res = this._cleanErrorState();
139      break;
140
141    case 5:
142      res = this._cleanCancelState();
143      break;
144
145    default:
146      res = this._cleanIdleState();
147  }
148
149  if (!res)
150    return false;
151
152  this.state = state;
153  var o = this;
154
155  switch (state) {
156    case 2:
157      res = this._doWaitState();
158      break;
159
160    case 3:
161      res = this._doRatedState();
162      break;
163
164    case 4:
165      res = this._doErrorState();
166      setTimeout(
167        function() {
168          return o.changeState(1);
169        },
170        this.ttl
171      );
172      break;
173
174    case 5:
175      res = this._doCancelState();
176      break;
177
178    default:
179      res = this._doIdleState();
180  }
181
182  return res;
183}
184
185/* Private */
186
187// Widget :: prepare widget
188ajax.widgets.rating.obj.prototype._prepareWidget = function() {
189
190  // Check stars
191  var links = $('.creviews-vote-bar a', this.elm$);
192  if (links.length == 0)
193    return false;
194
195  // Detect productid
196  var m = links.get(0).href.match(/productid=(\d+)/)
197  if (!m)
198    return false;
199
200  this.productid = parseInt(m[1]);
201  if (isNaN(this.productid) || this.productid < 1) {
202    this.productid = false;
203    return false;
204  }
205
206  // Detect Product Configurator properties
207  m = links.get(0).href.match(/pconf=(\d+)/)
208  if (m) {
209    this.pconf = parseInt(m[1]);
210    if (isNaN(this.pconf) || this.pconf < 1)
211      this.pconf = false;
212  }
213
214  links.on('click',this._rate); /*CLiCk_Event_deprecated_in_3_3*/
215
216  return true;
217}
218
219// Widget :: callback rate action
220ajax.widgets.rating.obj.prototype._callbackRate = function(state, a, b, c, d) {
221  var s = 0;
222
223  if (state && c.messages) {
224    for (var i = 0; i < c.messages.length; i++) {
225      if (c.messages[i].name == 'addVote' && c.messages[i].params.productid == this.productid) {
226        s = parseInt(c.messages[i].params.status);
227      }
228    }
229  }
230
231  var o = this;
232  switch (s) {
233    case 1:
234      this.changeState(3);
235      setTimeout(
236        function() {
237          return o.updateBar();
238        },
239        this.ttl
240      );
241      break;
242
243    case 2:
244      this.changeState(5);
245      setTimeout(
246        function() {
247          return o.updateBar();
248        },
249        this.ttl
250      );
251      break;
252
253    default:
254      if (!state && a.status == 0) {
255        this.changeState(1);
256      } else
257        this.changeState(4);
258  }
259
260  return true;
261}
262
263// Widget :: callback update bar
264ajax.widgets.rating.obj.prototype._callbackUpdateBar = function(responseText, textStatus, XMLHttpRequest) {
265  if (XMLHttpRequest.status == 200) {
266    this.savedElm = false;
267    this.changeState(1);
268
269  } else {
270    this.changeState(4);
271  }
272
273  return true;
274}
275
276ajax.widgets.rating.obj.prototype._doIdleState = function() {
277  if (this.savedElm) {
278    var s = this;
279    this.savedElm.children().each(
280      function() {
281        s.elm$.append(this);
282      }
283    );
284
285    this.savedElm = false;
286  }
287
288  this.elm$.width('auto');
289
290  return true;
291}
292
293ajax.widgets.rating.obj.prototype._cleanIdleState = function() {
294  this.savedWidth = $('li:last', this.elm$).offset().left - $('li:first', this.elm$).offset().left + $('li:last', this.elm$).width();
295  var pl = parseInt($('li:last', this.elm$).css('padding-left'));
296  if (!isNaN(pl))
297    this.savedWidth += pl;
298
299  var pr = parseInt($('li:last', this.elm$).css('padding-right'));
300  if (!isNaN(pr))
301    this.savedWidth += pr;
302
303  this.savedElm = this.elm$.clone();
304
305  this.elm$.empty();
306
307  return true;
308}
309
310ajax.widgets.rating.obj.prototype._doWaitState = function() {
311  var block = document.createElement('SPAN');
312  block.className = 'progress';
313
314  this.elm$
315    .width(this.savedWidth)
316    .empty()
317    .addClass('wait')
318    .append(block);
319
320  return true;
321}
322
323ajax.widgets.rating.obj.prototype._cleanWaitState = function() {
324  if (this.elm$.children().length == 1)
325    this.elm$.empty();
326
327  this.elm$.removeClass('wait');
328
329  return true;
330}
331
332ajax.widgets.rating.obj.prototype._doRatedState = function() {
333  var block = document.createElement('SPAN');
334  block.innerHTML = lbl_rated;
335
336  this.elm$
337    .width(this.savedWidth)
338    .empty()
339    .addClass('message')
340    .addClass('rated')
341    .append(block);
342
343  return true;
344}
345
346ajax.widgets.rating.obj.prototype._cleanRatedState = function() {
347  if (this.elm$.children().length == 1)
348    this.elm$.empty();
349
350  this.elm$
351    .removeClass('message')
352    .removeClass('rated');
353
354  return true;
355}
356
357ajax.widgets.rating.obj.prototype._doErrorState = function() {
358  var block = document.createElement('SPAN');
359  block.innerHTML = lbl_error;
360
361  this.elm$
362    .width(this.savedWidth)
363    .empty()
364    .addClass('message')
365    .addClass('error')
366    .append(block);
367
368  return true;
369}
370
371ajax.widgets.rating.obj.prototype._cleanErrorState = function() {
372  if (this.elm$.children().length == 1)
373    this.elm$.empty();
374
375  this.elm$
376    .removeClass('message')
377    .removeClass('error');
378
379  return true;
380}
381
382ajax.widgets.rating.obj.prototype._doCancelState = function() {
383  var block = document.createElement('SPAN');
384  block.innerHTML = lbl_cancel_vote;
385
386  this.elm$
387    .width(this.savedWidth)
388    .empty()
389    .addClass('message')
390    .addClass('cancel')
391    .append(block);
392
393  return true;
394}
395
396ajax.widgets.rating.obj.prototype._cleanCancelState = function() {
397  if (this.elm$.children().length == 1)
398    this.elm$.empty();
399
400  this.elm$
401    .removeClass('message')
402    .removeClass('cancel');
403
404  return true;
405}
406
407// onload handler
408$(ajax).on( /*BiNd_deprecated_in_3_0*/
409  'load',
410  function() {
411    return ajax.widgets.rating();
412  }
413);

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.