Garrett Rooney - Display.Hide-0.02

Documentation | Source

NAME

Display.Hide - Control the visibility of elements in a page

SYNOPSIS

  <p id="first">Some Stuff</p>
  <p id="second">More Stuff</p>

  <script type="lang/javascript>
    var controller = new Display.Hide('first', 'second');
  </script>

  <a onlick="controller.toggle()">Toggle Visibility</a>
  <a onlick="controller.hide()">Hide Elements</a>
  <a onlick="controller.show()">Show Elements</a>

DESCRIPTION

Display.Hide lets you control the visibility of elements in a page, showing, hiding, or toggling the visibility of them.

METHODS

new Display.Hide('id1', 'id2', ...);

Allocate a new Display.Hide object, which will control the visibility of the elements whos ids are passed to the constructor.

hide

Hide all the elements controlled by this instance.

show

Show all the elements controlled by this instance.

toggle

Toggle visibility of all the elements controlled by this instance.

AUTHOR

COPYRIGHT

Copyright (c) 2005 Garrett Rooney.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

/*

=head1 NAME

Display.Hide - Control the visibility of elements in a page

=head1 SYNOPSIS

  <p id="first">Some Stuff</p>
  <p id="second">More Stuff</p>

  <script type="lang/javascript>
    var controller = new Display.Hide('first', 'second');
  </script>

  <a onlick="controller.toggle()">Toggle Visibility</a>
  <a onlick="controller.hide()">Hide Elements</a>
  <a onlick="controller.show()">Show Elements</a>

=head1 DESCRIPTION

Display.Hide lets you control the visibility of elements in a page, showing,
hiding, or toggling the visibility of them.

=head1 METHODS

=cut

*/

if (Display == undefined) var Display = {};

/*

=head2 new Display.Hide('id1', 'id2', ...);

Allocate a new Display.Hide object, which will control the visibility of
the elements whos ids are passed to the constructor.

=cut

*/

Display.Hide = function() {
  this.ids = [];
  for (var i = 0; i < arguments.length; ++i) {
    this.ids[i] = arguments[i];
  }
}

Display.Hide.VERSION = '0.02';

/*

=head2 hide

Hide all the elements controlled by this instance.

=cut

*/

Display.Hide.prototype.hide = function() {
  for (i in this.ids) {
    var id = this.ids[i];

    var elem = document.getElementById(id);

    if (elem) {
      elem.style.display = 'none';
    }
  }
}

/*

=head2 show

Show all the elements controlled by this instance.

=cut

*/

Display.Hide.prototype.show = function() {
  for (i in this.ids) {
    var id = this.ids[i];

    var elem = document.getElementById(id);

    if (elem) {
      elem.style.display = '';
    }
  }
}

/*

=head2 toggle

Toggle visibility of all the elements controlled by this instance.

=cut

*/

Display.Hide.prototype.toggle = function() {
  for (i in this.ids) {
    var id = this.ids[i];

    var elem = document.getElementById(id);

    if (elem) {
      if (elem.style.display == 'none') {
        elem.style.display = '';
      } else {
        elem.style.display = 'none';
      }
    }
  }
}

/*

=head1 AUTHOR

Garrett Rooney <rooneg@electricjellyfish.net>, L<http://asdf.blogs.com>

=head1 COPYRIGHT

Copyright (c) 2005 Garrett Rooney.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=cut

*/