(function (ns) { /** * @alias app.gallery.View */ ns.View = function () { this.construct.apply(this, arguments); }; ns.View.prototype.construct = function (options) { this.options = $.extend( { type: undefined, containerId: undefined }, options ); this.container = $('#' + this.options.containerId); if (!this.container.length) { alert('Gallery container was not found.'); return; } switch (this.options.type) { case 'list': this.initListView(); break; case 'slider': this.initSliderView(); break; default: alert('Unknown gallery type.'); return; } }; /** * @see http://fancyapps.com/fancybox/#docs */ ns.View.prototype.initListView = function () { $('a', this.container).fancybox({ nextEffect: 'fade', prevEffect: 'fade', margin: 10, minWidth: 270, helpers: { title: {type: 'inside'} }, beforeShow: this.onBeforeShow }); var thisHash = window.location.hash; if (thisHash) { $(thisHash).trigger('click'); } }; ns.View.prototype.onBeforeShow = function () { this.title = '' + this.title + '
' + $(this.element).find('img').data('description'); }; /** * @see http://dimsemenov.com/plugins/royal-slider/documentation */ ns.View.prototype.initSliderView = function () { this.container.css('display', ''); this.container.royalSlider({ addActiveClass: true, arrowsNav: false, controlNavigation: 'none', autoScaleSlider: true, autoScaleSliderWidth: 960, autoScaleSliderHeight: 640, imageScalePadding: 10, imageScaleMode: 'fit', loop: true, fadeinLoadedSlide: false, globalCaption: true, keyboardNavEnabled: true, globalCaptionInside: false, hashchange: { enabled: true, change: true, prefix: 'image-', map: this.createId2numMap() }, visibleNearby: { enabled: true, centerArea: 0.5, center: true, breakpoint: 650, breakpointCenterArea: 0.64, navigateByCenterClick: true } }); }; /** * Create slideId => slideNum map * Method should be called before slider initialization */ ns.View.prototype.createId2numMap = function () { var map = {}, i, l, id, slide, slides = this.container.children(); for (i = 0, l = slides.length; i < l; ++i) { slide = slides[i]; id = (slide.dataset) ? slide.dataset.id : slide.getAttribute('data-id'); map[+id] = i; } return map; }; })(qs.defineNS('app.gallery'));