vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   CYB Chatbox external javascript (https://vborg.vbsupport.ru/showthread.php?t=269132)

Frosty 08-25-2011 10:21 AM

CYB Chatbox external javascript
 
Hey everyone,
Is there any way we can put the javascript of the CYB Chatbox in a file? It would surely decrease the page load, and source of the page wouldn't be so messy either.

I tried to do it myself, but it wouldn't load the Chatbox, I assume it's because it loads it like a normal js file, and variables probably can't work.

Any ideas? Thanks...

kh99 08-25-2011 12:05 PM

I'm not a js expert, but I think you should just be able to put the code in a file and put a <script> tag in the html. Did you put <script...> in the same place you took out the code?

Frosty 08-25-2011 12:40 PM

Yeah, of course. But the problem is that js has variables, and when you put it in a file and go directly to it, variables won't work - obviously!

It works if it isn't external. :/

kh99 08-25-2011 01:41 PM

Oh, you mean that it has template conditionals and PHP variables (javascript also has it's own variables, so I didn't understand what you were getting at).

What you can do is find all the PHP variables it uses, then put them in a template that outputs js code that simply sets a js variable to that value. Then change the js code (that you're trying to move to a file) to use the js variables, and change the template conditionals to js 'if' statements.

Another way would be to set the src of the scirpt tag to a php file that renders the template and returns the js. But that way you wouldn't be able to allow the browser to cache the output which I guess is the point of doing this.

Edit: The headinclude template already has a section that sets js variables, it looks like this:

Code:

<script type="text/javascript">
<!--
var SESSIONURL = "$session[sessionurl_js]";
var SECURITYTOKEN = "$bbuserinfo[securitytoken]";
var IMGDIR_MISC = "$stylevar[imgdir_misc]";
var vb_disable_ajax = parseInt("$vboptions[disable_ajax]", 10);
// -->
</script>


You could add yours there, but you'd probably want to have some sort of template conditional around it so you weren't putting it in every page (like maybe <if condition="THIS_SCRIPT == 'misc'">)


All times are GMT. The time now is 02:31 AM.

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.00996 seconds
  • Memory Usage 1,711KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete