PageSourceSearch

https://www.silven.com.br/frontend/js/App-flag.js

js silven.com.br collected 2026-09-30 17:20:04 UTC 10,775 bytes, 387 lines download raw bytes

1/**
2 * @copyright     D Loja Virtual
3 * @link          http://www.dlojavirtual.com
4 * @package       app.FrontEnd.Js
5 * @since         v 1.0
6 * @author        Bruno Lehnen Simões
7 *  @description   Revealing modules responsaveis pelo roteamento e pelas requisições aos Web Services
8 **/
9
10var AppWidgets = (function () {
11  function addClasses(element, classes) {
12    if (classes) {
13      if (!Array.isArray(classes)) {
14        element.addClass(classes);
15      } else {
16        $.each(classes, function (index, klass) {
17          element.addClass(klass);
18        });
19      }
20    }
21  }
22
23  function customElement(tag, options) {
24    var element = $('<' + tag + ' />', options.options);
25    element.append(options.child);
26
27    addClasses(element, options.classes);
28
29    return element;
30  }
31
32  function grid(rows, elements, options) {
33    return customElement('div', {
34      classes: ['grid-' + rows, 'alpha', 'omega'],
35      child: elements,
36      options: options
37    });
38  }
39
40  function row(elements, options) {
41    return customElement('div', {
42      classes: 'row',
43      child: elements
44    });
45  }
46
47  function gridRow(rows, elements, options) {
48    var rowList = new Array();
49    $.each(elements, function (index, element) {
50      rowList.push(row(element));
51    });
52
53    return grid(rows, rowList, options);
54  }
55
56  function button(title, options, classes) {
57    var classes = (!classes) ? new Array() : classes,
58      elements = new Array();
59    elements.push('<span class="btn-icon"></span>');
60    elements.push('<span class="btn-text">' + title + '</span>');
61    classes.unshift('btn');
62
63    return customElement('button', {
64      child: elements,
65      options: options,
66      classes: classes
67    });
68  }
69
70  return {
71    row: row,
72    grid: grid,
73    button: button,
74    gridRow: gridRow,
75    customElement: customElement
76  };
77
78})();
79
80var App = {
81  loaded: [],
82  current: null,
83  currentId: 'cart-products',
84  loadImage: null,
85
86  getLoadImage: function () {
87    var divImg = $('<div />');
88    divImg.addClass('loading-cart');
89
90
91    return divImg;
92  },
93
94  refreshApp: function () {
95    $.each($(document.head).children('script'), function (index, element) {
96      var clone = $('<script />', {
97        'type': element.type,
98        'src': element.src
99      });
100
101      $(element).remove();
102      $(document.head).append(element);
103    });
104  },
105
106  initJSON: function (callback) {
107    if (!window.JSON) {
108      App.include('json', callback);
109    } else {
110      callback.call(this)
111    }
112  },
113
114  //Init
115  init: function () {
116    App.initJSON(function () {
117      $('.one-step-checkout-item').show();
118
119      //Configura e monitora slides
120      App.Slider = $('#one-step-checkout-main').bxSlider({
121        mode: 'horizontal',
122        captions: false,
123        responsive: true,
124        auto: false,
125        pager: false,
126        controls: false,
127        touchEnabled: false,
128        pagerSelector: null,
129        infiniteLoop: false,
130        useCSS: false,
131        onSlideAfter: App.afterSlideCallback,
132        onSlideBefore: App.beforeSlideCallback
133      });
134
135      App.beforeSlideCallback(document.getElementById('cart-products'), function () {
136        //Eventos genéricos	
137        $(document.body).on('click', '.cart-slider-submit', function (e) {
138          if (typeof App.current.submit === 'function') {
139            App.current.submit.call(this, 'click');
140          }
141        });
142
143        $(document.body).on('keyup', null, function (e) {
144          if (e.which == 13 && App.currentId != 'cart-products' && typeof App.isValidCallback(App.current.submit)) {
145            App.current.submit('key');
146          }
147        });
148      });
149
150    });
151  },
152
153  //Controladores de slide
154  beforeSlideCallback: function (sElement, callback) {
155    App.currentId = $(sElement).attr('id');
156
157    App.include('carrinho/' + App.currentId, null,
158      function () {
159        App.current = window[App.currentId.toCamel()];
160        App.loadComponents(App.current, null, function () {
161          App.current.box = $(sElement);
162          App.current.loading = $(sElement).children('.box-loading');
163          App.current.loadingStart = function () {
164            App.current.loading.show();
165          }
166          App.current.loadingComplete = function () {
167            App.current.loading.hide();
168          }
169          App.current.init(callback);
170        });
171      }
172    );
173  },
174
175  afterSlideCallback: function (sElement) {
176    if (typeof App.current.focusObj !== 'undefined') {
177      App.current.focusObj.focus();
178    }
179  },
180
181  loadComponents: function (controller, beforeCallback, successCallback) {
182    if (controller.components && controller.components.length) {
183      App.initCallback(beforeCallback);
184
185      (function recursiveLoading() {
186        if (controller.components.length) {
187          var component = controller.components.shift();
188          var fullComponent = component.toCamel() + 'Component';
189
190          App.include(fullComponent, null, function (e) {
191            controller[component] = window[fullComponent];
192            recursiveLoading();
193          });
194
195        } else {
196          App.initCallback(successCallback);
197        }
198
199      })();
200
201    } else {
202      App.initCallback(successCallback);
203    }
204  },
205
206  //Metodos Utilitarios
207  include: function (name, beforeCallback, successCallback) {
208
209    // Versionamentos de JS do carrinho ¯\_(ツ)_/¯		
210    if (name == 'carrinho/cart-products') {
211      name = 'carrinho/cart-products-flag'
212    } else if (name == 'carrinho/cart-email') {
213      name = 'carrinho/cart-email.min.8543'
214    } else if (name == 'carrinho/cart-final') {
215      name = 'carrinho/cart-final'
216    } else if (name == 'ShippingComponent') {
217      name = 'ShippingComponent'
218    } else if (name == 'PaymentComponent') {
219      name = 'PaymentComponent'
220    }
221
222    var path = base_url + 'frontend/js/' + name + '.js',
223      sLen = App.loaded.length;
224
225    for (var i = 0; i < sLen; i++) {
226      if (App.loaded[i] == path) {
227        App.initCallback(successCallback);
228        return true;
229      }
230    }
231
232    App.initCallback(beforeCallback);
233
234    $.getScript(path, function () {
235      App.loaded.push(path);
236      App.initCallback(successCallback);
237    });
238
239  },
240
241  objLen: function (obj) {
242    var count = 0;
243
244    $.each(obj, function (att, current) {
245      if (typeof current === 'object' && current !== null) {
246        count++;
247      }
248    });
249
250    return count;
251  },
252
253  //Métodos Genéricos
254  initCallback: function (callback, data, context) {
255    context = (context) ? context : this;
256
257    if (typeof callback == 'function') {
258      callback.call(context, data);
259    }
260  },
261
262  isValidCallback: function (callback) {
263    return (typeof callback == 'function');
264  },
265  emptyCartIcon: function () {
266    $('.list-products-shopping-cart ul').children('li').remove();
267    $('.shopping-cart-total-products').html('0');
268    $('.shopping-cart-total-price, .total-price-shopping-cart').each(function (index, element) {
269      $(element).html('Seu carrinho está vazio');
270    });
271    $('.cart-action-buttons').hide();
272  },
273  deleteProductIcon: function (cart) {
274    comb = $('.cart-comb-' + cart.CatalogoCarrinho.estoque_id).remove();
275    App.refreshCartIcon(cart);
276  },
277
278  refreshCartIcon: function (cart) {
279    var totalProdBox = $('.shopping-cart-total-products'),
280      totalItens = $('.list-products-shopping-cart').first().children('ul').children('li').length;
281    del = (typeof del === 'undefined') ? false : del;
282
283    if (cart.CatalogoCarrinho) {
284      cart.total_carrinho = cart.CatalogoCarrinho.valor_total_produtos;
285      cart.estoque_id = cart.CatalogoCarrinho.estoque_id;
286    }
287
288    if (totalItens) {
289      cart.count_itens = totalItens;
290    } else {
291      cart.count_itens = '';
292    }
293
294    if (cart.count_itens) {
295      totalProdBox.html(cart.count_itens);
296    } else {
297      totalProdBox.html('');
298    }
299
300    $('.shopping-cart-total-price,.total-price-shopping-cart').each(function (index, element) {
301      $(element).html(cart.total_carrinho);
302    });
303
304    $('.cart-action-buttons').show();
305  },
306
307  addProductIcon: function (cart, img) {
308    if ($(img[0]).parent().hasClass('noimage')) {
309      img = $(img[0]).parent();
310    }
311
312    //Adapta função para result sets diferentes
313    if (cart.CatalogoCarrinho) {
314      cart = {
315        'nome_produto': cart.CatalogoCarrinhoProduto.nome_produto,
316        'total_produto': cart.CatalogoCarrinhoProduto.valor_total,
317        'quantidade_produto': cart.CatalogoCarrinhoProduto.quantidade_produto,
318        'estoque_id': cart.CatalogoCarrinhoProduto.estoque_id,
319        'total_carrinho': cart.CatalogoCarrinho.valor_total_produtos,
320        'combinacoes': cart.CatalogoCarrinhoProduto.combinacoes
321      }
322    }
323
324    var comb = $('.cart-comb-' + cart['estoque_id']);
325    img = $(img).clone();
326
327    if (!comb.length) {
328      var prodList = $('.list-products-shopping-cart').children('ul');
329
330      var li = document.createElement('li');
331      tot = $('.total-price-shopping-cart-wrapper'),
332        li.className = 'cart-comb-' + cart['estoque_id'];
333
334      var divImage = document.createElement('div');
335      divImage.className = 'img-product-shopping-cart';
336      $(divImage).append(img);
337
338      $(li).append(divImage);
339
340      var combinacao = JSON.parse(cart['combinacoes']);
341
342      if (combinacao.length > 0) {
343
344        var conteudo = '<span class="name-product-shopping-cart">' + cart['nome_produto'] + (cart['quantidade_produto'] > 1 ? ' (' + cart['quantidade_produto'] + ')' : '');
345
346        $.each(combinacao, function (index, value) {
347          conteudo += '<br/><span>' + value.Combinacao.combinacao + ': ' + value.Combinacao.atributo + '</span>';
348        });
349
350        conteudo += '</span>';
351
352        li.innerHTML += conteudo;
353
354      } else {
355        li.innerHTML += '<span class="name-product-shopping-cart">' + cart['nome_produto'] + (cart['quantidade_produto'] > 1 ? ' (' + cart['quantidade_produto'] + ')' : '') + '</span>';
356      }
357
358      li.innerHTML += '<span class="price-product-shopping-cart">' + cart['total_produto'] + '</span>';
359
360      prodList.append(li);
361
362    } else {
363
364      var combinacao = JSON.parse(cart['combinacoes']);
365
366      if (combinacao.length > 0) {
367
368        var conteudo = cart['nome_produto'] + ' (' + cart['quantidade_produto'] + ')';
369
370        $.each(combinacao, function (index, value) {
371          conteudo += '<br/><span>' + value.Combinacao.combinacao + ': ' + value.Combinacao.atributo + '</span>';
372        });
373
374        conteudo += '</span>';
375
376        comb.children('.name-product-shopping-cart').html(conteudo);
377
378      } else {
379        comb.children('.name-product-shopping-cart').html(cart['nome_produto'] + ' (' + cart['quantidade_produto'] + ')');
380      }
381
382      comb.children('.price-product-shopping-cart').html(cart['total_produto']);
383    }
384
385    App.refreshCartIcon(cart);
386  }
387}

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.