Newer
Older
var lg = 'quiqqer/template-cologne',
USER_BUTTON_CLICKED = false;

Michael Danielczok
committed
window.addEvent('domready', function () {
"use strict";

Michael Danielczok
committed
require([
'qui/QUI'
], function (QUI) {
initMobileMenu();

Michael Danielczok
committed
initExpandCategoryContent();
if (document.getElements('[href=#top]')) {
var toTop = document.getElements('[href=#top]'),
buttonVisible = false;
// show on load after 1s delay
if (QUI.getScroll().y > 300) {
toTop.addClass('toTop__show');
buttonVisible = true;
// show button toTop after scrolling down
QUI.addEvent('scroll', function () {
if (QUI.getScroll().y > 300) {
if (!buttonVisible) {
toTop.addClass('toTop__show');
buttonVisible = true;
if (!buttonVisible) {
return;
toTop.removeClass('toTop__show');
buttonVisible = false;
// scroll to top
toTop.addEvent('click', function (event) {
event.stop();
new Fx.Scroll(window).toTop();
var Header = document.getElement('.cologne-header');
require.config({
paths: {
Hammer : URL_OPT_DIR + 'bin/quiqqer-asset/hammerjs/hammerjs/hammer.min',
FastClick: URL_OPT_DIR + 'bin/quiqqer-asset/fastclick/fastclick/lib/fastclick'
require(['FastClick'], function (FastClick) {
FastClick.attach(document.body);
});
/**
* Sticky menu
* @type {boolean}
*/
var Menu = document.getElement('.cologne-header'),
TopBar = document.getElement('.topbar');
if (Menu) {
initMenu(Menu, TopBar);
}
/**
* Init basket
*/
if (document.getElement('.cologne-header-control-basket')) {
initBasket();
}
/**
* User icon
*/
if (Menu && TopBar) {
'Locale',
'package/quiqqer/tooltips/bin/html5tooltips'
], function (QUILocale, html5tooltips) {
QUI.setAttribute('control-loader-type', 'fa-spinner');
QUI.setAttribute('control-loader-color', '#999999');
var Logo = Menu.getElement('.logo'),
UserButton = document.getElement('.cologne-header-control-user');
var UserButtonLoader = UserButton.getElement('.cologne-header-control-user-loader');
window.addEvent('load', function () {
document.getElement('.cologne-header-menu').setStyle('overflow', 'visible');
/**
* Login
*/
require([
'utils/Controls'
], function (QUIControlUtils) {
if (QUIQQER_USER.id) {
var UserIcon = document.getElement(
'[data-qui="package/quiqqer/frontend-users/bin/frontend/controls/UserIcon"]'
);
QUIControlUtils.getControlByElement(UserIcon).then(function (UserIconControl) {
UserIconControl.addEvent('load', function () {
userIconLoadEvent(UserIconControl, QUILocale);
});
});
UserButton.addEvents({
click: function (event) {
if (event) {
event.stop();
if (!QUIQQER_USER.id) {
if (USER_BUTTON_CLICKED) {
return;
USER_BUTTON_CLICKED = true;
createLoginWindow();
}
}
});
if (UserButtonLoader) {
moofx(UserButtonLoader).animate({
opacity: 0
}, {
callback: function () {
UserButtonLoader.destroy();
}
});
}

Michael Danielczok
committed
if ("QUIQQER_LOGIN_FAILED" in window && window.QUIQQER_LOGIN_FAILED) {
new LoginWindow({
maxHeight : 380,
social : false,
registration: false,
logo : Logo ? Logo.src : '',
events : {
onSuccess: function () {
window.location.reload();
}
}

Michael Danielczok
committed
/**
* Init menu
*/
function initMenu (Menu, TopBar) {
var showMenuFrom = TopBar ? TopBar.getSize().y : 0,
SearchBtn = Menu.getElement('.search-button'),
SearchInput = TopBar ? TopBar.getElement('.template-search input[type="search"]') : null;
if (SHOW_MENU_START_POS && SHOW_MENU_START_POS.toInt() > 0) {

Michael Danielczok
committed
showMenuFrom = SHOW_MENU_START_POS.toInt();
}
if (SearchBtn && SearchInput) {
new Fx.Scroll(window, {
onComplete: function () {
SearchInput.focus();
}
}).toTop();
};
if (QUI.getWindowSize().x < 767) {
clickEvent = function () {
document.getElement('.quiqqer-products-search-suggest-form-button').click();
};
}
SearchBtn.addEvent('click', clickEvent);
*
* @param smooth {bool} - helpful on page reload when the page is already scrolled
*/
if (smooth === true) {
Menu.setStyles({
position : 'fixed',
transform: 'translateY(-100px)'
});

Michael Danielczok
committed
// Delay 500ms for performance reasons (on page load)
(function () {
moofx(Menu).animate({
transform: 'translateY(0)'
Menu.addClass('cologne-header-fixed');
document.body.addClass('header-fixed');
var showSearchBtn = function () {
if (!SearchBtn) {
return;
}
moofx(SearchBtn).animate({
opacity : 1,
transform: 'scale(1)'
}, {
duration: 300,
equation: 'cubic-bezier(0.6, -0.4, 0.2, 2.11)'
});
};
var hideSearchBtn = function () {
if (!SearchBtn) {
return;
}
moofx(SearchBtn).animate({
opacity : 0,
transform: 'scale(0)'
}, {
duration: 300
});
/**
* Set menu position to initial
*/
var removeMenuFixed = function () {
Menu.removeClass('cologne-header-fixed');
Menu.setStyle('position', null);
document.body.removeClass('header-fixed');

Michael Danielczok
committed
// check on page load if menu should stick to the top
if (QUI.getScroll().y >= showMenuFrom) {
if (isMenuSticky) {
return;
}
setMenuFixed(true);
showSearchBtn();
}
QUI.addEvent('scroll', function () {

Michael Danielczok
committed
if (QUI.getScroll().y >= showMenuFrom) {
if (!isMenuSticky) {
return;
}
removeMenuFixed();
hideSearchBtn();
});
}
/**
* Basket
*/
function initBasket () {
require([
'package/quiqqer/order/bin/frontend/controls/basket/Button'
], function (Basket) {
new Basket({
open : BASKET_OPEN.toInt(),
styles: {
float: 'right'
},
events: {
onCreate: function (Basket) {
var BasketNode = Basket.getElm(),
basketStyleCss = '';
if (BASKET_STYLE) {
basketStyleCss = 'basket-style-' + BASKET_STYLE;
}
// clear default content
BasketNode.set('html', '');
BasketNode.addClass('tpl-btn ' + basketStyleCss);

Michael Danielczok
committed
new Element('span', {
'class': 'quiqqer-order-basketButton-icon-custom',
html : '<span class="fa fa-shopping-basket"></span>'
}).inject(BasketNode);

Michael Danielczok
committed
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
new Element('span', {
'class': 'quiqqer-order-basketButton-quantity quiqqer-order-basketButton-batch-custom',
html : '0'
}).inject(BasketNode);
if (BASKET_STYLE && BASKET_STYLE === 'full') {
new Element('span', {
'class': 'quiqqer-order-basketButton-sum',
html : INITAL_BASKET_PRICE
}).inject(BasketNode);
}
document.getElement('.cologne-header-control-basket').set('html', '');
},
/**
* onShowBasketBegin event
*
* @param Basket
* @param pos - position of popup basket
* @param height - height of basket button
*/
showBasketBegin: function (Basket, pos, height) {
// move basket popup from bottom of the page to header
// it's better to manage for sticky header
Header.getElement('.cologne-header-control').adopt(Basket.$BasketContainer);
var headerHeight = Header.getSize().y;
// -1px because of header bottom border
pos.y = headerHeight - 1;
// reset button height
// see package/quiqqer/order/bin/frontend/controls/basket/Button.showSmallBasket()
height.y = 0;
Basket.$BasketContainer.setStyles({
right: 0 // right margin from .cologne-header-control-basket
});
// Do not scroll the page
Basket.$BasketContainer.addEvent('focus', function (event) {
event.preventDefault();
});
Basket.$BasketContainer.setStyles({
border: '1px solid #ddd'
});
}

Michael Danielczok
committed
}
}).inject(document.getElement('.cologne-header-control-basket'));
});
}

Michael Danielczok
committed
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
/**
* UserIcon load event
*
* @param UserIconControl
* @param QUILocale
*/
function userIconLoadEvent (UserIconControl, QUILocale) {
var Menu = UserIconControl.$Menu;
require([
'controls/users/LogoutWindow',
'qui/controls/contextmenu/Item',
'qui/controls/contextmenu/Separator'
], function (LogoutWindow, Item, Separator) {
Menu.appendChild(new Separator());
// own logout entry
Menu.appendChild(
new Item({
icon : 'fa fa-sign-out',
text : QUILocale.get(lg, 'frontend.usericon.menuentry.logout.label'),
events: {
click: function () {
createLogoutWindow(LogoutWindow);
}
}
})
);
});
UserIconControl.addEvent('onMenuShow', function (UserIconControl, MenuNode) {
MenuNode.setStyles({
left : null,
right: -25

Michael Danielczok
committed
});
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
});
}
/**
* Create and open logout window
*
* @param LogoutWindow
*/
function createLogoutWindow (LogoutWindow) {
new LogoutWindow({
class : 'cologne-logout-dialog',
title : false,
icon : false,
maxHeight: 350,
maxWidth : 400,
events : {
onOpen: function (Popup) {
var Content = Popup.getElm(),
ContentElms = [
Content.getElement('.qui-window-popup-content'),
Content.getElement('.qui-window-popup-buttons')
];
ContentElms.each(function (ContentElm) {
ContentElm.setStyle('opacity', 0);
});

Michael Danielczok
committed
var CancelButton = Content.getElement('button[name="cancel"]');
// CancelButton.removeClass('btn-light');
CancelButton.addClass('btn-secondary btn-outline');
}

Michael Danielczok
committed
// workaround due to the CancelButton.addClass
// to avoid the "flash" effect
(function () {
ContentElms.each(function (ContentElm) {
moofx(ContentElm).animate({
opacity: 1
});
});
}).delay(50);
}
}
}).open();

Michael Danielczok
committed
}
/**
* Create and open login popup
*/
function createLoginWindow (onlyLogin = false) {
USER_BUTTON_CLICKED = false;
require([
'Locale',
'utils/Controls',
'package/quiqqer/frontend-users/bin/frontend/controls/login/Window'
], function (QUILocale, QUIControlUtils, LoginWindow) {
new LoginWindow({
class : 'cologne-login-dialog',
title : false,
maxHeight: 550,
maxWidth : 400,
events : {
onOpen : function (LoginWindow) {
if (!REGISTER_URL && !onlyLogin) {
return;
}
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
var CreateAccountWrapper = new Element('div', {
'class': 'login-popup-create-account-wrapper'
});
new Element('a', {
href: REGISTER_URL,
html: QUILocale.get(lg, 'template.popup.login.registration.button'),
}).inject(CreateAccountWrapper);
CreateAccountWrapper.inject(Elm.getElement('.qui-window-popup-content'));
},
onSuccess: function () {
window.location.reload();
}
}
}).open();
});
}
/**
* Menu mobile
*
* In mobile resolution (less than 767px) opens category menu button
* the mobile navigation instead category navigation.
*/
function initMobileMenu () {
if (QUI.getWindowSize().x >= 768) {
return;

Michael Danielczok
committed
}
var OpenCategoryBtn = document.getElement('.shop-category-menu-button'),
MenuElm = document.getElement('[data-qui="package/quiqqer/menu/bin/SlideOut"]');
if (!OpenCategoryBtn) {
console.error('Open Category Button ".shop-category-menu-button" not found.');
return;
}
require(['utils/Controls'], function (Controls) {
Controls.getControlByElement(MenuElm).then(function (MenuControl) {
OpenCategoryBtn.removeEvents('click');
OpenCategoryBtn.addEvent('click', function () {
MenuControl.toggle();
});
});

Michael Danielczok
committed
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
/**
* Show content of category site after click on button
*/
function initExpandCategoryContent () {
var ButtonContainer = document.getElement('.quiqqer-category-content-button'),
Wrapper = document.getElement('.quiqqer-category-content-inner'),
Body = document.getElement('.quiqqer-category-content-inner-body'),
Bg = document.getElement('.quiqqer-category-content-inner-body__bg');
if (!ButtonContainer || !Wrapper || !Body) {
return;
}
var Button = ButtonContainer.getElement('button'),
realHeight = Body.getSize().y;
if (!Button) {
return;
}
if (Wrapper.getSize().y >= realHeight) {
// content is small, no button needed
Wrapper.setStyle('max-height', null);
Button.destroy();
if (Bg) {
Bg.destroy();
}
return;
}
(function () {
Button.setStyle('display', null);
moofx(Button).animate({
opacity: 1
}, {
duration: 200
});
}).delay(500);
Button.addEvent('click', function (event) {
event.stop();
moofx(Wrapper).animate({
maxHeight: realHeight
}, {
callback: function () {
moofx(ButtonContainer).animate({
opacity: 0
}, {
duration: 200,
callback: function () {
ButtonContainer.destroy();
}
});
if (Bg) {
moofx(Bg).animate({
opacity: 0
}, {
duration: 200,
callback: function () {
Bg.destroy();
}
});
}
Wrapper.setStyle('maxHeight', null);
}
});
});
}
});