PageSourceSearch

https://news.az/style/free-simple-slider.js?v=51

js news.az collected 2026-10-02 02:52:13 UTC 11,542 bytes, 306 lines download raw bytes

1"use strict";
2//$(document).ready(function () {
3
4    (function ($) {
5        $.fn.freeSimpleSlider = function (options) {
6
7            //==== SETTINGS ====
8            var settings = $.extend({
9                time: 5000,
10                animation: "slide",
11                arrows: true,
12                dots: true
13            }, options);
14
15
16            // ==== "Each" refers to each slider on the page  ====
17            return this.each(function () {
18                var self = $(this);
19                var slideLength = self.children('li').length;
20                var timer = parseInt(settings.time, 10);
21
22
23                //====  adds new element to HTML's DOM tree ====
24                self.addClass('slider-box').wrap("<div class='free-simple-slider'></div>");
25                self.children('li:first').addClass('current');
26                if (settings.animation === "slide") {
27                    self.addClass('slide-animation');
28                }
29                if (settings.animation === "fade") {
30                    self.addClass('slide-fade');
31                }
32
33
34                // ==== ADD ARROWS ==== 
35                if (settings.arrows === true) {
36                    self.after('<span class="arrows prev-arrow"><img width="64" height="64" src="https://news.az/img/left2.png?v=3" alt="prev"></span><span class="arrows next-arrow"><img width="64" height="64" src="https://news.az/img/right2.png?v=3" alt="next"></span>');
37                }
38                // ==== ADD DOTS ====
39                if (settings.dots === true) {
40                    self.after('<ul class="slider-dots"></ul>');
41                    var dotsContainer = self.parent('.free-simple-slider').children('.slider-dots');
42                    for (var i = 0; i < slideLength; i++) {
43                        dotsContainer.append('<li></li>');
44                    }
45                    dotsContainer.children('li').eq(0).addClass('current');
46                }
47
48                // ==== img src attribute change to background ====
49				/*
50                self.children('li').children('img').each(function () {
51                    var imgUrl = $(this).attr('src');
52                    $(this).parent('li').css('background-image', 'url(' + imgUrl + ')');
53                });
54				*/
55
56
57                // ==== CHANGE SLIDES FUNCTION ==== function with slider animation
58                var changeSlides = (function (normalDirection) {
59
60                    var current = self.children('li.current');
61                    var currentIndex = self.children('li.current').index();
62                    var nextDot;
63                    var currentDot = dotsContainer.children('li.current');
64
65                    //==== Direction of changing slides ====
66                    var next;
67                    if (normalDirection === false) {
68                        next = self.children('li').eq(currentIndex - 1);
69
70                        if (currentIndex - 1 < 0) {
71                            next = self.children('li:last');
72                        }
73
74                    } else {
75                        next = self.children('li').eq(currentIndex + 1);
76                        if (currentIndex + 1 === slideLength) {
77                            next = self.children('li:first');
78                        }
79                    }
80
81
82                    // ==== ANIMATION BASIC ====
83                    if (settings.animation === "basic") {
84                        next.addClass('current');
85                        current.removeClass('current');
86                    }
87
88                    // ==== ANIMATION FADE IN/OUT ====
89                    if (settings.animation === "fade") {
90                        next.addClass('current');
91                        current.removeClass('current').addClass('prev');
92                        setTimeout(function () {
93                            self.children('li.prev').removeClass('prev');
94                        }, 500);
95                    }
96
97                    // ==== ANIMATION SLIDE ====
98                    if (settings.animation === "slide") {
99                        next.addClass('current');
100                        current.removeClass('current').addClass('prev');
101                        setTimeout(function () {
102                            self.children('li.prev').removeClass('prev');
103                        }, 250);
104                    }
105
106
107
108                    //==== DOTS CHANGE ====
109                    if (settings.dots === true) {
110                        nextDot = dotsContainer.children('li').eq(next.index());// next.index() <- allows to use the same logic as in slides change
111                        currentDot.removeClass('current');
112                        nextDot.addClass('current');
113                    }
114
115                });
116
117                // ==== FIRE FUNCTION INTERWAL startChangeSlides()==== fires "changeSlides" function after time which is set in timer variable
118                var interval;
119                function startChangeSlides() {
120                    interval = setInterval(function () {
121                        changeSlides(true);
122                    }, timer);
123                }
124                startChangeSlides();
125
126                // ==== DOT NAVIGATION ==== changing slide with choose animation after click on dot navigation
127                if (settings.dots === true) {
128                    dotsContainer.children('li').on("click", function () {
129
130                        clearInterval(interval);
131                        dotsContainer.children('li').removeClass('current');
132
133                        if (settings.animation === "basic") {
134                            self.children('li').removeClass('current');
135                        }
136
137                        if (settings.animation === "fade") {
138                            self.children('li.current').addClass('prev').removeClass('current');
139                            setTimeout(function () {
140                                self.children('li.prev').removeClass('prev');
141                            }, 500);
142                        }
143
144                        if (settings.animation === "slide") {
145                            self.children('li.current').addClass('prev').removeClass('current');
146                            setTimeout(function () {
147                                self.children('li.prev').removeClass('prev');
148                            }, 250);
149                        }
150
151                        $(this).addClass('current');
152                        var clickedDotIndex = $(this).index();
153                        self.children('li').eq(clickedDotIndex).addClass('current');
154                        startChangeSlides();
155                    });
156                }
157
158                // ==== ARROW NAVIGATION ==== Changing slides after click on arrow animation
159                if (settings.arrows === true) {
160                    self.parent('.free-simple-slider').children('.prev-arrow').on('click', function (event) {
161                        event.preventDefault();
162                        clearInterval(interval);
163                        changeSlides(false);
164                        startChangeSlides();
165                    });
166
167                    self.parent('.free-simple-slider').children('.next-arrow').on('click', function (event) {
168                        event.preventDefault();
169                        clearInterval(interval);
170                        changeSlides(true);
171                        startChangeSlides();
172                    });
173                }
174				
175				// ===== TOUCH EVENTS ilə SWIPE dəstəyi =====
176				/*
177				var startX = 0;
178				var endX = 0;
179
180				self.on("touchstart", function (e) {
181					startX = e.originalEvent.touches[0].clientX;
182				});
183
184				self.on("touchend", function (e) {
185					endX = e.originalEvent.changedTouches[0].clientX;
186					var diffX = startX - endX;
187
188					if (Math.abs(diffX) > 50) { // sürüşmə minimum məsafəsi
189						clearInterval(interval);
190						if (diffX > 0) {
191							// sola sürüşdürüləndə növbəti slayd
192							changeSlides(true);
193						} else {
194							// sağa sürüşdürüləndə əvvəlki slayd
195							changeSlides(false);
196						}
197						startChangeSlides();
198					}
199				});
200				
201				
202				//===== HAMMER PLUGIN WITH SWIPE EVENT =====
203                if (typeof Hammer !== "undefined") {
204                    var hammertime = new Hammer(self[0]);
205                    hammertime.on('swipeleft', function () {
206                        clearInterval(interval);
207                        changeSlides(true);
208                        startChangeSlides();
209                    });
210                    hammertime.on('swiperight', function () {
211                        clearInterval(interval);
212                        changeSlides(false);
213                        startChangeSlides();
214                    });
215                }
216				*/
217				
218				
219				
220				// ===== TOUCH EVENTS ilə SWIPE dəstəyi =====
221				var startX = 0;
222				var endX = 0;
223
224				self.on("touchstart", function (e) {
225					startX = e.originalEvent.touches[0].clientX;
226				});
227
228				self.on("touchend", function (e) {
229					endX = e.originalEvent.changedTouches[0].clientX;
230					var diffX = startX - endX;
231
232					if (Math.abs(diffX) > 50) { // sürüşmə minimum məsafəsi
233						clearInterval(interval);
234						if (diffX > 0) {
235							// sola sürüşdürüləndə növbəti slayd
236							changeSlides(true);
237						} else {
238							// sağa sürüşdürüləndə əvvəlki slayd
239							changeSlides(false);
240						}
241						startChangeSlides();
242					}
243				});
244
245				// ===== MOUSE EVENTS ilə SWIPE dəstəyi (Desktop üçün) =====
246				var isDragging = false;
247
248				self.on("mousedown", function (e) {
249					startX = e.clientX;
250					isDragging = true;
251					$(document).on("mousemove.slider mouseup.slider", handleMouseSwipe);
252					e.preventDefault(); // Text seçilməsin və ya drag konflikt olmasın
253				});
254
255				function handleMouseSwipe(e) {
256					if (e.type === "mouseup") {
257						if (isDragging) {
258							endX = e.clientX;
259							var diffX = startX - endX;
260
261							if (Math.abs(diffX) > 50) { // Eyni minimum məsafə
262								clearInterval(interval);
263								if (diffX > 0) {
264									// Sola sürüşdürüləndə növbəti slayd
265									changeSlides(true);
266								} else {
267									// Sağa sürüşdürüləndə əvvəlki slayd
268									changeSlides(false);
269								}
270								startChangeSlides();
271							}
272							isDragging = false;
273						}
274						$(document).off("mousemove.slider mouseup.slider", handleMouseSwipe);
275					}
276					// mousemove zamanı endX-i yeniləmək istəsən, buraya əlavə edə bilərsən (preview üçün)
277				}
278
279				//===== HAMMER PLUGIN WITH SWIPE EVENT =====
280				if (typeof Hammer !== "undefined") {
281					var hammertime = new Hammer(self[0]);
282					// Mouse dəstəyini gücləndirmək üçün (əgər lazım olsa):
283					// hammertime.get('swipe').set({ direction: Hammer.DIRECTION_HORIZONTAL });
284					hammertime.on('swipeleft', function () {
285						clearInterval(interval);
286						changeSlides(true);
287						startChangeSlides();
288					});
289					hammertime.on('swiperight', function () {
290						clearInterval(interval);
291						changeSlides(false);
292						startChangeSlides();
293					});
294				}
295				////////////////////////////////
296				
297
298
299            });
300        };
301
302    }(jQuery));
303//});
304
305
306

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.