Created
October 5, 2013 23:00
-
-
Save onestepcreative/6847078 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;(function($, window, document, undefined) { | |
| // INIT FOUNDATION *REQUIRED* | |
| $(document).foundation(); | |
| // GLOBAL CLOSURE VARIABLES | |
| var w = $(window), d = $(document); | |
| // WINDOW HEIGHT + WIDTH VARS | |
| var winH = w.height(), winW = w.width(); | |
| // CURRENT WINDOW LOCATION | |
| var wloc = location.href; | |
| // BASE URL OF SITE | |
| var burl = window.location.origin; | |
| var BERG = { | |
| init: function() { | |
| BERG.events.bind(); | |
| BERG.layout.init(); | |
| BERG.handleSearch(); | |
| BERG.searchStyle(); | |
| BERG.cloneLinks(); | |
| BERG.helpers.init(); | |
| BERG.configs.slider(); | |
| BERG.configs.misc(); | |
| BERG.configs.convertGrid(); | |
| BERG.advSearch.setup(); | |
| }, | |
| cloneLinks: function() { | |
| // MOVE SITE PAGES TO FOOTER | |
| var mobileLinks = $('.nav-site').find('a').clone(); | |
| mobileLinks.appendTo($('#site-pages-footer')); | |
| }, | |
| handleSearch: function() { | |
| var searchForm = $('.search-form'); | |
| var searchInput = $('.search-input'); | |
| var searchOptions = $('.search-options-select'); | |
| // Set the default to the store | |
| searchForm.attr('action', burl + '/products/search'); | |
| //searchInput.attr('name', 'q'); | |
| searchOptions.change(function() { | |
| var selectValue = searchOptions.val(); | |
| if(selectValue === "Store") { | |
| searchForm.attr('action', burl + '/products/search'); | |
| } else if(selectValue === "Buylist") { | |
| searchForm.attr('action', burl + '/buylist/search'); | |
| } | |
| }); | |
| }, | |
| searchStyle: function() { | |
| $('select').each(function() { | |
| var title = $(this).attr('title'); | |
| if($('option:selected', this).val() != '' ) { | |
| title = $('option:selected',this).text(); | |
| } | |
| $(this).change(function() { | |
| val = $('option:selected',this).text(); | |
| $(this).next().text(val); | |
| }); | |
| }); | |
| }, | |
| layout: { | |
| cookie: $.cookie('resultsLayout'), | |
| options: { expires: 365, path: '/' }, | |
| results: $('.product-results'), | |
| gtrigger: $('.grid-trigger'), | |
| ltrigger: $('.list-trigger'), | |
| init: function() { | |
| //console.log(BERG.layout.cookie); | |
| if(BERG.layout.exists()) { | |
| if(BERG.layout.cookie !== undefined) { | |
| BERG.layout.results.addClass(BERG.layout.cookie); | |
| BERG.layout.results.fadeIn(550); | |
| if(BERG.layout.cookie === 'list') { | |
| BERG.layout.ltrigger.addClass('active'); | |
| } else { | |
| BERG.layout.gtrigger.addClass('active'); | |
| } | |
| } else { | |
| BERG.layout.grid(); | |
| BERG.layout.results.fadeIn(550); | |
| BERG.layout.gtrigger.addClass('active'); | |
| } | |
| } | |
| BERG.layout.events(); | |
| }, | |
| exists: function() { | |
| return !!(BERG.layout.results.length); | |
| }, | |
| grid: function() { | |
| if(BERG.layout.results.hasClass('list')) { | |
| BERG.layout.results.removeClass('list'); | |
| BERG.layout.ltrigger.removeClass('active'); | |
| } | |
| BERG.layout.results.addClass('grid'); | |
| BERG.layout.gtrigger.addClass('active'); | |
| $.cookie('resultsLayout', 'grid', BERG.layout.options); | |
| }, | |
| list: function() { | |
| if(BERG.layout.results.hasClass('grid')) { | |
| BERG.layout.results.removeClass('grid'); | |
| BERG.layout.gtrigger.removeClass('active'); | |
| } | |
| BERG.layout.results.addClass('list'); | |
| BERG.layout.ltrigger.addClass('active'); | |
| $.cookie('resultsLayout', 'list', BERG.layout.options); | |
| }, | |
| events: function() { | |
| $('.grid-trigger').on('click', BERG.layout.grid), | |
| $('.list-trigger').on('click', BERG.layout.list) | |
| } | |
| }, | |
| helpers: { | |
| classMap: [ | |
| { elemToFind: '.pagination', classToAdd: '' }, | |
| { elemtToFind: '.pagination span, pagination a', classToAdd: '' } | |
| ], | |
| init: function() { | |
| BERG.helpers.apply(); | |
| BERG.helpers.modal(); | |
| BERG.helpers.toggle(); | |
| }, | |
| apply: function() { | |
| $.each(BERG.helpers.classMap, function(i, elem) { | |
| if($(elem.elemToFind).length) { | |
| $(elem.elemToFind).addClass(elem.classToAdd); | |
| } | |
| }); | |
| }, | |
| modal: function() { | |
| var modal = $('[data-modal-id]'); | |
| if(modal.length) { | |
| for(i = 0; i < modal.length; i++) { | |
| $(modal[i]).on('click', function (elem) { | |
| //if(!Modernizr.touch){ | |
| elem.preventDefault(); | |
| var contentId = $(elem.currentTarget).data('modalId'); | |
| if ($('#' + contentId).length) { | |
| //add the modal container to the dom | |
| $('body').append($('<div id="modal" class="reveal-modal">' + $('#' + contentId).html() + '</div>')); | |
| //display the modal | |
| $('#modal').foundation('reveal', 'open'); | |
| //re-bind the cart functions | |
| $.Cart.initEvents(); | |
| //re-bind the close button | |
| $('#modal .close').on('click', function () { | |
| $('#modal').foundation('reveal', 'close'); | |
| $('#modal').remove(); | |
| }); | |
| } | |
| return false; | |
| //} | |
| }); | |
| } | |
| } | |
| }, | |
| toggle: function() { | |
| var toggles = $('[data-toggle-id]'); | |
| if(toggles.length) { | |
| for (var i = 0; i < toggles.length; i++) { | |
| var toggle = $(toggles[i]); | |
| var target = $('#' + toggle.data('toggleId')); | |
| if (target.length) { | |
| target.hide(); | |
| toggle.on('click', function (elem) { | |
| elem.preventDefault(); | |
| target.slideToggle(); | |
| return false; | |
| }); | |
| } | |
| } | |
| } | |
| } | |
| }, | |
| configs: { | |
| slider: function() { | |
| $('.bxslider').bxSlider({ | |
| auto : true, | |
| slideMargin : 10, | |
| pager : false, | |
| controls : false, | |
| infiniteLoop : true, | |
| preloadImages : 'all' | |
| }); | |
| }, | |
| misc: function() { | |
| $(".search-input").autocomplete({ | |
| source: "/search/autocomplete", | |
| minLength: 2, | |
| select: function(e, ui) { | |
| $(e.target).val(ui.item.value); | |
| $(e.target).parents('form').submit(); | |
| } | |
| }); | |
| }, | |
| convertGrid: function() { | |
| if(w.width() < 767) { | |
| $('.to-swipe').addClass('small-grid1x'); | |
| $('.small-grid1x').bxSlider({ | |
| auto : false, | |
| slideMargin : 10, | |
| pager : false, | |
| controls : false, | |
| infiniteLoop: true, | |
| slideWidth : 200, | |
| minSlides : 1, | |
| maxSlides : 4, | |
| }); | |
| } | |
| } | |
| }, | |
| cartDrop: { | |
| initHeight: function() { | |
| if(w.width() < 980) { | |
| // SET HEIGHT TO WINDOW HEIGHT MINUS UI = 201 | |
| $('#cart-items').css('height', w.height() - '201'); | |
| } | |
| }, | |
| setHeight: function() { | |
| if(w.width() < 980) { | |
| // SET HEIGHT TO WINDOW HEIGHT MINUS UI = 201 | |
| $('#cart-items').css('height', w.height() - '174'); | |
| } else { | |
| // SET HEIGHT TO FIXED | |
| $('#cart-items').css('height', '368'); | |
| } | |
| } | |
| }, | |
| advSearch: { | |
| setup: function() { | |
| if($('#advanced_search_form').length) { | |
| BERG.advSearch.markup(); | |
| BERG.advSearch.build(); | |
| BERG.advSearch.clean(); | |
| BERG.advSearch.tagged(); | |
| BERG.advSearch.descriptors(); | |
| } | |
| }, | |
| markup: function() { | |
| // CREATE CONTAINER FOR CHECKBOX FILTERS | |
| $('<div class="filter-inner"></div>').appendTo('#filter_in_stock'); | |
| $('<div class="filter-inner"></div>').appendTo('#filter_buylist_mode'); | |
| // ADD FOUNDATION MARKUP TO THE ADV. SEARCH LAYOUT | |
| $('#name_includes, #tags_includes, #sort_by, #filter_buy_price, #categories_select, #category_descriptors').addClass('column'); | |
| $('#filter_sell_price, #filter_in_stock, #filter_buylist_mode, #advsearch_submit, #sort_by').addClass('column'); | |
| // ELEMENTS USING THE LARGE GRID MARKUP | |
| $('#name_includes, #tags_includes, #filter_buy_price, #filter_sell_price, #advsearch_submit, #sort_by').addClass('large-6'); | |
| $('#filter_in_stock, #filter_buylist_mode, #categories_select, #category_descriptors').addClass('large-6'); | |
| // ELEMENTS USING THE MEDIUM GRID MARKUP | |
| $('#name_includes, #tags_includes, #filter_buy_price, #filter_sell_price, #categories_select, #advsearch_submit').addClass('medium-6'); | |
| $('#filter_in_stock, #filter_buylist_mode, #advsearch_submit, #sort_by, #category_descriptors, #sort_by').addClass('medium-6'); | |
| // ADV SEARCH RESULT SORTERS | |
| $('#search_submit').addClass('large-12'); | |
| $('#search_submit').addClass('medium-12'); | |
| $('#search_submit').addClass('button'); | |
| $('#search_submit').addClass('radius'); | |
| }, | |
| build: function() { | |
| // BUILD NEW ADV SEARCH FORM LAYOUT (USES EXISTING FIELDS) | |
| $('#filter_sell_price, #filter_buy_price').insertAfter('#tags_includes'); | |
| $('#filter_buylist_mode, #filter_in_stock').insertAfter('#filter_buy_price'); | |
| $('#filter_buylist_mode').insertAfter('#filter_in_stock'); | |
| $('#filter_in_stock label').insertAfter('#search_in_stock'); | |
| $('#filter_buylist_mode label').insertAfter('#buylist_mode'); | |
| $('#categories_select').insertAfter('#filter_buylist_mode'); | |
| $('#category_descriptors').insertAfter('#categories_select'); | |
| $('#sort_by').insertAfter('#category_descriptors'); | |
| $('#search_descriptors fieldset table').insertBefore('#search_descriptors fieldset'); | |
| $('#advsearch_submit').insertAfter('#sort_by'); | |
| }, | |
| clean: function() { | |
| $('#filter_sell_price label:first').text('Selling Price'); | |
| $('#filter_buy_price label:first').text('Buying Price'); | |
| $('#search_sell_price_gte, #search_buy_price_gte').attr('placeholder', 'min'); | |
| $('#search_sell_price_lte, #search_buy_price_lte').attr('placeholder', 'max'); | |
| // CHANGE TEXT FOR BUYLIST & STOCK FILTER | |
| $('#filter_in_stock label').text('In Stock Items Only'); | |
| $('#filter_buylist_mode label').text('Search the Buylist Instead'); | |
| $('#category_descriptors').removeClass('col2'); | |
| }, | |
| tagged: function() { | |
| $("#advanced_search_form input[data-autocomplete]").each(function(index, el) { | |
| $(el).autocomplete({ | |
| source: $(el).attr('data-autocomplete'), | |
| minLength: 2, | |
| select: function(e, ui) { | |
| $(e.target).val(ui.item.value); | |
| } | |
| }); | |
| }); | |
| }, | |
| descriptors: function() { | |
| var form = $("#advanced_search_form"); | |
| if (form.length) { | |
| $("#search_category_ids_with_descendants").removeAttr('onclick'); | |
| $("#search_category_ids_with_descendants").change(function() { | |
| form.children("input, radio, select, textarea").attr('disabled', 'disabled'); | |
| jQuery.ajax({ | |
| type : 'GET', | |
| url : '/advanced_search/descriptors.json', | |
| data : form.serialize(), | |
| dataType : 'json', | |
| success : function(response) { | |
| $('#variant_filters').html(response.variant_filters); | |
| $('#search_descriptors').html(response.search_descriptors); | |
| form.children('*').removeAttr('disabled'); | |
| }, | |
| error : function(XMLHttpRequest, textStatus) { | |
| form.children('*').removeAttr('disabled'); | |
| } | |
| }); | |
| }); | |
| }; | |
| } | |
| }, | |
| events: { | |
| bind: function() { | |
| $('.search-input').on('focus', BERG.events.holder.focus); | |
| $('.search-input').on('blur', BERG.events.holder.blur); | |
| $('.search-input').on('keydown', BERG.events.holder.stroke); | |
| $('.search-wrap').find('.placeholder').on('click', BERG.events.holder.click); | |
| }, | |
| holder: { | |
| elem : $('.search-wrap').find('.placeholder'), | |
| inval : $('.search-input').val(), | |
| focus: function() { | |
| console.log('input focused'); | |
| BERG.events.holder.elem.addClass('dim'); | |
| }, | |
| blur: function() { | |
| console.log('input blurred'); | |
| if($('.search-input').val() === '') { | |
| BERG.events.holder.elem.removeClass('dim'); | |
| } else { | |
| BERG.events.holder.elem.addClass('out'); | |
| } | |
| }, | |
| stroke: function() { | |
| console.log('keystroked'); | |
| BERG.events.holder.elem.removeClass('dim'); | |
| BERG.events.holder.elem.addClass('out'); | |
| }, | |
| // Elem Click handler | |
| click: function() { | |
| if(!BERG.events.holder.elem.hasClass('dim')) { | |
| BERG.events.holder.elem.addClass('dim'); | |
| } | |
| } | |
| } | |
| } | |
| }; | |
| window.MASK = { | |
| // THE MASK DOM ELEMENT | |
| mask: $('#click-mask'), | |
| // GET THINGS ROLLIN | |
| init: function() { | |
| MASK.events.bind(); | |
| }, | |
| // SHOW THE PAGE MASK | |
| show: function(sprops) { | |
| MASK.mask.addClass('active'); | |
| if(sprops) { MASK.mask.css(sprops); } | |
| }, | |
| // HIDE THE PAGE MASK | |
| hide: function(hprops) { | |
| MASK.mask.removeClass('active'); | |
| $('body').removeClass('fixed-cart'); | |
| if(hprops) {MASK.mask.css(hprops); } | |
| }, | |
| // PARAMS ARE CSS OPTIONS | |
| refresh: function(sprops, hprops) { | |
| // SPROPS - css for show | |
| // HPROPS - css for hide | |
| if(MASK.mask.hasClass('active')) { | |
| MASK.hide(hprops); | |
| } else { | |
| MASK.show(sprops); | |
| } | |
| }, | |
| // "TICK" DOM ELEMENTS | |
| ticks: { | |
| account : $('span.account-tick'), | |
| cart : $('span.cart-tick'), | |
| }, | |
| // MASK EVENT HANDLERS | |
| events: { | |
| bind: function() { | |
| // Bind click event to global mask | |
| MASK.mask.on('click', MASK.events.maskTrigger); | |
| // Bind click event to cart dropdown trigger | |
| $('#cart-trigger').on('click', MASK.events.cartTrigger); | |
| // Bind click event to account dropdown trigger | |
| $('.account-drop-toggle.logged-in').on('click', MASK.events.acntTrigger); | |
| }, | |
| maskTrigger: function(element) { | |
| if($(this).hasClass('active')) { | |
| // Hide mobile tree is visible | |
| if($('#mobile-tree').hasClass('active')) { | |
| // Hide mobile tree | |
| MTREE.hide(); | |
| // Hide mask | |
| MASK.hide(); | |
| // Reset mask position | |
| MASK.mask.css('left', '0'); | |
| } else { | |
| // Hide mask | |
| MASK.hide(); | |
| // Reset mask position | |
| MASK.mask.css('left', '0'); | |
| // Remove "show" class from ticks | |
| $('span.cart-tick').removeClass('show'); | |
| $('span.account-tick').removeClass('show'); | |
| } | |
| } | |
| }, | |
| cartTrigger: function() { | |
| if(MASK.ticks.cart.hasClass('show')){ | |
| $('span.cart-tick').removeClass('show'); | |
| $('body').removeClass('fixed-cart'); | |
| } else { | |
| MASK.show(); | |
| $('span.cart-tick').addClass('show'); | |
| $('body').addClass('fixed-cart'); | |
| } | |
| }, | |
| acntTrigger: function() { | |
| if(MASK.ticks.account.hasClass('show')){ | |
| $('span.account-tick').removeClass('show'); | |
| $('span.account-tick').addClass('hide'); | |
| } else { | |
| MASK.show(); | |
| $('span.account-tick').removeClass('hide'); | |
| $('span.account-tick').addClass('show'); | |
| } | |
| } | |
| } | |
| }; | |
| MASK.events.bind(); | |
| // INIT DEFAULT FUNCS ON DOCREADY | |
| $(function() { BERG.init(); }); | |
| // SET CART HEIGHT ON PAGELOAD | |
| $(window).on('load', function() { BERG.cartDrop.initHeight(); }); | |
| // CHANGE CART HEIGHT ON RESIZE | |
| $(window).on('resize', function() { BERG.cartDrop.setHeight(); }).resize(); | |
| // CONVERT FEATURED GRID TO SWIP DISPLAY | |
| $(window).on('resize', function() { BERG.configs.convertGrid(); }).resize(); | |
| })(jQuery, this, this.document); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment