(function (ns) { /** * @alias app.ecommerce.product.View * @constructor */ ns.View = function () { this.construct.apply(this, arguments); }; ns.View.prototype.construct = function (options) { this.options = $.extend(true, { imageContainer: undefined, tabsContainer: undefined, image: { width: undefined, height: undefined }, gallery: [] }, options); this.imageContainer = $('#' + this.options.imageContainer); this.slider = null; this.initSlider(); this.tabsContainer = $('#' + this.options.tabsContainer); this.initTabs(); this.initReviews(); }; ns.View.prototype.initSlider = function () { this.imageContainer.css('display', 'block'); this.imageContainer.royalSlider({ globalCaption: true, numImagesToPreload: 2, transitionType: 'fade', fadeinLoadedSlide: false, autoScaleSlider: true, autoScaleSliderWidth: this.options.image.width, autoScaleSliderHeight: this.options.image.height, imgWidth: this.options.image.width, arrowsNav: false, navigateByClick: false, slidesSpacing: 0, imageScalePadding: 0, minSlideOffset: 0, controlNavigation: ((this.options.gallery.length <= 1) ? 'none' : 'thumbnails'), thumbs: { fitInViewport: false } }).data('royalSlider'); this.slider = this.imageContainer.data('royalSlider'); if (this.slider) { this.slider.ev.on('rsSlideClick', _.bind(this.onSlideClick, this)); } }; ns.View.prototype.onSlideClick = function (ev) { $.fancybox( this.options.gallery, { nextEffect: 'fade', prevEffect: 'fade', loop: true, index: ev.target.currSlideId, helpers: { title: { type : 'inside' } } } ); }; ns.View.prototype.initTabs = function () { var selector = ''; if (-1 != (startPos = document.location.href.indexOf('#'))) { var hash = document.location.href.substr(startPos); if (hash == '#reviews' || hash == '#write-review') { selector += ' a[href="#reviews"]'; } } if ('' == selector) { selector += ' a:first'; } $(selector, this.tabsContainer).trigger('click'); }; ns.View.prototype.initReviews = function () { $('.reviews-list, .write-review').on('click', _.bind(function () { $('a[href="#reviews"]', this.tabsContainer).trigger('click'); }, this)); }; })(qs.defineNS('app.ecommerce.product'));