scratch – Blame information for rev 117
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
117 | office | 1 | /*========================= |
2 | Hash Navigation |
||
3 | ===========================*/ |
||
4 | s.hashnav = { |
||
5 | onHashCange: function (e, a) { |
||
6 | var newHash = document.location.hash.replace('#', ''); |
||
7 | var activeSlideHash = s.slides.eq(s.activeIndex).attr('data-hash'); |
||
8 | if (newHash !== activeSlideHash) { |
||
9 | s.slideTo(s.wrapper.children('.' + s.params.slideClass + '[data-hash="' + (newHash) + '"]').index()); |
||
10 | } |
||
11 | }, |
||
12 | attachEvents: function (detach) { |
||
13 | var action = detach ? 'off' : 'on'; |
||
14 | $(window)[action]('hashchange', s.hashnav.onHashCange); |
||
15 | }, |
||
16 | setHash: function () { |
||
17 | if (!s.hashnav.initialized || !s.params.hashnav) return; |
||
18 | if (s.params.replaceState && window.history && window.history.replaceState) { |
||
19 | window.history.replaceState(null, null, ('#' + s.slides.eq(s.activeIndex).attr('data-hash') || '')); |
||
20 | } else { |
||
21 | var slide = s.slides.eq(s.activeIndex); |
||
22 | var hash = slide.attr('data-hash') || slide.attr('data-history'); |
||
23 | document.location.hash = hash || ''; |
||
24 | } |
||
25 | }, |
||
26 | init: function () { |
||
27 | if (!s.params.hashnav || s.params.history) return; |
||
28 | s.hashnav.initialized = true; |
||
29 | var hash = document.location.hash.replace('#', ''); |
||
30 | if (hash) { |
||
31 | var speed = 0; |
||
32 | for (var i = 0, length = s.slides.length; i < length; i++) { |
||
33 | var slide = s.slides.eq(i); |
||
34 | var slideHash = slide.attr('data-hash') || slide.attr('data-history'); |
||
35 | if (slideHash === hash && !slide.hasClass(s.params.slideDuplicateClass)) { |
||
36 | var index = slide.index(); |
||
37 | s.slideTo(index, speed, s.params.runCallbacksOnInit, true); |
||
38 | } |
||
39 | } |
||
40 | } |
||
41 | if (s.params.hashnavWatchState) s.hashnav.attachEvents(); |
||
42 | }, |
||
43 | destroy: function () { |
||
44 | if (s.params.hashnavWatchState) s.hashnav.attachEvents(true); |
||
45 | } |
||
46 | }; |