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