drupal_add_js() is the function used for adding JavaScript to a Drupal page.
0
votes
1answer
21 views
How to parse PHP variables in drupal_add_js in template.php
I'm using drupal_add_js for some inline jQuery - I need to parse some php variables in the inline jQuery, what is the correct way to do it?
drupal_add_js('jQuery(document).ready(function () { ...
0
votes
0answers
16 views
Drupal behaviors not behaving as expected
I created a custom block which also loads some JS to handle some dynamic link creation. It was working perfectly last week and when I came back to it this week it stopped working.
function ...
0
votes
2answers
33 views
Two JS files attached to one module
Alright, so I have two files which should be added to a module. This is the way I do it:
$form['display']['#attached'] = array(
'js' => array(
array('data' => ...
0
votes
1answer
25 views
Add js file in .info theme file. And set it to load first
I added this line in my-theme.info
scripts[] = js/my-file.js
The files is loads but in last place. I need it to be loaded before all modules js files.
How can I set the weight?
I also tried ...
0
votes
0answers
29 views
Having trouble selecting elements in jQuery with JS added on the form
I have a form with a file element and a button. When I click the button it is supposed to run some JS. I have tried three separate ways to get this to work but each way gives me a different result.
...
0
votes
0answers
20 views
Does drupal_add_js and drupal_add_css validate external files
Should I validate the existence of an external js or css with drupal_http_request before I add with with drupal_add_css or drupal_add_js, if no can somebody point me in the right direction where is ...
0
votes
2answers
45 views
How to remove JS from a page during preprocess D7
I'm trying to remove few JS files from one page, which will be called in an Iframe (so no TEMPLATE_js_alter possible because of the if condition).
This code below unset the JS but they are still ...
0
votes
1answer
26 views
Javascript variable value in page source for seo from Drupal.settings
Declared a variable in settings.php
$conf['my-variable'] ="my-variable-value";
Added inline javascript
drupal_add_js("array('my-variable'=>variable_get('my-variable'))");
Need to print ...
0
votes
4answers
65 views
Pass php variable to javascript
I'm trying to pass variable to my js file. The file is located in my theme /js directory. The filename is backgroundConfig and this is the content of file:
(function($, Drupal){
...
0
votes
2answers
57 views
Using drupal_add_js with google maps
I want to pass down an array to my javascript. So that i could create markers on google map.
By doing this:
...
-1
votes
1answer
31 views
Include a Adobe Flash File Format (.swf) in Drupal 7 Custom Module
I had included java script and css files in Drupal 7 custom module using drupal_add_js and drupal_add_css. I was wondering how can I include a file with extension (.swf). Does anyone know this?
1
vote
2answers
34 views
Call a function in JS file from drupal
I have included a javascript in the module "myid" I've been developing in drupal by using this code:
function myid_init() {
drupal_add_js(drupal_get_path("module", "myid") . "js/myid.js");
}
...
0
votes
1answer
28 views
add jquery to drupal website
I want to add 2 jquery scripts to my website that have to be executed on every page.
Smoothstate
<script src="jquery.smoothState.js"></script>
<script ...
0
votes
1answer
41 views
Javascript added via drupal_add_js() does not get aggregated
I have a couple custom modules that I add javascript via drupal_add_js(). I have all the Bandwidth Optimizations options checked in the performance page (/admin/config/development/performance).
Since ...
0
votes
0answers
22 views
custom module css not add
function doLookup($baseRootDir) {
if (variable_get('xmldata')) {
$xmldata = variable_get('xmldata');
} else {
$xmldata = '';
}
$rootDir = realpath($baseRootDir . DIRECTORY_SEPARATOR . ...
0
votes
1answer
61 views
how to add validation on next button usign fieldgroup module
I am creating multiple page registration form using field group module
I wanna add validation on next and previous buttons.
If first page's field is empty user cannot go to next page they show ...
1
vote
1answer
26 views
D7 - Syntax of js custom file added directly to theme
Alright, so I've read the documentation of JS framework in Drupal and there is a simple example how the syntax of JS file should look:
Drupal.behaviors.myModuleBehavior = {
attach: function ...
0
votes
2answers
168 views
How can I add “x-tmpl” script tags to the page for use by Backbone/Mustache?
I'm building a D7 site that uses Backbone to parse JSON data (from Views JSON), and then feeds it to a series of Mustache templates for rendering with Javascript.
I want to keep the Mustache ...
0
votes
4answers
440 views
How to include custom JS file in any module in drupal 7?
I want to include custom JS file in a module.
function profile2_form_user_register_form_alter(&$form, &$form_state) {
...
0
votes
0answers
88 views
Drupal_add_css drupal_add_js not working dynamically
I am working on a drupal-7 project that have many CSS/JS files that need to be added dynamically.
This is the code which i am using in mymodule_init()
function doLookup($baseRootDir)
{
if ...
0
votes
2answers
36 views
can't remove js from page
I've looked at this post http://stackoverflow.com/questions/9578013/how-to-unset-a-js-file-from-a-drupal6-installation-doesn%C2%B4t-work-with-remove-sc and this one How to unset javascripts in Drupal?
...
0
votes
0answers
20 views
All my Js are called in the body, how can I fix that situation?
I a have a drupal 6 website to fix. All the scripts are called in the body, even with the scope value set to "header" or "footer" in the drupal_add_js function.
It's a problem because some script are ...
0
votes
0answers
61 views
Attach js to custom select element
I create custom select element using hook_element_info. I tried attach some js that should control this select, but seems '#attached' property doesn't work. Here my process callback:
/**
* Process ...
0
votes
2answers
78 views
Attach js file to every page w/term reference widget in Drupal 8
I have begun trying to port a small, simple module that I maintain to Drupal 8.
It was originally written (not by me) in Drupal 6 and used hook_init() in combination with drupal_add_js() to attach ...
0
votes
0answers
82 views
drupal_add_js is removing jQuery
I have the following in my module.
drupal_add_js(
drupal_get_path('module', 'responsive_videos') . '/js/fluidvids.js',
array(
'type' => 'file',
'scope' => 'footer',
...
0
votes
0answers
53 views
drupal_add_js in input filter
I have a module that provides an input filter for Drupal 6 and 7. It renders some elements using a (heavy) JavaScript module that I don't want to include on every page.
In Drupal 6 the input filter ...
0
votes
0answers
65 views
Page specific js despite loading pages with ajax
I am currently building a small site which loads menus and content using ajax (which works), however I can't find a way to add additional scripts to specific pages.
Usually I would add the js.script ...
0
votes
1answer
305 views
drupal_add_js not work in form validation failed
I add js file with drupal_add_js in hook_form_alter, it is ok and I see it in list of js loaded in page, but when I submit form and form not validate and return to that form (after validation failed) ...
1
vote
1answer
60 views
Passing an object to settings using drupal_add_js
I'm working on a module that will generate a graph using Google's chart api. The data used to generate the chart uses date objects because I'm graphing race times, like this
[
['Number', ...
0
votes
1answer
136 views
drupal_add_js and variables into anonymous functions, objects undefined?
Pulling my hair out. Read a lot of stuff about scopechain and closure to tackle this one myself. And as i understand at some level, i can't get this to work.
I wrote a module for likebuttons (like ...
0
votes
0answers
31 views
Not able to pass PHP variable to JS file [duplicate]
Javascript works fine, but i need to get my_var variable from module. At the moment its not working.
Clear my page cache and browser cache several times.
The variable 'my_var' is showing value on ...
1
vote
3answers
456 views
How to pass PHP variable to javascript in Drupal 7
Javascript works fine, but i need to get my_var variable from module. At the moment its not working.
Clear my page cache and browser cache several times.
The variable 'my_var' is showing value on ...
0
votes
0answers
63 views
How can I trigger a call to a custom module function before the browser unload event?
I have built a report for an client account that shows payments and charges with totals. I am now adding an export button using the PHPExport module.
As I already built the data to display in the ...
0
votes
2answers
378 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
41 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 ...
3
votes
2answers
845 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
380 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
153 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
105 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
108 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
vote
1answer
2k views
1
vote
1answer
378 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 ...
6
votes
5answers
2k 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
194 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
413 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
524 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
373 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 ...
6
votes
1answer
350 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
515 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
64 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 ...