daily pastebin goal
42%
SHARE
TWEET

Untitled

a guest Jan 12th, 2018 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready ->
  2.   page_id = $('#posts-container').data 'page-id'
  3.  
  4.   $('.facebook-message').live 'mouseover', ->
  5.     $(this).find('.message-tool-box-extras').show()
  6.  
  7.   $('.facebook-message').live 'mouseout', ->
  8.     $(this).find('.message-tool-box-extras').hide()
  9.  
  10.   $('#search-container').find(':submit').click ->
  11.     $("#posts-results").empty()
  12.     params =
  13.       q: $('#search_q').val()
  14.       page_id: page_id
  15.     $.read '/posts/search', params, post_result
  16.  
  17.   post_result = (response) ->
  18.     $('.feed-more img').hide()
  19.     _.each response, (wall_post) ->
  20.       post = wall_post.post
  21.       if post.message != null
  22.         post.message = post.message.replace /\n/,'</br>'
  23.  
  24.       if post.properties.actions? && post.properties.actions.length > 0
  25.         _.each post.properties.actions, (item) ->
  26.           post.properties["#{item.name.toLowerCase()}_link"] = encodeURIComponent item.link
  27.  
  28.       event_regex = /event.php/
  29.  
  30.       if post.properties.link? && post.properties.link.match event_regex
  31.         post.properties['is_event'] = true
  32.  
  33.     tmpl = $("#post_template").tmpl(response).appendTo "#posts-results"
  34.     $(tmpl).find(".post-time").localTimeFromUTC 'MM/dd/yyyy hh:mm a'
  35.     $(tmpl).find(".post-time").each ->
  36.       time = $(this).html()
  37.       $(this).html $.timeago time
  38.  
  39.     qtip_show = (event,api) ->
  40.       fb_user_id = $(event.originalEvent.currentTarget).data 'fb-user-id'
  41.       request_params =
  42.         page_id: page_id
  43.         user_id: fb_user_id
  44.  
  45.       $.read '/fb_users/{user_id}/user-details',request_params,(response) ->
  46.         user_actions_view = $("#user_actions_template").tmpl response
  47.         api.set 'content.text',user_actions_view
  48.         user_actions_view = $ api.elements.content
  49.  
  50.         user_actions_view.find('.submit-keyword').click (e) ->
  51.           keyword =
  52.             label: 'todo'
  53.             monitorable_id: page_id
  54.             monitorable_type: 'Page'
  55.             data: fb_user_id
  56.             entity_type: 'person'
  57.             action: [user_actions_view.find("select").val()]
  58.  
  59.           $.create '/keywords', { keyword } , (response) ->
  60.             alert 'tag added'
  61.  
  62.         user_actions_view.find('.tag-user').click (event) ->
  63.           user_actions_view.find(":hidden").show()
  64.  
  65.     qtip_params =
  66.       content: 'Loading...'
  67.       hide:
  68.         fixed: true
  69.         delay: 500
  70.         event: 'mouseleave'
  71.       events:
  72.         show: qtip_show
  73.     $('.user-avatar').qtip qtip_params
  74.  
  75.   $.read '/pages/{page_id}/posts', { page_id: page_id }, post_result
  76.  
  77.   $('.commentCount').live 'click', (event) ->
  78.     if $(this).parent().parent().find('.comments-container').length
  79.       $(this).parent().parent().find('.comments-container').remove()
  80.       return false
  81.  
  82.     post_id = $(this).data "post-id"
  83.     is_post_deleted = $(this).data "post-deleted"
  84.  
  85.     $.read '/posts/{post_id}/comments', { post_id: post_id }, (response) ->
  86.       template_params =
  87.         comments: response
  88.         post_id: post_id
  89.         is_post_deleted: is_post_deleted
  90.       $("#comment_list_template").tmpl(template_params).appendTo "#post-#{post_id}"
  91.  
  92.       $(".flag-post-comment").live "click", (event) ->
  93.         comment_id = $(this).data("post-comment-id")
  94.         mood = $(this).data("mood")
  95.         request_params =
  96.           post_id: post_id
  97.           comment_id: comment_id
  98.           comment:
  99.             mood: mood
  100.         $.update "/posts/{post_id}/comments/{comment_id}", request_params, (response) ->
  101.           $("#comment-#{comment_id}-flag").children().replaceWith($("#toggle_flag_template").tmpl({data:response.comment,type:'post-comment'}))
  102.  
  103.       $(".submit-comment").click (event) ->
  104.         request_params =
  105.           post_id: $(this).data "post-id"
  106.           post_as: $(this).parent().parent().find(":checked").val()
  107.           comment:
  108.             post_id: post_id
  109.             message: $(this).parent().parent().find("textarea").val()
  110.         $.create '/posts/{post_id}/comments', request_params, (response) ->
  111.           $("#comment_template").tmpl({ comment: response.comment, is_post_deleted: false, post_id: post_id }).appendTo("#post-" + post_id + "-comments-list")
  112.           $("#comment-entry-" + post_id).val("")
  113.           comment_link = $("#post-" + post_id).find(".commentCount")
  114.           comments_count = parseInt(comment_link.data('comment-count')) + 1
  115.           comment_link.attr("data-comment-count" , comments_count)
  116.           $("#post-" + post_id).find(".commentCount").html(comments_count + " Comments")
  117.  
  118.  
  119.       $(".delete-post-comment").live "click", ->
  120.         if confirm 'Are you sure?'
  121.           comment_id = $(this).data("comment-id")
  122.           $.destroy "/comments/{comment_id}", { comment_id: comment_id }, (response) ->
  123.             $("#comment-" + comment_id).replaceWith($("#comment_template").tmpl(response))
  124.         return false
  125.     return false
  126.  
  127.   #Delete a post listener
  128.   $(".delete-post").live 'click', ->
  129.     if confirm 'Are you sure?'
  130.       post_id = $(this).data('postid')
  131.       $.destroy '/posts/{post_id}', { post_id: post_id }, (response) ->
  132.         $("#post-" + post_id).replaceWith($("#post_template").tmpl(response))
  133.         $("#post-" + post_id).find(".post-time").localTimeFromUTC('MM/dd/yyyy hh:mm a')
  134.     return false
  135.  
  136.   $("#keywords-link").click ->
  137.     $.read "/pages/{page_id}/keywords", { page_id: page_id }, (response) ->
  138.         dialog = $("#keywords_dialog_template").tmpl({ keywords: response, page: { id: page_id }}).appendTo("body")
  139.         dialog.dialog {modal:true}
  140.         target = $('.keyword-link-container').find('a')
  141.         dialog.dialog "option",{position: {
  142.           my: 'left top',
  143.           at: 'right top',
  144.           of: target
  145.         },resizable: false}
  146.         $("#page-" + page_id + "-keywords").find("form").bind("ajax:success", (xhr,data,status) ->
  147.           $("#keyword_errors").html("")
  148.           $("#keyword_errors").hide()
  149.           $("#keywords_template").tmpl($.parseJSON(data)).appendTo(dialog.find(".keyword-list"))
  150.           dialog.find(".keywords-entry").find(":text").val("")
  151.           dialog.dialog("close")
  152.         $(".ui-widget-overlay").live "click", -> dialog.dialog("close"))
  153.  
  154.   $(".flag-post").live 'click', ->
  155.     post_id = $(this).data('post-id')
  156.     mood = $(this).data("mood")
  157.     $.update '/posts/{post_id}', { post_id: post_id, post: { mood: mood } }, (response) ->
  158.         console.log(response)
  159.         $("#flag_" + post_id).replaceWith($("#toggle_flag_template").tmpl({data:response.post,type:'post'}))
  160.  
  161.   $('.feed-more a').click ->
  162.     $('.feed-more img').show()
  163.     page = $(this).data('current-page') + 1
  164.     $(this).data('current-page', page)
  165.     $.read('/pages/{page_id}/posts', { page_id: page_id, page: page }, post_result)
  166.     return false
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top