Thilo Planz - HTML.Popup-0.04

Documentation | Source

NAME

HTML.Popup - Accessible Javascript Popup Links

SYNOPSIS

Unobtrusive event handlers

        <head>
        <script>
                function my_onload(){
                        var pop = new HTML.Popup(400, 600);
                        pop.attachToClass('popup'); // attach to all <a> of class 'popup'
                        pop.attachToTarget('popup'); // attach to all <a> with target 'popup'
                }
        </script>
        </head>
        <body onload='my_onload()'>

Inline event handlers

    <script>
    var pop = new HTML.Popup(400, 600);
    </script>
    
    <a href='/popup/blah.html' target='my_popup' onclick='return pop.popup(this)' >

DESCRIPTION

This module provides JavaScript onclick event handlers that can be attached to links to pop up windows.

If JavaScript is unavailable, the links will still work.

Specify href and target frame in the anchor tag, specify size in an HTML.Popup object and attach this to the onclick event of the href.

Constructor

  var pop = new HTML.Popup(width, height, features);
  // features is optional and defaults to 
  //   'location=no, statusbar=no, menubar=no'

Create a new HTML.Popup object.

Create one object for every "class" (set of decorations / size ) you need in your page.

Methods

attachToClass(classname)

Finds all link anchors in the document of the specified class and attaches the popup object as an onclick event handler.

attachToTarget(targetname)

Finds all link anchors in the document with the specified link target attribute and attaches the popup object as an onclick event handler.

This is probably the most convenient way to use this module, as you do need even need to set a class attribute for the anchor tag.

popup(element)

If you want to manually attach the onclick handlers inline, you can call this.

Pass in the anchor element in question (we need it to get the popup href and target).

Returns false for convenience (which you should return from onclick to shortcut executing the link a second time).

EXPORTS

Nothing.

AUTHOR

Thilo Planz <thilo@cpan.org>

ACKNOWLEDGEMENTS

This module draws inspiration from an article by Caio Chassot published on A List Apart, http://www.alistapart.com/articles/popuplinks/.

A List Apart on the whole is a highly recommended read for anyone with an interest in professional web design, http://www.alistapart.com/.

COPYRIGHT

 COPYRIGHT
      Copyright (c) 2005 Thilo Plamz .  All rights reserved.
      This module is free software; you can redistribute it and/or modify it
      under the terms of the Artistic license. 
// Set up namepace
if (!HTML) var HTML = {};

HTML.Popup = function (width, height, features) {
	this.width = width || 300;
	this.height = height || 300;
	this.features = features || 'location=no, statusbar=no, menubar=no';
}

HTML.Popup.VERSION = '0.04';

HTML.Popup.prototype.popup = function(element) {
	var href = element.getAttribute('href');
	var target = element.getAttribute('target') || '_blank';
	window.open (href, target, 
		'width='+ this.width + 
		', height=' + this.height+
		', ' + this.features
		).focus();
	return false;
}


HTML.Popup.prototype.attachToClass = function(classname) {
	var links = document.getElementsByTagName('a');
	var _obj = this;
	 for(l=0;l<links.length;l++){
		if (links[l].className == classname){
			links[l].onclick = function() {return _obj.popup(this); };
		}
	}
}

HTML.Popup.prototype.attachToTarget = function(targetname) {
	var links = document.getElementsByTagName('a');
	var _obj = this;
	 for(l=0;l<links.length;l++){
		if (links[l].getAttribute('target') == targetname){
			links[l].onclick = function() {return _obj.popup(this); };
		}
	}
}


/*

=head1 NAME

HTML.Popup - Accessible Javascript Popup Links

=head1 SYNOPSIS

=head2 Unobtrusive event handlers 

	<head>
	<script>
		function my_onload(){
			var pop = new HTML.Popup(400, 600);
			pop.attachToClass('popup'); // attach to all <a> of class 'popup'
			pop.attachToTarget('popup'); // attach to all <a> with target 'popup'
		}
	</script>
	</head>
	<body onload='my_onload()'>
	

=head2 Inline event handlers

    <script>
    var pop = new HTML.Popup(400, 600);
    </script>
    
    <a href='/popup/blah.html' target='my_popup' onclick='return pop.popup(this)' >
    	
    	
    	

=head1 DESCRIPTION

This module provides JavaScript onclick event handlers that
can be attached to links to pop up windows.

If JavaScript is unavailable, the links will still work.

Specify href and target frame in the anchor tag, specify size in an
HTML.Popup object and attach this to the onclick event of the href.

=head2 Constructor

  var pop = new HTML.Popup(width, height, features);
  // features is optional and defaults to 
  //   'location=no, statusbar=no, menubar=no'

Create a new C<HTML.Popup> object.

Create one object for every "class" (set of decorations / size )
you need in your page.

=head2 Methods

=head3 attachToClass(classname)

Finds all link anchors in the document of the specified class and 
attaches the popup object as an onclick event handler.

=head3 attachToTarget(targetname)

Finds all link anchors in the document with the specified 
link target attribute and 
attaches the popup object as an onclick event handler.

This is probably the most convenient way to use this module,
as you do need even need to set a class
attribute for the anchor tag.

=head3 popup(element)

If you want to manually attach the onclick handlers inline, you can
call this. 

Pass in the anchor element in question (we need it to get the
popup href and target).

Returns false for convenience (which you should return from
onclick to shortcut executing the link a second time).
  

=head2 EXPORTS

Nothing.


=head1 AUTHOR

Thilo Planz <thilo@cpan.org>

=head1 ACKNOWLEDGEMENTS

This module draws inspiration from an article by Caio Chassot
published on A List Apart, L<http://www.alistapart.com/articles/popuplinks/>.

A List Apart on the whole is a highly recommended read for anyone with
an interest in professional web design, L<http://www.alistapart.com/>.


=head1 COPYRIGHT

 COPYRIGHT
      Copyright (c) 2005 Thilo Plamz .  All rights reserved.
      This module is free software; you can redistribute it and/or modify it
      under the terms of the Artistic license. 

=cut

*/