Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Old January 9th, 2013, 06:43 AM
VincentasG VincentasG is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 34 VincentasG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 42 m 5 sec
Reputation Power: 1
Drupal 7 global javascript variables

Hi everyone,

In my Drupal 7 installation, I have 2 separate JavaScript files that are loaded by my sub-themes (base and admin sub-theme) - I don't know if this is useful information or not, but:
What if I want to define a JavaScript variable in the first js file that is loaded and use it in the second one? How should I define it?
Basically, the question could be: How to define global JavaScript variables in a Drupal environment?

I am using jQuery.

Reply With Quote
Old January 9th, 2013, 01:03 PM
IAmALlama IAmALlama is offline
Me
Click here for more information
 
Join Date: Apr 2007
Location: San Diego, CA
Posts: 2,267 IAmALlama User rank is Lance Corporal (50 - 100 Reputation Level)IAmALlama User rank is Lance Corporal (50 - 100 Reputation Level)IAmALlama User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 6 h 30 m 38 sec
Reputation Power: 9
javascript variables are global by default. doesn't matter if it is an included file or inline script tag. variables defined globally are available globally. For example, in jquery "$" is a variable defined as a function that is usually an included js file. The "$" function should be available anywhere in your scripts after jquery has loaded.

Reply With Quote
Old January 10th, 2013, 01:40 AM
Trenton9claude Trenton9claude is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 Trenton9claude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 20 sec
Reputation Power: 0
How to define global JavaScript variables in a Drupal environment?





Reply With Quote
Old January 10th, 2013, 01:37 PM
IAmALlama IAmALlama is offline
Me
Click here for more information
 
Join Date: Apr 2007
Location: San Diego, CA
Posts: 2,267 IAmALlama User rank is Lance Corporal (50 - 100 Reputation Level)IAmALlama User rank is Lance Corporal (50 - 100 Reputation Level)IAmALlama User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 6 h 30 m 38 sec
Reputation Power: 9
drupal is not special. Its just like any other javascript variable.

Code:
<script type="text/javascript">
var test = "hello world";
</script>

For a variable to be available inside an included file, it would just have to be defined before the file is included. variables defined in one file are available in later files in the order they appear in the source.

Reply With Quote
Old January 11th, 2013, 01:29 AM
VincentasG VincentasG is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 34 VincentasG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 42 m 5 sec
Reputation Power: 1
Thanks for answer ;)

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > Drupal 7 global javascript variables


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap