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

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 9 times)
Viewed : 58468
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
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
Unobtrusive javascript for maintaining scrollable layer state
Categories : DHTML, Java Script, HTML
Higly Customizable Javascript Calendar Script
Categories : Java Script, Calendar, Date Time, HTML, CSS
Show or Hide your Content using Javascript
Categories : Java Script, HTML, CSS, Beginner Guides
Hilight Form Element onFocus
Categories : Java Script, Form Processing, CSS
Conditional Check - a script that allows a user to submit a form only if the user check a checkbox.
Categories : HTML, Java Script, Form Processing, Beginner Guides
Enchancing dd/mm/yyyy forms with unobtrusive javascript
Categories : Java Script, HTML, User Interface, Date Time
How to get the Focus (Cursor) into a Form-Element.
Categories : HTML, Java Script
Rollover Image link effect using only single image.
Categories : Web Design, HTML, CSS, Beginner Guides
Menu in sliding bar or tree style. Handles frames by using small amount of javascript. Handles external and internal pages. Allows custom code to replace a menu item.
Categories : PHP Classes, PHP, Java Script, DHTML
Changing the Style of form objects using the JavaScript OnClick method.
Categories : Java Script, Form Processing, Beginner Guides, CSS
PHP Calendar
Categories : PHP, Calendar, Date Time, Java Script, CSS