Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 18 Aug 2011, 23:10
cclaerhout's Avatar
cclaerhout cclaerhout is offline
 
Join Date: Aug 2004
Real name: CÚdric Claerhout
Question [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.
  • That Editor is vB_Editor_QE_x; where x is the number of times I press "Edit" button (on the showthread page) to open the quick_editor. That number will be increment until I reload the showthread page.
  • That Editor used bbcodes with buttons. Some of this buttons have customised javascript.
    Exemple:
    • Button Template

      Block Disabled:      (Update License Status)  
      Suspended or Unlicensed Members Cannot View Code.

    • Javascript (in template)

      Block Disabled:      (Update License Status)  
      Suspended or Unlicensed Members Cannot View Code.

  • I fetch my two templates to 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 ?
P.S: I'm coding for hobby, it takes me hours to do what people here might do in 5 minutes.
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).
__________________
Reply With Quote
  #2  
Old 18 Aug 2011, 23:56
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
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).
Reply With Quote
  #3  
Old 19 Aug 2011, 02:51
cclaerhout's Avatar
cclaerhout cclaerhout is offline
 
Join Date: Aug 2004
Real name: CÚdric Claerhout
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 ?
__________________
Reply With Quote
  #4  
Old 19 Aug 2011, 03:01
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
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.
Reply With Quote
  #5  
Old 19 Aug 2011, 03:25
cclaerhout's Avatar
cclaerhout cclaerhout is offline
 
Join Date: Aug 2004
Real name: CÚdric Claerhout
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.
__________________
Reply With Quote
  #6  
Old 19 Aug 2011, 03:38
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
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.
Reply With Quote
  #7  
Old 19 Aug 2011, 04:16
cclaerhout's Avatar
cclaerhout cclaerhout is offline
 
Join Date: Aug 2004
Real name: CÚdric Claerhout
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.
Attached Images
File Type: gif schema.gif (69.1 KB, 49 views)
__________________
Reply With Quote
  #8  
Old 19 Aug 2011, 12:07
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
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:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


(it helps if you have a program that can reformat the .js file).
Reply With Quote
  #9  
Old 19 Aug 2011, 17:51
cclaerhout's Avatar
cclaerhout cclaerhout is offline
 
Join Date: Aug 2004
Real name: CÚdric Claerhout
I saw a product that uses "misc_start" hook to execute js:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

It might be a way to do this...

--------------- Added 19 Aug 2011 at 22:53 ---------------

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.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Then it uses the hook misc_start

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Now my problem is to know what code I have to use to EVAL() my javascript.

--------------- Added 19 Aug 2011 at 22:59 ---------------

By the way, I found a nice website that helps to reformat code online:
http://jsbeautifier.org/

--------------- Added 19 Aug 2011 at 23:36 ---------------

I've tried to put this code inside the display_editor function but it kills the quickedit function to transfer me to advanced editor :

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

P.S: addon_js is the id of the div containing my Javascript.

--------------- Added 20 Aug 2011 at 00:18 ---------------

This function looks nice, i've tried to edit it, but fail to every time

If someone got an idea...
__________________

Last edited by cclaerhout; 19 Aug 2011 at 22:57.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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


New To Site? Need Help?

All times are GMT. The time now is 09:06.

Layout Options | Width: Wide Color: