Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow targeting of non-body elements #21

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 33 additions & 25 deletions jquery.vegas.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,18 @@
fade: 0,
loading: true,
load: function() {},
complete: function() {}
complete: function() {},
bgtarget: 'body'
}
$.extend( options, $.vegas.defaults.background, settings );

if ( options.loading ) {
loading();
loading(options);
}

var $new = $background.clone();
$new.css( {
'position': 'fixed',
'position': 'absolute',
'left': '0px',
'top': '0px'
})
Expand All @@ -81,14 +82,14 @@
$('.vegas-background')
.not(this)
.remove();
$( 'body' ).trigger( 'vegascomplete', [ this, step - 1 ] );
$( options.bgtarget ).trigger( 'vegascomplete', [ this, step - 1 ] );
options.complete.apply( $new, [ step - 1 ] );
});
} else {
$new.hide()
.prependTo( 'body' )
.prependTo( options.bgtarget )
.fadeIn( options.fade, function() {
$( 'body' ).trigger( 'vegascomplete', [ this, step - 1 ] );
$( options.bgtarget ).trigger( 'vegascomplete', [ this, step - 1 ] );
options.complete.apply( this, [ step - 1 ] );
});
}
Expand All @@ -101,11 +102,11 @@
loaded();
}

$( 'body' ).trigger( 'vegasload', [ $current.get(0), step - 1 ] );
$( options.bgtarget ).trigger( 'vegasload', [ $current.get(0), step - 1 ] );
options.load.apply( $current.get(0), [ step - 1 ] );

if ( step ) {
$( 'body' ).trigger( 'vegaswalk', [ $current.get(0), step - 1 ] );
$( options.bgtarget ).trigger( 'vegaswalk', [ $current.get(0), step - 1 ] );
options.walk.apply( $current.get(0), [ step - 1 ] );
}
})
Expand Down Expand Up @@ -133,7 +134,8 @@
overlay: function( settings ) {
var options = {
src: null,
opacity: null
opacity: null,
bgtarget: 'body'
};
$.extend( options, $.vegas.defaults.overlay, settings );

Expand All @@ -143,7 +145,7 @@
.css( {
'margin': '0',
'padding': '0',
'position': 'fixed',
'position': 'absolute',
'left': '0px',
'top': '0px',
'width': '100%',
Expand All @@ -158,7 +160,7 @@
$overlay.css( 'opacity', options.opacity );
}

$overlay.prependTo( 'body' );
$overlay.prependTo( options.bgtarget );

return $.vegas;
},
Expand All @@ -170,7 +172,8 @@
delay: delay,
preload: false,
backgrounds: backgrounds,
walk: walk
walk: walk,
bgtarget: 'body'
};

$.extend( options, $.vegas.defaults.slideshow, settings );
Expand Down Expand Up @@ -211,6 +214,7 @@

var settings = backgrounds[ step++ ];
settings.walk = options.walk;
settings.bgtarget = options.bgtarget;

if ( typeof( settings.fade ) == 'undefined' ) {
settings.fade = options.fade;
Expand All @@ -227,7 +231,7 @@
if ( !keepPause ) {
paused = false;

$( 'body' ).trigger( 'vegasstart', [ $current.get(0), step - 1 ] );
$( options.bgtarget ).trigger( 'vegasstart', [ $current.get(0), step - 1 ] );
}

if ( !paused ) {
Expand All @@ -244,7 +248,7 @@
if ( step ) {
$.vegas( 'slideshow', { step: step }, true );

$( 'body' ).trigger( 'vegasnext', [ $current.get(0), step - 1, from - 1 ] );
$( options.bgtarget ).trigger( 'vegasnext', [ $current.get(0), step - 1, from - 1 ] );
}

return $.vegas;
Expand All @@ -257,7 +261,7 @@
if ( step ) {
$.vegas( 'slideshow', { step: step - 2 }, true );

$( 'body' ).trigger( 'vegasprevious', [ $current.get(0), step - 1, from - 1 ] );
$( options.bgtarget ).trigger( 'vegasprevious', [ $current.get(0), step - 1, from - 1 ] );
}

return $.vegas;
Expand All @@ -270,7 +274,7 @@
if ( step ) {
$.vegas( 'slideshow', { step: s }, true );

$( 'body' ).trigger( 'vegasjump', [ $current.get(0), step - 1, from - 1 ] );
$( options.bgtarget ).trigger( 'vegasjump', [ $current.get(0), step - 1, from - 1 ] );
}

return $.vegas;
Expand All @@ -283,7 +287,7 @@
paused = null;
clearInterval( timer );

$( 'body' ).trigger( 'vegasstop', [ $current.get(0), from - 1 ] );
$( options.bgtarget ).trigger( 'vegasstop', [ $current.get(0), from - 1 ] );

return $.vegas;
},
Expand All @@ -293,7 +297,7 @@
paused = true;
clearInterval( timer );

$( 'body' ).trigger( 'vegaspause', [ $current.get(0), step - 1 ] );
$( options.bgtarget ).trigger( 'vegaspause', [ $current.get(0), step - 1 ] );

return $.vegas;
},
Expand Down Expand Up @@ -336,7 +340,8 @@
function resize( $img, settings ) {
var options = {
align: 'center',
valign: 'center'
valign: 'center',
bgtarget: 'body'
}
$.extend( options, settings );

Expand All @@ -348,8 +353,8 @@
return;
}

var ww = $( window ).width(),
wh = $( window ).height(),
var ww = $( options.bgtarget ).width(),
wh = $( options.bgtarget ).height(),
iw = $img.width(),
ih = $img.height(),
rw = wh / ww,
Expand Down Expand Up @@ -399,8 +404,8 @@
}

// Display the loading indicator
function loading() {
$loading.prependTo( 'body' ).fadeIn();
function loading(options) {
$loading.prependTo( options.bgtarget ).fadeIn();
}

// Hide the loading indicator
Expand All @@ -412,8 +417,8 @@

// Get the background image from the body
function getBackground() {
if ( $( 'body' ).css( 'backgroundImage' ) ) {
return $( 'body' ).css( 'backgroundImage' ).replace( /url\("?(.*?)"?\)/i, '$1' );
if ( $( this.bgtarget ).css( 'backgroundImage' ) ) {
return $( this.bgtarget ).css( 'backgroundImage' ).replace( /url\("?(.*?)"?\)/i, '$1' );
}
}

Expand All @@ -438,6 +443,7 @@
// loading bool
// load: function
// complete: function
// bgtarget: string
},
slideshow: {
// fade: null
Expand All @@ -446,10 +452,12 @@
// backgrounds: array
// preload: bool
// walk: function
// bgtarget: string
},
overlay: {
// src: string
// opacity: float
// bgtarget: string
}
}
})( jQuery );