scratch – Blame information for rev 117
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
117 | office | 1 | /*========================= |
2 | Init/Destroy |
||
3 | ===========================*/ |
||
4 | s.init = function () { |
||
5 | if (s.params.loop) s.createLoop(); |
||
6 | s.updateContainerSize(); |
||
7 | s.updateSlidesSize(); |
||
8 | s.updatePagination(); |
||
9 | if (s.params.scrollbar && s.scrollbar) { |
||
10 | s.scrollbar.set(); |
||
11 | if (s.params.scrollbarDraggable) { |
||
12 | s.scrollbar.enableDraggable(); |
||
13 | } |
||
14 | } |
||
15 | if (s.params.effect !== 'slide' && s.effects[s.params.effect]) { |
||
16 | if (!s.params.loop) s.updateProgress(); |
||
17 | s.effects[s.params.effect].setTranslate(); |
||
18 | } |
||
19 | if (s.params.loop) { |
||
20 | s.slideTo(s.params.initialSlide + s.loopedSlides, 0, s.params.runCallbacksOnInit); |
||
21 | } |
||
22 | else { |
||
23 | s.slideTo(s.params.initialSlide, 0, s.params.runCallbacksOnInit); |
||
24 | if (s.params.initialSlide === 0) { |
||
25 | if (s.parallax && s.params.parallax) s.parallax.setTranslate(); |
||
26 | if (s.lazy && s.params.lazyLoading) { |
||
27 | s.lazy.load(); |
||
28 | s.lazy.initialImageLoaded = true; |
||
29 | } |
||
30 | } |
||
31 | } |
||
32 | s.attachEvents(); |
||
33 | if (s.params.observer && s.support.observer) { |
||
34 | s.initObservers(); |
||
35 | } |
||
36 | if (s.params.preloadImages && !s.params.lazyLoading) { |
||
37 | s.preloadImages(); |
||
38 | } |
||
39 | if (s.params.zoom && s.zoom) { |
||
40 | s.zoom.init(); |
||
41 | } |
||
42 | if (s.params.autoplay) { |
||
43 | s.startAutoplay(); |
||
44 | } |
||
45 | if (s.params.keyboardControl) { |
||
46 | if (s.enableKeyboardControl) s.enableKeyboardControl(); |
||
47 | } |
||
48 | if (s.params.mousewheelControl) { |
||
49 | if (s.enableMousewheelControl) s.enableMousewheelControl(); |
||
50 | } |
||
51 | // Deprecated hashnavReplaceState changed to replaceState for use in hashnav and history |
||
52 | if (s.params.hashnavReplaceState) { |
||
53 | s.params.replaceState = s.params.hashnavReplaceState; |
||
54 | } |
||
55 | if (s.params.history) { |
||
56 | if (s.history) s.history.init(); |
||
57 | } |
||
58 | if (s.params.hashnav) { |
||
59 | if (s.hashnav) s.hashnav.init(); |
||
60 | } |
||
61 | if (s.params.a11y && s.a11y) s.a11y.init(); |
||
62 | s.emit('onInit', s); |
||
63 | }; |
||
64 | |||
65 | // Cleanup dynamic styles |
||
66 | s.cleanupStyles = function () { |
||
67 | // Container |
||
68 | s.container.removeClass(s.classNames.join(' ')).removeAttr('style'); |
||
69 | |||
70 | // Wrapper |
||
71 | s.wrapper.removeAttr('style'); |
||
72 | |||
73 | // Slides |
||
74 | if (s.slides && s.slides.length) { |
||
75 | s.slides |
||
76 | .removeClass([ |
||
77 | s.params.slideVisibleClass, |
||
78 | s.params.slideActiveClass, |
||
79 | s.params.slideNextClass, |
||
80 | s.params.slidePrevClass |
||
81 | ].join(' ')) |
||
82 | .removeAttr('style') |
||
83 | .removeAttr('data-swiper-column') |
||
84 | .removeAttr('data-swiper-row'); |
||
85 | } |
||
86 | |||
87 | // Pagination/Bullets |
||
88 | if (s.paginationContainer && s.paginationContainer.length) { |
||
89 | s.paginationContainer.removeClass(s.params.paginationHiddenClass); |
||
90 | } |
||
91 | if (s.bullets && s.bullets.length) { |
||
92 | s.bullets.removeClass(s.params.bulletActiveClass); |
||
93 | } |
||
94 | |||
95 | // Buttons |
||
96 | if (s.params.prevButton) $(s.params.prevButton).removeClass(s.params.buttonDisabledClass); |
||
97 | if (s.params.nextButton) $(s.params.nextButton).removeClass(s.params.buttonDisabledClass); |
||
98 | |||
99 | // Scrollbar |
||
100 | if (s.params.scrollbar && s.scrollbar) { |
||
101 | if (s.scrollbar.track && s.scrollbar.track.length) s.scrollbar.track.removeAttr('style'); |
||
102 | if (s.scrollbar.drag && s.scrollbar.drag.length) s.scrollbar.drag.removeAttr('style'); |
||
103 | } |
||
104 | }; |
||
105 | |||
106 | // Destroy |
||
107 | s.destroy = function (deleteInstance, cleanupStyles) { |
||
108 | // Detach evebts |
||
109 | s.detachEvents(); |
||
110 | // Stop autoplay |
||
111 | s.stopAutoplay(); |
||
112 | // Disable draggable |
||
113 | if (s.params.scrollbar && s.scrollbar) { |
||
114 | if (s.params.scrollbarDraggable) { |
||
115 | s.scrollbar.disableDraggable(); |
||
116 | } |
||
117 | } |
||
118 | // Destroy loop |
||
119 | if (s.params.loop) { |
||
120 | s.destroyLoop(); |
||
121 | } |
||
122 | // Cleanup styles |
||
123 | if (cleanupStyles) { |
||
124 | s.cleanupStyles(); |
||
125 | } |
||
126 | // Disconnect observer |
||
127 | s.disconnectObservers(); |
||
128 | |||
129 | // Destroy zoom |
||
130 | if (s.params.zoom && s.zoom) { |
||
131 | s.zoom.destroy(); |
||
132 | } |
||
133 | // Disable keyboard/mousewheel |
||
134 | if (s.params.keyboardControl) { |
||
135 | if (s.disableKeyboardControl) s.disableKeyboardControl(); |
||
136 | } |
||
137 | if (s.params.mousewheelControl) { |
||
138 | if (s.disableMousewheelControl) s.disableMousewheelControl(); |
||
139 | } |
||
140 | // Disable a11y |
||
141 | if (s.params.a11y && s.a11y) s.a11y.destroy(); |
||
142 | // Delete history popstate |
||
143 | if (s.params.history && !s.params.replaceState) { |
||
144 | window.removeEventListener('popstate', s.history.setHistoryPopState); |
||
145 | } |
||
146 | if (s.params.hashnav && s.hashnav) { |
||
147 | s.hashnav.destroy(); |
||
148 | } |
||
149 | // Destroy callback |
||
150 | s.emit('onDestroy'); |
||
151 | // Delete instance |
||
152 | if (deleteInstance !== false) s = null; |
||
153 | }; |
||
154 | |||
155 | s.init(); |