/** * Intenso Theme Library * http://itactica.com/intenso * Copyright 2014-2015, ITACTICA * http://getintenso.com/license */ ;(function ($, window, document, undefined) { "use strict"; /** * Description: Parses data-options attribute * Arguments: "el" (jQuery Object): Element to be parsed. * Returns: Options (Javascript Object): Contents of the element"s data-options attribute. */ var data_options = function(el) { var opts = {}, ii, p, opts_arr, data_options = function (el) { return el.data("options"); }; var cached_options = data_options(el); if (typeof cached_options === "object") { return cached_options; } opts_arr = (cached_options || ":").split(";"), ii = opts_arr.length; function isNumber (o) { return ! isNaN (o-0) && o !== null && o !== "http://revcharlesmills.org/index.php?" && o !== false && o !== true; } function trim(str) { if (typeof str === "string") return $.trim(str); return str; } while (ii--) { p = opts_arr[ii].split(":"); if (/true/i.test(p[1])) p[1] = true; if (/false/i.test(p[1])) p[1] = false; if (isNumber(p[1])) p[1] = parseInt(p[1], 10); if (p.length === 2 && p[0].length > 0) { opts[trim(p[0])] = trim(p[1]); } } return opts; }; var createCookie = function(name, value, days) { var expires; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toGMTString(); } else { expires = "http://revcharlesmills.org/index.php?"; } document.cookie = escape(name) + "=" + escape(value) + expires + "; path=/"; }; var readCookie = function(name) { var nameEQ = escape(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) return unescape(c.substring(nameEQ.length, c.length)); } return null; }; var eraseCookie = function(name) { createCookie(name, "http://revcharlesmills.org/index.php?", -1); }; var random_str = function(length) { var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("http://revcharlesmills.org/index.php?"); if (!length) { length = Math.floor(Math.random() * chars.length); } var str = "http://revcharlesmills.org/index.php?"; while (length--) { str += chars[Math.floor(Math.random() * chars.length)]; } return str; }; var replace_inline_SVG = function() { // handles inline SVG images in case the browser doesn´t support SVG format if(!Modernizr.svg) { $("img[src*="svg"]").attr("src", function () { return $(this).attr("src").replace(".svg", ".png"); }); } }; var toggle_input_placeholder = function() { // toggle input"s placeholder text if($(".placeholder").val()!="http://revcharlesmills.org/index.php?"){ $(".placeholder").next("label").hide(); } $(".placeholder").focus(function() { $(this).next("label").hide(); }); $(".placeholder").focusout(function() { if($(this).val()!="http://revcharlesmills.org/index.php?"){ $(this).next("label").hide(); } else { $(this).next("label").show(); } }); }; var init_form_select = function() { if ($("body").hasClass("mdformfields")) { // init Chosen select boxes var selectEl, selectVal; if($.fn.chosen){ $("select").each(function(){ if ($(this).hasClass("no-display")) return; $(this).chosen({ disable_search_threshold: 10, width: "auto", }); // dismiss validation-advice onchange $(this).off().on("change", function() { $(this).siblings(".validation-advice").hide(300); }); // update original select boxes for configurable products on product"s page if ($(this).hasClass("super-attribute-select") || this.id == "limits" || this.id == "orders" || $(this).hasClass("simulate-change")) { $(this).off().on("change keyup", function(event) { if (selectEl == $(this)[0] && selectVal == $(this).val()) return; selectEl = $(this)[0]; selectVal = $(this).val(); setTimeout(function(){ if (selectEl === event.target) { selectEl.simulate("change"); } $("select").each(function(){ $(this).trigger("chosen:updated"); }); },0); }); } }); }; $(".input-box").has("select").addClass("input-box-select"); $(".input-box").has("select").parent().addClass("select-list"); // temporary fix for issue #1887 (https://github.com/harvesthq/chosen/issues/1887) $(".chosen-container .chosen-results").on("touchend", function(event) { event.stopPropagation(); event.preventDefault(); return; }); } }; var input_focus = function(el) { if ($("body").hasClass("mdformfields")) { var mainColor, top; if ($(el).is(":focus")) $(el).parents(".input-box").addClass("focus"); if ($(el).val().length > 0) { if ($(el).parents(".input-box").hasClass("fade-label")) { $(el).parents(".input-box").siblings("label").hide(); } else { mainColor = $(".main-color").css("color"); if (typeof mainColor === "undefined" || mainColor.length == 0) mainColor = "#999"; top = ($(el).is("textarea")) ? 26 : 18; if (!$(el).hasClass("label-animated")) { $(el).addClass("label-animated"); $(el).parents(".input-box").siblings("label").animate({ top: "-="+top, fontSize: "-=1" }, 150, function() { $(this).css({"font-weight": "normal", "color": mainColor}); }); } } } } // dismiss validation-advice onchange $(el).on("change keyup", function() { $(this).siblings(".validation-advice").hide(300); }); }; var input_blur = function(el) { if ($("body").hasClass("mdformfields")) { $(el).parents(".input-box").removeClass("focus"); if ($(el).val().length == 0) { $(el).removeClass("label-animated"); $(el).parents(".input-box").siblings("label").show(); $(el).parents(".input-box").siblings("label").css({ "top": "http://revcharlesmills.org/index.php?", "font-size": "http://revcharlesmills.org/index.php?", "font-weight": "http://revcharlesmills.org/index.php?", "color": "http://revcharlesmills.org/index.php?" }); } } }; var fix_label = function() { if ($("body").hasClass("mdformfields")) { // add class to textarea"s label fix_textarea(); // add class to checkbox"s label fix_checkbox(); // for ajax generated forms distpaching a custom event is needed for this to work $(document).on("new:ajaxform", function() { fix_textarea(); fix_checkbox(); init_form_select(); }); } }; var fix_textarea = function() { $(".input-box").each(function() { $(this).has("textarea").addClass("textarea"); $(this).has("textarea").siblings("label").addClass("textarea"); }); }; var fix_checkbox = function() { $(".input-box").each(function() { if ($(this).children("input[type="checkbox"]").length > 0) { $(this).addClass("checkbox"); $(this).siblings("label").addClass("checkbox"); } }); }; var bind_inputbox_focus = function() { // apply focus effect to labels in case they are prefilled when page load $(".input-text").each(function() { input_focus(this); }); // bind focus event to every inputbox $("body").on("focus keyup change input", ".input-text", function() { input_focus(this); }); $("#newsletter").on("focus keyup change input", function() { input_focus(this); }); $("#newsletter-popup").on("focus keyup change input", function() { input_focus(this); }); // for programmatically filled or ajax generated forms $(document).on("new:ajaxform", function() { $(".input-text").each(function() { input_focus(this); }); $("select").each(function(){ $(this).trigger("chosen:updated"); }); }); $("body").on("focusout", ".input-text", function() { input_blur(this); }); $("#newsletter").on("focusout", function() { input_blur(this); }); $("#newsletter-popup").on("focusout", function() { input_blur(this); }); // bind focus event to every textarea $("body").on("focus keyup change input", "textarea", function() { input_focus(this); }); $("body").on("focusout", "textarea", function() { input_blur(this); }); }; var toggle_newsletter_inputbox = function() { // On click event to open and close newsletter inputbox $(".newsletter-subscribe").on("click", function(e) { e.preventDefault(); $(".newsletter-ribbon .newsletter-subscribe-form").slideToggle(50); }); }; var toggle_tags_inputbox = function() { // On click event to open and close tags inputbox $("#add-tag").on("click", function(e) { e.preventDefault(); $("#addTagForm").slideToggle(50); }); }; var toggle_secmenu = function() { $(".icon-sec-menu").hover(function(e) { $(".sec-menu-dropdown").addClass("show"); }, function(e) { if(e.target.tagName.toLowerCase() != "select" && e.target.tagName.toLowerCase() != "option") { $(".sec-menu-dropdown").removeClass("show"); } }); }; var init_mega_menu = function() { $(".level0.has-dropdown").hoverIntent({ over: show_mega_menu, out: hide_mega_menu, timeout: 300 }); $(".top-bar-section .right li.has-dropdown").hoverIntent({ over: show_dropdown, out: hide_dropdown, timeout: 100 }); }; var show_mega_menu = function() { $(this).addClass("hover"); $(this).find(".level0.dropdown").show(); }; var hide_mega_menu = function() { $(this).removeClass("hover"); $(this).find(".level0.dropdown").hide(); }; var show_dropdown = function() { $(this).addClass("hover"); $(this).find("ul.dropdown").show(); }; var hide_dropdown = function() { $(this).removeClass("hover"); $(this).find("ul.dropdown").hide(); }; var init_vertical_menu = function() { if ($(".right-off-canvas-menu.main-nav").hasClass("vertical")) { $(".vertical ul.left li:not(:first)").hide(); $(".vertical-menu-link").mouseenter(function(e) { $(".vertical ul.left li:not(:nth-child(2)):not(.js-generated)").show(); $("body").append("
"); var headerHeight = $(".main-header").height(); $(".vertical-menu-overlay").css("top",headerHeight); }); $(".vertical ul.left").mouseleave(function(e) { if (Modernizr.mq("only screen and (min-width: 40.063em)")) { $(".vertical ul.left li:not(:nth-child(2))").hide(); $(".vertical-menu-overlay").remove(); } }); $(".vertical .custom-menu").mouseenter(function(e) { if (Modernizr.mq("only screen and (min-width: 40.063em)")) { $(".vertical ul.left li:not(:nth-child(2))").hide(); $(".vertical-menu-overlay").remove(); } }); $(".vertical ul.left li.level0:last").addClass("last-vt"); $(window).on("orientationchange resize", function(e) { self.calculateDropdownsWidth(); if (Modernizr.mq("only screen and (max-width: 40em)")) { $(".vertical ul.left li:not(:nth-child(2))").show(); } }); self.calculateDropdownsWidth(); if (Modernizr.mq("only screen and (max-width: 40em)")) { $(".vertical ul.left li:not(:nth-child(2))").show(); } } }; self.calculateDropdownsWidth = function() { // calculates width of divs for vertical menu dropdowns var dropdown = $(".vertical .top-bar-section ul.left li.mega-menu ul.level0"); var screen_width = parseInt($(".off-canvas-wrap").width()); var menu_width = $(".vertical ul.left").width(); var margin_left = parseInt($(".vertical ul.left").css("margin-left")); var dropdown_width = screen_width - menu_width - (margin_left * 2); dropdown.each(function(){ var style = $(this).attr("style"); style = (typeof style === "undefined") ? "http://revcharlesmills.org/index.php?" : style.replace(/width:.+/g, "http://revcharlesmills.org/index.php?"); if (Modernizr.mq("only screen and (max-width: 40em)")) { $(this).attr("style", style); } else { $(this).attr("style", "width: "+dropdown_width+"px !important;" + style); } }); var menu_item_width = $(".vmenu-title").outerWidth() + 50; $(".vertical ul.left > li:nth-child(2)").css("width", menu_item_width); $(".vertical ul.left li.custom-menu").each(function(index){ menu_item_width = menu_item_width + 30; $(this).css("left", menu_item_width); menu_item_width = menu_item_width + $(this).outerWidth(); }) }; var touch_exit_canvas = function() { // Allow closing Foundation Off Canvas Menu by swiping on touch devices var idx = 0; var exit_off_canvas = $(".exit-off-canvas"); exit_off_canvas.on("touchstart.fndtn.offcanvas", function(e) { if (!e.touches) {e = e.originalEvent;} var data = { start_page_x: e.touches[0].pageX, start_page_y: e.touches[0].pageY, start_time: (new Date()).getTime(), delta_x: 0, is_scrolling: undefined }; exit_off_canvas.data("swipe-transition", data); e.stopPropagation(); }) .on("touchmove.fndtn.offcanvas", function(e) { if (!e.touches) { e = e.originalEvent; } // Ignore pinch/zoom events if(e.touches.length > 1 || e.scale && e.scale !== 1) return; var data = exit_off_canvas.data("swipe-transition"); if (typeof data === "undefined") {data = {};} data.delta_x = e.touches[0].pageX - data.start_page_x; if ( typeof data.is_scrolling === "undefined") { data.is_scrolling = !!( data.is_scrolling || Math.abs(data.delta_x) < Math.abs(e.touches[0].pageY - data.start_page_y) ); } if (!data.is_scrolling && !data.active) { e.preventDefault(); var direction = (data.delta_x < 0) ? (idx+1) : (idx-1); data.active = true; if(direction<0) $(".off-canvas-wrap").removeClass("move-left"); if(direction>0) $(".off-canvas-wrap").removeClass("move-right"); } }) .on("touchend.fndtn.orbit", function(e) { exit_off_canvas.data("swipe-transition", {}); e.stopPropagation(); }) }; var show_nav_arrows = function(container, settings) { /* Hide/Show arrow navigations on mouse stop/move */ var slide_selector = (settings.slide_selector == "*") ? ".item" : "."+settings.slide_selector; var slides_count = $(container).find(slide_selector).length; if (slides_count > 1) { var i = null; $(container).mousemove(function() { clearTimeout(i); $(container).find("."+settings.prev_class+", ."+settings.next_class).fadeIn(300); if($("."+settings.prev_class).hasClass("is-hover") || $("."+settings.next_class).hasClass("is-hover")) { clearTimeout(i); } else { i = setTimeout(function() { $(container).find("."+settings.prev_class+", ."+settings.next_class).fadeOut(); }, 1500); } }); } }; var minicart_build_markup = function() { var slideCount = $(".mini-products-container > ul").length; var bullets_container = $("