Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 10th, 2012  |  syntax: None  |  size: 9.02 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. (function() {
  2.   $(document).ready(function() {
  3.     var page_id, post_result;
  4.     page_id = $('#posts-container').data('page-id');
  5.     $('.facebook-message').live('mouseover', function() {
  6.       return $(this).find('.message-tool-box-extras').show();
  7.     });
  8.     $('.facebook-message').live('mouseout', function() {
  9.       return $(this).find('.message-tool-box-extras').hide();
  10.     });
  11.     $('#search-container').find(':submit').click(function() {
  12.       var params;
  13.       $("#posts-results").empty();
  14.       params = {
  15.         q: $('#search_q').val(),
  16.         page_id: page_id
  17.       };
  18.       return $.read('/posts/search', params, post_result);
  19.     });
  20.     post_result = function(response) {
  21.       var qtip_params, qtip_show, tmpl;
  22.       $('.feed-more img').hide();
  23.       _.each(response, function(wall_post) {
  24.         var event_regex, post;
  25.         post = wall_post.post;
  26.         if (post.message !== null) {
  27.           post.message = post.message.replace(/\n/, '</br>');
  28.         }
  29.         if ((post.properties.actions != null) && post.properties.actions.length > 0) {
  30.           _.each(post.properties.actions, function(item) {
  31.             return post.properties["" + (item.name.toLowerCase()) + "_link"] = encodeURIComponent(item.link);
  32.           });
  33.         }
  34.         event_regex = /event.php/;
  35.         if ((post.properties.link != null) && post.properties.link.match(event_regex)) {
  36.           return post.properties['is_event'] = true;
  37.         }
  38.       });
  39.       tmpl = $("#post_template").tmpl(response).appendTo("#posts-results");
  40.       $(tmpl).find(".post-time").localTimeFromUTC('MM/dd/yyyy hh:mm a');
  41.       $(tmpl).find(".post-time").each(function() {
  42.         var time;
  43.         time = $(this).html();
  44.         return $(this).html($.timeago(time));
  45.       });
  46.       qtip_show = function(event, api) {
  47.         var fb_user_id, request_params;
  48.         fb_user_id = $(event.originalEvent.currentTarget).data('fb-user-id');
  49.         request_params = {
  50.           page_id: page_id,
  51.           user_id: fb_user_id
  52.         };
  53.         return $.read('/fb_users/{user_id}/user-details', request_params, function(response) {
  54.           var user_actions_view;
  55.           user_actions_view = $("#user_actions_template").tmpl(response);
  56.           api.set('content.text', user_actions_view);
  57.           user_actions_view = $(api.elements.content);
  58.           user_actions_view.find('.submit-keyword').click(function(e) {
  59.             var keyword;
  60.             keyword = {
  61.               label: 'todo',
  62.               monitorable_id: page_id,
  63.               monitorable_type: 'Page',
  64.               data: fb_user_id,
  65.               entity_type: 'person',
  66.               action: [user_actions_view.find("select").val()]
  67.             };
  68.             return $.create('/keywords', {
  69.               keyword: keyword
  70.             }, function(response) {
  71.               return alert('tag added');
  72.             });
  73.           });
  74.           return user_actions_view.find('.tag-user').click(function(event) {
  75.             return user_actions_view.find(":hidden").show();
  76.           });
  77.         });
  78.       };
  79.       qtip_params = {
  80.         content: 'Loading...',
  81.         hide: {
  82.           fixed: true,
  83.           delay: 500,
  84.           event: 'mouseleave'
  85.         },
  86.         events: {
  87.           show: qtip_show
  88.         }
  89.       };
  90.       return $('.user-avatar').qtip(qtip_params);
  91.     };
  92.     $.read('/pages/{page_id}/posts', {
  93.       page_id: page_id
  94.     }, post_result);
  95.     $('.commentCount').live('click', function(event) {
  96.       var is_post_deleted, post_id;
  97.       if ($(this).parent().parent().find('.comments-container').length) {
  98.         $(this).parent().parent().find('.comments-container').remove();
  99.         return false;
  100.       }
  101.       post_id = $(this).data("post-id");
  102.       is_post_deleted = $(this).data("post-deleted");
  103.       $.read('/posts/{post_id}/comments', {
  104.         post_id: post_id
  105.       }, function(response) {
  106.         var template_params;
  107.         template_params = {
  108.           comments: response,
  109.           post_id: post_id,
  110.           is_post_deleted: is_post_deleted
  111.         };
  112.         $("#comment_list_template").tmpl(template_params).appendTo("#post-" + post_id);
  113.         $(".flag-post-comment").live("click", function(event) {
  114.           var comment_id, mood, request_params;
  115.           comment_id = $(this).data("post-comment-id");
  116.           mood = $(this).data("mood");
  117.           request_params = {
  118.             post_id: post_id,
  119.             comment_id: comment_id,
  120.             comment: {
  121.               mood: mood
  122.             }
  123.           };
  124.           return $.update("/posts/{post_id}/comments/{comment_id}", request_params, function(response) {
  125.             return $("#comment-" + comment_id + "-flag").children().replaceWith($("#toggle_flag_template").tmpl({
  126.               data: response.comment,
  127.               type: 'post-comment'
  128.             }));
  129.           });
  130.         });
  131.         $(".submit-comment").click(function(event) {
  132.           var request_params;
  133.           request_params = {
  134.             post_id: $(this).data("post-id"),
  135.             post_as: $(this).parent().parent().find(":checked").val(),
  136.             comment: {
  137.               post_id: post_id,
  138.               message: $(this).parent().parent().find("textarea").val()
  139.             }
  140.           };
  141.           return $.create('/posts/{post_id}/comments', request_params, function(response) {
  142.             var comment_link, comments_count;
  143.             $("#comment_template").tmpl({
  144.               comment: response.comment,
  145.               is_post_deleted: false,
  146.               post_id: post_id
  147.             }).appendTo("#post-" + post_id + "-comments-list");
  148.             $("#comment-entry-" + post_id).val("");
  149.             comment_link = $("#post-" + post_id).find(".commentCount");
  150.             comments_count = parseInt(comment_link.data('comment-count')) + 1;
  151.             comment_link.attr("data-comment-count", comments_count);
  152.             return $("#post-" + post_id).find(".commentCount").html(comments_count + " Comments");
  153.           });
  154.         });
  155.         return $(".delete-post-comment").live("click", function() {
  156.           var comment_id;
  157.           if (confirm('Are you sure?')) {
  158.             comment_id = $(this).data("comment-id");
  159.             $.destroy("/comments/{comment_id}", {
  160.               comment_id: comment_id
  161.             }, function(response) {
  162.               return $("#comment-" + comment_id).replaceWith($("#comment_template").tmpl(response));
  163.             });
  164.           }
  165.           return false;
  166.         });
  167.       });
  168.       return false;
  169.     });
  170.     $(".delete-post").live('click', function() {
  171.       var post_id;
  172.       if (confirm('Are you sure?')) {
  173.         post_id = $(this).data('postid');
  174.         $.destroy('/posts/{post_id}', {
  175.           post_id: post_id
  176.         }, function(response) {
  177.           $("#post-" + post_id).replaceWith($("#post_template").tmpl(response));
  178.           return $("#post-" + post_id).find(".post-time").localTimeFromUTC('MM/dd/yyyy hh:mm a');
  179.         });
  180.       }
  181.       return false;
  182.     });
  183.     $("#keywords-link").click(function() {
  184.       return $.read("/pages/{page_id}/keywords", {
  185.         page_id: page_id
  186.       }, function(response) {
  187.         var dialog, target;
  188.         dialog = $("#keywords_dialog_template").tmpl({
  189.           keywords: response,
  190.           page: {
  191.             id: page_id
  192.           }
  193.         }).appendTo("body");
  194.         dialog.dialog({
  195.           modal: true
  196.         });
  197.         target = $('.keyword-link-container').find('a');
  198.         dialog.dialog("option", {
  199.           position: {
  200.             my: 'left top',
  201.             at: 'right top',
  202.             of: target
  203.           },
  204.           resizable: false
  205.         });
  206.         return $("#page-" + page_id + "-keywords").find("form").bind("ajax:success", function(xhr, data, status) {
  207.           $("#keyword_errors").html("");
  208.           $("#keyword_errors").hide();
  209.           $("#keywords_template").tmpl($.parseJSON(data)).appendTo(dialog.find(".keyword-list"));
  210.           dialog.find(".keywords-entry").find(":text").val("");
  211.           return dialog.dialog("close");
  212.         }, $(".ui-widget-overlay").live("click", function() {
  213.           return dialog.dialog("close");
  214.         }));
  215.       });
  216.     });
  217.     $(".flag-post").live('click', function() {
  218.       var mood, post_id;
  219.       post_id = $(this).data('post-id');
  220.       mood = $(this).data("mood");
  221.       return $.update('/posts/{post_id}', {
  222.         post_id: post_id,
  223.         post: {
  224.           mood: mood
  225.         }
  226.       }, function(response) {
  227.         console.log(response);
  228.         return $("#flag_" + post_id).replaceWith($("#toggle_flag_template").tmpl({
  229.           data: response.post,
  230.           type: 'post'
  231.         }));
  232.       });
  233.     });
  234.     return $('.feed-more a').click(function() {
  235.       var page;
  236.       $('.feed-more img').show();
  237.       page = $(this).data('current-page') + 1;
  238.       $(this).data('current-page', page);
  239.       $.read('/pages/{page_id}/posts', {
  240.         page_id: page_id,
  241.         page: page
  242.       }, post_result);
  243.       return false;
  244.     });
  245.   });
  246. }).call(this);