- css: function(a,b) {
- return a.constructor != String || b ?
- this.each(function(){
- if ( !b ) {
- for ( var j in a ) {
- $.attr(this.style,j,a[j]);
- }
- } else {
- $.attr(this.style,a,b);
- }
- }) : $.css( this.get(0), a );
- },
- toggle: function() {
- return this.each(function(){
- var d = $.getCSS(this,"display");
- if ( d == "none" || d === '' ) {
- $(this).show();
- } else {
- $(this).hide();
- }
- });
- },
- show: function(a) {
- return this.each(function(){
- this.style.display = this.$$oldblock ? this.$$oldblock : '';
- if ( $.getCSS(this,"display") == "none" ) {
- this.style.display = 'block';
- }
- });
- },
- hide: function(a) {
- return this.each(function(){
- this.$$oldblock = $.getCSS(this,"display");
- if ( this.$$oldblock == "none" ) {
- this.$$oldblock = 'block';
- }
- this.style.display = 'none';
- });
- },
- addClass: function(c) {
- return this.each(function(){
- if ($.hasWord(this,c)) {
- return null;
- }
- this.className += ( this.className.length > 0 ? " " : "" ) + c;
- });
- },
- removeClass: function(c) {
- return this.each(function(){
- this.className = !c ? '' :
- this.className.replace(
- new RegExp('(^|\\s*\\b[^-])'+c+'($|\\b(?=[^-]))', 'g'), '');
- });
- },
- // TODO: Optomize
- toggleClass: function(c) {
- return this.each(function(){
- if ($.hasWord(this,c)) {
- this.className =
- this.className.replace(
- new RegExp('(\\s*\\b[^-])'+c+'($|\\b(?=[^-]))', 'g'), '');
- } else {
- this.className += ( this.className.length > 0 ? " " : "" ) + c;
- }
- });
- },
- remove: function() {
- this.each(function(){this.parentNode.removeChild( this );});
- this.cur = [];
- return this;
- },
+ // Wrap each of the matched elements individually
+ return this.each(function(){
+ // Clone the structure that we're using to wrap
+ var b = a[0].cloneNode(true);
+
+ // Insert it before the element to be wrapped
+ this.parentNode.insertBefore( b, this );
+
+ // Find he deepest point in the wrap structure
+ while ( b.firstChild )
+ b = b.firstChild;
+
+ // Move the matched element to within the wrap structure
+ b.appendChild( this );
+ });
+ },
+
+ /**
+ * Append any number of elements to the inside of all matched elements.
+ * This operation is similar to doing an <tt>appendChild</tt> to all the
+ * specified elements, adding them into the document.
+ *
+ * @example $("p").append("<b>Hello</b>");
+ * @before <p>I would like to say: </p>
+ * @result <p>I would like to say: <b>Hello</b></p>
+ *
+ * @name append
+ * @type jQuery
+ * @any String html A string of HTML, that will be created on the fly and appended to the target.
+ * @any Element elem A DOM element that will be appended.
+ * @any Array<Element> elems An array of elements, all of which will be appended.
+ * @any Object obj Any object, converted to a string, then a text node.
+ */
+ append: function() {
+ return this.domManip(arguments, true, 1, function(a){
+ this.appendChild( a );
+ });
+ },
+
+ /**
+ * Prepend any number of elements to the inside of all matched elements.
+ * This operation is the best way to insert a set of elements inside, at the
+ * beginning, of all the matched element.
+ *
+ * @example $("p").prepend("<b>Hello</b>");
+ * @before <p>, how are you?</p>
+ * @result <p><b>Hello</b>, how are you?</p>
+ *
+ * @name prepend
+ * @type jQuery
+ * @any String html A string of HTML, that will be created on the fly and prepended to the target.
+ * @any Element elem A DOM element that will be prepended.
+ * @any Array<Element> elems An array of elements, all of which will be prepended.
+ * @any Object obj Any object, converted to a string, then a text node.
+ */
+ prepend: function() {
+ return this.domManip(arguments, true, -1, function(a){
+ this.insertBefore( a, this.firstChild );
+ });
+ },
+
+ /**
+ * Insert any number of elements before each of the matched elements.
+ *
+ * @example $("p").before("<b>Hello</b>");
+ * @before <p>how are you?</p>
+ * @result <b>Hello</b><p>how are you?</p>
+ *
+ * @name before
+ * @type jQuery
+ * @any String html A string of HTML, that will be created on the fly and inserted.
+ * @any Element elem A DOM element that will beinserted.
+ * @any Array<Element> elems An array of elements, all of which will be inserted.
+ * @any Object obj Any object, converted to a string, then a text node.
+ */
+ before: function() {
+ return this.domManip(arguments, false, 1, function(a){
+ this.parentNode.insertBefore( a, this );
+ });
+ },
+
+ /**
+ * Insert any number of elements after each of the matched elements.
+ *
+ * @example $("p").after("<p>I'm doing fine.</p>");
+ * @before <p>How are you?</p>
+ * @result <p>How are you?</p><p>I'm doing fine.</p>
+ *
+ * @name after
+ * @type jQuery
+ * @any String html A string of HTML, that will be created on the fly and inserted.
+ * @any Element elem A DOM element that will beinserted.
+ * @any Array<Element> elems An array of elements, all of which will be inserted.
+ * @any Object obj Any object, converted to a string, then a text node.
+ */
+ after: function() {
+ return this.domManip(arguments, false, -1, function(a){
+ this.parentNode.insertBefore( a, this.nextSibling );
+ });
+ },
+
+ /**
+ * End the most recent 'destructive' operation, reverting the list of matched elements
+ * back to its previous state. After an end operation, the list of matched elements will
+ * revert to the last state of matched elements.
+ *
+ * @example $("p").find("span").end();
+ * @before <p><span>Hello</span>, how are you?</p>
+ * @result $("p").find("span").end() == [ <p>...</p> ]
+ *
+ * @name end
+ * @type jQuery
+ */
+ end: function() {
+ return this.get( this.stack.pop() );
+ },
+
+ /**
+ * Searches for all elements that match the specified expression.
+ * This method is the optimal way of finding additional descendant
+ * elements with which to process.
+ *
+ * All searching is done using a jQuery expression. The expression can be
+ * written using CSS 1-3 Selector syntax, or basic XPath.
+ *
+ * @example $("p").find("span");
+ * @before <p><span>Hello</span>, how are you?</p>
+ * @result $("p").find("span") == [ <span>Hello</span> ]
+ *
+ * @name find
+ * @type jQuery
+ * @param String expr An expression to search with.
+ */
+ find: function(t) {
+ return this.pushStack( jQuery.map( this, function(a){
+ return jQuery.find(t,a);
+ }), arguments );
+ },
+
+ /**
+ * Removes all elements from the set of matched elements that do not
+ * match the specified expression. This method is used to narrow down
+ * the results of a search.
+ *
+ * All searching is done using a jQuery expression. The expression
+ * can be written using CSS 1-3 Selector syntax, or basic XPath.
+ *
+ * @example $("p").filter(".selected")
+ * @before <p class="selected">Hello</p><p>How are you?</p>
+ * @result $("p").filter(".selected") == [ <p class="selected">Hello</p> ]
+ *
+ * @name filter
+ * @type jQuery
+ * @param String expr An expression to search with.
+ */
+
+ /**
+ * Removes all elements from the set of matched elements that do not
+ * match at least one of the expressions passed to the function. This
+ * method is used when you want to filter the set of matched elements
+ * through more than one expression.
+ *
+ * Elements will be retained in the jQuery object if they match at
+ * least one of the expressions passed.
+ *
+ * @example $("p").filter([".selected", ":first"])
+ * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>
+ * @result $("p").filter([".selected", ":first"]) == [ <p>Hello</p>, <p class="selected">And Again</p> ]
+ *
+ * @name filter
+ * @type jQuery
+ * @param Array<String> exprs A set of expressions to evaluate against
+ */
+ filter: function(t) {
+ return this.pushStack(
+ t.constructor == Array &&
+ jQuery.map(this,function(a){
+ for ( var i = 0; i < t.length; i++ )
+ if ( jQuery.filter(t[i],[a]).r.length )
+ return a;
+ }) ||
+
+ t.constructor == Boolean &&
+ ( t ? this.get() : [] ) ||
+
+ t.constructor == Function &&
+ jQuery.grep( this, t ) ||
+
+ jQuery.filter(t,this).r, arguments );
+ },
+
+ /**
+ * Removes the specified Element from the set of matched elements. This
+ * method is used to remove a single Element from a jQuery object.
+ *
+ * @example $("p").not( document.getElementById("selected") )
+ * @before <p>Hello</p><p id="selected">Hello Again</p>
+ * @result [ <p>Hello</p> ]
+ *
+ * @name not
+ * @type jQuery
+ * @param Element el An element to remove from the set
+ */
+
+ /**
+ * Removes elements matching the specified expression from the set
+ * of matched elements. This method is used to remove one or more
+ * elements from a jQuery object.
+ *
+ * @example $("p").not("#selected")
+ * @before <p>Hello</p><p id="selected">Hello Again</p>
+ * @result [ <p>Hello</p> ]
+ *
+ * @name not
+ * @type jQuery
+ * @param String expr An expression with which to remove matching elements
+ */
+ not: function(t) {
+ return this.pushStack( t.constructor == String ?
+ jQuery.filter(t,this,false).r :
+ jQuery.grep(this,function(a){ return a != t; }), arguments );
+ },
+
+ /**
+ * Adds the elements matched by the expression to the jQuery object. This
+ * can be used to concatenate the result sets of two expressions.
+ *
+ * @example $("p").add("span")
+ * @before <p>Hello</p><p><span>Hello Again</span></p>
+ * @result [ <p>Hello</p>, <span>Hello Again</span> ]
+ *
+ * @name add
+ * @type jQuery
+ * @param String expr An expression whose matched elements are added
+ */
+
+ /**
+ * Adds each of the Elements in the array to the set of matched elements.
+ * This is used to add a set of Elements to a jQuery object.
+ *
+ * @example $("p").add([document.getElementById("a"), document.getElementById("b")])
+ * @before <p>Hello</p><p><span id="a">Hello Again</span><span id="b">And Again</span></p>
+ * @result [ <p>Hello</p>, <span id="a">Hello Again</span>, <span id="b">And Again</span> ]
+ *
+ * @name add
+ * @type jQuery
+ * @param Array<Element> els An array of Elements to add
+ */
+
+ /**
+ * Adds a single Element to the set of matched elements. This is used to
+ * add a single Element to a jQuery object.
+ *
+ * @example $("p").add( document.getElementById("a") )
+ * @before <p>Hello</p><p><span id="a">Hello Again</span></p>
+ * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ]
+ *
+ * @name add
+ * @type jQuery
+ * @param Element el An Element to add
+ */
+ add: function(t) {
+ return this.pushStack( jQuery.merge( this, t.constructor == String ?
+ jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
+ },
+
+ /**
+ * A wrapper function for each() to be used by append and prepend.
+ * Handles cases where you're trying to modify the inner contents of
+ * a table, when you actually need to work with the tbody.
+ *
+ * @member jQuery
+ * @param {String} expr The expression with which to filter
+ * @type Boolean
+ */
+ is: function(expr) {
+ return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
+ },
+
+ /**
+ *
+ *
+ * @private
+ * @name domManip
+ * @param Array args
+ * @param Boolean table
+ * @param Number int
+ * @param Function fn The function doing the DOM manipulation.
+ * @type jQuery
+ */
+ domManip: function(args, table, dir, fn){
+ var clone = this.size() > 1;
+ var a = jQuery.clean(args);