/** * Copyright © 2021 Codazon, Inc. All rights reserved. * See COPYING.txt for license details. */ define(['jquery', 'jquery-ui-modules/widget', 'owlslider', 'themecore'], function($) { var deskPrefix = 'desk_', mobiPrefix = 'mobi_', deskEvent = 'cdz_desktop', mobiEvent = 'cdz_mobile', win = window, $win = $(win), $body = $('body'), rtl = $body.hasClass('rtl-layout'), mBreakpoint = 768, winWidthChangedEvent = 'cdz_win_width_changed', nowTimeLoading = false, nowTimeLoaded = false, onNowTimeLoaded = (func) => { if (!nowTimeLoading) { nowTimeLoading = true; $.ajax({ url: codazon.dateTimeUrl, type: 'get', success: (rs) => { if (typeof rs.now != 'undefined') codazon.now = rs.now; codazon.localNow = (new Date()).getTime(); nowTimeLoaded = true; updateTimestamp(); $win.trigger('nowTimeLoaded'); } }); } if (nowTimeLoaded) { updateTimestamp(); func(); } else { $win.on('nowTimeLoaded', func); } }, itemEffect = ($parent, delayUnit) => { $('.cdz-transparent', $parent).each((i, el) => { var $item = $(el); setTimeout(() => { $item.removeClass('cdz-transparent').addClass('cdz-translator'); setTimeout(() => { $item.removeClass('cdz-translator'); }, 1000); }, delayUnit*i); }); }, formatDate = (str) => { return str.replaceAll('-', '/'); }, updateTimestamp = () => { codazon.curTimestamp = (new Date(formatDate(codazon.now))).getTime() + ((new Date()).getTime() - codazon.localNow); }, getCustomStyleElement = () => { var $css = $('#cdz-widget-css-script'); if (!$css.length) $css = $('`; $(css).insertAfter(this.element); }, _getCSSCode: function(parentClass, itemClass, itemsPerRow) { var self = this, conf = this.options, css = '', width; bpLength = itemsPerRow.length; var marginSide = rtl ? 'margin-left' : 'margin-right'; for(var i = bpLength - 1; i >=0; i--) { if (itemsPerRow[i].breakPoint < mBreakpoint) { var margin = 10, subtrahend = 11; } else { var margin = conf.margin, subtrahend = conf.margin; } var marginBottom = conf.marginBottom ? conf.marginBottom : margin; width = 100/itemsPerRow[i].items; css += '@media (min-width: ' + itemsPerRow[i].breakPoint + 'px)'; if (typeof itemsPerRow[i + 1] != 'undefined') { css += ' and (max-width: ' + (itemsPerRow[i + 1].breakPoint - 1) + 'px)'; } css += '{.' + parentClass + '{' + marginSide +': -' + margin + 'px}'; css += '.' + parentClass + ' .' + itemClass + '{width:calc(' + width + '% - ' + subtrahend + 'px);' + marginSide +':' + margin + 'px;margin-bottom:' + marginBottom + 'px}}\n'; }; return css; } }); $.widget('codazon.socialSharing', { _create: function() { var self = this, conf = this.options; this.element.on('click', '[data-type]', function(e) { e.preventDefault(); self._openPopup($(this).data('type')); }); }, _openPopup: function(type) { var conf = this.options, url; switch (type) { case 'facebook' : url = 'https://www.facebook.com/sharer/sharer.php?u=' + conf.url; break; case 'twitter' : url = 'https://twitter.com/intent/tweet?url='+ conf.url + '&text=' + conf.description; break; case 'linkedin' : url = 'https://www.linkedin.com/shareArticle?mini=true&url='+ conf.url + '&title=' + conf.title + '&ro=false&summary=' + conf.description; break; case 'pinterest' : url = 'https://www.pinterest.com/pin/create/button/?url='+ conf.url + '&media=' + conf.image + '&description=' + conf.description; break; case 'reddit' : url = 'https://www.reddit.com/submit?url=' + conf.url +'&title=' + conf.title; break; case 'whatsapp' : url = 'https://api.whatsapp.com/send/?text=' + conf.url + '&type=custom_url&app_absent=0'; break; case 'snapchat': url = 'https://www.snapchat.com/scan?attachmentUrl='+ conf.url;break; } if (url) win.open(url,"", 'menubar=1,resizable=1,width=700,height=600'); } }); $.widget('codazon.flexibleSlider', { options: { mbMargin: 10, sameHeight: ['.product-details', '.product-item-details'], pageNumber: false, divider: '/', pullDrag: true, noLoadedClass: false }, _create: function() { var conf = this.options, slideConf = conf.sliderConfig, $el = this.element; this.$css = getCustomStyleElement(); this.id = 'cdz-slider-' + themecore.uniqid(); $el.addClass(this.id); conf.noLoop = conf.forceNoLoop ? conf.forceNoLoop : $el.hasClass('product-items') || $el.parents('.product-items').length; this.totalItem = $el.children().length; if (conf.noLoadedClass) $el.parents('.' + conf.noLoadedClass).removeClass(conf.noLoadedClass); slideConf.rtl = rtl; slideConf.lazyLoad = true; slideConf.pullDrag = conf.pullDrag; slideConf.navElement = 'div'; slideConf.autoplayHoverPause = true; if (slideConf.responsive) { var forceNext = false, side = rtl ? 'left' : 'right', overflow = 'visible'; $.each(slideConf.responsive, (i, rsp) => { if ((slideConf.margin > conf.mbMargin) && (i < mBreakpoint)) { slideConf.responsive[i] = $.extend({}, {margin: conf.mbMargin}, slideConf.responsive[i]); } if (conf.noLoop) { var items = parseFloat(rsp.items), intItems = parseInt(items), pdr = '0%'; if (intItems != items) { slideConf.responsive[i].nav = false; if (conf.noLoop) { slideConf.responsive[i].items = intItems; slideConf.responsive[i].loop = false; pdr = ((items - intItems)*100/items) + '%'; forceNext = true; this.$css.append(`@media (min-width: ${i}px) {.${this.id}{padding-${side}: ${pdr};overflow:hidden}.${this.id}>.owl-stage-outer{overflow:visible}.${this.id}>.owl-dots{width:calc(100% + ${pdr})}}`); } else { slideConf.responsive[i].loop = true; } } else if (forceNext && conf.noLoop) { forceNext = false; this.$css.append(`@media (min-width: ${i}px) {.${this.id}{padding-${side}:${pdr};overflow:${overflow}}.${this.id}>.owl-stage-outer{overflow:hidden}.${this.id}>.owl-dots{width:calc(100% + ${pdr})}}`); } else if (conf.noLoop) { forceNext = false; } } else { if ((slideConf.responsive[i].items%1) > 0) { slideConf.responsive[i].loop = true; } else { slideConf.responsive[i].loop = slideConf.loop || false; } } }); } slideConf.onLoadedLazy = function(e) {$(e.element).css('opacity','').removeClass('owl-lazy cdz-lazy');}; $el.addClass('owl-carousel').owlCarousel(slideConf); this._sameHeight(); this._itemEffect(); if (conf.pageNumber) this._addPageNumber(); if (win.innerWidth <= 1024) { setTimeout(() => { $el.trigger('refresh.owl.carousel'); this._sameHeight(); }, 100); } if (slideConf.autoplay && (!slideConf.loop)) { $el.on('translated.owl.carousel', (e) => { var timeout = slideConf.autoplayTimeout ? slideConf.autoplayTimeout : 5000; if ($el.find('.owl-item').last().hasClass('active')) { setTimeout(() => $el.trigger('to.owl.carousel', [0, 0]), timeout); } }); } if (!slideConf.autoplay) $el.on('changed.owl.carousel', (e) => $el.trigger('stop.owl.autoplay')); }, _addPageNumber: function() { var conf = this.options, owlData = this.element.data('owl.carousel'); this.$pageNumber = $('