/** * @file slide_gallery.js * @brief Slideshow type image gallery plugin * @author NAVER (developers@xpressengine.com) **/ (function($){ var slideShow = xe.createPlugin('slideShow', { _holders : {}, _thumbs : {}, _current : {}, init : function() { this._holders = {}; this._thumbs = {}; this._current = {}; }, API_SHOW_SLIDE : function(sender, params) { var self=this, srl = params[0], key = '@'+srl, imgs, $zone, $thumb, $holder, i, c; var p = params; imgs = this.cast('GET_IMAGES', [srl]); if(!imgs.length) return; for(var i=0, nLen=imgs.length; i= imgs.length) side = 0; this.cast('SET_SLIDE', [srl, side]); }, API_NEXT_SLIDE : function(sender, params) { this._showSideSlide(params[0], +1); }, API_PREV_SLIDE : function(sender, params) { this._showSideSlide(params[0], -1); }, API_SET_SLIDE : function(sender, params) { var srl = params[0], idx = params[1], imgs, im, $holder, iwidth, w1, w2, h1, h2, scale; imgs = this.cast('GET_IMAGES', [srl]); if(!imgs.length) return; if(!is_def(im=imgs[idx])) return; // set current this._current['@'+srl] = idx; // change index indicator $('#zone_gallery_navigator_status_'+srl).text((idx+1)+'/'+imgs.length); // highlight next thunmbnail this._thumbs['@'+srl] .find('img') .eq(idx) .animate({opacity:1}) .end() .not(':eq('+idx+')') .animate({opacity:0.5}); // show next image smoothly $holder = this._holders['@'+srl]; iwidth = $holder.parent().innerWidth(); w1 = im.$obj.prop('width'); h1 = im.$obj.prop('height'); if (w1 == 0){ w1 = im.$obj.attr('width'); } if(h1 ==0){ h1 = im.$obj.attr('height'); } if(w1 > iwidth - 20) { w2 = iwidth - 20; scale = w2 / w1; h2 = Math.floor(h1 * scale); w1 = w2; h1 = h2; im.$obj.css('cursor', 'pointer'); im.$obj.attr('rel', 'xe_gallery'); } im.$obj.css({width:w1, height:h1, margin:'0 10px'}); $holder.empty().append(im.$obj); } }); var gallery = xe.getApp('Gallery')[0]; if(gallery) gallery.registerPlugin(new slideShow); })(jQuery);