Removed duplicated show/hide/toggle, added test for toggle(), started documentation of event properties/methods
This commit is contained in:
parent
d3d7d7ebff
commit
41cc839a2d
3 changed files with 106 additions and 58 deletions
|
@ -1,3 +1,100 @@
|
|||
/**
|
||||
* Describes the nature of the event.
|
||||
*
|
||||
* Native by all browsers.
|
||||
*
|
||||
* @example $("a").click(function(event) {
|
||||
* alert(event.type);
|
||||
* });
|
||||
* @result "click"
|
||||
*
|
||||
* @property
|
||||
* @name event.type
|
||||
* @type String
|
||||
* @cat Events
|
||||
*/
|
||||
|
||||
/**
|
||||
* Contains the DOM element that issued the event. This can be
|
||||
* the element that registered for the event or a child of it.
|
||||
*
|
||||
* Fixed where necessary (IE, Safari).
|
||||
*
|
||||
* Use to implement event delegation.
|
||||
*
|
||||
* @example $("a[@href=http://google.com]").click(function(event) {
|
||||
* alert(event.target.href);
|
||||
* });
|
||||
* @result "http://google.com"
|
||||
* @desc Alerts the href property of the target element.
|
||||
*
|
||||
* @example function handler(event) {
|
||||
* var target = $(event.target);
|
||||
* if( target.is("li") ) {
|
||||
* target.children().toggle();
|
||||
* }
|
||||
* }
|
||||
* $("ul").click(handler).find("li > ").hide();
|
||||
* @desc Implements a simple event delegation: The click handler is added
|
||||
* to an unordered list, and the children of it's li children are hidden.
|
||||
* Clicking one of the li children toggles (see toggle()) their children.
|
||||
*
|
||||
* @property
|
||||
* @name event.target
|
||||
* @type Element
|
||||
* @cat Events
|
||||
*/
|
||||
|
||||
/**
|
||||
* The pageX/Y property pair returns the mouse coordinates relative to the document.
|
||||
*
|
||||
* Fixed where necessary (IE).
|
||||
*
|
||||
* @example $("a").click(function(event) {
|
||||
* alert("Current mouse position: " + event.pageX + ", " + event.pageY );
|
||||
* });
|
||||
* @result "Current mouse position: 130, 640"
|
||||
*
|
||||
* @property
|
||||
* @name event.pageX/Y
|
||||
* @type String
|
||||
* @cat Events
|
||||
*/
|
||||
|
||||
/**
|
||||
* Stops the bubbling of an event, prohibiting other handlers to get to
|
||||
* handle that event.
|
||||
*
|
||||
* Fixed where necessary (IE).
|
||||
*
|
||||
* @example $("p").click(function(event){
|
||||
* event.stopPropagation();
|
||||
* // do something
|
||||
* });
|
||||
* @desc Prohibits other event handlers to be called.
|
||||
*
|
||||
* @name event.stopPropagation
|
||||
* @type undefined
|
||||
* @cat Events
|
||||
*/
|
||||
|
||||
/**
|
||||
* Prevents the browser from executing the default action.
|
||||
*
|
||||
* Fixed where necessary (IE).
|
||||
*
|
||||
* @example $("a").click(function(event){
|
||||
* event.preventDefault();
|
||||
* // do something
|
||||
* });
|
||||
* @desc Stops the browser from changing the page to the
|
||||
* href of any anchors.
|
||||
*
|
||||
* @name event.preventDefault
|
||||
* @type undefined
|
||||
* @cat Events
|
||||
*/
|
||||
|
||||
/*
|
||||
* A number of helper functions used for managing events.
|
||||
* Many of the ideas behind this code orignated from
|
||||
|
|
|
@ -9,4 +9,13 @@ test("animate(Hash, Object, Function) - assert that animate doesn't modify its a
|
|||
ok( hash.opacity == hashCopy.opacity, 'Check if animate changed the hash parameter' );
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
test("toggle()", function() {
|
||||
var x = $("#foo");
|
||||
ok( x.is(":visible") );
|
||||
x.toggle();
|
||||
ok( x.is(":hidden") );
|
||||
x.toggle();
|
||||
ok( x.is(":visible") );
|
||||
});
|
58
src/jquery/jquery.js
vendored
58
src/jquery/jquery.js
vendored
|
@ -1927,50 +1927,6 @@ jQuery.each({
|
|||
* @cat DOM/Attributes
|
||||
*/
|
||||
|
||||
/**
|
||||
* Displays each of the set of matched elements if they are hidden.
|
||||
*
|
||||
* @example $("p").show()
|
||||
* @before <p style="display: none">Hello</p>
|
||||
* @result [ <p style="display: block">Hello</p> ]
|
||||
*
|
||||
* @name show
|
||||
* @type jQuery
|
||||
* @cat Effects
|
||||
*/
|
||||
|
||||
/**
|
||||
* Hides each of the set of matched elements if they are shown.
|
||||
*
|
||||
* @example $("p").hide()
|
||||
* @before <p>Hello</p>
|
||||
* @result [ <p style="display: none">Hello</p> ]
|
||||
*
|
||||
* var pass = true, div = $("div");
|
||||
* div.hide().each(function(){
|
||||
* if ( this.style.display != "none" ) pass = false;
|
||||
* });
|
||||
* ok( pass, "Hide" );
|
||||
*
|
||||
* @name hide
|
||||
* @type jQuery
|
||||
* @cat Effects
|
||||
*/
|
||||
|
||||
/**
|
||||
* Toggles each of the set of matched elements. If they are shown,
|
||||
* toggle makes them hidden. If they are hidden, toggle
|
||||
* makes them shown.
|
||||
*
|
||||
* @example $("p").toggle()
|
||||
* @before <p>Hello</p><p style="display: none">Hello Again</p>
|
||||
* @result [ <p style="display: none">Hello</p>, <p style="display: block">Hello Again</p> ]
|
||||
*
|
||||
* @name toggle
|
||||
* @type jQuery
|
||||
* @cat Effects
|
||||
*/
|
||||
|
||||
/**
|
||||
* Adds the specified class to each of the set of matched elements.
|
||||
*
|
||||
|
@ -2054,20 +2010,6 @@ jQuery.each( {
|
|||
jQuery.attr( this, key, "" );
|
||||
this.removeAttribute( key );
|
||||
},
|
||||
show: function(){
|
||||
this.style.display = this.oldblock ? this.oldblock : "";
|
||||
if ( jQuery.css(this,"display") == "none" )
|
||||
this.style.display = "block";
|
||||
},
|
||||
hide: function(){
|
||||
this.oldblock = this.oldblock || jQuery.css(this,"display");
|
||||
if ( this.oldblock == "none" )
|
||||
this.oldblock = "block";
|
||||
this.style.display = "none";
|
||||
},
|
||||
toggle: function(){
|
||||
jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );
|
||||
},
|
||||
addClass: function(c){
|
||||
jQuery.className.add(this,c);
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue