2013-08-07 08:59:08 +00:00
|
|
|
( function ( $ ) {
|
|
|
|
var LIP, lightboxHooks;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function LightboxInterface() {
|
|
|
|
lightboxHooks = window.lightboxHooks;
|
|
|
|
|
|
|
|
function handleFullscreenChange() {
|
|
|
|
// If we're no longer in fullscreen mode, make sure
|
2013-09-04 01:01:57 +00:00
|
|
|
if ( !lbinterface.fullscreenButtonJustPressed &&
|
2013-08-07 08:59:08 +00:00
|
|
|
!document.fullscreenElement &&
|
|
|
|
!document.mozFullScreenElement &&
|
|
|
|
!document.webkitFullScreenElement ) {
|
2013-09-04 01:01:57 +00:00
|
|
|
lbinterface.fullscreen();
|
2013-10-31 22:14:24 +00:00
|
|
|
} else if ( lbinterface.fullscreenButtonJustPressed ) {
|
2013-09-04 01:01:57 +00:00
|
|
|
lbinterface.fullscreenButtonJustPressed = false;
|
2013-08-07 08:59:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var result,
|
|
|
|
addToPre = [],
|
2013-09-04 01:01:57 +00:00
|
|
|
addToPost = [],
|
|
|
|
lbinterface = this;
|
2013-08-07 08:59:08 +00:00
|
|
|
|
|
|
|
this.$overlay = $( '<div>' )
|
|
|
|
.addClass( 'mlb-overlay' );
|
|
|
|
|
|
|
|
this.$wrapper = $( '<div>' )
|
|
|
|
.addClass( 'mlb-wrapper' );
|
|
|
|
|
|
|
|
this.$main = $( '<div>' )
|
|
|
|
.addClass( 'mlb-main' );
|
|
|
|
|
|
|
|
this.$imageDiv = $( '<div>' )
|
|
|
|
.addClass( 'mlb-image' );
|
|
|
|
|
|
|
|
this.$preDiv = $( '<div>' )
|
|
|
|
.addClass( 'mlb-pre-image' );
|
|
|
|
result = lightboxHooks.callAll( 'addToPreDiv', this, addToPre );
|
|
|
|
this.setupPreDiv( result, addToPre );
|
|
|
|
|
|
|
|
this.$postDiv = $( '<div>' )
|
|
|
|
.addClass( 'mlb-post-image' );
|
|
|
|
result = lightboxHooks.callAll( 'addToPostDiv', this, addToPost );
|
|
|
|
this.setupPostDiv( result, addToPost );
|
|
|
|
|
|
|
|
this.$main.append(
|
|
|
|
this.$preDiv,
|
|
|
|
this.$imageDiv,
|
|
|
|
this.$postDiv
|
|
|
|
);
|
|
|
|
|
|
|
|
this.$wrapper.append(
|
|
|
|
this.$main
|
|
|
|
);
|
|
|
|
|
2013-10-22 16:34:08 +00:00
|
|
|
lightboxHooks.callAll( 'modifyInterface', this );
|
2013-08-07 08:59:08 +00:00
|
|
|
|
|
|
|
window.addEventListener( 'keyup', function ( e ) {
|
|
|
|
if ( e.keyCode === 27 ) {
|
|
|
|
// Escape button pressed
|
2013-09-04 01:01:57 +00:00
|
|
|
lbinterface.unattach();
|
2013-10-23 23:35:05 +00:00
|
|
|
if ( lbinterface.isFullScreen ) {
|
|
|
|
lbinterface.fullscreen();
|
|
|
|
}
|
2013-08-07 08:59:08 +00:00
|
|
|
}
|
2013-09-04 01:01:57 +00:00
|
|
|
} );
|
2013-08-07 08:59:08 +00:00
|
|
|
|
2013-09-04 01:01:57 +00:00
|
|
|
window.addEventListener( 'fullscreenchange', handleFullscreenChange );
|
|
|
|
window.addEventListener( 'mozfullscreenchange', handleFullscreenChange );
|
|
|
|
window.addEventListener( 'webkitfullscreenchange', handleFullscreenChange );
|
2013-08-07 08:59:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LIP = LightboxInterface.prototype;
|
|
|
|
|
2013-10-23 23:51:34 +00:00
|
|
|
LIP.empty = function () {
|
|
|
|
this.$imageDiv.empty();
|
|
|
|
|
|
|
|
lightboxHooks.callAll( 'clearInterface', this );
|
|
|
|
};
|
|
|
|
|
2013-08-07 08:59:08 +00:00
|
|
|
LIP.attach = function () {
|
|
|
|
$( document.body )
|
|
|
|
.append(
|
|
|
|
this.$wrapper,
|
|
|
|
this.$overlay
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
LIP.unattach = function () {
|
|
|
|
this.$wrapper.detach();
|
|
|
|
this.$overlay.detach();
|
|
|
|
};
|
|
|
|
|
|
|
|
LIP.fullscreen = function () {
|
|
|
|
var fullscreen;
|
|
|
|
|
|
|
|
if ( this.isFullScreen ) {
|
|
|
|
if ( !document.fullscreenElement &&
|
|
|
|
!document.mozFullScreenElement &&
|
|
|
|
!document.webkitFullScreenElement ) {
|
|
|
|
if ( document.cancelFullScreen ) {
|
|
|
|
document.cancelFullScreen();
|
|
|
|
} else if ( document.mozCancelFullScreen ) {
|
|
|
|
document.mozCancelFullScreen();
|
|
|
|
} else if ( document.webkitCancelFullScreen ) {
|
|
|
|
document.webkitCancelFullScreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$wrapper.html( this.$main.detach() );
|
2013-10-18 21:51:33 +00:00
|
|
|
this.$fullscreen = this.$fullscreen.detach();
|
|
|
|
|
|
|
|
lightboxHooks.callAll( 'defullscreen', this );
|
2013-08-07 08:59:08 +00:00
|
|
|
} else {
|
|
|
|
this.$fullscreen = this.$fullscreen || $( '<div>' )
|
|
|
|
.addClass( 'mlb-fullscreen-div' );
|
|
|
|
|
|
|
|
this.$fullscreen.html( this.$main.detach() );
|
|
|
|
|
|
|
|
this.$wrapper.append( this.$fullscreen );
|
|
|
|
|
|
|
|
fullscreen = this.$fullscreen[0];
|
|
|
|
if ( fullscreen.requestFullScreen ) {
|
|
|
|
fullscreen.requestFullScreen();
|
|
|
|
} else if ( fullscreen.mozRequestFullScreen ) {
|
|
|
|
fullscreen.mozRequestFullScreen();
|
|
|
|
} else if ( fullscreen.webkitRequestFullScreen ) {
|
|
|
|
fullscreen.webkitRequestFullScreen();
|
|
|
|
}
|
2013-10-18 21:51:33 +00:00
|
|
|
|
|
|
|
lightboxHooks.callAll( 'fullscreen', this );
|
2013-08-07 08:59:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.isFullScreen = !this.isFullScreen;
|
|
|
|
};
|
|
|
|
|
|
|
|
LIP.load = function ( image ) {
|
|
|
|
var ele = image.getImageElement( function () {
|
|
|
|
iface.$image = $( ele );
|
2013-10-31 22:03:59 +00:00
|
|
|
iface.$imageDiv.append( iface.$image );
|
2013-09-04 01:01:57 +00:00
|
|
|
image.globalMaxWidth = iface.$image.width();
|
|
|
|
image.globalMaxHeight = iface.$image.height();
|
2013-10-23 23:35:05 +00:00
|
|
|
image.autoResize( ele, iface.isFullScreen ? 0.9 : 0.5 );
|
2013-08-07 08:59:08 +00:00
|
|
|
|
|
|
|
window.addEventListener( 'resize', function () {
|
2013-10-28 22:32:56 +00:00
|
|
|
var result = lightboxHooks.callAll( 'imageResize', iface );
|
|
|
|
|
|
|
|
if ( result !== false ) {
|
|
|
|
image.autoResize( iface.$image.get( 0 ), iface.isFullScreen ? 0.9 : 0.5 );
|
|
|
|
}
|
2013-08-07 08:59:08 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
lightboxHooks.callAll( 'imageLoaded', iface );
|
|
|
|
} ),
|
|
|
|
iface = this;
|
|
|
|
|
|
|
|
this.currentImage = image;
|
|
|
|
};
|
|
|
|
|
2013-10-28 22:32:56 +00:00
|
|
|
LIP.replaceImageWith = function ( imageEle ) {
|
|
|
|
var $image = $( imageEle );
|
|
|
|
|
|
|
|
this.currentImage.src = imageEle.src;
|
|
|
|
|
|
|
|
this.$image.replaceWith( $image );
|
|
|
|
this.$image = $image;
|
|
|
|
|
|
|
|
this.currentImage.globalMaxWidth = this.$image.width();
|
|
|
|
this.currentImage.globalMaxHeight = this.$image.height();
|
|
|
|
this.currentImage.autoResize( imageEle, this.isFullScreen ? 0.9 : 0.5 );
|
|
|
|
};
|
|
|
|
|
2013-08-07 08:59:08 +00:00
|
|
|
LIP.setupPreDiv = function ( buildDefaults, toAdd ) {
|
2013-09-04 01:01:57 +00:00
|
|
|
var lbinterface = this;
|
|
|
|
|
2013-08-07 08:59:08 +00:00
|
|
|
if ( buildDefaults ) {
|
|
|
|
this.$controlBar = $( '<div>' )
|
|
|
|
.addClass( 'mlb-controls' );
|
|
|
|
|
|
|
|
this.$closeButton = $( '<div>' )
|
|
|
|
.text( ' ' )
|
|
|
|
.addClass( 'mlb-close' )
|
2013-09-04 01:01:57 +00:00
|
|
|
.click( function () {
|
|
|
|
lbinterface.unattach();
|
|
|
|
} );
|
2013-08-07 08:59:08 +00:00
|
|
|
|
|
|
|
this.$fullscreenButton = $( '<div>' )
|
|
|
|
.text( ' ' )
|
|
|
|
.addClass( 'mlb-fullscreen' )
|
|
|
|
.click( function () {
|
2013-09-04 01:01:57 +00:00
|
|
|
lbinterface.fullscreenButtonJustPressed = true;
|
|
|
|
lbinterface.fullscreen();
|
|
|
|
} );
|
2013-08-07 08:59:08 +00:00
|
|
|
|
|
|
|
this.$controlBar.append(
|
|
|
|
this.$closeButton,
|
|
|
|
this.$fullscreenButton
|
|
|
|
);
|
|
|
|
|
|
|
|
this.$preDiv.append( this.$controlBar );
|
|
|
|
|
|
|
|
lightboxHooks.callAll( 'modifyDefaultPreDiv', this );
|
|
|
|
}
|
|
|
|
|
|
|
|
this.addElementsToDiv( this.$preDiv, toAdd );
|
|
|
|
};
|
|
|
|
|
|
|
|
LIP.setupPostDiv = function ( buildDefaults, toAdd ) {
|
|
|
|
if ( buildDefaults ) {
|
|
|
|
lightboxHooks.callAll( 'modifyDefaultPostDiv', this );
|
|
|
|
}
|
|
|
|
|
|
|
|
this.addElementsToDiv( this.$postDiv, toAdd );
|
|
|
|
};
|
|
|
|
|
|
|
|
LIP.addElementsToDiv = function ( $div, toAdd ) {
|
|
|
|
var i;
|
|
|
|
|
|
|
|
for ( i = 0; i < toAdd.length; i++ ) {
|
|
|
|
$div.append( toAdd[i] );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
window.LightboxInterface = LightboxInterface;
|
|
|
|
}( jQuery ) );
|