Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery(function($) {
- var page_id = $("#posts-container").data("page-id");
- $('.facebook-message').live('mouseover',function() { $(this).find(".message-tool-box-extras").show(); } );
- $('.facebook-message').live('mouseout',function() { $(this).find(".message-tool-box-extras").hide(); } );
- $('#search-container').find(':submit').click(function() {
- $("#posts-results").empty();
- $.read('/posts/search',
- { search: { q: $('#search_q').val() , page_id: page_id } },
- post_result);
- });
- function post_result(response) {
- $('.feed-more img').hide();
- _.each(response, function(post) {
- //Jquery templates do not render the new line characters
- //so we replace them with br tags
- if(post.post.message != null) {
- post.post.message = post.post.message.replace(/\n/,'</br>');
- }
- //Let's get all the available actions for this post
- if(post.post.properties.actions != null && post.post.properties.actions.length > 0) {
- _.each(post.post.properties.actions, function(item) {
- post.post.properties[item.name.toLowerCase() + '_link'] = encodeURIComponent(item.link);
- });
- }
- //Facebook does not tell us when a link is a event, so we have to parse it
- //to figure it out
- var event_regex = /event.php/;
- if(post.post.properties.link != null && post.post.properties.link.match(event_regex)) {
- post.post.properties['is_event'] = true;
- }
- });
- var tmpl = $("#post_template").tmpl(response).appendTo("#posts-results");
- $(tmpl).find(".post-time").localTimeFromUTC('MM/dd/yyyy hh:mm a');
- $(tmpl).find(".post-time").each(function() {
- var time = $(this).html();
- $(this).html($.timeago(time));
- });
- $(".user-avatar").qtip({
- content: "Loading...",
- hide: { fixed:true, delay:500, event:'mouseleave' },
- events: {
- show: function(event,api) {
- var fb_user_id = $(event.originalEvent.currentTarget).data('fb-user-id');
- $.read('/fb_users/{user_id}/user-details',
- { page_id: page_id, user_id: fb_user_id },
- function(response) {
- var user_actions_view = $("#user_actions_template").tmpl(response);
- api.set('content.text',user_actions_view);
- var user_actions_view = $(api.elements.content);
- user_actions_view.find('.submit-keyword').bind('click', function(e) {
- console.log('submitting key:' + user_actions_view.find("select").val());
- $.create('/keywords',
- { keyword: {
- label: 'todo',
- monitorable_id: page_id,
- monitorable_type: 'Page',
- data: fb_user_id,
- entity_type: 'person',
- action: [user_actions_view.find("select").val()]
- }
- },
- function(response) {
- alert('tag added');
- });
- });
- user_actions_view.find('.tag-user').bind('click',function(event) {
- user_actions_view.find(":hidden").show();
- });
- });
- }
- }
- });
- };
- $.read('/pages/{page_id}/posts', { page_id: page_id }, post_result);
- $('.commentCount').live('click', function(event) {
- if( $(this).parent().parent().find('.comments-container').length )
- {
- $( this ).parent().parent().find('.comments-container').remove();
- return false;
- }
- var post_id = $(this).data("post-id");
- var is_post_deleted = $(this).data("post-deleted");
- //Read the comment list and add any event listeners
- $.read(
- '/posts/{post_id}/comments',
- { post_id: post_id },
- function(response) {
- $("#comment_list_template").tmpl({comments: response, post_id: post_id, is_post_deleted: is_post_deleted }).appendTo("#post-" + post_id);
- $(".flag-post-comment").live("click", function(event)
- {
- var comment_id = $(this).data("post-comment-id");
- var mood = $(this).data("mood");
- $.update(
- "/posts/{post_id}/comments/{comment_id}",
- { post_id: post_id, comment: {mood: mood}, comment_id: comment_id },
- function(response) {
- $("#comment-" + comment_id + "-flag").children().replaceWith($("#toggle_flag_template").tmpl({data:response.comment,type:'post-comment'}));
- }
- );
- return false;
- });
- /* *Listener for creating a comment */
- $(".submit-comment").bind("click", function(event) {
- var post_id = $(this).data("post-id");
- var post_as = $(this).parent().parent().find(":checked").val()
- $.create(
- "/posts/{post_id}/comments",
- { post_id: post_id,
- comment: {
- post_id: post_id,
- message: $(this).parent().parent().find("textarea").val(),
- },
- post_as: post_as
- },
- function(response) {
- $("#comment_template").tmpl({ comment: response.comment, is_post_deleted: false, post_id: post_id }).appendTo("#post-" + post_id + "-comments-list");
- $("#comment-entry-" + post_id).val("");
- var comment_link = $("#post-" + post_id).find(".commentCount");
- var comments_count = parseInt(comment_link.data('comment-count')) + 1;
- comment_link.attr("data-comment-count" , comments_count);
- $("#post-" + post_id).find(".commentCount").html(comments_count + " Comments")
- });
- });
- $(".delete-post-comment").live("click", function(event) {
- if( confirm('Are you sure?') )
- {
- var comment_id = $(this).data("comment-id");
- $.destroy(
- "/comments/{comment_id}",
- { comment_id: comment_id },
- function(response) {
- $("#comment-" + comment_id).replaceWith($("#comment_template").tmpl(response));
- },function(error) { alert("error"); });
- }
- return false;
- });
- }
- );
- return false;
- });
- //Delete a post listener
- $(".delete-post").live('click', function(event) {
- if ( confirm('Are you sure?') ) {
- var post_id = $(this).data('postid');
- var post_url = '/posts/' + post_id;
- $.ajax({
- type: 'POST',
- url: post_url,
- dataType: 'json',
- data: { _method: 'delete', id: post_id },
- error: function(data) {
- alert('error');
- },
- success: function(event,xhr,options) {
- $("#post-" + post_id).replaceWith($("#post_template").tmpl(event));
- $("#post-" + post_id).find(".post-time").localTimeFromUTC('MM/dd/yyyy hh:mm a');
- }
- });
- }
- return false;
- });
- $("#keywords-link").bind('click', function(event) {
- $.read("/pages/{page_id}/keywords",
- { page_id: page_id },
- function(response) {
- var dialog = $("#keywords_dialog_template").tmpl({ keywords: response, page: { id: page_id }}).appendTo("body");
- dialog.dialog({modal:true});
- var target = $('.keyword-link-container').find('a');
- dialog.dialog("option",{position: {
- my: 'left top',
- at: 'right top',
- of: target
- },resizable: false});
- $("#page-" + page_id + "-keywords").find("form").bind("ajax:success",function(xhr,data,status) {
- $("#keyword_errors").html("");
- $("#keyword_errors").hide();
- $("#keywords_template").tmpl($.parseJSON(data)).appendTo(dialog.find(".keyword-list"));
- dialog.find(".keywords-entry").find(":text").val("")
- dialog.dialog("close");
- });
- $(".ui-widget-overlay").live("click", function() { dialog.dialog("close"); } );
- });
- });
- $(".flag-post").live('click', function(event) {
- var post_id = $(this).data('post-id');
- var mood = $(this).data("mood");
- $.update('/posts/{post_id}',
- { post_id: post_id, post: { mood: mood } },
- function(response) {
- console.log(response);
- $("#flag_" + post_id).replaceWith($("#toggle_flag_template").tmpl({data:response.post,type:'post'}));
- });
- });
- $('.feed-more a').click(function() {
- $('.feed-more img').show();
- var page = $(this).data('current-page') + 1;
- $(this).data('current-page', page);
- $.read('/pages/{page_id}/posts', { page_id: page_id, page: page }, post_result);
- return false;
- });
- });
Add Comment
Please, Sign In to add comment