Permalink
Browse files

make note in readme about parents method

  • Loading branch information...
1 parent 746683e commit df47cbe233a59dbdc5701c5ca3e71dbbadf7a2d5 @ded committed Apr 21, 2011
Showing with 44 additions and 67 deletions.
  1. +1 −0 .gitignore
  2. +10 −2 README.md
  3. +4 −24 bonzo.js
  4. +1 −1 bonzo.min.js
  5. +7 −3 integration/integration.html
  6. +2 −2 make/build.js
  7. +1 −1 package.json
  8. +4 −24 src/bonzo.js
  9. +14 −10 src/ender.js
View
1 .gitignore
@@ -0,0 +1 @@
+node_modules
View
12 README.md
@@ -94,6 +94,10 @@ All other API methods
* bonzo.isAncestor(container, child)
* bonzo.noConflict
+Added in the Ender bridge
+
+ * parents(selector)
+
The name Bonzo
--------------
Bonzo Madrid was a malicious battle school commander of whom eventually is killed by [Ender Wiggin](http://en.wikipedia.org/wiki/Ender_Wiggin). Bonzo represents the DOM, of whom we'd all love to slay.
@@ -116,9 +120,13 @@ Tests
Ender integration
----------
-Bonzo fits in nicely with the Ender framework. To combine Bonzo to your Ender build, you can add it as such:
+Bonzo is a registered npm package and fits in nicely with the Ender framework. To combine Bonzo to your Ender build, you can add it as such:
+
+ $ ender build bonzo[,modb, modc,...]
+
+or, add it to your existing ender package
- $ ender -b bonzo[,modb, modc,...]
+ $ ender add bonzo
Contributors
-----
View
28 bonzo.js
@@ -78,22 +78,11 @@
},
first: function () {
- this.elements = [this[0]];
- this.each(function (el, i) {
- i && (delete this[i]);
- });
- this.length = 1;
- return this;
+ return bonzo(this[0]);
},
last: function () {
- this.elements = [this[this.length - 1]];
- this[0] = this.elements[0];
- this.each(function (el, i) {
- i && (delete this[i]);
- });
- this.length = 1;
- return this;
+ return bonzo(this[this.length - 1]);
},
html: function (html) {
@@ -176,8 +165,7 @@
},
related: function (method) {
- var i, l;
- this.elements = this.map(
+ return bonzo(this.map(
function (el) {
el = el[method];
while (el && el.nodeType !== 1) {
@@ -188,15 +176,7 @@
function (el) {
return el;
}
- );
- for (i = 0, l = this.length; i < l; i++) {
- delete this[i];
- }
- for (i = 0, l = this.elements.length; i < l; i++) {
- this[i] = this.elements[i];
- }
- this.length = l;
- return this;
+ ));
},
prependTo: function (target) {
View
2 bonzo.min.js
@@ -4,4 +4,4 @@
* Follow our software http://twitter.com/dedfat
* MIT License
*/
-!function(a){function t(a){return new p(a)}function s(){return{x:window.pageXOffset||c.scrollLeft,y:window.pageYOffset||c.scrollTop}}function r(a){return a===window||/^(?:body|html)$/i.test(a.tagName)}function q(a,b,c){var d=this.elements[0];if(a==null&&b==null)return(r(d)?s():{x:d.scrollLeft,y:d.scrollTop})[c];r(d)?window.scrollTo(a,b):(a!=null&&(d.scrollLeft=a),b!=null&&(d.scrollTop=b));return this}function p(a){this.elements=[],this.length=0;if(a){this.elements=Object.prototype.hasOwnProperty.call(a,"length")?a:[a],this.length=this.elements.length;for(var b=0;b<this.length;b++)this[b]=this.elements[b]}}function o(a,b,c){for(var d=0,e=a.length;d<e;++d)if(b.call(c,a[d],d,a))return!0;return!1}function n(a){return a&&a.nodeName&&a.nodeType==1}function m(a){return a.replace(/-(.)/g,function(a,b){return b.toUpperCase()})}function l(a){return a.replace(/(^\s*|\s*$)/g,"")}function k(a,b){for(i=0,len=a.length;i<len;i++)b(a[i])}function j(a){return new RegExp("(^|\\s+)"+a+"(\\s+|$)")}var b=document,c=b.documentElement,d=/^checked|value|selected$/,e=/^checked|selected$/,f=/msie/.test(navigator.userAgent),g=[],h=0;p.prototype={each:function(a){for(var b=0,c=this.length;b<c;b++)a.call(this,this[b],b);return this},map:function(a,b){var c=[],d;for(var e=0;e<this.length;e++)d=a.call(this,this[e]),b?b(d)&&c.push(d):c.push(d);return c},first:function(){this.elements=[this[0]],this.each(function(a,b){b&&delete this[b]}),this.length=1;return this},last:function(){this.elements=[this[this.length-1]],this[0]=this.elements[0],this.each(function(a,b){b&&delete this[b]}),this.length=1;return this},html:function(a){return typeof a=="string"?this.each(function(b){b.innerHTML=a}):this.elements[0]?this.elements[0].innerHTML:""},addClass:function(a){return this.each(function(b){this.hasClass(b,a)||(b.className=l(b.className+" "+a))})},removeClass:function(a){return this.each(function(b){this.hasClass(b,a)&&(b.className=l(b.className.replace(j(a)," ")))})},hasClass:function(a,b){return typeof b=="undefined"?o(this.elements,function(b){return j(a).test(b.className)}):j(b).test(a.className)},toggleClass:function(a){return this.each(function(b){this.hasClass(b,a)?b.className=l(b.className.replace(j(a)," ")):b.className=l(b.className+" "+a)})},show:function(a){return this.each(function(a){a.style.display=""})},hide:function(a){return this.each(function(a){a.style.display="none"})},append:function(a){return this.each(function(b){k(t.create(a),function(a){b.appendChild(a)})})},prepend:function(a){return this.each(function(b){var c=b.firstChild;k(t.create(a),function(a){b.insertBefore(a,c)})})},appendTo:function(a){return this.each(function(b){a.appendChild(b)})},next:function(){return this.related("nextSibling")},previous:function(){return this.related("previousSibling")},related:function(a){var b,c;this.elements=this.map(function(b){b=b[a];while(b&&b.nodeType!==1)b=b[a];return b||0},function(a){return a});for(b=0,c=this.length;b<c;b++)delete this[b];for(b=0,c=this.elements.length;b<c;b++)this[b]=this.elements[b];this.length=c;return this},prependTo:function(a){return this.each(function(b){a.insertBefore(b,t.firstChild(a))})},before:function(a){return this.each(function(b){k(t.create(a),function(a){b.parentNode.insertBefore(a,b)})})},after:function(a){return this.each(function(b){k(t.create(a),function(a){b.parentNode.insertBefore(a,b.nextSibling)})})},css:function(a,b){if(b===undefined&&typeof a=="string")return this[0].style[m(a)];var c=typeof a=="string"?function(c){c.style[m(a)]=b}:function(b){for(var c in a)a.hasOwnProperty(c)&&(b.style[m(c)]=a[c])};return this.each(c)},offset:function(){var a=this.elements[0],b=a.offsetWidth,c=a.offsetHeight,d=a.offsetTop,e=a.offsetLeft;while(a=a.offsetParent)d=d+a.offsetTop,e=e+a.offsetLeft;return{top:d,left:e,height:c,width:b}},attr:function(a,b){var c=this.elements[0];return typeof b=="undefined"?d.test(a)?e.test(a)&&typeof c[a]=="string"?!0:c[a]:c.getAttribute(a):this.each(function(c){c.setAttribute(a,b)})},removeAttr:function(a){return this.each(function(b){b.removeAttribute(a)})},data:function(a,b){var c=this.elements[0];if(typeof b=="undefined"){c.getAttribute("data-node-uid")||c.setAttribute("data-node-uid",++h);var d=c.getAttribute("data-node-uid");g[d]||(g[d]={});return g[d][a]}return this.each(function(c){c.getAttribute("data-node-uid")||c.setAttribute("data-node-uid",++h);var d=c.getAttribute("data-node-uid"),e={};e[a]=b,g[d]=e})},remove:function(){return this.each(function(a){a.parentNode&&a.parentNode.removeChild(a)})},empty:function(){return this.each(function(a){while(a.firstChild)a.removeChild(a.firstChild)})},detach:function(){return this.map(function(a){return a.parentNode.removeChild(a)})},scrollTop:function(a){return q.call(this,null,a,"y")},scrollLeft:function(a){return q.call(this,a,null,"x")}},t.aug=function(a,b){for(var c in a)a.hasOwnProperty(c)&&((b||p.prototype)[c]=a[c])},t.create=function(a){return typeof a=="string"?function(){var c=b.createElement("div"),d=[];c.innerHTML=a;var e=c.childNodes;c=c.firstChild,d.push(c);while(c=c.nextSibling)c.nodeType==1&&d.push(c);return d}():n(a)?[a.cloneNode(!0)]:[]},t.doc=function(){var a=c.scrollWidth,b=c.scrollHeight,d=this.viewport();return{width:Math.max(a,d.width),height:Math.max(b,d.height)}},t.firstChild=function(a){for(var b=a.childNodes,c=0,d=b&&b.length||0,e;c<d;c++)b[c].nodeType===1&&(e=b[d=c]);return e},t.viewport=function(){var a=self.innerHeight,b=self.innerWidth;f&&(a=c.clientHeight)&&(b=c.clientWidth);return{width:b,height:a}},t.isAncestor="compareDocumentPosition"in c?function(a,b){return(a.compareDocumentPosition(b)&16)==16}:"contains"in c?function(a,b){return a!==b&&a.contains(b)}:function(a,b){while(b=b.parentNode)if(b===a)return!0;return!1};var u=a.bonzo;t.noConflict=function(){a.bonzo=u;return this},a.bonzo=t}(this)
+!function(a){function t(a){return new p(a)}function s(){return{x:window.pageXOffset||c.scrollLeft,y:window.pageYOffset||c.scrollTop}}function r(a){return a===window||/^(?:body|html)$/i.test(a.tagName)}function q(a,b,c){var d=this.elements[0];if(a==null&&b==null)return(r(d)?s():{x:d.scrollLeft,y:d.scrollTop})[c];r(d)?window.scrollTo(a,b):(a!=null&&(d.scrollLeft=a),b!=null&&(d.scrollTop=b));return this}function p(a){this.elements=[],this.length=0;if(a){this.elements=Object.prototype.hasOwnProperty.call(a,"length")?a:[a],this.length=this.elements.length;for(var b=0;b<this.length;b++)this[b]=this.elements[b]}}function o(a,b,c){for(var d=0,e=a.length;d<e;++d)if(b.call(c,a[d],d,a))return!0;return!1}function n(a){return a&&a.nodeName&&a.nodeType==1}function m(a){return a.replace(/-(.)/g,function(a,b){return b.toUpperCase()})}function l(a){return a.replace(/(^\s*|\s*$)/g,"")}function k(a,b){for(i=0,len=a.length;i<len;i++)b(a[i])}function j(a){return new RegExp("(^|\\s+)"+a+"(\\s+|$)")}var b=document,c=b.documentElement,d=/^checked|value|selected$/,e=/^checked|selected$/,f=/msie/.test(navigator.userAgent),g=[],h=0;p.prototype={each:function(a){for(var b=0,c=this.length;b<c;b++)a.call(this,this[b],b);return this},map:function(a,b){var c=[],d;for(var e=0;e<this.length;e++)d=a.call(this,this[e]),b?b(d)&&c.push(d):c.push(d);return c},first:function(){return t(this[0])},last:function(){return t(this[this.length-1])},html:function(a){return typeof a=="string"?this.each(function(b){b.innerHTML=a}):this.elements[0]?this.elements[0].innerHTML:""},addClass:function(a){return this.each(function(b){this.hasClass(b,a)||(b.className=l(b.className+" "+a))})},removeClass:function(a){return this.each(function(b){this.hasClass(b,a)&&(b.className=l(b.className.replace(j(a)," ")))})},hasClass:function(a,b){return typeof b=="undefined"?o(this.elements,function(b){return j(a).test(b.className)}):j(b).test(a.className)},toggleClass:function(a){return this.each(function(b){this.hasClass(b,a)?b.className=l(b.className.replace(j(a)," ")):b.className=l(b.className+" "+a)})},show:function(a){return this.each(function(a){a.style.display=""})},hide:function(a){return this.each(function(a){a.style.display="none"})},append:function(a){return this.each(function(b){k(t.create(a),function(a){b.appendChild(a)})})},prepend:function(a){return this.each(function(b){var c=b.firstChild;k(t.create(a),function(a){b.insertBefore(a,c)})})},appendTo:function(a){return this.each(function(b){a.appendChild(b)})},next:function(){return this.related("nextSibling")},previous:function(){return this.related("previousSibling")},related:function(a){return t(this.map(function(b){b=b[a];while(b&&b.nodeType!==1)b=b[a];return b||0},function(a){return a}))},prependTo:function(a){return this.each(function(b){a.insertBefore(b,t.firstChild(a))})},before:function(a){return this.each(function(b){k(t.create(a),function(a){b.parentNode.insertBefore(a,b)})})},after:function(a){return this.each(function(b){k(t.create(a),function(a){b.parentNode.insertBefore(a,b.nextSibling)})})},css:function(a,b){if(b===undefined&&typeof a=="string")return this[0].style[m(a)];var c=typeof a=="string"?function(c){c.style[m(a)]=b}:function(b){for(var c in a)a.hasOwnProperty(c)&&(b.style[m(c)]=a[c])};return this.each(c)},offset:function(){var a=this.elements[0],b=a.offsetWidth,c=a.offsetHeight,d=a.offsetTop,e=a.offsetLeft;while(a=a.offsetParent)d=d+a.offsetTop,e=e+a.offsetLeft;return{top:d,left:e,height:c,width:b}},attr:function(a,b){var c=this.elements[0];return typeof b=="undefined"?d.test(a)?e.test(a)&&typeof c[a]=="string"?!0:c[a]:c.getAttribute(a):this.each(function(c){c.setAttribute(a,b)})},removeAttr:function(a){return this.each(function(b){b.removeAttribute(a)})},data:function(a,b){var c=this.elements[0];if(typeof b=="undefined"){c.getAttribute("data-node-uid")||c.setAttribute("data-node-uid",++h);var d=c.getAttribute("data-node-uid");g[d]||(g[d]={});return g[d][a]}return this.each(function(c){c.getAttribute("data-node-uid")||c.setAttribute("data-node-uid",++h);var d=c.getAttribute("data-node-uid"),e={};e[a]=b,g[d]=e})},remove:function(){return this.each(function(a){a.parentNode&&a.parentNode.removeChild(a)})},empty:function(){return this.each(function(a){while(a.firstChild)a.removeChild(a.firstChild)})},detach:function(){return this.map(function(a){return a.parentNode.removeChild(a)})},scrollTop:function(a){return q.call(this,null,a,"y")},scrollLeft:function(a){return q.call(this,a,null,"x")}},t.aug=function(a,b){for(var c in a)a.hasOwnProperty(c)&&((b||p.prototype)[c]=a[c])},t.create=function(a){return typeof a=="string"?function(){var c=b.createElement("div"),d=[];c.innerHTML=a;var e=c.childNodes;c=c.firstChild,d.push(c);while(c=c.nextSibling)c.nodeType==1&&d.push(c);return d}():n(a)?[a.cloneNode(!0)]:[]},t.doc=function(){var a=c.scrollWidth,b=c.scrollHeight,d=this.viewport();return{width:Math.max(a,d.width),height:Math.max(b,d.height)}},t.firstChild=function(a){for(var b=a.childNodes,c=0,d=b&&b.length||0,e;c<d;c++)b[c].nodeType===1&&(e=b[d=c]);return e},t.viewport=function(){var a=self.innerHeight,b=self.innerWidth;f&&(a=c.clientHeight)&&(b=c.clientWidth);return{width:b,height:a}},t.isAncestor="compareDocumentPosition"in c?function(a,b){return(a.compareDocumentPosition(b)&16)==16}:"contains"in c?function(a,b){return a!==b&&a.contains(b)}:function(a,b){while(b=b.parentNode)if(b===a)return!0;return!1};var u=a.bonzo;t.noConflict=function(){a.bonzo=u;return this},a.bonzo=t}(this)
View
10 integration/integration.html
@@ -9,10 +9,14 @@
<script src="../src/ender.js"></script>
<script type="text/javascript">
$.domReady(function () {
- var el1 = $('li').first().css('color', 'red').next().css('color', 'blue');
- var el2 = $('li').last().css('color', 'green');
+ var li = $('li');
+ var el1 = li.first().css('color', 'red').next().css('color', 'blue');
+ var el2 = li.last().css('color', 'green');
$('input[type=text]').attr('value', 'hello');
- $('#get-me').parents('div.robustr').addClass('aloha');
+ var getme = $('#get-me');
+ var parents = getme.parents('div.robustr').addClass('aloha');
+ console.log(getme.length);
+ console.log(parents.length);
});
</script>
</head>
View
4 make/build.js
@@ -1,4 +1,4 @@
-require('../build/smoosh').config({
+require('smoosh').config({
"JAVASCRIPT": {
"DIST_DIR": "./",
"bonzo": [
@@ -8,7 +8,7 @@ require('../build/smoosh').config({
},
"JSHINT_OPTS": {
"boss": true,
- "forin": true,
+ "forin": false,
"curly": true,
"debug": false,
"devel": false,
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "bonzo",
"description": "simple, hassle-free, library agnostic, extensible DOM utility",
- "version": "0.0.17",
+ "version": "0.1.0",
"homepage": "https://github.com/ded/bonzo",
"authors": ["Dustin Diaz <@ded>", "Jacob Thornton <@fat>"],
"repository": {
View
28 src/bonzo.js
@@ -72,22 +72,11 @@
},
first: function () {
- this.elements = [this[0]];
- this.each(function (el, i) {
- i && (delete this[i]);
- });
- this.length = 1;
- return this;
+ return bonzo(this[0]);
},
last: function () {
- this.elements = [this[this.length - 1]];
- this[0] = this.elements[0];
- this.each(function (el, i) {
- i && (delete this[i]);
- });
- this.length = 1;
- return this;
+ return bonzo(this[this.length - 1]);
},
html: function (html) {
@@ -170,8 +159,7 @@
},
related: function (method) {
- var i, l;
- this.elements = this.map(
+ return bonzo(this.map(
function (el) {
el = el[method];
while (el && el.nodeType !== 1) {
@@ -182,15 +170,7 @@
function (el) {
return el;
}
- );
- for (i = 0, l = this.length; i < l; i++) {
- delete this[i];
- }
- for (i = 0, l = this.elements.length; i < l; i++) {
- this[i] = this.elements[i];
- }
- this.length = l;
- return this;
+ ));
},
prependTo: function (target) {
View
24 src/ender.js
@@ -7,6 +7,19 @@
return $(b.create(node));
}
});
+ function uniq(ar) {
+ var a = [], i, j;
+ label:
+ for (i = 0; i < ar.length; i++) {
+ for (j = 0; j < a.length; j++) {
+ if (a[j] == ar[i]) {
+ continue label;
+ }
+ }
+ a[a.length] = ar[i];
+ }
+ return a;
+ }
$.ender({
parents: function (selector) {
var collection = $(selector), i, l, j, k, r = [];
@@ -19,17 +32,8 @@
}
}
}
- this.elements = [];
- for (i = 0, l = this.length; i < l; i++) {
- delete this[i];
- }
- for (i = 0, l = r.length; i < l; i++) {
- this[i] = r[i];
- }
- this.length = r.length;
- return this;
+ return b(uniq(collection));
}
}, true);
}();
-

0 comments on commit df47cbe

Please sign in to comment.