From c96906ac673bb1e4fef186854e5a347b4f7aa2da Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 23 Feb 2014 20:57:47 +0100 Subject: [PATCH] Improved wcfSlideshow() and wcfImageviewer() --- wcfsetup/install/files/js/WCF.ImageViewer.js | 42 ++++++++++++-------- wcfsetup/install/files/js/WCF.js | 15 +++++++ 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.ImageViewer.js b/wcfsetup/install/files/js/WCF.ImageViewer.js index e67085c9c7..e05cadc3be 100644 --- a/wcfsetup/install/files/js/WCF.ImageViewer.js +++ b/wcfsetup/install/files/js/WCF.ImageViewer.js @@ -290,9 +290,12 @@ $.widget('ui.wcfImageViewer', { /** * Opens the image viewer. * + * @param object event * @return boolean */ - open: function() { + open: function(event) { + if (event) event.preventDefault(); + if (this._isOpen) { return false; } @@ -301,7 +304,7 @@ $.widget('ui.wcfImageViewer', { this._loadNextImages(true); } else { - this._render(); + this._render(false, this.element.data('targetImageID')); if (this._items > 1 && this._slideshowEnabled) { this.startSlideshow(); @@ -321,6 +324,8 @@ $.widget('ui.wcfImageViewer', { * @return boolean */ close: function() { + if (event) event.preventDefault(); + if (!this._isOpen) { return false; } @@ -397,31 +402,34 @@ $.widget('ui.wcfImageViewer', { */ _render: function(initialized, targetImageID) { this._container.addClass('open'); - + console.debug("_render(" + initialized + ", " + targetImageID + ")"); + var $thumbnail = null; if (initialized) { - var $thumbnail = this._ui.imageList.children('li:eq(0)'); + $thumbnail = this._ui.imageList.children('li:eq(0)'); this._thumbnailMarginRight = parseInt($thumbnail.css('marginRight').replace(/px$/, '')) || 0; this._thumbnailWidth = $thumbnail.outerWidth(true); this._thumbnailContainerWidth = this._ui.imageList.parent().innerWidth(); - if (targetImageID) { - this._ui.imageList.children('li').each(function(index, item) { - var $item = $(item); - if ($item.data('objectID') == targetImageID) { - $thumbnail = $item; - return false; - } - }); - } - - $thumbnail.trigger('click'); - this.moveToImage($thumbnail.data('index')); - if (this._items > 1 && this.options.enableSlideshow && !targetImageID) { this.startSlideshow(); } } + if (targetImageID) { + this._ui.imageList.children('li').each($.proxy(function(index, item) { + var $item = $(item); + if ($item.data('objectID') == targetImageID) { + $item.trigger('click'); + this.moveToImage($item.data('index')); + + return false; + } + }, this)); + } + else if ($thumbnail !== null) { + $thumbnail.trigger('click'); + } + this._toggleButtons(); // check if there is enough space to load more thumbnails diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 61d2400e14..8bcf58f4a7 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -9888,6 +9888,21 @@ $.widget('ui.wcfSlideshow', { $(this._buttonList.find('.icon').removeClass('active').get(this._index)).addClass('active'); this._itemList.css('left', this._index * (this._width + this.options.itemGap) * -1); + + this._trigger('moveTo', null, { index: this._index }); + }, + + /** + * Returns item by index or null if index is invalid. + * + * @return jQuery + */ + getItem: function(index) { + if (this._items[index]) { + return this._items[index]; + } + + return null; } }); -- 2.20.1