如何实现CSS+;Drupal站点上特定页面上的JavaScript脚本?

如何实现CSS+;Drupal站点上特定页面上的JavaScript脚本?,javascript,html,css,drupal,integration,Javascript,Html,Css,Drupal,Integration,在过去的几天里,我在这里问了很多问题,试图修补我正在构建的模板的不同区域。我只是想做一些有用的东西,这样就可以很容易地进入并更改我稍后将创建的几个页面的所有内容(从美学角度看,这会更好,这只是让所有功能都发挥作用) 不过,我遇到了一个问题。我们使用Drupal作为我们的内容管理系统(不是我们的决定,而是我们的上级交给我们的)。主要的问题是,由于它被分发给了几个部门,我们无法控制其中的大部分。把它放在一起的人是管理员,我们只是“用户” 下面的代码可以正常工作,我花了很少的时间就可以很好地工作 &l

在过去的几天里,我在这里问了很多问题,试图修补我正在构建的模板的不同区域。我只是想做一些有用的东西,这样就可以很容易地进入并更改我稍后将创建的几个页面的所有内容(从美学角度看,这会更好,这只是让所有功能都发挥作用)

不过,我遇到了一个问题。我们使用Drupal作为我们的内容管理系统(不是我们的决定,而是我们的上级交给我们的)。主要的问题是,由于它被分发给了几个部门,我们无法控制其中的大部分。把它放在一起的人是管理员,我们只是“用户”

下面的代码可以正常工作,我花了很少的时间就可以很好地工作

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Text/Photo Swap Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function defaultText(){
    document.getElementById('textarea2').innerHTML = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi pulvinar lectus non lectus auctor egestas. Donec at nunc neque. Morbi ornare condimentum lobortis. Nam vehicula urna ac mauris pharetra rutrum. Duis et arcu eget sapien interdum porttitor ut et tortor. Maecenas ultricies dignissim pretium. Integer quis enim metus. Sed enim lacus, eleifend eu euismod volutpat, blandit eu sem. Vestibulum varius purus ut est accumsan pellentesque. Donec quis enim id lectus sollicitudin suscipit at volutpat augue. Curabitur et metus purus. Fusce luctus nunc vitae sapien pharetra id accumsan lectus malesuada.';
}
    function dogText(){
    document.getElementById('textarea2').innerHTML = 'The domestic dog (Canis lupus familiaris), is a subspecies of the gray wolf (Canis lupus), a member of the Canidae family of the mammilian order Carnivora. The term domestic dog is generally used for both domesticated and feral varieties. The dog may have been the first animal to be domesticated, and has been the most widely kept working, hunting, and companion animal in human history. The word dog may also mean the male of a canine species, as opposed to the word bitch for the female of the species.';
}function catText(){
    document.getElementById('textarea2').innerHTML = 'The domestic cat (Felis catus or Felis silvestris catus) is a small, usually furry, domesticated, carnivorous mammal. It is often called the housecat when kept as an indoor pet, or simply the cat when there is no need to distinguish it from other felids and felines. Cats are valued by humans for companionship and ability to hunt vermin and household pests. They are primarily nocturnal.';
}
function parrotText(){
    document.getElementById('textarea2').innerHTML = 'Parrots, also known as psittacines are birds of the roughly 372 species in 86 genera that make up the order Psittaciformes, found in most tropical and subtropical regions. The order is subdivided into three superfamilies: the Psittacoidea  parrots), the Cacatuoidea (cockatoos) and the Strigopoidea (New Zealand parrots). Parrots have a generally pantropical distribution with several species inhabiting temperate regions in the Southern Hemisphere as well. The greatest diversity of parrots is found in South America and Australasia.';
}
function lizardText(){
    document.getElementById('textarea2').innerHTML = 'Lizards are a widespread group of squamate reptiles, with more than 5600 species , ranging across all continents except Antarctica as well as most oceanic island chains. The group, traditionally recognized as the suborder Lacertilia, is defined as all extant members of the Lepidosauria (reptiles with overlapping scales), which are neither sphenodonts (i.e., tuatara) nor snakes ? they form an evolutionary grade. While the snakes are recognized as falling phylogenetically within the Toxicofera clade from which they evolved, the Sphenodonts are the sister group to the Squamates, the larger monophyletic group, which includes both the lizards and the snakes.';
}
function horseText(){
    document.getElementById('textarea2').innerHTML = 'The horse (Equus ferus caballus) is one of two extant subspecies of Equus ferus, or the wild horse. It is an odd-toed ungulate mammal belonging to the taxonomic family Equidae. The horse has evolved over the past 45 to 55 million years from a small multi-toed creature into the large, single-toed animal of today. Humans began to domesticate horses around 4000 BC, and their domestication is believed to have been widespread by 3000 BC. Horses in the subspecies caballus are domesticated, although some domesticated populations live in the wild as feral horses. These feral populations are not true wild horses, as this term is used to describe horses that have never been domesticated, such as the endangered Przewalski Horse, a separate subspecies, and the only remaining true wild horse. There is an extensive, specialized vocabulary used to describe equine-related concepts, covering everything from anatomy to life stages, size, colors, markings, breeds, locomotion, and behavior.';
}
function chickenText(){
    document.getElementById('textarea2').innerHTML = 'The chicken (Gallus gallus domesticus) is a domesticated fowl, a subspecies of the Red Junglefowl. As one of the most common and widespread domestic animals, and with a population of more than 24 billion in 2003, there are more chickens in the world than any other species of bird. Humans keep chickens primarily as a source of food, consuming both their meat and their eggs.';
}


//The switchImg function is what swaps out the awesome.png picture when thumbnails are clicked.
function switchImg(i){
document.images["awesome"].src = i;
}
</script>
<style>
<!--NEEDS TO BE FIXED-->
<!--This uses the picture in the URL as a background image, needs to be fixed to stretch across whole page; use %'s.-->
body {background: url('gradient.png');}

<!--This is all gallery stuff. Makes it all a certain size, floats it to the left, pads the images, makes the images appear in a span while the mouse
is hovering over it (might be taked out and replaced with JavaScript).-->
#gallery {position: relative; }
#gallery ul {list-style-type: none;
    width: 300px; }
#gallery li { display: inline; 
     float: left;
     padding: 5px; }
#gallery img {border-style: solid: 10px; border-color: #333; }
#gallery a { text-decoration: none;
             font-style: none;  
             color: #333; }
#gallery span {display: none; }
#gallery a:hover span {display: block;     
    position: absolute;
    top: 10px;
    left: 300px; 
    text-align: center; }

<!--NEEDS TO BE FIXED-->
<!--What does this do? Excellent question, my fine sir. This tries to float the image that changes on click to the right. -->   
#mainPicture {
    float: right;
        }

<!-- <=popOut STUFF=> <=popOut STUFF=> <=popOut STUFF=> <=popOut STUFF=> <=popOut STUFF=> <=popOut STUFF=> <=popOut STUFF=>-->
.popOut
{
    cursor: default;
    list-style: none;
}
.popOut a
{
    cursor: default;
}
.popOut a .preview
{
    display: none;
}
.popOut a:hover .preview
{
    display: block;
    position: absolute;
    top: -33px;
    left: -45px;
    z-index: 1;
}
.popOut img
{
    background: #ebf0f3;
    border-color: #ebf0f3;
    border-style: solid;
    border-width: 1px;
    color: inherit;
    vertical-align: top;
    width: 100px;
    height: 75px;
}
.popOut li
{
    background: #ebf0f3;
    border-color: #CCCCCC;
    border-style: solid;
    border-width: 0px;
    color: inherit;
    display: inline;
    float: left;
    margin: 3px;
    padding: 2px;
    position: relative;
}
.popOut .preview
{
    border-color: #000;
    width: 200px;
    height: 150px;
}
.popOut p
{
    text-align: center;
}

#textarea
{
    background-color: #ebf0f3;
}
</style>
</head>

<body>
<!--NEEDS TO BE FIXED-->
<!--Give the awesome picture a similar outline to the preview pictures.-->
<!--This picture is the one that is going to change when pictures are clicked on.-->
<div class="mainPicture"><img id="awesome" src="awesome.png" height="300" width="400" alt=""><!--style="position:relative; left:600px; top:326px;"--></div>

<!--Alright, so this gallery is to hold all of the pictures. They're all set to be a certain size (100x75px) and expand to a larger size(400x300px). As it stands now, 
they're in an unordered list, and are set to change the awesome.png image whenever they are clicked.-->
<td width="1000" rowspan="3">
<div id="gallery">
    <ul class="popOut">
        <li onclick="dogText()">
            <a href="#" onclick="switchImg('dog.jpg')">
                <img src="dog.jpg" width="100" height="75" alt="dog"><img src="dog.jpg" width="100" height="75" alt="dog" class="preview"> 
            </a>
        </li>
        <li onclick="catText()">
            <a href="#" onclick="switchImg('cat.jpg')">
                <img src="cat.jpg" width="100" height="75" alt="cat"><img src="cat.jpg" width="100" height="75" alt="cat" class="preview"> 
            </a>
        </li>
        <li onclick="parrotText()">
            <a href="#" onclick="switchImg('parrot.jpg')">
                <img src="parrot.jpg" width="100" height="75" alt="parrot"><img src="parrot.jpg" width="100" height="75" alt="parrot" class="preview"> 
            </a>
        </li>
        <li onclick="lizardText()">
            <a href="#" onclick="switchImg('lizard.jpg')">
                <img src="lizard.jpg" width="100" height="75" alt="lizard"><img src="lizard.jpg" width="100" height="75" alt="lizard" class="preview"> 
            </a>
        </li>
        <li onclick="horseText()">
            <a href="#" onclick="switchImg('horse.jpg')">
                <img src="horse.jpg" width="100" height="75" alt="horse"><img src="horse.jpg" width="100" height="75" alt="horse" class="preview"> 
            </a>
        </li>
        <li onclick="chickenText()">
            <a href="#" onclick="switchImg('chicken.jpg')"> 
                <img src="chicken.jpg" width="100" height="75" alt="chicken"><img src="chicken.jpg" width="100" height="75" alt="chicken" class="preview"> 
            </a>
        </li>
        <li onclick="defaultText()">
            <a href="#" onclick="switchImg('awesome.png')" class="textualLink"><p>Click for Default Image</p></a>
        </li>
    </ul>

    <!--This textarea is the field where information about whatever is clicked will pop up, and hopefully stay there. By default, it should contain some sort of welcome message.-->
    <div id="textarea" style="height:600px;width:320px;font:14px;font:14px/26px Arial, Helvetica, sans-serif;overflow:scroll; position:relative;
    top:12px;"><p id="textarea2">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi pulvinar lectus non lectus auctor egestas. Donec at nunc neque. Morbi ornare condimentum lobortis. Nam vehicula urna ac mauris pharetra rutrum. Duis et arcu eget sapien interdum porttitor ut et tortor. Maecenas ultricies dignissim pretium. Integer quis enim metus. Sed enim lacus, eleifend eu euismod volutpat, blandit eu sem. Vestibulum varius purus ut est accumsan pellentesque. Donec quis enim id lectus sollicitudin suscipit at volutpat augue. Curabitur et metus purus. Fusce luctus nunc vitae sapien pharetra id accumsan lectus malesuada.</p></div>
    </div>
    </div>
    </div>
</td>
</body>
</html>

文本/照片交换测试
函数defaultText(){
document.getElementById('textarea2').innerHTML='Lorem ipsum door sit amet,Concertetur adipising elit.Morbi pulvinar lectus non lectus auctor egestas.Donec at nunc neque.Morbi Ornar调味品lobortis.Nam Vehicleu urna ac mauris pharetra rutrum.Duis et Arcue Egien interdum porttitor ut et tortor.Maecenas ultricies Dignissis pretium.Integer quis enim metus.Sed enim lacus,eleifend eu euismod OVERLAPAT,blandit eu sem.purus和pellentesque的前庭变异。Donec quis enim id lectus sollicitud sucipat.Curabitur et metus purus.Fusce luctus nuc vitae sapien pharetra id accumsan malesuada.';
}
函数dogText(){
document.getElementById('textarea2')。innerHTML='家养狗(犬狼疮)是灰狼(犬狼疮)的一个亚种,mammilian目食肉动物科犬科的一员。术语“家养狗”通常用于驯养和野生品种。狗可能是第一个被驯养的动物,也是人类历史上最广泛的工作、狩猎和伴生动物。狗一词也可能指狗的雄性pecies,与bitch这个词相对,bitch指的是物种中的雌性;
}函数catText(){
document.getElementById('textarea2')。innerHTML='家猫(猫科动物或猫科动物)猫科动物是一种小型的、通常毛茸茸的家养食肉哺乳动物。当作为室内宠物饲养时,它通常被称为家猫,或者当不需要将它与其他猫科动物和猫科动物区分开来时,它通常被称为猫。猫被人类视为同伴和捕杀害虫的能力。它们主要是夜间活动的。”;
}
函数parrotText(){
document.getElementById('textarea2')。innerHTML='鹦鹉,也称为鹦鹉热,是鹦鹉热目86属约372种鸟类,分布于大多数热带和亚热带地区。鹦鹉热目又细分为三个超科:鹦鹉热科鹦鹉、鸭嘴鹦鹉科(凤头鹦鹉)和斑点鹦鹉科(新西兰鹦鹉)。鹦鹉一般分布在泛热带,有几个物种也居住在南半球的温带地区。南美洲和澳大拉西亚鹦鹉的多样性最大。”;
}
函数lizardText(){
document.getElementById('textarea2')。innerHTML='蜥蜴是一个广泛分布的鳞状爬行动物类群,有5600多种,分布在除南极洲以外的所有大陆以及大多数海洋岛链。该类群传统上被认为是蜥蜴亚目,被定义为鳞翅目的所有现存成员(鳞片重叠的爬行动物),既不是蝶齿目动物(即tuatara)也不是蛇?它们形成了一个进化等级。虽然蛇被认为在系统发育上属于它们进化的毒蕨纲,但蝶骨龙是鳞状体的姐妹类群,鳞状体是较大的单系类群,包括蜥蜴和蛇。”;
}
函数horseText(){
document.getElementById('textarea2')。innerHTML='马(Equalus ferus caballus)野马是野马的两个现存亚种之一。它是一种属于分类科马科的奇蹄有蹄类哺乳动物。在过去的4500万到5500万年中,马从一种小型多足动物进化为今天的大型单趾动物。人类大约在公元前4000年开始驯养马,而马的头最长据信,驯化在公元前3000年就已经广泛存在。卡巴勒斯亚种中的马是驯化的,尽管有些驯化的种群作为野马生活在野外。这些野马种群不是真正的野马,因为这一术语用于描述从未驯化过的马,如濒危的普氏野马独立的亚种,也是唯一剩下的真正的野马。有一个广泛的、专门的词汇用来描述马的相关概念,涵盖从解剖到生命阶段、大小、颜色、标记、品种、运动和行为的一切。”;
}
函数chickenText(){
document.getElementById('textarea2')。innerHTML='鸡(Gallus Gallus domesticus)是一种家养家禽,是红丛林猫头鹰的一个亚种。作为最常见和分布最广的家养动物之一,2003年的人口超过240亿,世界上的鸡比任何其他鸟类都多。人类养鸡主要是作为食物来源,食用它们的肉和蛋。”;
}
//switchImg函数是在单击缩略图时交换awesome.png图片的功能。
功能开关img(i){
document.images[“awesome”].src=i;
}
正文{background:url('gradient.png');}
#库{位置:相对;}
#库ul{列表样式类型:无;
宽度:300px;}
#画廊展示:内联;
浮动:左;
填充:5px;}
#画廊图片{边框样式:纯色:10px;边框颜色:#333;}
#画廊a{text decorti
<head>
<script src="PathToJavaScriptFile.js.txt">
</script>
</head>
<?php
function switchImg(i){
document.images["awesome"].src = i;
}
?>
<?php
drupal_add_js('PathToJavaScriptFile.js.txt', 'external');
?>
//code not tested
function yourmodulename_preprocess_page(&$vars)
{
 drupal_add_js(drupal_get_path('theme', 'MYTHEME') .'/mytheme.js', 'file'); 
//read the functions documentation!
}