home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / plugins / facebook / res / infobox.js < prev    next >
Encoding:
JavaScript  |  2010-06-22  |  30.6 KB  |  832 lines

  1. var TODAY_TEXT = "";
  2.  
  3. var ACTIVE_FILTERS = [];
  4.  
  5. function fb_comments_updater(self, slide, clear_error) {
  6.     return function(args) {
  7.         var comments_html = $($(args.comments_html)[0]);
  8.         var comment_link_html = $($(args.comment_link_html)[0]);
  9.         var comments = $(comments_html[0]).find(".comment");
  10.         var count = args.count;
  11.  
  12.         var new_comment;
  13.  
  14.         if ((comments.length) && (slide == "new")) {
  15.             new_comment = $(comments[comments.length-1]);
  16.             new_comment.hide();
  17.         } else {
  18.             new_comment = null;
  19.         }
  20.         comment_link_html.hide();
  21.         //comments_html.hide();
  22.         comments_html.find(".time").each(do_convert_time);
  23.         fb_init_comment_a(comments_html);
  24.         $(self).parents('.messagecell').find('.comments').replaceWith(comments_html);
  25.         //only want the "Comment ()" chunk, not the "()" after likes -----v
  26.         $($(self).parents(".messagecell").find('.comment_button_section')[0]).replaceWith(comment_link_html);
  27.         comment_box = $($(self).parents(".form_wrapper")[0]).find("textarea[name='foo']");
  28.  
  29.         if (slide == "new") {
  30.             slide_element = new_comment;
  31.         } else if (slide == "all") {
  32.             slide_element = comments_html;
  33.         }
  34.  
  35.         if (clear_error) {
  36.             fb_clear_error(function(){
  37.                 slide_element.slideDown(transitionDefault, function(){
  38.                     $($(self).parents(".form_wrapper")[0]).find('.loader_img').remove();
  39.                     comment_box[0].value = '';
  40.                     comment_box[0].disabled = false;
  41.                     comment_box.jGrow();
  42.                 });
  43.             });
  44.         } else {
  45.             //slide_element.slideDown(transitionDefault);
  46.         }
  47.         comment_box.focus();
  48.     };
  49. }
  50.  
  51. var show_comment_box = function(self){
  52.     var me = $(self);
  53.     me.parents(".messagecell").find('.comment_button_section').hide(); // placeholder
  54.     me.parents(".messagecell").find('.likes_comments_section').css('-webkit-user-select','none');
  55.  
  56.     var end = me.parents(".messagecell").find(".comments_end");
  57.     var txt;
  58.     if (end.text() =="placeholder"){
  59.         end.html('<div class="form_wrapper"><textarea name="foo" rows="1" class="input_area expanding minor_border"/></div>');
  60.         txt = end.find('textarea');
  61.  
  62.         var haveFocus = false;
  63.  
  64.         var blurFunc = function(animate) {
  65.             if (!haveFocus) {
  66.                 return true;
  67.             }
  68. //            if ($(txt).parents(".post_row").hasClass('mouseover')){
  69. //                return true;
  70. //            }
  71.             $(txt).unbind('keydown', 'esc');
  72.             $(txt).unbind('keydown', 'shift+return');
  73.             $(txt).unbind('keydown', 'return');
  74.             hide_this_comment_box(txt, animate);
  75.             haveFocus = false;
  76.             return true; //blur should continue, so that we don't keep focus and possibly trigger another blur event.
  77.         }
  78.  
  79.         $(txt.parents('.form_wrapper')[0]).css('padding-right', commentFieldPadding);
  80.  
  81.         txt.focus( function() {
  82.             if (haveFocus) {
  83.                 return;
  84.             }
  85.             haveFocus = true;
  86.             $(this).bind('keydown', 'esc', function(){ txt.blur(); });
  87.             $(this).bind('keydown', 'shift+return', function(){
  88.                 var start = this.selectionStart;
  89.                 var end   = this.selectionEnd;
  90.                 this.value = this.value.substr(0, start)
  91.                     + '\n'
  92.                     + this.value.substr(end, this.value.length);
  93.                 this.selectionStart = start + 1;
  94.                 this.selectionEnd = start + 1;
  95.                 return false;
  96.             });
  97.             $(this).bind('keydown', 'return', function(){
  98.                 if (this.value && !this.disabled) {
  99.                     post_comment(this);
  100.                 } else {
  101.                     //hide_this_comment_box();
  102.                 }
  103.                 return false;
  104.             });
  105.             haveFocus = true;
  106.             // When hiding the infobox, blur any active textboxes.
  107.             //TODO: fix/create the necessary functions so that things that don't need to happen don't
  108.             swapOut(function() { blurFunc(false); });
  109.             onHide(function() { blurFunc(false); });
  110.         });
  111.  
  112.         txt.blur(blurFunc);
  113.     }
  114.     txt = end.find('textarea');
  115. //    txt.parents('.messagecell').find('.comment_block, .likes').show();
  116.     txt.parents('.messagecell').find('.likes_comments_section').slideDown(transitionDefault/2, function(){
  117.         end.slideDown(transitionDefault/2, function(){
  118.             txt.jGrow();
  119.             txt.focus();
  120.             //me.parents('.messagecell').find('.likes_comments_section').show();
  121.             me.parents(".messagecell").find('.likes_comments_section').css('-webkit-user-select','text');
  122.         });
  123.     });
  124.  
  125.     if (me.parents(".messagecell").find('.comments').hasClass('have_comments') ) {
  126.         //return false;
  127.     }
  128.     comment_textfield = txt[0];
  129.     comment_textfield.disabled = true;
  130.     $(txt.parents(".form_wrapper")[0]).append(loader_img);
  131.  
  132.     var post_id = $($(self).parents(".post_row")[0]).attr('id');
  133.     D.rpc("get_comments",
  134.           {'post_id':post_id},
  135.           function (args) {
  136.             fb_comments_updater(self, "all")(args);
  137.             txt[0].disabled = false;
  138.             $($(self).parents(".form_wrapper")[0]).find('.loader_img').remove();
  139.             txt.focus();
  140.           },
  141.           function(error_obj){
  142.                 if (error_obj.error_msg == "no_change") {
  143.                   txt[0].disabled = false;
  144.                   $($(self).parents(".form_wrapper")[0]).find('.loader_img').remove();
  145.                   txt.focus();
  146.                   return;
  147.                 }
  148.                 error_text(comment_textfield, 'Error retrieving comments.', error_obj, function(){
  149.                     $($(self).parents(".form_wrapper")[0]).find('.loader_img').remove();
  150.                     txt[0].disabled = true;
  151.                     //me.parents(".activity-data").find('.comment_button_section').show();
  152.                     txt.slideUp();
  153.                 });
  154.             }
  155.         );
  156.     return false;
  157. }
  158.  
  159. var fb_comment_button_mousedown = function() {
  160. //    get_comments(this);
  161.     show_comment_box(this);
  162.     return true;
  163. }
  164.  
  165. var get_comments = function(self) {
  166.     var post_id = $($(self).parents(".post_row")[0]).attr('id');
  167.     $(self).parents('.messagecell').find('.comments').html('<span></span>');
  168.     D.rpc('get_comments', {'post_id':post_id},
  169.             function(args){
  170.                 var comments_html = args.comments_html;
  171.                 var comment_link_html = args.comment_link_html;
  172.                 var foo = $(comments_html);
  173.                 var bar = $(comment_link_html);
  174.                 foo.hide();
  175.                 foo.find(".time").each(do_convert_time);
  176.                 fb_init_comment_a(foo);
  177.                 $(self).parents('.messagecell').find('.comments').replaceWith(foo);
  178.                 //only want the "Comment ()" chunk, not the "()" after likes -----v
  179.                 var oldbar = $($(self).parents(".messagecell").find('.comment_button_section')[0]);
  180.                 if (oldbar.css('display') === 'none') {
  181.                     bar.hide();
  182.                 }
  183.                 oldbar.replaceWith(bar);
  184.                 foo.slideDown(transitionDefault);
  185.             },
  186.             function(error_obj){
  187.                 error_text($(self), 'Error retrieving comments.', error_obj, function(){
  188.                     $(self).parents('.messagecell').find('.comments').find('.loader_img').remove();
  189.                 });
  190.             }
  191.         );
  192. }
  193.  
  194. var post_comment = function (self){
  195.     self.disabled = true;
  196.     var comment_box = $(self);
  197.     var comment = $(self).attr('value');
  198.     var post_id = $($(self).parents(".post_row")[0]).attr('id');
  199.     $($(self).parents(".form_wrapper")[0]).append(loader_img);
  200.     D.rpc('post_comment', {'comment':comment, 'post_id':post_id},
  201.             function(args){
  202.                 var comment_html = args.comment_html;
  203.                 var comment_link_html = args.comment_link_html;
  204.                 var comment_post_link = args.comment_post_link;
  205.                 var foo = $(comment_html);
  206.                 var bar = $(comment_link_html);
  207.                 foo.hide();
  208.                 bar.hide();
  209.                 foo.find(".time").each(do_convert_time);
  210.                 fb_init_comment_a(foo);
  211.                 $(self).parents('.messagecell').find('.comments').append(foo);
  212.                 if ($(self).parents('.messagecell').find('.comment_post_link').length){
  213.                     $(self).parents('.messagecell').find('.comment_post_link').replaceWith(comment_post_link);
  214.                 } else {
  215.                     $(self).parents('.messagecell').find('.comments').after(comment_post_link);
  216.                 }
  217.                 //only want the "Comment ()" chunk, not the "()" after likes -----v
  218.                 $($(self).parents(".messagecell").find('.comment_button_section')[0]).replaceWith(bar);
  219.                 fb_clear_error(comment_box, function(){
  220.                     foo.slideDown(transitionDefault, function(){
  221.                         $($(self).parents(".form_wrapper")[0]).find('.loader_img').remove();
  222.                         comment_box[0].value = '';
  223.                         comment_box[0].disabled = false;
  224.                         comment_box.jGrow();
  225.                         comment_box.focus();
  226.                     });
  227.                 });
  228.             },
  229.             function(error_obj){
  230.                 error_text(comment_box, 'Error posting comment.', error_obj, function(){
  231.                     $($(self).parents(".form_wrapper")[0]).find('.loader_img').remove();
  232.                     comment_box[0].disabled = false;
  233.                     comment_box.focus();
  234.                 });
  235.             }
  236.         );
  237.     return false;
  238. }
  239.  
  240. function fb_liked(args) {
  241.     var me = args.me;
  242.     var likes_html = args.likes_html;
  243.     var link_html = args.link_html;
  244.     fb_clear_error(me, function(){
  245.         me.parents('.messagecell').find('.likes').replaceWith(likes_html);
  246.         me.parents('.messagecell').find('.like_link_block').replaceWith(link_html);
  247.     });
  248. }
  249.  
  250. function fb_disliked(args) {
  251.     var me = args.me;
  252.     var likes_html = args.likes_html;
  253.     var link_html = args.link_html;
  254.     fb_clear_error(me, function(){
  255.         me.parents('.messagecell').find('.dislikes').replaceWith(likes_html);
  256.         me.parents('.messagecell').find('.dislike_link_block').replaceWith(link_html);
  257.     });
  258. }
  259.  
  260. function fb_like_button_mousedown(){
  261.     me = $(this);
  262.     me.parents('.messagecell').find('.like_button_section, .num_likes').hide();
  263.     var post_id = $($(this).parents(".post_row")[0]).attr('id');
  264.     D.rpc('do_like', {'post_id':post_id},
  265.         function(args) {
  266.             args.me = me;
  267.             return fb_liked(args);
  268.         },
  269.         function(error_obj){
  270.             var msg = 'Error adding like.';
  271.             error_text(me, msg, error_obj, function(){
  272.                 me.parents('.messagecell').find('.like_button_section, .num_likes').show();
  273.             });
  274.         }
  275.     );
  276.     return false;
  277. }
  278.  
  279. function fb_unlike_button_mousedown(){
  280.     me = $(this);
  281.     me.parents('.messagecell').find('.like_button_section, .num_likes').hide();
  282.     var post_id = $($(this).parents(".post_row")[0]).attr('id');
  283.     D.rpc('do_unlike', {'post_id':post_id},
  284.         function(args) {
  285.             args.me = me;
  286.             return fb_liked(args);
  287.         },
  288.         function(error_obj){
  289.             error_text(me, 'Error removing like.', error_obj, function(){
  290.                 me.parents('.messagecell').find('.like_button_section, .num_likes').show();
  291.             });
  292.         }
  293.     );
  294.     return false;
  295. }
  296.  
  297. function fb_dislike_button_mousedown(){
  298.     me = $(this);
  299.     me.parents('.messagecell').find('.dislike_button_section, .num_dislikes').hide();
  300.     var post_id = $($(this).parents(".post_row")[0]).attr('id');
  301.     D.rpc('do_dislike', {'post_id':post_id},
  302.         function(args) {
  303.             args.me = me;
  304.             return fb_disliked(args);
  305.         },
  306.         function(error_obj){
  307.             var msg = 'Error adding dislike.';
  308.             error_text(me, msg, error_obj, function(){
  309.                 me.parents('.messagecell').find('.dislike_button_section, .num_dislikes').show();
  310.             });
  311.         }
  312.     );
  313.     return false;
  314. }
  315.  
  316. function fb_undislike_button_mousedown(){
  317.     me = $(this);
  318.     me.parents('.messagecell').find('.dislike_button_section, .num_dislikes').hide();
  319.     var post_id = $($(this).parents(".post_row")[0]).attr('id');
  320.     D.rpc('do_undislike', {'post_id':post_id},
  321.         function(args) {
  322.             args.me = me;
  323.             return fb_disliked(args);
  324.         },
  325.         function(error_obj){
  326.             var msg = 'Error removing dislike.';
  327.             error_text(me, msg, error_obj, function(){
  328.                 me.parents('.messagecell').find('.dislike_button_section, .num_dislikes').show();
  329.             });
  330.         }
  331.     );
  332.     return false;
  333. }
  334.  
  335. function fb_del_comment_link_mousedown(){
  336.     me = $(this);
  337.     $(me.parents('.del_comment')[0]).hide();
  338.     var comment_id = $($(this).parents(".comment")[0]).attr('id').substring("comment_".length);
  339.     D.rpc('remove_comment', {'comment_id':comment_id},
  340.             function(args){
  341.                 var comment_link_html = args.comment_link_html;
  342.                 var comment_post_link = args.comment_post_link;
  343.                 var current_comment_link = $(me.parents(".messagecell").find('.comment_button_section')[0]);
  344.                 var current_comment_post_link =
  345.                 fb_clear_error(me, function(){
  346.                     remove_comment(comment_id);
  347.                     current_comment_link.replaceWith(comment_link_html);
  348.                     me.parents(".messagecell").find('.comment_post_link').replaceWith(args.comment_post_link);
  349.                 });
  350.             },
  351.             function(error_obj){
  352.                 error_text(me, 'Error deleting comment.', error_obj, function(){
  353.                     $(me.parents('.del_comment')[0]).show();
  354.                 });
  355.             });
  356.     return false;
  357. }
  358.  
  359. //timestamps
  360. function fb_init_time(tree){
  361.     tree.find(".time").each(do_convert_time);
  362. }
  363.  
  364. // end timestamps
  365.  
  366. function fb_init_pix(tree){
  367.     var pix = tree.find(".picturelink");
  368.     pix.hide();
  369.     pix.css({'max-width':'100%'});
  370. }
  371. // end image sizing
  372.  
  373. function infoboxIsShowing() {
  374.     if (onInfoboxShow) {
  375.         onInfoboxShow();
  376.         onInfoboxShow = undefined;
  377.     };
  378. }
  379.  
  380. var LIGHTBOX_OPTIONS = {
  381.     changeCounterAfterSlide: false,
  382.     wrapNav: true,
  383.     imageDir: LIGHTBOX_IMAGE_DIR,
  384.     dataBoxFirst: true,
  385.     containerBorderSize: 0,
  386.     fixedDataBox: true,
  387.     clickLoadingClose: false,
  388.     clickBoxClose: false,
  389.     txtImage: "",
  390.     txtOf: "/",
  391.     //imageContext: 'popout.gif',
  392.     showContext: true,
  393.     forceTitleBar: true,
  394.     onShowFunction: function(){ D.notify('hook', 'digsby.facebook.photo_seen') },
  395. }
  396.  
  397. jQuery.fn.sort = function() {
  398.     return this.pushStack( [].sort.apply( this, arguments ), []);
  399. };
  400.  
  401. function fb_init_picturelink(tree){
  402.     tree.find(".media_row").each(function() {
  403.         var photos = $($(this).find(".photolinklink").sort(function (a,b){ return parseInt($(a).attr('index'), 10) > parseInt($(b).attr('index'), 10) ? 1 : -1; }));
  404.         var lightboxParent = $(this).find('.media_cell');
  405.         var array_updated = false;
  406.         var lightBoxHooks = photos.lightBox(jQuery.extend({},
  407.                                       LIGHTBOX_OPTIONS,
  408.                                       {parentSelector: lightboxParent,
  409.                                        onInitFunction: function(){
  410.                                                         if (array_updated){
  411.                                                             return;
  412.                                                         }
  413.                                                         D.rpc('get_album',
  414.                                                               {'aid':$(photos[0]).attr('aid')},
  415.                                                               function (args) {
  416.                                                                   var newdata = args.album;
  417.                                                                   var newArray = [];
  418.                                                                   for (var i = 0; i < newdata.length; i++){
  419.                                                                       var obj = newdata[i];
  420.                                                                       newArray.push(new Array(obj['src_big'], //href
  421.                                                                                               obj['caption'], //title
  422.                                                                                               obj['link'], //context
  423.                                                                                               $(photos[0]).offset(), //?
  424.                                                                                               '', //?
  425.                                                                                               obj['pid'] // image id
  426.                                                                                               )
  427.                                                                                     );
  428.                                                                   }
  429.                                                                   array_updated = true;
  430.                                                                   lightBoxHooks.updateImageArray(newArray);
  431.                                                               }
  432.                                                         )
  433.                                                         },
  434.                                        lengthTextFunction: function(arrayLen){
  435.                                             if (!array_updated){
  436.                                                 return '?';
  437.                                             } else {
  438.                                                 return arrayLen;
  439.                                             }
  440.                                        },
  441.                                        realIndexFunction: function (arrayIdx) {
  442.                                            if (!array_updated){
  443.                                                return parseInt($(photos[arrayIdx]).attr('index'), 10);
  444.                                            } else {
  445.                                                return arrayIdx;
  446.                                            }
  447.                                        },
  448.                                        imgIdFunction: function (obj) { return obj.getAttribute('pid'); },
  449.                                       }));
  450.     });
  451.     var picturelink = tree.find(".picturelink");
  452.     picturelink.bind("load", size_images);
  453. //    picturelink.fullsize({'forceTitleBar':true, 'shadow':false});
  454. }
  455.  
  456. function fb_uninit_picturelink(tree){
  457.     var picturelink = tree.find(".picturelink");
  458.     picturelink.unbind("load", size_images);
  459. //    picturelink.fullsize({'forceTitleBar':true, 'shadow':false});
  460. }
  461.  
  462. // our webkit does not support _blank links, so remove all "target" attributes
  463. // from <a> tags (target="_blank" comes in with some types of posts)
  464. function fb_init_a(tree) {
  465.     tree.find('a').removeAttr('target');
  466. }
  467.  
  468. function fb_init_comment_a(selector){
  469.     selector.find('a').addClass('no_ondown_link');
  470. }
  471.  
  472. function fb_initialize(tree){
  473.     if (!tree){
  474.         tree = $();
  475.     };
  476.     fb_init_time(tree);
  477.     fb_init_pix(tree);
  478.     fb_init_picturelink(tree);
  479.     fb_init_a(tree);
  480.     fb_init_comment_a(tree.find('.comment_block'));
  481.     return tree;
  482. }
  483.  
  484. function fb_initialize_swapin(tree){
  485.     if (!tree){
  486.         tree = $();
  487.     };
  488.     fb_init_picturelink(tree);
  489.     return tree;
  490. }
  491.  
  492. function fb_uninitialize(tree){
  493.     if (!tree){
  494.         tree = $();
  495.     };
  496. //    fb_uninit_time(tree);
  497. //    fb_uninit_pix(tree);
  498.     fb_uninit_picturelink(tree);
  499. //    fb_uninit_a(tree);
  500.     return tree;
  501. }
  502.  
  503. function fb_uninitialize_swapout(tree){
  504.     return fb_uninitialize(tree);
  505. }
  506.  
  507. var inited = false;
  508.  
  509. var scrollRequestOutstanding = false;
  510.  
  511. var myName = currentContentName;
  512.  
  513. var fb_on_scroll = function(post_table) {
  514. //    console.log('fb_on_scroll 1');
  515.     if (!inited || myName !== currentContentName){
  516.         console.log('fb_on_scroll ' + myName + ' shortcircut1: ' + currentContentName);
  517.         return;
  518.     }
  519.     if (scrollRequestOutstanding){
  520.         return;
  521.     }
  522.     scrollRequestOutstanding = true;
  523. //    console.log('fb_on_scroll 2');
  524.     if (fb_Active && fb_near_bottom()){
  525. //        console.log('post_table: ' + post_table);
  526.         var rows = $(post_table).find('.post_row');
  527.         var last_post_id = $(rows[rows.length-1]).attr('id');
  528.         D.rpc('next_item', {},
  529.               function(args){
  530.                   if (!scrollRequestOutstanding) {
  531.                       return;
  532.                   }
  533.                   if (!inited || myName !== currentContentName) {
  534.                       console.log('fb_on_scroll ' + myName + ' shortcircut2: ' + currentContentName);
  535.                       scrollRequestOutstanding = false;
  536.                       return;
  537.                   }
  538.  
  539.                   var dateparent = $('<div></div>');
  540.                   dateparent.append(args.html);
  541.                   var rows2 = dateparent.find('.post_row');
  542.  
  543.                   if (ACTIVE_FILTERS.length) {
  544.                       rows2.each(function() {
  545.                           if (filtered($(this))) {
  546.                               $(this).hide();
  547.                           }
  548.                       });
  549.                   }
  550.  
  551.                   fb_maybe_add_date_separators(rows, rows2);
  552.                   html = dateparent.contents().remove();
  553.                   html.remove();
  554.                   dateparent.remove();
  555.                   fb_initialize(html);
  556.                   html.appendTo($(post_table));
  557.                   scrollRequestOutstanding = false;
  558.                   fb_on_scroll(post_table);
  559.               },
  560.               function(args) {
  561.                   scrollRequestOutstanding = false;
  562.               }
  563.         );
  564.     } else {
  565.         //console.log('fb_on_scroll end: ' + currentContentName);
  566.         scrollRequestOutstanding = false;
  567.     };
  568. //    console.log('fb_on_scroll 3');
  569.  
  570. };
  571.  
  572. function apply_filters(filters){
  573.     ACTIVE_FILTERS = filters;
  574.     $('.post_row').each(function(){
  575.           if (filtered($(this))) {
  576.               $(this).hide();
  577.           } else {
  578.               $(this).show();
  579.           }
  580.     });
  581.     clear_previous_date_separators($());
  582.     fb_maybe_add_date_separators([], $('.post_row'));
  583.     fb_do_scroll();
  584. }
  585.  
  586. function filtered(row){
  587.     if (!ACTIVE_FILTERS.length) {
  588.         return false;
  589.     }
  590.     for (var i = 0; i < ACTIVE_FILTERS.length; i++) {
  591.         if (row.hasClass('fb_filter_' + ACTIVE_FILTERS[i])) {
  592.             return false;
  593.         }
  594.     }
  595.     return true;
  596. }
  597.  
  598.  
  599. function _insert_separator(el, the_date, today_text, today, do_count, initial) {
  600.     do_count = do_count || (do_count === null) || (do_count === undefined);
  601.  
  602.     var date_sep = document.createElement("span");
  603.     $(date_sep).addClass("date-separator");
  604.     $(date_sep).addClass("title");
  605.  
  606.     the_date = dayOfDate(the_date);
  607.     if (today === null || today === undefined) {
  608.         today = get_today();
  609.     }
  610.     var text = null;
  611.     var is_today = the_date.valueOf() == today.valueOf();
  612.  
  613.     if (is_today) {
  614.         $(date_sep).addClass("today");
  615.     }
  616.  
  617.     if (initial && is_today) {
  618.         test = null;
  619.     } else if (!initial && is_today) {
  620.         text = "Today";
  621.     } else if (_isSameMonth(the_date, today) || _isLastMonth(the_date, today)) {
  622.         if ((today.valueOf() - the_date.valueOf()) <= (1000 * 60 * 60 * 24)) {
  623.             text = "Yesterday";
  624.         } else {
  625.             text = the_date.format("mmmm d");
  626.         }
  627.     } else {
  628.        text = the_date.format("mmmm");
  629.     }
  630.  
  631.    if (do_count){
  632.        separator_count++;
  633.    }
  634.    if (!text) { return };
  635.    $(date_sep).text(text);
  636.  
  637.    $(date_sep).insertBefore($(el));
  638. }
  639.  
  640. function fb_maybe_add_date_separators(rows1, rows2, today) {
  641.     if (today === null || today === undefined) {
  642.         today = get_today();
  643.     }
  644.     var current_time_period = null;
  645.     if (rows1.length > 0) {
  646.         for (var j = rows1.length-1; j >= 0; j--) {
  647.             if (filtered($(rows1[j]))) {
  648.                 continue;
  649.             } else {
  650.                 current_time_period = relevant_time_diff(_get_timestamp(rows1[j]), today);
  651.                 break;
  652.             }
  653.         }
  654.     }
  655.  
  656.     for (var i = 0; i < rows2.length; i++) {
  657.         if (ACTIVE_FILTERS.length && filtered($(rows2[i]))) {
  658.             continue;
  659.         }
  660.         var time_period = relevant_time_diff(_get_timestamp(rows2[i]), today);
  661.         if ((!current_time_period) ||
  662.             (time_period.valueOf() != current_time_period.valueOf())) {
  663.              first_event_of_time_period = rows2[i];
  664.              _insert_separator(rows2[i], time_period, TODAY_TEXT, today, false, (!current_time_period));
  665.              current_time_period = time_period;
  666.         }
  667.     }
  668. }
  669.  
  670. var fb_Active = false;
  671.  
  672. swapOut(function(){
  673.     fb_Active = false;
  674. });
  675.  
  676. swapIn(fb_initialize_swapin);
  677. swapOut(fb_uninitialize_swapout);
  678.  
  679. function do_grant(){
  680.     D.notify('do_grant');
  681. }
  682.  
  683. function edit_status(){
  684.     D.notify('edit_status');
  685. }
  686.  
  687. function fb_false(){
  688.     //need a way to fire link clicked event on mousedown.
  689. //    D.rpc('link', {'href':$(this).attr('href')});
  690.     return false;
  691. }
  692.  
  693.  
  694. swapIn(function(){
  695.     //console.log('in 1');
  696.     $(".comment_button").live("mousedown", fb_comment_button_mousedown);
  697.     //console.log('in 2');
  698.     $(".like_button").live("mousedown", fb_false);
  699.     $(".like_button").live("click", fb_like_button_mousedown);
  700.     $(".dislike_button").live("mousedown", fb_false);
  701.     $(".dislike_button").live("click", fb_dislike_button_mousedown);
  702.     //console.log('in 3');
  703.     $(".del_comment_link").live("mousedown", fb_false);
  704.     $(".del_comment_link").live("click", fb_del_comment_link_mousedown);
  705.     //console.log('in 4');
  706.     $(".unlike_button").live("mousedown", fb_false);
  707.     $(".unlike_button").live("click", fb_unlike_button_mousedown);
  708.     $(".undislike_button").live("mousedown", fb_false);
  709.     $(".undislike_button").live("click", fb_undislike_button_mousedown);
  710.  
  711.     $(".no_ondown_link").live("mousedown", fb_false);
  712.     //console.log('in 5');
  713. //    $(".buddyicon").live("click", fb_buddyicon_click);
  714.     $(".do_grant").live("mousedown", fb_false);
  715.     $(".do_grant").live("click", do_grant);
  716.     //console.log('in 6');
  717.     $(".edit_status").live("click", edit_status);
  718.     //console.log('in 7');
  719.     $("body").live("click", kill_filter_menu);
  720.     kill_filter_menu();
  721. });
  722.  
  723. swapOut(function(){
  724.     //console.log('out 1');
  725.     $(".comment_button").die("mousedown", fb_comment_button_mousedown);
  726.     //console.log('out 2');
  727.     $(".like_button").die("mousedown", fb_false);
  728.     $(".like_button").die("click", fb_like_button_mousedown);
  729.     $(".dislike_button").die("mousedown", fb_false);
  730.     $(".dislike_button").die("click", fb_dislike_button_mousedown);
  731.     //console.log('out 3');
  732.     $(".del_comment_link").die("mousedown", fb_false);
  733.     $(".del_comment_link").die("click", fb_del_comment_link_mousedown);
  734.     //console.log('out 4');
  735.     $(".unlike_button").die("mousedown", fb_false);
  736.     $(".unlike_button").die("click", fb_unlike_button_mousedown);
  737.     $(".undislike_button").die("mousedown", fb_false);
  738.     $(".undislike_button").die("click", fb_undislike_button_mousedown);
  739.  
  740.     $(".no_ondown_link").die("mousedown", fb_false);
  741.     //console.log('out 5');
  742. //    $(".buddyicon").die("click", fb_buddyicon_click);
  743.     $(".do_grant").die("mousedown", fb_false);
  744.     $(".do_grant").die("click", do_grant);
  745.     //console.log('out 6');
  746.     $(".edit_status").die("click", edit_status);
  747.     //console.log('out 7');
  748.     $("body").die("click", kill_filter_menu);
  749. });
  750.  
  751. swapIn(function(){
  752.     fb_Active = true;
  753.     if (!inited){
  754.         fb_initialize();
  755.         do_bind();
  756.         inited=true;
  757.     };
  758. });
  759.  
  760.  
  761. function kill_filter_menu(){
  762.     fkeys = $('.filter_keys');
  763.     if (fkeys.hasClass('filter_keys_expanded')) {
  764.         fkeys.removeClass('filter_keys_expanded');
  765.         fkeys.find('.filter_key').not('.active_filter_key').hide();
  766.     }
  767. }
  768.  
  769. function do_bind(tree){
  770.     if (!tree){
  771.         tree = $();
  772.     };
  773.     tree.find('.filter_key').css('cursor', 'pointer');
  774.     tree.find('.filter_key').click(
  775.     function () {
  776.         if ($(this).parents('.filter_keys').hasClass('filter_keys_expanded')) {
  777.             $(this).parents('.filter_keys').find('.filter_key').removeClass('active_filter_key').removeClass('title').addClass('major');
  778.             $(this).addClass('active_filter_key').addClass('title').removeClass('major');
  779.             $(this).parents('.filter_keys').removeClass('filter_keys_expanded');
  780.             $(this).parents('.filter_keys').find('.filter_key').not('.active_filter_key').slideUp(100);
  781.             var filter_key_val = $(this).find('.filter_key_val');
  782.             if (filter_key_val.size() > 0) {
  783.                 apply_filters([filter_key_val.text()]);
  784.             } else {
  785.                 apply_filters([]);
  786.             }
  787.         } else {
  788.             $(this).parents('.filter_keys').addClass('filter_keys_expanded');
  789.             $(this).parents('.filter_keys').find('.filter_key').slideDown(100);
  790.         }
  791.         return false;
  792.     });
  793.     //tree.find('.filter_key a').click(function (){$(this).parent().click(); return false;});
  794. }
  795.  
  796. var post_table = null;
  797.  
  798. D.notify('initialize_feed'); //before binding the scroll events, though those really happen later.
  799.  
  800. function fb_do_scroll(){
  801.     fb_on_scroll(post_table)
  802. }
  803.  
  804. swapIn(function(){
  805.     console.log('swapin: '+ currentContentName);
  806.     post_table = $(document).find('.post_table')[0];
  807.     console.log('swapin2: '+ currentContentName);
  808.     setDesiredHeightCallback(fb_do_scroll);
  809.     console.log('swapin3: '+ currentContentName);
  810.     $(window).bind('scroll',fb_do_scroll);
  811.     console.log('swapin4: '+ currentContentName);
  812.     fb_do_scroll();
  813.     setTimeout(fb_do_scroll, 500);
  814. });
  815.  
  816. swapOut(function(){
  817.     console.log('swapout: '+ currentContentName);
  818.     $(window).unbind('scroll');
  819.     setDesiredHeightCallback(null);
  820. });
  821.  
  822. console.log('infobox.js: ' + currentContentName);
  823.  
  824. onHide(function () {
  825.     var lb = window._activeLightBox;
  826.     if (lb != null) {
  827.         console.log('LB.DESTROY');
  828.         lb.destroy();
  829.     }
  830.     kill_filter_menu();
  831. });
  832.