On my site http://motiongraphicscollective.com/ i am using colorbox.
When you click on a thumbnail at the home screen i use this script to open my colorbox.
jQuery.ajax({
type: 'POST',
url: 'http://motiongraphicscollective.com/wp-admin/admin-ajax.php',
data: {
action: 'myAjax',
blog_id: blog,
single_id: single,
},
beforeSend:function(data){ // Are not working with dataType:'jsonp'
$("#"+single+"").find('.project-title').html('<img src="http://motiongraphicscollective.com/wp-content/themes/parallelus-salutation/assets/images/bp-ajax-loader.gif">');
},
success: function(data, textStatus, XMLHttpRequest){
$("#single-content").html('');
$("#single-content").append(data);
$(".single_popup").click();
},
error: function(MLHttpRequest, textStatus, errorThrown){
alert(errorThrown);
}
});
$(document).bind('cbox_closed', function(){
$("#"+single+"").find('.project-title').html(title);
});
As you can see i use Ajax to open my colorbox. The function myAjax will fill the div #single content.
function myAjax(){
global $bp;
//get data from our ajax() call
$blog_id = $_POST['blog_id'];
$single_id = $_POST['single_id'];
switch_to_blog($blog_id);
$post_x = get_post($single_id);
//Author Media
$author = $post_x->post_author;
$author_firstname = get_the_author_meta('first_name',$author);
$author_lastname = get_the_author_meta('last_name',$author);
$author_proffesion = get_user_meta( $author,'user_profession', true );
if(!$author_firstname){
$author_name = get_the_author_meta('user_login',$author);
} else {
$author_name = $author_firstname . '</br>' . $author_lastname;
}
if ( is_user_logged_in() && !bp_is_my_profile() ){
$metion = '<a href="' . bp_get_send_public_message_link() . '" title="Mention this user in a new public message, this will send the user a notification to get their attention.">@ mention</a>';
}
$posttext = $post_x->post_content;
$regular_expression = '~<img [^\>]*\ />~';
$only_post_text = preg_replace( $regular_expression, '' , $posttext);
$output = '<div id="single-video">' . videoBox($single_id) . '</div>';
$output .= '<div id="single-middle">'.
'<div id="single-sidebar">'.
'<div id="single-sidebar-inner">'.
'<div id="single-avatar">' . bp_core_fetch_avatar( array( 'item_id' => $post_x->post_author, 'type' => 'full' ) ) . '</div>'.
'<div id="single-author"><h3 class="entry-title">' . $author_name . '</h3></div>'.
'<div id="single-proffession" class="proffesion">' . $author_proffesion .'</div>'.
'<div id="single-follow"></div>'.
'<div id="single-portfolio"><a class="btn" href="' . bp_core_get_user_domain($author) . '" title="to author profile">View more projects</a> </div>'.
'</div>'.
'</div>'.
'<div id="single-main">'.
'<div class="voting-box">'.
'<div id="up">'.
wdpv_get_vote_up_ms(true, $blog_id, $single_id) .
'</div>'.
'<div id="results">'.
wdpv_get_vote_result_ms(false, $blog_id, $single_id). '<span>Thumbs up</span>'.
'</div>'.
'</div>'.
'<div id="single-title">' . $post_x->post_title . '</div>'.
'<div id="single-text"><p>' . $only_post_text . '</p></div>'.
'</div>'.
'</div>';
restore_current_blog();
// Return String
die($output);
}
Maybe not the best piece of Ajax but it works.
But not all works, the thumbs up button doesn't work. This is a Wordpress plugin that also works with Ajax. (working example here http://motiongraphicscollective.com/2013/we-think-things-reel-2013/)
How can i make the thumbs up work within the colorbox?