$(function(){ // -------------------------------------------- // VARIABLES DECLARED // -------------------------------------------- var $selectAll = $('#select-all'); var $selectBox = $('.select-box'); var i; var findout_options = ['Word of mouth','Radio','TV','Print','Outdoor','Social Media','From a Friend','Advertisement']; var country_list = ["Afghanistan","Albania","Algeria","Andorra","Angola","Anguilla","Antigua & Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia & Herzegovina","Botswana","Brazil","British Virgin Islands","Brunei","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Cape Verde","Cayman Islands","Chad","Chile","China","Colombia","Congo","Cook Islands","Costa Rica","Cote D Ivoire","Croatia","Cruise Ship","Cuba","Cyprus","Czech Republic","Denmark","Djibouti","Dominica","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Estonia","Ethiopia","Falkland Islands","Faroe Islands","Fiji","Finland","France","French Polynesia","French West Indies","Gabon","Gambia","Georgia","Germany","Ghana","Gibraltar","Greece","Greenland","Grenada","Guam","Guatemala","Guernsey","Guinea","Guinea Bissau","Guyana","Haiti","Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Iran","Iraq","Ireland","Isle of Man","Israel","Italy","Jamaica","Japan","Jersey","Jordan","Kazakhstan","Kenya","Kuwait","Kyrgyz Republic","Laos","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Macau","Macedonia","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Mauritania","Mauritius","Mexico","Moldova","Monaco","Mongolia","Montenegro","Montserrat","Morocco","Mozambique","Namibia","Nepal","Netherlands","Netherlands Antilles","New Caledonia","New Zealand","Nicaragua","Niger","Nigeria","Norway","Oman","Pakistan","Palestine","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Poland","Portugal","Puerto Rico","Qatar","Reunion","Romania","Russia","Rwanda","Saint Pierre & Miquelon","Samoa","San Marino","Satellite","Saudi Arabia","Senegal","Serbia","Seychelles","Sierra Leone","Singapore","Slovakia","Slovenia","South Africa","South Korea","Spain","Sri Lanka","St Kitts & Nevis","St Lucia","St Vincent","St. Lucia","Sudan","Suriname","Swaziland","Sweden","Switzerland","Syria","Taiwan","Tajikistan","Tanzania","Thailand","Timor L'Este","Togo","Tonga","Trinidad & Tobago","Tunisia","Turkey","Turkmenistan","Turks & Caicos","Uganda","Ukraine","United Arab Emirates","United Kingdom","Uruguay","Uzbekistan","Venezuela","Vietnam","Virgin Islands (US)","Yemen","Zambia","Zimbabwe"]; var month_names = []; var $dropdownToggle = $('.dropdown-toggle'); // -------------------------------------------- // DOM MANIPULATION // -------------------------------------------- // populate FIND-OUT node populateSelectNode($('#countries'), country_list); // populate BIRTHDATE node // months node //updateNumberOfDays(); // -------------------------------------------- // EVENT LISTENERS // -------------------------------------------- $('#scroll-top').click(function(){ $('html, body').animate({ scrollTop: 0, }, 1000); }); $(document).on("click", '.checkbox-button', function(event) { $('.filter-checkbox-wrapper').toggleClass('checkbox-expand'); $(this).children().toggleClass('fa-plus fa-minus'); }) $(document).on("click", '.read-more-collapse', function() { var profilePara = $(this).prev().prev().html(); if ($(this).hasClass('more')) { $(this).removeClass('more'); $(this).addClass('less'); $(this).parent().find('.profile-reviews-para').css('display','none'); $(this).parent().find('.profile-reviews-complete').css('display','block'); $(this).html('Collapse'); } else { $(this).removeClass('less'); $(this).addClass('more'); $(this).parent().find('.profile-reviews-complete').css('display','none'); $(this).parent().find('.profile-reviews-para').css('display','block'); $(this).html('Read More'); } }) $(document).on("click", '.photo-gallery-button', function(event) { $('.product-photo-gallery').toggleClass('shop-show'); $('html, body').addClass('overflow-hidden'); }) $(document).on("click", '.popup-img', function(event) { $('.review-popup-image').addClass('review-popup-show'); $('.review-popup-image figure').html($(this).children().children()[0].outerHTML) }) $(document).on("click", '#popup-close', function(event) { $('.review-popup-image').removeClass('review-popup-show'); }) 'use strict'; var categoryArray = $.map(categoryList, function (team) { return { value: team, data: { category: 'Category' }}; }); var userArray = $.map(userList, function (team) { return { value: team, data: { category: 'People' }}; }); var productArray = $.map(productList, function (team) { return { value: team, data: { category: 'Products' }}; }); var brandArray = $.map(brandList, function (team) { return { value: team, data: { category: 'Brands' }}; }); var currentbrandArray = $.map(currentbrandList, function (team) { return { value: team, data: { category: 'Brands' }}; }); var searchquery = categoryArray.concat(userArray, productArray, brandArray); // Initialize ajax autocomplete: $('#autocomplete-ajax').autocomplete({ // serviceUrl: '/autosuggest/service/url', lookup: searchquery, minChars: 1, onSelect: function(suggestion) { $('#search-form').submit(); }, onHint: function (hint) { $('#autocomplete-ajax-x').val(hint); }, groupBy: 'category' }); $('#autocomplete-ajax-mobile').autocomplete({ // serviceUrl: '/autosuggest/service/url', lookup: searchquery, minChars: 1, onSelect: function(suggestion) { $('#mobile-search-form').submit(); }, onHint: function (hint) { $('#autocomplete-ajax-x').val(hint); }, groupBy: 'category' }); $('#autocomplete-addaproduct').autocomplete({ lookup: productArray, minChars: 1, onSelect: function(suggestion) { } }); $('#autocomplete-addaproductbrand').autocomplete({ lookup: brandArray, minChars: 1, onSelect: function(suggestion) { } }); $('#autocomplete-searchbrand').autocomplete({ lookup: currentbrandArray, minChars: 1, onSelect: function(suggestion) { fetch_category(this.value); fetch_product('all'); }, onHint: function (hint) { } }); $('.refine-best').on('change', function() { updateBestOptions($("option:selected", this).text(), $(this).val()); $('html, body').animate({ scrollTop: $('#best-waypoint').offset().top - 100 }, 500) }) $('#years, #months').on('change', function(){ updateNumberOfDays(); }); // all options in privacy settings $selectAll.on('change', function() { changeSelected($selectBox, $selectAll); }) // IMPORTANT populate the Character Count div (mceu_charCount) div inside tinymce status bar $(window).on('load', function() { $("#mceu_2-body").append('
'); }) // Tab handler in my-community // Tab handler in my-community $('a[data-tabName]').on('click', function(e) { e.preventDefault(); var tabId = '#' + $(this).attr('data-tabName'); var oldtabId = '#' + $(this).parent().siblings().find('.tabActive').attr('data-tabName'); $(this).parent().siblings().find('.tablink').removeClass('tabActive'); $(oldtabId).removeClass('active'); $(tabId).removeClass('active'); $(tabId).toggleClass('active'); $(this).addClass('tabActive'); }) $("#deleteModal").on("show.bs.modal", function(e) { var link = $(e.relatedTarget); $(this).find(".modal-remove").load(link.attr("name")); }) // Accordion search refiner handler $('.accordion').click(function() { // restrict only ONE tab open, remove this f(n) to allow multiple tabs open $('.accordion').not($(this)).children().removeClass('fa-minus'); $('.accordion').not($(this)).children().addClass('fa-plus'); if ($(this).children().hasClass('fa-plus')) { $(this).children().addClass('fa-minus'); $(this).children().removeClass('fa-plus'); } else { $(this).children().addClass('fa-plus'); $(this).children().removeClass('fa-minus'); } }) $('.accordion-refine').on('click', function() { // restrict only ONE tab open, remove this f(n) to allow multiple tabs open if ($(this).hasClass('active')) { $('.search-accordion-dropdown .btn.btn-green').removeClass('showBtn'); } else { $('.search-accordion-dropdown .btn.btn-green').addClass('showBtn'); } $('.accordion-refine').not(this).each(function() { $(this).removeClass('active'); var tempId = '#' + $(this).attr('data-accordionName') }) var accordionId = '#' + $(this).attr('data-accordionName'); $(this).next().toggleClass('fa-chevron-down fa-chevron-up'); }) $('.refine-best').on('focus', function() { $(this).next().addClass('fa-chevron-up'); $(this).next().removeClass('fa-chevron-down'); }) $('.refine-best').on('focusout', function() { $(this).next().addClass('fa-chevron-down'); $(this).next().removeClass('fa-chevron-up'); }) $('.refine-search').on('focus', function() { $(this).next().addClass('fa-chevron-up'); $(this).next().removeClass('fa-chevron-down'); }) $('.refine-search').on('focusout', function() { $(this).next().addClass('fa-chevron-down'); $(this).next().removeClass('fa-chevron-up'); }) $('.filter-apply').on('click', function() { $('.search-accordion-dropdown .btn.btn-green').removeClass('showBtn'); $('.accordion-refine').removeClass('active'); $('#filter').removeClass('show'); $('.accordion-refine').next().removeClass('fa-chevron-up'); $('.accordion-refine').next().addClass('fa-chevron-down') $('html, body').animate({ scrollTop: ($('.search-accordion-dropdown').offset().top - $('.refine-search-container').height()) }, 500) }) // Rating hearts handler, properly displays the # of hearts that should light up $('.fa.fa-heart.review-heart').on('click', function() { var self = $(this); var className = self.attr('data-number'); var all = 'one-like two-like three-like four-like five-like'; self.toggleClass(className); self.addClass('heart-active'); if ( self.next().hasClass('heart-active') ) { self.nextAll().removeClass('heart-active ' + all); self.prevAll().removeClass(all); self.prevAll().addClass(className) self.removeClass(all); self.addClass(className); } else { $(this).prevAll().each(function() { self.hasClass('heart-active') ? $(this).addClass('heart-active ' + className) : $(this).removeClass('heart-active ' + all); }) } var thisval = $(this).attr('name'); $('#rating').val(thisval).change(); $('#rating').valid(); }) // // Only 1 checkbox with similar value allowed to be checked // $('.product-filter input[type="checkbox"]').on('change', function() { // $('.product-filter input[type="checkbox"][value=' + $(this).val() + ']').not(this).prop('checked', false); // }); // Shop option button listener $('.shop-option-button').on('click', function() { $('.product-shop-options').toggleClass('shop-show'); $('.product-shop-options-heading').toggleClass('shop-show'); $('html, body').addClass('overflow-hidden'); }) $('#shop-close').on('click', function() { $('.product-shop-options').removeClass('shop-show'); $('.product-shop-options-heading').removeClass('shop-show'); $('html, body').removeClass('overflow-hidden'); }) $('#gallery-close').on('click', function() { $('.product-photo-gallery').removeClass('shop-show'); $('html, body').removeClass('overflow-hidden'); }) // profile reviews trimming // profilePara variable is dummy variable to replicate data being requested from an API $('.product-filter-apply').on('click', function(){ $('.filter-checkbox-wrapper').removeClass('checkbox-expand'); $('.checkbox-button').children().toggleClass('fa-plus fa-minus'); $('html, body').animate({ scrollTop: $('.product-heading').offset().top + 100 }, 500) }) // Mobile Navigation Menu listener $('.dropdown-menu li a').on('click', function(e) { if (!$(this).parent().hasClass('dropdown-submenu') && !$(this).parent().parent().hasClass('dropdown-language') && !$(this).parent().parent().hasClass('dropdown-link') && !$(this).parent().parent().hasClass('dropdown-mobile-language') && !$(this).parent().hasClass('no-dropdown')) { e.preventDefault(); e.stopPropagation(); } $(this).next().toggleClass('dropdown-submenu-show'); if ($(this).children().hasClass('fa-chevron-down')) { $(this).children().removeClass('fa-chevron-down'); $(this).children().addClass('fa-chevron-up') } else if ($(this).children().hasClass('fa-chevron-up')) { $(this).children().removeClass('fa-chevron-up'); $(this).children().addClass('fa-chevron-down') } $(this).toggleClass('dropdownActive'); }) $dropdownToggle.on('click', function(e) { if ($(window).width() <= 769) { if ($(this).hasClass('dropdownActive')) { $(this).removeClass('dropdownActive') $(this).children().not('.fa-wrench').addClass('fa-chevron-down') $(this).children().removeClass('fa-chevron-up'); } else if (!$(this).hasClass('dropdownActive')) { $dropdownToggle.removeClass('dropdownActive'); $(this).addClass('dropdownActive'); $(this).children().not('.fa-wrench').addClass('fa-chevron-up'); $(this).children().removeClass('fa-chevron-down'); } $dropdownToggle.children('.fa-chevron-up').each(function() { if ( !$(this).parent().hasClass('dropdownActive') ) { $(this).removeClass('fa-chevron-up'); $(this).addClass('fa-chevron-down'); } }) } }) $('#home-wrapper').on('click', function() { if ( $(window).width() <= 769 ) { $('.navbar-collapse.collapse').removeClass('in'); $dropdownToggle.removeClass('dropdownActive'); $dropdownToggle.children().removeClass('fa-chevron-up'); $dropdownToggle.children().addClass('fa-chevron-down'); } }) if ( $(window).width() > 769 ) { $dropdownToggle.addClass('disabled'); } $(window).on('resize', function() { if ( $(window).width() > 769 && !$dropdownToggle.hasClass('disabled') ) { $dropdownToggle.addClass('disabled'); } else if ( $(window).width() <= 769 && $dropdownToggle.hasClass('disabled') ) { $dropdownToggle.removeClass('disabled'); } }) $('[data-toggle="validator"]').validator({ callback: { message: 'The hobbies must be between 5 and 200 characters long', callback: function (value, validator, $field) { // Get the plain text without HTML var text = tinyMCE.activeEditor.getContent({ format: 'text' }); return text.length >= 5 && text.length <= 200; } }, custom: { chkgrp: function ($el) { var name = $el.data('chkgrp') var $checkboxes = $el.closest('form').find('input[name="' + name + '"]') return $checkboxes.is(':checked') } }, errors: { chkgrp: 'Need at least one checked' } }).on('change.bs.validator', '[data-chkgrp]', function (e) { var $el = $(e.target) var name = $el.data('chkgrp') var $checkboxes = $el.closest('form').find('input[name="' + name + '"]') $checkboxes.not(':checked').trigger('input') }); // -------------------------------------------- // INITIALIZING JAVASCRIPT PACKAGES // -------------------------------------------- // 1. Slick.js // 2. TinyMCE $('.slider-carousel').on('init.slick', function(event, slick) { $('.index-page').addClass('index-loaded'); }) // Used in home page -> index.html $('.slider-carousel').slick({ prevArrow: '', nextArrow: '', dots: true, autoplay: true, autoplaySpeed: 20000, }); // Used in multiple pages -> contact-us.html, write-review.html, edit-profile.html // Not loaded on every page, do check tinymce.js is loaded into that page // not necessary if gulped into one js file if (window.tinymce && window.tinyMCE) { tinymce.init({ selector: "textarea", plugins: [ "autolink lists link" ], toolbar: "bold italic | bullist numlist | link", menubar: false, branding: false }); } $("#colors_chart").jChart(); }); // -------------------------------------------- // UTILITY FUNCTIONS // -------------------------------------------- // Changes all PRIVACY OPTIONS to the selected value from the dropdown menu function changeSelected(target, value) { target.val(value.val()); } //function to update the days based on the current values of month and year function updateNumberOfDays(){ $('#days').html(''); month = $('#months').val(); year = $('#years').val(); days = daysInMonth(month, year); for(i=1; i < days+1 ; i++){ i = leftPad(i,2); $('#days').append($(''); $('#best-heading').html(text); $('.best-carousels').addClass('hidden-carousel'); $(activeCarousel).removeClass('hidden-carousel'); for (i = 0; i <= 4; i++) { if (!(bestValues[i] === value)) { $('.refine-best').append($('