var app = function () {
// ie mode
var isrtl = false;
var isie8 = false;
var isie9 = false;
var isie10 = false;
var responsive = true;
var responsivehandlers = [];
var handleinit = function() {
if ($('body').css('direction') === 'rtl') {
isrtl = true;
}
isie8 = !! navigator.useragent.match(/msie 8.0/);
isie9 = !! navigator.useragent.match(/msie 9.0/);
isie10 = !! navigator.useragent.match(/msie 10.0/);
if (isie10) {
jquery('html').addclass('ie10'); // detect ie10 version
}
}
// runs callback functions set by app.addresponsivehandler().
var runresponsivehandlers = function () {
// reinitialize other subscribed elements
for (var i in responsivehandlers) {
var each = responsivehandlers[i];
each.call();
}
}
// handle the layout reinitialization on window resize
var handleresponsiveonresize = function () {
var resize;
if (isie8) {
var currheight;
$(window).resize(function () {
if (currheight == document.documentelement.clientheight) {
return; //quite event since only body resized not window.
}
if (resize) {
cleartimeout(resize);
}
resize = settimeout(function () {
runresponsivehandlers();
}, 50); // wait 50ms until window resize finishes.
currheight = document.documentelement.clientheight; // store last body client height
});
} else {
$(window).resize(function () {
if (resize) {
cleartimeout(resize);
}
resize = settimeout(function () {
runresponsivehandlers();
}, 50); // wait 50ms until window resize finishes.
});
}
}
var handleiefixes = function() {
//fix html5 placeholder attribute for ie7 & ie8
if (isie8 || isie9) { // ie8 & ie9
// this is html5 placeholder fix for inputs, inputs with placeholder-no-fix class will be skipped(e.g: we need this for password fields)
jquery('input[placeholder]:not(.placeholder-no-fix), textarea[placeholder]:not(.placeholder-no-fix)').each(function () {
var input = jquery(this);
if (input.val() == '' && input.attr("placeholder") != '') {
input.addclass("placeholder").val(input.attr('placeholder'));
}
input.focus(function () {
if (input.val() == input.attr('placeholder')) {
input.val('');
}
});
input.blur(function () {
if (input.val() == '' || input.val() == input.attr('placeholder')) {
input.val(input.attr('placeholder'));
}
});
});
}
}
// handles scrollable contents using jquery slimscroll plugin.
var handlescrollers = function () {
$('.scroller').each(function () {
var height;
if ($(this).attr("data-height")) {
height = $(this).attr("data-height");
} else {
height = $(this).css('height');
}
$(this).slimscroll({
allowpagescroll: true, // allow page scroll when the element scroll is ended
size: '7px',
color: ($(this).attr("data-handle-color") ? $(this).attr("data-handle-color") : '#bbb'),
railcolor: ($(this).attr("data-rail-color") ? $(this).attr("data-rail-color") : '#eaeaea'),
position: isrtl ? 'left' : 'right',
height: height,
alwaysvisible: ($(this).attr("data-always-visible") == "1" ? true : false),
railvisible: ($(this).attr("data-rail-visible") == "1" ? true : false),
disablefadeout: true
});
});
}
var handlesearch = function() {
$('.search-btn').click(function () {
if($('.search-btn').hasclass('show-search-icon')){
if ($(window).width()>767) {
$('.search-box').fadeout(300);
} else {
$('.search-box').fadeout(0);
}
$('.search-btn').removeclass('show-search-icon');
} else {
if ($(window).width()>767) {
$('.search-box').fadein(300);
} else {
$('.search-box').fadein(0);
}
$('.search-btn').addclass('show-search-icon');
}
});
}
var handlemenu = function() {
$(".header .navbar-toggle").click(function () {
if ($(".header .navbar-collapse").hasclass("open")) {
$(".header .navbar-collapse").slidedown(300)
.removeclass("open");
} else {
$(".header .navbar-collapse").slidedown(300)
.addclass("open");
}
});
}
var handlesidebarmenu = function () {
$(".sidebar .dropdown a").click(function () {
if ($(this).hasclass("collapsed") == false) {
$(this).addclass("collapsed");
$(this).siblings(".dropdown-menu").slidedown(300);
} else {
$(this).removeclass("collapsed");
$(this).siblings(".dropdown-menu").slideup(300);
}
});
}
function handledifinits() {
$(".header .navbar-toggle span:nth-child(2)").addclass("short-icon-bar");
$(".header .navbar-toggle span:nth-child(4)").addclass("short-icon-bar");
}
function handleuniform() {
if (!jquery().uniform) {
return;
}
var test = $("input[type=checkbox]:not(.toggle), input[type=radio]:not(.toggle, .star)");
if (test.size() > 0) {
test.each(function () {
if ($(this).parents(".checker").size() == 0) {
$(this).show();
$(this).uniform();
}
});
}
}
var handlefancybox = function () {
jquery(".fancybox-fast-view").fancybox();
if (!jquery.fancybox) {
return;
}
if (jquery(".fancybox-button").size() > 0) {
jquery(".fancybox-button").fancybox({
groupattr: 'data-rel',
preveffect: 'none',
nexteffect: 'none',
closebtn: true,
helpers: {
title: {
type: 'inside'
}
}
});
$('.fancybox-video').fancybox({
type: 'iframe'
});
}
}
// handles bootstrap accordions.
var handleaccordions = function () {
jquery('body').on('shown.bs.collapse', '.accordion.scrollable', function (e) {
app.scrollto($(e.target), -100);
});
}
// handles bootstrap tabs.
var handletabs = function () {
// fix content height on tab click
$('body').on('shown.bs.tab', '.nav.nav-tabs', function () {
handlesidebarandcontentheight();
});
//activate tab if tab id provided in the url
if (location.hash) {
var tabid = location.hash.substr(1);
$('a[href="#' + tabid + '"]').click();
}
}
return {
init: function () {
// init core variables
handleinit();
handleresponsiveonresize();
handleiefixes();
handlesearch();
handlefancybox();
handledifinits();
handlesidebarmenu();
handleaccordions();
handlemenu();
handlescrollers();
this.addresponsivehandler(function(){
app.initbxslider(true);
});
},
inituniform: function (els) {
if (els) {
jquery(els).each(function () {
if ($(this).parents(".checker").size() == 0) {
$(this).show();
$(this).uniform();
}
});
} else {
handleuniform();
}
},
inittouchspin: function () {
$(".product-quantity .form-control").touchspin({
buttondown_class: "btn quantity-down",
buttonup_class: "btn quantity-up"
});
$(".quantity-down").html("");
$(".quantity-up").html("");
},
initbxslider: function (reload) {
$('.bxslider').each(function(){
var width = $(window).width();
var slides;
var slidemargin = parseint($(this).attr("data-slide-margin"));
var slidecontainerwidth = $(this).closest('.bxslider-wrapper').width();
var slidewidth;
if (width <= 480) {
slides = $(this).attr("data-slides-phone");
} else if (width > 480 && width <= 992) {
slides = $(this).attr("data-slides-tablet");
} else {
slides = $(this).attr("data-slides-desktop");
}
slides = parseint(slides);
slidewidth = slidecontainerwidth / slides;
if (reload === true) {
if (!$(this).data("bxslider")) {
return;
}
$(this).data("bxslider").reloadslider({
minslides: slides,
maxslides: slides,
slidewidth: slidewidth,
slidemargin: slidemargin,
moveslides:5,
responsive:true
});
} else {
//alert(2);
var slider = $(this).bxslider({
minslides: slides,
maxslides: slides,
slidewidth: slidewidth,
slidemargin: slidemargin,
moveslides:5,
responsive:true
});
$(this).data("bxslider", slider);
}
});
},
initimagezoom: function () {
$('.product-main-image').zoom({url: $('.product-main-image img').attr('data-bigimgsrc')});
},
initsliderrange: function () {
$( "#slider-range" ).slider({
range: true,
min: 0,
max: 500,
values: [ 50, 250 ],
slide: function( event, ui ) {
$( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
}
});
$( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) +
" - $" + $( "#slider-range" ).slider( "values", 1 ) );
},
// wrapper function to scroll(focus) to an element
scrollto: function (el, offeset) {
var pos = (el && el.size() > 0) ? el.offset().top : 0;
if (el) {
if ($('body').hasclass('page-header-fixed')) {
pos = pos - $('.header').height();
}
pos = pos + (offeset ? offeset : -1 * el.height());
}
jquery('html,body').animate({
scrolltop: pos
}, 'slow');
},
//public function to add callback a function which will be called on window resize
addresponsivehandler: function (func) {
responsivehandlers.push(func);
},
scrolltop: function () {
app.scrollto();
},
gridoption1: function () {
$(function(){
$('.grid-v1').mixitup();
});
}
};
}();