1if (typeof Object.create !== 'function') { 2 Object.create = function(obj) { 3 function F() {} 4 F.prototype = obj; 5 return new F(); 6 }; 7} 8 9(function($, window, document, undefined) { 10 $.fn.socialfeed = function(_options) { 11 12 13 var defaults = { 14 plugin_folder: '', // a folder in which the plugin is located (with a slash in the end) 15 template: 'template.html', // a path to the template file 16 show_media: false, // show images of attachments if available 17 media_min_width: 300, 18 length: 500, // maximum length of post message shown 19 date_format: 'll' 20 }; 21 //--------------------------------------------------------------------------------- 22 var options = $.extend(defaults, _options), 23 container = $(this), 24 template, 25 social_networks = ['facebook', 'instagram', 'vk', 'google', 'blogspot', 'twitter', 'pinterest', 'rss'], 26 posts_to_load_count = 0, 27 loaded_post_count = 0; 28 // container.empty().css('display', 'block'); 29 //--------------------------------------------------------------------------------- 30 31 //--------------------------------------------------------------------------------- 32 // This function performs consequent data loading from all of the sources by calling corresponding functions 33 function calculatePostsToLoadCount() { 34 social_networks.forEach(function(network) { 35 if (options[network]) { 36 if (options[network].accounts) { 37 posts_to_load_count += options[network].limit * options[network].accounts.length; 38 } else { 39 posts_to_load_count += options[network].limit; 40 } 41 } 42 }); 43 } 44 45 calculatePostsToLoadCount(); 46 47 function fireCallback() { 48 var fire = true; 49 /*$.each(Object.keys(loaded), function() { 50 if (loaded[this] > 0) 51 fire = false; 52 });*/ 53 if (fire && options.callback) { 54 options.callback(); 55 } 56 } 57 58 var Utility = { 59 request: function(url, callback) { 60 $.ajax({ 61 url: url, 62 dataType: 'jsonp', 63 success: callback 64 }); 65 }, 66 get_request: function(url, callback) { 67 $.get(url, callback, 'json'); 68 }, 69 wrapLinks: function(string, social_network) { 70 var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; 71 if (social_network === 'google-plus') { 72 string = string.replace(/(@|#)([a-z0-9_]+['])/ig, Utility.wrapGoogleplusTagTemplate); 73 } else { 74 string = string.replace(exp, Utility.wrapLinkTemplate); 75 } 76 return string; 77 }, 78 wrapLinkTemplate: function(string) { 79 return '<a target="_blank" href="' + string + '">' + string + '<\/a>'; 80 }, 81 wrapGoogleplusTagTemplate: function(string) { 82 return '<a target="_blank" href="https://plus.google.com/s/' + string + '" >' + string + '<\/a>'; 83 }, 84 shorten: function(string) { 85 string = $.trim(string); 86 if (string.length > options.length) { 87 return jQuery.trim(string).substring(0, options.length).split(" ").slice(0, -1).join(" ") + "..."; 88 } else { 89 return string; 90 } 91 }, 92 stripHTML: function(string) { 93 if (typeof string === "undefined" || string === null) { 94 return ''; 95 } 96 return string.replace(/(<([^>]+)>)|nbsp;|\s{2,}|/ig, ""); 97 } 98 }; 99 100 function SocialFeedPost(social_network, data) { 101 this.content = data; 102 this.content.social_network = social_network; 103 this.content.attachment = (this.content.attachment === undefined) ? '' : this.content.attachment; 104 this.content.time_ago = data.dt_create.fromNow(); 105 this.content.date = data.dt_create.format(options.date_format); 106 this.content.dt_create = this.content.dt_create.valueOf(); 107 this.content.text = Utility.wrapLinks(Utility.shorten(data.message + ' ' + data.description), data.social_network); 108 this.content.moderation_passed = (options.moderation) ? options.moderation(this.content) : true; 109 110 Feed[social_network].posts.push(this); 111 } 112 SocialFeedPost.prototype = { 113 render: function() { 114 var rendered_html = Feed.template(this.content); 115 var data = this.content; 116 117 if ($(container).children('[social-feed-id=' + data.id + ']').length !== 0) { 118 return false;
119 } 120 if ($(container).children().length === 0) { 121 $(container).append(rendered_html); 122 } else { 123 var i = 0, 124 insert_index = -1; 125 $.each($(container).children(), function() { 126 if ($(this).attr('dt-create') < data.dt_create) { 127 insert_index = i; 128 return false; 129 } 130 i++; 131 }); 132 $(container).append(rendered_html); 133 if (insert_index >= 0) { 134 insert_index++; 135 var before = $(container).children('div:nth-child(' + insert_index + ')'), 136 current = $(container).children('div:last-child'); 137 $(current).insertBefore(before); 138 } 139 140 } 141 if (options.media_min_width) { 142 143 var query = '[social-feed-id=' + data.id + '] img.attachment'; 144 var image = $(query); 145 146 // preload the image 147 var height, width = ''; 148 var img = new Image(); 149 var imgSrc = image.attr("src"); 150 151 $(img).on('load', function() { 152 153 if (img.width < options.media_min_width) { 154 image.hide(); 155 } 156 // garbage collect img 157 delete img; 158 159 }).on('error', function() { 160 // image couldnt be loaded 161 image.hide(); 162 163 }).attr({ 164 src: imgSrc 165 }); 166 167 } 168 169 loaded_post_count++; 170 if (loaded_post_count == posts_to_load_count) { 171 fireCallback(); 172 } 173 174 } 175 176 }; 177 178 var Feed = { 179 template: false, 180 init: function() { 181 Feed.getTemplate(function() { 182 social_networks.forEach(function(network) { 183 if (options[network]) { 184 if ( options[network].accounts ) { 185 //loaded[network] = 0; 186 options[network].accounts.forEach(function(account) { 187 //loaded[network]++; 188 Feed[network].getData(account); 189 }); 190 } else if ( options[network].urls ) { 191 options[network].urls.forEach(function(url) { 192 Feed[network].getData(url); 193 }); 194 } else { 195 Feed[network].getData(); 196 } 197 } 198 }); 199 }); 200 }, 201 getTemplate: function(callback) { 202 if (Feed.template) 203 return callback(); 204 else { 205 if (options.template_html) { 206 Feed.template = doT.template(options.template_html); 207 return callback(); 208 } else { 209 $.get(options.template, function(template_html) { 210 Feed.template = doT.template(template_html); 211 return callback(); 212 }); 213 } 214 } 215 }, 216 twitter: { 217 posts: [], 218 loaded: false, 219 api: 'http://api.tweecool.com/', 220 221 getData: function(account) { 222 223 var cb = new Codebird(); 224 cb.setConsumerKey(options.twitter.consumer_key, options.twitter.consumer_secret); 225 226 // Allow setting your own proxy with Codebird 227 if (options.twitter.proxy !== undefined) { 228 cb.setProxy(options.twitter.proxy); 229 } 230 231 switch (account[0]) { 232 case '@': 233 var userid = account.substr(1); 234 cb.__call( 235 "statuses_userTimeline", 236 "id=" + userid + "&count=" + options.twitter.limit, 237 Feed.twitter.utility.getPosts, 238 true // this parameter required 239 ); 240 break; 241 case '#': 242 var hashtag = account.substr(1); 243 cb.__call( 244 "search_tweets", 245 "q=" + hashtag + "&count=" + options.twitter.limit, 246 function(reply) { 247 Feed.twitter.utility.getPosts(reply.statuses); 248 }, 249 true // this parameter required 250 ); 251 break; 252 default: 253 } 254 }, 255 utility: { 256 getPosts: function(json) { 257 if (json) { 258 $.each(json, function() { 259 var element = this; 260 var post = new SocialFeedPost('twitter', Feed.twitter.utility.unifyPostData(element)); 261 post.render(); 262 }); 263 } 264 }, 265 unifyPostData: function(element) { 266 var post = {};
267 if (element.id) { 268 post.id = element.id; 269 //prevent a moment.js console warning due to Twitter's poor date format. 270 post.dt_create = moment(new Date(element.created_at)); 271 post.author_link = 'http://twitter.com/' + element.user.screen_name; 272 post.author_picture = element.user.profile_image_url; 273 post.post_url = post.author_link + '/status/' + element.id_str; 274 post.author_name = element.user.name; 275 post.message = element.text; 276 post.description = ''; 277 post.link = 'http://twitter.com/' + element.user.screen_name + '/status/' + element.id_str; 278 279 if (options.show_media === true) { 280 if (element.entities.media && element.entities.media.length > 0) { 281 var image_url = element.entities.media[0].media_url; 282 if (image_url) { 283 post.attachment = '<img class="attachment" src="' + image_url + '" />'; 284 } 285 } 286 } 287 } 288 return post; 289 } 290 } 291 }, 292 facebook: { 293 posts: [], 294 graph: 'https://graph.facebook.com/', 295 loaded: false, 296 getData: function(account) { 297 var proceed = function(request_url){ 298 Utility.request(request_url, Feed.facebook.utility.getPosts); 299 }; 300 var fields = '?fields=id,from,message,created_time,story,permalink_url'; 301 fields += (options.show_media === true)?',picture,full_picture':''; 302 var request_url, limit = '&limit=' + options.facebook.limit,
303 query_extention = '&access_token=' + options.facebook.access_token + '&callback=?'; 304 switch (account[0]) { 305 case '@': 306 var username = account.substr(1); 307 Feed.facebook.utility.getUserId(username, function(userdata) { 308 if (userdata.id !== '') { 309 request_url = Feed.facebook.graph + 'v2.4/' + userdata.id + '/posts'+ fields + limit + query_extention; 310 proceed(request_url); 311 } 312 }); 313 break; 314 case '!': 315 var page = account.substr(1); 316 request_url = Feed.facebook.graph + 'v2.4/' + page + '/feed'+ fields + limit + query_extention; 317 proceed(request_url); 318 break; 319 default: 320 proceed(request_url); 321 } 322 }, 323 utility: { 324 getUserId: function(username, callback) {
325 var query_extention = '&access_token=' + options.facebook.access_token + '&callback=?'; 326 var url = 'https://graph.facebook.com/' + username + '?' + query_extention; 327 var result = ''; 328 $.get(url, callback, 'json'); 329 }, 330 prepareAttachment: function(element) { 331 var image_url = element.picture; 332 if (image_url.indexOf('_b.') !== -1) { 333 //do nothing it is already big 334 } else if (image_url.indexOf('safe_image.php') !== -1) { 335 image_url = Feed.facebook.utility.getExternalImageURL(image_url, 'url'); 336 337 } else if (image_url.indexOf('app_full_proxy.php') !== -1) { 338 image_url = Feed.facebook.utility.getExternalImageURL(image_url, 'src'); 339 340 } else if (element.object_id) { 341 image_url = Feed.facebook.graph + element.object_id + '/picture/?type=normal'; 342 } 343 return '<img class="attachment" src="' + image_url + '" />'; 344 }, 345 getExternalImageURL: function(image_url, parameter) { 346 image_url = decodeURIComponent(image_url).split(parameter + '=')[1]; 347 if (image_url.indexOf('fbcdn-sphotos') === -1) { 348 return image_url.split('&')[0]; 349 } else { 350 return image_url; 351 } 352 353 }, 354 getPosts: function(json) { 355 if (json['data']) { 356 json['data'].forEach(function(element) { 357 var post = new SocialFeedPost('facebook', Feed.facebook.utility.unifyPostData(element)); 358 post.render(); 359 }); 360 } 361 }, 362 unifyPostData: function(element) { 363 var post = {}, 364 text = (element.message) ? element.message : element.story; 365 366 post.id = element.id; 367 post.dt_create = moment(element.created_time); 368 post.author_link = 'http://facebook.com/' + element.from.id; 369 post.author_picture = Feed.facebook.graph + element.from.id + '/picture'; 370 post.author_name = element.from.name; 371 post.name = element.name || ""; 372 post.message = (text) ? text : ''; 373 post.description = (element.description) ? element.description : ''; 374 post.link = (element.link) ? element.link : 'http://facebook.com/' + element.from.id; 375 post.permalink_url = element.permalink_url; 376 // post.large_image = (element.full_picture) ? element.full_picture : attachment 377 378 if (options.show_media === true) { 379 if (element.picture) { 380 var attachment = Feed.facebook.utility.prepareAttachment(element); 381 if (attachment) { 382 post.attachment = attachment; 383 if (element.full_picture) { 384 post.large_image = element.full_picture; 385 post.attachment = '<img class="attachment" src="'+ post.large_image +'" />'; 386 } 387 } 388 } 389 } 390 return post; 391 } 392 } 393 }, 394 google: { 395 posts: [], 396 loaded: false, 397 api: 'https://www.googleapis.com/plus/v1/', 398 getData: function(account) { 399 var request_url; 400 switch (account[0]) { 401 case '#': 402 var hashtag = account.substr(1); 403 request_url = Feed.google.api + 'activities?query=' + hashtag + '&key=' + options.google.access_token + '&maxResults=' + options.google.limit; 404 Utility.get_request(request_url, Feed.google.utility.getPosts); 405 break; 406 case '@': 407 var username = account.substr(1); 408 request_url = Feed.google.api + 'people/' + username + '/activities/public?key=' + options.google.access_token + '&maxResults=' + options.google.limit; 409 Utility.get_request(request_url, Feed.google.utility.getPosts); 410 break; 411 default: 412 } 413 }, 414 utility: { 415 getPosts: function(json) { 416 if (json.items) { 417 $.each(json.items, function(i) { 418 var post = new SocialFeedPost('google', Feed.google.utility.unifyPostData(json.items[i])); 419 post.render(); 420 }); 421 } 422 }, 423 unifyPostData: function(element) { 424 var post = {}; 425
426 post.id = element.id; 427 post.attachment = ''; 428 post.description = ''; 429 post.dt_create = moment(element.published); 430 post.author_link = element.actor.url; 431 post.author_picture = element.actor.image.url; 432 post.author_name = element.actor.displayName; 433 434 if (options.show_media === true) { 435 if (element.object.attachments) { 436 $.each(element.object.attachments, function() { 437 var image = ''; 438 if (this.fullImage) { 439 image = this.fullImage.url; 440 } else { 441 if (this.objectType === 'album') { 442 if (this.thumbnails && this.thumbnails.length > 0) { 443 if (this.thumbnails[0].image) { 444 image = this.thumbnails[0].image.url; 445 } 446 } 447 } 448 } 449 post.attachment = '<img class="attachment" src="' + image
449+ '"/>'; 450 }); 451 } 452 } 453 post.message = element.title; 454 post.link = element.url; 455 456 return post; 457 } 458 } 459 }, 460 instagram: { 461 posts: [], 462 api: 'https://api.instagram.com/v1/', 463 loaded: false, 464 accessType: function() { 465 // If we have both the client_id and access_token set in options, 466 // use access_token for authentication. If client_id is not set 467 // then use access_token. If neither are set, log an error to console. 468 if (typeof options.instagram.access_token === 'undefined' && typeof options.instagram.client_id === 'undefined') { 469 console.log('You need to define a client_id or access_token to authenticate with Instagram\'s API.'); 470 return undefined; 471 } 472 if (options.instagram.access_token) { options.instagram.client_id = undefined; } 473 options.instagram.access_type = (typeof options.instagram.client_id === 'undefined' ? 'access_token' : 'client_id'); 474 return options.instagram.access_type; 475 }, 476 getData: function(account) { 477 var url; 478 479 // API endpoint URL depends on which authentication type we're using. 480 if (this.accessType() !== 'undefined') { 481 var authTokenParams = options.instagram.access_type + '=' + options.instagram[options.instagram.access_type]; 482 } 483 484 switch (account[0]) { 485 case '@': 486 var username = account.substr(1); 487 url = Feed.instagram.api + 'users/search/?q=' + username + '&' + authTokenParams + '&count=1' + '&callback=?'; 488 Utility.request(url, Feed.instagram.utility.getUsers); 489 break; 490 case '#': 491 var hashtag = account.substr(1); 492 url = Feed.instagram.api + 'tags/' + hashtag + '/media/recent/?' + authTokenParams + '&' + 'count=' + options.instagram.limit + '&callback=?'; 493 Utility.request(url, Feed.instagram.utility.getImages); 494 break; 495 case '&': 496 var id = account.substr(1); 497 url = Feed.instagram.api + 'users/' + id + '/?' + authTokenParams + '&' + 'count=' + options.instagram.limit + '&callback=?'; 498 Utility.request(url, Feed.instagram.utility.getUsers); 499 default: 500 } 501 }, 502 utility: { 503 getImages: function(json) { 504 if (json.data) { 505 json.data.forEach(function(element) { 506 var post = new SocialFeedPost('instagram', Feed.instagram.utility.unifyPostData(element)); 507 post.render(); 508 }); 509 } 510 }, 511 getUsers: function(json) { 512 // API endpoint URL depends on which authentication type we're using. 513 if (options.instagram.access_type !== 'undefined') { 514 var authTokenParams = options.instagram.access_type + '=' + options.instagram[options.instagram.access_type]; 515 } 516 517 if (!jQuery.isArray(json.data)) json.data = [json.data] 518 json.data.forEach(function(user) { 519 var url = Feed.instagram.api + 'users/' + user.id + '/media/recent/?' + authTokenParams + '&' + 'count=' + options.instagram.limit + '&callback=?'; 520 Utility.request(url, Feed.instagram.utility.getImages); 521 }); 522 }, 523 unifyPostData: function(element) { 524 var post = {}; 525
526 post.id = element.id; 527 post.dt_create = moment(element.created_time * 1000); 528 post.author_link = 'http://instagram.com/' + element.user.username; 529 post.author_picture = element.user.profile_picture; 530 post.author_name = element.user.full_name || element.user.username; 531 post.message = (element.caption && element.caption) ? element.caption.text : ''; 532 post.description = ''; 533 post.link = element.link; 534 if (options.show_media) { 535 post.attachment = '<img class="attachment" src="' + element.images.standard_resolution.url + '' + '" />'; 536 } 537 return post; 538 } 539 } 540 }, 541 vk: { 542 posts: [], 543 loaded: false, 544 base: 'http://vk.com/', 545 api: 'https://api.vk.com/method/', 546 user_json_template: 'https://api.vk.com/method/' + 'users.get?fields=first_name,%20last_name,%20screen_name,%20photo&uid=', 547 group_json_template: 'https://api.vk.com/method/' + 'groups.getById?fields=first_name,%20last_name,%20screen_name,%20photo&gid=', 548 getData: function(account) { 549 var request_url; 550 551 switch (account[0]) { 552 case '@': 553 var username = account.substr(1); 554 request_url = Feed.vk.api + 'wall.get?owner_id=' + username + '&filter=' + options.vk.source + '&count=' + options.vk.limit + '&callback=?'; 555 Utility.get_request(request_url, Feed.vk.utility.getPosts); 556 break; 557 case '#': 558 var hashtag = account.substr(1); 559 request_url = Feed.vk.api + 'newsfeed.search?q=' + hashtag + '&count=' + options.vk.limit + '&callback=?'; 560 Utility.get_request(request_url, Feed.vk.utility.getPosts); 561 break; 562 default: 563 } 564 }, 565 utility: { 566 getPosts: function(json) { 567 if (json.response) { 568 $.each(json.response, function() { 569 if (this != parseInt(this) && this.post_type === 'post') { 570 var owner_id = (this.owner_id) ? this.owner_id : this.from_id, 571 vk_wall_owner_url = (owner_id > 0) ? (Feed.vk.user_json_template + owner_id + '&callback=?') : (Feed.vk.group_json_template + (-1) * owner_id + '&callback=?'), 572 element = this; 573 Utility.get_request(vk_wall_owner_url, function(wall_owner) { 574 Feed.vk.utility.unifyPostData(wall_owner, element, json); 575 }); 576 } 577 }); 578 } 579 }, 580 unifyPostData: function(wall_owner, element, json) { 581 var post = {}; 582 583 post.id = element.id; 584 post.dt_create = moment.unix(element.date); 585 post.description = ' '; 586 post.message = Utility.stripHTML(element.text); 587 if (options.show_media) { 588 if (element.attachment) { 589 if (element.attachment.type === 'link') 590 post.attachment = '<img class="attachment" src="' + element.attachment.link.image_src + '" />'; 591 if (element.attachment.type === 'video') 592 post.attachment = '<img class="attachment" src="' + element.attachment.video.image_big + '" />'; 593 if (element.attachment.type === 'photo') 594 post.attachment = '<img class="attachment" src="' + element.attachment.photo.src_big + '" />'; 595 } 596 } 597 598 if (element.from_id > 0) { 599 var vk_user_json = Feed.vk.user_json_template + element.from_id + '&callback=?'; 600 Utility.get_request(vk_user_json, function(user_json) { 601 var vk_post = new SocialFeedPost('vk', Feed.vk.utility.getUser(user_json, post, element, json)); 602 vk_post.render(); 603 }); 604 605 } else { 606 var vk_group_json = Feed.vk.group_json_template + (-1) * element.from_id + '&callback=?'; 607 Utility.get_request(vk_group_json, function(user_json) { 608 var vk_post = new SocialFeedPost('vk', Feed.vk.utility.getGroup(user_json, post, element, json)); 609 vk_post.render(); 610 }); 611 } 612 }, 613 getUser: function(user_json, post, element, json) { 614 post.author_name = user_json.response[0].first_name + ' ' + user_json.response[0].last_name; 615 post.author_picture = user_json.response[0].photo; 616 post.author_link = Feed.vk.base + user_json.response[0].screen_name; 617 post.link = Feed.vk.base + user_json.response[0].screen_name + '?w=wall' + element.from_id + '_' + element.i
617d; 618 619 return post; 620 }, 621 getGroup: function(user_json, post, element, json) { 622 post.author_name = user_json.response[0].name; 623 post.author_picture = user_json.response[0].photo; 624 post.author_link = Feed.vk.base + user_json.response[0].screen_name; 625 post.link = Feed.vk.base + user_json.response[0].screen_name + '?w=wall-' + user_json.response[0].gid + '_' + element.id; 626 627 return post; 628 } 629 } 630 }, 631 blogspot: { 632 loaded: false, 633 getData: function(account) { 634 var url; 635 636 switch (account[0]) { 637 case '@': 638 var username = account.substr(1); 639 url = 'http://' + username + '.blogspot.com/feeds/posts/default?alt=json-in-script&callback=?'; 640 request(url, getPosts); 641 break; 642 default: 643 } 644 }, 645 utility: { 646 getPosts: function(json) { 647 $.each(json.feed.entry, function() { 648 var post = {}, 649 element = this; 650 post.id = element.id['$t'].replace(/[^a-z0-9]/gi, ''); 651 post.dt_create = moment((element.published['$t'])); 652 post.author_link = element.author[0]['uri']['$t']; 653 post.author_picture = 'http:' + element.author[0]['gd$image']['src']; 654 post.author_name = element.author[0]['name']['$t']; 655 post.message = element.title['$t'] + '</br></br>' + stripHTML(element.content['$t']); 656 post.description = ''; 657 post.link = element.link.pop().href; 658 659 if (options.show_media) { 660 if (element['media$thumbnail']) { 661 post.attachment = '<img class="attachment" src="' + element['media$thumbnail']['url'] + '" />'; 662 } 663 } 664 665 post.render(); 666 667 }); 668 } 669 } 670 }, 671 pinterest: { 672 posts: [], 673 loaded: false, 674 apiv1: 'https://api.pinterest.com/v1/', 675 676 getData: function(account) { 677 var request_url, 678 limit = 'limit=' + options.pinterest.limit, 679 fields = 'fields=id,created_at,link,note,creator(url,first_name,last_name,image),image', 680 query_extention = fields + '&access_token='
680+ options.pinterest.access_token + '&' + limit + '&callback=?'; 681 switch (account[0]) { 682 case '@': 683 var username = account.substr(1); 684 if (username === 'me') { 685 request_url = Feed.pinterest.apiv1 + 'me/pins/?' + query_extention; 686 } else { 687 request_url = Feed.pinterest.apiv1 + 'boards/' + username + '/pins?' + query_extention; 688 } 689 break; 690 default: 691 } 692 Utility.request(request_url, Feed.pinterest.utility.getPosts); 693 }, 694 utility: { 695 696 getPosts: function(json) { 697 json.data.forEach(function(element) { 698 var post = new SocialFeedPost('pinterest', Feed.pinterest.utility.unifyPostData(element)); 699 post.render(); 700 }); 701 }, 702 703 unifyPostData: function(element){ 704 var post = {}; 705 706 post.id = element.id; 707 post.dt_create= moment(element.created_at); 708 post.author_link = element.creator.url; 709 post.author_picture = element.creator.image['60x60' ].url; 710 post.author_name = element.creator.first_name + element.creator.last_name; 711 post.message = element.note; 712 post.description = ''; 713 post.social_network = 'pinterest'; 714 post.link = element.link ? element.link : 'https://www.pinterest.com/pin/' + element.id; 715 if (options.show_media) { 716 post.attachment = '<img class="attachment" src="' + element.image['original'].url + '" />'; 717 } 718 return post; 719 } 720 } 721 }, 722 rss : { 723 posts: [], 724 loaded: false, 725 api : 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0', 726 727 getData: function(url) { 728 var limit = '&num='+ options.rss.limit, 729 request_url = Feed.rss.api + limit + '&q=' + encodeURIComponent(url); 730 731 Utility.request(request_url, Feed.rss.utility.getPosts); 732 }, 733 utility: { 734 735 getPosts: function(json) { 736 $.each(json.responseData.feed.entries, function(index, element) { 737 var post = new SocialFeedPost('rss', Feed.rss.utility.unifyPostData(index, element)); 738 post.render(); 739 }); 740 }, 741 742 unifyPostData: function(index, element){ 743 var post = {}; 744 745 post.id = index; 746 post.dt_create= moment(element.publishedDate, 'ddd, DD MMM YYYY HH:mm:ss ZZ', 'en'); 747 post.author_link = ''; 748 post.author_picture = ''; 749 post.author_name = element.author; 750 post.message = Utility.stripHTML(element.title); 751 post.description = Utility.stripHTML(element.content); 752 post.social_network = 'rss'; 753 post.link = element.link; 754 if (options.show_media && element.mediaGroups ) { 755 post.attachment = '<img class="attachment" src="' + element.mediaGroups[0].contents[0].url + '" />'; 756 } 757 return post; 758 } 759 } 760 } 761 }; 762 763 //make the plugin chainable 764 return this.each(function() { 765 // Initialization 766 Feed.init(); 767 if (options.update_period) { 768 setInterval(function() { 769 return Feed.init(); 770 }, options.update_period); 771 } 772 }) 773 }; 774 775})(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.