Improved wcfSlideshow() and wcfImageviewer()
authorAlexander Ebert <ebert@woltlab.com>
Sun, 23 Feb 2014 19:57:47 +0000 (20:57 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 23 Feb 2014 19:57:47 +0000 (20:57 +0100)
wcfsetup/install/files/js/WCF.ImageViewer.js
wcfsetup/install/files/js/WCF.js

index e67085c9c713908566ad44930b95553b6683693e..e05cadc3be8dfb558d0bda49671c4c78bbe889ae 100644 (file)
@@ -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
index 61d2400e148ca6ef59752cc195a2b28228227585..8bcf58f4a7f7806814f93c1ba9b8b78b23f80381 100755 (executable)
@@ -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;
        }
 });