PageSourceSearch

https://cafeallegre.com/js/fws2.js

js cafeallegre.com collected 2026-10-08 19:25:44 UTC 22,087 bytes, 614 lines download raw bytes

1(function ($) {
2
3    "use strict";
4    
5    // from jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
6    $.extend($.easing,
7    {
8        FWS2easeOutCubic: function (x, t, b, c, d) {
9            return c * ((t = t / d - 1) * t * t + 1) + b;
10        },
11        FWS2easeInOutExpo: function (x, t, b, c, d) {
12            if (t == 0)
13                return b;
14            if (t == d)
15                return b + c;
16            if ((t /= d / 2) < 1)
17                return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
18            return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
19        }
20    });
21
22    $.fn.fws2 = function (options) {
23        
24        var glob = {
25            options: {
26                cs              : 0,
27                duration        : 750,
28                hoverpause      : 1,
29                pause           : 6000,
30                arrows          : 1,
31                bullets         : 1,
32                height          : 600,
33                expandDuration  : 750,
34                linktext        : "Read More",
35                
36                titleHTML       : '<h4>%title%</h4>',             
37                descriptionHTML : '<p>%desc%</p>',                     
38                linkHTML        : '<a href="%link%">%linktext%</a>',   
39               
40                beforeInit      : function() {},
41                afterInit       : function() {},
42                slideStart      : function() {},
43                slideEnd        : function() {}
44            },
45            slides: []
46        };
47
48        $.extend(glob.options, options);
49
50        var randID = "fws2-instance-" + new Date().getTime();
51
52        $('<div id="' + randID + '" class="fws2"></div>').appendTo(this);
53
54        var $instance = $("#" + randID);
55
56        var content = {
57            
58            resize: function () {
59                $instance.css({height: $instance.find(".slide:first").height()});
60            },
61            
62            replaceHTML: function(html, th){
63                
64                th.linktext = th.linktext ? th.linktext : glob.options.linktext;
65                
66                return html.replace("%title%", th.title)
67                        .replace("%desc%", th.description)
68                        .replace("%link%", th.link)
69                        .replace("%linktext%", th.linktext);
70                
71            },
72            
73            buildHTML: function () {
74                
75                var parent = this;
76                
77                var html = "";
78                html += '<div class="slider_container">';
79                    $(glob.slides).each(function () {
80
81                        var linktext = this.linktext ? this.linktext : glob.options.linktext;
82                        
83                        html += '<div class="slide">';
84                            html += '<img src="' + this.image + '" alt="'+this.alt+'">';
85                            html += '<div class="slide_content">';
86                                html += '<div class="slide_content_wrap">';
87                                    html += '<div class="title">' + parent.replaceHTML(glob.options.titleHTML, this) + '</div>';
88                                    html += '<div class="description">' + parent.replaceHTML(glob.options.descriptionHTML, this) + '</div>';
89                                    html += '<div class="readmore">' + parent.replaceHTML(glob.options.linkHTML, this) + '</div>';
90                                html += '</div>';
91                            html += '</div>';
92                        html += '</div>';
93                    });
94                html += '</div>';
95
96                if (glob.options.arrows == "1") {
97                    html += '<div class="slidePrev"><i class="fa fa-chevron-left"></i></div>';
98                    html += '<div class="slideNext"><i class="fa fa-chevron-right"></i></div>';
99                }
100                
101                html += '<div class="timers"></div>';
102
103                if (glob.options.bullets == "1") {
104                    html += '<div class="bullets"></div>';
105                }
106
107                $(html).appendTo($instance);
108
109                for (var i = 0; i < glob.slides.length; i++) {
110                    $('<div class="timer"><div class="progress"></div></div>').appendTo($instance.find(".timers"));
111                    $('<div class="bullet"><i class="fa fa-circle"></i></div>').appendTo($instance.find(".bullets"));
112                }
113            },
114            
115            imgLoaded: function ($img, callback, step) {
116                
117                if (typeof $.fn.imagesLoaded !== "undefined") {
118                    // imagesLoaded script is loaded
119                    $img.imagesLoaded(function () {
120                        if (typeof callback === "function") {
121                            callback();
122                        }
123                    });
124                    return;
125                }
126            
127                var total = $img.length;
128                var loaded = 0;
129
130                if (total <= 0) {
131                    if (typeof callback === "function") {
132                        callback();
133                    }
134                }
135
136                $img.each(function () {
137                    var image = new Image;
138                    image.onload = function () {
139
140                        if (typeof step === "function") {
141                            step();
142                        }
143
144                        loaded++;
145                        if (loaded >= total) {
146                            if (typeof callback === "function") {
147                                callback();
148                            }
149                        }
150                    };
151
152                    image.onerror = function () {
153                        console.warn("Could not load image");
154                    };
155
156                    image.src = $(this).attr("src");
157                });
158            },
159            
160            init: function () {
161
162                /* Build html */
163                this.buildHTML();
164                
165                this.imgLoaded($instance.find("img"), function () {
166                   
167                    $instance.find(".bullets .bullet").eq(glob.options.cs).addClass("active");
168                    $instance.find(".timers").css({
169//                        width: ($instance.find(".timers .timer").length + 1) * $instance.find(".timers .timer").width() + 5
170                    });
171                    $instance.find(".slide").eq(glob.options.cs).fadeIn({
172                        duration: glob.options.expandDuration,
173                        easing: "swing"
174                    });
175                    $instance.animate({
176                        height: $instance.find(".slide:first").height()
177                    }, {
178                        duration: glob.options.expandDuration,
179                        easing: "FWS2easeInOutExpo",
180                        complete: function () {
181
182                            // Arrows and bullets animation show duration
183
184                            var controls_anim_duration = 1500;
185
186                            $instance.find(".slidePrev").animate({
187                                left: 0
188                            }, {
189                                duration: controls_anim_duration,
190                                easing: "FWS2easeInOutExpo"
191                            });
192
193                            $instance.find(".slideNext").animate({
194                                right: 0
195                            }, {
196                                duration: controls_anim_duration,
197                                easing: "FWS2easeInOutExpo"
198                            });
199
200                            $instance.find(".bullets").animate({
201                                bottom: 15
202                            }, {
203                                duration: controls_anim_duration,
204                                easing: "FWS2easeInOutExpo"
205                            });
206
207                            content.showText();
208                            controls.position();
209                            content.resize();
210                            auto.run();
211                            auto.focus();
212
213                            setTimeout(function () {
214                                if (typeof glob.options.afterInit === "function") {
215                                    glob.options.afterInit();
216                                }
217                            }, controls_anim_duration);
218
219                        }
220                    });
221
222                });
223            },
224            
225            show: function () {
226                /* Show slide */
227
228                content.hideText();
229
230                $instance.find(".bullets .bullet").removeClass("active");
231                $instance.find(".bullets .bullet").eq(glob.options.cs).addClass("active");
232
233                $instance.find(".slide").eq(glob.options.cs).css({
234                    opacity: 0,
235                    zIndex: 2
236                }).show().animate({
237                    opacity: 1
238                }, {
239                    queue: false,
240                    duration: glob.options.duration,
241                    easing: "swing",
242                    start: function () {
243                        if (typeof glob.options.slideStart === "function") {
244                            glob.options.slideStart($instance.find(".slide").eq(glob.options.cs));
245                        }
246                    },
247                    complete: function () {
248                        $instance.find(".slide").filter(":lt(" + glob.options.cs + ")").css("zIndex", 0).hide();
249                        $instance.find(".slide").filter(":gt(" + glob.options.cs + ")").css("zIndex", 0).hide();
250                        $instance.find(".slide").eq(glob.options.cs).css("zIndex", 1);
251
252                        content.showText();
253                        auto.run();
254
255                        if (typeof glob.options.slideEnd === "function") {
256                            glob.options.slideEnd($instance.find(".slide").eq(glob.options.cs));
257                        }
258                    }
259                });
260            },
261            
262            showText: function () {
263
264                var $slide = $instance.find(".slide").eq(glob.options.cs);
265
266                /* Position Text */
267                var textWrapper = $slide.find(".slide_content_wrap");
268
269                textWrapper.css({
270                    top: "50%",
271                    left: 0,
272                    display: "block"
273                });
274
275                textWrapper.css({
276                    marginTop: -1 * textWrapper.height() / 2,
277                    marginLeft: "8%"
278                });
279
280                /* Show slide text */
281                $slide.find(".title").fadeTo(300, 1);
282
283                setTimeout(function () {
284                    $slide.find(".description").fadeTo(300, 1);
285                }, 150);
286
287                setTimeout(function () {
288                    $slide.find(".readmore").fadeTo(300, 1);
289                }, 300);
290            },
291            
292            hideText: function () {
293                /* Hide slide text */
294
295                $instance.find(".slide .title").fadeTo(300, 0);
296
297                setTimeout(function () {
298                    $instance.find(".slide .description").fadeTo(300, 0);
299                }, 150);
300
301                setTimeout(function () {
302                    $instance.find(".slide .readmore").fadeTo(300, 0);
303                }, 300);
304            },
305            
306            slidePrev: function() {
307                
308                if ($instance.find(".slide").is(":animated")) {
309                    return;
310                }
311
312                if (glob.options.cs <= 0) {
313                    glob.options.cs = $instance.find(".slide:last").index();
314
315                    $instance.find(".timers .timer .progress").stop();
316                    $instance.find(".timers .timer .progress").css({
317                        width: "100%"
318                    });
319                    $instance.find(".timers .timer:last .progress").animate({
320                        width: "0%"
321                    }, {
322                        queue: false,
323                        duration: glob.options.duration,
324                        easing: "FWS2easeOutCubic"
325                    });
326
327                } else {
328                    glob.options.cs--;
329
330                    $instance.find(".timers .timer .progress").stop();
331                    $instance.find(".timers .timer:gt(" + glob.options.cs + ") .progress").css({
332                        width: "0%"
333                    });
334                    $instance.find(".timers .timer:eq(" + glob.options.cs + ") .progress").animate({
335                        width: "0%"
336                    }, {
337                        queue: false,
338                        duration: glob.options.duration,
339                        easing: "FWS2easeOutCubic"
340                    });
341                }
342
343                this.show();
344            },
345            
346            slideNext: function(){
347
348                if ($instance.find(".slide").is(":animated")) {
349                    return;
350                }
351
352                if ($instance.find(".slide").eq(glob.options.cs + 1).length <= 0) {
353
354                    glob.options.cs = 0;
355
356                    $instance.find(".timers .timer .progress").stop();
357
358                    $instance.find(".timers .timer:last .progress").animate({
359                        width: "100%"
360                    }, {
361                        queue: false,
362                        duration: glob.options.duration,
363                        easing: "FWS2easeOutCubic",
364                        complete: function () {
365                            $instance.find(".timers .timer .progress").css({
366                                width: "0%"
367                            });
368                        }
369                    });
370                } else {
371                    glob.options.cs++;
372
373                    $instance.find(".timers .timer .progress").stop();
374                    $instance.find(".timers .timer:lt(" + glob.options.cs + ") .progress").animate({
375                        width: "100%"
376                    }, {
377                        queue: false,
378                        duration: glob.options.duration,
379                        easing: "FWS2easeOutCubic"
380                    });
381
382                }
383                
384                this.show();
385            }
386        };
387
388        var controls = {
389            
390            /* Adjust buttons position */
391            position: function () {
392
393                $instance.find(".slidePrev, .slideNext").css({
394                    top: $instance.height() / 2 - $instance.find(".slideNext").height() / 2
395                });
396
397                $instance.find(".slidePrev").css({left: 0});
398                $instance.find(".slideNext").css({right: 0});
399            },
400            
401            bindControls: function () {
402                
403                if ($.mobile) {
404                    $instance.on("swiperight", function (e) {
405                        content.slidePrev();
406                    });
407
408                    $instance.on("swipeleft", function (e) {
409                        content.slideNext();
410                    });
411                }
412                
413                $(window).on("resize",function () {
414                    content.resize();
415                    controls.position();
416                });
417
418                /* Hover effect */
419                $instance.find(".slidePrev, .slideNext").on("mouseover", function () {
420                    $(this).animate({
421                        opacity: 1
422                    }, {
423                        queue: false,
424                        duration: 1000,
425                        easing: "FWS2easeOutCubic"
426                    });
427                });
428
429                /* Hover effect - mouseout */
430                $instance.find(".slidePrev, .slideNext").on("mouseout", function () {
431                    $(this).animate({
432                        opacity: 0.5
433                    }, {
434                        queue: false,
435                        duration: 1000,
436                        easing: "FWS2easeOutCubic"
437                    });
438                });
439
440                /* Arrow Key Bind */
441                $(document).on("keyup", function (e) {
442                    if (e.which === 39) {
443                        $instance.find(".slideNext").trigger("click");
444                    }
445                    if (e.which === 37) {
446                        $instance.find(".slidePrev").trigger("click");
447                    }
448                });
449
450                /* Next Button */
451                $instance.find(".slideNext").on("click", function (e) {
452                    
453                    e.stopPropagation();
454
455                    content.slideNext();
456                });
457
458                /* Previous Button */
459                $instance.find(".slidePrev").on("click", function (e) {
460                    
461                    e.stopPropagation();
462                    
463                    content.slidePrev();
464                });
465
466                $instance.find(".bullets .bullet").on("click", function (e) {
467                    
468                    e.stopPropagation();
469                    
470                    if ($instance.find(".slide").is(":animated")) {
471                        return;
472                    }
473                    
474                    if ($(this).hasClass("active")) {
475                        return;
476                    }
477
478                    glob.options.cs = $(this).index();
479
480                    $instance.find(".timers .timer .progress").stop();
481                    
482                    var $reverse = $instance.find(".timers .timer:gt(" + glob.options.cs + ") .progress, .timers .timer:eq(" + glob.options.cs + ") .progress").get().reverse();
483                    var dgt = glob.options.duration / $($reverse).length;
484                    
485                    $($reverse).each(function (i) {
486                        var th = this;
487                        setTimeout(function () {
488                            $(th).animate({
489                                width: 0
490                            }, {
491                                queue: false,
492                                duration: dgt,
493                                easing: "linear"
494                            });
495                        }, i * dgt);
496                        
497                    });
498                    
499                    var dlt = glob.options.duration / $instance.find(".timers .timer:lt(" + glob.options.cs + ")").length;
500                    $instance.find(".timers .timer:lt(" + glob.options.cs + ") .progress").each(function (i) {
501                        var th = this;
502                        setTimeout(function () {
503                            $(th).animate({
504                                width: "100%"
505                            }, {
506                                queue: false,
507                                duration: dlt,
508                                easing: "linear"
509                            });
510                        }, i * dlt);
511                    });
512
513
514                    content.show();
515                });
516            }
517            
518        };
519        
520        var auto = {
521            /* Run timer */
522            run: function () {
523
524                if (glob.options.pause === 0) {
525                    return;
526                }
527
528                $instance.find(".timer:eq(" + glob.options.cs + ") .progress").animate({
529                    width: "100%"
530                }, {
531                    queue: false,
532                    duration: (glob.options.pause - (glob.options.pause / 100) * ((($instance.find(".timer:eq(" + glob.options.cs + ") .progress").width() / $instance.find(".timer:eq(" + glob.options.cs + ")").width()) * 100))),
533                    easing: "linear",
534                    complete: function () {
535                        content.slideNext();
536                    }
537                });
538            },
539            /* Stop on focus */
540            focus: function () {
541
542                if (glob.options.hoverpause === 1) {
543                    $instance.find(".slide_content").on("mouseover", function () {
544                        if ($instance.find(".slide").is(":animated"))
545                            return;
546                        $instance.find(".timer .progress").stop();
547                    });
548
549                    $instance.find(".slide_content").on("mouseleave", function () {
550                        if ($instance.find(".slide").is(":animated"))
551                            return;
552                        auto.run();
553                    });
554                }
555            }
556        };
557        
558        this.start = function () {
559            if (typeof glob.options.beforeInit === "function") {
560                glob.options.beforeInit();
561            }
562            content.init();
563            controls.bindControls();
564            return this;
565        };
566        
567        this.addSlide = function(slide) {
568            glob.slides.push(slide); 
569            return this;
570        };
571        
572        this.settings = function(settings) {
573            $.extend(glob.options, settings);
574            return this;
575        };
576        
577        this.destroy = function() {
578            $instance
579                    .stop()
580                    .off()
581                    .find("*")
582                    .stop()
583                    .off();
584            $instance.remove();
585            
586            return this;
587        };
588        
589        this.restart = function() {
590            
591            glob.options.cs = 0;
592            
593            $instance
594                    .stop()
595                    .off()
596                    .find("*")
597                    .stop()
598                    .off();
599            $instance.empty();
600            
601            this.start();
602            return this;
603        };
604        
605        this.getSlidesNum = function(){
606            return glob.slides.length;
607        };
608        
609        return this;
610        
611    };
612
613})(jQuery);
614

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.