PluginProbe
Post Grid Gutenberg Blocks – PostX / trunk
Post Grid Gutenberg Blocks – PostX vtrunk
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
ultimate-post / assets / js / customSlider.js

customSlider.js in Post Grid Gutenberg Blocks – PostX trunk, at assets/js/customSlider.js

463 lines 12.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function ($) {
2 "use strict";
3 $.fn.UltpSlider = function (options) {
4 /*Merge options and default options*/
5 let opts = $.extend({}, $.fn.UltpSlider.defaults, options);
6 /*Functions Scope*/
7 let thisTicker = $(this),
8 intervalID,
9 timeoutID,
10 isPause = false;
11 let pauseVal = true;
12 let onPressTime = 0;
13
14 /*Always wrap, used in many place*/
15 thisTicker.wrap("<div class='acmeticker-wrap'></div>");
16 /*Wrap is always relative*/
17 thisTicker.parent().css({
18 position: "relative",
19 });
20 thisTicker
21 .children()
22 .first()
23 .addClass("active"); /* ==== ADD active class to first item ===== */
24
25 /* ==================================================
26 horizontal , vertical and typewriter Control
27 ===================================================== */
28 if (
29 opts.type == "horizontal" ||
30 opts.type == "vertical" ||
31 opts.type == "typewriter"
32 ) {
33 /* ==== typewriter ===== */
34 let typeAutoPlay = "";
35 if (opts.type == "typewriter") {
36 typeAutoPlay = setInterval(function () {
37 slidePlay();
38 }, opts.speed);
39 }
40
41 let sliderAutoPlay = "";
42 if (opts.type == "horizontal" || opts.type == "vertical") {
43 sliderAutoPlay = setInterval(function () {
44 slidePlay();
45 }, opts.speed);
46 }
47
48 /* ===== Prev Func ===== */
49 $(opts.controls.prev).on("click", function () {
50 if (opts.type == "horizontal" || opts.type == "vertical") {
51 clearInterval(sliderAutoPlay);
52 handleSlider("prev");
53 if (pauseVal) {
54 sliderAutoPlay = setInterval(function () {
55 slidePlay();
56 }, opts.speed);
57 }
58 }
59 if (opts.type == "typewriter") {
60 clearInterval(typeAutoPlay);
61 handleSlider("prev");
62 if (pauseVal) {
63 typeAutoPlay = setInterval(function () {
64 slidePlay();
65 }, opts.speed);
66 }
67 }
68 });
69
70 /* ===== Next Event ===== */
71 $(opts.controls.next).on("click", function () {
72 if (opts.type == "horizontal" || opts.type == "vertical") {
73 clearInterval(sliderAutoPlay);
74 handleSlider("next");
75 if (pauseVal) {
76 sliderAutoPlay = setInterval(function () {
77 slidePlay();
78 }, opts.speed);
79 }
80 }
81 if (opts.type == "typewriter") {
82 clearInterval(typeAutoPlay);
83 handleSlider("next");
84 if (pauseVal) {
85 typeAutoPlay = setInterval(function () {
86 slidePlay();
87 }, opts.speed);
88 }
89 }
90 });
91
92 /* ===== Pause Event ===== */
93 $(opts.controls.toggle).on("click", function () {
94 if (opts.type == "horizontal" || opts.type == "vertical") {
95 if (pauseVal) {
96 pauseVal = false;
97 clearInterval(sliderAutoPlay);
98 } else {
99 pauseVal = true;
100 clearInterval(sliderAutoPlay);
101 sliderAutoPlay = setInterval(function () {
102 slidePlay();
103 }, opts.speed);
104 }
105 }
106 if (opts.type == "typewriter") {
107 if (pauseVal) {
108 pauseVal = false;
109 clearInterval(typeAutoPlay);
110 } else {
111 pauseVal = true;
112 clearInterval(typeAutoPlay);
113 typeAutoPlay = setInterval(function () {
114 slidePlay();
115 }, opts.speed);
116 }
117 }
118 });
119
120 /* ===== Hover Pause Event ===== */
121 if (opts.pauseOnHover) {
122 thisTicker.on("mouseenter", function () {
123 if (opts.type === "typewriter") {
124 clearInterval(typeAutoPlay);
125 }
126 if (opts.type === "horizontal" || opts.type === "vertical") {
127 clearInterval(sliderAutoPlay);
128 }
129 });
130
131 thisTicker.on("mouseleave", function () {
132 if (opts.type === "typewriter" && pauseVal) {
133 typeAutoPlay = setInterval(function () {
134 slidePlay();
135 }, opts.speed);
136 }
137 if (
138 (opts.type === "horizontal" || opts.type === "vertical") &&
139 pauseVal
140 ) {
141 sliderAutoPlay = setInterval(function () {
142 slidePlay();
143 }, opts.speed);
144 }
145 });
146 }
147 }
148
149 /* =========================
150 Marque Slide Control
151 ============================ */
152 if (opts.type == "marquee") {
153 let marqueeSpeed = opts.speed;
154 let i = 0;
155 let mainWidth;
156 let dir = opts.direction;
157 let contentWidth = thisTicker.outerWidth();
158 let wrapperWidth = $(".ultp-newsTicker-wrap").outerWidth();
159 let rtl = $(document).find("body").hasClass("rtl");
160
161 if (dir == "right") {
162 mainWidth = wrapperWidth;
163 }
164 if (dir == "left") {
165 mainWidth = thisTicker.outerWidth();
166 }
167 let marqueeSlide = setInterval(function () {
168 if (mainWidth < i && dir == "left" && !rtl) {
169 i = -wrapperWidth;
170 }
171 // if(-(mainWidth) > i && dir == "left" && !rtl){
172 // i = wrapperWidth;
173 // }
174 if (mainWidth < i && dir == "right" && !rtl) {
175 i = -contentWidth;
176 }
177
178 /* ===== For RTL Support ===== */
179 if (contentWidth < i && dir == "right" && rtl) {
180 i = -wrapperWidth;
181 }
182 if (wrapperWidth < i && dir == "left" && rtl) {
183 i = -mainWidth;
184 }
185 thisTicker.css(dir, -i);
186 i++;
187 }, marqueeSpeed);
188
189 /* =====================
190 Prev Button Control
191 ======================== */
192 $(opts.controls.prev).on("click", function () {
193 if (!pauseVal) {
194 /* ===== If Slide Pause ===== */
195 pauseVal = true;
196 marqueeSlide = setInterval(function () {
197 if (mainWidth < i && dir == "left" && !rtl) {
198 i = -wrapperWidth;
199 }
200 if (-wrapperWidth > i && dir == "left" && !rtl) {
201 i = mainWidth - 100;
202 }
203 if (mainWidth < i && dir == "right" && !rtl) {
204 i = -contentWidth;
205 }
206
207 /* ===== For RTL Support ===== */
208 if (contentWidth < i && dir == "right" && rtl) {
209 i = -mainWidth;
210 }
211 if (wrapperWidth < i && dir == "left" && rtl) {
212 i = -mainWidth;
213 }
214 thisTicker.css(dir, -i);
215 i++;
216 }, marqueeSpeed);
217 } else {
218 if (-thisTicker.outerWidth() > i && dir == "right" && !rtl) {
219 // i = $(window).width();
220 i = mainWidth;
221 }
222 if (
223 i < -$(".ultp-newsTicker-wrap").outerWidth() &&
224 dir == "left" &&
225 !rtl
226 ) {
227 i = mainWidth;
228 }
229
230 /* ===== For RTL Support ===== */
231 if (-mainWidth > i && dir == "right" && rtl) {
232 i = thisTicker.outerWidth();
233 }
234 if (-mainWidth > i && dir == "left" && rtl) {
235 i = $(".ultp-newsTicker-wrap").outerWidth();
236 }
237 // let childWidth = thisTicker.outerWidth() / thisTicker.children().length;
238 i = i - 250;
239 }
240 });
241
242 /* ===== Onpress Event ===== */
243 $(opts.controls.prev)
244 .on("mousedown touchstart", function (e) {
245 onPressTime = setInterval(function () {
246 if (!rtl && dir == "right") {
247 if (i > -contentWidth) {
248 i = i - 30;
249 } else {
250 i = $(".ultp-newsTicker-wrap").outerWidth() - 10;
251 }
252 } else if (rtl && dir == "left") {
253 if (i < -contentWidth) {
254 i = $(".ultp-newsTicker-wrap").outerWidth() - 10;
255 }
256 i = i - 30;
257 } else if (!rtl && dir == "left") {
258 if (i < -$(".ultp-newsTicker-wrap").outerWidth()) {
259 i = contentWidth;
260 }
261 i = i - 30;
262 } else {
263 if (
264 i < -$(".ultp-newsTicker-wrap").outerWidth() &&
265 rtl &&
266 dir == "right"
267 ) {
268 i = contentWidth;
269 }
270 i = i - 30;
271 }
272 }, 100);
273 })
274 .bind("mouseup mouseleave touchend", function () {
275 clearInterval(onPressTime);
276 });
277
278 /* =====================
279 Next Event Control
280 ======================== */
281 $(opts.controls.next).on("click", function () {
282 if (!pauseVal) {
283 /* ===== If Slide Pause ===== */
284 pauseVal = true;
285 marqueeSlide = setInterval(function () {
286 if (mainWidth < i && dir == "left" && !rtl) {
287 i = -wrapperWidth;
288 }
289 // if(-(mainWidth) > i && dir == "left" && !rtl){
290 // i = wrapperWidth;
291 // }
292 if (mainWidth < i && dir == "right" && !rtl) {
293 i = -contentWidth;
294 }
295
296 /* ===== RTL Support ===== */
297 if (wrapperWidth < i && dir == "left" && rtl) {
298 i = -mainWidth;
299 }
300 if (contentWidth < i && dir == "right" && rtl) {
301 i = -mainWidth;
302 }
303 thisTicker.css(dir, -i);
304 i++;
305 }, marqueeSpeed);
306 } else {
307 // let ChildWidth = thisTicker.outerWidth() / thisTicker.children().length;
308 i = i + 250;
309 }
310 });
311
312 /* ======= Next Onpress Event ======= */
313 $(opts.controls.next)
314 .on("mousedown touchstart", function (e) {
315 onPressTime = setInterval(function () {
316 i = i + 80;
317 }, 80);
318 })
319 .bind("mouseup mouseleave touchend", function () {
320 clearInterval(onPressTime);
321 });
322
323 /* =====================
324 Pause Event Control
325 ======================== */
326 $(opts.controls.toggle).on("click", function () {
327 if (pauseVal) {
328 pauseVal = false;
329 clearInterval(marqueeSlide);
330 } else {
331 pauseVal = true;
332 marqueeSlide = setInterval(function () {
333 if (mainWidth < i && dir == "left" && !rtl) {
334 i = -wrapperWidth;
335 }
336 // if(-(mainWidth) > i && dir == "left" && !rtl){
337 // i = wrapperWidth;
338 // }
339 if (
340 $(".ultp-newsTicker-wrap").outerWidth() < i &&
341 dir == "left" &&
342 rtl
343 ) {
344 i = -(contentWidth + 100);
345 }
346 if (mainWidth < i && dir == "right" && !rtl) {
347 i = -contentWidth;
348 }
349 if (contentWidth < i && dir == "right" && rtl) {
350 i = -$(".ultp-newsTicker-wrap").outerWidth();
351 }
352 thisTicker.css(dir, -i);
353 i++;
354 }, marqueeSpeed);
355 }
356 });
357
358 /* ======= Hover Pause Control Button ======= */
359 if (opts.pauseOnHover) {
360 thisTicker.on("mouseenter", function () {
361 clearInterval(marqueeSlide);
362 });
363
364 thisTicker.on("mouseleave", function () {
365 if (pauseVal) {
366 marqueeSlide = setInterval(function () {
367 if (mainWidth < i && dir === "left" && !rtl) {
368 i = -$(".ultp-newsTicker-wrap").outerWidth();
369 }
370
371 if (
372 $(".ultp-newsTicker-wrap").outerWidth() < i &&
373 dir === "left" &&
374 rtl
375 ) {
376 i = -mainWidth;
377 }
378
379 if (
380 $(".ultp-newsTicker-wrap").outerWidth() < i &&
381 dir === "right" &&
382 !rtl
383 ) {
384 i = -contentWidth;
385 }
386
387 if (contentWidth < i && dir === "right" && rtl) {
388 i = -mainWidth;
389 }
390
391 thisTicker.css(dir, -i);
392 i++;
393 }, marqueeSpeed);
394 }
395 });
396 }
397 }
398 /* =====================================
399 Next Previous Auto Play Control
400 ===================================== */
401 function handleSlider(val) {
402 let slideIndex = thisTicker.find(".active").index();
403 if (slideIndex < 0) {
404 slideIndex = 0;
405 }
406 let index = 1;
407 if (val == "prev") {
408 thisTicker.children().eq(slideIndex).removeClass("active");
409 thisTicker
410 .children()
411 .eq(slideIndex - index)
412 .addClass("active");
413 }
414 if (val == "next") {
415 thisTicker.children().eq(slideIndex).removeClass("active");
416 if (slideIndex == thisTicker.children().length - 1) {
417 index = -(thisTicker.children().length - 1);
418 }
419 thisTicker
420 .children()
421 .eq(slideIndex + index)
422 .addClass("active");
423 }
424 }
425
426 /* ======= Auto Slide Function ======= */
427 function slidePlay() {
428 let index = 1;
429 let slideIndex = thisTicker.find(".active").index();
430 if (slideIndex < 0) {
431 slideIndex = 0;
432 }
433 thisTicker.children().eq(slideIndex).removeClass("active");
434 if (slideIndex == thisTicker.children().length - 1) {
435 index = -(thisTicker.children().length - 1);
436 }
437 thisTicker
438 .children()
439 .eq(slideIndex + index)
440 .addClass("active");
441 }
442 };
443
444 /* ====================
445 Default Value
446 ===================== */
447 $.fn.UltpSlider.defaults = {
448 /*Note: Marquee only take speed not autoplay*/
449 type: "horizontal" /*vertical/horizontal/marquee/typewriter*/,
450 autoplay: 2000 /*true/false/number*/ /*For vertical/horizontal 4000*/ /*For typewriter 2000*/,
451 speed: 50 /*true/false/number*/ /*For vertical/horizontal 600*/ /*For marquee 0.05*/ /*For typewriter 50*/,
452 direction:
453 "up" /*up/down/left/right*/ /*For vertical up/down*/ /*For horizontal/marquee right/left*/ /*For typewriter direction doesnot work*/,
454 pauseOnFocus: true,
455 pauseOnHover: true,
456 controls: {
457 prev: "" /*Can be used for vertical/horizontal/typewriter*/ /*not work for marquee*/,
458 next: "" /*Can be used for vertical/horizontal/typewriter*/ /*not work for marquee*/,
459 toggle: "" /*Can be used for vertical/horizontal/marquee/typewriter*/,
460 },
461 };
462 })(jQuery);
463