layout.js
16.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
var Layout = function () {
// IE mode
var isRTL = false;
var isIE8 = false;
var isIE9 = false;
var isIE10 = false;
var isIE11 = 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/);
isIE11 = !! navigator.userAgent.match(/MSIE 11.0/);
if (isIE10) {
jQuery('html').addClass('ie10'); // detect IE10 version
}
if (isIE11) {
jQuery('html').addClass('ie11'); // detect IE11 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');
}
});
// close search box on body click
if($('.search-btn').size() != 0) {
$('.search-box, .search-btn').on('click', function(e){
e.stopPropagation();
});
$('body').on('click', function() {
if ($('.search-btn').hasClass('show-search-icon')) {
$('.search-btn').removeClass("show-search-icon");
$('.search-box').fadeOut(300);
}
});
}
}
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 handleSubMenuExt = function() {
$(".header-navigation .dropdown").on("hover", function() {
if ($(this).children(".header-navigation-content-ext").show()) {
if ($(".header-navigation-content-ext").height()>=$(".header-navigation-description").height()) {
$(".header-navigation-description").css("height", $(".header-navigation-content-ext").height()+22);
}
}
});
}
var handleSidebarMenu = function () {
$(".sidebar .dropdown a i").click(function (event) {
event.preventDefault();
if ($(this).parent("a").hasClass("collapsed") == false) {
$(this).parent("a").addClass("collapsed");
$(this).parent("a").siblings(".dropdown-menu").slideDown(300);
} else {
$(this).parent("a").removeClass("collapsed");
$(this).parent("a").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 () {
if (!jQuery.fancybox) {
return;
}
jQuery(".fancybox-fast-view").fancybox();
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) {
Layout.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();
}
}
var handleMobiToggler = function () {
$(".mobi-toggler").on("click", function(event) {
event.preventDefault();//the default action of the event will not be triggered
$(".header").toggleClass("menuOpened");
$(".header").find(".header-navigation").toggle(300);
});
}
var handleTheme = function () {
var panel = $('.color-panel');
// handle theme colors
var setColor = function (color) {
$('#style-color').attr("href", "../../assets/frontend/layout/css/themes/" + color + ".css");
$('.corporate .site-logo img').attr("src", "../../assets/frontend/layout/img/logos/logo-corp-" + color + ".png");
$('.ecommerce .site-logo img').attr("src", "../../assets/frontend/layout/img/logos/logo-shop-" + color + ".png");
}
$('.icon-color', panel).click(function () {
$('.color-mode').show();
$('.icon-color-close').show();
});
$('.icon-color-close', panel).click(function () {
$('.color-mode').hide();
$('.icon-color-close').hide();
});
$('li', panel).click(function () {
var color = $(this).attr("data-style");
setColor(color);
$('.inline li', panel).removeClass("current");
$(this).addClass("current");
});
}
return {
init: function () {
// init core variables
handleTheme();
handleInit();
handleResponsiveOnResize();
handleIEFixes();
handleSearch();
handleFancybox();
handleDifInits();
handleSidebarMenu();
handleAccordions();
handleMenu();
handleScrollers();
handleSubMenuExt();
handleMobiToggler();
},
initUniform: function (els) {
if (els) {
jQuery(els).each(function () {
if ($(this).parents(".checker").size() == 0) {
$(this).show();
$(this).uniform();
}
});
} else {
handleUniform();
}
},
initTwitter: function () {
!function(d,s,id){
var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}
}(document,"script","twitter-wjs");
},
initTouchspin: function () {
$(".product-quantity .form-control").TouchSpin({
buttondown_class: "btn quantity-down",
buttonup_class: "btn quantity-up"
});
$(".quantity-down").html("<i class='fa fa-angle-down'></i>");
$(".quantity-up").html("<i class='fa fa-angle-up'></i>");
},
initFixHeaderWithPreHeader: function () {
jQuery(window).scroll(function() {
if (jQuery(window).scrollTop()>37){
jQuery("body").addClass("page-header-fixed");
}
else {
jQuery("body").removeClass("page-header-fixed");
}
});
},
initNavScrolling: function () {
function NavScrolling () {
if (jQuery(window).scrollTop()>60){
jQuery(".header").addClass("reduce-header");
}
else {
jQuery(".header").removeClass("reduce-header");
}
}
NavScrolling();
jQuery(window).scroll(function() {
NavScrolling ();
});
},
initOWL: function () {
$(".owl-carousel6-brands").owlCarousel({
pagination: false,
navigation: true,
items: 6,
addClassActive: true,
itemsCustom : [
[0, 1],
[320, 1],
[480, 2],
[700, 3],
[975, 5],
[1200, 6],
[1400, 6],
[1600, 6]
],
});
$(".owl-carousel5").owlCarousel({
pagination: false,
navigation: true,
items: 5,
addClassActive: true,
itemsCustom : [
[0, 1],
[320, 1],
[480, 2],
[660, 2],
[700, 3],
[768, 3],
[992, 4],
[1024, 4],
[1200, 5],
[1400, 5],
[1600, 5]
],
});
$(".owl-carousel4").owlCarousel({
pagination: false,
navigation: true,
items: 4,
addClassActive: true,
});
$(".owl-carousel3").owlCarousel({
pagination: false,
navigation: true,
items: 3,
addClassActive: true,
itemsCustom : [
[0, 1],
[320, 1],
[480, 2],
[700, 3],
[768, 2],
[1024, 3],
[1200, 3],
[1400, 3],
[1600, 3]
],
});
$(".owl-carousel2").owlCarousel({
pagination: false,
navigation: true,
items: 2,
addClassActive: true,
itemsCustom : [
[0, 1],
[320, 1],
[480, 2],
[700, 3],
[975, 2],
[1200, 2],
[1400, 2],
[1600, 2]
],
});
},
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();
});
}
};
}();