Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've been asking a lot of questions here over the past few days trying to tinker with different areas of this template I'm building. I just wanted to make something that works so it would be easy to go in and change all the content for several pages I'll be creating later (which will look a lot nicer aesthetically, this is just getting all the functionality to work).

I ran into a problem, though. We're using Drupal as our Content Management System (not our decision; we got it handed to us by our superiors). The main issue is that since it got handed out to several departments, we have no control over a lot of it. The people who put it together are the administrators, we're just "users."

The code below works, and it works pretty well for the little amount of time I've put into it.

<!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>

However, several hours have been spent today between me and my buddy trying to find a way to override the built-in CSS and how to integrate the JavaScript.

I saw pages telling me to just put and tags in the Source Code for the page/node I was trying to build:

<head>
<script src="PathToJavaScriptFile.js.txt">
</script>
</head>

I saw pages telling me to use a php tag to incorporate the JavaScript code into the page, much the same way it would be in a tag in a normal HTML page:

<?php
function switchImg(i){
document.images["awesome"].src = i;
}
?>

I even tried just plain old calling the .js file into the page using what I believe is called a module:

<?php
drupal_add_js('PathToJavaScriptFile.js.txt', 'external');
?>

Fun fact, guys: Drupal is dumb. None of those worked, and every single thing I find with my Google-fu is some variation of those three choices. Are any of you particular masters with Drupal? If you can help me solve this problem, I swear on my own life that I will bake and ship to you a batch of my grandmother's famous chocolate chip cookies.

I'm losing my mind. I just want to add some CSS and JavaScript so I can impress the guy who gave me my internship :/

share|improve this question

closed as off topic by Kev May 12 '12 at 15:37

Questions on Stack Overflow are expected to relate to programming within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
You might want to ask this over at drupal.stackexchange.com. –  thirtydot May 11 '12 at 18:14
2  
Cross-posted: drupal.stackexchange.com/questions/30895 @thirtydot - please just flag silently so we can migrate, don't suggest to OP they should cross-post –  Kev May 12 '12 at 15:37

1 Answer 1

up vote 1 down vote accepted

First you start explaining on why you are using drupal. Then after that you ask your question. And then complain about drupal. Read the tips on asking questions! You need to provide what version are you using of drupal. Or how did you built your module. Or details relevant to the question.

The drupal way is not to override css and the output. What would your client think if he asks you to use Drupal and he finds out you didn't actually used it? There is a reason people use drupal and is stability, reliability, scalability, etc.

You need to create a node of type page and add the content there. Then you can go to your template.php file in the sites/all/themes/your-theme-name/template.php and use a theme_preprocess_page() to add the js.

Or you can do it in a module. For example you can't just add code to a module they are not includes (like what I think you did in your example). They are modules and they work on certain ways.

In your module (or your theme) you could create a hook. (remember to enable it in the admin config page) For example

//code not tested
function yourmodulename_preprocess_page(&$vars)
{
 drupal_add_js(drupal_get_path('theme', 'MYTHEME') .'/mytheme.js', 'file'); 
//read the functions documentation!
}

A few other points.

  • why your javascripts have the .txt extension?
  • Also what theme are you using? I recommend you to use Zen theme.
  • I think there's something weird with that path. Why are your files under PathToJavaScriptFile/. Normally js files go in the theme folder on sites/all/themes/yourthemename
  • the examples you posted are very vague but the one with javascript inside php is just plain wrong.

EDIT: Considering you don´t have access to the admin or the rest of the page. See if you can create a node and set Full HTML as a format filter. Then you can add your Javascript from there with the script tag.

share|improve this answer
    
I complain about Drupal because it doesn't fit our needs. The higher ups thought it would be a good idea, and we don't have the power to change it. On top of that, we have almost no administrative rights. We straight up don't have access to the template.php file, anything having to do with the themes, OR the admin config page. Moreover, this is being created for our department. We were just handed a template that left us no tools to make it the way we want to. The uploader changed .js to .js.txt. We don't have choice of theme. We don't have access to the themes folder. –  Henry Edward Quinn IV May 11 '12 at 20:11
    
There's not a client that won't be happy, since we're trying to best represent our department in making this website. We just have no creative license, and we'd like ours to look better than the other departments nationwide. –  Henry Edward Quinn IV May 11 '12 at 20:15
1  
Have you tried adding a node type page and using the Full HTML input format? –  lomelyo May 11 '12 at 22:33
1  
@HenryEdwardQuinnIV It's not Drupal that doesn't fit your needs; it's who set those restrictions you are having, the problem. It is a mystery why they thought that administrating a site without using any administrative pages would be possible. –  kiamlaluno May 14 '12 at 4:33
1  
@HenryEdwardQuinnIV What do you mean by "dumbed down version of JavaScript". To get jQuery you need to surround your js file into (function ($) { //your jQuery codes go here }(jQuery)); –  lomelyo May 14 '12 at 19:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.