From cb6a7f428fc164b4803c2d99af0ad6ffc9fdb9dc Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Tue, 6 Jan 2015 17:31:01 -0500 Subject: [PATCH] added 2015/assets/js/jquery.feeds.js, 2015/assets/js/jquery.feeds.min.js also updated server/staging/lp15/weblabels.html --- 2015/assets/js/jquery.feeds.js | 225 +++++++++++++++++++++++++++++ 2015/assets/js/jquery.feeds.min.js | 17 +++ server/staging/lp15/weblabels.html | 10 ++ 3 files changed, 252 insertions(+) create mode 100644 2015/assets/js/jquery.feeds.js create mode 100644 2015/assets/js/jquery.feeds.min.js diff --git a/2015/assets/js/jquery.feeds.js b/2015/assets/js/jquery.feeds.js new file mode 100644 index 00000000..31de7b0d --- /dev/null +++ b/2015/assets/js/jquery.feeds.js @@ -0,0 +1,225 @@ +/*! + * jQuery Feeds v0.5 + * https://camagu.github.com/jquery-feeds + * + * Copyright (c) 2013, Camilo Aguilar + * Dual licensed under the MIT and GPL licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl.html + * + * Includes a modified version of Simple JavaScript Templating + * http://ejohn.org/blog/javascript-micro-templating/ + * Copyright (c) John Resig (http://ejohn.org) + * MIT licensed + * + * Date: 2013-02-18 + */ + +/*jshint evil: true */ +( function( $ ) { + + var cache = {}; + + $.fn.feeds = function( options ) { + + var engine = { + service: '//ajax.googleapis.com/ajax/services/feed/load?v=1.0', + + settings: { + loadingTemplate: '
Loading entries ...
', + entryTemplate: '
' + + '' + + '' + + '
' + + '
', + feeds: {}, + max: -1, + xml: false, + ssl: 'auto', + onComplete: function( entries ) { + + }, + preprocess: function( feed ) { + + } + }, + + feeds: { }, + entries: [ ], + + feedsLength: 0, + feedsLoaded: 0, + + $element: null, + $loader: null, + + init: function( element, options ) { + this.settings = $.extend( this.settings, options ); + this.feeds = this.settings.feeds; + + for ( var i in this.feeds ) { + if ( this.feeds.hasOwnProperty( i ) ) { + this.feedsLength++; + } + } + + var protocol = this.settings.ssl === 'auto' ? document.location.protocol : this.settings.ssl ? 'https:' : 'http:'; + if ( $.inArray( protocol, [ 'http:', 'https' ]) === -1 ) { + protocol = 'https:'; + } + + this.service = protocol + this.service; + + this.$element = $( element ); + + var render = typeof this.settings.loadingTemplate === 'function' ? this.settings.loadingTemplate : this.tmpl( this.settings.loadingTemplate ); + this.$loader = $( render.call( this, { } ) ); + this.$element.html( this.$loader ); + + var output = this.settings.xml ? 'json_xml' : 'json'; + + for ( var j in this.feeds ) { + this.fetchFeed( j, this.feeds[ j ], this.settings.max, output ); + } + }, + + fetchFeed: function( key, feed, max, output ) { + var self = this; + + var cacheKey = feed + '**' + max + '**' + output; + if ( typeof cache[ cacheKey ] !== 'undefined' ) { + self.processResponse( cache[ cacheKey ], key, feed ); + return; + } + + $.ajax( { + url: this.service, + dataType: 'jsonp', + data: { + q: feed, + num: max, + output: output + }, + beforeSend: function( ) { + this.feed = feed; + this.key = key; + }, + success: function( data ) { + cache[ cacheKey ] = data; + self.processResponse( data, this.key, this.feed ); + } + } ); + }, + + processResponse: function( data, key, feed ) { + if ( data.responseStatus !== 200 ) { + if ( window.console && window.console.log ) { + console.log( 'Unable to load feed ' + feed + ': (' + data.responseStatus + ') ' + data.responseDetails ); + } + } else { + var currentFeed = data.responseData.feed; + var feedEntries = currentFeed.entries; + + var type = data.responseData.feed.type; + + if ( this.settings.xml ) { + var $xml = $( data.responseData.xmlString ); + + if ( type.match( /^rss.*/ ) ) { + $xml = $xml.filter( 'rss' ).find( 'channel' ); + } else if ( type.match( /^atom.*/ ) ) { + $xml = $xml.filter( 'feed' ); + } + + currentFeed.xml = $xml; + } + + for ( var i in feedEntries ) { + var entry = $.extend( {}, feedEntries[ i ] ); + entry.source = key; + entry.publishedDateRaw = entry.publishedDate; + + entry.feedUrl = currentFeed.feedUrl; + entry.feedTitle = currentFeed.title; + entry.feedLink = currentFeed.link; + entry.feedDescription = currentFeed.description; + entry.feedAuthor = currentFeed.author; + + if ( this.settings.xml ) { + if ( type.match( /^rss.*/ ) ) { + entry.xml = currentFeed.xml.find( 'item' ).eq( i ); + } else if ( type.match( /^atom.*/ ) ) { + entry.xml = currentFeed.xml.find( 'entry' ).eq( i ); + } else { + entry.xml = { }; + } + } + + if ( this.settings.preprocess.call( entry, currentFeed ) !== false ) { + this.entries.push( entry ); + } + } + } + + this.feedsLoaded++; + this.checkComplete(); + }, + + checkComplete: function( ) { + if ( this.feedsLoaded === this.feedsLength ) { + this.$loader.remove( ); + + this.entries.sort( function( a, b) { + var aDate = new Date( a.publishedDateRaw ).getTime( ); + var bDate = new Date( b.publishedDateRaw ).getTime( ); + + return bDate - aDate; + } ); + + var render = typeof this.settings.entryTemplate === 'function' ? this.settings.entryTemplate : this.tmpl( this.settings.entryTemplate ); + + for ( var i in this.entries ) { + var entry = this.entries[ i ]; + + var html = render.call( this, entry ); + + this.$element.append( html ); + } + + this.settings.onComplete.call( this.$element[ 0 ], this.entries ); + } + }, + + + // Simple JavaScript Templating (modified) + // John Resig - http://ejohn.org/ - MIT Licensed + // @see http://ejohn.org/blog/javascript-micro-templating/ + tmplCache: {}, + tmpl: function tmpl( str, data ) { + + var fn = !/\W/.test( str ) ? this.tmplCache[ str ] = this.tmplCache[ str ] || this.tmpl( document.getElementById( str ).innerHTML ) : + + new Function( "obj", + "var p=[],print=function(){p.push.apply(p,arguments);};" + + + "with(obj){p.push('" + + str + .replace( /[\r\t\n]/g, " " ) + .split( ")[^\t]*)'/g, "$1\r" ) + .replace( /\t=(.*?)!>/g, "',typeof $1 != 'undefined' ? $1 : '','" ) + .split( "\t" ).join( "');" ) + .split( "!>" ).join( "p.push('" ) + .split( "\r" ).join( "\\'" ) + + "');}return p.join('');" + ); + + return data ? fn( data ) : fn; + } + }; + + return $( this ).each( function( ) { + engine.init( this, options ); + }); + }; +}( jQuery ) ); \ No newline at end of file diff --git a/2015/assets/js/jquery.feeds.min.js b/2015/assets/js/jquery.feeds.min.js new file mode 100644 index 00000000..305f66b2 --- /dev/null +++ b/2015/assets/js/jquery.feeds.min.js @@ -0,0 +1,17 @@ +/*! + * jQuery Feeds v0.5 + * https://camagu.github.com/jquery-feeds + * + * Copyright (c) 2013, Camilo Aguilar + * Dual licensed under the MIT and GPL licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl.html + * + * Includes a modified version of Simple JavaScript Templating + * http://ejohn.org/blog/javascript-micro-templating/ + * Copyright (c) John Resig (http://ejohn.org) + * MIT licensed + * + * Date: 2013-02-18 + */ +(function(e){var t={};e.fn.feeds=function(n){var r={service:"//ajax.googleapis.com/ajax/services/feed/load?v=1.0",settings:{loadingTemplate:'
Loading entries ...
',entryTemplate:'
',feeds:{},max:-1,xml:!1,ssl:"auto",onComplete:function(e){},preprocess:function(e){}},feeds:{},entries:[],feedsLength:0,feedsLoaded:0,$element:null,$loader:null,init:function(t,n){this.settings=e.extend(this.settings,n),this.feeds=this.settings.feeds;for(var r in this.feeds)this.feeds.hasOwnProperty(r)&&this.feedsLength++;var i=this.settings.ssl==="auto"?document.location.protocol:this.settings.ssl?"https:":"http:";e.inArray(i,["http:","https"])===-1&&(i="https:"),this.service=i+this.service,this.$element=e(t);var s=typeof this.settings.loadingTemplate=="function"?this.settings.loadingTemplate:this.tmpl(this.settings.loadingTemplate);this.$loader=e(s.call(this,{})),this.$element.html(this.$loader);var o=this.settings.xml?"json_xml":"json";for(var u in this.feeds)this.fetchFeed(u,this.feeds[u],this.settings.max,o)},fetchFeed:function(n,r,i,s){var o=this,u=r+"**"+i+"**"+s;if(typeof t[u]!="undefined"){o.processResponse(t[u],n,r);return}e.ajax({url:this.service,dataType:"jsonp",data:{q:r,num:i,output:s},beforeSend:function(){this.feed=r,this.key=n},success:function(e){t[u]=e,o.processResponse(e,this.key,this.feed)}})},processResponse:function(t,n,r){if(t.responseStatus!==200)window.console&&window.console.log&&console.log("Unable to load feed "+r+": ("+t.responseStatus+") "+t.responseDetails);else{var i=t.responseData.feed,s=i.entries,o=t.responseData.feed.type;if(this.settings.xml){var u=e(t.responseData.xmlString);o.match(/^rss.*/)?u=u.filter("rss").find("channel"):o.match(/^atom.*/)&&(u=u.filter("feed")),i.xml=u}for(var a in s){var f=e.extend({},s[a]);f.source=n,f.publishedDateRaw=f.publishedDate,f.feedUrl=i.feedUrl,f.feedTitle=i.title,f.feedLink=i.link,f.feedDescription=i.description,f.feedAuthor=i.author,this.settings.xml&&(o.match(/^rss.*/)?f.xml=i.xml.find("item").eq(a):o.match(/^atom.*/)?f.xml=i.xml.find("entry").eq(a):f.xml={}),this.settings.preprocess.call(f,i)!==!1&&this.entries.push(f)}}this.feedsLoaded++,this.checkComplete()},checkComplete:function(){if(this.feedsLoaded===this.feedsLength){this.$loader.remove(),this.entries.sort(function(e,t){var n=(new Date(e.publishedDateRaw)).getTime(),r=(new Date(t.publishedDateRaw)).getTime();return r-n});var e=typeof this.settings.entryTemplate=="function"?this.settings.entryTemplate:this.tmpl(this.settings.entryTemplate);for(var t in this.entries){var n=this.entries[t],r=e.call(this,n);this.$element.append(r)}this.settings.onComplete.call(this.$element[0],this.entries)}},tmplCache:{},tmpl:function(t,n){var r=/\W/.test(t)?new Function("obj","var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('"+t.replace(/[\r\t\n]/g," ").split(")[^\t]*)'/g,"$1\r").replace(/\t=(.*?)!>/g,"',typeof $1 != 'undefined' ? $1 : '','").split(" ").join("');").split("!>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');"):this.tmplCache[t]=this.tmplCache[t]||this.tmpl(document.getElementById(t).innerHTML);return n?r(n):r}};return e(this).each(function(){r.init(this,n)})}})(jQuery); \ No newline at end of file diff --git a/server/staging/lp15/weblabels.html b/server/staging/lp15/weblabels.html index f7bcbf5a..20c0960d 100644 --- a/server/staging/lp15/weblabels.html +++ b/server/staging/lp15/weblabels.html @@ -137,6 +137,16 @@ moment.js + + jquery.feeds.min.js + + Expat
+ GNU General + Public License version 3 or later + + jquery.feeds.js + + -- 2.25.1