PageSourceSearch

https://dti.or.th/js/jquery.newsfade.1.0.js

js dti.or.th collected 2026-10-02 13:03:12 UTC 4,913 bytes, 135 lines download raw bytes

1/**
2 * jquery.newsfade.1.0.js
3 * 
4 * A news rotator plugin for using with jQuery.
5 *
6 * Copyright (c) 2011 Muneer Saheed <muneer AT encodez DOT com>
7 *
8 * http://www.encodez.com/plugins/jquery/quick-news-fader.html
9 * 
10 * Permission is hereby granted, free of charge, to any person
11 * obtaining a copy of this software and associated documentation
12 * files (the "Software"), to deal in the Software without
13 * restriction, including without limitation the rights to use, copy,
14 * modify, merge, publish, distribute, sublicense, and/or sell copies
15 * of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
25 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
26 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 * SOFTWARE.
29 */
30(function( $ ){
31  $.fn.newsFade = function(options) {
32    var properties = 
33    {
34      count         : 0
35      ,current       : 0
36      ,news_fader_t  : null
37      ,component     : null
38      ,items         : []
39    }
40    var defaults = {
41      interval  : 5000
42      ,style    : "fadeIn"
43      ,limit    : 1
44      ,auto     : false
45      ,motionSpeed : 500
46      ,height   : null
47    };
48    var options = $.extend(defaults, options);
49    if (options.height !== null)
50      $(this).find(".news-fade-wrapper").css({"height": options.height});
51    var methods =
52    {
53      loopNews : function(arg) {
54        $(properties.component).find("li").remove();
55        properties.current = arg;
56        for (var i = 0; i < options.limit; i++)
57        {
58          var tmpNews = '<li>' + 
59                methods.getNews() + 
60                '</li>';
61          $(properties.component).find("ul").append(tmpNews);
62        }
63        $("ul", properties.component).hide();        
64        switch(options.style) {
65          case "fadeIn" :
66            $(properties.component).find("ul").fadeIn(options.motionSpeed);
67            break;
68          case "slideDown" :
69            $(properties.component).find("ul").slideDown(options.motionSpeed);
70            break;
71          default :
72            $(properties.component).find("ul").fadeIn(options.motionSpeed);
73        }        
74        if (defaults.auto)
75        {
76          properties.news_fader_t = window.setTimeout(function(i) {
77             methods.loopNews(properties.current);
78          }, options.interval);
79        }
80      },
81      prev : function() {
82        properties.current = properties.current-2;
83        clearTimeout(properties.news_fader_t);
84        methods.loopNews(properties.current);
85      },
86      next : function() {
87        clearTimeout(properties.news_fader_t);
88        methods.loopNews(properties.current);
89      },
90      play : function() {
91        clearTimeout(properties.news_fader_t);
92        options.auto = true;
93        methods.loopNews(properties.current);
94      },
95      pause : function() {
96        options.auto = false;
97        clearTimeout(properties.news_fader_t);
98      },
99      getNews : function() {
100        if (properties.current === undefined) properties.current = 0;
101        if (properties.current >= properties.count)
102          properties.current = 0;
103        else if (properties.current < 0)
104          properties.current = properties.count - 1;
105        
106        return properties.items[properties.current++];
107      }
108    }
109    properties.component = this;
110    if (properties.component !== null) {
111      $("a#prev", properties.component).click(function(e) {
112        e.preventDefault();
113        return methods['prev'].apply( this, Array.prototype.slice.call( options, 1 ));
114      });
115      $("a#next", properties.component).click(function(e) {
116        e.preventDefault();
117        return methods['next'].apply( this, Array.prototype.slice.call( options, 1 ));
118      });
119      $("a#play", properties.component).click(function(e) {
120        e.preventDefault();
121        return methods['play'].apply( this, Array.prototype.slice.call( options, 1 ));
122      });
123      $("a#pause", properties.component).click(function(e) {
124        e.preventDefault();
125        return methods['pause'].apply( this, Array.prototype.slice.call( options, 1 ));
126      });
127      $(this).find("li").each(function(index) {
128        properties.items.push($(this).html());
129        $(this).remove();
130      });
131      properties.count = properties.items.length;
132      return methods['loopNews'].apply( this, Array.prototype.slice.call( options, 1 ));
133    }
134  }
135}
135)( jQuery );

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.