0

On the surface, this question seems easy (and admittedly I am new to javascript so it may be), but here are the details:

The work I do is in Drupal, therefore I work predominately with CSS and Drupal's interface. However, for the current function I am doing, I need to use Javascript to add an overlay onto an existing Google map. I have already written the javascript, and the map is working, but the location of my javascript is inside the javascript of the module I am using to make the map. If I keep it there, then once the module updates, my work will be overridden by the new javascript. Therefore, what I need to do is add my functionality inside a new javascript file saved elsewhere that can effect the javascript inside the map module without having to write anything into the map module. I have seen plenty on this that requires a call to be placed in the original js file, but that won't work, as it will be overridden on the next update.

2
  • Create a block in Drupal and add it in that. It's the simplest solution Commented Apr 7, 2014 at 18:03
  • Can this be done through views? Currently I have the map on a page created through views. Commented Apr 7, 2014 at 18:12

1 Answer 1

1

You can easily add JS for specific view...

function yourtheme_preprocess_views_view(&$vars) {
    $view = $vars['view'];
    // Make sure it's the correct view
    if ($view->name == 'your-view-name') {
        // add needed javascript
        drupal_add_js(drupal_get_path('theme', 'your-theme') . '/your-js.js');
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.