Skip to content
Browse files

fix array reverse, cleanups

  • Loading branch information...
2 parents d92e43d + 01d43d2 commit 04ff9c0fd69ddbe526d0b137003ce3fad3efb405 @madrobby committed Jan 21, 2011
Showing with 44 additions and 3 deletions.
  1. +1 −1 README.rdoc
  2. +10 −2 src/zepto.js
  3. +33 −0 test/zepto.html
View
2 README.rdoc
@@ -58,7 +58,7 @@ Context and .find calls are equivalent:
html('new html'): set the contents of the element(s)
text('new text'): set the text contents of the element(s)
- append, prepend, before, after: like html, but add html to element contents (or before/after)
+ append, prepend, before, after: like html(), but add html (or a DOM Element or a Zepto object) to element contents (or before/after)
html(): get first element's .innerHTML
text(): get first element's .innerText
show(): forces elements to be displayed (only works correctly for block elements right now)
View
12 src/zepto.js
@@ -182,8 +182,16 @@ var Zepto = (function() {
for (key in adjacencyOperators)
$.fn[key] = (function(operator) {
return function(html){
- return this.each(function(){
- this['insertAdjacent' + (html instanceof Element ? 'Element' : 'HTML')](operator, html);
+ return this.each(function(index, element){
+ if (html instanceof Z) {
+ dom = html.dom;
+ if (operator == "afterBegin" || operator == "afterEnd")
+ for (var i=0; i<dom.length; i++) element['insertAdjacentElement'](operator, dom[dom.length-i-1]);
+ else
+ for (var i=0; i<dom.length; i++) element['insertAdjacentElement'](operator, dom[i]);
+ } else {
+ element['insertAdjacent'+(html instanceof Element ? 'Element' : 'HTML')](operator, html);
+ }
});
};
})(adjacencyOperators[key]);
View
33 test/zepto.html
@@ -775,6 +775,39 @@
'<div>append</div></div><div>after</div>',
$('#beforeafter_container').html()
);
+
+ //testing with Zepto object as parameter
+ $('#beforeafter_container').html('<div id="beforeafter"></div>');
+
+ $('#beforeafter').append($(div('append')));
+ $('#beforeafter').prepend($(div('prepend')));
+ $('#beforeafter').before($(div('before')));
+ $('#beforeafter').after($(div('after')));
+
+ t.assertEqual(
+ '<div>before</div><div id="beforeafter"><div>prepend</div>'+
+ '<div>append</div></div><div>after</div>',
+ $('#beforeafter_container').html()
+ );
+
+ //testing with a zepto object of more than one element as parameter
+ $(document.body).append('<div class="append">append1</div><div class="append">append2</div>');
+ $(document.body).append('<div class="prepend">prepend1</div><div class="prepend">prepend2</div>');
+ $(document.body).append('<div class="before">before1</div><div class="before">before2</div>');
+ $(document.body).append('<div class="after">after1</div><div class="after">after2</div>');
+
+ $('#beforeafter_container').html('<div id="beforeafter"></div>');
+
+ $('#beforeafter').append($('.append'));
+ $('#beforeafter').prepend($('.prepend'));
+ $('#beforeafter').before($('.before'));
+ $('#beforeafter').after($('.after'));
+
+ t.assertEqual(
+ '<div class="before">before1</div><div class="before">before2</div><div id="beforeafter"><div class="prepend">prepend1</div><div class="prepend">prepend2</div>'+
+ '<div class="append">append1</div><div class="append">append2</div></div><div class="after">after1</div><div class="after">after2</div>',
+ $('#beforeafter_container').html()
+ );
},
testAddRemoveClass: function(t){

0 comments on commit 04ff9c0

Please sign in to comment.
Something went wrong with that request. Please try again.