WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Unobtrusive javascript for applying expand/shrink behaviour
Categories : DHTML, CSS, Java Script, HTML Click here to Update Your Picture
Ioannis Cherouvim
Date : Dec 03rd 2005
Grade : 4 of 5 (graded 8 times)
Viewed : 45610
File : 4263.zip
Images : No Images for this code example.
Search : More code by Ioannis Cherouvim
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

title : Unobtrusive javascript for applying expand/shrink behaviour

story : This is JS script for applying expand/shrink behaviour
to blocks of html. It works unobtrusivelly, which means
that the HTML document is clean from JS. Everything is
applied dynamicly. Load the script on your head using
<script type='text/javascript' src='collapse.js'></script>
and it will generate buttons and apply behaviour on them.
It will do the job for divs which have a class name
called 'collapsable'. This is customizable of course.

If the client does not have javascript he will see the
whole document expanded on it's original state.

Live demo @ http://temp.cherouvim.com/forums/collapse/

author : Ioannis Cherouvim
web : http://cherouvim.com
date : 2005-12-03


collapse.js
var COLLAPSABLE_PARENT_NAME = "collapsable";
var COLLAPSABLE_PARENT_TYPE = "div";
var COLLAPSABLE_CHILD_TYPE = "p";

var COLLAPSABLE_EXPAND = "[expand]";
var COLLAPSABLE_SHRINK = "[shrink]";

init = function() {
    if(document.getElementById && document.createTextNode) {
        var entries = document.getElementsByTagName(COLLAPSABLE_PARENT_TYPE);
        for(i=0;i<entries.length;i++)
            if (entries[i].className==COLLAPSABLE_PARENT_NAME)
                assignCollapse(entries[i]);
    }
}

assignCollapse = function (div) {
    var button = document.createElement('a');
    button.style.cursor='pointer';
    button.setAttribute('expand', COLLAPSABLE_EXPAND);
    button.setAttribute('shrink', COLLAPSABLE_SHRINK);
    button.setAttribute('state', -1);
    button.innerHTML='dsds';
    div.insertBefore(button, div.getElementsByTagName(COLLAPSABLE_CHILD_TYPE)[0]);

    button.onclick=function(){
        var state = -(1*this.getAttribute('state'));
        this.setAttribute('state', state);
        this.parentNode.getElementsByTagName(COLLAPSABLE_CHILD_TYPE)[0].style.display=state==1?'none':'block';
        this.innerHTML = this.getAttribute(state==1?'expand':'shrink');
    };                   
    button.onclick();
}


window.onload=init;


demo HTML
<html>
<head>
<style type='text/css'>
<!--
body {
    font: 10px Georgia, Arial;
    width: 450px;
    margin: 3px auto;
    border: 3px double gray;
}

h1, h2 {
    padding: 0;
    margin: 0;
    display: inline;
}
.collapsable {
    margin: 1em;
    padding: 1em;
    border: 1px solid black;
    background: #eee;
   
}

-->
</style>
<script type='text/javascript' src='collapse.js'></script>
</head>
<body>
<h1>expand-shrink</h1>

<div class='collapsable'>
<h2>title1</h2>
<p>foo bar example foo bar example foo bar example foo bar example foo bar example foo bar example </p>
</div>

<div class='collapsable'>
<h2>title2</h2>
<p>example.com foo bar example.com foo bar example.com foo bar example.com foo bar </p>
</div>

<div class='collapsable'>
<h2>title3</h2>
<p>example.comfoo barexample.comfoo bar example.com foo bar example.com foo bar example.comfoo barexample.com foo bar example.com foo bar example.com foo bar example.comfoo barexample.comfoo bar example.com foo bar example.com foo bar example.comfoo barexample.com foo bar example.com foo bar example.com foo bar </p>
</div>

</body>
</html>



Javascript animated menu items
Categories : DHTML, CSS, Java Script, HTML
Table editable dynamic form with edit + selection (select / option) + checkbox.
Categories : Java Script, DHTML, User Interface, CSS, HTML
Unobtrusive javascript for maintaining scrollable layer state
Categories : DHTML, Java Script, HTML
Show or Hide your Content using Javascript
Categories : Java Script, HTML, CSS, Beginner Guides
Higly Customizable Javascript Calendar Script
Categories : Java Script, Calendar, Date Time, HTML, CSS
Page Loading Message shown during the time your site's page is being loaded.
Categories : HTML, CSS, Java Script
Javascript Background Scroller
Categories : Java Script, CSS, HTML
day and week grid with clickable fields on/off and possibility to insert in DB
Categories : PHP, Java Script, CSS
<FORM> causing an extra line in HTML output on IE
Categories : Beginner Guides, HTML, CSS
A ball is attached to your mouse cursor with an elastic cord!
Categories : Java Script, DHTML, Graphics
Mordern Peroidic Table - Science
Categories : Java Script, HTML, Charts and Graphs
Javascript Color Picker
Categories : Java Script, Colors, HTML
Simple Javascript CSS Digital Clock
Categories : Java Script, Date Time, CSS, Beginner Guides, Web Design
Cool tool tip
Categories : Java Script, HTML, Web Design
Java Script Based Navigation
Categories : HTML, Java Script, Navigation