我正在使用以下 hook_block 开发一个自定义模块:
<?php
function mytwitter_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks['hashtag_search'] = array(
'info' => t('Hashtag Search'),
'cache'=> BLOCK_CACHE_GLOBAL
);
$blocks['eclap_timeline'] = array(
'info' => t('Timeline @UserTwitter')
);
return $blocks;
case 'configure':
case 'save':
return _mytwitter_block_settings_save($delta, $edit);
case 'view':
default:
switch ($delta) {
case 'hashtag_search':
$block['subject'] = t('#Hashtag search');
$block['content'] = ***##i want put here the java script##***
break;
case '_timeline':
$block['subject'] = t('My Twitter user timeline');
$block['content'] = t('andremo ad installare qui la timeline');
}
return $block;
}
}
?>
我想使用以下代码javascript:
var HASHTAG = 'TEATRO'; // don't include the #
var UPDATE_INTERVAL = 1000; // how often to update the hash tag in milliseconds
var MAX_TWEETS = 5; // max number of tweets at a time. make this larger if the topic is popular
var ANIM_SPEED = 500; // speed of animation
var tweets = new Array();
var count = 0;
var tweets_per_call = 0;
var firstID = -1;
(function() {
// call the twitter api on a set interval
setInterval(function() {
$.getJSON("http://search.twitter.com/search.json?q=%23" + HASHTAG + "&result_type=recent&rpp=5&callback=?", {}, function(data) {
tweets_per_call = data.results.length;
firstID = -1;
// for each response, create a visual tweet
$.each(data.results, handleTweets);
});
}, UPDATE_INTERVAL);
})();
// handle the data from twitter
function handleTweets(key, data) {
tweetFound = false;
// see if tweet already exists, if so don't handle it and exit
for (var i = 0; i < tweets.length; i++) {
if (tweets[i].tweet == data.text) {
tweets_per_call--;
return;
}
}
// increase tweet counter
count++;
// if its the first tweet in a request, set it to the current counter
if (firstID == -1) {
firstID = count;
}
// add tweet to array
tweets.push({
id: count,
tweet: data.text
});
// add tweet to page
addTweet(count, data);
// remove the oldest tweet if there are more than
if (tweets.length > MAX_TWEETS) {
$('#' + tweets[0].id).hide(ANIM_SPEED, removeTweet(tweets[0].id));
tweets.shift();
}
}
// add tweet to html
function addTweet(id, data) {
var delayTime = ANIM_SPEED;
// set delay time for each tweet
delayTime = (id - firstID) * ANIM_SPEED;
// use jquery to add html to the page
$('#tweets').prepend("<article id='" + id + "'><table><tr><td><span class='user'>@" + data.from_user + "</span> " + data.text + "</td></tr></table></article>");
// hide the tweet so it can be animated in
$('#' + id).hide(0);
// delay the display of the tweet until the ones in front of it have finished
setTimeout(function() {
$('#' + id).slideDown(ANIM_SPEED);
}, delayTime);
}
// remove a tweet
function removeTweet(id) {
$('#' + id).remove();
}
使用这种样式的 css:
html, body, #tweets
{
overflow: hidden;
font-family: Verdana, Arial, sans-serif;
font-size: 12px;
}
#tweets
{
position: absolute;
width: 900px;
left: 50%;
margin-left: -450px;
top: 20px;
color: #FFF;
}
/* each tweet box */
article
{
width: 300px;
height: 60px;
background-color: #222;
border-radius: 0px;
margin-bottom: 40px;
}
table
{
height: 100%;
width: 100%;
}
td
{
vertical-align: middle;
padding: 0px 20px 0px 20px;
}
/* twitter user name */
.user
{
font-weight: bold;
font-size: 15px;
color: #7e9137;
}
在这种情况下如何使用函数 drupal_add_js?...我必须在 javascript 中更改一些内容..帮助!