/* 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 = $('