The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
[vB 3] How to load Javascript code in a template called with AJAX ?
VBULLETIN 3
I made a product that modifies the Editor of the template postbit_quickedit.
Problem: The buttons using customised Javascript don't work. Problem origin: The postbit_quickedit template is called with AJAX. So my Javascript can't be interpret. My problem: After spending hours trying to understand how to make my hard coded Javascript code works with this template called via AJAX, I still don't get it. Is there an easy way to do it ?The only solution I found, is to fetch my JS template to Showtread template, but it's only working for the first edit (vB_Editor_QE_1). |
#2
|
|||
|
|||
Javascript included in a document returned by an ajax call won't be executed, as you found out. However, you can eval() it. That is, if you can get the code into a javascript string, you can just call eval(string).
|
#3
|
||||
|
||||
Thanks for your answer. Just to be sure, the eval() is the Javascript function, not the PHP function. If it's the Javascript function,where should I put it ? Inside my Javascript code which is postbit_quickedit template ? Somewhere else in my postbit_quickedit template ? Or to the parent page, the Showthread template ?
|
#4
|
|||
|
|||
Yes, I mean the javascript eval(). You say that your template called with ajax, so there has to be javascript code doing the ajax call and handling the return, right? So I guess you'd have to do the eval where the return from that ajax call is processed.
|
#5
|
||||
|
||||
It's postbit_quickedit vB template, the one who is displayed when the "edit" button is pressed.
I understand the logic what what you said, but I'm no sure to be able to find this ^^ I'm going to keep on searching. If vB has a hook for this, don't hesitate to tell me Thanks again. |
#6
|
|||
|
|||
Yeah, sorry I had trouble understanding. I guess what you mean is that the template is getting sent whenever you hit edit (and you have nothing to do with that), but there's javascript in it that you'd like to execute.
Anyway, maybe someone else will have an idea. |
#7
|
||||
|
||||
No I guess you were right. Many websites also explain the Javascript must be eval() or something equivalent.
Sources:
But I don't know how to do it, especially with vB. I've attached a scheme of my problem. |
#8
|
|||
|
|||
I don't know if there's a clever way to do it, but if you want to run some javascript after the quick editor loads, you could modify clientscript/vbulletin_quick_edit.php. There's a function that gets called when the ajax call is complete:
HTML Code:
vB_AJAX_QuickEditor.prototype.display_editor=function(C){ (it helps if you have a program that can reformat the .js file). |
#9
|
||||
|
||||
I saw a product that uses "misc_start" hook to execute js:
PHP Code:
--------------- Added [DATE]1313790827[/DATE] at [TIME]1313790827[/TIME] --------------- The "quickeditor_improver" product uses a trick to get access to that Javascript file: It uses the hook "showthread_complete" to search inside the SHOWTHREAD "clientscript/vbulletin_quick_edit.js?v=" and replaces it with a new value via misc.php page. Code:
unset($search, $replace); $search = 'clientscript/vbulletin_quick_edit.js?v='; $replace = 'misc.php?do=PUT_NAME_HERE_quickedit&v='; $vbulletin->templatecache['SHOWTHREAD'] = str_replace($search, $replace, $vbulletin->templatecache['SHOWTHREAD']); unset($search, $replace); Code:
if ($_REQUEST['do'] == 'PUT_NAME_HERE') { @ob_start(); ?> Copy here the content of "vbulletin_quick_edit.js" file (without the header) <?php header('Content-type: application/x-javascript'); exit; } --------------- Added [DATE]1313791148[/DATE] at [TIME]1313791148[/TIME] --------------- By the way, I found a nice website that helps to reformat code online: http://jsbeautifier.org/ --------------- Added [DATE]1313793365[/DATE] at [TIME]1313793365[/TIME] --------------- I've tried to put this code inside the display_editor function but it kills the quickedit function to transfer me to advanced editor : Code:
var div = C.responseXML.getElementById("addon_js"); div.innerHTML = innerHTML; var x = div.getElementsByTagName("script"); for(var i=0;i<x.length;i++) { eval(x[i].text);} --------------- Added [DATE]1313795897[/DATE] at [TIME]1313795897[/TIME] --------------- This function looks nice, i've tried to edit it, but fail to every time If someone got an idea... |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|