summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Häggqvist <[email protected]>2014-06-27 17:23:35 +0200
committerVictor Häggqvist <[email protected]>2014-06-27 17:23:35 +0200
commit66bf57fb29f6b25e2258ab966bf13f7a44889cfc (patch)
treeee1ba0bdf3baa3675b46ce0690db1ce8a2e4b6d3
parentf161285163a5c5ed54d37ed9ca7f0d283f560e8f (diff)
break out demo js
-rw-r--r--demo.js125
-rw-r--r--index.php137
2 files changed, 126 insertions, 136 deletions
diff --git a/demo.js b/demo.js
new file mode 100644
index 0000000..cae2059
--- /dev/null
+++ b/demo.js
@@ -0,0 +1,125 @@
+$( function() {
+
+ // Show and hide loader
+ var activityIndicatorOn = function() {
+ $('<div id="imagelightbox-loading"><div></div></div>' ).appendTo('body');
+ },
+ activityIndicatorOff = function() {
+ $('#imagelightbox-loading').remove();
+ },
+
+ // Show and hide overlay
+ overlayOn = function() {
+ $('<div id="imagelightbox-overlay"></div>').appendTo('body');
+ },
+ overlayOff = function() {
+ $('#imagelightbox-overlay').remove();
+ },
+
+ // Show and hide close button
+ closeButtonOn = function(instance) {
+ $('<a href="#" id="imagelightbox-close">Close</a>').appendTo('body').on('click touchend', function(){ $(this).remove(); instance.quitImageLightbox(); return false; });
+ },
+ closeButtonOff = function() {
+ $('#imagelightbox-close').remove();
+ },
+
+ // Show and hide caption
+ captionOn = function() {
+ var description = $('a[href="' + $('#imagelightbox').attr('src') + '"] img').attr('alt');
+ if(description.length > 0)
+ $('<div id="imagelightbox-caption">' + description + '</div>').appendTo('body');
+ },
+ captionOff = function() {
+ $('#imagelightbox-caption').remove();
+ },
+
+ // Show, hide and keep navigation boubble updated
+ navigationOn = function(instance, selector) {
+ var images = $(selector);
+ if (images.length) {
+ var nav = $('<div id="imagelightbox-nav"></div>');
+ for(var i = 0; i < images.length; i++)
+ nav.append('<a href="#"></a>');
+
+ nav.appendTo('body');
+ nav.on('click touchend', function(){ return false; });
+
+ var navItems = nav.find('a');
+ navItems.on('click touchend', function() {
+ var $this = $(this);
+ if (images.eq($this.index()).attr('href') != $('#imagelightbox').attr('src'))
+ instance.switchImageLightbox($this.index());
+
+ navItems.removeClass('active');
+ navItems.eq($this.index()).addClass('active');
+
+ return false;
+ })
+ .on('touchend', function(){ return false; });
+ }
+ },
+ navigationUpdate = function(selector) {
+ var items = $('#imagelightbox-nav a');
+ items.removeClass('active');
+ items.eq( $( selector ).filter('[href="' + $('#imagelightbox').attr('src') + '"]').index( selector ) ).addClass('active');
+ },
+ navigationOff = function() {
+ $('#imagelightbox-nav').remove();
+ };
+
+ // WITH ACTIVITY INDICATION
+ $('a[data-imagelightbox="0"]').imageLightbox(
+ {
+ onLoadStart: function() { activityIndicatorOn(); },
+ onLoadEnd: function() { activityIndicatorOff(); },
+ onEnd: function() { activityIndicatorOff(); }
+ });
+
+ // WITH OVERLAY & ACTIVITY INDICATION
+ $('a[data-imagelightbox="1"]').imageLightbox(
+ {
+ onStart: function() { overlayOn(); },
+ onEnd: function() { overlayOff(); activityIndicatorOff(); },
+ onLoadStart: function() { activityIndicatorOn(); },
+ onLoadEnd: function() { activityIndicatorOff(); }
+ });
+
+ // WITH "CLOSE" BUTTON & ACTIVITY INDICATION
+ var instanceTwo = $('a[data-imagelightbox="2"]').imageLightbox(
+ {
+ quitOnDocClick: false,
+ onStart: function() { closeButtonOn( instanceTwo ); },
+ onEnd: function() { closeButtonOff(); activityIndicatorOff(); },
+ onLoadStart: function() { activityIndicatorOn(); },
+ onLoadEnd: function() { activityIndicatorOff(); }
+ });
+
+ // WITH CAPTION & ACTIVITY INDICATION
+ $('a[data-imagelightbox="3"]').imageLightbox(
+ {
+ onLoadStart: function() { captionOff(); activityIndicatorOn(); },
+ onLoadEnd: function() { captionOn(); activityIndicatorOff(); },
+ onEnd: function() { captionOff(); activityIndicatorOff(); }
+ });
+
+ // WITH DIRECTION REFERENCE
+ var selectorFour = 'a[data-imagelightbox="4"]';
+ var instanceFour = $(selectorFour).imageLightbox(
+ {
+ onStart: function() { navigationOn( instanceFour, selectorFour ); },
+ onEnd: function() { navigationOff(); activityIndicatorOff(); },
+ onLoadStart: function() { activityIndicatorOn(); },
+ onLoadEnd: function() { navigationUpdate( selectorFour ); activityIndicatorOff(); }
+ });
+
+ // ALL COMBINED
+ var instanceF = $('a[data-imagelightbox="5"]').imageLightbox(
+ {
+ onStart: function() { overlayOn(); closeButtonOn( instanceF ); },
+ onEnd: function() { overlayOff(); captionOff(); closeButtonOff(); activityIndicatorOff(); },
+ onLoadStart: function() { captionOff(); activityIndicatorOn(); },
+ onLoadEnd: function() { captionOn(); activityIndicatorOff(); }
+ });
+
+});
diff --git a/index.php b/index.php
index 81f6f08..2d70448 100644
--- a/index.php
+++ b/index.php
@@ -57,141 +57,6 @@ $headings = array(
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="./touch-imagelightbox.min.js"></script>
- <script>
-
- $( function()
- {
- var activityIndicatorOn = function()
- {
- $( '<div id="imagelightbox-loading"><div></div></div>' ).appendTo( 'body' );
- },
- activityIndicatorOff = function()
- {
- $( '#imagelightbox-loading' ).remove();
- },
-
- overlayOn = function()
- {
- $( '<div id="imagelightbox-overlay"></div>' ).appendTo( 'body' );
- },
- overlayOff = function()
- {
- $( '#imagelightbox-overlay' ).remove();
- },
-
- closeButtonOn = function( instance )
- {
- $( '<a href="#" id="imagelightbox-close">Close</a>' ).appendTo( 'body' ).on( 'click touchend', function(){ $( this ).remove(); instance.quitImageLightbox(); return false; });
- },
- closeButtonOff = function()
- {
- $( '#imagelightbox-close' ).remove();
- },
-
- captionOn = function()
- {
- var description = $( 'a[href="' + $( '#imagelightbox' ).attr( 'src' ) + '"] img' ).attr( 'alt' );
- if( description.length > 0 )
- $( '<div id="imagelightbox-caption">' + description + '</div>' ).appendTo( 'body' );
- },
- captionOff = function()
- {
- $( '#imagelightbox-caption' ).remove();
- },
-
- navigationOn = function( instance, selector )
- {
- var images = $( selector );
- if( images.length )
- {
- var nav = $( '<div id="imagelightbox-nav"></div>' );
- for( var i = 0; i < images.length; i++ )
- nav.append( '<a href="#"></a>' );
-
- nav.appendTo( 'body' );
- nav.on( 'click touchend', function(){ return false; });
-
- var navItems = nav.find( 'a' );
- navItems.on( 'click touchend', function()
- {
- var $this = $( this );
- if( images.eq( $this.index() ).attr( 'href' ) != $( '#imagelightbox' ).attr( 'src' ) )
- instance.switchImageLightbox( $this.index() );
-
- navItems.removeClass( 'active' );
- navItems.eq( $this.index() ).addClass( 'active' );
-
- return false;
- })
- .on( 'touchend', function(){ return false; });
- }
- },
- navigationUpdate = function( selector )
- {
- var items = $( '#imagelightbox-nav a' );
- items.removeClass( 'active' );
- items.eq( $( selector ).filter( '[href="' + $( '#imagelightbox' ).attr( 'src' ) + '"]' ).index( selector ) ).addClass( 'active' );
- },
- navigationOff = function()
- {
- $( '#imagelightbox-nav' ).remove();
- };
-
- // WITH ACTIVITY INDICATION
- $( 'a[data-imagelightbox="0"]' ).imageLightbox(
- {
- onLoadStart: function() { activityIndicatorOn(); },
- onLoadEnd: function() { activityIndicatorOff(); },
- onEnd: function() { activityIndicatorOff(); }
- });
-
- // WITH OVERLAY & ACTIVITY INDICATION
- $( 'a[data-imagelightbox="1"]' ).imageLightbox(
- {
- onStart: function() { overlayOn(); },
- onEnd: function() { overlayOff(); activityIndicatorOff(); },
- onLoadStart: function() { activityIndicatorOn(); },
- onLoadEnd: function() { activityIndicatorOff(); }
- });
-
- // WITH "CLOSE" BUTTON & ACTIVITY INDICATION
- var instanceC = $( 'a[data-imagelightbox="2"]' ).imageLightbox(
- {
- quitOnDocClick: false,
- onStart: function() { closeButtonOn( instanceC ); },
- onEnd: function() { closeButtonOff(); activityIndicatorOff(); },
- onLoadStart: function() { activityIndicatorOn(); },
- onLoadEnd: function() { activityIndicatorOff(); }
- });
-
- // WITH CAPTION & ACTIVITY INDICATION
- $( 'a[data-imagelightbox="3"]' ).imageLightbox(
- {
- onLoadStart: function() { captionOff(); activityIndicatorOn(); },
- onLoadEnd: function() { captionOn(); activityIndicatorOff(); },
- onEnd: function() { captionOff(); activityIndicatorOff(); }
- });
-
- // WITH DIRECTION REFERENCE
- var selectorE = 'a[data-imagelightbox="4"]';
- var instanceE = $( selectorE ).imageLightbox(
- {
- onStart: function() { navigationOn( instanceE, selectorE ); },
- onEnd: function() { navigationOff(); activityIndicatorOff(); },
- onLoadStart: function() { activityIndicatorOn(); },
- onLoadEnd: function() { navigationUpdate( selectorE ); activityIndicatorOff(); }
- });
-
- // ALL COMBINED
- var instanceF = $( 'a[data-imagelightbox="5"]' ).imageLightbox(
- {
- onStart: function() { overlayOn(); closeButtonOn( instanceF ); },
- onEnd: function() { overlayOff(); captionOff(); closeButtonOff(); activityIndicatorOff(); },
- onLoadStart: function() { captionOff(); activityIndicatorOn(); },
- onLoadEnd: function() { captionOn(); activityIndicatorOff(); }
- });
-
- });
- </script>
+ <script src="./demo.js"></script>
</body>
</html>