home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / plugins / facebook / res / live_funcs.js < prev    next >
Encoding:
JavaScript  |  2010-06-21  |  7.2 KB  |  226 lines

  1. // timestamps
  2.  
  3. var transitionDefault = 200;
  4.  
  5. var fxAttrs = [
  6.     // height animations
  7.     [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
  8.     // width animations
  9.     [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
  10.     // opacity animations
  11.     [ "opacity" ]
  12. ];
  13.  
  14. function genFx( type, num ){
  15.     var obj = {};
  16.     jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function(){
  17.         obj[ this ] = type;
  18.     });
  19.     return obj;
  20. }
  21.  
  22. var FB_SLIDE_UP = genFx('hide', 1);
  23.  
  24. function format_time(sec, how) {
  25.  unix = parseInt(sec);
  26.  millis = sec * 1000;
  27.  
  28.  now = new Date();
  29.  d = new Date(millis);
  30.  
  31.  if (how === "pretty") {
  32.   return prettyDate(d);
  33.  } else if (how === "smart") {
  34.   if (Math.abs(((now.getMonth() - d.getMonth()) % 12) < 2 ) && (now.getFullYear() == d.getFullYear())) {
  35.    return d.format("shortTime");
  36.   } else if (d.getFullYear() != now.getFullYear()){ // not this year
  37.    return d.format("mmmm");
  38.   } else { // Between 1 month and 1 year old
  39.    return d.format("mmmm d");
  40.   }
  41.  } else {
  42.   return d.format(how);
  43.  }
  44. }
  45.     function convert_time(sec){
  46.         var t = new Date;
  47.         t.setTime(parseInt(sec * 1000));
  48.         return t.toLocaleTimeString();
  49.     }
  50.  
  51. function do_convert_time(){
  52.     try {
  53.         var t = format_time($(this).attr("timestamp"), 'smart')
  54.         $(this).text(t);
  55.     } catch (err) {}
  56. }
  57. // end timestamps
  58.  
  59. // image sizing
  60. function size_images(){
  61.         var suggested_max = 64;
  62.         var imgs = $($(this).parents(".messagecell")[0]).find(".picturelink[complete=true]")
  63.         var max = suggested_max;
  64. //        var max = 0;
  65.         if (imgs.length > 0){
  66.             for (var i = 0; i < imgs.length; i++){
  67.                 img = imgs[i];
  68.                 if (img.width > img.height) {
  69.                     max = Math.min(img.naturalHeight, Math.max(max, suggested_max));
  70. //                    max = Math.max(max, suggested_max);
  71.                 } else {
  72.                     max = Math.min(max,
  73.                             Math.min(img.naturalHeight,
  74.                                     Math.max(max,
  75.                                             Math.max(Math.round(img.naturalHeight/(img.naturalWidth/suggested_max)),
  76.                                                     suggested_max))));
  77. //                    max = Math.max(max, Math.max(Math.round(img.naturalHeight/(img.naturalWidth/suggested_max)), suggested_max));
  78.                 }
  79.             };
  80.  
  81.             if (max > 0) {
  82.                 imgs.css({'max-height': max + 'px', 'visibility':'visible'});
  83. //                for exact size
  84. //                imgs.css("max-width", Math.round((max/img.naturalHeight)*img.naturalWidth) + "px");
  85.             }
  86.         };
  87.         $(this).show();
  88.     };
  89. // end image sizing
  90.  
  91.  
  92. function hide_this_comment_box(self, animate) {
  93.     if (animate === undefined)
  94.         animate = true;
  95.  
  96.     if (self === undefined){
  97.         alert('need self')
  98.     } else {
  99.         var me2 = $(self);
  100.     }
  101.     var comment_box_disabled = $(me2.parents(".messagecell")[0]).find('[name="foo"]')[0].disabled;
  102.     if (!comment_box_disabled){
  103.         me2.parents(".messagecell").find('.likes_comments_section').css('-webkit-user-select','none');
  104.         var end2 = $(me2.parents(".messagecell")[0]).find(".comments_end");
  105.         var comment_button_section = me2.parents(".messagecell").find(".comment_button_section");
  106.         var likes_comment_section = me2.parents('.messagecell').find('.likes_comments_section');
  107.         var time = animate ? transitionDefault : 0;
  108.         if (time) {
  109.             end2.animate(FB_SLIDE_UP, {queue:false, duration:time});
  110.             offset_top = me2.parents(".messagecell").offset().top;
  111.             var pageYOffset = window.pageYOffset;
  112.             var offsetHeight = document.body.offsetHeight;
  113.             if (offset_top < pageYOffset){
  114.                 $('html, body').animate({
  115.                     scrollTop: offset_top
  116.                 }, {queue:false, duration:time});
  117.             }
  118.             likes_comment_section.slideUp(time, function(){
  119.                 likes_comment_section.css('-webkit-user-select','text');
  120.             });
  121.             comment_button_section.show();
  122.         } else {
  123.             end2.hide();
  124.             comment_button_section.show();
  125.             likes_comment_section.hide();
  126.             likes_comment_section.css('-webkit-user-select','text');
  127.         }
  128.     }
  129.     return false;
  130. };
  131.  
  132.  
  133.  
  134. function error_text(self, text, error_obj, callback){
  135.     error = self.parents(".messagecell").find('.error_section');
  136.     if (error_obj !== undefined && error_obj !== null) {
  137.         if (error_obj.error_code){
  138.             text += '<br/>' + error_obj.error_code + ': ';
  139.         };
  140.         if (error_obj.error_msg){
  141.             text += error_obj.error_msg;
  142.         };
  143.         if (error_obj.grant) {
  144.             text += ' - <a href="javascript:null;" title="Opens a login window at facebook.com" class="do_grant">Grant Permission</a>'
  145.         };
  146.     }
  147.  
  148.     error.html(text);
  149.     if (error.css('display') === 'none'){
  150.         error.slideDown(transitionDefault, callback);
  151.     } else if (!error.css('display')) {
  152.         error.css('display', 'block');
  153.         if (callback){
  154.             callback();
  155.         };
  156.     } else {
  157.         if (callback){
  158.             callback();
  159.         };
  160.     }
  161. }
  162.  
  163. function fb_clear_error(self, callback){
  164.     error = self.parents(".messagecell").find('.error_section');
  165.     var do_clear = function (){
  166.         error.html('');
  167.         if (callback){ callback(); };
  168.     }
  169.     if (error.css('display') === 'block'){
  170.         error.slideUp(transitionDefault / 2, do_clear);
  171.     } else if (!error.css('display')) {
  172.         error.css('display', 'none');
  173.         do_clear();
  174.     } else {
  175.         do_clear();
  176.     }
  177. }
  178.  
  179. function refresh_row(params){
  180.     params = params[0];
  181.     var post_id = params.post_id;
  182.     var newhtml = params.newhtml;
  183.     var row = $($('.post_row[id="' + post_id + '"]')[0]);
  184.     row.hide();
  185.     row.replaceWith(newhtml);
  186.     var row2 = $($('.post_row[id="' + post_id + '"]')[0]);
  187.     row2.find(".time").each(function(){
  188.         $(this).text(format_time($(this).attr("timestamp"), 'smart'));
  189.     });
  190.     row2.find(".picturelink").bind("load",size_images);
  191.     row2.show();
  192.  
  193. };
  194.  
  195. function remove_comment(comment_id){
  196.     var comment = $("#comment_" + comment_id);
  197.     comment.slideUp((transitionDefault ? transitionDefault/2 : 0), function(){comment.remove();});
  198. };
  199.  
  200. var commentFieldPadding;
  201.  
  202. $(function(){
  203.     var t = $("<textarea/>").css({'position':'fixed', 'right':'-500px', 'bottom':'-500px'}).appendTo(document.body);
  204.     commentFieldPadding =  t.outerWidth() - t.width();
  205.     t.remove();
  206. })
  207.  
  208. function fb_buddyicon_click(){
  209.     var me = $(this);
  210.     $('.post_row').not(':has(.buddyicon[src=' + me.attr('src') + '])').toggle();
  211. }
  212.  
  213. function fb_near_bottom(){
  214.     var desired = window.digsby_infobox_desired_height;
  215.     var window_inner_height = window.innerHeight;
  216.     if (!desired || desired < window_inner_height) {
  217.         desired = window_inner_height;
  218.     }
  219.     var pageYOffset = window.pageYOffset;
  220.     var offsetHeight = document.body.offsetHeight;
  221.  
  222.     ret = ( pageYOffset >= ( offsetHeight - ( desired * 2.0 ) ) );
  223.     return ret;
  224. }
  225.  
  226.