PageSourceSearch

https://www.cheering.jp/static/js/jquery.zrssfeed.js

js cheering.jp collected 2026-10-04 02:52:23 UTC 12,387 bytes, 343 lines download raw bytes

1/**
2 * Plugin: jquery.zRSSFeed
3 * 
4 * Version: 1.1.9
5 * (c) Copyright 2010-2012, Zazar Ltd
6 * 
7 * Description: jQuery plugin for display of RSS feeds via Google Feed API
8 *              (Based on original plugin jGFeed by jQuery HowTo. Filesize function by Cary Dunn.)
9 * 
10 * History:
11 * 1.1.9 - New dateformat option to allow feed date formatting
12 * 1.1.8 - Added historical option to enable scoring in the Google Feed API
13 * 1.1.7 - Added feed offset, link redirect & link content options
14 * 1.1.6 - Added sort options
15 * 1.1.5 - Target option now applies to all feed links
16 * 1.1.4 - Added option to hide media and now compressed with Google Closure
17 * 1.1.3 - Check for valid published date
18 * 1.1.2 - Added user callback function due to issue with ajaxStop after jQuery 1.4.2
19 * 1.1.1 - Correction to null xml entries and support for media with jQuery < 1.5
20 * 1.1.0 - Added support for media in enclosure tags
21 * 1.0.3 - Added feed link target
22 * 1.0.2 - Fixed issue with GET parameters (Seb Dangerfield) and SSL option
23 * 1.0.1 - Corrected issue with multiple instances
24 *
25 **/
26
27function startSpiner() {
28    var opts = {
29        lines: 13 // The number of lines to draw
30        , length: 28 // The length of each line
31        , width: 14 // The line thickness
32        , radius: 42 // The radius of the inner circle
33        , scale: 1 // Scales overall size of the spinner
34        , corners: 1 // Corner roundness (0..1)
35        , color: '#f19698' // #rgb or #rrggbb or array of colors
36        , opacity: 0.25 // Opacity of the lines
37        , rotate: 0 // The rotation offset
38        , direction: 1 // 1: clockwise, -1: counterclockwise
39        , speed: 1 // Rounds per second
40        , trail: 60 // Afterglow percentage
41        , fps: 20 // Frames per second when using setTimeout() as a fallback for CSS
42        , zIndex: 2e9 // The z-index (defaults to 2000000000)
43        , className: 'spinner' // The CSS class to assign to the spinner
44        , top: '50%' // Top position relative to parent
45        , left: '50%' // Left position relative to parent
46        , shadow: false // Whether to render a shadow
47        , hwaccel: false // Whether to use hardware acceleration
48        // , position: 'absolute' // Element positioning
49    };
50    var target = document.getElementById('spinner');
51    return new Spinner(opts).spin(target);
52}
53
54(function($){
55	  $.fn.rssfeed = function(url, options, fn) {
56        var spinner = startSpiner();
57		    // Set plugin defaults
58		    var defaults = {
59			      // limit: 4,
60			      limit: 20,
61			      offset: 1,
62			      header: false,
63			      titletag: 'h4',
64			      date: true,
65			      dateformat: 'date',
66			      content: true,
67			      snippet: true,
68			      media: true,
69			      showerror: true,
70			      errormsg: '',
71			      key: null,
72			      ssl: false,
73			      linktarget: '_blank',
74			      linkredirect: '',
75			      linkcontent: false,
76			      sort: '',
77			      sortasc: true,
78			      historical: false
79		    };
80		    var options = $.extend(defaults, options); 
81		    // Functions
82		    return this.each(function(i, e) {
83			      var $e = $(e);
84			      var s = '';
85
86			      // Check for SSL protocol
87			      if (options.ssl) s = 's';
88
89			      // Add feed class to user div
90			      if (!$e.hasClass('rssFeed')) $e.addClass('rssFeed');
91
92			      // Check for valid url
93			      if(url == null) return false;
94
95			      // Add start offset to feed length
96			      if (options.offset > 0) options.offset -= 1;
97			      options.limit += options.offset;
98            // var  api = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D'http%3A%2F%2Fcheering.way-nifty.com%2Finstructor%2Findex.rdf'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeyss&callback=JSON_CALLBACK";
99
100            //$.get("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D'http%3A%2F%2Fcheering.way-nifty.com%2Finstructor%2Findex.rdf'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeyss").done(function( data ) {
101/*            $.get("/get_news").done(function( data ) {
102                spinner.stop();
103                $("#spinner").remove();
104                _process(e, data, options);
105            });*/
106
107		    });
108	  };
109
110	  // Function to create HTML result
111	  var _process = function(e, data, options) {
112		    // Get JSON feed data
113		    // var feeds = data.query.results.body.rdf;
114		    // if (!feeds) {
115			      // return false;
116		    // }
117		alert('Test!!!!');
118        var feeds = data;
119		    var rowArray = [];
120		    var rowIndex = 0;
121		    var html = '';
122		    var row = 'odd';
123
124		    // Get XML data for media (parseXML not used as requires 1.5+)
125		    if (options.media) {
126			      var xml = _getXMLDocument(data.xmlString);
127			      var xmlEntries = xml.getElementsByTagName('item');
128		    }
129		    
130		    // Add header if required
131		    if (options.header){
132            var headerInformation = data["rdf:RDF"]["channel"];
133
134			      html +=	'<div class="rssHeader">' +
135				        // '<a href="'+feeds.link+'" title="'+ feeds.description +'">'+ feeds.title +'</a>' +
136				        '<a href="'+headerInformation.link+'" title="'+ headerInformation.description +'">'+ headerInformation.title +'</a>' +
137				        '</div>';
138        }
139		    // Add body
140		    html += '<div class="rssBody">' + '<ul>';
141        feeds.item = feeds.item.length > options.limit ? feeds.item.splice(0, options.limit) : feeds.item;
142		    // Add feeds
143		    for (var i=options.offset; i<feeds.item.length; i++) {
144			      rowIndex = i - options.offset;
145			      rowArray[rowIndex] = [];
146			      // Get individual feed
147            // Frank comment here
148			      // var entry = feeds.entries[i];
149			      var entry = feeds.item[i];
150            entry.publishedDate = entry.date;
151			      var pubDate;
152			      var sort = '';
153			      var feedLink = entry.link;
154			      // Apply sort column
155			      switch (options.sort) {
156				    case 'title':
157					      sort = entry.title;
158					      break;
159				    case 'date':
160					      // sort = entry.publishedDate;
161					      sort = entry.publishedDate;
162					      break;
163			      }
164			      rowArray[rowIndex]['sort'] = sort;
165
166			      // Format published date
167			      if (entry.publishedDate) {
168
169				        var entryDate = new Date(entry.publishedDate);
170				        var pubDate = entryDate.toLocaleDateString() + ' ' + entryDate.toLocaleTimeString();
171
172				        switch (options.dateformat) {
173					      case 'datetime':
174						        break;
175					      case 'date':
176						        pubDate = entryDate.toLocaleDateString();
177						        break;
178					      case 'time':
179						        pubDate = entryDate.toLocaleTimeString();
180						        break;
181					      case 'timeline':
182						        pubDate = _getLapsedTime(entryDate);
183						        break;
184					      default:
185						        pubDate = _formatDate(entryDate,options.dateformat);
186						        break;
187				        }
188			      }
189			      
190			      // Add feed row
191			      if (options.linkredirect) feedLink = encodeURIComponent(feedLink);
192			      rowArray[rowIndex]['html'] = '<'+ options.titletag +'><a href="'+ options.linkredirect + feedLink +'" title="View this feed at '+ feeds.title +'">'+ entry.title +'</a></'+ options.titletag +'>'
193
194			      if (options.date && pubDate) rowArray[rowIndex]['html'] += '<div style="background:#f19698; width:100px; float:left; text-align:center;  color:#FFFFFF;padding:0px 5px;">'+ pubDate +'</div>'
195			      if (options.content) {
196			          
197				        // Use feed snippet if available and optioned
198				        if (options.snippet && entry.contentSnippet != '') {
199					          // var content = entry.contentSnippet;
200					          var content = entry.description;
201				        } else {
202					          // var content = entry.content;
203					          var content = entry.description;
204				        }
205
206				        if (options.linkcontent) {
207					          content = '<a href="'+ options.linkredirect + feedLink +'" title="View this feed at '+ feeds.title +'">'+ content +'</a>'
208				        }
209				        
210				        rowArray[rowIndex]['html'] += '<p>'+ content +'</p>'
211			      }
212			      
213			      // Add any media
214			      if (options.media && xmlEntries.length > 0) {
215				        var xmlMedia = xmlEntries[i].getElementsByTagName('enclosure');
216				        if (xmlMedia.length > 0) {
217					          
218					          rowArray[rowIndex]['html'] += '<div class="rssMedia"><div>Media files</div><ul>'
219					          
220					          for (var m=0; m<xmlMedia.length; m++) {
221						            var xmlUrl = xmlMedia[m].getAttribute("url");
222						            var xmlType = xmlMedia[m].getAttribute("type");
223						            var xmlSize = xmlMedia[m].getAttribute("length");
224						            rowArray[rowIndex]['html'] += '<li><a href="'+ xmlUrl +'" title="Download this media">'+ xmlUrl.split('/').pop() +'</a> ('+ xmlType +', '+ _formatFilesize(xmlSize) +')</li>';
225					          }
226					          rowArray[rowIndex]['html'] += '</ul></div>'
227				        }
228			      }
229					  
230		    }
231		    
232		    // Sort if required
233		    if (options.sort) {
234			      rowArray.sort(function(a,b) {
235
236				        // Apply sort direction
237				        if (options.sortasc) {
238					          var c = a['sort'];
239					          var d = b['sort'];
240				        } else {
241					          var c = b['sort'];
242					          var d = a['sort'];
243				        }
244
245				        if (options.sort == 'date') {
246					          return new Date(c) - new Date(d);
247				        } else {
248					          c = c.toLowerCase();
249					          d = d.toLowerCase();
250					          return (c < d) ? -1 : (c > d) ? 1 : 0;
251				        }
252			      });
253		    }
254
255		    // Add rows to output
256		    $.each(rowArray, function(e) {
257			      // Alternate row classes
258			      if (row == 'odd') {
259				        row = 'even';
260			      } 
261			      html += '<li class="rssRow '+row+'">' + rowArray[e]['html'] + '</li>';
262		    });
263
264		    html += '</ul>' + '</div>';
265
266		    $(e).html(html);
267		    // Apply target to links
268		    $('a',e).attr('target',options.linktarget);
269	  };
270
271	  var _formatFilesize = function(bytes) {
272		    var s = ['bytes', 'kb', 'MB', 'GB', 'TB', 'PB'];
273		    var e = Math.floor(Math.log(bytes)/Math.log(1024));
274		    return (bytes/Math.pow(1024, Math.floor(e))).toFixed(2)+" "+s[e];
275	  }
276
277	  var _formatDate = function(date,mask) {
278
279		    // Convert to date and set return to the mask
280		    var fmtDate = new Date(date);
281		    date = mask;
282
283		    // Replace mask tokens
284		    date = date.replace('dd', _formatDigit(fmtDate.getDate()));
285		    date = date.replace('MM', _formatDigit(fmtDate.getMonth()+1));
286		    date = date.replace('yyyy',fmtDate.getFullYear());
287		    date = date.replace('hh', _formatDigit(fmtDate.getHours()));
288		    date = date.replace('mm', _formatDigit(fmtDate.getMinutes()));
289		    date = date.replace('ss', _formatDigit(fmtDate.getSeconds()));
290		    return date;
291	  }
292
293	  var _formatDigit = function(digit) {
294		    digit += '';
295		    if (digit.length < 2) digit = '0' + digit;
296		    return digit;
297	  }
298
299	  var _getXMLDocument = function(string) {
300		    var browser = navigator.appName;
301		    var xml;
302		    if (browser == 'Microsoft Internet Explorer') {
303			      xml = new ActiveXObject('Microsoft.XMLDOM');
304			      xml.async = 'false';
305			      xml.loadXML(string);
306		    } else {
307			      xml = (new DOMParser()).parseFromString(string, 'text/xml');
308		    }
309		    return xml;
310	  }
311
312	  var _getLapsedTime = function(date) {
313
314		    // Get current date and format date parameter
315		    var todayDate = new Date();	
316		    var pastDate = new Date(date);
317
318		    // Get lasped time in seconds
319		    var lapsedTime = Math.round((todayDate.getTime() - pastDate.getTime())/1000)
320
321		    // Return lasped time in seconds, minutes, hours, days and weeks
322		    if (lapsedTime < 60) {
323			      return '< 1 min';
324		    } else if (lapsedTime < (60*60)) {
325			      var t = Math.round(lapsedTime / 60) - 1;
326			      var u = 'min';
327		    } else if (lapsedTime < (24*60*60)) {
328			      var t = Math.round(lapsedTime / 3600) - 1;
329			      var u = 'hour';
330		    } else if (lapsedTime < (7*24*60*60)) {
331			      var t = Math.round(lapsedTime / 86400) - 1;
332			      var u = 'day';
333		    } else {
334			      var t = Math.round(lapsedTime / 604800) - 1;
335			      var u = 'week';
336		    }
337		    
338		    // Check for plural units
339		    if (t > 1) u += 's';
340		    return t + ' ' + u;
341	  }
342
343})(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.