(function($, block) { // Entity formatters for use by tweet list var entity_formatters = { 'urls': function(e) { return '' + e.display_url + ''; }, 'user_mentions': function(e) { return '@'+e.screen_name+''; }, 'hashtags': function(e) { return '#' +e.text+''; }, 'default': function(e) { return '{ENTITY}'; } }; // processes entities for the given message and entity object var process_entities = function(message, entities) { // short-circuit failure mode if(typeof entities === 'undefined') { return message; } // build list of entities sorted on starting index var es = []; $.each(entities, function(t, ts) { $.each(ts, function(_, e) { e['type'] = t; es.push(e); }); }); es.sort(function(a,b) { return a['indices'][0] - b['indices'][0]; }); // process entities one-by-one in order of appearance var marker = 0; var result = ""; for(var i in es) { var e = es[i]; var start = e['indices'][0]; var stop = e['indices'][1]; //copy string content result += message.substring(marker, start); //process entity (through formatter or no-op function) var formatter = entity_formatters[e.type] || function(e) { return message.substring(start,stop) }; result += formatter(e); // update marker location marker = stop; } // append tail of message result += message.substring(marker, message.length); return result; } block.fn.tweets = function(config) { var options = $.extend({ memory: 100 }, config); <<<<<<< Updated upstream:template_static/lib/tweets.js // create the necessary HTML in the block container //this.$element.append('
' + text + '
'); $content.append($text); // Build outer structure of containing divs: $tweet.append($content); $item.append($tweet); // place new tweet in front of list ======= tweets = window.sessionStorage.getItem('tweets'); tweets = JSON.parse(tweets); tweets.push(tweet); if(tweets.length >= options.memory) { tweets.shift(); } window.sessionStorage.setItem('tweets', JSON.stringify(tweets)); var $item = tweetCell(tweet) >>>>>>> Stashed changes:dashboard_static/lib/tweets.js $list.prepend($item); // remove stale tweets if ($list.children().length > options.memory) { $list.children().last().remove(); } }); return this.$element; }; })(jQuery, block);