drupal_add_js() is the function used for adding JavaScript to a Drupal page.
0
votes
1answer
26 views
Passing Settings from Drupal Module to Javascript: Uncaught TypeError: Cannot read property
In my module I have the following code.
$my_settings = array(
'basePath' => '/',
'my_locs' => $my_locs // Array of numbers
);
drupal_add_js(array('my_module' => $my_settings), ...
0
votes
1answer
18 views
How to desactivate jquery_update logic for the homepage
The objective of this is to remove all legacy javascript files from the homepage except for the new javascript files I specifically want to load.
Here is how I remove all the Javascript files I don't ...
4
votes
2answers
714 views
is it good idea to add js file for every page?
I have some JS and CSS on my site that are very specific to some pages. From a Drupal perspective, it is good idea to add them using drupal_add_js() instead of THEME.info? Does such thing affect ...
0
votes
1answer
89 views
Drupal #attached doesn't work with some themes
I've written a module which loads CSS and JS files using the #attached property. This works fine across most themes, but for some themes the files are not loading.
e.g.:
...
0
votes
1answer
25 views
What should be the path to the file while using #attached in a custom_module_block_view()?
I have created a custom module and was trying to add javascript file to a block using #attached method which was described here. I am confused with the Path/to/file as I have tried to give a full path ...
-1
votes
1answer
56 views
Using Drupal Default jQuery only on node form?
I need to use the jQuery 2.0 in my drupal 7 site, so i have unset two drupal jQuery files and added the latest version of jQuery using this code in my template.php file so it will not affect the views ...
0
votes
1answer
25 views
Push Items to Array using drupal_add_js
I'm using this code in a for loop to push items to an array but it doesn't add to the array, just overwrites it each time I think:
drupal_add_js(array('THINGS' => array('ONE' => array('VAR' ...
-1
votes
1answer
68 views
1
vote
1answer
64 views
How to add_js per content type in my module?
I'm looking for a way for my module to evaluate the content type in a preprocess hook and conditionally add some javascript.
Theme_preprocess_page() makes the content type accessible plus some ...
5
votes
3answers
431 views
Adding JS to a Drupal 8 theme (replacement for drupal_add_js)
In Drupal 7, I can use drupal_add_js within a theme's template.php file as a theme_preprocess_html(&$vars) function:
drupal_add_js(drupal_get_path('theme', 'mytheme') . '/js/scripts.js',
...
0
votes
2answers
25 views
How to use Drupal.behaviors in Drupal 7?
I have these codes in my druapl 7 theme js file (js/test.js):
(function($) {
alert("Hi");
Drupal.behaviors.mythemename = {
attach: function(context, settings) {
alert("Bye");
...
2
votes
2answers
184 views
Adding a jQuery UI widget in the administrative front-end
I have created a form within the administrative front-end in my Drupal 7 site to allow administrators to change some configuration options. I've defined the path to it in the following way (in ...
1
vote
1answer
132 views
Difference between theme.info and drupal_add_js ( jquery-2.0.3 )
On a fairly new drupal (7.23) site I tried including the jquery-2.0.3.js file with the drupal_add_js function in one of my modules hook_init function. All was working good and well when I was testing ...
1
vote
1answer
67 views
Autofill fields on profile form based on previous fields
I have a particularly long user profile form on my client's site. Some of those fields can be autofilled using information already entered (such as spouse last name). The filling out needs to be done ...
5
votes
1answer
124 views
what is the difference between using drupal_add_js and ['#attached']
What is the difference between drupal_add_js() and $form['#attached']['js'][] ?
When is the purpose of using each of the above functions?
(I mean I know that it is used to attached js to say form if ...
0
votes
2answers
108 views
JavaScript supposed to always be called on front page, but doesn't always run
I have some JavaScript that is called on the front page, and is supposed to execute. When I go the page initially, it works fine. Then if I go to another page, then come back, it doesn't show. It ...
0
votes
2answers
37 views
How to load one certain js before all others?
We are struggling around here with SVG in IE8. Amongst other approaches we'ld also like to try the SVG Web Toolkit. In it's quick start guide they say:
To use SVG Web, you must drop a script tag ...
2
votes
1answer
136 views
How to add data to Drupal.settings without drupal_add_js
Is there any way to add some variables to Drupal.settings without drupal_add_js (with setting argument).
I'm creating a site that has a custom ctools popup style but I'm not feeling good with ...
2
votes
1answer
66 views
Including JS files in template.php to control weight/order/group
I'm looking to include a few JS files (some libraries, others are custom modules with dependencies on libraries). Originally I had all JS files added through our .info file, and while I could control ...
0
votes
2answers
122 views
How do I apply cufon.js only for Internet Explorer, in template.php?
I have some font problems in Internet Explorer, so I am trying to apply font-family through JavaScript. It works, but the JavaScript code runs for every browser.
How do I run JavaScript code only on ...
1
vote
1answer
126 views
A lot of core JavaScript files not being included
For some reason a bunch of core JS files are not being loaded. I've had to manually add them in with a module hook_js_alter function like so:
function MYMODULE_js_alter(&$js) {
...
1
vote
0answers
105 views
Autosubmit for exposed filters and .appendTo
I want the combobox to my self send exposed filter, I have no problem there it succeeds to do with .change, the problem is that these combobox need them in another div outside the container exposed ...
0
votes
1answer
79 views
Add js script to register page
Like the title says really, I'm trying to add a script to my register page, I'm using Zen as my theme, and I've added a script into the .info file, and to just test that it works I have added an ...
0
votes
1answer
263 views
drupal_add_js only once
I have a field which is used in a nodeblock, and only appears on a few select pages. This however will vary throughout the lifetime of the website so I've been looking for a way to insert the ...
0
votes
0answers
49 views
Can I use js change form_state value?
I attached a js file in a form, like :
$form['#attached'] = array(
'js' => array(
array('data' => array('test' => array('data' => array())), 'type' => 'setting'),
...
0
votes
2answers
430 views
Adding JavaScript before drupal.js
I am trying to add jQuery to my page (it is not being added by default). The file is adding to the page but after drupal.js causing the error:
SCRIPT5009: 'jQuery' is undefined
drupal.js, line 5 ...
0
votes
2answers
225 views
Drupal javascript file loading and jQuery
I have several javascript files in custom modules containing many functions which are used across the code. In D6 I simply added them during hook_init() and it was fine.
...
0
votes
2answers
159 views
JS Javascript into a single node / page
I have a form that works fine outside of drupal where it called a script ..../default.js However this does not work inside drupal 6 when i copy the code from ym html/php file.
I have seen this line
...
0
votes
2answers
196 views
Does aggregating JS/CSS interfere with my drupal_add_js()?
I want to use drupal_add_js and drupal_add_css on a per-page basis so I have added a 'scripts' text field to my basic content type and have set the Format Type to PHP.
It works beautifully until I ...
0
votes
1answer
240 views
Setting a Drupal.settings JS variable from a form field
i'm working on my first custom module and really fumbling along :). thanks in advance for your advice!
goal
i've added a checkbox to the comment form. if the user leaves it checked, then following ...
0
votes
0answers
43 views
Addng Javascript files
Another question for you guys. Let me first explain that I am adding javascript files the way I think they are supposed to be added, by putting them in my template file using drupal_add_js. However, a ...
2
votes
3answers
2k views
How to get jquery working on Drupal 7 - for Newbies
I have been reading many tutorials online on how to get jquery working on drupal 7.
Although there are many lines of code and examples, what i cannot find is what piece of code to put where (maybe it ...
2
votes
2answers
520 views
drupal_match_path() for multiple wildcard patterns?
I want to add some CSS and JS to multiple matched wildcard URL patterns. According to Add javascript to multiple specific urls, I can use a wildcard using drupal_match_path() and that works well for ...
-1
votes
2answers
111 views
Javascript cost calculator
I used JavaScript to construct my calculator, and I'm wondering how to get it to work.
I've tried drupal_add_js(), but it didn't work. I've tried two different modules that incorporate JavaScript, ...
0
votes
1answer
1k views
Having trouble adding a custom js file to my Drupal 7 site
I added a javascript file to my site in the theme's .info file
scripts[] = js/myjs.js
The js file loads and I can see that it's included in the head when I load the site, however the jQuery ...
2
votes
1answer
777 views
drupal_add_js() won't work with footer scope
i 'm trying to add a file to end of body via template.php in mytheme_preprocess_page.
this is the line i have:
drupal_add_js(drupal_get_path('theme', 'mytheme') . '/js/file.js',array('type' => ...
0
votes
0answers
32 views
Calculations in a custom content type that display in saved content
Drupal 6.28, custom content type. I need to have users select numbers (possibly with attached text, e.g., 3 - meets expectations, 3.5 - exceeds some expectations) from two or three select lists (how ...
0
votes
1answer
200 views
JS Resize function for div containing a a slideview slideshow and set as a page background
This is for a drpal 7 install.
Is there a way to apply the same function they discuss in this thread
...
1
vote
0answers
118 views
drupal_add_js setting does not work in admin overlay
I do a form alter for the node edit form (hook_field_widget_form()). Within this alteration I add some settings to the Drupal.settings object with:
$settings = array(
'custom_api' => array(
...
1
vote
1answer
116 views
Generate js variable before javascript loaded
I have a block with invocation code inside(it invokes js code from OpenX ads server), my site is responsive and this block get cloned(with jquery .clone() function) on ipad or iphone version of the ...
1
vote
3answers
529 views
Add Google Analytics JS file to every page
We use Google Analytics on each of our sites for our own reporting. We have implemented GA using the Google Analytics module, and everything works as expected.
However, I'm also part of a large ...
0
votes
2answers
755 views
overlay does not work after enabling my custom module
I am using latest Drupal 7.
I just noticed my admin overlay is not working.
First I thought its due to Jquery Update contrib module installation however that not it.
Its apparently due to my ...
3
votes
0answers
2k views
TypeError: jQuery(“#mycarousel”).jcarousel is not a function [closed]
I added this jQuery function to my drupal7 header for jcorousel plugin.
<script type="text/javascript">
jQuery.noConflict();
(function($) {
$(document).ready(function() {
...
0
votes
0answers
235 views
drupal_add_js() includes JS with wrong weigth
A module I am using on my site uses the drupal_add_js() function to include some JavaScript. Although the function is used correctly the JavaScript file is included before the jQuery script which ...
3
votes
1answer
169 views
Is there advantage to using Drupal.settings, as opposed to directly passing json-encoded var to javascript function
Inside my custom views template, views-view-myview.tpl.php, I have a variable ("$myvar"), which I need to pass to a custom javascript function. Here is how I am currently doing it:
A. json-encode ...
1
vote
0answers
940 views
How to use an external jQuery plugin with Drupal's no-conflict jQuery
I'm using drupal_add_js() to load some external js:
drupal_add_js('http://jquery-accordion.googlecode.com/svn/trunk/jquery.accordion.js', 'external');
This produces 'TypeError: $ is not a function' ...
1
vote
1answer
95 views
Why won't JS fire on ubercart checkout page and how do I fix?
I need some custom JS (jQuery to be precise) to run on ubercart's /cart/checkout page. I turned off JS optimization and tried adding it to several different files that are already loading and the JS ...
1
vote
1answer
2k views
Adding jQuery to Drupal 7 site: drupal_add_js() adds but doesn't call?
I'm using jQuery accordion effects to display some information. I include the libraries:
drupal_add_js('http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js', file);
...
3
votes
3answers
543 views
Conditional drupal_add_css and _js are adding code to every page
I am trying to add a CSS and JS files when a certain content type is being viewed (Drupal 6). The problem is that the code is being added to every page.
I have tried this first, included in ...
1
vote
1answer
754 views
How is JavaScript included in Drupal 7?
My site is built on Drupal 7, and a number of my .js scripts are throwing this exception: Uncaught TypeError: Property '$' of object [object Window] is not a function. After some research, I think ...