/* global jQuery */ /* global skrollr */ /* global Modernizr */ /* ------------------------------------------- * * 3Clicks javascript code is splitted into 2 sections: * 1) core functions ("G1 Core" section) - you shouldn't modify them * 2) theme related functions ("G1 Main" section) * * If you want to start modyfing our code, you should * look at "G1 Main" section. Some functions are invoked * when document is ready and some need to be launched * later, when all window elements are loaded. * * If you want to add your custom functions, please * add theme using our "modifications.js" script. * It's located in 3clicks-child-theme folder. * --------------------------------------------- */ /* =================== */ /* G1 core */ /* =================== */ /*jshint unused:false, undef:false */ /* =================================== */ /* G1 JavaScript additional functions */ /* =================================== */ // ====== global functions extending language capabilities ====== // /** * is_string */ if (typeof is_string !== 'function') { var is_string = function(value) { "use strict"; return typeof value === 'string'; }; } /** * is_array */ if (typeof is_array !== 'function') { var is_array = function(value) { "use strict"; return value && typeof value === 'object' && typeof value.length === 'number' && typeof value.splice === 'function' && !(value.propertyIsEnumerable('length')); }; } /** * create_cookie */ if (typeof create_cookie !== 'function') { var create_cookie = function(name,value,days) { "use strict"; var expires; if (days) { var date = new Date(); date.setTime(date.getTime() + (days*24*60*60*1000)); expires = '; expires=' + date.toGMTString(); } else { expires = ''; } document.cookie = name + '=' + value + expires + '; path=/'; }; } /** * read_cookie */ if (typeof read_cookie !== 'function') { var read_cookie = function(name) { "use strict"; var nameEQ = name + '='; var ca = document.cookie.split(';'); for(var i = 0; i < ca.length; i += 1) { var c = ca[i]; while (c.charAt(0) === ' ') { c = c.substring(1,c.length); } if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length,c.length); } } return null; }; } /** * rgb2hex */ if (typeof rgb2hex !== 'function') { var rgb2hex = function (rgb) { "use strict"; if ( rgb.search("rgb") === -1 ) { return rgb; } else { rgb = rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))?\)$/); var hex = function (x) { return ("0" + parseInt(x, 10).toString(16)).slice(-2); }; return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); } }; } /** * strpad */ if (typeof strpad !== 'function') { var strpad = function(input, padLength, padString, padType) { "use strict"; padString = typeof padString !== 'undefined' ? padString : ' '; padType = typeof padType !== 'undefined' ? padType : 'right'; if (padLength > input.length) { for (var i = 0; i < (padLength - input.length); i += 1) { switch (padType) { case 'left': input = padString + input; break; default: input = input + padString; } } } return input; }; } /* ======== */ /* G1 core */ /* ======== */ /* ===== G1 namespace ===== */ var G1 = { isIOS: navigator.userAgent.match(/(iPad|iPhone|iPod)/g) !== null, isIE: navigator.userAgent.match(/msie/ig) !== null }; (function() { "use strict"; /* ===== G1 init ===== */ G1.init = function() { var i, callbacks = []; callbacks = G1.getFilter().apply('g1_init', callbacks, null); for (i = 0; i < callbacks.length; i += 1) { var context = callbacks[i].context; var method = callbacks[i].method; if (typeof context[method] === 'function') { context[method](); } } }; G1.hooks = {}; /* ===== G1 Filter hook ===== */ G1.hooks.filter = function () { // private scope var that = {}; var filters = {}; var add = function(name, callback, priority) { if (typeof filters[name] === 'undefined') { filters[name] = []; } if (typeof filters[name][priority] === 'undefined') { filters[name][priority] = []; } filters[name][priority].push(callback); }; var apply = function(name, value, params) { if (typeof filters[name] !== 'undefined') { for (var priority in filters[name]) { if (filters[name].hasOwnProperty(priority)) { for (var index in filters[name][priority]) { if (filters[name][priority].hasOwnProperty(index)) { var filter = filters[name][priority][index]; var context; var funcName; if (is_string(filter)) { context = window; funcName = filter; } else if (is_array(filter)) { context = filter[0]; funcName = filter[1]; } else { throw { name: 'TypeError', message: 'callback needs to be a string of an object' }; } value = context[funcName](value, params); } } } } } return value; }; var remove = function() { // not implemented }; var has = function() { // not implemented }; // public scope that.add = add; that.apply = apply; that.remove = remove; that.has = has; return that; }; G1.getFilter = function() { if (typeof this.filter === 'undefined') { this.filter = this.hooks.filter(); } return this.filter; }; })(); /* ===================== */ /* G1 core public api */ /* ===================== */ /** * @param name filter name * @param callback context and function which will be used for filtering * @param priority order in which the functions associated with a particular filter are executed */ var g1_add_filter = function(name, callback, priority) { "use strict"; G1.getFilter().add(name, callback, priority); }; /** * @param name filter name * @param value filtered value * @param params object holds all parameters passed to the filter */ var g1_apply_filters = function(name, value, params) { "use strict"; return G1.getFilter().apply(name, value, params); }; /* =========== */ /* G1 jQuery */ /* =========== */ (function() { "use strict"; G1.jQuery = {}; /* =================================== * g1BoxHeight * package: G1 jQuery * * Returns computed box height * (content + borders + margins + paddings) * =================================== */ (function($) { $.fn.g1BoxHeight = function () { var $this = $(this); var height = parseInt($this.css('margin-top'), 10) + parseInt($this.css('padding-top'), 10) + parseInt($this.css('border-top-width'), 10) + parseInt($this.height(), 10) + parseInt($this.css('border-bottom-width'), 10) + parseInt($this.css('padding-bottom'), 10) + parseInt($this.css('margin-bottom'), 10); return height; }; })(jQuery); /* =================================== * g1Toggle * package: G1 jQuery * * Adds/removes class on element * =================================== */ G1.jQuery.g1Toggle = {}; G1.jQuery.g1Toggle.config = { 'target_active_class_name':'g1-toggle-on', 'target_class_name':'g1-toggle-ui', 'target_attr_name': 'data-g1-toggle-target', 'action_attr_name': 'data-g1-toggle-action', 'default_action': 'toggle' }; (function($) { // Toggle class definition var g1Toggle = function(element, options) { // private var that = {}; var $element = $(element); var activeClassName = options.active_class_name; var className = options.class_name; var init = function() { $element.addClass(className); }; var triggerEvent = function(name, params) { $element.trigger(name, params); }; var show = function () { $element.addClass(activeClassName); triggerEvent('g1_toggle.after_show'); }; var hide = function () { $element.removeClass(activeClassName); triggerEvent('g1_toggle.after_hide'); }; var toggle = function() { if ($element.hasClass(activeClassName)) { hide(); } else { show(); } }; // public that.show = show; that.hide = hide; that.toggle = toggle; init(); return that; }; // Toggle plugin definition $.fn.g1Toggle = function (action, options) { return this.each(function () { var $this = $(this); var instance = $this.data('g1_toggle'); action = typeof action === 'string' ? action : G1.jQuery.g1Toggle.config.default_action; options = typeof options === 'object' ? options : {}; options = $.extend({ 'active_class_name': G1.jQuery.g1Toggle.config.target_active_class_name, 'class_name': G1.jQuery.g1Toggle.config.target_class_name }, options); // create instance if (!instance) { instance = g1Toggle(this, options); $this.data('g1_toggle', instance); } // invoke the method instance[action](); return this; }); }; })(jQuery); /* ================================ * g1Tabs * package: G1 jQuery * * Handles tabbed content * ================================ */ G1.jQuery.g1Tabs = {}; G1.jQuery.g1Tabs.defaults = { event: 'click', cssSelectorTitle: '.g1-tab-title', cssSelectorContent: '.g1-tab-content' }; (function($) { var g1Tabs = function() { // private var that = {}; var init = function( options ) { return this.each(function(){ options = options || {}; var $this = $(this); var data = $this.data('g1Tabs'); /* If the plugin hasn't been initialized yet */ if ( !data ) { /* support metadata plugin (v1.0 and v2.0) */ options = $.extend({}, $.fn.g1Tabs.defaults, options, $.metadata ? $this.metadata() : $.meta ? $this.data() : {}); $this.data('g1Tabs', { 'target' : $this, 'options' : options }); var $navigation = $(''); var $viewport = $('
'); var index = 0; var tabsContent = $this.find(options.cssSelectorContent); $this.find( options.cssSelectorTitle ).each(function(){ var $div = $('
' ); var $tabContent = $(this).next( options.cssSelectorContent ); if ( $tabContent.length === 0 && typeof tabsContent[index] !== 'undefined') { $tabContent = $(tabsContent[index]).html(); } $div.append( $tabContent ); var $li = $('
  • '); $li.append( $(this).detach() ); $navigation.append( $li ); $viewport.append( $div ); var eventType = ''; var classes = $this.attr('class'); var matches = classes.match(/g1-type-[^\s]+/gi); if ( matches && matches.length > 0) { eventType = matches[0].replace('g1-type--', ''); } var event = eventType || options.event; $li.bind(event, function() { $this.find('.g1-tabs-nav-item').removeClass('g1-tabs-nav-current-item'); $(this).addClass('g1-tabs-nav-current-item'); $this.find('.g1-tabs-viewport-item').hide(); $div.show(); $('body').trigger('g1ContentElementVisible', [$div]); }); index += 1; }); $this.find('*').remove(); if ( $this.is( '.g1-tabs--bottom' ) ) { $this.prepend( $navigation ); $this.prepend( $viewport ); } else { $this.prepend( $viewport ); $this.prepend( $navigation ); } $this.wrapInner('
    '); var hash = window.location.hash; var tabSelector = '.g1-tabs-nav-item:first'; if (hash) { var selector = hash; var $tab = $this.find(selector); var validTab = ($tab.length > 0 && $tab.hasClass('g1-tab-title')); if (validTab) { tabSelector = selector; } } selectTab.apply(this, [tabSelector]); $(window).bind( 'load', function(){ $this.g1Tabs( 'adjustHeight' ); }); } }); }; var adjustHeight = function() { return this.each(function(){ var $this = $(this); if ( $this.g1Tabs( 'isPositionVertical') ) { if ( $this.find( '.g1-tabs-nav').height() > $this.find( '.g1-tabs-viewport').height() ) { $this.find( '.g1-tabs-viewport' ).css( 'min-height', $this.find( '.g1-tabs-nav' ).height() ); } } }); }; var isPositionHorizontal = function() { if ( $(this).is( '.position-top-left, .position-top-center, .position-top-right, .position-bottom-left, .position-bottom-center, .position-bottom-right' ) ) { return true; } else { return false; } }; var isPositionVertical = function() { return !( $(this).g1Tabs( 'isPositionHorizontal') ); }; var next = function( ) { }; var prev = function() { }; var select = function() { }; var selectTab = function(selector) { var $this = $(this); var $elem = $this.find(selector); if (!$elem.is('.g1-tabs-nav-item')) { $elem = $elem.parents('.g1-tabs-nav-item'); } var elemIndex = $elem.index(); $elem.addClass('g1-tabs-nav-current-item'); $this.find('.g1-tabs-viewport-item').hide(); $this.find('.g1-tabs-viewport-item').eq(elemIndex).show(); }; var destroy = function() { }; that.init = init; that.adjustHeight = adjustHeight; that.isPositionHorizontal = isPositionHorizontal; that.isPositionVertical = isPositionVertical; that.next = next; that.prev = prev; that.select = select; that.selectTab = selectTab; that.destroy = destroy; return that; }; // Tabs plugin definition $.fn.g1Tabs = function (method) { var $this = $(this); var instance = $this.data('g1_tabs'); // create instance if (!instance) { instance = g1Tabs(); $this.data('g1_tabs', instance); } // method calling logic if ( instance[method] ) { return instance[method].apply(this, Array.prototype.slice.call( arguments, 1)); } else if (typeof method === 'object' || !method) { var options = Array.prototype.slice.call( arguments, 1); return instance.init.apply(this, options); } else { $.error('Method ' + method + ' does not exist on G1.jQuery.tabs'); } }; $.fn.g1Tabs.defaults = G1.jQuery.g1Tabs.defaults; })(jQuery); /* =============================== * g1CollapseMenu * package: G1 jQuery * * Replaces list menu to select * =============================== */ (function($){ var g1CollapseMenu = function($element) { var that = {}; var oldMenu, newMenu; var init = function() { oldMenu = $element; newMenu = createMenu(); }; var createMenu = function() { var $select = $("