8346e283ad797ef549be70335d3961f4324901baRyan Grove/**
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @module node
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @submodule node-base
8346e283ad797ef549be70335d3961f4324901baRyan Grove */
8346e283ad797ef549be70335d3961f4324901baRyan Grove
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeneyvar Y_Node = Y.Node;
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt SweeneyY.mix(Y_Node.prototype, {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney /**
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * Makes the node visible.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * If the "transition" module is loaded, show optionally
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * animates the showing of the node using either the default
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * transition effect ('fadeIn'), or the given named effect.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @method show
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @for Node
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @param {String} name A named Transition effect to use as the show effect.
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @param {Object} config Options to use with the transition.
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @param {Function} callback An optional function to run after the transition completes.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @chainable
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney */
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney show: function(callback) {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney callback = arguments[arguments.length - 1];
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney this.toggleView(true, callback);
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney return this;
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney },
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney /**
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * The implementation for showing nodes.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * Default is to toggle the style.display property.
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @method _show
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @protected
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @chainable
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney */
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney _show: function() {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney this.setStyle('display', '');
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney },
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney _isHidden: function() {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney return Y.DOM.getStyle(this._node, 'display') === 'none';
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney },
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo /**
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo * Displays or hides the node.
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo * If the "transition" module is loaded, toggleView optionally
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo * animates the toggling of the node using either the default
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo * transition effect ('fadeIn'), or the given named effect.
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo * @method toggleView
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo * @for Node
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo * @param {Boolean} [on] An optional boolean value to force the node to be shown or hidden
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo * @param {Function} [callback] An optional function to run after the transition completes.
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo * @chainable
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo */
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney toggleView: function(on, callback) {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney this._toggleView.apply(this, arguments);
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo return this;
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney },
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney _toggleView: function(on, callback) {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney callback = arguments[arguments.length - 1];
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8346e283ad797ef549be70335d3961f4324901baRyan Grove // base on current state if not forcing
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney if (typeof on != 'boolean') {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney on = (this._isHidden()) ? 1 : 0;
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney }
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney if (on) {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney this._show();
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney } else {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney this._hide();
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney }
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney if (typeof callback == 'function') {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney callback.call(this);
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney }
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney return this;
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney },
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney /**
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * Hides the node.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * If the "transition" module is loaded, hide optionally
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * animates the hiding of the node using either the default
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * transition effect ('fadeOut'), or the given named effect.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @method hide
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @param {String} name A named Transition effect to use as the show effect.
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @param {Object} config Options to use with the transition.
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @param {Function} callback An optional function to run after the transition completes.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @chainable
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney */
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney hide: function(callback) {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney callback = arguments[arguments.length - 1];
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney this.toggleView(false, callback);
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney return this;
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney },
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney /**
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * The implementation for hiding nodes.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * Default is to toggle the style.display property.
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @method _hide
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @protected
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @chainable
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney */
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney _hide: function() {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney this.setStyle('display', 'none');
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney }
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney});
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt SweeneyY.NodeList.importMethod(Y.Node.prototype, [
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney /**
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * Makes each node visible.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * If the "transition" module is loaded, show optionally
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * animates the showing of the node using either the default
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * transition effect ('fadeIn'), or the given named effect.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @method show
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @param {String} name A named Transition effect to use as the show effect.
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @param {Object} config Options to use with the transition.
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @param {Function} callback An optional function to run after the transition completes.
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @for NodeList
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @chainable
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney */
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney 'show',
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney /**
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * Hides each node.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * If the "transition" module is loaded, hide optionally
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * animates the hiding of the node using either the default
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * transition effect ('fadeOut'), or the given named effect.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @method hide
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @param {String} name A named Transition effect to use as the show effect.
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @param {Object} config Options to use with the transition.
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @param {Function} callback An optional function to run after the transition completes.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @chainable
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney */
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney 'hide',
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo /**
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo * Displays or hides each node.
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo * If the "transition" module is loaded, toggleView optionally
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo * animates the toggling of the nodes using either the default
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo * transition effect ('fadeIn'), or the given named effect.
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo * @method toggleView
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo * @param {Boolean} [on] An optional boolean value to force the nodes to be shown or hidden
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo * @param {Function} [callback] An optional function to run after the transition completes.
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo * @chainable
b89fb6c1c300b2d7138d80360f249c8c192da700Juan Ignacio Dopazo */
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney 'toggleView'
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney]);