0
我無法在Drupal模塊頁面上獲取並運行visualsearch.js控件。我使用的是與demo.html腳本塊完全相同的javascript(可以在下載zip包中找到它或通過查看其站點演示的源代碼),我將它複製並粘貼到單獨的JavaScript文件中。我還在Drupal模塊中加載了所有css和javascript依賴項,遵循demo.html中定義的順序。Drupal模塊中的Visualsearch.js頁面
Drupal的代碼
<?php
function mymodule_menu() {
$items = array();
$items['mymodule'] = array(
'title' => 'MyModule',
'page callback' => 'mymodule_main',
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM
);
return $items;
}
function mymodule_main() {
drupal_add_css(absolute paths of all css dependencies);
drupal_add_js(absolute paths of all javascript dependencies (in order), followed by the standalone javascript file that contains the code extracted from the demo.html script block);
return "
<div id=\"VS\" class=\"container\">
<div id=\"searchbox\"></div>
<div id=\"feedback\"></div>
</div>";
}
我在一個純HTML/JavaScript環境運行此完全相同的設置,一切工作正常。也就是說,我製作了一個加載依賴關係的html頁面,幷包含如上所示的html。然後,我有一個單獨的腳本,其中包含從demo.html腳本塊中提取的代碼。