Fixed a bunch of endline issues.
[jquery.git] / src / jquery / jquery.js
index cda8fae..1893498 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * jQuery - New Wave Javascript
+ * jQuery @VERSION - New Wave Javascript
  *
  * Copyright (c) 2006 John Resig (jquery.com)
  * Dual licensed under the MIT (MIT-LICENSE.txt)
@@ -95,7 +95,10 @@ if ( typeof $ != "undefined" )
  * @result [ <p>two</p> ]
  *
  * @example $("<div><p>Hello</p></div>").appendTo("#body")
- * @desc Creates a div element (and all of its contents) dynamically, and appends it to the element with the ID of body.
+ * @desc Creates a div element (and all of its contents) dynamically, 
+ * and appends it to the element with the ID of body. Internally, an
+ * element is created and it's innerHTML property set to the given markup.
+ * It is therefore both quite flexible and limited. 
  *
  * @name $
  * @param String expr An expression to search with, or a string of HTML to create on the fly.
@@ -154,6 +157,7 @@ if ( typeof $ != "undefined" )
  * behaves just like $(document).ready(), in that it should be used to wrap
  * all of the other $() operations on your page. While this function is,
  * technically, chainable - there really isn't much use for chaining against it.
+ * You can have as many $(document).ready events on your page as you like.
  *
  * @example $(function(){
  *   // Document is ready
@@ -186,7 +190,7 @@ var $ = jQuery;
 
 jQuery.fn = jQuery.prototype = {
        /**
-        * The current SVN version of jQuery.
+        * The current version of jQuery.
         *
         * @private
         * @property
@@ -194,7 +198,7 @@ jQuery.fn = jQuery.prototype = {
         * @type String
         * @cat Core
         */
-       jquery: "$Rev$",
+       jquery: "@VERSION",
 
        /**
         * The number of elements currently matched.
@@ -391,8 +395,8 @@ jQuery.fn = jQuery.prototype = {
         * ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
         * ok( $('#name').attr('name') == "name", 'Check for name attribute' );
         * ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
-        * ok( $('#form').attr('action') == "formaction", 'Check for action attribute' );
-        * 
+        * ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
+        *
         * @name attr
         * @type Object
         * @param String name The name of the property to access.
@@ -493,7 +497,7 @@ jQuery.fn = jQuery.prototype = {
         * representation of itself. Eg. fontWeight, fontSize, fontFamily, borderWidth,
         * borderStyle, borderBottomWidth etc.
         *
-        * @test ok( $('#foo').css("display") == 'block', 'Check for css property "display"');
+        * @test ok( $('#main').css("display") == 'none', 'Check for css property "display"');
         *
         * @name css
         * @type Object
@@ -644,7 +648,7 @@ jQuery.fn = jQuery.prototype = {
                        // Insert it before the element to be wrapped
                        this.parentNode.insertBefore( b, this );
 
-                       // Find he deepest point in the wrap structure
+                       // Find the deepest point in the wrap structure
                        while ( b.firstChild )
                                b = b.firstChild;
 
@@ -1160,52 +1164,6 @@ jQuery.fn = jQuery.prototype = {
        },
        
        /**
-        * Executes the first callback for every element that fits the expression
-        * and executes the second callback for every element that does not fit
-        * the expression.
-        *
-        * @example $('div').ifelse(':visible',
-     *   function() { $(this).slideUp(); },
-         function() { $(this).slideDown(); }
-     * );
-        * @desc Slides down all visible div elements and slides down all others
-        * 
-        * @test var checked = 0, notChecked = 0;
-        * var inputChecked = $(':input').ifelse(':checked',
-        *   function() { checked++; },
-        *   function() { notChecked++ }
-        * );
-        * ok( checked == 2, 'Check is if/else: Count checked elements' );
-        * ok( notChecked == 12, 'Check is if/else: Count unchecked elements' );
-        *
-        * $('#first, #foo, #ap').ifelse('p',
-        *   function() { $(this).html('me == p') },
-        *   function() { $(this).html('me != p') }
-        * );
-        * ok( $('#first').text() == 'me == p', 'Check filter-if-clause' );
-        * ok( $('#foo').text() == 'me != p', 'Check else-clause' );
-        * ok( $('#ap').text() == 'me == p', 'Check filter-if-clause' );
-        *
-        * @name ifelse
-        * @type jQuery
-        * @param String expression The expression with which to filter
-        * @param Function ifCallback Called for elements that fit the expression
-        * @param Function elseCallback Called for elements that don't fit the expression
-        * @cat DOM/Traversing
-        */
-       ifelse: function(expr, ifCallback, elseCallback) {
-               var ifCallback = ifCallback || function() {};
-        var elseCalllback = elseCallback || function() {};
-        return this.each(function() {
-            if($(this).is(expr)) {
-                ifCallback.apply(this);
-            } else {
-                elseCallback.apply(this);
-            }
-        });
-       },
-
-       /**
         *
         *
         * @private
@@ -1426,10 +1384,6 @@ jQuery.extend({
                        o.className += ( o.className ? " " : "" ) + c;
                },
                remove: function(o,c){
-                       /*
-                       o.className = !c ? "" :
-                               o.className.replace(
-                                       new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");*/
                        if( !c ) {
                                o.className = "";
                        } else {
@@ -1497,14 +1451,16 @@ jQuery.extend({
                        });
 
                        return p == "height" ? oHeight : oWidth;
-               } else if ( p == "opacity" && jQuery.browser.msie )
-                       return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
+               }
 
                return jQuery.curCSS( e, p );
        },
 
        curCSS: function(elem, prop, force) {
                var ret;
+               
+               if (prop == 'opacity' && jQuery.browser.msie)
+                       return jQuery.attr(elem.style, 'opacity');
 
                if (!force && elem.style[prop]) {
 
@@ -1538,7 +1494,9 @@ jQuery.extend({
                var r = [];
                for ( var i = 0; i < a.length; i++ ) {
                        if ( a[i].constructor == String ) {
-
+                               // trim whitespace, otherwise indexOf won't work as expected
+                               a[i] = jQuery.trim(a[i]);
+                               
                                var table = "";
 
                                if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
@@ -1607,7 +1565,7 @@ jQuery.extend({
                        enabled: "!a.disabled",
                        disabled: "a.disabled",
                        checked: "a.checked",
-                       selected: "a.selected",
+                       selected: "a.selected || jQuery.attr(a, 'selected')",
 
                        // Form elements
                        text: "a.type=='text'",
@@ -1873,11 +1831,27 @@ jQuery.extend({
                        disabled: "disabled",
                        checked: "checked"
                };
+               
+               // IE actually uses filters for opacity ... elem is actually elem.style
+               if (name == "opacity" && jQuery.browser.msie && value != undefined) {
+                       // IE has trouble with opacity if it does not have layout
+                       // Would prefer to check element.hasLayout first but don't have access to the element here
+                       elem['zoom'] = 1; 
+                       if (value == 1) // Remove filter to avoid more IE weirdness
+                               return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"");
+                       else
+                               return elem["filter"] = elem["filter"].replace(/alpha\([^\)]*\)/gi,"") + "alpha(opacity=" + value * 100 + ")";
+               } else if (name == "opacity" && jQuery.browser.msie) {
+                       return elem["filter"] ? parseFloat( elem["filter"].match(/alpha\(opacity=(.*)\)/)[1] )/100 : 1;
+               }
+               
+               // Mozilla doesn't play well with opacity 1
+               if (name == "opacity" && jQuery.browser.mozilla && value == 1) value = 0.9999;
 
                if ( fix[name] ) {
                        if ( value != undefined ) elem[fix[name]] = value;
                        return elem[fix[name]];
-               } else if( value == undefined && $.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
+               } else if( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
                        return elem.getAttributeNode(name).nodeValue;
                } else if ( elem.getAttribute != undefined ) {
                        if ( value != undefined ) elem.setAttribute( name, value );