PageSourceSearch

https://www.emptycosmetictubes.com/Content/C_JS/m122/jquery.elastislide.js

js emptycosmetictubes.com collected 2026-10-08 07:17:34 UTC 12,500 bytes, 290 lines download raw bytes

1(function(window, $, undefined) {
2    $.fn.touchwipe = function(settings) {
3        var config = {
4            min_move_x: 20,
5            min_move_y: 20,
6            wipeLeft: function() {},
7            wipeRight: function() {},
8            wipeUp: function() {},
9            wipeDown: function() {},
10            preventDefaultEvents: true
11        };
12        if (settings) $.extend(config, settings);
13        this.each(function() {
14            var startX;
15            var startY;
16            var isMoving = false;
17            function cancelTouch() {
18                this.removeEventListener('touchmove', onTouchMove);
19                startX = null;
20                isMoving = false
21            }
22            function onTouchMove(e) {
23                if (config.preventDefaultEvents) {
24                    e.preventDefault()
25                }
26                if (isMoving) {
27                    var x = e.touches[0].pageX;
28                    var y = e.touches[0].pageY;
29                    var dx = startX - x;
30                    var dy = startY - y;
31                    if (Math.abs(dx) >= config.min_move_x) {
32                        cancelTouch();
33                        if (dx > 0) {
34                            config.wipeLeft()
35                        } else {
36                            config.wipeRight()
37                        }
38                    } else if (Math.abs(dy) >= config.min_move_y) {
39                        cancelTouch();
40                        if (dy > 0) {
41                            config.wipeDown()
42                        } else {
43                            config.wipeUp()
44                        }
45                    }
46                }
47            }
48            function onTouchStart(e) {
49                if (e.touches.length == 1) {
50                    startX = e.touches[0].pageX;
51                    startY = e.touches[0].pageY;
52                    isMoving = true;
53                    this.addEventListener('touchmove', onTouchMove, false)
54                }
55            }
56            if ('ontouchstart' in document.documentElement) {
57                this.addEventListener('touchstart', onTouchStart, false)
58            }
59        });
60        return this
61    };
62    $.elastislide = function(options, element) {
63        this.$el = $(element);
64        this._init(options)
65    };
66    $.elastislide.defaults = {
67        speed: 450,
68        easing: '',
69        imageW: 190,
70        margin: 3,
71        border: 2,
72        minItems: 1,
73        current: 0,
74        onClick: function() {
75            return false
76        }
77    };
78    $.elastislide.prototype = {
79        _init: function(options) {
80            this.options = $.extend(true, {},
81            $.elastislide.defaults, options);
82            this.$slider = this.$el.find('ul');
83            this.$items = this.$slider.children('li');
84            this.itemsCount = this.$items.length;
85            this.$esCarousel = this.$slider.parent();
86            this._validateOptions();
87            this._configure();
88            this._addControls();
89            this._initEvents();
90            this.$slider.show();
91            this._slideToCurrent(false)
92        },
93        _validateOptions: function() {
94            if (this.options.speed < 0) this.options.speed = 450;
95            if (this.options.margin < 0) this.options.margin = 4;
96            if (this.options.border < 0) this.options.border = 1;
97            if (this.options.minItems < 1 || this.options.minItems > this.itemsCount) this.options.minItems = 1;
98            if (this.options.current > this.itemsCount - 1) this.options.current = 0
99        },
100        _configure: function() {
101            this.current = this.options.current;
102            this.visibleWidth = this.$esCarousel.width();
103            if (this.visibleWidth < this.options.minItems * (this.options.imageW + 2 * this.options.border) + (this.options.minItems - 1) * this.options.margin) {
104                this._setDim((this.visibleWidth - (this.options.minItems - 1) * this.options.margin) / this.options.minItems);
105                this._setCurrentValues();
106                this.fitCount = this.options.minItems
107            } else {
108                this._setDim();
109                this._setCurrentValues()
110            }
111            this.$slider.css({
112                width: this.sliderW
113            })
114        },
115        _setDim: function(elW) {
116            this.$items.css({
117                marginRight: this.options.margin,
118                width: (elW) ? elW: this.options.imageW + 2 * this.options.border
119            }).children('a').css({
120                borderWidth: this.options.border
121            })
122        },
123        _setCurrentValues: function() {
124            this.itemW = this.$items.outerWidth(true);
125            this.sliderW = this.itemW * this.itemsCount;
126            this.visibleWidth = this.$esCarousel.width();
127            this.fitCount = Math.floor(this.visibleWidth / this.itemW)
128        },
129        _addControls: function() {
130            this.$navNext = $('<span class="es-nav-next">Next</span>');
131            this.$navPrev = $('<span class="es-nav-prev">Previous</span>');
132            $('<div class="es-nav"/>').append(this.$navPrev).append(this.$navNext).appendTo(this.$el)
133        },
134        _toggleControls: function(dir, status) {
135            if (dir && status) {
136                if (status === 1)(dir === 'right') ? this.$navNext.show() : this.$navPrev.show();
137                else(dir === 'right') ? this.$navNext.hide() : this.$navPrev.hide()
138            } else if (this.current === this.itemsCount - 1 || this.fitCount >= this.itemsCount) this.$navNext.hide()
139        },
140        _initEvents: function() {
141            var instance = this;
142            $(window).bind('resize.elastislide',
143            function(event) {
144                instance._setCurrentValues();
145                if (instance.visibleWidth < instance.options.minItems * (instance.options.imageW + 2 * instance.options.border) + (instance.options.minItems - 1) * instance.options.margin) {
146                    instance._setDim((instance.visibleWidth - (instance.options.minItems - 1) * instance.options.margin) / instance.options.minItems);
147                    instance._setCurrentValues();
148                    instance.fitCount = instance.options.minItems
149                } else {
150                    instance._setDim();
151                    instance._setCurrentValues()
152                }
153                instance.$slider.css({
154                    width: instance.sliderW + 10
155                });
156                clearTimeout(instance.resetTimeout);
157                instance.resetTimeout = setTimeout(function() {
158                    instance._slideToCurrent()
159                },
160                200)
161            });
162            this.$navNext.bind('click.elastislide',
163            function(event) {
164                instance._slide('right')
165            });
166            this.$navPrev.bind('click.elastislide',
167            function(event) {
168                instance._slide('left')
169            });
170           // this.$items.bind('click.elastislide',
171           // function(event) {
172            //    instance.options.onClick($(this));
173             //   return false
174          //  });
175            instance.$slider.touchwipe({
176                wipeLeft: function() {
177                    instance._slide('right')
178                },
179                wipeRight: function() {
180                    instance._slide('left')
181                }
182            })
183        },
184        _slide: function(dir, val, anim, callback) {
185            if (this.$slider.is(':animated')) return false;
186            var ml = parseFloat(this.$slider.css('margin-left'));
187            if (val === undefined) {
188                var amount = this.fitCount * this.itemW,
189                val;
190                if (amount < 0) return false;
191                if (dir === 'right' && this.sliderW - (Math.abs(ml) + amount) < this.visibleWidth) {
192                    amount = this.sliderW - (Math.abs(ml) + this.visibleWidth) - this.options.margin;
193                    this._toggleControls('right', -1);
194                    this._toggleControls('left', 1)
195                } else if (dir === 'left' && Math.abs(ml) - amount < 0) {
196                    amount = Math.abs(ml);
197                    this._toggleControls('left', -1);
198                    this._toggleControls('right', 1)
199                } else {
200                    var fml; (dir === 'right') ? fml = Math.abs(ml) + this.options.margin + Math.abs(amount) : fml = Math.abs(ml) - this.options.margin - Math.abs(amount);
201                    if (fml > 0) this._toggleControls('left', 1);
202                    else this._toggleControls('left', -1);
203                    if (fml < this.sliderW - this.visibleWidth) this._toggleControls('right', 1);
204                    else this._toggleControls('right', -1)
205                } (dir === 'right') ? val = '-=' + amount: val = '+=' + amount
206            } else {
207                var fml = Math.abs(val);
208                if (Math.max(this.sliderW, this.visibleWidth) - fml < this.visibleWidth) {
209                    val = -(Math.max(this.sliderW, this.visibleWidth) - this.visibleWidth);
210                    if (val !== 0) val += this.options.margin;
211                    this._toggleControls('right', -1);
212                    fml = Math.abs(val)
213                }
214                if (fml > 0) this._toggleControls('left', 1);
215                else this._toggleControls('left', -1);
216                if (Math.max(this.sliderW, this.visibleWidth) - this.visibleWidth > fml + this.options.margin) this._toggleControls('right', 1);
217                else this._toggleControls('right', -1)
218            }
219            $.fn.applyStyle = (anim === undefined) ? $.fn.animate: $.fn.css;
220            var sliderCSS = {
221                marginLeft: val
222            };
223            var instance = this;
224            this.$slider.applyStyle(sliderCSS, $.extend(true, [], {
225                duration: this.options.speed,
226                easing: this.options.easing,
227                complete: function() {
228                    if (callback) callback.call()
229                }
230            }))
231        },
232        _slideToCurrent: function(anim) {
233            var amount = this.current * this.itemW;
234            this._slide('', -amount, anim)
235        },
236        add: function($newelems, callback) {
237            this.$items = this.$items.add($newelems);
238            this.itemsCount = this.$items.length;
239            this._setDim();
240            this._setCurrentValues();
241            this.$slider.css({
242                width: this.sliderW
243            });
244            this._slideToCurrent();
245            if (callback) callback.call($newelems)
246        },
247        destroy: function(callback) {
248            this._destroy(callback)
249        },
250        _destroy: function(callback) {
251            this.$el.unbind('.elastislide').removeData('elastislide');
252            $(window).unbind('.elastislide');
253            if (callback) callback.call()
254        }
255    };
256    var logError = function(message) {
257        if (this.console) {
258            console.error(message)
259        }
260    };
261    $.fn.elastislide = function(options) {
262        if (typeof options === 'string') {
263            var args = Array.prototype.slice.call(arguments, 1);
264            this.each(function() {
265                var instance = $.data(this, 'elastislide');
266                if (!instance) {
267                    logError("cannot call methods on elastislide prior to initialization; attempted to call method '" + options + "'");
268                    return
269                }
270                if (!$.isFunction(instance[options]) || options.charAt(0) === "_") {
271                    logError("no such method '" + options + "' for elastislide instance");
272                    return
273                }
274                instance[options].apply(instance, args)
275            })
276        } else {
277            this.each(function() {
278                var instance = $.data(this, 'elastislide');
279                if (!instance) {
280                    $.data(this, 'elastislide', new $.elastislide(options, this))
281                }
282            })
283        }
284        return this
285    }
286})(window, jQuery);
287$('#carousel').elastislide({
288    imageW: 136,
289    minItems: 3
290});

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.