PageSourceSearch

https://horoshie-kraski.ru/bitrix/templates/dresscode/js/dwCarousel.js?17736646718380

js horoshie-kraski.ru collected 2026-10-07 16:45:14 UTC 8,380 bytes, 252 lines download raw bytes

1(function($) {
2    jQuery.fn.dwCarousel = function(options) {
3
4        var options = $.extend({
5            resizeAutoParams: false,
6            slideItem: "li, .slideItem",
7            slideBox: ".slideBox",
8            resizeElement: false,
9            resizeWidth: false,
10            countElement: 6,
11            severity: 8,
12            speed: 400,
13        }, options);
14
15        options.tmpCountElement = options.countElement; //save original value
16
17        var $_this = $(this);
18        var $main = new Main($(this));
19
20        function Main(obj) {
21
22            this.ths = obj;
23            this.ul = $_this.find(options.slideBox);
24            this.li = this.ul.children(options.slideItem);
25            this.a =  this.ul.find("a");
26            this.qtyLI = this.li.length;
27            this.curPos = null;
28            this.startTouch = false;
29            this.startTouchPos = false;
30            this.clicking = false;
31            this.active = false;
32            this.lastWidth = 0;
33
34        }
35
36        // main functions
37
38        var onLoadUp = function(){
39
40            $_this.css({
41                "overflow" : "hidden",
42                "position" : "relative"
43            });
44
45            $main.ul.css({
46                "position": "relative",
47                "overflow" : "hidden",
48                "clear" : "both",
49                "left" : "0px",
50            });
51
52            $main.lastWidth = $(window).width();
53
54        };
55
56        var bindEvents = function(e){
57
58            if (e) {
59
60                if(typeof options.leftButton != "undefined" && options.leftButton != ""){
61                    $(document).on("click", options.leftButton, {direction: "left"}, moveUL);
62                }
63
64                if(typeof options.rightButton != "undefined" && options.rightButton != ""){
65                    $(document).on("click", options.rightButton, {direction: "right"}, moveUL);
66                }
67
68                $(document).on("mouseup touchend", touchEnd);
69
70
71                $main.ul.on("mousedown touchstart", touchStart);
72                $main.ul.on("mousemove touchmove", touchMove);
73                $main.active = true;
74
75            }
76        }
77
78        var resizeElements = function(count) {
79            $main.ul.css({
80                width: ($main.qtyLI * 100) + "%"
81            });
82
83            $main.li.css({
84                width: (100 / $main.qtyLI / count) + "%"
85            });
86        };
87
88        var calculateParams = function(windowSize){
89            var currentCount = options.tmpCountElement;
90            var tmpCount = 15360;
91            options.countElement = options.tmpCountElement;
92            if (options.resizeElement === true) {
93                if(options.resizeWidth !== false){
94                    options.countElement = Math.floor($_this.outerWidth() / options.resizeWidth);
95                }else if(options.resizeAutoParams !== false){
96                    $.each(options.resizeAutoParams, function(screenWidth, countElements) {
97                        if(parseFloat(windowSize) <= parseFloat(screenWidth)){
98                            if(parseFloat(tmpCount) > parseFloat(screenWidth)){
99                                options.countElement = countElements;
100                                tmpCount = screenWidth;
101                            }
102
103                        }
104                    });
105                }
106
107            }
108
109            if (options.countElement < $main.qtyLI) {
110
111                $(options.leftButton).show();
112                $(options.rightButton).show();
113
114                if (!$main.active) {
115                    $main.active = true;
116                    bindEvents(true);
117                }
118
119            } else {
120
121                $(options.leftButton).hide();
122                $(options.rightButton).hide();
123                $main.ul.unbind();
124                $main.active = false;
125
126            }
127
128            $main.ul.css("left", 0);
129
130        };
131
132        var moveUL = function(event) {
133            var direction = event.data.direction == "left" ? "left" : "right",
134                maxPos = $main.qtyLI - options.countElement,
135                animateValue = null;
136
137            if (direction == "left") {
138                if (!$main.curPos) {
139                    animateValue = "-" + (100 / options.countElement * maxPos) + "%";
140                    $main.curPos = Math.floor(maxPos);
141                } else {
142                    animateValue = "-" + (100 / options.countElement * --$main.curPos) + "%";
143                }
144            } else {
145                if (++$main.curPos >= maxPos) {
146                    $main.curPos = animateValue = 0;
147                } else {
148                    if(maxPos - $main.curPos < 1){
149                        animateValue = "-" + (100 / options.countElement * maxPos) + "%";
150                    }
151                    else{
152                        animateValue = "-" + (100 / options.countElement * $main.curPos) + "%";
153                    }
154                }
155            }
156
157            $main.ul.finish().animate({
158                "left": animateValue
159            }, options.speed);
160
161            event.preventDefault();
162        };
163
164        var touchStart = function(event) {
165            $main.startTouch = event.type == "touchstart" ? event.originalEvent.touches[0].pageX : event.pageX;
166            $main.startTouchPos = Math.abs(parseInt($main.ul.css("left"), 10));
167            if(event.type !== "touchstart"){
168                event.preventDefault();
169            }
170        };
171
172        var touchMove = function(event) {
173            if($main.startTouch !== false){
174                event.pageX = event.type == "touchmove" ? event.originalEvent.touches[0].pageX : event.pageX;
175                var animateValue = (-$main.startTouchPos - ($main.startTouch - event.pageX));
176                var maxPos = ($main.li.outerWidth() * $main.qtyLI) - (options.countElement * $main.li.outerWidth());
177
178                if (animateValue > 0) {
179                    animateValue /= 8;
180                } else if (maxPos < Math.abs(parseInt($main.ul.css("left")))) {
181                    animateValue = -(maxPos + ((Math.abs(animateValue) - maxPos) / 8));
182                }
183
184                $main.ul.stop().css({
185                    "left" : animateValue + "px"
186                });
187
188                $main.clicking = true;
189            }
190        };
191
192        var touchEnd = function(event) {
193
194            if ($main.startTouch !== false) {
195                var maxPos = ($main.li.outerWidth() * $main.qtyLI) - (options.countElement * $main.li.outerWidth()),
196                    posNow = parseInt($main.ul.css("left")),
197                    animateValue = null;
198                if (posNow > 0) {
199                    animateValue = 0;
200                } else if (Math.abs($main.startTouchPos - Math.abs(posNow)) < 30) {
201                    animateValue = "-" + $main.startTouchPos;
202                    $main.clicking = false;
203                } else if (maxPos < Math.abs(posNow)) {
204                    animateValue = "-" + maxPos;
205                } else {
206                    var moveValue = (Math.abs(posNow) > $main.startTouchPos ? Math.ceil(Math.abs(posNow) / $main.li.outerWidth()) : Math.floor(Math.abs(posNow) / $main.li.outerWidth())) * $main.li.outerWidth();
207                    animateValue = "-" + (moveValue > maxPos ? maxPos : moveValue);
208                }
209
210                $main.ul.finish().animate({
211                    "left": animateValue
212                }, options.speed);
213
214                $main.startTouch = false;
215
216                if($main.clicking){
217                    $main.a.each(function(){
218
219                        var $ths = $(this);
220
221                        if($ths.is(":hover")){
222                            $ths.one("click", function(event){
223                                event.preventDefault();
224                            });
225
226                            return false;
227                        }
228
229                    });
230
231                    $main.clicking = false;
232
233                }
234
235            }
236        };
237
238        $(window).resize(function(e){
239            if($(window).width() != $main.lastWidth){
240                calculateParams($(window).innerWidth());
241                resizeElements(options.countElement);
242            }
243        });
244
245        calculateParams($(window).innerWidth());
246        resizeElements(options.countElement);
247        bindEvents();
248        onLoadUp();
249
250    };
251
252})($);

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.