1 /*jslint 
  2 browser: true,
  3 nomen: false,
  4 debug: true,
  5 forin: true,
  6 undef: true,
  7 white: false,
  8 onevar: false 
  9  */
 10 var sc, jQuery;
 11  
 12 /**
 13  * View helper methods for Twitter apps
 14  *  
 15  */
 16 
 17 /**
 18  * This removes any extra items from a set of elements. Intended to be used for
 19  * limiting the size of timelines
 20  * 
 21  * This does NOT remove bound event listeners in order to increase speed. Be careful!
 22  * 
 23  * @param {string} item_selector a jquery-compatible selector to get items
 24  * @param {integer} max_items the max # of item we should have
 25  * @param {boolean} remove_from_top whether or not to remove extra items from the top. default is FALSE
 26  * @requires jQuery
 27  * @member sc.helpers 
 28  */
 29 sc.helpers.removeExtraElements = function(item_selector, max_items, remove_from_top) {
 30 
 31 	if (!remove_from_top) {
 32 		remove_from_top = false;
 33 	}
 34 
 35 	var jqitems = jQuery(item_selector);
 36 
 37 	var parent = jqitems.parent().get(0);
 38 
 39 	var diff = jqitems.length - max_items;
 40 	
 41 	sch.debug('removing extra elements from '+item_selector);
 42 	sch.debug('matching item count '+jqitems.length);
 43 	sch.debug('max_items: '+max_items);
 44 	sch.debug('diff: '+diff);
 45 	sch.debug('remove_from_top: '+remove_from_top);
 46 
 47 	if (diff > 0) {
 48 
 49 		if (!remove_from_top) {
 50 	        jqitems.slice(diff * -1).each( function() {
 51 				this.parentNode.removeChild( this );
 52 			} );
 53 		} else {
 54 	        jqitems.slice(diff).each( function() {
 55 				this.parentNode.removeChild( this );
 56 			} );
 57 		}
 58 	}
 59 };
 60 
 61 
 62 
 63 /**
 64  * This removes any duplicate items from a series of elements. Intended to be used for
 65  * limiting the sice of timelines
 66  * 
 67  * @param {string} item_selector a jquery-compatible selector to get items
 68  * @param {boolean} remove_from_top whether or not to remove extra items from the top. default is FALSE
 69  * @TODO
 70  * @member sc.helpers 
 71  */
 72 sc.helpers.removeDuplicateElements = function(item_selector, remove_from_top) {
 73 	sc.helpers.dump('removeDuplicateElements TODO');
 74 
 75 };
 76 
 77 
 78 
 79 /**
 80  * This updates relative times in elements. Each element has to have an attribute
 81  * that contains the created_at value provided by Twitter
 82  * 
 83  * @param {string} item_selector the jQuery selector for the elements which will contain the relative times
 84  * @param {string} time_attribute the attribute of the element that contains the created_at value
 85  * @requires jQuery
 86  * @member sc.helpers 
 87  */
 88 sc.helpers.updateRelativeTimes = function(item_selector, time_attribute) {
 89 	jQuery(item_selector).each(function(i) {
 90 		var time = jQuery(this).attr(time_attribute);
 91 		var relative_time = sc.helpers.getRelativeTime(time);
 92 		jQuery(this).html( relative_time );
 93 	});
 94 };
 95 
 96 
 97 /**
 98  * this marks all items in the selected set of elements as read. It does this by removing
 99  * the 'new' class
100  * 
101  * @param {string} item_selector
102  * @requires jQuery
103  * @member sc.helpers 
104  */
105 sc.helpers.markAllAsRead = function(item_selector) {
106 	jQuery(item_selector).removeClass('new');
107 };
108