/*LOGIN*/
/**
* Gets Cookie called 'name'
*
* @param {string} name Name of the cookie to read
*/
function ReadCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0)
{
var cont = c.substring(nameEQ.length, c.length);
if ((cont+" ").indexOf("?")>=0) {cont="";}
var contsp = cont.split('|');
if (contsp.length>0) {return contsp[0];}
else {
return cont;}
}
}
return "";
}
$(document).ready(function(){
var $form_modal = $('.cd-user-modal'),
$form_login = $form_modal.find('#cd-login'),
$form_signup = $form_modal.find('#cd-signup'),
$form_forgot_password = $form_modal.find('#cd-reset-password'),
$form_modal_tab = $('.cd-switcher'),
$tab_login = $form_modal_tab.children('li').eq(0).children('a'),
$tab_signup = $form_modal_tab.children('li').eq(1).children('a'),
$forgot_password_link = $form_login.find('.cd-form-bottom-message a'),
$back_to_login_link = $form_forgot_password.find('.cd-form-bottom-message a'),
$main_nav = $('.main-nav');
$cookieLog = ReadCookie('login');
//open modal
$main_nav.on('click', function(event){
if( $(event.target).is($main_nav) ) {
// on mobile open the submenu
$(this).children('ul').toggleClass('is-visible');
} else {
// on mobile close submenu
$main_nav.children('ul').removeClass('is-visible');
//show modal layer
$form_modal.addClass('is-visible');
//show the selected form
( $(event.target).is('.cd-signup') ) ? signup_selected() : login_selected();
}
});
//close modal
$('.cd-user-modal').on('click', function(event){
if( $(event.target).is($form_modal) || $(event.target).is('.cd-close-form') ) {
$form_modal.removeClass('is-visible');
}
});
//close modal when clicking the esc keyboard button
$(document).keyup(function(event){
if(event.which=='27'){
$form_modal.removeClass('is-visible');
}
});
//hide or show password
$('.hide-password').on('click', function(){
var $this= $(this),
$password_field = $this.prev('input');
( 'password' == $password_field.attr('type') ) ? $password_field.attr('type', 'text') : $password_field.attr('type', 'password');
( 'Mostrar' == $this.text() ) ? $this.text('Ocultar') : $this.text('Mostrar');
//focus and move cursor to the end of input field
$password_field.putCursorAtEnd();
});
//show forgot-password form
$forgot_password_link.on('click', function(event){
event.preventDefault();
forgot_password_selected();
});
//back to login from the forgot-password form
$back_to_login_link.on('click', function(event){
event.preventDefault();
login_selected();
});
function login_selected(){
$form_login.addClass('is-selected');
$form_signup.removeClass('is-selected');
$form_forgot_password.removeClass('is-selected');
$tab_login.addClass('selected');
$tab_signup.removeClass('selected');
}
function forgot_password_selected(){
$form_login.removeClass('is-selected');
$form_signup.removeClass('is-selected');
$form_forgot_password.addClass('is-selected');
}
//REMOVE THIS - it's just to show error messages
$form_login.find('input[type="submit"]').on('click', function(event){
event.preventDefault();
$form_login.find('input[type="email"]').toggleClass('has-error').next('span').toggleClass('is-visible');
});
$form_signup.find('input[type="submit"]').on('click', function(event){
event.preventDefault();
$form_signup.find('input[type="email"]').toggleClass('has-error').next('span').toggleClass('is-visible');
});
});
//credits https://css-tricks.com/snippets/jquery/move-cursor-to-end-of-textarea-or-input/
jQuery.fn.putCursorAtEnd = function() {
return this.each(function() {
// If this function exists...
if (this.setSelectionRange) {
// ... then use it (Doesn't work in IE)
// Double the length because Opera is inconsistent about whether a carriage return is one character or two. Sigh.
var len = $(this).val().length * 2;
this.setSelectionRange(len, len);
} else {
// ... otherwise replace the contents with itself
// (Doesn't work in Google Chrome)
$(this).val($(this).val());
}
});
};
jQuery('#cody-info ul li').eq(1).on('click', function(){
$('#cody-info').hide();
});
/*SLIDER*/
$( document ).ready(function() {
$('.responsive').slick({
infinite: false,
autoplay:false,
speed: 300,
slidesToShow: 4,
slidesToScroll: 1,
responsive: [
{
breakpoint: 1024,
settings: {
slidesToShow: 3,
slidesToScroll: 1,
infinite: true,
dots: true,
arrows: true
}
},
{
breakpoint: 600,
settings: {
slidesToShow: 2,
slidesToScroll: 1
}
},
{
breakpoint: 480,
settings: {
slidesToShow: 1,
slidesToScroll: 1
}
}
// You can unslick at a given breakpoint now by adding:
// settings: "unslick"
// instead of a settings object
]
});
$('.slick').slick({
dots:true,
autoplay: true,
autoplaySpeed: 2000,
fade: true,
arrows: true
});
$('.testimonial-slider').slick({
infinite: false,
autoplay:false,
speed: 300,
slidesToShow: 3,
slidesToScroll: 1,
responsive: [
{
breakpoint: 1024,
settings: {
slidesToShow: 3,
slidesToScroll: 1,
infinite: true,
dots: true,
arrows: true
}
},
{
breakpoint: 600,
settings: {
slidesToShow: 2,
slidesToScroll: 1
}
},
{
breakpoint: 480,
settings: {
slidesToShow: 1,
slidesToScroll: 1
}
}
// You can unslick at a given breakpoint now by adding:
// settings: "unslick"
// instead of a settings object
]
});
});
/*MOBILE MENU*/
$(document).ready(function(){
$('.sidebar-menu-nav-right,.slide-fade-menu,.sliding-panel-close').on('click touchstart',function (e) {
$('.slide-content-menu,.slide-fade-menu').toggleClass('is-visible-menu');
$('#wrapper').toggleClass('is-obscured');
e.preventDefault();
});
});
/*MENU DEPARTAMENTO*/
$(document).ready(function(){
$('#menu-icon-shape').on('click', function() {
$('#menu-icon-shape').toggleClass('active');
$('#top, #middle, #bottom').toggleClass('active');
$('#overlay-nav').toggleClass('active');
});
});
/*ACORDION*/
$(document).ready(function(){
$(function() {
$('.acc__title').click(function(j) {
var dropDown = $(this).closest('.acc__card').find('.acc__panel');
$(this).closest('.acc').find('.acc__panel').not(dropDown).slideUp();
if ($(this).hasClass('active')) {
$(this).removeClass('active');
} else {
$(this).closest('.acc').find('.acc__title.active').removeClass('active');
$(this).addClass('active');
}
dropDown.stop(false, true).slideToggle();
j.preventDefault();
});
});
});
/*LIKE HEART*/
$(document).ready(function(){
$(".heart.fa").click(function() {
if ($cookieLog==""){
alert("Execute o seu registro ou login para criar a lista de desejos");
}
else
{
$(this).toggleClass("fa-heart fa-heart-o");
var item_id = $(this).attr('id');
if(parseInt(item_id) < 1) {
return false;
}
var URL_WISH = '/bin/addwish.pas';
$.ajax({
url: URL_WISH,
data: "item_id="+item_id+"&login="+$cookieLog,//{ajax:"true", action:'add_to_wishlist', item_id:item_id},
type: "GET",
error: function(XMLHttpRequest, textStatus, errorThrown) {
// usualy on headers 404 or Internal Server Error
//_toastr("ERROR 404 - Item Not Added to Wishlit!","top-right","error",false);
},
success: function(data) {
data = data.trim(); // remove output spaces
// PHP RETURN: INVALID ITEM ID
if(data == '_invalid_id_') {
//_toastr("Incorreto - Item não adicionado, incorreto!","top-right","error",false);
} else
// PHP RETURN: INVALID USER
if(data == '_invalid_user_') {
//_toastr("Não logado - Você deve logar para criar sua lista de desejos!","top-right","error",false);
} else
// PHP RETURN: OK, ADDED TO WISHLIST
if(data == '_ok_') {
//_toastr("Item adicionado a sua lista de desejos!","top-right","success",false);
// PHP RETURN: SOMETHING ELSE THAN EXPECTED
}
else
// PHP RETURN: OK, ADDED TO WISHLIST
if(data == '_removed_') {
//_toastr("Item removido com sucesso da sua lista de desejos!","top-right","success",false);
// PHP RETURN: SOMETHING ELSE THAN EXPECTED
}
else
{
// if the php output is not _invalid_id_ OR _ok_ - maybe you have a php errors/warnings
//_toastr("Erro desconhecido - Item não pode ser adicionado!","top-right","error",false);
}
}
});
}
});
});
/*SELECT CATEGORY*/
$(document).ready(function(){
$('select#select-product').on('change', function (e) {
var val = $(this).val();
if(val == 'all'){
$('.item').removeClass('hide');
} else {
$('.item').removeClass('hide').filter( ':not([data-category*="' + val + '"])' ).addClass( 'hide');
}
});
// For button fields
$('button').click(function(){
// Get the category from the selection
var category = $(this).attr('data-category');
// Remove active class
$('button').removeClass('active');
// Add active class to clicked item
$(this).addClass('active');
// Filter the items
$('.item').removeClass('hide').filter( '[data-category*="' + category + '"]' ).addClass( 'hide');
});
});
/*PAGINATION*/
var size = 200;
var $cont,chunks;
var html = '';
jQuery(document).ready(function($) {
$cont = $('.content-card');
var filterChecks = $('.tag-filters :checkbox');
createPagination($cont);
filterChecks.change(function() {
html = '';
var results = [];
var classSelectors = filterChecks.filter(':checked').map(function() {
return '.' + this.value;
}).get();
if(classSelectors.length){
for(var x = 0; x < $cont.has(classSelectors.join()).length; x++){
results.push($cont.has(classSelectors.join())[x]);
}
createPagination(results);
} else {
createPagination($cont);
}
});
$('div.pagination').on('click', 'a', function(){
$cont.hide();
$(chunks[parseInt($(this).text())-1]).show();
});
});
function createPagination(data){
chunks = new Array(Math.ceil(data.length / size)).fill("").map(function() {
return this.splice(0, size)
}, data.slice());
$cont.hide();
for(var i = 0; i < chunks.length; i++){
html += '
'+(i+1)+'';
}
$('div.pagination').html(html);
$(chunks[0]).show();
}
/*CUSTOM-DROPDOWN*/
$(document).ready(function(){
(function($) {
var CheckboxDropdown = function(el) {
var _this = this;
this.isOpen = false;
this.areAllChecked = false;
this.$el = $(el);
this.$label = this.$el.find('.dropdown-label');
this.$checkAll = this.$el.find('[data-toggle="check-all"]').first();
this.$inputs = this.$el.find('[type="checkbox"]');
this.onCheckBox();
this.$label.on('click', function(e) {
e.preventDefault();
_this.toggleOpen();
});
this.$checkAll.on('click', function(e) {
e.preventDefault();
_this.onCheckAll();
});
this.$inputs.on('change', function(e) {
_this.onCheckBox();
});
};
CheckboxDropdown.prototype.onCheckBox = function() {
this.updateStatus();
};
CheckboxDropdown.prototype.updateStatus = function() {
var checked = this.$el.find(':checked');
this.areAllChecked = false;
this.$checkAll.html('Check All');
if(checked.length <= 0) {
this.$label.html('Organizar Por');
}
else if(checked.length === 1) {
this.$label.html(checked.parent('label').text());
}
else if(checked.length === this.$inputs.length) {
this.$label.html('Todos Selecionados');
this.areAllChecked = true;
this.$checkAll.html('Uncheck All');
}
else {
this.$label.html(checked.length + 'Selecionado');
}
};
CheckboxDropdown.prototype.onCheckAll = function(checkAll) {
if(!this.areAllChecked || checkAll) {
this.areAllChecked = true;
this.$checkAll.html('Uncheck All');
this.$inputs.prop('checked', true);
}
else {
this.areAllChecked = false;
this.$checkAll.html('Check All');
this.$inputs.prop('checked', false);
}
this.updateStatus();
};
CheckboxDropdown.prototype.toggleOpen = function(forceOpen) {
var _this = this;
if(!this.isOpen || forceOpen) {
this.isOpen = true;
this.$el.addClass('on');
$(document).on('click', function(e) {
if(!$(e.target).closest('[data-control]').length) {
_this.toggleOpen();
}
});
}
else {
this.isOpen = false;
this.$el.removeClass('on');
$(document).off('click');
}
};
var checkboxesDropdowns = document.querySelectorAll('[data-control="checkbox-dropdown"]');
for(var i = 0, length = checkboxesDropdowns.length; i < length; i++) {
new CheckboxDropdown(checkboxesDropdowns[i]);
}
})(jQuery);
});
/*FILTER CATEGORY PRODUCT*/
$(document).ready(function(){
var $filterCheckboxes = $('input[type="checkbox"]');
var filterFunc = function() {
var selectedFilters = {};
$filterCheckboxes.filter(':checked').each(function() {
if (!selectedFilters.hasOwnProperty(this.name)) {
selectedFilters[this.name] = [];
}
selectedFilters[this.name].push(this.value);
});
// create a collection containing all of the filterable elements
var $filteredResults = $('.product-item');
// loop over the selected filter name -> (array) values pairs
$.each(selectedFilters, function(name, filterValues) {
// filter each .animal element
$filteredResults = $filteredResults.filter(function() {
var matched = false,
currentFilterValues = $(this).data('category').split(' ');
// loop over each category value in the current .animal's data-category
$.each(currentFilterValues, function(_, currentFilterValue) {
// if the current category exists in the selected filters array
// set matched to true, and stop looping. as we're ORing in each
// set of filters, we only need to match once
if ($.inArray(currentFilterValue, filterValues) != -1) {
matched = true;
return false;
}
});
// if matched is true the current .animal element is returned
return matched;
});
});
$('.product-item').hide().filter($filteredResults).show();
}
$filterCheckboxes.on('change', filterFunc);
});
/*SIDEBAR NAV CATEGORIA PRODUTO*/
$(document).ready(function(){
$('.sidebar-nav-right,.slide-fade,.sliding-panel-close').on('click touchstart',function (e) {
$('.slide-content,.slide-fade').toggleClass('is-visible');
$('#wrapper').toggleClass('is-obscured');
e.preventDefault();
});
});
/*INPUT QUANTITY SINGLE PRODUTO*/
$(document).ready(function(){
// Increment value in quantity input
$('.qty-plus').each(function(index) {
$(this).click(function(e) {
e.preventDefault();
var current = $(this).siblings("input.quantity").val();
var currentVal = parseInt($(this).siblings("input.quantity").val());
var inputElement = document.querySelector('input[name="product_quantity"]');
if (inputElement){
var maxval = parseInt(inputElement.getAttribute("max"));
//alert(maxval);
}
if (!isNaN(currentVal)) {
if (currentVal + 1<=maxval){
$(this).siblings("input.quantity").val(currentVal + 1);
}
} else {
$(this).siblings("input.quantity").val(1);
console.log("Failed!")
}
});
});
// Decrement value in quantity input
$(".qty-minus").each(function(index) {
$(this).click(function(e) {
e.preventDefault();
var currentVal = parseInt($(this).siblings("input.quantity").val());
if (!isNaN(currentVal) && currentVal > 1) {
$(this).siblings("input.quantity").val(currentVal - 1);
} else {
$(this).siblings("input.quantity").val(1);
}
});
});
});
/*SIDEBAR MINICART SINGLE PRODUTO*/
$(document).ready(function(){
$('#offCanvas').on('click', function () {
$('.nav-offcanvas').addClass('open');
$('.offcanvas-overlay').addClass('on');
});
$('#offCanvasClose, .offcanvas-overlay').on('click', function () {
$('.nav-offcanvas').removeClass('open');
$('.offcanvas-overlay').removeClass('on');
});
});
/*MINI CART SINGLE PRODUTO*/
$(document).ready(function() {
$('#smartcart').smartCart();
});
/*MASCARA SINGLE PRODUTO*/
$( document ).ready(function() {
$("input[name='data-cep']").mask("00000 000");
});
/*MASCARA FORMULARIO CHECKOUT*/
$( document ).ready(function() {
$("input[name='data-cpf']").mask("000.000.000-00");
$("input[name='expiry-data']").mask("00 / 00");
$("input[name='number-card']").mask("0000 0000 0000 0000");
$("input[name='cod-security']").mask("000");
});
$( document ).ready(function() {
$("input[name='data-nasc']").mask("00/00/0000");
$("input[name='cel-numb']").mask("(00) 000000-0000");
$("input[name='cep-numb']").mask("00000-000");
});
/*SELECT-CHECKOUT*/
$(document).ready(function(){
// Iterate over each select element
$('select#parcelas').each(function () {
// Cache the number of options
var $this = $(this),
numberOfOptions = $(this).children('option').length;
// Hides the select element
$this.addClass('s-hidden');
// Wrap the select element in a div
$this.wrap('');
// Insert a styled div to sit over the top of the hidden select element
$this.after('');
// Cache the styled div
var $styledSelect = $this.next('div.styledSelect');
// Show the first select option in the styled div
$styledSelect.text($this.children('option').eq(0).text());
// Insert an unordered list after the styled div and also cache the list
var $list = $('', {
'class': 'options'
}).insertAfter($styledSelect);
// Insert a list item into the unordered list for each select option
for (var i = 0; i < numberOfOptions; i++) {
$('', {
text: $this.children('option').eq(i).text(),
rel: $this.children('option').eq(i).val()
}).appendTo($list);
}
// Cache the list items
var $listItems = $list.children('li');
// Show the unordered list when the styled div is clicked (also hides it if the div is clicked again)
$styledSelect.click(function (e) {
e.stopPropagation();
$('div.styledSelect.active').each(function () {
$(this).removeClass('active').next('ul.options').hide();
});
$(this).toggleClass('active').next('ul.options').toggle();
});
// Hides the unordered list when a list item is clicked and updates the styled div to show the selected list item
// Updates the select element to have the value of the equivalent option
$listItems.click(function (e) {
e.stopPropagation();
$styledSelect.text($(this).text()).removeClass('active');
$this.val($(this).attr('rel'));
$list.hide();
/* alert($this.val()); Uncomment this for demonstration! */
});
// Hides the unordered list when clicking outside of it
$(document).click(function () {
$styledSelect.removeClass('active');
$list.hide();
});
});
});
/*FUNCTION EDIT TABLE PRODUCT CHECKOUT*/
var removedItem,
sum = 0;
$(function(){
// calculate the values at the start
calculatePrices();
// Click to remove an item
$(document).on("click", "a.remove", function() {
removeItem.apply(this);
});
// Undo removal link click
$(document).on("click", ".removeAlert a", function(){
// insert it into the table
addItemBackIn();
//remove the removal alert message
hideRemoveAlert();
});
$(document).on("change", "input.quantity", function(){
var val = $(this).val(),
pricePer,
total
if ( val <= "0") {
removeItem.apply(this);
} else {
// reset the prices
sum = 0;
// get the price for the item
pricePer = $(this).parents("td").prev("td").text();
// set the pricePer to a nice, digestable number
pricePer = formatNum(pricePer);
// calculate the new total
total = parseFloat(val * pricePer).toFixed(2);
// set the total cell to the new price
$(this).parents("td").siblings(".itemTotal").text("R$" + total);
// recalculate prices for all items
calculatePrices();
}
});
});
function removeItem() {
// store the html
removedItem = $(this).closest("tr").clone();
// fade out the item row
$(this).closest("tr").fadeOut(500, function() {
$(this).remove();
sum = 0;
calculatePrices();
});
// fade in the removed confirmation alert
$(".removeAlert").fadeIn();
// default to hide the removal alert after 5 sec
setTimeout(function(){
hideRemoveAlert();
}, 5000);
}
function hideRemoveAlert() {
$(".removeAlert").fadeOut(500);
}
function addItemBackIn() {
sum = 0;
$(removedItem).prependTo("table.items tbody").hide().fadeIn(500)
calculatePrices();
}
function updateSubTotal(){
$("table.items td.itemTotal").each(function(){
var value = $(this).text();
// set the pricePer to a nice, digestable number
value = formatNum(value);
sum += parseFloat(value);
$("table.pricing td.subtotal").text("R$" + sum.toFixed(2));
});
}
function calculateTotal() {
var subtotal = $("table.pricing td.subtotal").text(),
total;
subtotal = formatNum(subtotal);
total = (subtotal).toFixed(2);
$("table.pricing td.orderTotal").text("R$" + total);
}
function calculatePrices() {
updateSubTotal();
calculateTotal();
}
function formatNum(num) {
return parseFloat(num.replace(/[^0-9-.]/g, ''));
}
$( document ).ready(function() {
$("#button-testimony").click(function() {
$("#box-testimony form").toggle("slow");
return false;
});
});