Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-08-2011, 06:33 PM
abdicar abdicar is offline
 
Join Date: Oct 2006
Posts: 22
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Reload Captcha in custom JavaScript.

Hello there,

We are doing in a custom page an integration with the vBulletin captcha, and we are almost done, but in special circunstances when we get an error from a progress we need to reload the captcha with ajax in the same form.

At this time, all the progress of captcha are made my the file vbulletin_ajax_imagereg.js, but it works with YUI, and to be honest I never use it before and I spend few hours and still I didnt get a easy way to reload the captcha calling a funcition in one line without press the default reload captcha link.

PHP Code:
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 4.1.2
|| # ---------------------------------------------------------------- # ||
|| # Copyright ?2000-2011 vBulletin Solutions Inc. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/
function vB_AJAX_ImageReg()
{
    
this.init()
}
vB_AJAX_ImageReg.prototype.init = function ()
{
    if (
AJAX_Compatible && (typeof vb_disable_ajax == "undefined" || vb_disable_ajax 2) && YAHOO.util.Dom.get("refresh_imagereg"))
    {
        
YAHOO.util.Event.on("refresh_imagereg""click"this.fetch_imagethistrue);
        
YAHOO.util.Dom.removeClass("refresh_imagereg""hidden");
        
YAHOO.util.Event.on("imagereg""click"this.fetch_imagethistrue)
    }
};
vB_AJAX_ImageReg.prototype.fetch_image = function (A)
{
    
YAHOO.util.Event.stopEvent(A);
    
YAHOO.util.Dom.removeClass("progress_imagereg""hidden");
    
YAHOO.util.Connect.asyncRequest("POST""ajax.php?do=imagereg"
    {
        
success this.handle_ajax_responsefailure this.handle_ajax_errortimeout vB_Default_Timeout
        
scope this
    
},
    
SESSIONURL "securitytoken=" SECURITYTOKEN "&do=imagereg&hash=" YAHOO.util.Dom.get("hash").getAttribute("value"));
    return 
false;
};
vB_AJAX_ImageReg.prototype.handle_ajax_error = function (A)
{
    
vBulletin_AJAX_Error_Handler(A)
};
vB_AJAX_ImageReg.prototype.handle_ajax_response = function (B)
{
    
YAHOO.util.Dom.addClass("progress_imagereg""hidden");
    if (
B.responseXML)
    {
        var 
B.responseXML.getElementsByTagName("error");
        if (
A.length) {
            
alert(A[0].firstChild.nodeValue)
        }
        else
        {
            var 
B.responseXML.getElementsByTagName("hash")[0].firstChild.nodeValue;
            if (
C)
            {
                
YAHOO.util.Dom.get("hash").setAttribute("value"C);
                
YAHOO.util.Dom.get("imagereg").setAttribute("src""image.php?" SESSIONURL "type=hv&hash=" C)
            }
        }
    }
};
function 
vB_AJAX_ImageReg_Init()
{
    new 
vB_AJAX_ImageReg()
}; 
If we use a simple <a href="">, what we can call from inline to reload the captcha?

Thank you in advanced for any help.

--------------- Added [DATE]1299619304[/DATE] at [TIME]1299619304[/TIME] ---------------

Update:

Well, I tried this and works fine in FF and Chrome, but IE (as always sucks) return an error.

PHP Code:
    function fakeClick(anchorObj) {
 

        
      var 
evt document.createEvent("MouseEvents"); 
      
evt.initMouseEvent("click"truetruewindow
          
00000falsefalsefalsefalse0null); 
      var 
allowDefault anchorObj.dispatchEvent(evt);

    } 
Error in IE:

Quote:

Mensaje: El objeto no acepta esta propiedad o m?todo
In english something like: Error: Object doesn't support this action

If anyone can suggest me something better will be very nice.

--------------- Added [DATE]1299621670[/DATE] at [TIME]1299621670[/TIME] ---------------

Update:

Ok, I get solved with this:

PHP Code:
    function robotClick(anchorObj) {

        if (
anchorObj.click) {
            
anchorObj.click()
        }else{
            var 
evt document.createEvent("MouseEvents"); 
            
evt.initMouseEvent("click"truetruewindow
            
00000falsefalsefalsefalse0null); 
            var 
allowDefault anchorObj.dispatchEvent(evt);      }

    } 
And you can call it in your JS as easy as: robotClick(document.getElementById('refresh_imager eg'));

I somebody have a better solution ( I'm pretty sure that It could exist please reply
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:01 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04184 seconds
  • Memory Usage 2,205KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)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
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete