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

Reply
 
Thread Tools Display Modes
  #1  
Old 12-06-2006, 07:49 PM
JPnyc JPnyc is offline
 
Join Date: May 2005
Posts: 60
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Can Javascript be run from the plugin system?

I did search on this but got no hits. Can javascript be run from the plugin system, or just php? I have a script that I want run onload of the showthread template. The onload event handler is contained within the script. I tried it on various showthread hooks, but no dice. I know the script works, since I've placed it into the showthread template to test, and it works.
Reply With Quote
  #2  
Old 12-07-2006, 12:52 AM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Not to my knowledge, no. AFAIK, Plugins can only be used to execute PHP Code.
Reply With Quote
  #3  
Old 12-07-2006, 01:02 AM
Guest190829
Guest
 
Posts: n/a
Default

Yes, you can add html and javascript to the headinclude variable before the template is called.
Reply With Quote
  #4  
Old 12-07-2006, 03:41 AM
JPnyc JPnyc is offline
 
Join Date: May 2005
Posts: 60
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ah so the <script> tags should be included? What if I want the script to run from the body instead of the head of the doc? It's only needed on the showthread template, so to put it into the headinclude seems overkill. Also, for some reason, when included in the head, the script doesn't work, when moved to the body, it does. Obviously some conflict with some other script in the head.
Reply With Quote
  #5  
Old 12-07-2006, 04:18 AM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You can just code the plugin to only add it to headinclude if showthread is being called (allthough that won't fix your second problem of it not working).
Reply With Quote
  #6  
Old 12-07-2006, 01:14 PM
JPnyc JPnyc is offline
 
Join Date: May 2005
Posts: 60
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Right, for some reason it only functions when outside the head of the doc. I might have to hardcode it into the template as I've been doing. The plugin system is a tremendous step forward for companies like ours who run 30 forums in vb format. When we go to upgrade, being able to just upload all the customizations rather than adding them by hand, is just a godsend.
Reply With Quote
  #7  
Old 11-29-2007, 11:08 AM
JPnyc JPnyc is offline
 
Join Date: May 2005
Posts: 60
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry for reviving an old thread, but it was mine to begin with so I hope no one minds, and the subject is still the same. I need to execute some Javascript from the plugin system and not sure how to go about it. Can I use PHP to spit out or execute the JS? If so, would echo or eval be used? Can I just put a javascript directly into the plugin system and have it execute on a hook? Thanks
Reply With Quote
  #8  
Old 11-29-2007, 11:33 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Plugins are executing PHP and are executed server-side.

JavaScript is embeded in them HTML page, and is executed on the client-side. You can put JS in your templates, use echo (echo is not advised in plugins) or assign your JS code to a variable in a plugin and include that variable in a template. You can however never execute JS in a plugin as JS does not execute on the server-side.
Reply With Quote
  #9  
Old 11-29-2007, 12:11 PM
JPnyc JPnyc is offline
 
Join Date: May 2005
Posts: 60
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

okay thanks, but I could use PHP in a plug-in to write a JavaScript function to the page, on a given hook, could I not? I mean passing it through PHP as a string literal.

We run 30 forums, and I'm looking for a way to have these alterations be part of the plug-in system, so that I can just upload an XML file rather than making manual changes to templates on 30 forums. Thanks
Reply With Quote
  #10  
Old 11-29-2007, 12:33 PM
RedTyger's Avatar
RedTyger RedTyger is offline
 
Join Date: Nov 2006
Location: UK
Posts: 1,310
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The attached product should do what you want. When installed, the source code of showthread looks like this, changes highlighted in bold:

Code:
<script type="text/javascript" src="clientscript/vbulletin_global.js?v=367"></script>
<script type="text/javascript" src="clientscript/vbulletin_menu.js?v=367"></script>

<!-- END TEMPLATE: headinclude --><script type="text/javascript" src="clientscript/yourscript.js"></script>

and

Code:
<body onload="do_js();">

You'll have to edit the product to change what javascript is added, of course. Make sure the semicolon at the end of the onload bit is left, sometimes other onload javascript is included too, apparently.
Attached Files
File Type: xml jpnyc_js.xml (671 Bytes, 13 views)
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 08:10 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04832 seconds
  • Memory Usage 2,269KB
  • Queries Executed 12 (?)
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
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (1)postbit_attachment
  • (9)postbit_onlinestatus
  • (10)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
  • postbit_attachment
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete