/** * @license text 2.0.15 Copyright jQuery Foundation and other contributors. * Released under MIT license, http://github.com/requirejs/text/LICENSE */ /*jslint regexp: true */ /*global require, XMLHttpRequest, ActiveXObject, define, window, process, Packages, java, location, Components, FileUtils */ define('text',['module'], function (module) { 'use strict'; var text, fs, Cc, Ci, xpcIsWindows, progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTxP', 'Msxml2.XMLHTTP.4.0'], xmlRegExp = /^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im, bodyRegExp = /
]*>\s*([\s\S]+)\s*<\/body>/im, hasLocation = typeof location !== 'undefined' && location.href, defaultProtocol = hasLocation && location.protocol && location.protocol.replace(/\:/, ''), defaultHostName = hasLocation && location.hostname, defaultPort = hasLocation && (location.port || undefined), buildMap = {}, masterConfig = (module.config && module.config()) || {}; function useDefault(value, defaultValue) { return value === undefined || value === '' ? defaultValue : value; } //Allow for default ports for http and https. function isSamePort(protocol1, port1, protocol2, port2) { if (port1 === port2) { return true; } else if (protocol1 === protocol2) { if (protocol1 === 'http') { return useDefault(port1, '80') === useDefault(port2, '80'); } else if (protocol1 === 'https') { return useDefault(port1, '443') === useDefault(port2, '443'); } } return false; } text = { version: '2.0.15', strip: function (content) { //Strips declarations so that external SVG and XML //documents can be added to a document without worry. Also, if the string //is an HTML document, only the part inside the body tag is returned. if (content) { content = content.replace(xmlRegExp, ""); var matches = content.match(bodyRegExp); if (matches) { content = matches[1]; } } else { content = ""; } return content; }, jsEscape: function (content) { return content.replace(/(['\\])/g, '\\$1') .replace(/[\f]/g, "\\f") .replace(/[\b]/g, "\\b") .replace(/[\n]/g, "\\n") .replace(/[\t]/g, "\\t") .replace(/[\r]/g, "\\r") .replace(/[\u2028]/g, "\\u2028") .replace(/[\u2029]/g, "\\u2029"); }, createXhr: masterConfig.createXhr || function () { //Would love to dump the ActiveX crap in here. Need IE 6 to die first. var xhr, i, progId; if (typeof XMLHttpRequest !== "undefined") { return new XMLHttpRequest(); } else if (typeof ActiveXObject !== "undefined") { for (i = 0; i < 3; i += 1) { progId = progIds[i]; try { xhr = new ActiveXObject(progId); } catch (e) { } if (xhr) { progIds = [progId]; // so faster next time break; } } } return xhr; }, /** * Parses a resource name into its component parts. Resource names * look like: module/name.ext!strip, where the !strip part is * optional. * @param {String} name the resource name * @returns {Object} with properties "moduleName", "ext" and "strip" * where strip is a boolean. */ parseName: function (name) { var modName, ext, temp, strip = false, index = name.lastIndexOf("."), isRelative = name.indexOf('./') === 0 || name.indexOf('../') === 0; if (index !== -1 && (!isRelative || index > 1)) { modName = name.substring(0, index); ext = name.substring(index + 1); } else { modName = name; } temp = ext || modName; index = temp.indexOf("!"); if (index !== -1) { //Pull off the strip arg. strip = temp.substring(index + 1) === "strip"; temp = temp.substring(0, index); if (ext) { ext = temp; } else { modName = temp; } } return { moduleName: modName, ext: ext, strip: strip }; }, xdRegExp: /^((\w+)\:)?\/\/([^\/\\]+)/, /** * Is an URL on another domain. Only works for browser use, returns * false in non-browser environments. Only used to know if an * optimized .js version of a text resource should be loaded * instead. * @param {String} url * @returns Boolean */ useXhr: function (url, protocol, hostname, port) { var uProtocol, uHostName, uPort, match = text.xdRegExp.exec(url); if (!match) { return true; } uProtocol = match[2]; uHostName = match[3]; uHostName = uHostName.split(':'); uPort = uHostName[1]; uHostName = uHostName[0]; return (!uProtocol || uProtocol === protocol) && (!uHostName || uHostName.toLowerCase() === hostname.toLowerCase()) && ((!uPort && !uHostName) || isSamePort(uProtocol, uPort, protocol, port)); }, finishLoad: function (name, strip, content, onLoad) { content = strip ? text.strip(content) : content; content = content.split('\n').join('').split('\t').join('').split(/>\s+<').split(/\s+/g).join(' '); if (masterConfig.isBuild) { buildMap[name] = content; } onLoad(content); }, load: function (name, req, onLoad, config) { //Name has format: some.module.filext!strip //The strip part is optional. //if strip is present, then that means only get the string contents //inside a body tag in an HTML string. For XML/SVG content it means //removing the declarations so the content can be inserted //into the current doc without problems. // Do not bother with the work if a build and text will // not be inlined. if (config && config.isBuild && !config.inlineText) { onLoad(); return; } masterConfig.isBuild = config && config.isBuild; var parsed = text.parseName(name), nonStripName = parsed.moduleName + (parsed.ext ? '.' + parsed.ext : ''), url = req.toUrl(nonStripName), useXhr = (masterConfig.useXhr) || text.useXhr; // Do not load if it is an empty: url if (url.indexOf('empty:') === 0) { onLoad(); return; } //Load the text. Use XHR if possible and in a browser. if (!hasLocation || useXhr(url, defaultProtocol, defaultHostName, defaultPort)) { text.get(url, function (content) { text.finishLoad(name, parsed.strip, content, onLoad); }, function (err) { if (onLoad.error) { onLoad.error(err); } }); } else { //Need to fetch the resource across domains. Assume //the resource has been optimized into a JS module. Fetch //by the module name + extension, but do not include the //!strip part to avoid file system issues. req([nonStripName], function (content) { text.finishLoad(parsed.moduleName + '.' + parsed.ext, parsed.strip, content, onLoad); }); } }, write: function (pluginName, moduleName, write, config) { if (buildMap.hasOwnProperty(moduleName)) { var content = text.jsEscape(buildMap[moduleName]); write.asModule(pluginName + "!" + moduleName, "define(function () { return '" + content + "';});\n"); } }, writeFile: function (pluginName, moduleName, req, write, config) { var parsed = text.parseName(moduleName), extPart = parsed.ext ? '.' + parsed.ext : '', nonStripName = parsed.moduleName + extPart, //Use a '.js' file name so that it indicates it is a //script that can be loaded across domains. fileName = req.toUrl(parsed.moduleName + extPart) + '.js'; //Leverage own load() method to load plugin value, but only //write out values that do not have the strip argument, //to avoid any potential issues with ! in file names. text.load(nonStripName, req, function (value) { //Use own write() method to construct full module value. //But need to create shell that translates writeFile's //write() to the right interface. var textWrite = function (contents) { return write(fileName, contents); }; textWrite.asModule = function (moduleName, contents) { return write.asModule(moduleName, fileName, contents); }; text.write(pluginName, nonStripName, textWrite, config); }, config); } }; if (masterConfig.env === 'node' || (!masterConfig.env && typeof process !== "undefined" && process.versions && !!process.versions.node && !process.versions['node-webkit'] && !process.versions['atom-shell'])) { //Using special require.nodeRequire, something added by r.js. fs = require.nodeRequire('fs'); text.get = function (url, callback, errback) { try { var file = fs.readFileSync(url, 'utf8'); //Remove BOM (Byte Mark Order) from utf8 files if it is there. if (file[0] === '\uFEFF') { file = file.substring(1); } callback(file); } catch (e) { if (errback) { errback(e); } } }; } else if (masterConfig.env === 'xhr' || (!masterConfig.env && text.createXhr())) { text.get = function (url, callback, errback, headers) { var xhr = text.createXhr(), header; xhr.open('GET', url, true); //Allow plugins direct access to xhr headers if (headers) { for (header in headers) { if (headers.hasOwnProperty(header)) { xhr.setRequestHeader(header.toLowerCase(), headers[header]); } } } //Allow overrides specified in config if (masterConfig.onXhr) { masterConfig.onXhr(xhr, url); } xhr.onreadystatechange = function (evt) { var status, err; //Do not explicitly handle errors, those should be //visible via console output in the browser. if (xhr.readyState === 4) { status = xhr.status || 0; if (status > 399 && status < 600) { //An http 4xx or 5xx error. Signal an error. err = new Error(url + ' HTTP status: ' + status); err.xhr = xhr; if (errback) { errback(err); } } else { callback(xhr.responseText); } if (masterConfig.onXhrComplete) { masterConfig.onXhrComplete(xhr, url); } } }; xhr.send(null); }; } else if (masterConfig.env === 'rhino' || (!masterConfig.env && typeof Packages !== 'undefined' && typeof java !== 'undefined')) { //Why Java, why is this so awkward? text.get = function (url, callback) { var stringBuffer, line, encoding = "utf-8", file = new java.io.File(url), lineSeparator = java.lang.System.getProperty("line.separator"), input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), encoding)), content = ''; try { stringBuffer = new java.lang.StringBuffer(); line = input.readLine(); // Byte Order Mark (BOM) - The Unicode Standard, version 3.0, page 324 // http://www.unicode.org/faq/utf_bom.html // Note that when we use utf-8, the BOM should appear as "EF BB BF", but it doesn't due to this bug in the JDK: // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058 if (line && line.length() && line.charAt(0) === 0xfeff) { // Eat the BOM, since we've already found the encoding on this file, // and we plan to concatenating this buffer with others; the BOM should // only appear at the top of a file. line = line.substring(1); } if (line !== null) { stringBuffer.append(line); } while ((line = input.readLine()) !== null) { stringBuffer.append(lineSeparator); stringBuffer.append(line); } //Make sure we return a JavaScript string and not a Java string. content = String(stringBuffer.toString()); //String } finally { input.close(); } callback(content); }; } else if (masterConfig.env === 'xpconnect' || (!masterConfig.env && typeof Components !== 'undefined' && Components.classes && Components.interfaces)) { //Avert your gaze! Cc = Components.classes; Ci = Components.interfaces; Components.utils['import']('resource://gre/modules/FileUtils.jsm'); xpcIsWindows = ('@mozilla.org/windows-registry-key;1' in Cc); text.get = function (url, callback) { var inStream, convertStream, fileObj, readData = {}; if (xpcIsWindows) { url = url.replace(/\//g, '\\'); } fileObj = new FileUtils.File(url); //XPCOM, you so crazy try { inStream = Cc['@mozilla.org/network/file-input-stream;1'] .createInstance(Ci.nsIFileInputStream); inStream.init(fileObj, 1, 0, false); convertStream = Cc['@mozilla.org/intl/converter-input-stream;1'] .createInstance(Ci.nsIConverterInputStream); convertStream.init(inStream, "utf-8", inStream.available(), Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER); convertStream.readString(inStream.available(), readData); convertStream.close(); inStream.close(); callback(readData.value); } catch (e) { throw new Error((fileObj && fileObj.path || '') + ': ' + e); } }; } return text; }); define('css', [], function () { if ("undefined" == typeof window) return { load: function (a, b, c) { c() } }; var a = document.getElementsByTagName("head")[0], b = window.navigator.userAgent.match(/Trident\/([^ ;]*)|AppleWebKit\/([^ ;]*)|Opera\/([^ ;]*)|rv\:([^ ;]*)(.*?)Gecko\/([^ ;]*)|MSIE\s([^ ;]*)|AndroidWebKit\/([^ ;]*)/) || 0, c = !1, d = !0; b[1] || b[7] ? c = parseInt(b[1]) < 6 || parseInt(b[7]) <= 9 : b[2] || b[8] ? d = !1 : b[4] && (c = parseInt(b[4]) < 18); var e = {}; e.pluginBuilder = "./css-builder"; var f, g, h, i = function () { f = document.createElement("style"), a.appendChild(f), g = f.styleSheet || f.sheet }, j = 0, k = [], l = function (a) { g.addImport(a), f.onload = function () { m() }, j++, 31 == j && (i(), j = 0) }, m = function () { h(); var a = k.shift(); return a ? (h = a[1], void l(a[0])) : void (h = null) }, n = function (a, b) { if (g && g.addImport || i(), g && g.addImport) h ? k.push([a, b]) : (l(a), h = b); else { f.textContent = '@import "' + a + '";'; var c = setInterval(function () { try { f.sheet.cssRules, clearInterval(c), b() } catch (a) { } }, 10) } }, o = function (b, c) { var e = document.createElement("link"); if (e.type = "text/css", e.rel = "stylesheet", d) e.onload = function () { e.onload = function () { }, setTimeout(c, 7) }; else var f = setInterval(function () { for (var a = 0; a < document.styleSheets.length; a++) { var b = document.styleSheets[a]; if (b.href == e.href) return clearInterval(f), c() } }, 10); e.href = b, a.appendChild(e) }; return e.normalize = function (a, b) { return ".css" == a.substr(a.length - 4, 4) && (a = a.substr(0, a.length - 4)), b(a) }, e.load = function (a, b, d, e) { (c ? n : o)(b.toUrl(a + ".css"), d) }, e }); define('utils', [], function () { var utils = { object: { import: function (source) { var arg = Object.keys(arguments).slice(1); for (var obj in arg) { var keys = Object.keys(arguments[arg[obj]]); for (var key in keys) { source[keys[key]] = arguments[arg[obj]][keys[key]]; } } }, diff: deepDiffMapper() }, collection: { map: function (a, field, b) { var parts = field.split('->'); for (var i in a) { for (var j in b) { if (b[j][parts[1]] == a[i][parts[0]]) { a[i][parts[0]] = b[j]; } } } }, byId: function (array) { var refs = {}; array.forEach(function (e, i, a) { refs[e.id] = a[i]; }); return refs; } }, render: { options: renderOptions }, handlers: { yiiErrorHandler: yiiErrorHandler }, array: { dynamicSort: dynamicSort, enum: enumArray }, jQueryMapId: jQueryMapBy('data-id'), jQueryMapBy: jQueryMapBy, form: { serialize: formSerialize }, dom: { serialize: domSerializer, validate: domValidate }, showTarget: showTarget, hideTarget: hideTarget, contentEditableCommit: contentEditableCommit, setValueOnName: setValueOnName }; window._utils = utils; return utils; function enumArray(size, init) { return Array.apply(null, { length: size }).map(function (value, index) { return index + (init || 0); }); } function domValidate($el, report) { var form = $('').append($el.clone()); var validity = form.get(0).checkValidity(); if (report !== false) $el.parents('form').get(0).reportValidity(); return validity; } function domSerializer(el) { var $tr = $(el); var obj = {}; $tr.find('input, textarea').toArray().forEach(function (e, i, a) { if ($(e).is('[disabled]')) return; if (!($(e).data('label') || $(e).attr('name'))) return; if (!$(e).is(':checkbox') && !$(e).is(':radio')) return setValueOnName(obj, ($(e).data('label') || $(e).attr('name')), $(e).val()) if (!$(e).val()) return setValueOnName(obj, ($(e).data('label') || $(e).attr('name')), $(e).prop('checked')); if (!$(e).prop('checked')) return; setValueOnName(obj, ($(e).data('label') || $(e).attr('name')), $(e).val()); }); $tr.find('select').toArray().forEach(function (e, i, a) { if ($(e).is('[disabled]')) return; var val = $(e).val(); if (!($(e).data('label') || $(e).attr('name'))) return; if (!Array.isArray(val)) { var option = $('option[value="' + val + '"]', e); var option_data = { id: option.val(), text: option.text() }; return setValueOnName(obj, ($(e).data('label') || $(e).attr('name')), [option_data]); } setValueOnName(obj, ($(e).data('label') || $(e).attr('name')), $(e).val().map(keyValueObj)) function keyValueObj(index) { var option = $('option[value="' + index + '"]', e); return { id: option.val(), text: option.text() }; } }); return obj; } function setValueOnName(obj, key, value) { var ponteiro = obj; key.split('[') .map(function (f) { return f.split(']').join(''); }) .forEach(function (key, index, array) { if (index == (array.length - 1) && ponteiro[key] && Array.isArray(ponteiro[key])) { return ponteiro[key].push(value); } if (index == (array.length - 1) && ponteiro[key]) { ponteiro[key] = [ponteiro[key]]; return ponteiro[key].push(value); } if (index == (array.length - 1)) { return ponteiro[key] = value; } if (!ponteiro[key]) ponteiro[key] = {}; ponteiro = ponteiro[key]; }); } function contentEditableCommit() { $($(this).data('target')).val($(this).html().trim()); } function showTarget() { if (!$(this).is('[data-target]')); $target = $($(this).data('target')); $target.slideDown(300); } function hideTarget() { if (!$(this).is('[data-target]')); $target = $($(this).data('target')); $target.slideUp(300); } function renderOptions(options, selected) { return Object.keys(options) .map(function (e) { return ""; }).join(''); } function yiiErrorHandler(data) { $('.has-error').removeClass('has-error'); data = data.result.responseJSON; if (!data.errors) return; data.errors.forEach(function (error) { $root = $($('[name=' + error.field + ']').parents('.form-group')); $root.addClass('has-error'); $('.help-block-error', $root).html(error.message); }); } function jQueryMapBy(field) { return function (i, e) { return $(e).attr(field); } } function dynamicSort(property) { var sortOrder = 1; if (property[0] === "-") { sortOrder = -1; property = property.substr(1); } return function (a, b) { var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0; return result * sortOrder; } } function formSerialize($el) { var obj = {}; $el.serializeArray().forEach(function (e) { var ponteiro = obj; e.name .split('[') .map(function (f) { return f.split(']').join(''); }) .forEach(function (key, index, array) { if (index == (array.length - 1) && ponteiro[key] && Array.isArray(ponteiro[key])) { return ponteiro[key].push(e.value); } if (index == (array.length - 1) && ponteiro[key]) { ponteiro[key] = [ponteiro[key]]; return ponteiro[key].push(e.value); } if (index == (array.length - 1)) { return ponteiro[key] = e.value; } if (!ponteiro[key]) ponteiro[key] = {}; ponteiro = ponteiro[key]; }); }); //'variantes[2][valores]'.match(/\[(\w+)\]/g).forEach(console.log) return obj; } /* Faz diff de dois objetos em javascript, [ Houveram alterações no script original para atender as nossas necessidades ] Ref: https://stackoverflow.com/questions/8572826/generic-deep-diff-between-two-objects */ function deepDiffMapper() { return { VALUE_CREATED: 'created', VALUE_UPDATED: 'updated', VALUE_DELETED: 'deleted', VALUE_UNCHANGED: 'unchanged', map: function (obj1, obj2) { if (this.isFunction(obj1) || this.isFunction(obj2)) { throw 'Invalid argument. Function given, object expected.'; } if (this.isValue(obj1) || this.isValue(obj2)) { var type = this.compareValues(obj1, obj2); if (type == this.VALUE_UNCHANGED) return -1; return { type: this.compareValues(obj1, obj2), data: (obj1 === undefined) ? obj2 : obj1, from: obj1, to: obj2 }; } var removed = []; var diff = {}; for (var key in obj1) { if (this.isFunction(obj1[key])) { continue; } var value2 = undefined; if ('undefined' != typeof (obj2[key])) { value2 = obj2[key]; } var val = this.map(obj1[key], value2); diff[key] = val; if (val == -1) { removed.push(key); delete diff[key]; }; if (this.isObject(val) && !Object.keys(val).length) { removed.push(key); delete diff[key]; } } for (var key in obj2) { if (this.isFunction(obj2[key]) || ('undefined' != typeof (diff[key]))) { continue; } if (removed.indexOf(key) != -1) { continue; } var val = this.map(undefined, obj2[key]); diff[key] = val; } return diff; }, compareValues: function (value1, value2) { if (value1 === value2) { return this.VALUE_UNCHANGED; } if (this.isDate(value1) && this.isDate(value2) && value1.getTime() === value2.getTime()) { return this.VALUE_UNCHANGED; } if ('undefined' == typeof (value1)) { return this.VALUE_CREATED; } if ('undefined' == typeof (value2)) { return this.VALUE_DELETED; } return this.VALUE_UPDATED; }, isFunction: function (obj) { return {}.toString.apply(obj) === '[object Function]'; }, isArray: function (obj) { return {}.toString.apply(obj) === '[object Array]'; }, isDate: function (obj) { return {}.toString.apply(obj) === '[object Date]'; }, isObject: function (obj) { return {}.toString.apply(obj) === '[object Object]'; }, isValue: function (obj) { return !this.isObject(obj) && !this.isArray(obj); } } }; }); (function () { var handledEvents = ['blur', 'change', 'focus', 'focusin', 'focusout', 'select', 'submit', 'click', 'contextmenu', 'dblclick', 'hover', 'mousedown', 'mouseenter', 'mouseleave', 'mousemove', 'touchmove', 'mouseout', 'mouseover', 'mouseup', 'keydown', 'keypress', 'keyup', 'resize', 'scroll']; handledEvents.forEach(function (event) { document.addEventListener(event, componentEvent, true); }); new MutationObserver(componentObserver).observe(document.body, { childList: true, subtree: true }); function componentObserver(mutations, observer) { var update = false; for (var index = 0; index < mutations.length; index++) { var mutation = mutations[index]; if (mutation.type === 'childList' && mutation.addedNodes.length) update = true; } if (update) installComponents(); } function installComponents() { var components = [].slice.call(document.querySelectorAll('[data-component]')); components.forEach(function (component) { var self = component; if (component.installed) return; self.component_name = self.attributes['data-component'].value; require([self.attributes['data-component'].value], function (module) { if (self.installed) return; module.install.call(self, self); self.installed = true; }); }); }; function insereElemento(c, element) { var component = (element.attributes['data-component']) ? element.attributes['data-component'].value : ''; if (component) { element.component = component; c.last_component[component] = { element: element, name: component, elements: [] }; c.components.push(c.last_component[component]); } if (typeof element.className != "string") return; var classList = element.className.split(' '); var l = classList.length; for (var i = 0; i < l; i++) { var _class = classList[i]; var _i = _class.indexOf('_'); if (_i == -1) continue; if (_class.indexOf('--') != -1) continue; if (_i != _class.lastIndexOf('_')) continue; var parts = _class.split('_'); if (!c.last_component[parts[0]]) continue; c.last_component[parts[0]].elements.push({ name: _class, element: element }); } return c; } function componentEvent(event) { if (!event.target || !event.target.tagName || ['HTML', 'BODY'].indexOf(event.target.tagName) != -1) return; var element = event.target; var element_list = []; var _event = event; while (element != document.body) { element_list.push(element); element = element.parentElement; } var data = element_list.reverse().reduce(insereElemento, { waiting_components: {}, components: [], last_component: {} }); var called = []; if(data.components != undefined && data.components.length != 0) { data.components.reverse().forEach(function (component) { if (!require.s.contexts['_'].defined[component.name]) return; var module = require(component.name); if (!module.events[event.type]) return; component.elements .reverse() .forEach(function (element) { if (!module.events[event.type][element.name]) return; if (called.indexOf(module.events[event.type][element.name]) != -1) return; module.events[event.type][element.name].call(element.element, component.element, _event); called.push(module.events[event.type][element.name]); }); }); } return false; } define('Component/BEM', [], function () { HTMLElement.prototype.is = getElementState; HTMLElement.prototype.state = setElementState; HTMLElement.prototype.element = elementFinder; Object.defineProperty(HTMLElement.prototype, 'BEM', { get: function () { return elementFinder.bind(this, '_')(); } }) function elementFinder(name) { var timeout = setTimeout(doElementChanges), is_htmlElement = name instanceof HTMLElement, is_array = name instanceof Array, self = this, options = { element_selector: name }, menu = { state: setOption.bind(this, 'state'), modifier: setOption.bind(this, 'modifier'), variation: setOption.bind(this, 'variation'), helper: setOption.bind(this, 'helper'), element: elementFinder.bind(this), append: appendToElement.bind(this), first: getFirst.bind(this), last: getLast.bind(this), all: selectElements.bind(this), do: doFn, now: doNow }; var define = Object.defineProperty.bind(this, menu); define('value', { get: getAttrOrEmpty.bind(self, 'value'), set: setAttr.bind(self, 'value') }); define('html', { get: getAttrOrEmpty.bind(self, 'innerHTML'), set: setAttr.bind(self, 'innerHTML') }); define('timeout', { get: function () { return timeout; }, set: function (nv) { timeout = nv; return nv } }); if (is_htmlElement || is_array) return menu; options.element_selector = "." + this.component_name; if (name != '_') options.element_selector += "_" + name; return menu; function doFn(fn) { fn(menu); return menu; } function doNow() { doElementChanges(); return menu; } function appendToElement(html) { selectElements().forEach(function (el) { el.innerHTML += html }); } function getFirst() { return selectElements()[0]; } function getLast() { return selectElements().reduce(function (c, e) { return e || c; }, null); } function selectElements() { if (options.element_selector instanceof Array) return options.element_selector; if (options.element_selector instanceof HTMLElement) return [options.element_selector]; if (options.element_selector.indexOf('_') == -1) return [self]; return [].slice.call(self.querySelectorAll(options.element_selector)) } function getAttrOrEmpty(attr) { var selection = selectElements(); if (!selection) return ""; return selection[0][attr]; } function setAttr(attr, value) { selectElements().forEach(function (element) { element[attr] = value; }); } function setOption(opt, name, state) { if (!options[opt]) { options[opt] = [{ name: name, state: state }]; return menu; } options[opt].push({ name: name, state: state }); return menu; } function doElementChanges() { if (timeout) clearTimeout(timeout); var elements = selectElements(); elements.forEach(function (el) { setStates(el, options.state, function (e) { return 'is-' + e.name; }); setStates(el, options.helper, function (e) { return 'h-' + e.name; }); setStates(el, options.modifier, function (e) { return '-' + e.name; }); setStates(el, options.variation, function (e) { return self.component_name + "_" + name + "--" + e.name; }); }); if (!elements.length) return; } } function getElementState(state) { return this.classList.contains('is-' + state); } function setElementState(state, status) { var is = this.is(state); if (is && status) return; if (is ^ status) this.BEM.state(state, status); } function setStates(element, states, classFn) { if (!states || !states.length) return; return states.forEach(addClass); function addClass(el) { if (el.state) return element.classList.add(classFn(el)); element.classList.remove(classFn(el)); } } }); define('Component', ['Component/BEM'], function () { function Component(name) { this.name = name; return this }; Component._events = {}; Component.instances = []; Component.on = function () { on.apply(Component, arguments); } Component.off = function () { off.apply(Component, arguments); } Component.emit = function () { emit.apply(Component, arguments); } Component.prototype = { on: on, off: off, emit: emit, _events: {}, events: {}, elements: {}, register: register, bootstrap: bootstrap, install: function () { } }; function on(event, cb) { event = this._events[event] = this._events[event] || [] event.push(cb); } function off(event, cb) { if (!this._events[event]) return; event = this._events[event]; event.splice(event.indexOf(cb) >>> 0, 1); } function emit(event) { var list = this._events[event] if (!list || !list[0]) return var args = list.slice.call(arguments, 1) list.slice().map(function (i) { i.apply(this, args) }) } function bootstrap() { Component.instances.push(this); var self = this; Object.keys(self.elements).forEach(function (target) { Object.keys(self.elements[target]).forEach(function (event) { self.register(self.name + '_' + target, event, self.elements[target][event]); if (handledEvents.indexOf(event) != -1) return; if (event[0] != '$') { handledEvents.push(event); document.addEventListener(event, componentEvent, true); return; } if (!jQuery) return console.log('O evento "' + event + '" necessita de jQuery para acontecer'); if (event.slice(0, 2) == "$$") { jQuery(document).on(event.slice(2), '.' + self.name + '_' + target, function (_event) { self.elements[target][event].call(this, $(this).parents('[data-component="' + self.name + '"]').get(0), _event); }); return; } jQuery(document).on(event.slice(1), '.' + self.name + '_' + target, self.elements[target][event]); }) }) } function register(target, event, fn) { if (!this.events[event]) this.events[event] = {}; if (!this.events[event][target]) this.events[event][target] = {}; this.events[event][target] = fn; } var el = document.createElement('DIV'); document.body.appendChild(el); document.body.removeChild(el); window.Component = Component; return Component; }); })(); define('stepper', ['Component'], function () { var stepper = new Component('stepper'); stepper.install = function () { $('.stepper_input', this).on('keyup', onKeydown); setInputStates(this); } stepper.elements.adder = { click: addValue } stepper.elements.reducer = { click: reduceValue } stepper.bootstrap(); return stepper; function addValue(component, event) { if ($(this).is('.disabled')) return; var $target = $('.stepper_input', component); $target.val(parseInt($target.val()) + 1); setInputStates(component); $target.get(0).dispatchEvent(new Event('change', { bubbles: true })); } function reduceValue(component, event) { if ($(this).is('.disabled')) return; var $target = $('.stepper_input', component); $target.val(parseInt($target.val()) - 1).trigger('change'); setInputStates(component); $target.get(0).dispatchEvent(new Event('change', { bubbles: true })); } function onKeydown(event) { if ($.inArray(event.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 || (event.keyCode === 65 && (event.ctrlKey === true || event.metaKey === true)) || (event.keyCode >= 35 && event.keyCode <= 40)) { return; } if ((event.shiftKey || (event.keyCode < 48 || event.keyCode > 57)) && (event.keyCode < 96 || event.keyCode > 105)) { event.preventDefault(); } setInputStates($(this).parent('[data-component="stepper"]').get(0)); } function setInputStates(component) { if (component.attributes['data-disabled'] && component.attributes['data-disabled'].value) { $('.stepper_adder, .stepper_reducer', component).addClass('disabled'); $('.stepper_input', component).attr('disabled', 'disabled'); return; } var $target = $('.stepper_input', component); var value = parseInt($target.val()); var max = (component.attributes['data-max']) ? parseInt(component.attributes['data-max'].value) : false; var min = (component.attributes['data-min']) ? parseInt(component.attributes['data-min'].value) : false; if (max !== false && value < max) { $('.stepper_adder', component).removeClass('disabled'); } if (max !== false && value >= max) { $target.val(max); $('.stepper_adder', component).addClass('disabled'); }; if (min !== false && value > min) { $('.stepper_reducer', component).removeClass('disabled'); } if (min !== false && value <= min) { $target.val(min); $('.stepper_reducer', component).addClass('disabled'); } } }); define('calendar', ['Component'], function () { var module = new Component('calendar'); module.install = install; module.elements = {}; module.bootstrap(); return module; function install(base) { $.fn.datepicker.dates['pt-BR'] = { days: ["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"], daysShort: ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb"], daysMin: ["D", "S", "T", "Q", "Q", "S", "S"], months: ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"], monthsShort: ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"], today: "Hoje", monthsTitle: "Meses", clear: "Limpar", format: "yyyy-mm-dd" // format:"dd/mm/yyyy" }; var content = base.element("datepicker").first(); content.dataset.date = base.element("selected-date").first().value; calendar = $(".calendar_datepicker").datepicker({ startDate: new Date(), weekStart: 1, beforeShowDay: beforeShowDay.bind(null, base), // datesDisabled: base.element("crowded").first().value, language: base.dataset.lang }).on('changeDate', function (e) { var selected_date = base.element("selected-date").first(); var clicked_date = calendar.datepicker('getFormattedDate'); selected_date.value = clicked_date; content.dataset.date = clicked_date; $("input[name=dataSelecionada]").trigger('change'); }) } function memo(val) { try { if (!cache[val]) cache[val] = JSON.parse(val); return cache[val]; } catch (e) { return {} } } function beforeShowDay(base, date) { var date_full = moment(date).format('Y-MM-DD'); var date_now = moment().format('Y-MM-DD'); var year = moment(date).format('Y'); var month = moment(date).format('MM'); var day = moment(date).format('DD'); var close_days = base.element("close-days").first().value; var open_days = base.element("open-days"); var holidays = base.element("holidays").first().value; var crowded = base.element("crowded").first().value; var night_sessions = base.element("night-sessions").first() ? base.element("night-sessions").first().value : '[]'; if (open_days) { open_days = open_days.first(); open_days = open_days ? open_days.value : null; open_days && (open_days = JSON.parse(open_days)); }; var shown_days = (date.getFullYear() + '-' + zeroPad(date.getMonth() + 1) + '-' + zeroPad(date.getDate())); var is_closed = close_days.indexOf(shown_days) !== -1; var is_holiday = holidays.indexOf(shown_days) !== -1; var is_crowded = crowded.indexOf(shown_days) !== -1; var is_night_sessions = night_sessions.indexOf(shown_days) !== -1; if (open_days && !is_closed) { is_closed = open_days.every(i => i !== shown_days); } var classes = []; var tooltip = []; var label_aberto_modificar = base.dataset.labelabertomodificar; var label_aberto = base.dataset.labelaberto; var obj = { content: ""; // if(carrinho.descontos.length >0 ){ // texto_mensagem_cupom = "
" + carrinho.descontos[0].cupom_mensagem + "
"; // $('.msg-descont-cupom').html(texto_mensagem_cupom).css('display', display_descontos); // }else // $('.msg-descont-cupom').html(texto_mensagem_cupom).css('display', display_descontos); } else { // Mensagem padrão $('.checkout_discount-message').html(texto_desconto).css('display', display_descontos); } } function getBenefitText(benefit) { if (benefit.cortesias && benefit.tipo_cortesia == 2) { return "" + carrinhoi18n.app.pagamento.tem_condicao_especial_de_compra + ""; } if (benefit.cortesias && benefit.tipo_cortesia == 1) { return carrinhoi18n.app.pagamento.tem_cortesias_especiais; } switch (benefit.aplicacao) { case 3: case "3": if (benefit.tipo_valor == 1) { return ' R$' + maskedMoney(benefit.valor) + ' ' + carrinhoi18n.app.pagamento.desconto_valor_valor_compra + " "; } return '' + benefit.valor + ' ' + carrinhoi18n.app.pagamento.desconto_percentual_valor_compra + " "; break; case 1: case "1": if (benefit.tipo_valor == 1) { return ' R$' + maskedMoney(benefit.valor) + ' ' + carrinhoi18n.app.pagamento.desconto_valor_frete_produtos + " "; } return '' + benefit.valor + ' ' + carrinhoi18n.app.pagamento.desconto_percencual_frete_produtos + " "; break; default: if (benefit.tipo_valor == 1) { // console.log(carrinhoi18n.app.pagamento.desconto_valor_produto_unico); return ' R$' + maskedMoney(benefit.valor) + ' ' + carrinhoi18n.app.pagamento.desconto_valor_produto_unico + " "; } return '' + benefit.valor + ' ' + carrinhoi18n.app.pagamento.desconto_percentual_produto_unico + " "; } } function setDesconto(component) { component.desconto = { last_input: "" }; } function maskedMoney(number) { number = number.toFixed(3) * 100; if (number % 1) number++; number = Math.floor(number); return $('').mask('#.##0,00', { reverse: true }).masked(number); } }); // NOVO CALENDARIO DE PASSAPORTES/OPCIONAIS 2020 define('newcalendar', ['Component'], function () { var module = new Component('newcalendar'); var cache = {} var dataClickSel = []; var window_size = $(window).width(); module.install = install; module.elements = { 'trigger': { click: toggleCalendar }, 'close': { click: toggleCalendar } }; module.bootstrap(); return module; function install(base) { $.fn.datepicker.dates['pt-BR'] = { days: ["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"], daysShort: ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb"], daysMin: ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb"], months: ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"], monthsShort: ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"], today: "Hoje", monthsTitle: "Meses", clear: "Limpar", format: "yyyy-mm-dd" // format:"dd/mm/yyyy" }; var content = base.element("datepicker").first(); content.dataset.date = base.element("selected-date").first().value; // init colocar o loading em todas as tds => .newcalendar .datepicker table tbody td.day (loading-normal) if (base.element("type-product").first().value == 'passaportes') { $('head').append(``); } $(".newcalendar_datepicker").datepicker({ startDate: new Date(), weekStart: 1, beforeShowDay: beforeShowDay.bind(null, base), // datesDisabled: base.element("crowded").first().value, language: base.dataset.lang, templates: { leftArrow: "