· 10 years ago · Jun 21, 2016, 08:12 PM
1var neemuPlugin=neemuPlugin||{};(function(window,document,undefined,$){var _nm = window._nm =window._nm||{};_nm.buildDate='21_06_2016';(function(window, document) {
2/**
3 * Copyright (c) 2015 - Neemu Serviços em Tecnologia da Informação S.A
4 *
5 * LICENSE: This software is the confidential and proprietary information of
6 * Neemu S.A ("Confidential Information"). You shall not disclose such
7 * Confidential Information and shall use it only in accordance with the terms
8 * of the license agreement you entered into with Neemu S.A.
9 */
10
11
12
13 if (!Function.prototype.bind) {
14 Function.prototype.bind = function(oThis) {
15 if (typeof this !== 'function') {
16 // closest thing possible to the ECMAScript 5
17 // internal IsCallable function
18 throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
19 }
20
21 var aArgs = Array.prototype.slice.call(arguments, 1),
22 fToBind = this,
23 fNOP = function() {},
24 fBound = function() {
25 return fToBind.apply(this instanceof fNOP && oThis
26 ? this
27 : oThis,
28 aArgs.concat(Array.prototype.slice.call(arguments)));
29 };
30
31 fNOP.prototype = this.prototype;
32 fBound.prototype = new fNOP();
33
34 return fBound;
35 };
36 }
37
38 if (!String.prototype.trim) {
39 String.prototype.trim = function () {
40 return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
41 };
42 }
43
44 // Passos para a produção do ECMA-262, Edition 5, 15.4.4.14
45// Referência: http://es5.github.io/#x15.4.4.14
46if (!Array.prototype.indexOf) {
47 Array.prototype.indexOf = function(elementoDePesquisa, pontoInicial) {
48
49 var k;
50
51 //1. Deixe-o ser o resultado da chamada de toObject
52 // passando o valor de this como argumento.
53 if (this == null) {
54 throw new TypeError('"this" é nulo (null) ou não foi definido (undefined');
55 }
56
57 var O = Object(this);
58
59 // 2. Deixar o tamanhoValor ser o resultado da
60 // chamada do método interno Get de 0 com o
61 // argumento "length"
62 // 3. Deixar o tamanhoValor ser um ToUint32(tamanhoValor).
63 var tamanho = O.length >>> 0;
64
65 // 4. se o tamanho é 0, retorna -1.
66 if (tamanho === 0) {
67 return -1;
68 }
69
70 // 5. Se o argumento pontoInicial for passado, use o ToInteger(pontoInicial); senao use 0.
71 var n = + pontoInicial || 0;
72
73 if (Math.abs(n) === Infinity) {
74 n = 0;
75 }
76
77 //6. Se n >= tamanho, retorna -1.
78 if (n >= tamanho) {
79 return -1;
80 }
81
82 // 7. Se n>= 0, entao k seja n.
83 // 8. Senao, n<0, k seja tamanho - abs(n).
84 // Se k é menor que 0, entao k seja 0.
85 k = Math.max(n >= 0 ? n : tamanho - Math.abs(n), 0);
86
87 // 9. Repita, enquanto k < tamanho
88 while (k < tamanho) {
89 // a. Deixe Pk ser ToString(k).
90 // isto é implicito para operandos LHS de um operador
91
92 // b. Deixe o kPresent ser o resultado da chamada do método interno de 0 com argumento Pk
93 // Este passo pode ser combinado com c.
94 // c. Se kPresent é true, entao
95 // i. Deixe o elementK ser o resultado da chamada do metodo interno Get de 0 com argumento ToString(k)
96 // ii. Deixe o resultado ser aplicado pelo Algoritmo de
97 // Comparação de Igualdade Estrita (Strict Equality Comparison) para o elementoDePesquisa e elementK
98 // iii. caso verdadeiro, retorne k.
99 if (k in O && O[k] === elementoDePesquisa) {
100 return k;
101 }
102 k++;
103 }
104 return -1;
105 };
106}
107
108if (!window.getComputedStyle) {
109 window.getComputedStyle = function(el, pseudo) {
110 this.el = el;
111 this.getPropertyValue = function(prop) {
112 var re = /(\-([a-z]){1})/g;
113 if (prop == 'float') prop = 'styleFloat';
114 if (re.test(prop)) {
115 prop = prop.replace(re, function () {
116 return arguments[2].toUpperCase();
117 });
118 }
119 return el.currentStyle[prop] ? el.currentStyle[prop] : null;
120 }
121 return this;
122 }
123}
124
125if (!document.getElementsByClassName) {
126 var indexOf = [].indexOf || function(prop) {
127 for (var i = 0; i < this.length; i++) {
128 if (this[i] === prop) return i;
129 }
130 return -1;
131 };
132 getElementsByClassName = function(className, context) {
133 var elems = document.querySelectorAll ? context.querySelectorAll("." + className) : (function() {
134 var all = context.getElementsByTagName("*"),
135 elements = [],
136 i = 0;
137 for (; i < all.length; i++) {
138 if (all[i].className && (" " + all[i].className + " ").indexOf(" " + className + " ") > -1 && indexOf.call(elements, all[i]) === -1) elements.push(all[i]);
139 }
140 return elements;
141 })();
142 return elems;
143 };
144 document.getElementsByClassName = function(className) {
145 return getElementsByClassName(className, document);
146 };
147 var Element = Element || null;
148 if(Element) {
149 Element.prototype.getElementsByClassName = function(className) {
150 return getElementsByClassName(className, this);
151 };
152 }
153}
154
155// Production steps of ECMA-262, Edition 5, 15.4.4.19
156// Reference: http://es5.github.io/#x15.4.4.19
157if (!Array.prototype.map) {
158
159 Array.prototype.map = function(callback, thisArg) {
160
161 var T, A, k;
162
163 if (this == null) {
164 throw new TypeError(' this is null or not defined');
165 }
166
167 // 1. Let O be the result of calling ToObject passing the |this|
168 // value as the argument.
169 var O = Object(this);
170
171 // 2. Let lenValue be the result of calling the Get internal
172 // method of O with the argument "length".
173 // 3. Let len be ToUint32(lenValue).
174 var len = O.length >>> 0;
175
176 // 4. If IsCallable(callback) is false, throw a TypeError exception.
177 // See: http://es5.github.com/#x9.11
178 if (typeof callback !== 'function') {
179 throw new TypeError(callback + ' is not a function');
180 }
181
182 // 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
183 if (arguments.length > 1) {
184 T = thisArg;
185 }
186
187 // 6. Let A be a new array created as if by the expression new Array(len)
188 // where Array is the standard built-in constructor with that name and
189 // len is the value of len.
190 A = new Array(len);
191
192 // 7. Let k be 0
193 k = 0;
194
195 // 8. Repeat, while k < len
196 while (k < len) {
197
198 var kValue, mappedValue;
199
200 // a. Let Pk be ToString(k).
201 // This is implicit for LHS operands of the in operator
202 // b. Let kPresent be the result of calling the HasProperty internal
203 // method of O with argument Pk.
204 // This step can be combined with c
205 // c. If kPresent is true, then
206 if (k in O) {
207
208 // i. Let kValue be the result of calling the Get internal
209 // method of O with argument Pk.
210 kValue = O[k];
211
212 // ii. Let mappedValue be the result of calling the Call internal
213 // method of callback with T as the this value and argument
214 // list containing kValue, k, and O.
215 mappedValue = callback.call(T, kValue, k, O);
216
217 // iii. Call the DefineOwnProperty internal method of A with arguments
218 // Pk, Property Descriptor
219 // { Value: mappedValue,
220 // Writable: true,
221 // Enumerable: true,
222 // Configurable: true },
223 // and false.
224
225 // In browsers that support Object.defineProperty, use the following:
226 // Object.defineProperty(A, k, {
227 // value: mappedValue,
228 // writable: true,
229 // enumerable: true,
230 // configurable: true
231 // });
232
233 // For best browser support, use the following:
234 A[k] = mappedValue;
235 }
236 // d. Increase k by 1.
237 k++;
238 }
239
240 // 9. return A
241 return A;
242 };
243}
244
245/**
246 * Module which contains utilitarian functions
247 *
248 * @author Javier Zambrano <javier@neemu.com>
249 * @author Andrews Lince <andrews@neemu.com>
250 * @version 2.2.0
251 * @param {Object} window
252 * @param {Object} document
253 * @return {Object}
254 */
255function Commons(){}
256
257var cm = Commons.prototype;
258
259/**
260 * Default ajax request
261 *
262 * @author Andrew C. Pacifico <andrewpacifico@neemu.com>
263 * @method ajax
264 * @param {Object} options A set of key/value pairs that configure
265 * the Ajax request.
266 * @param {Object} options.url A string containing the URL to which the request
267 * is sent. This parameter is obrigatory.
268 * @param {Object} options.type The method of request. The default value is 'GET'
269 * @param {Object} options.data Data to be sent to the server. It is converted
270 * to a query string,
271 * @return {Void}
272 */
273cm.ajax = function(options) {
274 var callback = (typeof options.callback === 'function')
275 ? options.callback
276 : function(data) {};
277
278 var requestData = (typeof options.data === 'object') ? options.data : {};
279
280 var requestMethod = (
281 options.type === undefined
282 || (
283 options.type.toUpperCase() !== 'GET'
284 && options.type.toUpperCase() !== 'POST'
285 )
286 )
287 ? 'GET'
288 : options.type.toUpperCase();
289
290 if (typeof options.url !== 'string' && options.url === '') {
291 return;
292 }
293
294 var xhr = new XMLHttpRequest();
295 xhr.onreadystatechange = function() {
296 if (xhr.readyState == XMLHttpRequest.DONE) {
297 if(xhr.status == 200) {
298 var responseData;
299 try {
300 responseData = JSON.parse(xhr.responseText);
301 } catch(e) {
302 responseData = xhr.responseText;
303 }
304 callback(responseData);
305 } else if(xhr.status == 400) {
306 console.log('There was an error 400')
307 } else {
308 console.log('something else other than 200 was returned')
309 }
310 }
311 }
312
313 // encode request data
314 var query = [];
315 for(var param in requestData) {
316 query.push(param + '=' + encodeURIComponent(requestData[param]));
317 }
318 var encodedData = query.join('&');
319 var url = (requestMethod === 'POST')
320 ? options.url
321 : options.url +
322 (options.url.indexOf('?') >= 0 ? '&' : '?') +
323 encodedData;
324
325 xhr.open(requestMethod, url, true);
326 if (requestMethod === 'POST') {
327 xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
328 xhr.send(encodedData);
329 } else {
330 xhr.send();
331 }
332}
333;
334/**
335 * Ajax request using JSONP
336 * @author Ivanildo de castro <ivanildocastro@neemu.com>
337 * @since 1.0.0
338 * @param {Object} options
339 * - {String} url
340 * - {Boolean} async[optional],
341 * - {Function} success
342 * - {Object} data[optional]
343 * @return {Void}
344 */
345cm.ajaxJsonp = function(options){
346 //-----------------------------------------------------------------------------------------
347 var
348 url = (typeof options.url === 'string')?options.url:'',
349 async = (typeof options.async === 'boolean')?options.async:true,
350 callback = options.success?options.success:function(){},
351 data = (typeof options.data === 'object')?options.data:'',
352 //-----------------------------------------------------------------------------------------
353 callbackName = 'jsonp_neemu_callback_' + (new Date()).getTime(),
354 scriptTag = document.createElement('script');
355 //-----------------------------------------------------------------------------------------
356 var head = document.head || document.getElementsByTagName('head')[0];
357
358
359 window[callbackName] = function(data){
360 try{
361 delete window[callbackName];
362 }catch(e){
363 window[callbackName] = undefined;
364 }
365
366 head.removeChild(scriptTag);
367 if(typeof callback === 'function' && !scriptTag.ajaxAbort){
368 callback(data);
369 }
370 }.bind(this);
371 //-----------------------------------------------------------------------------------------
372 if(data){
373 var query = [];
374 for(var i in data){
375 query.push(i+'='+data[i]);
376 }
377 data = query.join('&');
378 }
379 //-----------------------------------------------------------------------------------------
380 url = url + (url.indexOf('?') >= 0 ? '&' : '?') + 'callback=' + callbackName + '&'+data;
381 //-----------------------------------------------------------------------------------------
382 scriptTag.async = async;
383 scriptTag.src = url;
384 scriptTag.setAttribute('ajax_jsonp', 'neemu_plugin');
385
386 head.appendChild(scriptTag);
387
388 //-----------------------------------------------------------------------------------------
389}
390;
391/**
392 * Aborta a requst jsonp do método ajaxJsonp
393 * @author Ivanildo de castro <ivanildocastro@neemu.com>
394 * @since 2.2.0
395 */
396cm.ajaxJsonpAbort = function(){
397 var o = this.querySelectorAll('script[ajax_jsonp=neemu_plugin]');
398 for(var i = 0;i<o.length;i++){
399 o[i].ajaxAbort = true;
400 }
401};
402/**
403 * Simulates a ajax request using JSONP
404 *
405 * @author Andrews Lince <andrews@neemu.com>
406 * @since 1.0.0
407 * @param {String} url
408 * @return {Void}
409 */
410cm.ajaxRequestJsonp = function(url) {
411 document
412 .getElementsByTagName("head")[0]
413 .appendChild(this.createElement("script", {
414 "src": url
415 }));
416};
417/**
418 * Remove a list of items from a given array.
419 *
420 * @author Andrew C. Pacifico <andrewpacifico@neemu.com>
421 * @param {Array} array The array to remove the elements.
422 * @param {Array} items The list elements to remove.
423 */
424cm.arrayRemove = function(array, items) {
425
426 for (var i = 0, len = items.length; i < len; ++i) {
427 var index = array.indexOf(items[i]);
428
429 if (index !== -1) {
430 array.splice(index, 1);
431 }
432 }
433
434}
435;
436/**
437 * Randomize the elements of a given array.
438 *
439 * @author Andrew C. Pacifico <andrewpacifico@neemu.com>
440 * @param {Array} array The array to shuffle the elements.
441 * @return {Array} The shuffled array
442 */
443cm.arrayShuffle = function(array) {
444 var currentIndex = array.length, temporaryValue, randomIndex ;
445
446 // While there remain elements to shuffle...
447 while (0 !== currentIndex) {
448
449 // Pick a remaining element...
450 randomIndex = Math.floor(Math.random() * currentIndex);
451 currentIndex -= 1;
452
453 // And swap it with the current element.
454 temporaryValue = array[currentIndex];
455 array[currentIndex] = array[randomIndex];
456 array[randomIndex] = temporaryValue;
457 }
458
459 return array;
460}
461;
462/**
463 * Sort a array of objects by specific field that object
464 *
465 * @since 1.0.0
466 * @{@link http://stackoverflow.com/a/979325}
467 * @example
468 *
469 * var testArray = [
470 * {
471 * index : "2",
472 * name : "title2"
473 * },
474 * {
475 * index : "1",
476 * name : "title1"
477 * }
478 * ];
479 *
480 * testArray.sort(_nm.commons.arraySortBy(
481 * "index", // field sort
482 * false // ascending
483 * ));
484 *
485 * // returns
486 * [
487 * {
488 * index : "1",
489 * name : "title1"
490 * },
491 * {
492 * index : "2",
493 * name : "title2"
494 * }
495 * ]
496 *
497 * @param {String} field
498 * @param {Boolean} reverse
499 * @param {Function} primer
500 * @return {Array}
501 */
502cm.arraySortBy = function(field, reverse, primer) {
503
504 // default primer as parseInt
505 if (primer === undefined) {
506 primer = parseInt;
507 }
508
509 var key = primer
510 ? function(x) { return primer(x[field]) }
511 : function(x) { return x[field] };
512
513 reverse = !reverse ? 1 : -1;
514
515 return function (a, b) {
516 return a = key(a), b = key(b), reverse * ((a > b) - (b > a));
517 }
518};
519/**
520 * Check one condition periodically until it is true or reaches
521 * the retry limit
522 *
523 * @author Jhozefem Pontes <jhozefem@neemu.com>
524 * @since 1.0.0
525 * @param {Integer} max maximum number of retry
526 * @param {Integer} time time interval between retry
527 * @param {Function} fnCheck callback check
528 * @param {Function} fnCallback callback which will be executed if the
529 * check function is true
530 * @return {Void}
531 */
532cm.checkConditionInterval = function(max, time, fnCheck, fnCallback) {
533 var qtty = 0,
534 response,
535 returnType = "success",
536 fnCheckInterval = setInterval(function() {
537 qtty++;
538
539 try {
540 response = fnCheck();
541 } catch(e) {
542 response = false;
543 }
544
545 if (response !== false || qtty >= max) {
546 clearInterval(fnCheckInterval);
547 if(qtty >= max) {
548 returnType = "error";
549 }
550 fnCallback(returnType, response);
551 }
552 }, time);
553};
554/**
555 * Remove a cookie
556 *
557 * reference: https://developer.mozilla.org/en-US/docs/DOM/document.cookie
558 * @author Jhozefem Pontes <jhozefem@neemu.com>
559 * @since 1.0.0
560 * @param {String} name
561 * @param {String} host
562 * @return {Void}
563 */
564cm.deleteCookie = function(name, host) {
565 this.setCookie(name, '', -1, '/', host);
566};
567/**
568 * Returns a cookie by your name
569 *
570 * @author Jhozefem Pontes <jhozefem@neemu.com>
571 * @author Andrews Lince <jhozefem@neemu.com>
572 * @since 1.0.0
573 * @param {String} name
574 * @return {Void}
575 */
576cm.getCookie = function(name) {
577 var cValue = document.cookie.replace(
578 new RegExp(
579 "(?:(?:^|.*;)\\s*"
580 + encodeURIComponent(name).replace(/[\-\.\+\*]/g, "\\$&")
581 + "\\s*\\=\\s*([^;]*).*$)|^.*$"
582 ),
583 "$1"
584 );
585 cValue = this.decodeUrl(cValue);
586
587 return cValue || undefined;
588};
589/**
590 * Set a cookie on the browser
591 *
592 * @author Jhozefem Popntes <jhozefem@neemu.com>
593 * @author Andrews Lince <andrews@neemu.com>
594 * @since 1.0.0
595 * @param {String} cName
596 * @param {String} sValue
597 * @param {Integer} vEnd
598 * @param {String} sPath
599 * @param {String} sDomain
600 * @param {Boolean} bSecure
601 * @return {Void}
602 */
603cm.setCookie = function(cName, sValue, vEnd, sPath, sDomain, bSecure) {
604 if (vEnd != Infinity && typeof(vEnd) == 'number') {
605 var minutes = vEnd;
606 vEnd = new Date();
607 vEnd.setTime(vEnd.getTime() + (minutes * 60 * 1000));
608 }
609
610 if (!cName || /^(?:expires|max\-age|path|domain|secure)$/i.test(cName)) {
611 return false;
612 }
613
614 var sExpires = "";
615 if (vEnd) {
616 switch (vEnd.constructor) {
617 case Number:
618 sExpires = (vEnd === Infinity)
619 ? "; expires=Fri, 31 Dec 9999 23:59:59 GMT"
620 : "; max-age=" + vEnd;
621 break;
622 case String:
623 sExpires = "; expires=" + vEnd;
624 break;
625 case Date:
626 //sExpires = "; expires=" + vEnd.toUTCString();
627 sExpires = "; expires=" + vEnd.toString();
628 break;
629 }
630 }
631
632 document.cookie = encodeURIComponent(cName)
633 + "=" + encodeURIComponent(sValue)
634 + sExpires
635 + (sDomain ? "; domain=" + sDomain : "")
636 + (sPath ? "; path=" + sPath : "")
637 + (bSecure ? "; secure" : "");
638
639 return true;
640};
641/**
642 * Call a function after which the HTML page is totally loaded
643 *
644 * @author Jhozefem Pontes <jhozefem@neemu.com>
645 * @since 1.0.0
646 * @param {Function} callbackFunction
647 * @return {Void}
648 */
649cm.domReady = function(callbackFunction) {
650 var win = window;
651 if(document.readyState === "complete") {
652 callbackFunction();
653 } else if (win.addEventListener) {
654 win.addEventListener("load", callbackFunction);
655 } else {
656 win.attachEvent("onload", callbackFunction);
657 }
658};
659/**
660 * Cria animações com os style do DOM element
661 * @author Ivanildo de Castro <ivanildocastro@neemu.com>
662 * @since 2.1.0
663 * @param {Object} element
664 * @param {Object} properties
665 * @param {Integer} time
666 * @param {Function} callback[optional]
667 */
668cm.animate = function(element, properties, time, callback){
669 if(typeof element === 'object' && element.nodeType === 1 && typeof properties === 'object'){
670
671 var options = {}, o, property, start, end;
672
673 for(var i in properties){
674 property = i.replace(/-[a-z]{1}/g, function($1){
675 return $1[1].toUpperCase();
676 });
677
678 start = parseInt(
679 element.style[property] ||
680 window
681 .getComputedStyle(element,null)
682 .getPropertyValue(property.replace(/[A-Z]{1}/g, function($1){
683 return '-' + $1.toLowerCase();
684 }))
685 );
686
687 if(!start && ['height', 'width'].indexOf(property) !== -1){
688
689 var propertyOffset = 'offset'+property.replace(/^[A-z]{1}/, function($1){
690 return $1.toUpperCase();
691 });
692
693 start = element[propertyOffset];
694 }else if(!start){
695 start = 0;
696 }
697
698 end = properties[i];
699 end = (end > start)?(end - start):(start - end);
700
701 o = {
702 start:start,
703 step:(end/time),
704 end:properties[i]
705 };
706
707 o.step = ((o.start < o.end)?1:-1) * o.step;
708 options[property] = o;
709 }
710
711 setTimeout(
712 function(element, options, timeStart, time, callback){
713 timeStart++;
714
715 if(timeStart > time){
716 if(typeof callback === 'function'){
717 callback.call(element, element);
718 }
719 }else{
720
721 for(var i in options){
722 var
723 o = options[i],
724 start = o.start + o.step;
725
726 o.start = start;
727 element.style[i] = start + 'px';
728 }
729
730 setTimeout(
731 arguments.callee.bind(
732 this,
733 element,
734 options,
735 timeStart,
736 time,
737 callback), 1);
738 }
739 }.bind(
740 {},
741 element,
742 options,
743 0,
744 time,
745 callback
746 ), 1);
747 }
748};
749/**
750 * Cria animações de alerta vibrante :)
751 * @author Ivanildo de Castro <ivanildocastro@neemu.com>
752 * @since 2.1.0
753 * @param {Object} element
754 * @param {Integer} intShakes
755 * @param {Integer} intDistance
756 * @param {Integer} intDuration
757 * @param {Function} callback[optional]
758 * @param {Integer} count(Obs.:controle interno da função, nuca será necessário usar externamente)
759 */
760cm.shake = function(element, intShakes, intDistance, intDuration, callback, count){
761
762 if(!element.inShakes){
763
764 element.inShakes = true;
765 count = (!count && count === undefined)?intShakes:count;
766
767 if(count > 0){
768 var
769 thisShake = arguments.callee,
770 marginLeftInitial = parseInt(
771 element.style.marginLeft ||
772 window.getComputedStyle(element,null).getPropertyValue('margin-left')
773 );
774
775 //1# animação
776 this.animate(
777 element,
778 {marginLeft:marginLeftInitial + (intDistance*-1)},
779 parseInt(((intDuration/intShakes)/4)),
780 //2# animação
781 this.animate.bind(
782 this,
783 element,
784 {marginLeft:marginLeftInitial + intDistance},
785 parseInt((intDuration/intShakes)/2),
786 //3# animação
787 this.animate.bind(
788 this,
789 element,
790 {marginLeft:marginLeftInitial},
791 parseInt(((intDuration/intShakes)/4)),
792 //4# loop
793 function(){
794 delete element.inShakes;
795 thisShake.call(
796 this,
797 element,
798 intShakes,
799 intDistance,
800 intDuration,
801 callback,
802 count - 1
803 )
804 }.bind(this)
805 )
806 )
807 );
808
809 }else{
810 delete element.inShakes;
811 }
812
813 //para executar quando iniciar a animação
814 if(typeof callback === 'function' && count === 0){
815 callback(element);
816 }
817 }
818};
819/**
820 * Manage the event register in a object
821 *
822 * @author Jhozefem Pontes <jhozefem@neemu.com>
823 * @author Andrews Lince <andrews@neemu.com>
824 * @since 1.0.0
825 * @param {Array} objects
826 * @param {String} event
827 * @param {Function} callback
828 * @return {Void}
829 */
830cm.addEventListener = function(objects, event, callback) {
831 var type = Object.prototype.toString.call(objects);
832 if(type !== "[object NodeList]" && type !== "[object Array]") {
833 objects = [ objects ];
834 }
835
836 for(var index = 0; index < objects.length; index++) {
837 if(objects[index] === undefined) {
838 break;
839 }
840
841 if(typeof(objects[index].addEventListener) === "function") {
842 objects[index].addEventListener(event, callback, false);
843 } else {
844 objects[index].attachEvent("on" + event, callback);
845 }
846 }
847};
848/**
849 * Remove the event in a object
850 * @author Ivanildo de Castro <ivanildocastro@neemu.com>
851 * @since 1.0.0
852 * @param {Array} objects
853 * @param {String} event
854 * @param {Function} callback
855 * @return {Void}
856 */
857cm.removeEventListener = function(objects, event, callback) {
858 var type = Object.prototype.toString.call(objects);
859 if(type !== "[object NodeList]" && type !== "[object Array]") {
860 objects = [ objects ];
861 }
862
863 for(var index = 0; index < objects.length; index++) {
864 if(objects[index] === undefined) {
865 break;
866 }
867
868 if(typeof(objects[index].removeEventListener) === "function") {
869 objects[index].removeEventListener(event, callback, false);
870 } else {
871 objects[index].detachEvent("on" + event, callback);
872 }
873 }
874};
875/**
876 * Param de executar o evento para os demais filhos do objeto
877 * @author Ivanildo de Castro <ivanildocastro@neemu.com>
878 * @since 2.1.0
879 * @param {Object} event
880 */
881cm.stopPropagation = function(event){
882 if(event.preventDefault){
883 event.preventDefault();
884 }
885
886 if(event.stopPropagation){
887 event.stopPropagation();
888 }
889
890 event.cancelBubble = true;
891};
892/**
893 * Format a number from currency option
894 *
895 * @author Jhozefem Pontes <jhozefem@neemu.com>
896 * @author Andrews Lince <andrews@neemu.com>
897 * @since 1.0.0
898 * @param {Number} value
899 * @param {String} currency
900 * @return {String}
901 */
902cm.formatCurrency = function(value, currency) {
903
904 // checks if value is valid
905 if(value === undefined) {
906 return value;
907 }
908
909 // sets the default currency which brazilian
910 // if (currency === undefined) {
911 // // currency = "BRL";
912 // currency = "";
913 // }
914
915 var finalValue = "";
916
917 value = value.toString();
918
919 // checks if the value is rounded and has no decimal places
920 if (
921 !this.strstr(value, ",")
922 && !this.strstr(value, ".")
923 ) {
924 value = value + ".00";
925 }
926
927 //removendo if else que não vai ser preciso pela condições
928 //if(value.match(/[^0-9]+/g) != null) {
929 value = value.replace(/[^0-9,\.]+/g, '');
930
931 if(value.indexOf(",") !== -1) {
932 value = value.replace(/\./g, "").replace(",", ".");
933 }
934
935 finalValue = parseFloat(value);
936 //} else {
937 // finalValue = (parseFloat(value) / 100);
938 //}
939
940 // return finalValue.toFixed(2) + " " + currency.trim();
941 return finalValue.toFixed(2);
942};
943/**
944 * Get all the url parameters (by query string)
945 *
946 * @author Andrews Lince <andrews@neemu.com>
947 * @since 1.0.0
948 * @return {Object}
949 */
950cm.getRequestParams = function() {
951 var requestParams = {},
952 reqParts = [],
953 nextIndex = 0,
954 currentRequestParams = this.decodeUrl(window.location.search)
955 .substr(1).split("&");
956
957 for (var i = 0; i < currentRequestParams.length; i++) {
958 reqParts = currentRequestParams[i].split("=");
959 nextIndex = i + 1;
960
961 // validate if the next index contains "="
962 if (
963 currentRequestParams[nextIndex] !== undefined
964 && !this.strstr(currentRequestParams[nextIndex], "=")
965 ) {
966 // append the valur from the next index
967 reqParts[1] += "&" + currentRequestParams[nextIndex];
968
969 // remove next index
970 currentRequestParams.splice(nextIndex, 1);
971 }
972
973 requestParams[reqParts[0]] = reqParts[1];
974 }
975
976 return requestParams;
977};;
978/**
979 * Checks if is a mobile environment
980 *
981 * @author Jhozefem Pontes <jhozefem@neemu.com>
982 * @since 1.0.0
983 * @return {Boolean} [description]
984 */
985cm.isMobile = function() {
986 var check = false;
987
988 (function(a){
989 if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) {
990 check = true;
991 }
992 })(navigator.userAgent||navigator.vendor||window.opera);
993
994 return check;
995};
996/**
997 * Checks if the current page is a neemu search (with and without ajax)
998 *
999 * @author Andrews Lince <andrews@neemu.com>
1000 * @since 1.0.0
1001 * @param {String} email
1002 * @return {Boolean}
1003 */
1004cm.isNeemuSearch = function(){
1005 return (window.NeemuSearch !== undefined)
1006 ? true
1007 : false;
1008};
1009/**
1010 * Checks if the current page is a neemu search
1011 *
1012 * @author Andrews Lince <andrews@neemu.com>
1013 * @since 1.0.0
1014 * @param {String} string
1015 * @return {Boolean}
1016 */
1017cm.isSearchFilter = function(string) {
1018 return (
1019 this.strstr(string, "common_filter")
1020 || this.strstr(string, "range_filter")
1021 )
1022 ? true
1023 : false;
1024};
1025/**
1026 * Performs a regex validation in a string and returns if is a valid
1027 * email or not
1028 *
1029 * @author Jhozefem Pontes <jhozefem@neemu.com>
1030 * @author Andrews Lince <andrews@neemu.com>
1031 * @since 1.0.0
1032 * @param {String} email
1033 * @return {Boolean}
1034 */
1035cm.isValidEmail = function(email) {
1036 var isValidEmail = false,
1037 regexPattern = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
1038
1039 if (email !== undefined && typeof(email) === "string") {
1040 isValidEmail = regexPattern.test(email);
1041 }
1042
1043 return isValidEmail;
1044};
1045/**
1046 * Checks if a variable exists
1047 *
1048 * @author Javier Ferreira <javier@neemu.com>
1049 * @since 1.0.0
1050 * @param {Mixed} variable
1051 * @return {Boolean}
1052 */
1053cm.isset = function(variable) {
1054 return variable !== undefined && variable !== null;
1055};
1056/**
1057 * Include a script (js or css) in the page and register the file in a
1058 * queue, for manage this files
1059 *
1060 * @author Andrews Lince <andrews@neemu.com>
1061 * @since 1.0.0
1062 * @param {String} source
1063 * @param {Function} callback
1064 * @return {Void}
1065 */
1066cm.loadFile = function(source, callback) {
1067 var file = undefined,
1068 doc = document;
1069
1070 if (this.strstr(source, ".js")) {
1071 file = doc.createElement('script');
1072 file.setAttribute("type","text/javascript");
1073 file.setAttribute("async", 'true');
1074 file.setAttribute("src", source);
1075 } else if (this.strstr(source, ".css")) {
1076 file = doc.createElement("link");
1077 file.setAttribute("rel", "stylesheet");
1078 file.setAttribute("type", "text/css");
1079 file.setAttribute("href", source);
1080 }
1081
1082 // append in the HEAD element
1083 if (file !== undefined) {
1084 doc.getElementsByTagName('head')[0].appendChild(file);
1085
1086 if(typeof(file.readyState) !== "undefined") {
1087 file.onreadystatechange = function() {
1088 if(
1089 file.readyState === "loaded"
1090 || file.readyState === "complete"
1091 ) {
1092 file.onreadystatechange = null;
1093
1094 if(typeof(callback) === "function") {
1095 callback();
1096 }
1097 }
1098 };
1099 } else {
1100 file.onload = function() {
1101 file.onload = null;
1102
1103 if(typeof(callback) === "function") {
1104 callback();
1105 }
1106 };
1107 }
1108 }
1109
1110 return file;
1111};
1112/**
1113 * Adiciona class ao objeto DOM
1114 * @author Ivanildo de Castro <ivanildocastro@neemu.com>
1115 * @since 2.0.0
1116 * @param {Object} element
1117 * @param {String} className
1118 * @return {Void}
1119 */
1120cm.addClass = function(element, className){
1121 var array = (typeof element === 'object' && element.length)?element:[element];
1122
1123 for(var i = 0; i < array.length ; i++){
1124 var c = array[i].className + '';
1125 c = c.trim().replace(/\s+/g, ' ');
1126 if(!(new RegExp('\\b'+className.trim()+'\\b','gi')).test(c)){
1127 c += ' '+className;
1128 }
1129 array[i].className = c;
1130 }
1131}
1132;
1133/**
1134 * Creates a HTML element
1135 *
1136 * @author Jhozefem Pontes <jhozefem@neemu.com>
1137 * @author Andrews Lince <andrews@neemu.com>
1138 * @since 1.0.0
1139 * @param {String} type DOM element
1140 * @param {Object} opt Objetos que representam os atributos do no
1141 * @return {Node}
1142 * @example
1143 * createElement("div", {
1144 * id : "neemu",
1145 * style : "margin-top:20px; color:red;"
1146 * });
1147 */
1148cm.createElement = function(type, opt) {
1149 var element = document.createElement(type);
1150 for (var name in opt) {
1151 if (name === "html") {
1152 element.innerHTML = opt[name];
1153 } else {
1154 element.setAttribute(name, opt[name]);
1155 }
1156 }
1157 return element;
1158};
1159/**
1160 * Encode a JSON object to the base 64 value
1161 *
1162 * @author Jhozefem Pontes <jhozefem@neemu.com>
1163 * @author Andrews Lince <andrews@neemu.com>
1164 * @since 1.0.0
1165 * @param {Object} value
1166 * @return {String}
1167 */
1168cm.encode = function(value) {
1169 var json = this.parseObjectToJSON(value);
1170
1171 return (window.btoa)
1172 ? window.btoa(unescape(encodeURIComponent(json)))
1173 : this.base64Encode(json);
1174};
1175/**
1176 * Checks if the object has some property
1177 *
1178 * @author Andrews Lince <andrews@neemu.com>
1179 * @since 1.0.0
1180 * @param {Object} obj
1181 * @return {Boolean}
1182 */
1183cm.objectIsEmpty = function(obj) {
1184 return (Object.getOwnPropertyNames(obj).length === 0)
1185 ? true
1186 : false;
1187};
1188/**
1189 * Merge the properties of two objects
1190 *
1191 * reference: http://stackoverflow.com/a/171256
1192 * @since 1.0.0
1193 * @param {Object} obj1
1194 * @param {Object} obj2
1195 * @return {Object}
1196 */
1197cm.objectMerge = function(obj1, obj2) {
1198 var obj3 = {};
1199 for (var attrname in obj1) { obj3[attrname] = obj1[attrname]; }
1200 for (var attrname in obj2) { obj3[attrname] = obj2[attrname]; }
1201 return obj3;
1202};
1203/**
1204 * Turn a object to the json string
1205 *
1206 * @author Jhozefem Pontes <jhozefem@neemu.com>
1207 * @since 1.0.0
1208 * @param {Object} obj
1209 * @return {String}
1210 */
1211cm.parseObjectToJSON = function(obj) {
1212
1213 /**
1214 * Prepare a string between double quotes to json
1215 *
1216 * @author Jhozefem Pontes <jhozefem@neemu.com>
1217 * @since 1.0.0
1218 * @param {String} string
1219 * @return {String}
1220 */
1221 function quoteString (string) {
1222 var escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
1223 meta = { '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\' };
1224
1225 escapable.lastIndex = 0;
1226 return escapable.test(string) ?
1227 '"' + string.replace(escapable, function(a)
1228 {
1229 var c = meta[a];
1230 return typeof c === 'string' ?
1231 c
1232 : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
1233 }) + '"' : '"' + string + '"';
1234 };
1235
1236 var type = typeof (obj);
1237
1238 if (type != "object" || obj === null) {
1239 if (type == "string") {
1240 obj = quoteString(obj);
1241 }
1242
1243 return String(obj);
1244 } else {
1245 var value,
1246 json = [],
1247 isArray = (obj && obj.constructor == Array);
1248
1249 for (var prop in obj) {
1250 value = obj[prop];
1251 type = typeof(value);
1252
1253 if (!isArray && (type == "function" || value === undefined)) {
1254 value = '';
1255 type = 'string';
1256 }
1257
1258 if (type == "string") {
1259 value = quoteString(value);
1260 } else if (type == "object" && value !== null) {
1261 value = this.parseObjectToJSON(value);
1262 }
1263
1264 if(type != "function" && value !== undefined) {
1265 json.push((isArray ? "" : '"' + prop + '":') + String(value));
1266 }
1267 }
1268
1269 return (isArray ? "[" : "{") + String(json) + (isArray ? "]" : "}");
1270 }
1271};
1272/**
1273 * Remove class do objeto DOM
1274 * @author Ivanildo de Castro <ivanildocastro@neemu.com>
1275 * @since 2.0.0
1276 * @param {Object} element
1277 * @param {String} className
1278 * @return {Void}
1279 */
1280cm.removeClass = function(element, className){
1281 var array = (typeof element === 'object' && element.length)?element:[element];
1282
1283 for(var i = 0; i < array.length ; i++){
1284 var c = array[i].className + '';
1285 array[i].className = c.replace(new RegExp('\s*'+className+'\s*','gi'), '').trim();
1286 }
1287};
1288/**
1289 * Defines the sku availability from value
1290 *
1291 * @author Andrews Lince <andrews@neemu.com>
1292 * @since 1.0.0
1293 * @param {Boolean|Integer|String} value
1294 * @return {Boolean}
1295 */
1296cm.processAvailability = function(value) {
1297 var availability = false;
1298
1299 switch (typeof(value)) {
1300 case "string" :
1301
1302 if (!isNaN(value) && (parseInt(value) > 0)) {
1303 availability = true;
1304 } else if (value.toLowerCase() === "true") {
1305 availability = true;
1306 }
1307
1308 break;
1309
1310 case "number" :
1311
1312 if (value > 0) {
1313 availability = true;
1314 }
1315
1316 break;
1317
1318 case "boolean" :
1319
1320 availability = value;
1321
1322 break;
1323 }
1324
1325 return (availability)
1326 ? 1
1327 : 0;
1328};
1329
1330cm.querySelectorAll = (function(){
1331
1332function isIE(v){
1333 var t = new RegExp('msie[ ]+'+v);
1334 return t.test(navigator.userAgent.toLowerCase());
1335}
1336
1337function toArray(o){
1338 if(o.length){
1339 var
1340 oo = [],
1341 i;
1342 for(i=0;i<o.length;i++){
1343 oo.push(o[i]);
1344 }
1345
1346 return oo;
1347 }
1348
1349 return [];
1350}
1351
1352/**
1353 * Classe de obter o elemento
1354 * @author ivanildo de castro
1355 */
1356function QuerySelectorAll(){
1357}
1358
1359var q = QuerySelectorAll.prototype;
1360
1361/**
1362 * Obtem o elemento pelo seletor
1363 * @param {String} selector
1364 * @param {Object} parent[optional]
1365 * @return {Array}
1366 */
1367q.get = function(selector, parent){
1368
1369 var elements = [];
1370
1371 if(typeof selector === 'string' && selector.trim().length){
1372
1373 selector = this.checkSelector(selector);
1374 var lengthi = selector.length, i, j, nElements;
1375
1376 if(lengthi){
1377 elements = [(parent || document)];
1378 for(i = 0;i < lengthi;i++){
1379 nElements = [];
1380 for(j = 0;j < elements.length;j++){
1381 nElements = nElements.concat(this.getBy(elements[j], selector[i]));
1382 }
1383 elements = nElements;
1384 if(elements.length === 0){
1385 break;
1386 }
1387 }
1388 }
1389 }
1390
1391 return elements;
1392};
1393
1394/**
1395 * Verifica o selector e retorna o array com o selector no formato
1396 * @param {String} selector
1397 * @return {Array}
1398 */
1399q.checkSelector = function(selector){
1400 return selector.replace(/(\[[^\[\]]*\])/g, function($1){
1401 return $1.replace(/\s+/g,'');
1402 }).replace(/\s*\>\s*/g, ' >').match(/[^ ]+/g);
1403};
1404
1405/**
1406 * Obtem o elemento pelo seu tipo
1407 * @param {Object} parent
1408 * @param {String} selector
1409 * @return {Array}
1410 */
1411q.getBy = function(parent, selector){
1412
1413 if(selector[0] === '>'){
1414 return this.getByChild(parent, selector.substring(1));
1415 }
1416
1417 var
1418 type = selector[0],
1419 subSelector = this.getSubSelector(selector),
1420 elements = [];
1421
1422 selector = subSelector[0].substring(1);
1423 subSelector = subSelector.slice(1);
1424
1425 if(type === '#'){
1426 elements = this.getById(parent, selector, subSelector);
1427 }else if(type === '.'){
1428 elements = this.getByClass(parent, selector, subSelector);
1429 }else if(type === '['){
1430 elements = this.getByAttr(parent, '['+selector, subSelector);
1431 }else{
1432 elements = this.getByTag(parent, type+selector, subSelector);
1433 }
1434
1435 return elements
1436};
1437
1438/**
1439 * Obtem o elemento pelo ID
1440 * @param {Object} parent
1441 * @param {String} selector
1442 * @param {Array} subSelector
1443 * @return {Array}
1444 */
1445q.getById = function(parent, selector, subSelector){
1446 subSelector = (subSelector || []);
1447 subSelector.unshift('#'+selector);
1448 return this.checkElementIsValid(
1449 toArray(parent.getElementsByTagName('*')),
1450 subSelector
1451 );
1452};
1453
1454/**
1455 * Obtem o elemento pela CLASSE
1456 * @param {Object} parent
1457 * @param {String} selector
1458 * @param {Array} subSelector
1459 * @return {Array}
1460 */
1461q.getByClass = function(parent, selector, subSelector){
1462 var elements = toArray(parent.getElementsByClassName(selector));
1463 if(subSelector && subSelector.length){
1464 elements = this.checkElementIsValid(elements, subSelector);
1465 }
1466
1467 return elements;
1468};
1469
1470/**
1471 * Obtem o elemento pelo ATRIBUTO
1472 * @param {Object} parent
1473 * @param {String} selector
1474 * @param {Array} subSelector
1475 * @return {Array}
1476 */
1477q.getByAttr = function(parent, selector, subSelector){
1478 var
1479 i,
1480 elements = toArray(parent.getElementsByTagName('*'))
1481 elAttr = [];
1482
1483 for(i=0;i<elements.length;i++){
1484 if(this.checkElementHasAttribute(elements[i], selector)){
1485 elAttr.push(elements[i]);
1486 }
1487 }
1488
1489 elements = elAttr;
1490 if(subSelector && subSelector.length){
1491 elements = this.checkElementIsValid(elements, subSelector);
1492 }
1493
1494 return elements;
1495};
1496
1497/**
1498 * Obtem o elemento pela TAG
1499 * @param {Object} parent
1500 * @param {String} selector
1501 * @param {Array} subSelector
1502 * @return {Array}
1503 */
1504q.getByTag = function(parent, selector, subSelector){
1505 var elements = toArray(parent.getElementsByTagName(selector));
1506 if(subSelector && subSelector.length){
1507 elements = this.checkElementIsValid(elements, subSelector);
1508 }
1509
1510 return elements;
1511};
1512
1513/**
1514 * Obtem o elemento filho
1515 * @param {Object} parent
1516 * @param {String} selector
1517 */
1518q.getByChild = function(parent, selector){
1519 return this.checkElementIsValid(
1520 toArray(parent.childNodes),
1521 this.getSubSelector(selector)
1522 );
1523};
1524
1525/**
1526 * Verifica se são elementos válidos
1527 * @param {Array} elements
1528 * @param {Array} selector
1529 * @return {Array}
1530 */
1531q.checkElementIsValid = function(elements, selector){
1532 var nElements = [], element;
1533
1534 for(var i = 0;i < elements.length ;i++){
1535 element = elements[i];
1536 if(element.nodeType === 1 && this.checkSubSelector(element, selector)){
1537 nElements.push(element);
1538 }
1539 }
1540
1541 return nElements;
1542};
1543
1544/**
1545 * Check for element if sub selector is valid
1546 * @param {Object} element
1547 * @param {Array} selector
1548 * @return {Boolean}
1549 */
1550q.checkSubSelector = function(element, selector){
1551 var found = true, i, subSelector, type, tester;
1552
1553 for(i=0;i<selector.length;i++){
1554
1555 subSelector = selector[i];
1556 type = subSelector[0];
1557 tester = new RegExp('\\b'+subSelector.substring(1)+'\\b', 'gi');
1558
1559 if(
1560 (type === '.' && !tester.test(element.className)) ||//class
1561 (type === '#' && !tester.test(element.id)) ||//id
1562 (type === '[' && !this.checkElementHasAttribute(element, subSelector)) ||//attriute
1563 (['.', '#', '['].indexOf(type) === -1 && element.nodeName !== subSelector.toUpperCase())//tag
1564 ){
1565 found = false;
1566 }
1567 }
1568
1569 return found;
1570};
1571
1572/**
1573 * Verifica se tem o atributo no elemento e se o valor confere
1574 * @param {Object} element
1575 * @param {String} attribute
1576 * @return boolean
1577 */
1578q.checkElementHasAttribute = function(element, attribute){
1579 var
1580 attrs = attribute.match(/\w+(\=[\'\"]?[^\'\"\]\[]+[\'\"]?)?/gi),
1581 attr, value, attrCompare, valueCompare,found = true;
1582
1583 if(!attrs){
1584 return false;
1585 }
1586
1587 for(i=0;i<attrs.length;i++){
1588 attr = attrs[i].split('=');
1589
1590 attrCompare = attr[0];
1591 valueCompare = (attr[1] || '').replace(/[\'\"\s]/g, '');
1592 value = (element.getAttribute(attrCompare) || '').trim();
1593
1594 if(!valueCompare){
1595 if(!element.hasAttribute(attrCompare)){
1596 found = false;
1597 }
1598 }else if(!(new RegExp('\\b'+valueCompare+'\\b', 'gi')).test(value)){
1599 found = false;
1600 }
1601 }
1602
1603 return found;
1604};
1605
1606/**
1607 * Obtem os seletores usados no get
1608 * @param {String} selector
1609 * @return {Array}
1610 */
1611q.getSubSelector = function(selector){
1612 return selector.match(/(\#|\.|[A-z]?)[\w\-]+|\[[^\[\]]*\]/gi);
1613};
1614
1615q = new QuerySelectorAll();
1616return q.get.bind(q);
1617
1618})()
1619;
1620/**
1621 * Generate a random value by user agent, referrer, cookie and native
1622 * javascript method (Math.random())
1623 *
1624 * @author Jhozefem Pontes <jhozefem@neemu.com>
1625 * @since 1.0.0
1626 * @return {Number}
1627 */
1628cm.random = function() {
1629 var value;
1630
1631 value = this.parseStringToNumber(navigator.userAgent)
1632 + this.parseStringToNumber(document.referrer)
1633 + this.parseStringToNumber(document.cookie.substr(0, 100))
1634 + parseInt(Math.random() * 1e6);
1635
1636 return value % Math.pow(10, 12);
1637};
1638/**
1639 * @author Andrews Lince <andrews@neemu.com>
1640 * @version 2.1.13
1641 * @param {Number} min
1642 * @param {Number} max
1643 * @return {Number}
1644 */
1645cm.randomBetween = function(min, max) {
1646 return Math.floor(Math.random() * (max - min + 1)) + min;
1647};;
1648/**
1649 * Remove a HTML element
1650 *
1651 * @author Jhozefem Pontes <jhozefem@neemu.com>
1652 * @author Andrews Lince <andrews@neemu.com>
1653 * @since 1.0.0
1654 * @param {HTMLElement} element
1655 * @return {Void}
1656 */
1657cm.removeElement = function(element) {
1658 if (element) {
1659 element.parentNode.removeChild(element);
1660 }
1661};
1662/**
1663 * Encode a value for base 36
1664 *
1665 * @author Jhozefem Pontes <jhozefem@neemu.com>
1666 * @author Andrews Lince <andrews@neemu.com>
1667 * @since 1.0.0
1668 * @param {String} value
1669 * @return {String}
1670 */
1671cm.base36encode = function(value) {
1672 var nvalue = "",
1673 modvalue,
1674 map = [
1675 "0", "1", "2", "3", "4", "5", "6", "7", "8",
1676 "9", "A", "B", "C", "D", "E", "F", "G", "H",
1677 "I", "J", "K", "L", "M", "N", "O", "P", "Q",
1678 "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
1679 ];
1680
1681 while (value > 0) {
1682 modvalue = value % 36;
1683 value = Math.floor(value / 36);
1684 nvalue = map[modvalue] + nvalue;
1685 }
1686
1687 return nvalue;
1688};
1689// discuss at: http://phpjs.org/functions/base64_decode/
1690// original by: Tyler Akins (http://rumkin.com)
1691// improved by: Thunder.m
1692// improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1693// improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1694// input by: Aman Gupta
1695// input by: Brett Zamir (http://brett-zamir.me)
1696// bugfixed by: Onno Marsman
1697// bugfixed by: Pellentesque Malesuada
1698// bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1699// example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==');
1700// returns 1: 'Kevin van Zonneveld'
1701// example 2: base64_decode('YQ===');
1702// returns 2: 'a'
1703// example 3: base64_decode('4pyTIMOgIGxhIG1vZGU=');
1704// returns 3: '✓ à la mode'
1705cm.base64Decode = function(data) {
1706 var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
1707 var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
1708 ac = 0,
1709 dec = '',
1710 tmp_arr = [];
1711
1712 if (!data) {
1713 return data;
1714 }
1715
1716 data += '';
1717
1718 do {
1719 // unpack four hexets into three octets using index points in b64
1720 h1 = b64.indexOf(data.charAt(i++));
1721 h2 = b64.indexOf(data.charAt(i++));
1722 h3 = b64.indexOf(data.charAt(i++));
1723 h4 = b64.indexOf(data.charAt(i++));
1724
1725 bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
1726
1727 o1 = bits >> 16 & 0xff;
1728 o2 = bits >> 8 & 0xff;
1729 o3 = bits & 0xff;
1730
1731 if (h3 == 64) {
1732 tmp_arr[ac++] = String.fromCharCode(o1);
1733 } else if (h4 == 64) {
1734 tmp_arr[ac++] = String.fromCharCode(o1, o2);
1735 } else {
1736 tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
1737 }
1738 } while (i < data.length);
1739
1740 dec = tmp_arr.join('');
1741
1742 return decodeURIComponent(escape(dec.replace(/\0+$/, '')));
1743};
1744// discuss at: http://phpjs.org/functions/base64_encode/
1745 // original by: Tyler Akins (http://rumkin.com)
1746 // improved by: Bayron Guevara
1747 // improved by: Thunder.m
1748 // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1749 // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1750 // improved by: Rafał Kukawski (http://kukawski.pl)
1751 // bugfixed by: Pellentesque Malesuada
1752 // example 1: base64_encode('Kevin van Zonneveld');
1753 // returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
1754 // example 2: base64_encode('a');
1755 // returns 2: 'YQ=='
1756 // example 3: base64_encode('✓ à la mode');
1757 // returns 3: '4pyTIMOgIGxhIG1vZGU='
1758cm.base64Encode = function(data) {
1759 var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
1760 var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
1761 ac = 0,
1762 enc = '',
1763 tmp_arr = [];
1764
1765 if (!data) {
1766 return data;
1767 }
1768
1769 data = unescape(encodeURIComponent(data));
1770
1771 do {
1772 // pack three octets into four hexets
1773 o1 = data.charCodeAt(i++);
1774 o2 = data.charCodeAt(i++);
1775 o3 = data.charCodeAt(i++);
1776
1777 bits = o1 << 16 | o2 << 8 | o3;
1778
1779 h1 = bits >> 18 & 0x3f;
1780 h2 = bits >> 12 & 0x3f;
1781 h3 = bits >> 6 & 0x3f;
1782 h4 = bits & 0x3f;
1783
1784 // use hexets to index into b64, and append result to encoded string
1785 tmp_arr[ac++] = b64.charAt(h1)
1786 + b64.charAt(h2)
1787 + b64.charAt(h3)
1788 + b64.charAt(h4);
1789 } while (i < data.length);
1790
1791 enc = tmp_arr.join('');
1792
1793 var r = data.length % 3;
1794
1795 return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
1796};
1797/**
1798 * Decodes a URL, using the methods decodeURIComponent() and unescape()
1799 *
1800 * @author Jhozefem Pontes <jhozefem@neemu.com>
1801 * @since 1.0.0
1802 * @param {String} url
1803 * @return {String}
1804 */
1805cm.decodeUrl = function(url) {
1806 var durl;
1807
1808 try {
1809 durl = decodeURIComponent(decodeURI(url.replace(/\+/g, '%20')));
1810 } catch(e) {
1811 durl = unescape(url);
1812 }
1813
1814 return durl;
1815};
1816/**
1817 * Get current url
1818 *
1819 * @author Andrews Lince <andrews@neemu.com>
1820 * @since 1.0.0
1821 * @return {String}
1822 */
1823cm.getUrl = function(){
1824 return this.decodeUrl(window.location.href);
1825};
1826/**
1827 * Get a parameter value by your name
1828 *
1829 * @author Andrews Lince <andrews@neemu.com>
1830 * @since 1.0.0
1831 * @param {String} param
1832 * @param {String} url
1833 * @return {String}
1834 */
1835cm.getUrlParamValue = function(param, url) {
1836 if (url === undefined) {
1837 url = this.decodeUrl(window.location.href);
1838 }
1839
1840 param = param.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
1841 var match = url.match('[?&]' + param + '=([^&]*)');
1842 return match ? match[1] : null;
1843};
1844/**
1845 * Get all the url parameters (by query string)
1846 *
1847 * @author Jhozefem Pontes <jhozefem@neemu.com>
1848 * @author Andrews Lince <andrews@neemu.com>
1849 * @since 1.0.0
1850 * @param {String} value
1851 * @return {Object}
1852 */
1853cm.getUrlVars = function(value) {
1854 var vars = {},
1855 url = (value && typeof(value) === "string")
1856 ? encodeURI(value)
1857 : this.decodeUrl(window.location.href);
1858
1859 var parts = url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
1860 var keyEncode = decodeURI(key);
1861 var valueEncode = decodeURI(value);
1862 vars[keyEncode] = valueEncode;
1863 });
1864
1865 return vars;
1866};
1867/**
1868 * Turn a string to the integer value
1869 *
1870 * @author Jhozefem Pontes <jhozefem@neemu.com>
1871 * @since 1.0.0
1872 * @param {String} value [description]
1873 * @return {Number}
1874 */
1875cm.parseStringToNumber = function(value) {
1876 var number = 0;
1877
1878 if (typeof(value) == "string") {
1879 var vLength = value.length;
1880 for (var i = 0, len = vLength; i < len; i++) {
1881 number += value.charCodeAt(i);
1882 }
1883 }
1884
1885 return number;
1886};
1887 /**
1888 * Remove accents from a string
1889 *
1890 * @author Jhozefem Pontes <jhozefem@neemu.com>
1891 * @author Andrews Lince <andrews@neemu.com>
1892 * @since 1.0.0
1893 * @param {String} str
1894 * @return {String}
1895 */
1896cm.removeAccents = function(str) {
1897 var mapaAcentosHex = {
1898 a : /[\xE0-\xE6]/g,
1899 e : /[\xE8-\xEB]/g,
1900 i : /[\xEC-\xEF]/g,
1901 o : /[\xF2-\xF6]/g,
1902 u : /[\xF9-\xFC]/g,
1903 c : /\xE7/g,
1904 n : /\xF1/g
1905 };
1906
1907 for (var letra in mapaAcentosHex) {
1908 var expressaoRegular = mapaAcentosHex[letra];
1909 str = str.replace(expressaoRegular, letra);
1910 }
1911
1912 return str;
1913};
1914/**
1915 * Remove HTML tags from a string
1916 *
1917 * @author Jhozefem Pontes <jhozefem@neemu.com>
1918 * @since 1.0.0
1919 * @param {String} value
1920 * @return {String}
1921 */
1922cm.removeHtmlTag = function(value) {
1923 return value.replace(/<(?:.|\s)*?>/g, '');
1924};
1925/**
1926 * Remove espaços em branco desnecessário
1927 * @author Ivanildo de Castro <ivanildocastro@neemu.com>
1928 * @since 1.0.0
1929 * @param {String} text
1930 * @return {String}
1931 */
1932cm.removeWhiteSpaces = function(text){
1933 if(typeof text === 'string'){
1934 return text.trim().replace(/\s+/g, ' ');
1935 }
1936
1937 return text;
1938};
1939/**
1940 * Checks is exists some occurrence of a string another string
1941 *
1942 * @author Andrews Lince <andrews@neemu.com>
1943 * @since 1.0.0
1944 * @param {String} haystack
1945 * @param {String} needle
1946 * @return {Boolean}
1947 */
1948cm.strstr = function(haystack, needle) {
1949 return (needle && haystack.indexOf(needle) != -1)
1950 ? true
1951 : false;
1952};
1953// discuss at: http://phpjs.org/functions/utf8_encode/
1954// original by: Webtoolkit.info (http://www.webtoolkit.info/)
1955// improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1956// improved by: sowberry
1957// improved by: Jack
1958// improved by: Yves Sucaet
1959// improved by: kirilloid
1960// bugfixed by: Onno Marsman
1961// bugfixed by: Onno Marsman
1962// bugfixed by: Ulrich
1963// bugfixed by: Rafal Kukawski
1964// bugfixed by: kirilloid
1965// example 1: utf8_encode('Kevin van Zonneveld');
1966// returns 1: 'Kevin van Zonneveld'
1967cm.utf8Encode = function(argString) {
1968 if (argString === null || typeof argString === 'undefined') {
1969 return '';
1970 }
1971
1972 var string = (argString + ''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");
1973 var utftext = '',
1974 start, end, stringl = 0;
1975
1976 start = end = 0;
1977 stringl = string.length;
1978 for (var n = 0; n < stringl; n++) {
1979 var c1 = string.charCodeAt(n);
1980 var enc = null;
1981
1982 if (c1 < 128) {
1983 end++;
1984 } else if (c1 > 127 && c1 < 2048) {
1985 enc = String.fromCharCode(
1986 (c1 >> 6) | 192, (c1 & 63) | 128
1987 );
1988 } else if ((c1 & 0xF800) != 0xD800) {
1989 enc = String.fromCharCode(
1990 (c1 >> 12) | 224, ((c1 >> 6) & 63) | 128, (c1 & 63) | 128
1991 );
1992 } else { // surrogate pairs
1993 if ((c1 & 0xFC00) != 0xD800) {
1994 throw new RangeError('Unmatched trail surrogate at ' + n);
1995 }
1996 var c2 = string.charCodeAt(++n);
1997 if ((c2 & 0xFC00) != 0xDC00) {
1998 throw new RangeError('Unmatched lead surrogate at ' + (n - 1));
1999 }
2000 c1 = ((c1 & 0x3FF) << 10) + (c2 & 0x3FF) + 0x10000;
2001 enc = String.fromCharCode(
2002 (c1 >> 18) | 240, ((c1 >> 12) & 63) | 128, ((c1 >> 6) & 63) | 128, (c1 & 63) | 128
2003 );
2004 }
2005 if (enc !== null) {
2006 if (end > start) {
2007 utftext += string.slice(start, end);
2008 }
2009 utftext += enc;
2010 start = end = n + 1;
2011 }
2012 }
2013
2014 if (end > start) {
2015 utftext += string.slice(start, stringl);
2016 }
2017
2018 return utftext;
2019};
2020/**
2021 * Checks if the current user agent is a search bot
2022 *
2023 * @author Andrews Lince <andrews@neemu.com>
2024 * @since 1.0.0
2025 * @return {Boolean}
2026 */
2027cm.userAgentIsBot = function() {
2028 var userAgent = navigator.userAgent;
2029 return (
2030 this.strstr(userAgent, "Googlebot")
2031 || this.strstr(userAgent, "BingPreview")
2032 )
2033 ? true
2034 : false;
2035};
2036
2037window._nm = (window._nm || {});
2038window._nm.commons = new Commons();
2039})(window, document);
2040_nm.VERSION = "2.13.9";
2041
2042_nm.url = window.location.href;
2043
2044_nm.isMobile = false;
2045
2046_nm.callbacks = {
2047 beforeLogRequests: []
2048};
2049
2050window.neemuCallback = function(data){}
2051
2052/**
2053 * Copyright (c) 2015 - Neemu Serviços em Tecnologia da Informação S.A
2054 *
2055 * LICENSE: This software is the confidential and proprietary information of
2056 * Neemu S.A ("Confidential Information"). You shall not disclose such
2057 * Confidential Information and shall use it only in accordance with the terms
2058 * of the license agreement you entered into with Neemu S.A.
2059 *
2060 * Module which implements some prototype functions, for given
2061 * crossbrowser support
2062 *
2063 * @author Javier Zambrano <javier@neemu.com>
2064 * @author Andrews Lince <andrews@neemu.com>
2065 * @version 1.0.0
2066 */
2067
2068if (!String.prototype.trim) {
2069
2070 /**
2071 * Implements trim function, to remove blank spaces around the strings
2072 *
2073 * @author Javier Zambrano <javier@neemu.com>
2074 * @author Andrews Lince <andrews@neemu.com>
2075 * @since 1.0.0
2076 * @return {String}
2077 */
2078 String.prototype.trim = function () {
2079 return this.replace(/^\s+/,'').replace(/\s+$/, '');
2080 };
2081}
2082
2083if(!Array.prototype.slice) {
2084
2085 /**
2086 * Implements a function to remove a specific position from a array
2087 *
2088 * @author Javier Zambrano <javier@neemu.com>
2089 * @since 1.0.0
2090 * @param {Integer} begin
2091 * @param {Integer} end
2092 * @return {Array}
2093 */
2094 Array.prototype.slice = function(begin, end) {
2095 // IE < 9 gets unhappy with an undefined end argument
2096 end = (typeof end !== 'undefined')
2097 ? end
2098 : this.length;
2099
2100 // For native Array objects, we use the native slice function
2101 if (Object.prototype.toString.call(this) === "[object Array]") {
2102 return Array.prototype.slice.call(this, begin, end);
2103 }
2104
2105 // For array like object we handle it ourselves.
2106 var i, cloned = [],
2107 size, len = this.length;
2108
2109 // Handle negative value for "begin"
2110 var start = begin || 0;
2111 start = (start >= 0)
2112 ? start
2113 : len + start;
2114
2115 // Handle negative value for "end"
2116 var upTo = (end)
2117 ? end
2118 : len;
2119 if (end < 0) {
2120 upTo = len + end;
2121 }
2122
2123 // Actual expected size of the slice
2124 size = upTo - start;
2125
2126 if (size > 0) {
2127 cloned = new Array(size);
2128 if (this.charAt) {
2129 for (i = 0; i < size; i++) {
2130 cloned[i] = this.charAt(start + i);
2131 }
2132 } else {
2133 for (i = 0; i < size; i++) {
2134 cloned[i] = this[start + i];
2135 }
2136 }
2137 }
2138
2139 return cloned;
2140 };
2141}
2142
2143if (!Object.keys) {
2144
2145 /**
2146 * Returns only keys from a array
2147 *
2148 * @since 2.0.0
2149 * @{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys}
2150 * @return {Array}
2151 */
2152 Object.keys = (function() {
2153 "use strict";
2154 var hasOwnProperty = Object.prototype.hasOwnProperty,
2155 hasDontEnumBug = !({ toString: null }).propertyIsEnumerable("toString"),
2156 dontEnums = [
2157 "toString",
2158 "toLocaleString",
2159 "valueOf",
2160 "hasOwnProperty",
2161 "isPrototypeOf",
2162 "propertyIsEnumerable",
2163 "constructor"
2164 ],
2165 dontEnumsLength = dontEnums.length;
2166
2167 return function(obj) {
2168 if (typeof obj !== "object" && (typeof obj !== "function" || obj === null)) {
2169 throw new TypeError("Object.keys called on non-object");
2170 }
2171
2172 var result = [], prop, i;
2173
2174 for (prop in obj) {
2175 if (hasOwnProperty.call(obj, prop)) {
2176 result.push(prop);
2177 }
2178 }
2179
2180 if (hasDontEnumBug) {
2181 for (i = 0; i < dontEnumsLength; i++) {
2182 if (hasOwnProperty.call(obj, dontEnums[i])) {
2183 result.push(dontEnums[i]);
2184 }
2185 }
2186 }
2187 return result;
2188 };
2189 }());
2190}
2191
2192/**
2193 * Copyright (c) 2015 - Neemu Serviços em Tecnologia da Informação S.A
2194 *
2195 * LICENSE: This software is the confidential and proprietary information of
2196 * Neemu S.A ("Confidential Information"). You shall not disclose such
2197 * Confidential Information and shall use it only in accordance with the terms
2198 * of the license agreement you entered into with Neemu S.A.
2199 */
2200
2201/**
2202 * Module implemented to extract the page information, process this
2203 * data and send this to log service
2204 *
2205 * @author Javier Zambrano <javier@neemu.com>
2206 * @author Andrews Lince <andrews@neemu.com>
2207 * @version 2.0.0
2208 * @param {Object} window
2209 * @param {Object} document
2210 * @param {undefined} undefined
2211 * @return {Object}
2212 */
2213_nm.extraction = (function (window, document, undefined) {
2214 /**
2215 * Constante to define the page type
2216 *
2217 * @since 2.0.0
2218 * @type {String}
2219 */
2220 var PAGE_CHECKOUT_CONFIRMATION = "checkoutConfirmacao",
2221 PAGE_NEEMU_PAGES_INDEX = "neemu-pages-index",
2222 PAGE_ADD_TO_CART = "adicionarcarrinho",
2223 PAGE_DEPARTMENT = "departamento",
2224 PAGE_NEEMU_PAGES = "neemupages",
2225 PAGE_NAVIGATION = "navigation",
2226 PAGE_COMPARISON = "comparador",
2227 PAGE_CHECKOUT = "checkout",
2228 PAGE_CHECKOUT_CART = "carrinho",
2229 PAGE_REC_PRINT = "recprint",
2230 PAGE_PRODUCT = "produto",
2231 PAGE_SEARCH = "busca",
2232 PAGE_LOGIN = "login",
2233 PAGE_GENERAL = "geral",
2234 PAGE_HOME = "home",
2235 PAGE_NOT_FOUND = "404",
2236 PAGE_HOTSITE = "hotsite",
2237 PAGE_WISHLIST = "wishlist",
2238 PAGE_COLLECTION_GERAL = 'colGeral',
2239 PAGE_COLLECTION_HOME = 'colHome',
2240 PAGE_COLLECTION_SEARCH = 'colSearch',
2241 PAGE_COLLECTION_DETAILS = 'colDetails',
2242 PAGE_COLLECTION_AUTHOR = 'colAuthor',
2243 PAGE_COLLECTION_REGISTER = 'colRegister',
2244 PAGE_COLLECTION_RELATED = 'colRelated',
2245 PAGE_COLLECTION_TAG = 'colTag';
2246
2247 /**
2248 * @since 2.0.0
2249 * @type {Object}
2250 */
2251 var storeConfig = {};
2252
2253 /**
2254 * @since 2.0.0
2255 * @type {Object}
2256 */
2257 var finalJson = {};
2258
2259 /**
2260 * @since 2.0.0
2261 * @type {Object}
2262 */
2263 var info = {
2264 general : {
2265 pgType : PAGE_GENERAL
2266 },
2267 department : {
2268 cId : "",
2269 tree : []
2270 },
2271 checkoutConfirmation : {},
2272 checkoutInformation : {},
2273 autocomplete : {},
2274 quickFilter : {},
2275 navigation : {},
2276 product : {},
2277 search : {},
2278 hotsite : {},
2279 user : {},
2280 rec : {},
2281 filters : [],
2282 skuList : [],
2283 skuListFinal : [],
2284 wishlist : {}
2285 };
2286
2287 /**
2288 * @since 2.0.0
2289 * @type {String}
2290 */
2291 var sid = "";
2292
2293 /**
2294 * @since 2.0.0
2295 * @type {String}
2296 */
2297 var agent = "";
2298
2299 /**
2300 * @since 2.0.0
2301 * @type {String}
2302 */
2303 var protocol = "";
2304
2305 /**
2306 * @since 2.0.0
2307 * @type {String}
2308 */
2309 var logServer = "";
2310
2311 /**
2312 * @since 2.0.0
2313 * @type {Boolean}
2314 */
2315 var pauseExtraction = false;
2316
2317 /**
2318 * @since 2.0.0
2319 * @type {Boolean}
2320 */
2321 var loadInitRecommendation = false;
2322
2323 /**
2324 * @since 2.0.0
2325 * @type {Object}
2326 */
2327 var $_ME;
2328
2329 /************ [ METHODS FROM LOAD COOKIE INFORMATIONS - BEGIN ] ***********/
2330
2331 var setMe = function(o) {
2332 $_ME = o;
2333 };
2334
2335 var loadDepartmentList = function(value, cname) {
2336 cname = cname || "department_list";
2337 value = value || $_ME.info.department.cId;
2338
2339 if (value) {
2340 value = value.toString();
2341 }
2342
2343 if (value && (typeof(value) !== "string" || value.trim() !== "")) {
2344 var departmentList = _nm.commons.getCookie(cname),
2345 departmentOld = departmentList, // armazenando para tratamento do valor atual
2346 departmentValue = value;
2347
2348 // no começo da string, sempre o produto atual está no inÃÂcio
2349 departmentList = departmentValue;
2350
2351 if (departmentOld !== undefined) {
2352 var departmentListSplit = departmentOld.split("|");
2353
2354 for(var i = 0, len = departmentListSplit.length, lim = 10, qtt = 1; i < len; i++) {
2355 /**
2356 * não pode adicionar a query atual novamente na lista e
2357 * nem os valores undefined que estão guardados
2358 */
2359 if (
2360 departmentListSplit[i] != departmentValue
2361 && departmentListSplit[i] !== undefined
2362 && departmentListSplit[i].trim() !== ""
2363 && departmentListSplit[i].indexOf("%")== -1
2364 ) {
2365 departmentList += "|" + departmentListSplit[i];
2366 qtt++;
2367
2368 if (qtt >= lim) {
2369 break;
2370 }
2371 }
2372 }
2373 }
2374
2375 _nm.commons.setCookie(
2376 cname,
2377 departmentList,
2378 43200, // 30 dias
2379 '/',
2380 '.' + _nm.conf.store.host
2381 );
2382 }
2383 };
2384
2385 var loadQueryList = function(value, cname) {
2386 cname = cname || "query_list";
2387 value = value || $_ME.info.search.q;
2388
2389 // preenchimento do query_list
2390 if (typeof value == "string" && value.trim() !== "")
2391 {
2392 var queryValue = _nm.commons.removeAccents(value).toLowerCase(),
2393 queryList = _nm.commons.getCookie(cname),
2394 queryListOld = queryList, // armazenando para tratamento do valor atual
2395 lim = 10; // limite de valores no cookie
2396
2397 if (_nm.conf.store.host === "mobly.com.br") {
2398 lim = 20;
2399 }
2400
2401 // limitando em 20 caracteres
2402 if (queryValue.length > 20) {
2403 queryValue = "";
2404 }
2405
2406 if (queryListOld !== undefined && queryValue.trim() !== "") {
2407 var queryListSplit = queryListOld.split("|");
2408
2409 // no começo da string, sempre o produto atual está no inÃÂcio
2410 queryList = queryValue;
2411
2412 for(var i = 0, len = queryListSplit.length, qtt = 1; i < len; i++) {
2413 queryListSplit[i] = _nm.commons.removeAccents(queryListSplit[i]);
2414
2415 // limitando em 20 caracteres
2416 if (queryListSplit[i].length > 20) {
2417 queryListSplit[i] = "";
2418 }
2419
2420 // não pode adicionar a query atual novamente na lista e nem os valores undefined que estão guardados
2421 if (
2422 queryListSplit[i] !== queryValue
2423 && queryListSplit[i] !== undefined
2424 && queryListSplit[i].trim() !== ""
2425 && queryListSplit[i].indexOf("%") == -1
2426 ) {
2427 queryList += "|" + queryListSplit[i];
2428 qtt++;
2429
2430 if (qtt >= lim) {
2431 break;
2432 }
2433 }
2434 }
2435 }
2436
2437 if (!queryList) {
2438 queryList = queryValue;
2439 }
2440
2441 // novo valor do query_list calculado
2442 _nm.commons.setCookie(
2443 cname,
2444 queryList,
2445 43200, // 30 dias
2446 '/',
2447 '.' + _nm.conf.store.host
2448 );
2449 }
2450 };
2451
2452 var loadClickList = function(value, cname) {
2453 cname = cname || "click_list";
2454 value = value || $_ME.info.product.id;
2455
2456 if(value) {
2457 value = value.toString();
2458 }
2459
2460 // preenchimento do click_list
2461 if (typeof(value) === "string" && value.trim() !== "") {
2462 var clickValue = _nm.commons.removeAccents(value);
2463 var clickList = _nm.commons.getCookie(cname);
2464 var clickListOld = clickList; // armanazenando para tratamento do valor atual
2465 var lim = 10; // limite de valores no cookie
2466
2467 if(_nm.conf.store.host == "mobly.com.br") {
2468 lim = 20;
2469 }
2470
2471 // limitando em 20 caracteres
2472 if(clickValue.length > 20) {
2473 clickValue = "";
2474 }
2475
2476 if (clickListOld !== undefined && clickValue.trim() !== "") {
2477 var clickListSplit = clickListOld.split("|");
2478
2479 // no começo da string, sempre o produto atual está no inÃÂcio
2480 clickList = clickValue;
2481
2482 for(var i = 0, len = clickListSplit.length, qtt = 1; i < len; i++) {
2483 clickListSplit[i] = _nm.commons.removeAccents(clickListSplit[i]);
2484
2485 // limitando em 20 caracteres
2486 if(clickListSplit[i].length > 20) {
2487 clickListSplit[i] = "";
2488 }
2489
2490 /**
2491 * não pode adicionar a click atual novamente na lista e
2492 * nem os valores undefined que estão guardados
2493 */
2494 if(
2495 clickListSplit[i] != clickValue
2496 && clickListSplit[i] != "undefined"
2497 && clickListSplit[i].trim() != ""
2498 && clickListSplit[i].indexOf("%") == -1
2499 ) {
2500 clickList += "|" + clickListSplit[i];
2501 qtt++;
2502
2503 if(qtt >= lim) {
2504 break;
2505 }
2506 }
2507 }
2508 }
2509
2510 if(!clickList) {
2511 clickList = clickValue;
2512 }
2513
2514 // novo valor do click_list calculado
2515 _nm.commons.setCookie(
2516 cname,
2517 clickList,
2518 43200, // 30 dias
2519 '/',
2520 '.' + _nm.conf.store.host
2521 );
2522 }
2523 };
2524
2525 var loadPurchaseList = function(values, cname) {
2526 cname = cname || "nm_purchase_list";
2527 values = values || $_ME.info.skuList;
2528
2529 var purchaseList = _nm.commons.getCookie(cname);
2530
2531 for(var j = 0, len_j = values.length; j < len_j; j++) {
2532 var value = values[j];
2533
2534 value = (typeof(value) === "object")
2535 ? value.sku.toString()
2536 : value.toString();
2537
2538 // preenchimento do nm_purchase_list
2539 if (typeof(value) === "string" && value.trim() !== "") {
2540 var purchaseValue = _nm.commons.removeAccents(value);
2541 var purchaseListOld = purchaseList; // armanazenando para tratamento do valor atual
2542 var lim = 10; // limite de valores no cookie
2543
2544 // limitando em 20 caracteres
2545 if(purchaseValue.length > 20) {
2546 purchaseValue = "";
2547 }
2548
2549 if (purchaseListOld !== undefined && purchaseValue.trim() !== "") {
2550 var purchaseListSplit = purchaseListOld.split('|');
2551
2552 // no começo da string, sempre o produto atual está no inÃÂcio
2553 purchaseList = purchaseValue;
2554
2555 for(var i = 0, len = purchaseListSplit.length, qtt = 1; i < len; i++) {
2556 purchaseListSplit[i] = _nm.commons.removeAccents(purchaseListSplit[i]);
2557
2558 // limitando em 20 caracteres
2559 if(purchaseListSplit[i].length > 20) {
2560 purchaseListSplit[i] = "";
2561 }
2562
2563 /**
2564 * não pode adicionar a purchase atual novamente na
2565 * lista e nem os valores undefined que estão guardados
2566 */
2567 if(
2568 purchaseListSplit[i] != purchaseValue
2569 && purchaseListSplit[i] != "undefined"
2570 && purchaseListSplit[i].trim() != ""
2571 && purchaseListSplit[i].indexOf("%") == -1
2572 ) {
2573 purchaseList += "|" + purchaseListSplit[i];
2574 qtt++;
2575
2576 if(qtt >= lim) {
2577 break;
2578 }
2579 }
2580 }
2581 }
2582
2583 if(!purchaseList) {
2584 purchaseList = purchaseValue;
2585 }
2586 }
2587 }
2588
2589 // novo valor do purchase_list calculado
2590 _nm.commons.setCookie(
2591 cname,
2592 purchaseList,
2593 43200, // 30 dias
2594 '/',
2595 '.' + _nm.conf.store.host
2596 );
2597 };
2598
2599 /**
2600 * Pega o skuList do carrinho e cria um cookie dos produtos do carrinho
2601 * @return {Void}
2602 */
2603 var loadCartList = function(cname) {
2604 cname = cname || "cart_list";
2605
2606 var cartList = "";
2607
2608 if(Object.prototype.toString.call($_ME.info.skuList) === "[object Array]"){
2609 for(var cont = 0, tamanho = $_ME.info.skuList.length; cont < tamanho; cont++) {
2610 if(
2611 typeof($_ME.info.skuList[cont].id) === "string"
2612 && typeof($_ME.info.skuList[cont].sku) === "string"
2613 ) {
2614 if($_ME.info.skuList[cont].id !== $_ME.info.skuList[cont].sku) {
2615 cartList += $_ME.info.skuList[cont].id + ":" + $_ME.info.skuList[cont].sku;
2616 } else {
2617 cartList += $_ME.info.skuList[cont].id;
2618 }
2619
2620 if(cont+1 != tamanho) {
2621 cartList += "|";
2622 }
2623 }
2624 }
2625 }
2626
2627 _nm.commons.setCookie(
2628 cname,
2629 cartList,
2630 null,
2631 '/',
2632 '.' + _nm.conf.store.host
2633 );
2634 };
2635
2636 /************ [ METHODS FROM LOAD COOKIE INFORMATIONS - END ] *************/
2637
2638 /**
2639 * Correct common errors in emails
2640 * @since v2.8.4
2641 * @param {String} email E-mail to be correct
2642 * @return {String} Corrected e-mail
2643 */
2644 var correctEmail = function(email) {
2645 return email
2646 .replace("gmail.con", "gmail.com")
2647 .replace("com.bbr", "com.br");
2648 };
2649
2650 /**
2651 * @author Andrews Lince <andrews@neemu.com>
2652 * @version 2.1.0
2653 * @return {Void}
2654 */
2655 var initializeLogInformation = function() {
2656 $_ME.finalJson = {};
2657 // $_ME.info.skuList = [];
2658 // $_ME.info.skuListFinal = [];
2659 // $_ME.info.product.skus = [];
2660 // $_ME.info.search = {};
2661
2662 _nm.callbacks = {
2663 beforeLogRequests: []
2664 };
2665
2666 $_ME.info = {
2667 general : {
2668 pgType : PAGE_GENERAL
2669 },
2670 department : {
2671 cId : "",
2672 tree : []
2673 },
2674 checkoutConfirmation : {},
2675 checkoutInformation : {},
2676 autocomplete : {},
2677 quickFilter : {},
2678 navigation : {},
2679 product : {},
2680 search : {},
2681 hotsite : {},
2682 user : {},
2683 rec : {},
2684 filters : [],
2685 skuList : [],
2686 skuListFinal : [],
2687 wishlist : {}
2688 };
2689 };
2690
2691 var parseIsPaused = function() {
2692 return $_ME.pauseExtraction;
2693 };
2694
2695 /**
2696 * Sets flag value for pausing the parse process
2697 *
2698 * @author Andrews Lince <andrews@neemu.com>
2699 * @since 2.0.0
2700 * @return {Void}
2701 */
2702 var pauseParse = function() {
2703 $_ME.pauseExtraction = true;
2704 };
2705
2706 /**
2707 * Sets flag value for continue the parse process
2708 *
2709 * @author Andrews Lince <andrews@neemu.com>
2710 * @since 2.0.0
2711 * @return {Void}
2712 */
2713 var continueParse = function() {
2714 $_ME.pauseExtraction = false;
2715
2716 // continue the parse process
2717 generateLogInformation.call($_ME, {
2718 data: $_ME.info,
2719 callback: function(data) {
2720 send.call($_ME, getLogRequestUrl.call($_ME, data));
2721 }
2722 });
2723 };
2724
2725 /**
2726 * Convert filters from intersect search version (using ids) to the
2727 * normal format (using strings)
2728 * @author Andrews Lince <andrews@neemu.com>
2729 * @since 2.12.5
2730 * @param {Object} searchInformation
2731 * @return {Void}
2732 */
2733 var convertSearchFilters = function(searchInformation) {
2734 var newFilters = [];
2735 var multipleValuesSeparator = "|";
2736 for (var nmA in searchInformation.filters) {
2737 var newObjFilter = {};
2738 for (var nmB in searchInformation.filters[nmA]) {
2739 if (typeof(searchInformation.filters[nmA][nmB]) !== "function") {
2740 var selectedValue = searchInformation.filters[nmA][nmB];
2741
2742 // filtros contÃÂnuos
2743 var rangeSeparator = ":";
2744 if (_nm.commons.strstr(selectedValue, rangeSeparator)) {
2745
2746 /**
2747 * mais de um filtro selecionado para o mesmo
2748 * atributo (range_filter[11]=67|234|22)
2749 */
2750 if (
2751 _nm.commons.strstr(
2752 selectedValue,
2753 multipleValuesSeparator
2754 )
2755 ) {
2756 var listValues = selectedValue.split(
2757 multipleValuesSeparator
2758 );
2759 var found = false;
2760 var valores = [];
2761 for (var i = 0; i < listValues.length; i++) {
2762
2763 var valueParts = listValues[i].split(rangeSeparator);
2764
2765 // intersect format
2766 if (valueParts.length === 3) {
2767 var allowedValues = window.nmFilterInfo[nmB].values[valueParts[2]];
2768 for (var j = 0; j < allowedValues.length; j++) {
2769 if (listValues[i] === allowedValues[j]) {
2770 valores.push(
2771 valueParts[0] + ":" + valueParts[1]
2772 );
2773
2774 if (!found) {
2775 found = true;
2776 }
2777 }
2778 }
2779 }
2780 }
2781
2782 if (found) {
2783 newObjFilter[window.nmFilterInfo[nmB].name] =
2784 valores.join("|");
2785
2786 newFilters.push(newObjFilter);
2787
2788 break;
2789 }
2790 }
2791
2792 else {
2793 var valueParts = selectedValue.split(rangeSeparator);
2794
2795 // intersect format
2796 if (valueParts.length === 3) {
2797 var allowedValues = window.nmFilterInfo[nmB].values[valueParts[2]];
2798 for (var i = 0; i < allowedValues.length; i++) {
2799 if (selectedValue === allowedValues[i]) {
2800 newObjFilter[window.nmFilterInfo[nmB].name] =
2801 valueParts[0] + ":" + valueParts[1];
2802
2803 newFilters.push(newObjFilter);
2804
2805 break;
2806 }
2807 }
2808 }
2809
2810 // old search api version
2811 else {
2812
2813 }
2814 }
2815 }
2816
2817 else {
2818
2819 /**
2820 * mais de um filtro selecionado para o mesmo
2821 * atributo (common_filter[11]=67|234|22)
2822 */
2823 if (
2824 _nm.commons.strstr(
2825 selectedValue,
2826 multipleValuesSeparator
2827 )
2828 ) {
2829 var listValues = selectedValue.split(
2830 multipleValuesSeparator
2831 );
2832 var found = false;
2833 var valores = [];
2834 for (var i = 0; i < listValues.length; i++) {
2835 if (
2836 window.nmFilterInfo.hasOwnProperty(nmB) &&
2837 window.nmFilterInfo[nmB].values.hasOwnProperty(
2838 listValues[i]
2839 )
2840 ) {
2841 valores.push(String(
2842 window.nmFilterInfo[nmB].values[listValues[i]]
2843 ));
2844
2845 if (!found) {
2846 found = true;
2847 }
2848 }
2849 }
2850
2851 if (found) {
2852 newObjFilter[window.nmFilterInfo[nmB].name] =
2853 valores.join("|");
2854
2855 newFilters.push(newObjFilter);
2856
2857 break;
2858 }
2859 }
2860
2861 /**
2862 * apenas um filtro selecionado (common_filter[11]=67)
2863 */
2864 else {
2865 if (
2866 window.nmFilterInfo.hasOwnProperty(nmB) &&
2867 window.nmFilterInfo[nmB].values.hasOwnProperty(
2868 selectedValue
2869 )
2870 ) {
2871 newObjFilter[window.nmFilterInfo[nmB].name] = String(
2872 window.nmFilterInfo[nmB].values[selectedValue]
2873 );
2874
2875 newFilters.push(newObjFilter);
2876
2877 break;
2878 }
2879 }
2880 }
2881 }
2882 }
2883 }
2884
2885 return newFilters;
2886 };
2887
2888 /**
2889 * Checks if is necessary parser the object "_neemu" (neemu protocol)
2890 * @author Andrews Lince <andrews@neemu.com>
2891 * @since 2.13.4
2892 * @return {Boolean}
2893 */
2894 var neemuProtocolIsEnabled = function(window, storeConfig) {
2895 return (
2896 window._neemu !== undefined &&
2897 storeConfig.isNeemuProtocol !== false
2898 );
2899 };
2900
2901 /**
2902 * Defines the informations which will be sent to log
2903 *
2904 * @author Andrews Lince <andrews@neemu.com>
2905 * @since 2.0.0
2906 * @param {Object} opt
2907 * @return {Void}
2908 */
2909 var generateLogInformation = function (opt) {
2910 var win = window,
2911 queryString = win.location.search;
2912
2913 // parse the "_neemu" object (neemu protocol)
2914 if (neemuProtocolIsEnabled(window, $_ME.storeConfig)) {
2915 parseApiObject();
2916 }
2917
2918 // create recommendation areas
2919 if (
2920 $_ME.storeConfig.rec !== undefined
2921 && $_ME.storeConfig.rec.enable !== false
2922 && window.neemuPlugin.recommendation !== undefined
2923 && window.neemuPlugin.recommendation.pageType !== undefined
2924 ) {
2925 initRecommendation.call($_ME, neemuPlugin.recommendation.pageType);
2926 }
2927
2928 /********************** [ GENERAL INFORMATION ] ***********************/
2929 /*
2930 var nmSid = (
2931 _nm.conf.preset !== undefined
2932 && _nm.commons.strstr(_nm.conf.preset, "chaordic")
2933 )
2934 ? _nm.commons.getCookie("chaordic_browserId")
2935 : $_ME.sid;
2936 */
2937
2938 var extras = $_ME.info.general.extras || {};
2939
2940 if(
2941 _nm.conf.preset !== undefined &&
2942 _nm.commons.strstr(_nm.conf.preset, "chaordic")
2943 ){
2944 extras["chaordic_browserId"] = _nm.commons.getCookie("chaordic_browserId");
2945 extras["chaordic_anonymousUserId"] = _nm.commons.getCookie("chaordic_anonymousUserId");
2946 extras["chaordic_session"] = _nm.commons.getCookie("chaordic_session");
2947 }
2948
2949 $_ME.info.general.storeId = _nm.conf.store.id,
2950 $_ME.info.general.version = _nm.VERSION + "-" + _nm.buildDate,
2951 $_ME.info.general.chn = getChannel();
2952 $_ME.info.general.sid = $_ME.sid;//nmSid;
2953 $_ME.info.general.aid = window.nmExtractionAccessId || "";
2954 $_ME.info.general.agent = navigator.userAgent;
2955 $_ME.info.general.url = _nm.commons.getUrl();
2956 $_ME.info.general.referrer = _nm.commons.decodeUrl(document.referrer);
2957 $_ME.info.general.ts = Date.now ? Date.now() : (new Date()).getTime();
2958 $_ME.info.general.extras = extras;
2959
2960 // verificando se o referrer tem o protocolo
2961 if($_ME.info.general.referrer.indexOf('http') != 0 && $_ME.info.general.referrer != '') {
2962 $_ME.info.general.referrer = 'http://' + $_ME.info.general.referrer;
2963 }
2964
2965 /************************ [ USER INFORMATION ] ************************/
2966
2967 // geolocation
2968 if ($_ME.info.user.geolocation !== undefined) {
2969 $_ME.info.general.uGeo = $_ME.info.user.geolocation;
2970 }
2971
2972 // logged id
2973 if ($_ME.info.user.loggedId !== undefined) {
2974 $_ME.info.general.uId = $_ME.info.user.loggedId.toString();
2975 }
2976
2977 // name
2978 if ($_ME.info.user.name !== undefined) {
2979 $_ME.info.general.uName = $_ME.info.user.name;
2980 }
2981
2982 // email
2983 if (
2984 $_ME.info.user.email !== undefined
2985 && _nm.commons.isValidEmail($_ME.info.user.email)
2986 ) {
2987 $_ME.info.general.uEmail = correctEmail.call(
2988 this,
2989 $_ME.info.user.email
2990 );
2991 }
2992
2993 // checks if user is not logged on store, but is logged on neemu cookie
2994 if (
2995 typeof($_ME.info.general.uName) === "undefined" &&
2996 typeof($_ME.info.general.uEmail) === "undefined" &&
2997 neemuUserIsLogged()
2998 ) {
2999 var cookieUser = getNeemuLoggedUser();
3000
3001 if (cookieUser.name !== undefined) {
3002 $_ME.info.general.uName = cookieUser.name;
3003 }
3004
3005 if (cookieUser.email !== undefined) {
3006 $_ME.info.general.uEmail = cookieUser.email;
3007 $_ME.info.general.uId = "neemu" + $_ME.info.general.uEmail;
3008 }
3009 }
3010
3011 $_ME.finalJson.general = $_ME.info.general;
3012
3013 // detect page type
3014 switch ($_ME.info.general.pgType) {
3015
3016 case PAGE_DEPARTMENT :
3017
3018 // checks whether it is necessary order the tree departments
3019 if (
3020
3021 // check is has greater then one departament
3022 $_ME.info.department.tree.length > 1
3023
3024 // checks if the tree department is disorderly
3025 && parseInt($_ME.info.department.tree[0].index) > parseInt($_ME.info.department.tree[1].index)
3026 ) {
3027 $_ME.info.department.tree.sort(_nm.commons.arraySortBy(
3028 "index", // field sort
3029 false // ascending
3030 ));
3031 }
3032
3033 // processing category names
3034 var cNames = [];
3035 for (var i = 0; i < $_ME.info.department.tree.length; i++) {
3036 cNames.push($_ME.info.department.tree[i].name);
3037 }
3038 $_ME.info.department.tree = cNames;
3039
3040 // checks if category id was informed
3041 if ($_ME.info.department.cId === "") {
3042 $_ME.info.department.cId = cNames.join(" | ");
3043 }
3044
3045 $_ME.finalJson.info = $_ME.info.department;
3046
3047 break;
3048
3049 case PAGE_PRODUCT :
3050
3051 /******************* [ PRODUCT INFORMATION ] ******************/
3052
3053 $_ME.finalJson.info = $_ME.info.product;
3054
3055 /********************* [ SKU INFORMATION ] ********************/
3056
3057 if ($_ME.info.skuList) {
3058
3059 // convert sku index to the count index
3060 for (var prop in $_ME.info.skuList) {
3061 if (typeof($_ME.info.skuList[prop]) === "object") {
3062 $_ME.info.skuListFinal.push($_ME.info.skuList[prop]);
3063 }
3064 }
3065
3066 $_ME.info.product.skus = $_ME.info.skuListFinal;
3067 }
3068
3069 /**************** [ AUTOCOMPLETE INFORMATION ] ****************/
3070
3071 var acTypeClick = _nm.commons.getUrlParamValue("typeclick");
3072 if (acTypeClick !== null) {
3073 $_ME.finalJson.ac = {
3074 type : 3,
3075 prefix : _nm.commons.getUrlParamValue("p"),
3076 pos : _nm.commons.getUrlParamValue("ac_pos"),
3077 rank : parseInt(_nm.commons.getUrlParamValue("ranking"))
3078 };
3079 }
3080
3081 var origin = _nm.commons.getUrlParamValue("nm_origem");
3082 if (origin !== null) {
3083
3084 /*************** [ NEEMU MAIL INFORMATION ] ***************/
3085
3086 /**
3087 * TODO: o JSON do Neemu Mail será implementado depois,
3088 * a pedido do Cristian Rossi
3089 */
3090 /*if (_nm.commons.strstr(origin, "neemumail")) {
3091 finalJson.neemumailInformation = {
3092 campaign : origin.replace("neemumail_", ""),
3093 campaignId : _nm.commons.getUrlParamValue("nm_campanha"),
3094 ranking : _nm.commons.getUrlParamValue("nm_ranking_rec")
3095 };
3096 }*/
3097
3098 /************* [ RECOMMENDATION INFORMATION ] *************/
3099
3100 if (_nm.commons.strstr(origin, "rec")) {
3101
3102 // get ranking
3103 var recRanking =
3104 _nm.commons.getUrlParamValue("nm_ranking_rec");
3105
3106 var recList = {
3107 pgName : _nm.commons.getUrlParamValue("nm_rec_page") || "",
3108 scName : _nm.commons.getUrlParamValue("nm_rec_showcase") || "",
3109 scId : _nm.commons.getUrlParamValue("nm_rec_vid") || "",
3110 rank : recRanking,
3111 id : _nm.commons.getUrlParamValue("nm_rec_id") || "",
3112 scenario : _nm.commons.getUrlParamValue("nm_rec_scenario") || "",
3113 seg : _nm.commons.getUrlParamValue("nm_rec_segment") || "",
3114 cName : _nm.commons.getUrlParamValue("nm_rec_category") || "",
3115 chn : $_ME.info.general.chn
3116 };
3117
3118 if(typeof recList.rank == 'string') {
3119 recList.rank = parseInt(recList.rank);
3120 }
3121
3122 if(typeof recList.scId == 'string') {
3123 recList.scId = parseInt(recList.scId);
3124 }
3125
3126 recList.tree = [
3127 [
3128 recList.chn,
3129 recList.scenario,
3130 recList.seg,
3131 recList.pgName,
3132 recList.cName,
3133 recList.scName,
3134 recList.scId
3135 ],
3136 [
3137 recList.chn,
3138 recList.scenario,
3139 recList.seg,
3140 recList.pgName,
3141 recList.cName,
3142 recList.scId,
3143 recList.scName
3144 ],
3145 [
3146 recList.chn,
3147 recList.scenario,
3148 recList.pgName,
3149 recList.scName,
3150 recList.cName,
3151 recList.seg,
3152 recList.scId
3153 ]
3154 ];
3155
3156 // prime offer
3157 var primeOffer = _nm.commons.getUrlParamValue("nm_primeoffer");
3158 if (primeOffer!== null) {
3159 recList.primeoffer = primeOffer;
3160 }
3161
3162 $_ME.finalJson.rec = {
3163 list : [recList]
3164 };
3165 }
3166 }
3167
3168 break;
3169
3170 case PAGE_CHECKOUT :
3171
3172 $_ME.finalJson.info = $_ME.info.checkoutInformation;
3173
3174 break;
3175
3176 case PAGE_CHECKOUT_CART :
3177
3178 $_ME.finalJson.info = {
3179 skus : $_ME.info.skuList
3180 };
3181
3182 // sets the sku list for the recommendation
3183 if(
3184 $_ME.info.skuList
3185 && neemuPlugin.recommendation !== undefined
3186 && neemuPlugin.recommendation.skuRecommendation === undefined
3187 ) {
3188 neemuPlugin.recommendation.skuRecommendation = { id: '', sku: '' };
3189 for(var i = 0; i < $_ME.info.skuList.length; i++) {
3190 neemuPlugin.recommendation.skuRecommendation.id += $_ME.info.skuList[i].id + ';';
3191 neemuPlugin.recommendation.skuRecommendation.sku += $_ME.info.skuList[i].sku + ';';
3192 }
3193 }
3194
3195 break;
3196
3197 case PAGE_CHECKOUT_CONFIRMATION :
3198
3199 $_ME.finalJson.info = $_ME.info.checkoutConfirmation;
3200 $_ME.finalJson.info.skus = $_ME.info.skuList;
3201
3202 break;
3203
3204 case PAGE_COMPARISON :
3205
3206 $_ME.finalJson.comparisonInformation = {
3207 skuList : $_ME.info.skuList
3208 };
3209
3210 break;
3211
3212 case PAGE_NAVIGATION :
3213
3214 $_ME.finalJson.info = $_ME.info.navigation;
3215 $_ME.finalJson.info.pIds = $_ME.info.search.pIds;
3216
3217 break;
3218
3219 case PAGE_HOTSITE :
3220
3221 $_ME.finalJson.info = $_ME.info.hotsite;
3222
3223 break;
3224
3225 case PAGE_NEEMU_PAGES_INDEX :
3226 case PAGE_NEEMU_PAGES :
3227 case PAGE_SEARCH :
3228
3229 if (
3230 $_ME.info.search.filters !== undefined &&
3231 $_ME.info.general.apiSearchVersion !== undefined
3232 ) {
3233 var newFilters = convertSearchFilters($_ME.info.search);
3234
3235 delete $_ME.info.search.filters;
3236
3237 $_ME.info.search.filters = newFilters;
3238 }
3239
3240 if ($_ME.info.autocomplete.type !== undefined) {
3241 $_ME.finalJson.ac = $_ME.info.autocomplete;
3242 }
3243
3244 if (!_nm.commons.objectIsEmpty($_ME.info.quickFilter)) {
3245 $_ME.finalJson.qf = $_ME.info.quickFilter;
3246 }
3247
3248 $_ME.finalJson.info = $_ME.info.search;
3249
3250 break;
3251 case PAGE_WISHLIST :
3252 $_ME.finalJson.info = $_ME.info.wishlist;
3253
3254 case PAGE_COLLECTION_HOME:
3255 case PAGE_COLLECTION_SEARCH:
3256 case PAGE_COLLECTION_DETAILS:
3257 case PAGE_COLLECTION_AUTHOR:
3258 case PAGE_COLLECTION_REGISTER:
3259 case PAGE_COLLECTION_RELATED:
3260 case PAGE_COLLECTION_TAG:
3261 this.generateCollectionLogInformation(this.info.general.pgType);
3262 break;
3263 }
3264
3265 // var nameObj = LOGLABEL[opt.type];
3266 // logInfo[nameObj] = opt.data;
3267
3268 // /*define se a recomendacao é teste no objeto*/
3269 // if (neemu.rec !== undefined) {
3270 // var recHasTest = neemu.rec.getRecTest();
3271 // setRecTestGeneral.call(this, recHasTest);
3272 // }
3273
3274 // if (
3275 // typeof _nm.conf.parse !== 'undefined'
3276 // && typeof _nm.conf.parse.general !== 'undefined'
3277 // && typeof _nm.conf.parse.general.testAB !== 'undefined'
3278 //) {
3279 // logInformation.generalInfo.testab =
3280 // neemu.parse.exec(_nm.conf.parse.general.testAB);
3281 // }
3282
3283 // /* verificando se existe clique da rec guardado em cookie */
3284 // var recDataClick = logInformation.recDataClickCookie;
3285 // if (recDataClick !== false && getPageType() == CART_PAGE) {
3286
3287 // if (recDataClick.sku === '') {
3288 // recDataClick.sku = recDataClick.pid;
3289 // }
3290
3291 // logInfo[nameObj].rec_atc_pid = recDataClick.pid;
3292 // logInfo[nameObj].rec_atc_sku = recDataClick.sku;
3293 // logInfo[nameObj].rec_atc_vtr = recDataClick.vtr;
3294 // logInfo[nameObj].rec_atc_pos = recDataClick.pos;
3295 // }
3296
3297 if (
3298 (
3299 /**
3300 * checks if the page should have the global variable
3301 * "neemu_product_list"
3302 */
3303 $_ME.info.general.pgType === PAGE_SEARCH
3304 || $_ME.info.general.pgType === PAGE_NEEMU_PAGES
3305 || $_ME.info.general.pgType === PAGE_NEEMU_PAGES_INDEX
3306 )
3307
3308 && (
3309 // checks if the result search is greater than zero
3310 window.neemuNumResultadosTotal !== undefined
3311 && neemuNumResultadosTotal > 0
3312 )
3313
3314 // checks if the sku_list is not loaded
3315 && $_ME.finalJson.info.pIds
3316 && !$_ME.finalJson.info.pIds.length
3317 ) {
3318 var qtyRepeats = 0;
3319 var qtyRepeatsMax = 20;
3320 var extractionInterval = setInterval(function() {
3321 qtyRepeats++;
3322 if (
3323 qtyRepeats < qtyRepeatsMax
3324 && (window.neemu_product_list !== undefined)
3325 ) {
3326
3327 // populate the skulist
3328 $_ME.finalJson.info.pIds = window.neemu_product_list;
3329
3330 // send log information
3331 opt.callback.call($_ME, $_ME.finalJson);
3332
3333 // stop the repetition
3334 clearInterval(extractionInterval);
3335 }
3336 }, 300);
3337 } else {
3338 opt.callback.call($_ME, $_ME.finalJson);
3339 }
3340 };
3341
3342 /**
3343 * @author Jhozefem Pontes <jhozefem@neemu.com>
3344 * @author Andrews Lince <andrews@neemu.com>
3345 * @since 1.0.0
3346 * @param {Integer} testValue
3347 * @return {Boolean}
3348 */
3349 var isAllowTest = function(testValue) {
3350 var value = _nm.commons.parseStringToNumber($_ME.sid),
3351 allow = false;
3352
3353 value = value % 100;
3354
3355 if (testValue > value) {
3356 allow = true;
3357 }
3358
3359 return allow;
3360 };
3361
3362 /**
3363 * Generate a aleatory code for the user session
3364 *
3365 * @author Jhozefem Pontes <jhozefem@neemu.com>
3366 * @since 2.0.0
3367 * @return {String}
3368 */
3369 var getSessionId = function() {
3370
3371 // checks if the cookie already is saved
3372 var sid = _nm.commons.getCookie("neemu_sid");
3373 if (sid == undefined || sid == "undefined") {
3374 var dt = new Date(),
3375 t = _nm.commons.base36encode(dt.getTime()),
3376 r = _nm.commons.base36encode(_nm.commons.random());
3377
3378 for (var i = t.length; i < 8; i++) { t = "0" + t; }
3379 for (var i = r.length; i < 4; i++) { r = "0" + r; }
3380
3381 sid = t + r;
3382 }
3383
3384 // sets the cookie
3385 _nm.commons.setCookie('neemu_sid', sid, Infinity, "/", "." + conf.store.host);
3386
3387 return sid;
3388 };
3389
3390 /**
3391 * Generate a aleatory code for the user access
3392 *
3393 * @author Andrews Lince <andrews@neemu.com>
3394 * @since 2.8.0
3395 * @return {String}
3396 */
3397 var getAccessId = function() {
3398
3399 var accessId = "";
3400
3401 /**
3402 * TODO: verificação comentada temporariamente, pois estava gerando o
3403 * mesmo accessId durante as paginações.
3404 */
3405 // if (window.nmExtractionAccessId !== undefined) {
3406 // accessId = window.nmExtractionAccessId;
3407 // } else {
3408
3409 // part 1
3410 var sid = getSessionId.call(this);
3411
3412 // part 2
3413 var year = new Date().getFullYear();
3414 var secondsYear = new Date().getTime() - new Date(year, 1, 1).getTime();
3415 var secondsYearB36 = _nm.commons.base36encode(secondsYear);
3416
3417 // part 3
3418 var randomNumber = _nm.commons.randomBetween(1, 60466175).toString();
3419 var randomNumberB36 = _nm.commons.base36encode(randomNumber);
3420
3421 accessId = sid + secondsYearB36 + randomNumberB36;
3422 // }
3423
3424 return accessId;
3425 };
3426
3427 /**
3428 * @author Andrews Lince <andrews@neemu.com>
3429 * @version 2.1.11
3430 * @return {String}
3431 */
3432 var getChannel = function() {
3433 return (_nm.isMobile)
3434 ? "site-mobile"
3435 : "site"
3436 };
3437
3438 /**
3439 * @author Andrews Lince <andrews@neemu.com>
3440 * @param {Object} data
3441 * @param {Boolean} erro
3442 * @return {String}
3443 */
3444 var getLogRequestUrl = function(data, erro) {
3445 if (erro === undefined) {
3446 erro = false;
3447 }
3448
3449 var logRequestUrl = $_ME.protocol;
3450 logRequestUrl += $_ME.logServer;
3451 logRequestUrl += '/grava.php?callback=neemuCallback';
3452 logRequestUrl += '&psid=1';
3453 logRequestUrl += '&sid=' + $_ME.sid;
3454 logRequestUrl += '&log' + ((erro) ? 'Erro' : '') + '=' + _nm.commons.encode(data);
3455
3456 return logRequestUrl;
3457 }
3458
3459 /**
3460 * Recupera informações gerais e a URL FINAL do grava.php
3461 * @param {Object} opt
3462 */
3463 var getUrlFinal = function(opt) {
3464 if (opt.log) {
3465
3466 // execute store parse
3467 $_ME.storeConfig.parse(_nm);
3468
3469 if (!$_ME.pauseExtraction) {
3470 generateLogInformation.call($_ME, {
3471 data: opt.data,
3472 callback: function(data) {
3473 send.call($_ME, getLogRequestUrl.call($_ME, data));
3474 }
3475 });
3476 }
3477 } else {
3478 send.call($_ME, getLogRequestUrl.call($_ME, opt.data, true));
3479 }
3480 };
3481
3482 /**
3483 * @author Andrews Lince <andrews@neemu.com>
3484 * @since 2.0.0
3485 * @return {Boolean}
3486 */
3487 var canSendExtraction = function() {
3488 var host = window.location.host;
3489 return (
3490 !_nm.commons.userAgentIsBot() &&
3491 (
3492 _nm.commons.strstr(host, _nm.conf.store.host) ||
3493 _nm.commons.strstr(host, "neemu.com") ||
3494 _nm.commons.strstr(host, "teste")
3495 ) &&
3496 (
3497 window.neemuExtractInfo === undefined ||
3498 window.neemuExtractInfo == 1
3499 )
3500 )
3501 ? true
3502 : false;
3503 };
3504
3505 /**
3506 * Adicionar grava no header e enviar
3507 * @param {String} source url final
3508 */
3509 var send = function(source) {
3510 // executing callbacks
3511 for (var i = 0; i < _nm.callbacks.beforeLogRequests.length; i++) {
3512 _nm.callbacks.beforeLogRequests[i].call(this);
3513 }
3514
3515 // validate the send extraction
3516 if (canSendExtraction.call($_ME)) {
3517 var scriptTag = _nm.commons.createElement('script', {
3518 'src': source
3519 });
3520 var head = document.getElementsByTagName('head')[0];
3521 head.appendChild(scriptTag);
3522
3523 // indicates which the page already was extracted
3524 window.nmPageLoggedTest = 1;
3525
3526 /**
3527 * checks if is necessary copy the url from log to the clipboard
3528 * (only on Internet Explorer), to help in the debug process of
3529 * the extraction
3530 */
3531 if (
3532 (
3533 $_ME.storeConfig.copyLogUrlOnIE !== undefined
3534 && $_ME.storeConfig.copyLogUrlOnIE === true
3535 )
3536 && _nm.commons.strstr(source, "&log=")
3537 && _nm.commons.strstr(navigator.userAgent.toLowerCase(), "msie")
3538 ) {
3539 if (confirm("Você gostaria de salvar a URL do grava no clipboard?")) {
3540 if (window.clipboardData.setData("Text", source.split("&log=")[1])) {
3541 alert("URL do grava salva com sucesso!");
3542 }
3543 }
3544 }
3545 }
3546
3547 // remoção do SID e PSID antigos
3548 _nm.commons.deleteCookie("sessao_logsite", _nm.conf.store.host);
3549 _nm.commons.deleteCookie("sessao_logsite_permanente", _nm.conf.store.host);
3550 };
3551
3552 /**
3553 * @author Andrews Lince <andrews@neemu.com>
3554 * @version 2.0.0
3555 * @return {Void}
3556 */
3557 var process = function () {
3558
3559 // block empty search (only if necessary)
3560 if (
3561 _nm.blockEmptySearch !== undefined
3562 && (
3563 window.searchBlocked === undefined
3564 || window.searchBlocked !== true
3565 )
3566 ) {
3567 _nm.blockEmptySearch.set($_ME.storeConfig.blockEmptySearch);
3568 }
3569
3570 // recommendation test
3571 if (
3572 $_ME.storeConfig.rec !== undefined
3573 && $_ME.storeConfig.rec.test !== undefined
3574 ) {
3575 _nm.rec.setRecTest.call($_ME, isAllowTest($_ME.storeConfig.rec.test));
3576 }
3577
3578 // sets the "neemuPlugin" informations
3579 if (window.neemuPlugin !== undefined) {
3580 neemuPlugin.session_id = $_ME.sid;
3581 neemuPlugin.neemuClientMainhost = _nm.conf.store.host;
3582 }
3583
3584 getUrlFinal.call($_ME, {
3585 log : true,
3586 data : info
3587 });
3588 };
3589
3590 /**
3591 * Inicia o processo de extração
3592 * @author Javier Zambrano
3593 * @author Andrews Lince <andrews@neemu.com>
3594 * @since 1.0.0
3595 * @param {Object} opt objeto com informações do conf
3596 */
3597 var startLog = function(opt) {
3598 initializeLogInformation.call($_ME);
3599
3600 // chaordic features
3601 if (opt.chaordic) {
3602 _nm.chaordic.init(opt);
3603 }
3604
3605 if (
3606 $_ME.storeConfig.debug !== undefined
3607 && $_ME.storeConfig.debug === true
3608 ) {
3609 process.call($_ME);
3610 } else {
3611 try {
3612 process.call($_ME);
3613 } catch(e) {
3614
3615 // format stack trace
3616 var traceArray = (e.stack || e.message).split("\n");
3617 for (var i = 0; i < traceArray.length; i++) {
3618 traceArray[i] = traceArray[i].trim();
3619 }
3620
3621 getUrlFinal.call($_ME, {
3622 log : false,
3623 data : {
3624 url : _nm.commons.getUrl(),
3625 message : e.message,
3626 stackTrace : traceArray,
3627 userAgent : $_ME.agent,
3628 canal : getChannel(),
3629 pageType : ($_ME.info.general.pgType || "genericError"),
3630 version : _nm.VERSION ? _nm.VERSION + "-" + _nm.buildDate : 0
3631 }
3632 });
3633 }
3634 }
3635 };
3636
3637 /**
3638 * Initialize the configurated preset from the store
3639 * @author Andrews Lince <andrews@neemu.com>
3640 * @since 2.12.18
3641 * @return {Void}
3642 */
3643 var loadPreset = function(extractionConfig) {
3644 if (
3645 extractionConfig.preset !== undefined &&
3646 typeof(_nm.preset[extractionConfig.preset].init) === "function"
3647 ) {
3648 _nm.preset[extractionConfig.preset].init(extractionConfig);
3649 }
3650 };
3651
3652 /**
3653 * @author Andrews Lince <andrews@neemu.com>
3654 * @since 2.0.0
3655 * @param {Object} opt
3656 * @return {Void}
3657 */
3658 var init = function(opt) {
3659
3660 loadPreset(opt);
3661
3662 // checks if the page already was extracted
3663 if (
3664 window.nmPageLoggedTest === undefined
3665 || (
3666 window.nmPageLoggedTest !== undefined
3667 && window.nmPageLoggedTest !== 1
3668 )
3669 ) {
3670 window.nmExtractionAccessId = getAccessId.call(this);
3671
3672 var fnStartLog = function(opt) {
3673 var execute = true;
3674 if (opt.blackList !== undefined) {
3675 var sizeBlackList = opt.blackList.length, i = 0;
3676 for (i; i < sizeBlackList; i++) {
3677 var urlBlackSite = opt.blackList[i];
3678 if (_nm.commons.strstr(_nm.commons.getUrl(), urlBlackSite)) {
3679 execute = false;
3680 }
3681 }
3682 }
3683 if (execute) {
3684
3685 // register store configurations
3686 $_ME.storeConfig = opt;
3687
3688 // register the user session id
3689 $_ME.sid = getSessionId.call(this);
3690
3691 // register the user agent
3692 $_ME.agent = navigator.userAgent || navigator.vendor || window.opera;
3693
3694 // register the protocol
3695 $_ME.protocol = window.location.protocol + "//";
3696
3697 // register the log server
3698 $_ME.logServer = opt.store.logServer + "/" +
3699 getStoreIdByEnv(opt.store.id, window.location.host);
3700
3701 // detect if is mobile device
3702 _nm.isMobile = _nm.commons.isMobile();
3703
3704 /**
3705 * TODO: esse trecho parece que era necessário por conta do módulo
3706 * especÃÂfico da vtex. Verificar com o Jhozefem se isso ainda
3707 * precisa estar na API ou se essas coisas serão passadas pelo
3708 * time de operação.
3709 */
3710 // if (opt.autocomplete && typeof opt.autocomplete == 'object') {
3711 // if (opt.type && opt.type == 'vtex') {
3712 // if (opt.autocomplete && typeof opt.autocomplete == 'object') {
3713 // vtex.removeAutocomplete();
3714 // }
3715 // }
3716 // addAutocomplete.call(this, opt.autocomplete);
3717 // }
3718
3719 if (opt.domReady) {
3720 _nm.commons.domReady(function() {
3721 startLog.call($_ME, opt);
3722 });
3723 } else {
3724 startLog.call($_ME, opt);
3725 }
3726 }
3727 }
3728
3729 /**
3730 * add configuration "waitInitExtraction" by default
3731 * for neemu protocol
3732 */
3733 if (
3734 _nm.neemuProtocolLoaded &&
3735 !opt.preset &&
3736 opt.waitInitExtraction === undefined
3737 ) {
3738 opt.waitInitExtraction = {
3739 times: 20,
3740 delay: 250,
3741 fnCallback: function(_nm) {
3742 return window._neemu !== undefined
3743 }
3744 };
3745 }
3746
3747 if (opt.waitInitExtraction !== undefined) {
3748 _nm.commons.checkConditionInterval(
3749 opt.waitInitExtraction.times,
3750 opt.waitInitExtraction.delay,
3751 function(){
3752 return opt.waitInitExtraction.fnCallback(_nm);
3753 },
3754 function() {
3755 fnStartLog(opt);
3756 }
3757 );
3758 } else {
3759 fnStartLog(opt);
3760 }
3761 }
3762 };
3763
3764 /**
3765 * Process the store id by according with environment
3766 * @author Andrews Lince <andrews@neemu.com>
3767 * @since 2.10.9
3768 * @param {String} storeId Store id from store
3769 * @param {String} host current host from URL
3770 * @return {String}
3771 */
3772 var getStoreIdByEnv = function(storeId, host) {
3773
3774 // store production by default
3775 var storeIdByEnv = storeId;
3776
3777 // neemu development
3778 if (_nm.commons.strstr(host, "local.")) {
3779 storeIdByEnv += "-dev";
3780 }
3781
3782 // neemu staging
3783 else if (_nm.commons.strstr(host, "valid.neemu.com")) {
3784 storeIdByEnv += "-stg";
3785 }
3786
3787 // neemu production
3788 else if (_nm.commons.strstr(host, ".neemu.com")) {
3789 storeIdByEnv += "-prd";
3790 }
3791
3792 return storeIdByEnv;
3793 };
3794
3795 /**
3796 * @author Andrews Lince <andrews@neemu.com>
3797 * @since 2.0.0
3798 * @param {String} pageType
3799 * @return {Void}
3800 */
3801 var initRecommendation = function(pageType) {
3802 if (
3803 _nm.rec !== undefined
3804 && neemuPlugin !== undefined
3805 && $_ME.storeConfig.rec !== undefined
3806 && neemuPlugin.recommendation !== undefined
3807 && $_ME.storeConfig.rec.hasOwnProperty(pageType)
3808 ) {
3809 loadInitRecommendation = true;
3810
3811 _nm.rec.insert({
3812 url : $_ME.storeConfig.rec.url,
3813 page : pageType,
3814 test : $_ME.storeConfig.rec.test,
3815 info : $_ME.storeConfig.rec[pageType],
3816 allowMobile : $_ME.storeConfig.rec.allowMobile || false
3817 });
3818 }
3819 };
3820
3821 /**
3822 * Returns the pagetype
3823 * @author Andrews Lince <andrews@neemu.com>
3824 * @since 2.12.10
3825 * @return {String}
3826 */
3827 var getPageType = function() {
3828 return $_ME.info.general.pgType;
3829 };
3830
3831 var setPageType = function(pageType) {
3832 $_ME.info.general.pgType = pageType;
3833
3834 /**
3835 * disregards page types of user action tracking
3836 */
3837 if (
3838 pageType !== PAGE_REC_PRINT
3839 && pageType !== PAGE_ADD_TO_CART
3840 ) {
3841 if (neemuPlugin.recommendation === undefined) {
3842 neemuPlugin.recommendation = {};
3843 }
3844
3845 // navigation >> departamento
3846 if (pageType === PAGE_NAVIGATION) {
3847 neemuPlugin.recommendation.pageType = "departamento";
3848 }
3849
3850 // checks if the page type is search and if is a not found search
3851 else if (
3852 pageType === PAGE_SEARCH
3853 && window.neemuNumResultadosTotal !== undefined
3854 && window.neemuNumResultadosTotal === 0
3855 ) {
3856 neemuPlugin.recommendation.pageType = PAGE_NOT_FOUND;
3857 }
3858
3859 neemuPlugin.recommendation.pageType =
3860 (
3861 (neemuPlugin.recommendation.pageType !== undefined)
3862 ? neemuPlugin.recommendation.pageType
3863 : pageType
3864 );
3865 }
3866 };
3867
3868 /**
3869 * @author Andrews Lince <andrews@neemu.com>
3870 * @since 2.0.0
3871 * @param {Object} data
3872 * @return {Void}
3873 */
3874 var _setAccount = function(data) {
3875 // $_ME.sid = _nm.commons.getSessionId();
3876 };
3877
3878 /**
3879 * Identifies the logged user by cookie from Neemu
3880 * @author Andrews Lince <andrews@neemu.com>
3881 * @since 2.12.18
3882 * @return {Boolean}
3883 */
3884 var neemuUserIsLogged = function() {
3885 return (
3886 _nm.commons.getCookie("neemuDataUserName") !== undefined ||
3887 _nm.commons.getCookie("neemuDataUserEmail") !== undefined
3888 )
3889 };
3890
3891 /**
3892 * Returns the informations from logged Neemu user
3893 * @author Andrews Lince <andrews@neemu.com>
3894 * @since 2.12.18
3895 * @return {Boolean}
3896 */
3897 var getNeemuLoggedUser = function() {
3898 var neemuLoggedUser = {},
3899 name = _nm.commons.getCookie("neemuDataUserName"),
3900 email = _nm.commons.getCookie("neemuDataUserEmail");
3901
3902 if (name !== undefined) {
3903 neemuLoggedUser.name = name;
3904 }
3905
3906 if (email !== undefined) {
3907 neemuLoggedUser.email = email;
3908 }
3909
3910 return neemuLoggedUser;
3911 };
3912
3913 /**
3914 * Saves the user informations in cookie, by 30 days
3915 * @author Andrews Lince <andrews@neemu.com>
3916 * @since 2.12.18
3917 * @param {Object} data
3918 * - name
3919 * - email
3920 * @return {Boolean}
3921 */
3922 var setNeemuLoggedUser = function(data) {
3923 if (data.name !== undefined) {
3924 _nm.commons.setCookie(
3925 "neemuDataUserName",
3926 data.name,
3927 43200, // 30 dias
3928 "/",
3929 "." + _nm.conf.store.host
3930 );
3931 }
3932
3933 if (data.email !== undefined) {
3934 _nm.commons.setCookie(
3935 "neemuDataUserEmail",
3936 data.email,
3937 43200, // 30 dias
3938 "/",
3939 "." + _nm.conf.store.host
3940 );
3941 }
3942 };
3943
3944 /**
3945 * @author Andrews Lince <andrews@neemu.com>
3946 * @param {Object} data
3947 * - geolocation
3948 * - loggedId
3949 * - name
3950 * - email
3951 * @return {Void}
3952 */
3953 var _setUser = function(data) {
3954
3955 setNeemuLoggedUser(data);
3956
3957 $_ME.info.user = data;
3958 };
3959
3960 var _addProductSearch = function(param1, param2) {
3961 if ($_ME.info.search.pIds === undefined) {
3962 $_ME.info.search.pIds = [];
3963 }
3964
3965 if(typeof(param1) != 'undefined' && typeof(param2) != 'undefined') {
3966 var sku = {};
3967 sku[param2] = param1;
3968
3969 $_ME.info.search.pIds.push(sku);
3970 }
3971 else if(typeof(param1) == 'object') {
3972 for(var i = 0; i < param1.length; i++) {
3973 var sku = {};
3974 sku[param1[i].ranking] = param1[i].id;
3975
3976 $_ME.info.search.pIds.push(sku);
3977 }
3978 }
3979 };
3980
3981 /**
3982 * @author Andrews Lince <andrews@neemu.com>
3983 * @since 2.1.0
3984 * @param {Object} data
3985 * @return {Object}
3986 */
3987 var castOfSearchInformations = function(data) {
3988
3989 // cast from integer values
3990 data.pg = parseInt(data.pg);
3991 data.qty = parseInt(data.qty);
3992 data.qtyAnd = parseInt(data.qtyAnd);
3993
3994 if (data.hasSuggest!== undefined) {
3995 data.hasSuggest = parseInt(data.hasSuggest);
3996 }
3997
3998 return data;
3999 };
4000
4001 /**
4002 * @author Andrews Lince <andrews@neemu.com>
4003 * @since 2.1.0
4004 * @return {Void}
4005 */
4006 var getSearchSort = function() {
4007 var searchSort = _nm.commons.getUrlParamValue("sort");
4008 if (searchSort !== null) {
4009 $_ME.info.search.sort = parseInt(searchSort);
4010 $_ME.info.navigation.sort = parseInt(searchSort);
4011 }
4012 };
4013
4014 /**
4015 * @author Andrews Lince <andrews@neemu.com>
4016 * @since 2.1.0
4017 * @param {Object} data
4018 * @return {Object}
4019 */
4020 var _setNeemuPagesInformation = function(data) {
4021 if (data.q === data.qOrig) {
4022 delete data.qOrig;
4023 }
4024
4025 data = castOfSearchInformations(data);
4026
4027 // merge search information
4028 $_ME.info.search = _nm.commons.objectMerge($_ME.info.search, data);
4029 };
4030
4031 /**
4032 * @author Andrews Lince <andrews@neemu.com>
4033 * @since 2.1.0
4034 * @param {Object} data
4035 * @return {Object}
4036 */
4037 var _setNeemuPagesIndexInformation = function(data) {
4038 if (data.q === data.qOrig) {
4039 delete data.qOrig;
4040 }
4041
4042 data = castOfSearchInformations(data);
4043
4044 // merge search information
4045 $_ME.info.search = _nm.commons.objectMerge($_ME.info.search, data);
4046 };
4047
4048 /**
4049 * @author Andrews Lince <andrews@neemu.com>
4050 * @since 2.1.0
4051 * @return {Void}
4052 */
4053 var _setNavigationInformation = function(data) {
4054 data = castOfSearchInformations(data);
4055
4056 // sort
4057 getSearchSort.call($_ME);
4058
4059 // defines the category id for neemu recommendation
4060 if (!neemuPlugin.departmentInformation) {
4061 neemuPlugin.departmentInformation = {};
4062 }
4063 neemuPlugin.departmentInformation.categoryId = data.cId;
4064
4065 $_ME.info.navigation = _nm.commons.objectMerge($_ME.info.navigation, data);
4066
4067 $_ME.loadDepartmentList(data.cId);
4068 };
4069
4070 /**
4071 * @author Andrews Lince <andrews@neemu.com>
4072 * @param {Object} data
4073 * - query
4074 * - qtyResults
4075 * - processTime
4076 * @return {Void}
4077 */
4078 var _setSearchInformation = function(data) {
4079 var w = window,
4080 queryString = w.location.search
4081 requestParams = _nm.commons.getRequestParams();
4082
4083 // old version of search (without mustache)
4084 if (w.neemuQuery !== undefined) {
4085
4086 $_ME.info.search.pg = 0;
4087 $_ME.info.search.qty = parseInt(w.neemuNumResultadosTotal) || 0;
4088 $_ME.info.search.qtyAnd = parseInt(w.neemuNumResultadosAnd) || 0;
4089 $_ME.info.search.q = w.neemuQuery || "";
4090 $_ME.info.search.hasSuggest = parseInt(w.neemuSugestaoConsulta) || 0;
4091
4092 // dyd you mean
4093 if (w.neemuVqd !== "0") {
4094 $_ME.info.search.qOrig = w.neemuQOriginal;
4095 }
4096
4097 // product ids
4098 var productList = w.neemu_product_list || [],
4099 pIds = [];
4100 for (var i = 0; i < productList.length; i++) {
4101 var obj = {};
4102 obj[String(productList[i].ranking)] = productList[i].id
4103 pIds.push(obj);
4104 }
4105 $_ME.info.search.pIds = pIds;
4106
4107 // page number
4108 var urlPgNumber = _nm.commons.getUrlParamValue("page");
4109 if (w.nmPgNumber === undefined) {
4110 w.nmPgNumber = (urlPgNumber !== null)
4111 ? parseInt(urlPgNumber)
4112 : 1;
4113 } else if (
4114 typeof $_ME.info.search.pIds[0] !== undefined &&
4115 !$_ME.info.search.pIds[0].hasOwnProperty("1")
4116 ) {
4117 w.nmPgNumber = (urlPgNumber !== null)
4118 ? parseInt(urlPgNumber)
4119 : w.nmPgNumber + 1;
4120 }
4121 $_ME.info.search.pg = w.nmPgNumber;
4122
4123 // sort
4124 var searchSort = _nm.commons.getUrlParamValue("sort");
4125 if (searchSort !== null) {
4126 $_ME.info.search.sort = parseInt(searchSort);
4127 }
4128
4129 // origin
4130 // var searchOrigin = _nm.commons.getUrlParamValue("origem");
4131 // if (searchOrigin !== null) {
4132 // $_ME.info.search.origin = searchOrigin;
4133 // }
4134
4135 if (w.neemuOrigin !== undefined) {
4136 $_ME.info.search.origin = w.neemuOrigin;
4137 }
4138
4139 // filters
4140 if (_nm.commons.isSearchFilter(queryString)) {
4141 var searchFilters = [];
4142
4143 for (var paramName in requestParams) {
4144 if (_nm.commons.isSearchFilter(paramName)) {
4145 var objFilter = {};
4146 objFilter[paramName.match(/\[(.*)\]/)[1]] =
4147 requestParams[paramName].trim();
4148 searchFilters.push(objFilter);
4149 }
4150 }
4151
4152 $_ME.info.search.filters = searchFilters;
4153 }
4154
4155 // a/b test
4156 if (w.neemuTesteAB !== undefined) {
4157 $_ME.info.general.testab = w.neemuTesteAB;
4158 }
4159
4160 /******************** [ AUTOCOMPLETE INFORMATION ] ********************/
4161
4162 var acTypeClick = _nm.commons.getUrlParamValue("typeclick");
4163 if (acTypeClick !== null) {
4164 $_ME.info.autocomplete = {
4165 type : parseInt(acTypeClick),
4166 prefix : _nm.commons.getUrlParamValue("p"),
4167 q : _nm.commons.getUrlParamValue("q"),
4168 pos : _nm.commons.getUrlParamValue("ac_pos"),
4169 rank : parseInt(_nm.commons.getUrlParamValue("ranking"))
4170 };
4171
4172 // autocomplete with category
4173 var categoryFilter = _nm.commons.getUrlParamValue("common_filter[Categoria]");
4174 if (categoryFilter !== null) {
4175 $_ME.info.autocomplete.type = 2;
4176 }
4177 }
4178
4179 /******************** [ QUICK FILTER INFORMATION ] ********************/
4180
4181 /**
4182 * TODO: verificar com a Adriana como mandar essa informação
4183 * de quick filter, pois nem sempre vem uma categoria.
4184 */
4185
4186 /******************** [ NEEMU PAGES INFORMATION ] *********************/
4187
4188 if (
4189 w.neemuPageType !== undefined &&
4190 _nm.commons.strstr(w.neemuPageType, PAGE_NEEMU_PAGES)
4191 ) {
4192 // remove unnecessary fields
4193 delete $_ME.info.search.type;
4194 delete $_ME.info.search.pg;
4195
4196 $_ME.info.general.pgType = w.neemuPageType;
4197 $_ME.info.search.q = w.location.pathname.slice(1);
4198 }
4199
4200 /********************* [ NAVIGATION INFORMATION ] *********************/
4201
4202 if (w.neemuCategoria !== undefined && w.neemuCategoria.id !== "") {
4203 delete $_ME.info.search.query;
4204 $_ME.info.general.pgType = PAGE_NAVIGATION;
4205 $_ME.info.search.categoryId = w.neemuCategoria.id;
4206 $_ME.info.search.categoryName = w.neemuCategoria.name;
4207 $_ME.info.search.type = w.neemuNavType.replace("nav_", "");
4208
4209 // departmentList
4210 loadDepartmentList.call($_ME, $_ME.info.search.categoryId);
4211 } else {
4212 // queryList
4213 loadQueryList.call($_ME, $_ME.info.search.query);
4214 }
4215 }
4216
4217 // new version of search (with mustache)
4218 else {
4219
4220 // checks if is necessary consider the original query
4221 if (data.q === data.qOrig) {
4222 delete data.qOrig;
4223 }
4224
4225 data = castOfSearchInformations(data);
4226
4227 if (data.qty === 0) {
4228 neemuPlugin.recommendation.pageType = PAGE_NOT_FOUND;
4229 }
4230
4231 // merge search information
4232 $_ME.info.search = _nm.commons.objectMerge($_ME.info.search, data);
4233
4234 // sort
4235 getSearchSort.call($_ME);
4236
4237 // filters
4238 if (_nm.commons.isSearchFilter(queryString)) {
4239 var searchFilters = [];
4240 var searchFiltersKeys = [];
4241
4242 for (var paramName in requestParams) {
4243 if (_nm.commons.isSearchFilter(paramName)) {
4244 var objFilter = {};
4245 var filterName = paramName.match(/\[(.*)\]/)[1];
4246 var filterValue = requestParams[paramName].trim();
4247 objFilter[filterName] = filterValue;
4248 searchFilters.push(objFilter);
4249 searchFiltersKeys.push({
4250 name: filterName,
4251 value: filterValue
4252 });
4253 }
4254 }
4255
4256 $_ME.info.search.filters = searchFilters;
4257 }
4258
4259 /******************** [ AUTOCOMPLETE INFORMATION ] ********************/
4260
4261 var acTypeClick = _nm.commons.getUrlParamValue("typeclick");
4262 if (acTypeClick !== null) {
4263 $_ME.info.autocomplete = {
4264 type : parseInt(acTypeClick),
4265 prefix : _nm.commons.getUrlParamValue("p"),
4266 q : data.q || _nm.commons.getUrlParamValue("q"),
4267 pos : _nm.commons.getUrlParamValue("ac_pos"),
4268 rank : parseInt(_nm.commons.getUrlParamValue("ranking"))
4269 };
4270 }
4271
4272 /******************** [ QUICK FILTER INFORMATION ] ********************/
4273
4274 var origin = _nm.commons.getUrlParamValue("origem");
4275 if (origin === "co") {
4276 $_ME.info.quickFilter = {
4277 type : 2 // click
4278 };
4279
4280 $_ME.info.quickFilter.hasFilter = 0;
4281
4282 // checks if exists filters
4283 if (searchFilters && searchFilters.length) {
4284 $_ME.info.quickFilter.hasFilter = 1;
4285 $_ME.info.quickFilter[searchFiltersKeys[0].name] =
4286 searchFiltersKeys[0].value;
4287 }
4288 }
4289 }
4290
4291 $_ME.loadQueryList();
4292 };
4293
4294 /**
4295 * @author Leticia Santos <leticia.n.santos@neemu.com>
4296 * @since 2.12.29
4297 * @param {Object} data
4298 * @return {Void}
4299 */
4300 var _setWishlistInformation = function(data) {
4301 var w = window;
4302 // old version of search (without mustache)
4303 if (w.neemuQuery !== undefined) {
4304 // product ids
4305 var productList = w.neemu_product_list || [],
4306 pIds = [];
4307 for (var i = 0; i < productList.length; i++) {
4308 var obj = {};
4309 obj[String(productList[i].ranking)] = productList[i].id
4310 pIds.push(obj);
4311 }
4312 $_ME.info.wishlist.pIds = pIds;
4313
4314 // page number
4315 var urlPgNumber = _nm.commons.getUrlParamValue("page");
4316 if (w.nmPgNumber === undefined) {
4317 w.nmPgNumber = (urlPgNumber !== null)
4318 ? parseInt(urlPgNumber)
4319 : 1;
4320 } else if (
4321 typeof $_ME.info.search.pIds[0] !== undefined &&
4322 !$_ME.info.wishlist.pIds[0].hasOwnProperty("1")
4323 ) {
4324 w.nmPgNumber = (urlPgNumber !== null)
4325 ? parseInt(urlPgNumber)
4326 : w.nmPgNumber + 1;
4327 }
4328 $_ME.info.wishlist.pg = w.nmPgNumber;
4329 } else {
4330 //TODO
4331 }
4332 };
4333
4334 /**
4335 * @author Andrews Lince <andrews@neemu.com>
4336 * @since 2.0.0
4337 * @return {Void}
4338 */
4339 var _setHomePageType = function() {
4340 setPageType.call($_ME, PAGE_HOME);
4341 };
4342
4343 /**
4344 * @author Andrews Lince <andrews@neemu.com>
4345 * @since 2.0.0
4346 * @return {Void}
4347 */
4348 var _setSearchPageType = function() {
4349 setPageType.call($_ME, PAGE_SEARCH);
4350
4351 // set store search type
4352 $_ME.info.search.type = _nm.conf.store.id;
4353 };
4354
4355 /**
4356 * @author Andrews Lince <andrews@neemu.com>
4357 * @since 2.0.0
4358 * @return {Void}
4359 */
4360 var _setSearchNeemuPageType = function() {
4361 setPageType.call($_ME, PAGE_SEARCH);
4362
4363 // set neemu search type
4364 $_ME.info.search.type = "neemuSearch";
4365 };
4366
4367 /**
4368 * @author Andrews Lince <andrews@neemu.com>
4369 * @since 2.0.0
4370 * @return {Void}
4371 */
4372 var _setDepartmentPageType = function() {
4373 setPageType.call($_ME, PAGE_DEPARTMENT);
4374 };
4375
4376 /**
4377 * @author Andrews Lince <andrews@neemu.com>
4378 * @since 2.0.0
4379 * @return {Void}
4380 */
4381 var _setRecPrintPageType = function() {
4382 setPageType.call($_ME, PAGE_REC_PRINT);
4383 };
4384
4385 /**
4386 * @author Andrews Lince <andrews@neemu.com>
4387 * @since 2.0.0
4388 * @return {Void}
4389 */
4390 var _setAddToCartPageType = function() {
4391 setPageType.call($_ME, PAGE_ADD_TO_CART);
4392 };
4393
4394 /**
4395 * @author Andrews Lince <andrews@neemu.com>
4396 * @since 2.0.0
4397 * @return {Void}
4398 */
4399 var _setProductPageType = function() {
4400 setPageType.call($_ME, PAGE_PRODUCT);
4401 };
4402
4403 /**
4404 * @author Andrews Lince <andrews@neemu.com>
4405 * @since 2.0.0
4406 * @return {Void}
4407 */
4408 var _setCartPageType = function() {
4409 setPageType.call($_ME, PAGE_CHECKOUT_CART);
4410 };
4411
4412 /**
4413 * @author Andrews Lince <andrews@neemu.com>
4414 * @since 2.0.0
4415 * @return {Void}
4416 */
4417 var _setCheckoutPageType = function() {
4418 setPageType.call($_ME, PAGE_CHECKOUT);
4419 };
4420
4421 /**
4422 * @author Andrews Lince <andrews@neemu.com>
4423 * @since 2.0.0
4424 * @return {Void}
4425 */
4426 var _setCheckoutConfirmationPageType = function() {
4427 setPageType.call($_ME, PAGE_CHECKOUT_CONFIRMATION);
4428 };
4429
4430 /**
4431 * @author Andrews Lince <andrews@neemu.com>
4432 * @since 2.0.0
4433 * @return {Void}
4434 */
4435 var _setComparisonPageType = function() {
4436 setPageType.call($_ME, PAGE_COMPARISON);
4437 };
4438
4439 /**
4440 * @author Andrews Lince <andrews@neemu.com>
4441 * @since 2.1.0
4442 * @return {Void}
4443 */
4444 var _setNavigationPageType = function() {
4445 setPageType.call($_ME, PAGE_NAVIGATION);
4446 };
4447
4448 /**
4449 * @author Andrews Lince <andrews@neemu.com>
4450 * @since 2.1.0
4451 * @return {Void}
4452 */
4453 var _setNeemuPagesPageType = function() {
4454 setPageType.call($_ME, PAGE_NEEMU_PAGES);
4455 };
4456
4457 /**
4458 * @author Andrews Lince <andrews@neemu.com>
4459 * @since 2.1.0
4460 * @return {Void}
4461 */
4462 var _setNeemuPagesIndexPageType = function() {
4463 setPageType.call($_ME, PAGE_NEEMU_PAGES_INDEX);
4464 };
4465
4466 /**
4467 * @author Andrews Lince <andrews@neemu.com>
4468 * @since 2.1.0
4469 * @return {Void}
4470 */
4471 var _setHotsitePageType = function() {
4472 setPageType.call($_ME, PAGE_HOTSITE);
4473 };
4474
4475 /**
4476 * @author Leticia Santos <leticia.n.santos@neemu.com>
4477 * @since 2.12.29
4478 * @return {Void}
4479 */
4480 var _setWishlistPageType = function() {
4481 setPageType.call($_ME, PAGE_WISHLIST);
4482 };
4483
4484 /**
4485 * @author Andrews Lince <andrews@neemu.com>
4486 * @since 2.0.0
4487 * @param {Object} data
4488 * - id
4489 * - title
4490 * - img
4491 * - stock
4492 * - url
4493 * - cId
4494 * - price
4495 * - sPrice
4496 * - cPrice
4497 * - price
4498 * - inst
4499 * - qty
4500 * - amount
4501 * @return {Void}
4502 */
4503 var _setProductInformation = function(data) {
4504
4505 // checks if is necessary process sku availability
4506 if (data.stock !== undefined) {
4507 data.stock = _nm.commons.processAvailability(data.stock);
4508
4509 // checks if the product is unavailable
4510 if (!data.stock) {
4511 neemuPlugin.recommendation.pageType = "produtoInd";
4512 }
4513 }
4514
4515 // checks if is necessary remove campaign price
4516 if (data.cPrice !== undefined) {
4517 if (data.cPrice === "") {
4518 delete data.cPrice;
4519 } else {
4520 data.cPrice = data.cPrice;
4521 }
4522 }
4523
4524 // format old price
4525 if (data.price !== undefined) {
4526 data.price = _nm.commons.formatCurrency(data.price);
4527 }
4528
4529 // format sale price
4530 if (data.sPrice !== undefined) {
4531 data.sPrice = _nm.commons.formatCurrency(data.sPrice);
4532 }
4533
4534 if (data.inst !== undefined) {
4535
4536 // format installment value
4537 if (data.inst.amount !== undefined) {
4538 data.inst.amount = _nm.commons.formatCurrency(data.inst.amount);
4539 }
4540
4541 data.inst.qty = parseInt(data.inst.qty);
4542
4543 data.inst = [ data.inst ];
4544 }
4545
4546 // recommendation information
4547 if (undefined === neemuPlugin.productInformation) {
4548 neemuPlugin.productInformation = {};
4549 }
4550
4551 neemuPlugin.productInformation.id = data.id;
4552 neemuPlugin.productInformation.availability = data.stock;
4553 neemuPlugin.productInformation.productTypeId = data.cId;
4554
4555 $_ME.info.product = data;
4556
4557 $_ME.loadClickList();
4558 };
4559
4560 /**
4561 * @author Andrews Lince <andrews@neemu.com>
4562 * @since 2.0.0
4563 * @param {Object} data
4564 * - title
4565 * @return {Void}
4566 */
4567 var _setHotsiteInformation = function(data) {
4568
4569 // set the default type as "neemu"
4570 if (data.type === undefined) {
4571 data.type = 'neemu';
4572 }
4573
4574 $_ME.info.hotsite = data;
4575 };
4576
4577 /**
4578 * @author Andrews Lince <andrews@neemu.com>
4579 * @since 2.0.0
4580 * @param {Object} data
4581 * - position
4582 * - id
4583 * - productTypeId
4584 * - price
4585 * - name
4586 * - sku
4587 * @return {Void}
4588 */
4589 var _setComparisonInformation = function(data) {
4590
4591 // format price (only if necessary)
4592 if (
4593 typeof(data.price) === "string"
4594 && !_nm.commons.strstr(data.price, " ")
4595 ) {
4596 data.price = _nm.commons.formatCurrency(data.price);
4597 }
4598
4599 $_ME.info.skuList.push(data);
4600 }
4601
4602 /**
4603 * @author Andrews Lince <andrews@neemu.com>
4604 * @since 2.0.0
4605 * - name
4606 * @return {Void}
4607 */
4608 var _setCheckoutStep = function(data) {
4609 $_ME.info.checkoutInformation = {
4610 step : data.name
4611 };
4612 };
4613
4614 /**
4615 * SET INFORMATIONS
4616 */
4617 var track = function() {
4618
4619 /**
4620 * permitindo que a extração seja feita mais de 1 vez na página (por
4621 * causa do ajax)
4622 */
4623 window.nmPageLoggedTest = 0;
4624
4625 // running extraction
4626 _nm.extraction.init.call(this, _nm.conf);
4627 };
4628
4629 /**
4630 * @author Andrews Lince <andrews@neemu.com>
4631 * @since 2.0.0
4632 * @param {Object} data
4633 * - infoName
4634 * - infoValue
4635 * @return {Void}
4636 */
4637 var _addCustomInformation = function(data) {
4638 $_ME.info.general[data.infoName] = data.infoValue;
4639 };
4640
4641 /**
4642 * @author Andrews Lince <andrews@neemu.com>
4643 * @since 2.0.0
4644 * @return {Void}
4645 */
4646 var _addHomeInformation = function(data) {
4647 };
4648
4649 /**
4650 * @author Andrews Lince <andrews@neemu.com>
4651 * @since 2.0.0
4652 * @param {Object} data
4653 * - cId
4654 * - tree
4655 * - level
4656 * - name
4657 * @return {Void}
4658 */
4659 var _addDepartmentInformation = function(data) {
4660 $_ME.info.department.cId = data.cId.toString() || "";
4661
4662 // defines the category id for neemu recommendation
4663 if (!neemuPlugin.departmentInformation) {
4664 neemuPlugin.departmentInformation = {};
4665 }
4666 neemuPlugin.departmentInformation.categoryId = $_ME.info.department.cId;
4667
4668 if (
4669 data.tree !== undefined
4670 && data.tree.index !== undefined
4671 && data.tree.name !== undefined
4672 ) {
4673 $_ME.info.department.tree.push({
4674 index : data.tree.index.toString(),
4675 name : data.tree.name
4676 });
4677 }
4678
4679 $_ME.loadDepartmentList();
4680 };
4681
4682 /**
4683 * @author Andrews Lince <andrews@neemu.com>
4684 * @since 2.0.0
4685 * @param {Object} data
4686 * - name
4687 * - value
4688 * @return {Void}
4689 */
4690 var _addFilterInformation = function(data) {
4691 $_ME.info.filters.push(data);
4692 };
4693
4694 /**
4695 * @author Andrews Lince <andrews@neemu.com>
4696 * @since 2.0.0
4697 * @param {Object} data
4698 * - sku
4699 * - stock
4700 * - price
4701 * - sPrice
4702 * - inst
4703 * - qty
4704 * - amount
4705 * @return {Void}
4706 */
4707 var _addSku = function(data) {
4708
4709 // cast the availability for a boolean value
4710 if (data.stock !== undefined) {
4711 data.stock = _nm.commons.processAvailability.call(
4712 $_ME,
4713 data.stock
4714 );
4715 }
4716
4717 if (data.price !== undefined) {
4718 data.price = _nm.commons.formatCurrency(data.price);
4719 }
4720
4721 // checks if sale price for this sku was nor informed
4722 if (data.sPrice === undefined) {
4723
4724 // uses sale price from product for this sku
4725 data.sPrice = $_ME.info.product.sPrice;
4726 }
4727
4728 data.sPrice = _nm.commons.formatCurrency(data.sPrice);
4729
4730 if (data.inst !== undefined) {
4731
4732 // format installment value
4733 if (data.inst.amount !== undefined) {
4734 data.inst.amount = _nm.commons.formatCurrency(data.inst.amount);
4735 }
4736
4737 data.inst.qty = parseInt(data.inst.qty);
4738
4739 data.inst = [ data.inst ];
4740 }
4741
4742 $_ME.info.skuList[data.sku] = data;
4743 };
4744
4745 /**
4746 * @author Andrews Lince <andrews@neemu.com>
4747 * @since 2.1.10
4748 * @param {Array} data
4749 * @return {Void}
4750 */
4751 var _addSearchSkuList = function(data) {
4752 $_ME.info.search.pIds = data;
4753 };
4754
4755 /**
4756 * @author Andrews Lince <andrews@neemu.com>
4757 * @since 2.0.0
4758 * @param {Object} data
4759 * - sku
4760 * - specName
4761 * - specValue
4762 * @return {Void}
4763 */
4764 var _addSkuSpec = function(data) {
4765 $_ME.info.skuList[data.sku][data.specName] = data.specValue;
4766 };
4767
4768 /**
4769 * @author Andrews Lince <andrews@neemu.com>
4770 * @since 2.0.0
4771 * @param {Object} data
4772 * - skuId
4773 * - $_ME.info.ame
4774 * - $_ME.info.alue
4775 * @return {Void}
4776 */
4777 var _addCustomSkuInformation = function(data) {
4778
4779 };
4780
4781 /**
4782 * @author Andrews Lince <andrews@neemu.com>
4783 * @since 2.0.0
4784 * @param {Object} data
4785 * - id
4786 * - price
4787 * - qty
4788 * - sku
4789 * @return {Void}
4790 */
4791 var _addCartItem = function(data) {
4792
4793 // cast of the quantity for a boolean value
4794 if (data.qty) {
4795 data.qty = parseInt(data.qty);
4796 }
4797
4798 // format price (only if necessary)
4799 if (
4800 typeof(data.price) === "string"
4801 && !_nm.commons.strstr(data.price, " ")
4802 ) {
4803 data.price = _nm.commons.formatCurrency(data.price);
4804 }
4805
4806 $_ME.info.skuList.push(data);
4807
4808 $_ME.loadCartList();
4809 };
4810
4811 /**
4812 * @author Andrews Lince <andrews@neemu.com>
4813 * @since 2.0.0
4814 * @param {Object} data
4815 * - order
4816 * - totalAmount
4817 * - shippingAmount
4818 * - city
4819 * - state
4820 * - coutry
4821 * @return {Void}
4822 */
4823 var _addOrder = function(data) {
4824 data.ship = _nm.commons.formatCurrency(data.ship);
4825 data.amount = _nm.commons.formatCurrency(data.amount);
4826
4827 $_ME.info.checkoutConfirmation = data;
4828
4829 $_ME.loadPurchaseList();
4830 };
4831
4832 /**
4833 * @author Andrews Lince <andrews@neemu.com>
4834 * @since 2.0.0
4835 * @param {Object} data
4836 * - skuId
4837 * - price
4838 * - qty
4839 * - productId
4840 * @return {Void}
4841 */
4842 var _addOrderItem = function(data) {
4843
4844 // cast of the quantity for a boolean value
4845 if (data.qty) {
4846 data.qty = parseInt(data.qty);
4847 }
4848
4849 // format price (only if necessary)
4850 if (
4851 typeof(data.price) === "string"
4852 && !_nm.commons.strstr(data.price, " ")
4853 ) {
4854 data.price = _nm.commons.formatCurrency(data.price);
4855 }
4856
4857 data.price = data.price;
4858
4859 if (window.neemuPlugin.recommendation.skuRecommendation === undefined) {
4860 window.neemuPlugin.recommendation.skuRecommendation = {
4861 id : "",
4862 sku : ""
4863 };
4864 }
4865
4866 window.neemuPlugin.recommendation.skuRecommendation.id += data.id + ";";
4867 window.neemuPlugin.recommendation.skuRecommendation.sku += data.sku + ";";
4868
4869 $_ME.info.skuList.push(data);
4870 };
4871
4872 /**
4873 * @author Andrews Lince <andrews@neemu.com>
4874 * @since 2.0.0
4875 * @return {Void}
4876 */
4877 var parseApiObject = function() {
4878 if (window._neemu !== undefined) {
4879 var commandsLoaded = [];
4880 var neemuLength = window._neemu.length;
4881 for (var i = 0; i < neemuLength; i++) {
4882 var command = window._neemu[i][0].trim();
4883 commandsLoaded[command] = true;
4884 if (window["_nm"][command] !== undefined) {
4885 window["_nm"][command].apply(
4886 ($_ME || window),
4887 window._neemu[i].slice(1)
4888 );
4889 }
4890 }
4891 }
4892 };
4893
4894 /**
4895 * @author Andrews Lince <andrews@neemu.com>
4896 * @since 2.0.0
4897 * @param {Object} data
4898 * - product (product information)
4899 * - cId (cateogry id)
4900 * - cPrice (campaign price)
4901 * - id (product id)
4902 * - title (product title)
4903 * - sPrice (sale price)
4904 * - pgName (page name)
4905 * - scName (showcase name)
4906 * - rank (product ranking)
4907 * - img (url from product image)
4908 * - stock (product availability)
4909 * - skus (sku list)
4910 * - sPrice (sku price)
4911 * - sku (sku number)
4912 * - stock (sku availability)
4913 * - rec (recommendation information)
4914 * - segment (showcase segment)
4915 * @param {Function} fnCallback
4916 * @return {Void}
4917 */
4918 var trackAddToCart = function(data, fnCallback) {
4919
4920 // sets the addToCart page type
4921 _setAddToCartPageType();
4922
4923 if (data.product !== undefined) {
4924 for (var i = 0; i < data.product.length; i++) {
4925 if (data.product[i].rank !== undefined) {
4926 data.product[i].rank = parseInt(data.product[i].rank);
4927 }
4928
4929 if (data.product[i].sPrice !== undefined) {
4930 data.product[i].sPrice = _nm.commons.formatCurrency(data.product[i].sPrice);
4931 }
4932
4933 if (data.product[i].stock !== undefined) {
4934 data.product[i].stock = _nm.commons.processAvailability(
4935 data.product[i].stock
4936 );
4937 }
4938
4939 if (data.product[i].skus !== undefined) {
4940 if (data.product[i].skus.length) {
4941 for (var j = 0; j < data.product[i].skus.length; j++) {
4942 data.product[i].skus[j].sPrice =
4943 _nm.commons.formatCurrency(
4944 data.product[i].skus[j].sPrice
4945 );
4946 }
4947 }
4948 }
4949 }
4950 }
4951
4952 sendRequestExtras.call($_ME, {
4953 params : {
4954 log : _nm.commons.base64Encode(_nm.commons.parseObjectToJSON({
4955 general : $_ME.info.general,
4956 product : data.product,
4957 rec : {
4958 list : [
4959 getRecListFromTrack.call($_ME, {
4960 chn : $_ME.info.general.chn,
4961 scName : data.rec.nm_rec_showcase,
4962 scId : data.rec.nm_rec_vid,
4963 scenario : data.rec.nm_rec_scenario,
4964 pgName : data.rec.nm_rec_page,
4965 cName : data.rec.nm_rec_category,
4966 seg : data.rec.nm_rec_segment,
4967 rank : data.rec.nm_ranking_rec
4968 })
4969 ]
4970 }
4971 }))
4972 }
4973 });
4974
4975 fnCallback();
4976 };
4977
4978 /**
4979 * @author Andrews Lince <andrews@neemu.com>
4980 * @since 2.0.0
4981 * @param {Object} data
4982 * - loadDelay
4983 * - status
4984 * - recList[]
4985 * - type
4986 * - access[]
4987 * - scenario
4988 * - segment
4989 * - page
4990 * - category
4991 * @return {Void}
4992 */
4993 var trackRecPrint = function(options) {
4994
4995 // sets the recview page type
4996 _setRecPrintPageType();
4997
4998 var recList = options.recList,
4999 recListLength = recList.length,
5000 recPrint = {
5001 general : $_ME.info.general,
5002 info : {
5003 rTime : options.loadDelay,
5004 rCode : options.status,
5005 oType : neemuPlugin.recommendation.pageType,
5006 oInfo : "",
5007 list : []
5008 }
5009 };
5010
5011 for (var i = 0; i < recListLength; i++) {
5012 var scenario = (recList[i].access !== undefined && recList[i].access.scenario !== undefined) ? recList[i].access.scenario : "",
5013 segment = (recList[i].access !== undefined && recList[i].access.segment !== undefined) ? recList[i].access.segment : "",
5014 cName = (recList[i].access !== undefined && recList[i].access.category !== undefined) ? recList[i].access.category : "";
5015
5016 recPrint.info.list[i] = getRecListFromTrack.call($_ME, {
5017 chn : $_ME.info.general.chn,
5018 scName : recList[i].type,
5019 scId : recList[i].vid,
5020 scenario : scenario,
5021 pgName : neemuPlugin.recommendation.pageType,
5022 cName : cName,
5023 seg : segment
5024 });
5025 }
5026
5027 if (recPrint.info.oType == "produto") {
5028 // recPrint.info.oInfo = _nm.commons.getUrlParamValue("nm_rec_id");
5029 recPrint.info.oInfo = neemuPlugin.productInformation.id;
5030 } else if (recPrint.info.oType == "departamento") {
5031 recPrint.info.oInfo = $_ME.info.department.categoryId;
5032 } else if (recPrint.info.oType == "busca") {
5033 recPrint.info.oInfo = $_ME.info.search.query;
5034 }
5035
5036 sendRequestExtras.call($_ME, {
5037 params : {
5038 log : _nm.commons.base64Encode(_nm.commons.parseObjectToJSON(recPrint))
5039 }
5040 });
5041 };
5042
5043 /**
5044 * @author Andrews Lince <andrews@neemu.com>
5045 * @version 2.1.0
5046 * @param {Object} data
5047 * - chn (channel)
5048 * - scName (showcase name)
5049 * - scId (showcase id)
5050 * - scenario (scenario)
5051 * - pgName (page name)
5052 * - cName (category name)
5053 * - seg (segment)
5054 * - rank (ranking)
5055 * @return {Object}
5056 */
5057 var getRecListFromTrack = function(data) {
5058
5059 // default values
5060 var recInfo = {
5061 chn : data.chn,
5062 scName : data.scName,
5063 scId : data.scId,
5064 scenario : data.scenario,
5065 pgName : data.pgName,
5066 cName : data.cName,
5067 seg : data.seg,
5068 tree : [
5069 [
5070 data.chn,
5071 data.scenario,
5072 data.seg,
5073 data.pgName,
5074 data.cName,
5075 data.scName,
5076 data.scId
5077 ],
5078 [
5079 data.chn,
5080 data.scenario,
5081 data.seg,
5082 data.pgName,
5083 data.cName,
5084 data.scId,
5085 data.scName
5086 ],
5087 [
5088 data.chn,
5089 data.scenario,
5090 data.pgName,
5091 data.scName,
5092 data.cName,
5093 data.seg,
5094 data.scId
5095 ]
5096 ]
5097 };
5098
5099 // checks if ranking was informed
5100 if (data.rank !== undefined) {
5101 recInfo.rank = data.rank;
5102 }
5103
5104 return recInfo;
5105 };
5106
5107 /**
5108 * Send a ajax request (using JSONP) for tracking of the user's action
5109 *
5110 * @author Andrews Lince <andrews@neemu.com>
5111 * @since 2.0.0
5112 * @param {Object} data
5113 * - params
5114 * @return {Void}
5115 */
5116 var sendRequestExtras = function(data) {
5117 var url = "//" + _nm.conf.store.logServer + "/" + _nm.conf.store.id + "/extras",
5118 count = 0,
5119 paramsLength = 0;
5120
5121 if (data.params !== undefined) {
5122 paramsLength = Object.keys(data.params).length;
5123 if (paramsLength) {
5124 url += "?";
5125
5126 for (var paramName in data.params) {
5127 if (count > 0) {
5128 url += "&";
5129 }
5130
5131 url += paramName + "=" + data.params[paramName];
5132
5133 paramsLength++;
5134 }
5135 }
5136
5137 _nm.commons.ajaxRequestJsonp(url);
5138 }
5139 };
5140
5141 // public methods
5142 return {
5143
5144 // constants
5145 PAGE_CHECKOUT_CONFIRMATION : PAGE_CHECKOUT_CONFIRMATION,
5146 PAGE_NAVIGATION : PAGE_NAVIGATION,
5147 PAGE_NEEMU_PAGES_INDEX : PAGE_NEEMU_PAGES_INDEX,
5148 PAGE_CHECKOUT_CART : PAGE_CHECKOUT_CART,
5149 PAGE_NEEMU_PAGES : PAGE_NEEMU_PAGES,
5150 PAGE_DEPARTMENT : PAGE_DEPARTMENT,
5151 PAGE_COMPARISON : PAGE_COMPARISON,
5152 PAGE_REC_PRINT : PAGE_REC_PRINT,
5153 PAGE_CHECKOUT : PAGE_CHECKOUT,
5154 PAGE_GENERAL : PAGE_GENERAL,
5155 PAGE_PRODUCT : PAGE_PRODUCT,
5156 PAGE_SEARCH : PAGE_SEARCH,
5157 PAGE_LOGIN : PAGE_LOGIN,
5158 PAGE_HOME : PAGE_HOME,
5159 PAGE_HOTSITE : PAGE_HOTSITE,
5160 PAGE_WISHLIST : PAGE_WISHLIST,
5161 PAGE_COLLECTION_GERAL : PAGE_COLLECTION_GERAL,
5162 PAGE_COLLECTION_HOME : PAGE_COLLECTION_HOME,
5163 PAGE_COLLECTION_SEARCH : PAGE_COLLECTION_SEARCH,
5164 PAGE_COLLECTION_DETAILS : PAGE_COLLECTION_DETAILS,
5165 PAGE_COLLECTION_AUTHOR : PAGE_COLLECTION_AUTHOR,
5166 PAGE_COLLECTION_REGISTER : PAGE_COLLECTION_REGISTER,
5167 PAGE_COLLECTION_RELATED : PAGE_COLLECTION_RELATED,
5168 PAGE_COLLECTION_TAG : PAGE_COLLECTION_TAG,
5169
5170 // neemu protocol methods
5171 _setCheckoutConfirmationPageType : _setCheckoutConfirmationPageType,
5172 _setNeemuPagesIndexInformation : _setNeemuPagesIndexInformation,
5173 _setNeemuPagesIndexPageType : _setNeemuPagesIndexPageType,
5174 _setNeemuPagesInformation : _setNeemuPagesInformation,
5175 _addDepartmentInformation : _addDepartmentInformation,
5176 _setComparisonInformation : _setComparisonInformation,
5177 _setNavigationInformation : _setNavigationInformation,
5178 _setSearchNeemuPageType : _setSearchNeemuPageType,
5179 _setProductInformation : _setProductInformation,
5180 _setDepartmentPageType : _setDepartmentPageType,
5181 _setNeemuPagesPageType : _setNeemuPagesPageType,
5182 _setNavigationPageType : _setNavigationPageType,
5183 _setComparisonPageType : _setComparisonPageType,
5184 _setWishlistPageType : _setWishlistPageType,
5185 _setHotsitePageType : _setHotsitePageType,
5186 _setWishlistInformation : _setWishlistInformation,
5187 _setHotsiteInformation : _setHotsiteInformation,
5188 _setSearchInformation : _setSearchInformation,
5189 _addFilterInformation : _addFilterInformation,
5190 _addCustomInformation : _addCustomInformation,
5191 _setCheckoutPageType : _setCheckoutPageType,
5192 _addHomeInformation : _addHomeInformation,
5193 _setProductPageType : _setProductPageType,
5194 _setSearchPageType : _setSearchPageType,
5195 _addProductSearch : _addProductSearch,
5196 _addSearchSkuList : _addSearchSkuList,
5197 _setCartPageType : _setCartPageType,
5198 _setCheckoutStep : _setCheckoutStep,
5199 _setHomePageType : _setHomePageType,
5200 _addOrderItem : _addOrderItem,
5201 _addCartItem : _addCartItem,
5202 _setAccount : _setAccount,
5203 _addSkuSpec : _addSkuSpec,
5204 _addOrder : _addOrder,
5205 _setUser : _setUser,
5206 _addSku : _addSku,
5207
5208 loadDepartmentList : loadDepartmentList,
5209 getNeemuLoggedUser : getNeemuLoggedUser,
5210 setNeemuLoggedUser : setNeemuLoggedUser,
5211 neemuUserIsLogged : neemuUserIsLogged,
5212 loadPurchaseList : loadPurchaseList,
5213 parseIsPaused : parseIsPaused,
5214 loadClickList : loadClickList,
5215 loadQueryList : loadQueryList,
5216 continueParse : continueParse,
5217 loadCartList : loadCartList,
5218 getPageType : getPageType,
5219 pauseParse : pauseParse,
5220 setMe : setMe,
5221 initializeLogInformation: initializeLogInformation,
5222 parseApiObject : parseApiObject,
5223 trackAddToCart : trackAddToCart,
5224 trackRecPrint : trackRecPrint,
5225 track : track,
5226 info : info,
5227 init : init
5228 };
5229
5230})(window, document, undefined);
5231
5232// _nm.extraction = extraction;
5233_nm.extraction.setMe(_nm.extraction);
5234
5235//check for change on hash of location
5236_nm.commons.addEventListener(window, "hashchange", function(){
5237 _nm.extraction.track();
5238});
5239
5240//on change of url browser
5241/*
5242(function(history){
5243 if(!window.requestChangeUrl){
5244 window.requestChangeUrl = true;
5245 var ps = history.pushState;
5246 history.pushState = function(data, title, url){
5247 ps.apply(history, arguments);
5248 _nm.extraction.track();
5249 };
5250 }
5251})(window.history);
5252*/
5253
5254/**
5255 * Código da loja
5256 * @type {String}
5257 */
5258var nmStoreId = "ceatotem";
5259
5260/**
5261 * Obtém o pageType da página atual
5262 * @author Operação Neemu <operacao@neemu.com>
5263 * @param {Object} _nm
5264 * @return {String}
5265 */
5266function nmGetPageType(_nm) {
5267 return '';
5268};
5269
5270/**
5271 * Verifica se o usuário está logado
5272 * @author Operação Neemu <operacao@neemu.com>
5273 * @param {Object} _nm
5274 * @return {Boolean}
5275 */
5276function nmUserIsLogged(_nm) {
5277 return false;
5278}
5279
5280/**
5281 * Método para obter as informações do usuário logado
5282 * @author Operação Neemu <operacao@neemu.com>
5283 * @param {Object} _nm
5284 * @return {Object}
5285 * - loggedId
5286 * - email
5287 * - name
5288 */
5289function nmGetUserInfo(_nm) {
5290 return {};
5291};
5292
5293/**
5294 * Executa todo o processo de extração das informações das páginas
5295 * @author Operação Neemu <operacao@neemu.com>
5296 * @param {Object} _nm
5297 * @return {Void}
5298 */
5299function nmExecuteExtraction(_nm) {
5300 switch (neemuGetPageType(_nm)) {
5301
5302 case _nm.extraction.PAGE_HOME :
5303
5304 _nm.extraction._setHomePageType();
5305
5306 break;
5307
5308 case _nm.extraction.PAGE_SEARCH :
5309
5310 // busca neemu
5311 if (_nm.commons.isNeemuSearch()) {
5312
5313 // define o tipo da página como "busca neemu"
5314 _nm.extraction._setSearchNeemuPageType();
5315
5316 // processa as informações da página de busca
5317 _nm.extraction._setSearchInformation();
5318 }
5319
5320 // busca do cliente
5321 else {
5322
5323 // define o tipo da página como "busca do cliente"
5324 _nm.extraction._setSearchPageType();
5325
5326 /**
5327 * Objeto com as informações de busca
5328 * @type {Object}
5329 * @example
5330 *
5331 * {
5332 * sort: 1,
5333 * pg: 1,
5334 * qty: 234,
5335 * qtyAnd: 234,
5336 * q: "notebook",
5337 * pIds: [
5338 * {
5339 * "1": "123"
5340 * },
5341 * {
5342 * "2": "456"
5343 * }
5344 * ...
5345 * ],
5346 * filters: [
5347 * {
5348 * "Categoria": "4938756"
5349 * },
5350 * {
5351 * "Marca": "Philco|Samsung"
5352 * }
5353 * ]
5354 * }
5355 */
5356 var searchInfo = {};
5357
5358 // seta as informações da página de busca do cliente
5359 _nm.extraction._setSearchInformation(searchInfo);
5360 }
5361
5362 break;
5363
5364 case _nm.extraction.PAGE_PRODUCT :
5365
5366 /**
5367 * Objeto com as informações de produto
5368 * @type {Object}
5369 * @example
5370 *
5371 * {
5372 * id: "1239876",
5373 * title: "IT Sabrina Sato Diva A105",
5374 * cName: "Óculos de Sol",
5375 * cId: "654",
5376 * stock: 1,
5377 * price: "420.00",
5378 * sPrice: "323.00",
5379 * img: "https://media.eotica.com.br/catalog/product/o/c/oculos-it-a105-c3-1-gs.jpg",
5380 * inst: [
5381 * {
5382 * qty: 4,
5383 * amount: "230.00"
5384 * }
5385 * ],
5386 * skus: [
5387 * {
5388 * stock: 1,
5389 * sPrice: "215.00",
5390 * sku: "2134876"
5391 * }
5392 * ]
5393 * }
5394 */
5395 var productInformation = {};
5396
5397 extraction._setProductPageType();
5398 extraction._setProductInformation(productInformation);
5399
5400 break;
5401
5402 case _nm.extraction.PAGE_DEPARTMENT :
5403
5404 extraction._setDepartmentPageType();
5405
5406 var breadcrumb = commons.querySelectorAll('#informeAquiOSeletorDoBreadcrumb');
5407 for(var i = 1, len = breadcrumb.length; i < len; i++) {
5408
5409 /**
5410 * Objeto com as informações do departamento
5411 * @type {Object}
5412 * @example
5413 *
5414 * {
5415 * cId: "213786",
5416 * tree: [
5417 * {
5418 * index: 1,
5419 * name: "Categoria 1"
5420 * },
5421 * {
5422 * index: 2,
5423 * name: "Categoria 2"
5424 * },
5425 * {
5426 * index: 3,
5427 * name: "Categoria 3"
5428 * }
5429 * ]
5430 * }
5431 */
5432 var departmentInformation = {};
5433
5434 extraction._addDepartmentInformation(departmentInformation);
5435 }
5436
5437 break;
5438
5439 case _nm.extraction.PAGE_CHECKOUT :
5440
5441 _nm.extraction._setCheckoutPageType();
5442
5443 _nm.extraction._setCheckoutStep({
5444 name : ""
5445 });
5446
5447 break;
5448
5449 case _nm.extraction.PAGE_CHECKOUT_CART :
5450
5451 _nm.extraction._setCartPageType();
5452
5453 var products = [];
5454 for(var i = 0; i < products.length; i++) {
5455 _nm.extraction._addCartItem({
5456 id: "",
5457 sku: "",
5458 price: _nm.commons.formatCurrency(""),
5459 qty: 1
5460 });
5461 }
5462
5463 break;
5464
5465 case _nm.extraction.PAGE_CHECKOUT_CONFIRMATION :
5466
5467 _nm.extraction._setCheckoutConfirmationPageType();
5468
5469 var products = [];
5470 for(var i = 0, len_i = products.length; i < len_i; i++) {
5471 _nm.extraction._addOrderItem({
5472 id: '',
5473 sku: '',
5474 qty: 1,
5475 price: _nm.commons.formatCurrency('')
5476 });
5477 }
5478
5479 break;
5480 }
5481}
5482
5483/**
5484 * Configurações da loja
5485 */
5486var conf = {
5487 store : {
5488 id : nmStoreId,
5489 host : nmStoreId + ".com.br",
5490 logServer : "laas.neemu.com"
5491 },
5492 parse : function(_nm) {
5493
5494 // verifica se o usuário está logado
5495 if (nmUserIsLogged(_nm)) {
5496
5497 // seta as informações do usuário logado
5498 _nm.extraction._setUser(nmGetUserInfo(_nm));
5499 }
5500
5501 nmExecuteExtraction(_nm);
5502
5503 window.neemuPlugin = window.neemuPlugin || {};
5504 window.neemuPlugin.recommendation = {
5505 recList: [{
5506 type: 'viu-viu',
5507 div: 'mais-procurados',
5508 gid: '1'
5509 }],
5510 recListReserve: [{
5511 type: 'populares',
5512 gid: '1'
5513 }]
5514 };
5515 _nm.commons.loadFile('http://raas.neemu.com/cea/rec.js');
5516 }
5517};
5518_nm.conf=conf;window._nm=_nm;})(window,document, undefined,window.jQuery);_nm.extraction.init(_nm.conf);