コード例 #1
0
ファイル: LightBox.js プロジェクト: MrBlaschke/flexcss
 /**
  * @param img
  * @private
  */
 _calculateContainer(img) {
     if (Settings.isIE()) {
         setTimeout(function () {
             this._imageContainer.style.height = img.offsetHeight + 'px';
         }.bind(this), 0);
     }
 }
コード例 #2
0
ファイル: LightBox.js プロジェクト: MrBlaschke/flexcss
                imageObj.addEventListener('load', function () {
                    this._imageContainer.className = 'image-container';
                    var img = document.createElement('img');
                    // current image
                    this.img = img;

                    img.src = imgSrc;
                    LightBox._setupMaxWidthHeight(target, img, imageObj);
                    this._imageContainer.appendChild(img);
                    this._imageContainer.style.backgroundImage = 'url(' + imgSrc + ')';

                    resolve(self._modalContainerDiv);
                    this._isLoading = false;

                    if (Settings.isIE()) {
                        self._resizeEvent = global.addEventListener('resize', function () {
                            setTimeout(function () {
                                self._imageContainer.style.height = img.offsetHeight + 'px';
                            }, 0);
                        });
                    }

                    if (self.options.registerPrevNextEvents) {
                        self._setupPrevNextStates();
                        // prev or next on touch/click
                        self._imageContainer.addEventListener(Settings.getTabEvent(), function (e) {
                            if (self.isLoading()) {
                                return;
                            }
                            e.preventDefault();

                            var ev = e;
                            var pageX = global.TouchEvent && ev instanceof TouchEvent ?
                                ev.changedTouches[0].pageX : ev.pageX;
                            var rect = self._imageContainer.getBoundingClientRect(), imgX = rect.left,
                                wrapperWidth = rect.width,
                                posX = pageX - imgX;

                            self.switchImageByDirection(wrapperWidth / 2 > posX).catch(function () {
                                self._runOptionalClose();
                            });
                        });

                        // register keyboard events
                        self._keyboardNextEvent = function (e) {
                            if (e.keyCode === KEY_NEXT || e.keyCode === KEY_PREV) {
                                if (self.isLoading()) {
                                    return;
                                }
                                self.switchImageByDirection(e.keyCode === KEY_PREV).catch(function () {
                                    self._runOptionalClose();
                                });
                            }
                        };
                        global.addEventListener('keydown', self._keyboardNextEvent);
                    } else {
                        self._imageContainer.addEventListener(Settings.getTabEvent(), function () {
                            self._runOptionalClose();
                        });
                    }

                    self.highRes(thumbnail, imgHighResolution);
                }.bind(this));