Skip to content

Instantly share code, notes, and snippets.

@nathanborror
Created October 6, 2009 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanborror/202782 to your computer and use it in GitHub Desktop.
Save nathanborror/202782 to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.3/mootools-yui-compressed.js"></script>
<script type="text/javascript">
var Box = new Class({
initialize: function(element) {
this.element = $(element);
this.p = this.element.getElement('p');
this.doc = $(document);
this.element.addEvent('click', this.click.bind(this));
this.doc.addEvents({
'click': this.hide.bind(this),
'reset': this.hide.bind(this)
});
},
click: function(e) {
e.stop();
var target = $(e.target);
if (target.get('tag') == 'a') {
if (this.p.getStyle('display') == 'block') {
this.hide();
}
else {
this.show();
}
}
},
hide: function(e) {
this.p.setStyle('display', 'none');
},
show: function(e) {
this.doc.fireEvent('reset');
this.p.setStyle('display', 'block');
}
});
window.addEvent('domready',function() {
new Box('button1');
new Box('button2');
});
</script>
<style type="text/css" media="screen">
body { font: 16px "Helvetica Neue", helvetica, arial, sans-serif; }
a { text-decoration: none; }
.button { margin-bottom: 10px; padding: 20px; width: 300px; border: 1px solid #ddd; }
.button a { display: block; }
.button p { display: none; }
</style>
</head>
<body>
<div class="button" id="button1">
<a href="#">Button 1</a>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div class="button" id="button2">
<a href="#">Button 2</a>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment