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 Utility.request(request_url, Feed.facebook.utility.getPosts); 309 }; 310 var fields = '?fields=id,from,name,message,created_time,story,description,link'; 311 fields += (options.show_media === true)?',picture,object_id':''; 312 var request_url, limit = '&limit=' + options.facebook.limit,
313 query_extention = '&access_token=' + options.facebook.access_token + '&callback=?'; 314 switch (account[0]) { 315 case '@': 316 var username = account.substr(1); 317 Feed.facebook.utility.getUserId(username, function(userdata) { 318 if (userdata.id !== '') { 319 request_url = Feed.facebook.graph + 'v2.12/' + userdata.id + '/posts'+ fields + limit + query_extention; 320 proceed(request_url); 321 } 322 }); 323 break; 324 case '!': 325 var page = account.substr(1); 326 request_url = Feed.facebook.graph + 'v2.12/' + page + '/feed'+ fields + limit + query_extention; 327 proceed(request_url); 328 break; 329 default: 330 proceed(request_url); 331 } 332 }, 333 utility: { 334 getUserId: function(username, callback) {
335 var query_extention = '&access_token=' + options.facebook.access_token + '&callback=?'; 336 var url = 'https://graph.facebook.com/' + username + '?' + query_extention; 337 var result = ''; 338 $.get(url, callback, 'json'); 339 }, 340 prepareAttachment: function(element) { 341 var image_url = element.picture; 342 if (image_url.indexOf('_b.') !== -1) { 343 //do nothing it is already big 344 } else if (image_url.indexOf('safe_image.php') !== -1) { 345 image_url = Feed.facebook.utility.getExternalImageURL(image_url, 'url'); 346 347 } else if (image_url.indexOf('app_full_proxy.php') !== -1) { 348 image_url = Feed.facebook.utility.getExternalImageURL(image_url, 'src'); 349 350 } else if (element.object_id) { 351 image_url = Feed.facebook.graph + element.object_id + '/picture/?type=normal'; 352 } 353 return '<img class="attachment" src="' + image_url + '" />'; 354 }, 355 getExternalImageURL: function(image_url, parameter) { 356 image_url = decodeURIComponent(image_url).split(parameter + '=')[1]; 357 if (image_url.indexOf('fbcdn-sphotos') === -1) { 358 return image_url.split('&')[0]; 359 } else { 360 return image_url; 361 } 362 363 }, 364 getPosts: function(json) { 365 if (json['data']) { 366 json['data'].forEach(function(element) { 367 var post = new SocialFeedPost('facebook', Feed.facebook.utility.unifyPostData(element)); 368 post.render(); 369 }); 370 } 371 }, 372 unifyPostData: function(element) { 373 var post = {}, 374 text = (element.message) ? element.message : element.story; 375 376 post.id = element.id; 377 post.dt_create = moment(element.created_time); 378 post.author_link = 'http://facebook.com/' + element.from.id; 379 post.author_picture = Feed.facebook.graph + element.from.id + '/picture'; 380 post.author_name = element.from.name; 381 post.name = element.name || ""; 382 post.message = (text) ? text : ''; 383 post.description = (element.description) ? element.description : ''; 384 post.link = (element.link) ? element.link : 'http://facebook.com/' + element.from.id; 385 386 if (options.show_media === true) { 387 if (element.picture) { 388 var attachment = Feed.facebook.utility.prepareAttachment(element); 389 if (attachment) { 390 post.attachment = attachment; 391 } 392 } 393 } 394 return post; 395 } 396 } 397 }, 398 google: { 399 posts: [], 400 loaded: false, 401 api: 'https://www.googleapis.com/plus/v1/', 402 getData: function(account) { 403 var request_url; 404 switch (account[0]) { 405 case '#': 406 var hashtag = account.substr(1); 407 request_url = Feed.google.api + 'activities?query=' + hashtag + '&key=' + options.google.access_token + '&maxResults=' + options.google.limit; 408 Utility.get_request(request_url, Feed.google.utility.getPosts); 409 break; 410 case '@': 411 var username = account.substr(1); 412 request_url = Feed.google.api + 'people/' + username + '/activities/public?key=' + options.google.access_token + '&maxResults=' + options.google.limit; 413 Utility.get_request(request_url, Feed.google.utility.getPosts); 414 break; 415 default: 416 } 417 }, 418 utility: { 419 getPosts: function(json) { 420 if (json.items) { 421 $.each(json.items, function(i) { 422 var post = new SocialFeedPost('google', Feed.google.utility.unifyPostData(json.items[i])); 423 post.render(); 424 }); 425 } 426 }, 427 unifyPostData: function(element) { 428 var post = {}; 429
430 post.id = element.id; 431 post.attachment = ''; 432 post.description = ''; 433 post.dt_create = moment(element.published); 434 post.author_link = element.actor.url; 435 post.author_picture = element.actor.image.url; 436 post.author_name = element.actor.displayName; 437 438 if (options.show_media === true) { 439 if (element.object.attachments) { 440 $.each(element.object.attachments, function() { 441 var image = ''; 442 if (this.fullImage) { 443 image = this.fullImage.url; 444 } else { 445 if (this.objectType === 'album') { 446 if (this.thumbnails && this.thumbnails.length > 0) { 447 if (this.thumbnails[0].image) { 448 image = this.thumbnails[0].image.url; 449 } 450 } 451 } 452 } 453 post.attachment = '<img class="attachment" src="' + image
453+ '"/>'; 454 }); 455 } 456 } 457 post.message = element.title; 458 post.link = element.url; 459 460 return post; 461 } 462 } 463 }, 464 instagram: { 465 posts: [], 466 api: 'https://api.instagram.com/v1/', 467 loaded: false, 468 accessType: function() { 469 // If we have both the client_id and access_token set in options, 470 // use access_token for authentication. If client_id is not set 471 // then use access_token. If neither are set, log an error to console. 472 if (typeof options.instagram.access_token === 'undefined' && typeof options.instagram.client_id === 'undefined') { 473 console.log('You need to define a client_id or access_token to authenticate with Instagram\'s API.'); 474 return undefined; 475 } 476 if (options.instagram.access_token) { options.instagram.client_id = undefined; } 477 options.instagram.access_type = (typeof options.instagram.client_id === 'undefined' ? 'access_token' : 'client_id'); 478 return options.instagram.access_type; 479 }, 480 getData: function(account) { 481 var url; 482 483 // API endpoint URL depends on which authentication type we're using. 484 if (this.accessType() !== 'undefined') { 485 var authTokenParams = options.instagram.access_type + '=' + options.instagram[options.instagram.access_type]; 486 } 487 488 switch (account[0]) { 489 case '@': 490 var username = account.substr(1); 491 url = Feed.instagram.api + 'users/search/?q=' + username + '&' + authTokenParams + '&count=1' + '&callback=?'; 492 Utility.request(url, Feed.instagram.utility.getUsers); 493 break; 494 case '#': 495 var hashtag = account.substr(1); 496 url = Feed.instagram.api + 'tags/' + hashtag + '/media/recent/?' + authTokenParams + '&' + 'count=' + options.instagram.limit + '&callback=?'; 497 Utility.request(url, Feed.instagram.utility.getImages); 498 break; 499 case '&': 500 var id = account.substr(1); 501 url = Feed.instagram.api + 'users/' + id + '/?' + authTokenParams + '&' + 'count=' + options.instagram.limit + '&callback=?'; 502 Utility.request(url, Feed.instagram.utility.getUsers); 503 default: 504 } 505 }, 506 utility: { 507 getImages: function(json) { 508 if (json.data) { 509 json.data.forEach(function(element) { 510 var post = new SocialFeedPost('instagram', Feed.instagram.utility.unifyPostData(element)); 511 post.render(); 512 }); 513 } 514 }, 515 getUsers: function(json) { 516 // API endpoint URL depends on which authentication type we're using. 517 if (options.instagram.access_type !== 'undefined') { 518 var authTokenParams = options.instagram.access_type + '=' + options.instagram[options.instagram.access_type]; 519 } 520 521 if (!jQuery.isArray(json.data)) json.data = [json.data] 522 json.data.forEach(function(user) { 523 var url = Feed.instagram.api + 'users/' + user.id + '/media/recent/?' + authTokenParams + '&' + 'count=' + options.instagram.limit + '&callback=?'; 524 Utility.request(url, Feed.instagram.utility.getImages); 525 }); 526 }, 527 unifyPostData: function(element) { 528 var post = {}; 529
530 post.id = element.id; 531 post.dt_create = moment(element.created_time * 1000); 532 post.author_link = 'http://instagram.com/' + element.user.username; 533 post.author_picture = element.user.profile_picture; 534 post.author_name = element.user.full_name || element.user.username; 535 post.message = (element.caption && element.caption) ? element.caption.text : ''; 536 post.description = ''; 537 post.link = element.link; 538 if (options.show_media) { 539 post.attachment = '<img class="attachment" src="' + element.images.standard_resolution.url + '' + '" />'; 540 } 541 return post; 542 } 543 } 544 }, 545 vk: { 546 posts: [], 547 loaded: false, 548 base: 'http://vk.com/', 549 api: 'https://api.vk.com/method/', 550 user_json_template: 'https://api.vk.com/method/' + 'users.get?fields=first_name,%20last_name,%20screen_name,%20photo&uid=', 551 group_json_template: 'https://api.vk.com/method/' + 'groups.getById?fields=first_name,%20last_name,%20screen_name,%20photo&gid=', 552 getData: function(account) { 553 var request_url; 554 555 switch (account[0]) { 556 case '@': 557 var username = account.substr(1); 558 request_url = Feed.vk.api + 'wall.get?owner_id=' + username + '&filter=' + options.vk.source + '&count=' + options.vk.limit + '&callback=?'; 559 Utility.get_request(request_url, Feed.vk.utility.getPosts); 560 break; 561 case '#': 562 var hashtag = account.substr(1); 563 request_url = Feed.vk.api + 'newsfeed.search?q=' + hashtag + '&count=' + options.vk.limit + '&callback=?'; 564 Utility.get_request(request_url, Feed.vk.utility.getPosts); 565 break; 566 default: 567 } 568 }, 569 utility: { 570 getPosts: function(json) { 571 if (json.response) { 572 $.each(json.response, function() { 573 if (this != parseInt(this) && this.post_type === 'post') { 574 var owner_id = (this.owner_id) ? this.owner_id : this.from_id, 575 vk_wall_owner_url = (owner_id > 0) ? (Feed.vk.user_json_template + owner_id + '&callback=?') : (Feed.vk.group_json_template + (-1) * owner_id + '&callback=?'), 576 element = this; 577 Utility.get_request(vk_wall_owner_url, function(wall_owner) { 578 Feed.vk.utility.unifyPostData(wall_owner, element, json); 579 }); 580 } 581 }); 582 } 583 }, 584 unifyPostData: function(wall_owner, element, json) { 585 var post = {}; 586 587 post.id = element.id; 588 post.dt_create = moment.unix(element.date); 589 post.description = ' '; 590 post.message = Utility.stripHTML(element.text); 591 if (options.show_media) { 592 if (element.attachment) { 593 if (element.attachment.type === 'link') 594 post.attachment = '<img class="attachment" src="' + element.attachment.link.image_src + '" />'; 595 if (element.attachment.type === 'video') 596 post.attachment = '<img class="attachment" src="' + element.attachment.video.image_big + '" />'; 597 if (element.attachment.type === 'photo') 598 post.attachment = '<img class="attachment" src="' + element.attachment.photo.src_big + '" />'; 599 } 600 } 601 602 if (element.from_id > 0) { 603 var vk_user_json = Feed.vk.user_json_template + element.from_id + '&callback=?'; 604 Utility.get_request(vk_user_json, function(user_json) { 605 var vk_post = new SocialFeedPost('vk', Feed.vk.utility.getUser(user_json, post, element, json)); 606 vk_post.render(); 607 }); 608 609 } else { 610 var vk_group_json = Feed.vk.group_json_template + (-1) * element.from_id + '&callback=?'; 611 Utility.get_request(vk_group_json, function(user_json) { 612 var vk_post = new SocialFeedPost('vk', Feed.vk.utility.getGroup(user_json, post, element, json)); 613 vk_post.render(); 614 }); 615 } 616 }, 617 getUser: function(user_json, post, element, json) { 618 post.author_name = user_json.response[0].first_name + ' ' + user_json.response[0].last_name; 619 post.author_picture = user_json.response[0].photo; 620 post.author_link = Feed.vk.base + user_json.response[0].screen_name; 621 post.link = Feed.vk.base + user_json.response[0].screen_name + '?w=wall' + element.from_id + '_' + element.i
621d; 622 623 return post; 624 }, 625 getGroup: function(user_json, post, element, json) { 626 post.author_name = user_json.response[0].name; 627 post.author_picture = user_json.response[0].photo; 628 post.author_link = Feed.vk.base + user_json.response[0].screen_name; 629 post.link = Feed.vk.base + user_json.response[0].screen_name + '?w=wall-' + user_json.response[0].gid + '_' + element.id; 630 631 return post; 632 } 633 } 634 }, 635 blogspot: { 636 loaded: false, 637 getData: function(account) { 638 var url; 639 640 switch (account[0]) { 641 case '@': 642 var username = account.substr(1); 643 url = 'http://' + username + '.blogspot.com/feeds/posts/default?alt=json-in-script&callback=?'; 644 request(url, getPosts); 645 break; 646 default: 647 } 648 }, 649 utility: { 650 getPosts: function(json) { 651 $.each(json.feed.entry, function() { 652 var post = {}, 653 element = this; 654 post.id = element.id['$t'].replace(/[^a-z0-9]/gi, ''); 655 post.dt_create = moment((element.published['$t'])); 656 post.author_link = element.author[0]['uri']['$t']; 657 post.author_picture = 'http:' + element.author[0]['gd$image']['src']; 658 post.author_name = element.author[0]['name']['$t']; 659 post.message = element.title['$t'] + '</br></br>' + stripHTML(element.content['$t']); 660 post.description = ''; 661 post.link = element.link.pop().href; 662 663 if (options.show_media) { 664 if (element['media$thumbnail']) { 665 post.attachment = '<img class="attachment" src="' + element['media$thumbnail']['url'] + '" />'; 666 } 667 } 668 669 post.render(); 670 671 }); 672 } 673 } 674 }, 675 pinterest: { 676 posts: [], 677 loaded: false, 678 apiv1: 'https://api.pinterest.com/v1/', 679 680 getData: function(account) { 681 var request_url, 682 limit = 'limit=' + options.pinterest.limit, 683 fields = 'fields=id,created_at,link,note,creator(url,first_name,last_name,image),image', 684 query_extention = fields + '&access_token='
684+ options.pinterest.access_token + '&' + limit + '&callback=?'; 685 switch (account[0]) { 686 case '@': 687 var username = account.substr(1); 688 if (username === 'me') { 689 request_url = Feed.pinterest.apiv1 + 'me/pins/?' + query_extention; 690 } else { 691 request_url = Feed.pinterest.apiv1 + 'boards/' + username + '/pins?' + query_extention; 692 } 693 break; 694 default: 695 } 696 Utility.request(request_url, Feed.pinterest.utility.getPosts); 697 }, 698 utility: { 699 700 getPosts: function(json) { 701 json.data.forEach(function(element) { 702 var post = new SocialFeedPost('pinterest', Feed.pinterest.utility.unifyPostData(element)); 703 post.render(); 704 }); 705 }, 706 707 unifyPostData: function(element){ 708 var post = {}; 709 710 post.id = element.id; 711 post.dt_create= moment(element.created_at); 712 post.author_link = element.creator.url; 713 post.author_picture = element.creator.image['60x60' ].url; 714 post.author_name = element.creator.first_name + element.creator.last_name; 715 post.message = element.note; 716 post.description = ''; 717 post.social_network = 'pinterest'; 718 post.link = element.link ? element.link : 'https://www.pinterest.com/pin/' + element.id; 719 if (options.show_media) { 720 post.attachment = '<img class="attachment" src="' + element.image['original'].url + '" />'; 721 } 722 return post; 723 } 724 } 725 }, 726 rss : { 727 posts: [], 728 loaded: false, 729 api : 'https://query.yahooapis.com/v1/public/yql?q=', 730 datatype: 'json', 731 732 getData: function(url) { 733 var limit = options.rss.limit, 734 yql = encodeURIComponent('select entry FROM feednormalizer where url=\'' + url + '\' AND output=\'atom_1.0\' | truncate(count=' + limit + ')' ), 735 request_url = Feed.rss.api + yql + '&format=json&callback=?'; 736 737 Utility.request(request_url, Feed.rss.utility.getPosts, Feed.rss.datatype); 738 }, 739 utility: { 740 741 getPosts: function(json) { 742 console.log(json); 743 if (json.query.count > 0 ){ 744 $.each(json.query.results.feed, function(index, element) { 745 var post = new SocialFeedPost('rss', Feed.rss.utility.unifyPostData(index, element)); 746 post.render(); 747 }); 748 } 749 }, 750 751 unifyPostData: function(index, element){ 752 753 var item = element; 754 755 if ( element.entry !== undefined ){ 756 item = element.entry; 757 } 758 var post = {}; 759 760 post.id = '"' + item.id + '"'; 761 post.dt_create= moment(item.published, 'YYYY-MM-DDTHH:mm:ssZ', 'en'); 762 763 post.author_link = ''; 764 post.author_picture = ''; 765 post.author_name = ''; 766 if( item.creator !== undefined ){ 767 post.author_name = item.creator; 768 } 769 post.message = item.title; 770 post.description = ''; 771 if( item.summary !== undefined ){ 772 post.description = Utility.stripHTML(item.summary.content); 773 } 774 post.social_network = 'rss'; 775 post.link = item.link.href; 776 if (options.show_media && item.thumbnail !== undefined ) { 777 post.attachment = '<img class="attachment" src="' + item.thumbnail.url + '" />'; 778 } 779 return post; 780 } 781 } 782 } 783 }; 784 785 //make the plugin chainable 786 return this.each(function() { 787 // Initialization 788 Feed.init(); 789 if (options.update_period) { 790 setInterval(function() { 791 return Feed.init(); 792 }, options.update_period); 793 } 794 }) 795 }; 796 797})(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.