[英]How can I add functionality to one javascript program using another without altering the first js file
On the surface, this question seems easy (and admittedly I am new to javascript so it may be), but here are the details: 从表面上看,这个问题似乎很简单(诚然,我是javascript的新手,所以可能是),但是这里是细节:
The work I do is in Drupal, therefore I work predominately with CSS and Drupal's interface. 我所做的工作是在Drupal中进行的,因此我主要使用CSS和Drupal的界面进行工作。 However, for the current function I am doing, I need to use Javascript to add an overlay onto an existing Google map.
但是,对于我正在执行的当前功能,我需要使用Javascript将叠加层添加到现有的Google地图上。 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.
我已经编写了JavaScript,并且地图可以工作,但是我的JavaScript的位置在我用来制作地图的模块的javascript中。 If I keep it there, then once the module updates, my work will be overridden by the new javascript.
如果我将其保留在该模块中,则一旦模块更新,我的工作将被新的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.
因此,我需要做的是将功能添加到保存在其他位置的新javascript文件中,这可以影响map模块内部的javascript,而无需在map模块中写入任何内容。 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.
我已经看到了很多有关此问题的信息,它要求在原始js文件中放置一个调用,但这将无法正常工作,因为它将在下一次更新中被覆盖。
You can easily add JS for specific view... 您可以轻松地为特定视图添加JS ...
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');
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.