2011-11-01 44 views
1

我想在Drupal CMS模块中测试jqScheduler for PHP。在drupal中添加javascript

当$ eventcal-> render();函数在Drupal模块中调用,以下代码在页面开始之外的<html>部分之前生成。

<style type=text/css>/* 
    Document : calendar 
. 
. 
. 
<script type='text/javascript'>jQuery(document).ready(function() {jQuery.datepicker... 
<html xmlns="http://www.w3.org/1999/xhtml" lang="fa" xml:lang="fa"> 

<head> 

有没有办法拦截上面的代码,以便我可以将它们放在我需要它们的地方。

例子:

$output = "<script type='text/javascript'>jQuery(document).ready(function() .... </script>"; 

我添加CSS & JA文件添加此类似代码

 function study_jqScheduler() { 
      drupal_add_css('sites/all/libraries/jqgrid/themes/redmond/jquery-ui-1.8.16.custom.css'); 
     drupal_add_css('sites/all/libraries/jqgrid/themes/jquery.ui.tooltip.css'); 
     drupal_add_css('sites/all/libraries/jqgrid/themes/ui.jqscheduler.css'); 
drupal_add_js('sites/all/libraries/jqgrid/js/jquery-ui-custom.min.js'); 
drupal_add_js('sites/all/libraries/jqgrid/js/jquery.js'); 
drupal_add_js('sites/all/libraries/jqgrid/js/jquery.jqScheduler.min.js'); 
require_once "sites/all/libraries/jqgrid/php/jqUtils.php"; 
require_once "sites/all/libraries/jqgrid/php/jqScheduler.php"; 
require_once "sites/all/libraries/jqgrid/php/jqGridPdo.php"; 
require_once "sites/all/libraries/jqgrid/jq-config.php"; 
    global $base_path; 
    $base_path1=drupal_get_path('module', 'study'); 
    // Set the url from where we obtain the data 
ini_set("display_errors",1); 
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); 
$conn->query("SET NAMES utf8"); 
$eventcal = new jqScheduler($conn); 
$eventcal->setLocale('en_GB'); 
$eventcal->setUrl($base_path.$base_path1.'/eventcal.php'); 
$eventcal->setUser(1); 
$eventcal->setUserNames(array('1'=>"Calender User 1",'2'=>"Calendar user 2",'3'=>"Calendar user 3")); 
$eventcal->multiple_cal = true; 
$output.= $eventcal->render(); 
    return $output; 
} 

回答

1

你需要从你的页面的回调函数返回$eventcal->render();,然后将它添加到内容区域像平常一样。

function mymodule_page_callback() { 
    drupal_add_js('...'); 
    drupal_add_css('...'); 

    return $eventcal->render(); 
} 

希望帮助时,请确保您接受的答案,以前的问题,如果他们已经帮你(见this post for details of how to do this)。如果你已经表明你很欣赏他们花在帮助你的时间,那么人们将会更加倾向于帮助...你可以通过接受这些答案来做到这一点:-)

+0

我正在使用return但不起作用 –

+0

好吧,我得到它,'render()'直接输出到缓冲区,它不会返回呈现的日历。这很容易解决,但我不愿意告诉你,直到你接受你以前的问题的答案......这是一个社区,所有成员都需要参与该社区:-) – Clive