forked from malsup/cycle2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.cycle2.hash.js
43 lines (35 loc) · 1.08 KB
/
jquery.cycle2.hash.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*! hash plugin for Cycle2; version: BETA-20120910 */
(function($) {
"use strict";
$(document).on( 'cycle-pre-initialize', function( e, opts ) {
onHashChange( opts, true );
opts._onHashChange = function() {
onHashChange( opts, false );
};
$( window ).on( 'hashchange', opts._onHashChange);
});
$(document).on( 'cycle-update-view', function( e, opts, slideOpts ) {
if ( slideOpts.hash )
window.location.hash = slideOpts.hash;
});
$(document).on( 'cycle-destroyed', function( e, opts) {
if ( opts._onHashChange ) {
$( window ).off( 'hashchange', opts._onHashChange );
}
});
function onHashChange( opts, setStartingSlide ) {
var hash = window.location.hash.substring(1);
opts.slides.each(function(i) {
if ( $(this).data( 'cycle-hash' ) === hash ) {
if ( setStartingSlide === true ) {
opts.startingSlide = i;
}
else {
opts.nextSlide = i;
opts.API.prepareTx( true, false );
}
return false;
}
});
}
})(jQuery);