View Single Post
  #788  
Old 05-23-2006, 12:12 PM
Abe1's Avatar
Abe1 Abe1 is offline
 
Join Date: Feb 2004
Location: I LOVE New York!
Posts: 2,886
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by HuangA
Abe1:
Thanks for following up the request here's a little starter on how to make it so that you only really need it once. I've edited the postbit_button template to the following (it still comes up multiple times, but it only really need to be created 'once' at the top because its a function with parameters). It doesn't work yet because I am not familiar with call back functions, and I can't figure out how to pass the pid variable to the call back functions. If there's any AJAX guru or javascript expert who can help fix the rest, we can safely move the majority of the code to a separate .js file which can be cached by user browser and we can reduce the bandwidth usage by a lot (imagein the segment of code appear only once in a cached js VS appearing in html for each post appearing on page).

Code:
<script type="text/javascript">
<!--
function post_thanks_give( pid )
{
	do_thanks_button = new vB_AJAX_Handler(true)
	do_thanks_button.onreadystatechange = function () {
		alert('state ready pid: ' + pid);
		alert('state: ' + do_thanks_button.handler.readyState);
		if (do_thanks_button.handler.readyState == 4 && do_thanks_button.handler.status == 200)
		{
			fetch_object('post_thanks_button_' + pid).innerHTML = do_thanks_button.handler.responseText
		}
	}
	do_thanks_button.send('showthread.php?do=post_thanks_button_ajax&p='+pid)
	
	do_thanks_add = new vB_AJAX_Handler(true)
	do_thanks_add.onreadystatechange = function () {
		if (do_thanks_add.handler.readyState == 4 && do_thanks_add.handler.status == 200)
		{
			fetch_object('post_thanks_box_'+pid).innerHTML = do_thanks_add.handler.responseText
		}
	}
	do_thanks_add.send('showthread.php?do=post_thanks_add_ajax&p='+pid)
}

function post_thanks_remove_all( pid )
{
	do_thanks_button = new vB_AJAX_Handler(true)
	do_thanks_button.onreadystatechange = function () {
		if (do_thanks_button.handler.readyState == 4 && do_thanks_button.handler.status == 200)
		{
			fetch_object('post_thanks_button_'+pid).innerHTML = do_thanks_button.handler.responseText
		}
	}
	do_thanks_button.send('showthread.php?do=post_thanks_button_add_ajax&p='+pid)
	
	do_thanks_remove_all = new vB_AJAX_Handler(true)
	do_thanks_remove_all.onreadystatechange = function () {
		if (do_thanks_remove_all.handler.readyState == 4 && do_thanks_remove_all.handler.status == 200)
		{
			fetch_object('post_thanks_box_'+pid).innerHTML = do_thanks_remove_all.handler.responseText
		}
	}
	do_thanks_remove_all.send('showthread.php?do=post_thanks_remove_all_ajax&p='+pid)
}

function post_thanks_remove_user( pid )
{
	do_thanks_button = new vB_AJAX_Handler(true)
	do_thanks_button.onreadystatechange = function () {
		if (do_thanks_button.handler.readyState == 4 && do_thanks_button.handler.status == 200)
		{
			fetch_object('post_thanks_button_'+pid).innerHTML = do_thanks_button.handler.responseText
		}
	}
	do_thanks_button.send('showthread.php?do=post_thanks_button_add_ajax&p='+pid)

	do_thanks_remove_user = new vB_AJAX_Handler(true)
	do_thanks_remove_user.onreadystatechange = function () {
		if (do_thanks_remove_user.handler.readyState == 4 && do_thanks_remove_user.handler.status == 200)
		{
			fetch_object('post_thanks_box_'+pid).innerHTML = do_thanks_remove_user.handler.responseText
		}
	}
	do_thanks_remove_user.send('showthread.php?do=post_thanks_remove_user_ajax&p='+pid)
}

document.write('<a href="#" id="post_thanks_button_$post[postid]" onclick="post_thanks_give( $post[postid] ); return false;"> <img src="images/buttons/post_thanks.gif" alt="Thanks" border="0" /></a>');
//-->
</script>
<noscript>
<a href="showthread.php?do=post_thanks_add&amp;p=$post[postid]"> <img src="images/buttons/post_thanks.gif" alt="Thanks" border="0" /></a>
</noscript>
Problems with the above so far: the call back doesn't work, so it doesn't properly achieve the ajax effect, and the remove functions doesn't work for whatever reason... do NOT, I repeat do NOT deploy / test the above on your production board. Hopefully someone can fine tune it to work and this hack would be perfect
I'll try to figure this out when I have time. Right now I'm working on something for my 'Form Hack'. Something that can generate a form so people who dont understand php or html be able to get a custom form for their site.
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01039 seconds
  • Memory Usage 1,800KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete