FluidbookCartGrandVision.prototype = {
init: function () {
+ var $this = this;
+ this.items = this.fluidbook.cache.get('cart', []);
+ $(document).on('click', '.grandvision-slideshow .next', function () {
+ $this.nextSlide();
+ return false;
+ });
+
+ $(document).on('click', '.grandvision-slideshow .prev', function () {
+ $this.prevSlide();
+ return false;
+ });
+
+ $(document).on('click', '.grandvision-slideshow .dots a', function () {
+ var diff = $(this).data('i') - $this.currentSlide;
+ if (diff !== 0) {
+ $this.gotoSlide($(this).data('i'), diff>=1?1:-1);
+ }
+ return false;
+ });
},
- openMenu: function (p1, p2) {
+ openMenu: function (p1, p2, cb) {
if (p1 === 'details') {
- return this.openDetails(p2);
+ return this.openDetails(p2, cb);
+ }
+ },
+
+ getProductData: function (ref) {
+ var res = this.fluidbook.settings.basketReferences[ref];
+ if (res === undefined || res === undefined) {
+ return false;
+ }
+ return res;
+ },
+
+ openDetails(reference, callback) {
+ var data = this.getProductData(reference);
+ if (!data) {
+ this.fluidbook.tooltip.displayTooltip('No product matches this EAN');
+ return false;
+ }
+
+ var res = '<div id="grandvision-details">';
+ res += this.fluidbook.menu.getCaption('', true);
+ res += '<div class="content">';
+ res += '<div class="grandvision-details-infos">'
+ res += '<h2>' + data['Model Code'] + '</h2>';
+ res += '<ul class="infos">';
+ res += '<li>Brand: ' + data.BRAND + '</li>';
+ res += '<li>Category: ' + data.Category + '</li>';
+ res += '<li>Color: ' + data['Color Code'] + ' ' + data['Colour Description'] + '</li>';
+ if (data.Gender !== '') {
+ res += '<li>Gender: ' + data.Gender + '</li>';
+ }
+ res += '<li>EAN: ' + reference + '</li>';
+ res += '</ul>';
+ res += '<a href="#" data-cart-ref="' + reference + '">' + getSpriteIcon("external-extra-icon-burger") + ' Add to my selection</a>';
+ res += '</div>';
+ res += this.getProductSlideshow(reference, data);
+ res += '</div>';
+ res += '</div>';
+
+ this.fluidbook.menu.viewWrap(res, 'cart-grandvision-details', 'data-max-width="810" data-min-width="810"');
+
+ if (callback !== undefined) {
+ callback();
+ }
+ },
+
+ getProductSlideshow: function (ref, data) {
+ var slides = '';
+ this.nbslides = 0;
+ this.currentSlide = 0;
+ this.transitioning = false;
+ var o=1;
+ if (data.front) {
+ slides += '<div class="slide" style="opacity: '+o+';"><img src="data/commerce/' + ref + '-front.jpg" /></div>';
+ this.nbslides++;
+ o=0;
+ }
+ if (data.angle) {
+ slides += '<div class="slide" style="opacity: '+o+';"><img src="data/commerce/' + ref + '-angle.jpg" /></div>';
+ this.nbslides++;
+ o=0;
+ }
+ if (data['360']) {
+ slides += '<div class="slide" style="opacity: '+o+';"><video src="data/commerce/' + ref + '-360.mp4" autoplay muted loop preload /></div>';
+ this.nbslides++;
+ o=0;
}
+ if (this.nbslides === 0) {
+ return '';
+ }
+ var res = '<div class="grandvision-slideshow">';
+ res += '<div class="slides">';
+ res += slides;
+ res += '</div>';
+ if (this.nbslides >= 2) {
+ res += '<a href="#" class="prev">' + getSpriteIcon('interface-prev') + '</a>';
+ res += '<a href="#" class="next">' + getSpriteIcon('interface-next') + '</a>';
+ res += '<nav class="dots">';
+ for (var i = 0; i < this.nbslides; i++) {
+ var c='';
+ if(i===0){
+ c=' class="active"';
+ }
+ res += '<a href="#" '+c+' data-i="' + i + '"></a>';
+ }
+ res += '</nav>';
+ }
+ res += '</div>';
+ return res;
+ },
+
+ gotoSlide: function (i, dir) {
+ if(this.transitioning){
+ return;
+ }
+ this.transitioning=true;
+ var $this = this;
+ this.nextSlideIndex = this.normalizeSlide(i);
+ var t = 0.6;
+ var w = 360;
+ TweenMax.to($('.grandvision-slideshow .slide:eq(' + this.currentSlide + ')'), t, {left: w * dir*-1, opacity: 0});
+ TweenMax.fromTo($('.grandvision-slideshow .slide:eq(' + this.nextSlideIndex + ')'), t, {left: w * dir , opacity: 0}, {
+ left: 0,
+ opacity: 1,
+ onComplete: function () {
+ $this.endTransition();
+ }
+ });
+ },
+
+ endTransition: function () {
+ this.transitioning = false;
+ this.currentSlide = this.nextSlideIndex;
+ $('.grandvision-slideshow .dots a').removeClass('active');
+ $('.grandvision-slideshow .dots a:eq('+this.currentSlide+')').addClass('active');
+ },
+
+ normalizeSlide: function (i) {
+ return (i + this.nbslides) % this.nbslides;
+ },
+ nextSlide: function () {
+ this.gotoSlide(this.currentSlide + 1, 1);
+ },
+
+ prevSlide: function () {
+ this.gotoSlide(this.currentSlide - 1, -1);
},
- openDetails(reference) {
+ addToCart: function (ref, quantity) {
+ if (this.items.indexOf(ref) === -1) {
+ this.items.push(ref);
+ this.save();
+ }
+ return true;
+ },
+
+ removeFromCart: function (key) {
+ this.items.splice(key, 1);
+ this.save();
+ },
+
+ save: function () {
+ this.fluidbook.cache.set('cart', this.getItems());
+ this.fluidbook.cart.updateLinks();
+ },
+ getItems: function () {
+ var res = [];
+ var $this = this;
+ $(this.items).each(function (i, ref) {
+ if ($this.data[ref] !== undefined && $this.data[ref] !== null) {
+ res.push(ref);
+ }
+ });
+ return res;
},
};
\ No newline at end of file