Permalink
Browse files

WIP

  • Loading branch information...
1 parent 8e14ed6 commit b55fea22f1e4a6476d2091ae26244db5ded98d1a Couto committed Aug 7, 2012
Showing with 105 additions and 13 deletions.
  1. +1 −1 README.md
  2. +49 −5 dist/callipygean.js
  3. +2 −1 dist/callipygean.min.js
  4. +1 −0 lib/callipygean.js
  5. +32 −5 lib/utils.js
  6. +1 −1 package.json
  7. +19 −0 test/utils.test.js
View
@@ -72,4 +72,4 @@ _(Nothing yet)_
## License
Copyright (c) 2012 Couto
-Licensed under the MIT license.
+Licensed under the [MIT license](http://couto.mit-license.org).
View
@@ -7,17 +7,18 @@
*
* Copyright (c) 2012 Couto
* Licensed under the MIT license.
+ * http://couto.mit-license.org
*/
(function (exports) {
'use strict';
/**
-* _
-* Object to collect utility functions
-*
-* @type {Object}
-*/
+ * _
+ * Object to collect utility functions
+ *
+ * @type {Object}
+ */
var _ = {
/**
@@ -63,6 +64,33 @@ var _ = {
return element;
},
+ /**
+ * bind
+ *
+ * @memberOf _
+ * @static
+ *
+ * @param {Function} fn A function whose context is going to be bound
+ * @param {Object} ctx Object that will serve as context
+ * @param {Mixed} [args*] Prearranged arguments
+ * @return {Funciton} A Function bound to the given context with the pre-arranged arguments
+ */
+ bind: (function (bind) {
+ var slice = Array.prototype.slice;
+
+ return (bind && typeof bind === 'function') ?
+ function (fn, ctx) {
+ var args = slice.call(arguments, 2);
+ return bind.apply(fn, [ctx].concat(args));
+ } :
+ function (fn, ctx) {
+ var args = slice.call(arguments, 2);
+ return function () {
+ fn.apply(ctx, args.concat(slice.call(arguments)));
+ };
+ };
+
+ }(Function.prototype.bind)),
/**
* _.is
@@ -324,6 +352,8 @@ var _ = {
}
}(obj, ul, this));
+ this.bindEvents(ul);
+
return ul;
@@ -366,6 +396,20 @@ var _ = {
return type;
+ },
+
+ bindEvents: function (el) {
+ el.addEventListener('click', this._clickHandler);
+ },
+
+ unbindEvents: function (el) {
+ el.removeEventListener('click', this._clickHandler);
+ },
+
+ _clickHandler: function (evt) {
+ if (evt.currentTarget.getAttribute('class').indexOf('expandable') !== -1) {
+ this.expand(evt.currentTarget);
+ }
}
};
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -7,6 +7,7 @@
*
* Copyright (c) 2012 Couto
* Licensed under the MIT license.
+ * http://couto.mit-license.org
*/
(function (exports) {
View
@@ -1,9 +1,9 @@
/**
-* _
-* Object to collect utility functions
-*
-* @type {Object}
-*/
+ * _
+ * Object to collect utility functions
+ *
+ * @type {Object}
+ */
var _ = {
/**
@@ -49,6 +49,33 @@ var _ = {
return element;
},
+ /**
+ * bind
+ *
+ * @memberOf _
+ * @static
+ *
+ * @param {Function} fn A function whose context is going to be bound
+ * @param {Object} ctx Object that will serve as context
+ * @param {Mixed} [args*] Prearranged arguments
+ * @return {Funciton} A Function bound to the given context with the pre-arranged arguments
+ */
+ bind: (function (bind) {
+ var slice = Array.prototype.slice;
+
+ return (bind && typeof bind === 'function') ?
+ function (fn, ctx) {
+ var args = slice.call(arguments, 2);
+ return bind.apply(fn, [ctx].concat(args));
+ } :
+ function (fn, ctx) {
+ var args = slice.call(arguments, 2);
+ return function () {
+ fn.apply(ctx, args.concat(slice.call(arguments)));
+ };
+ };
+
+ }(Function.prototype.bind)),
/**
* _.is
View
@@ -18,7 +18,7 @@
"licenses": [
{
"type": "MIT",
- "url": "https://github.com/Couto/callipygean/blob/master/LICENSE-MIT"
+ "url": "http://couto.mit-license.org"
}
],
"main": "lib/callipygean",
View
@@ -84,6 +84,25 @@ describe('Utils - Test Suite', function () {
}
});
+ describe('bind', function () {
+ it('should return a function', function () {
+ expect(_.bind(function () {}, this)).to.be.a('function');
+ });
+
+ it('should have the right ctx and arguments', function () {
+ var bait = function () {
+ return {
+ context: this,
+ 'arguments': arguments
+ };
+ },
+ testee = _.bind(bait, {'a': 'b'}, 'c', 'd');
+
+ expect(testee().context).to.deep.equal({'a': 'b'});
+ expect(testee(1, 2, 3)['arguments']).to.deep.equal(['c', 'd', 1, 2, 3]);
+ });
+ });
+
describe('is', function () {
describe('Object', function () {

0 comments on commit b55fea2

Please sign in to comment.