Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Path to drupal module from inside of javascript

Is there a way to get the drupal(7) module path from which the .js was loaded?
I know that JS is a front-end language, but possibly Drupal passes that info in the Drupal object somehow?

Basicly I want to do something like this:

$('#selectable_html').load("selectable_html.html");  

But since Drupal constructs pages on the fly this request transforms to "http://___/node/add/selectable_html.html", which is obviously wrong.

like image 601
NoRiM Avatar asked Feb 23 '23 10:02

NoRiM


1 Answers

You can pass things to Javascript via Drupal using drupal_add_js using the 'setting' option.

Add settings ('setting'): Adds settings to Drupal's global storage of JavaScript settings. Per-page settings are required by some modules to function properly.

drupal_add_js(array('myModule' => array('key' => 'value')), 'setting');

You could then pass the path returned from drupal_get_path('module', 'name') and access it in Javascript using Drupal.setting.

All settings will be accessible at Drupal.settings.

like image 131
Bart Avatar answered Feb 26 '23 01:02

Bart