Skip to content
Browse files

Version 0.7.0: Enable dj() to be the wrapper. dj() is now a function …

…whereas in 0.6 it was an object.
  • Loading branch information...
1 parent 8988f43 commit 9e2a5da9ed74b23a6ae0ea337ee0b60dbd398e99 @ryanve committed Jan 8, 2013
Showing with 80 additions and 16 deletions.
  1. +71 −8 dj.js
  2. +7 −6 dj.min.js
  3. +1 −1 ender.js
  4. +1 −1 package.json
View
79 dj.js
@@ -4,7 +4,7 @@
* @author Ryan Van Etten (c) 2012
* @link http://github.com/ryanve/dj
* @license MIT
- * @version 0.6.1
+ * @version 0.7.0
*/
/*jslint browser: true, devel: true, node: true, passfail: false, bitwise: true
@@ -18,7 +18,9 @@
} else { root[name] = root[name] || factory(); } // browser
}(this, 'dj', function () {
- var OP = Object.prototype
+ var hook
+ , methods
+ , OP = Object.prototype
, owns = OP.hasOwnProperty
, gnd = (function () {
@@ -70,8 +72,61 @@
object["__proto__"] = parent; // ensure `Object.getPrototypeOf` will work in IE
return object;
}
-
;
+
+ /**
+ * Logic for discerning arrays/arr-like object from other objects or types.
+ * If `o` is a valid "object" w/ a non-NaN "number" length prop, it returns
+ * the length. Otherwise it returns undefined.
+ * @param {*} o is the object (or unknown) in question
+ * @return {number|undefined}
+ */
+ function count (o) {// inlined @ minification
+ if ( !o || typeof o != 'object' || o.nodeType > 0 || o === window ) return
+ if ( typeof (o = o.length) == 'number' && o === o ) return o
+ }
+
+ /**
+ * $()
+ * @param {*=} item CSS selector | DOM node(s) | fn to fire | anything
+ * @param {Object=} root node(s) from which to base selector queries
+ * @return {Dj}
+ */
+ function dj (item, root) {
+ return new Dj(item, root)
+ }
+
+ /**
+ * @constructor
+ * @param {*=} item CSS selector | DOM node(s) | fn to fire | anything
+ * @param {Object=} root node(s) from which to base selector queries
+ * adapted from jQuery and ender
+ */
+ function Dj (item, root) {
+ var i
+ this.length = 0 // Ensure `this` owns "length" like a real array
+ // The check sequence here is designed to maximize extendabilty
+ // Start @ strings so the result parlays into the subsequent checks
+ if (typeof item == 'string') // Only set .selector for strings
+ item = hook('select')(this['selector'] = item, root)
+ if (null == item) // wrap any item *except* null|undefined
+ return this
+ if (typeof item == 'function') // designed for closure or ready shortcut
+ hook('closure')(item, root)
+ else if ((i = count(item)) == null) // node | scalar | not arr-like
+ this[this.length++] = item
+ else for (this.length = i = i > 0 ? i >> 0 : 0; i--;) // Array-like
+ this[i] = item[i]
+ // The bitwise >> 0 in the loop expr ensures this.length is an *integer*
+ // A return `this` is implicit when instantiated via `new`
+ }
+
+ // Allow `$.fn` and `$.prototype` to remain in sync
+ // and make it so `$() instanceof $` is `true`
+ // @link github.com/ender-js/ender-js/pull/17
+ dj.prototype = dj['fn'] = Dj.prototype = {}; // nu(AP)
+
+ dj['fn']['$'] = dj; // reference to self
/**
* Make new empty object w/ same proto as the `source`. Then
@@ -95,7 +150,7 @@
}
/**
- * Multi-purpose extender/augmenter, with simple yet very useful options, called
+ * Multi-purpose extdj/augmenter, with simple yet very useful options, called
* expand b/c many libs implement extend/augment methods, so this makes it easier
* to integrate ( and drop preconceived notions about what it should do ).
* Expand your mind ;]
@@ -277,7 +332,7 @@
if ( null === k ) { // GET-status-all
return !!info;
}
-
+
// `k` must be "object" if we get to here
if ( info ) {// SET-multi
prefix = typeof v == 'string' ? v : '';
@@ -301,10 +356,13 @@
}// hookRemix
- return {// the export
- 'hook': hookRemix()
- , 'owns' : owns
+ hook = hookRemix();
+
+ methods = {
+ 'hook': hook
+ , 'owns': owns
, 'pro': pro
+ , 'count': count
, 'nu': nu
, 'bridge': bridge
, 'resample': resample
@@ -314,5 +372,10 @@
return bridge.call(subModule, this, force);
}
};
+
+ mixin(dj, methods, true);
+
+ // set the hook and return `dj`
+ return hook('dj', dj);
}));
View
13 dj.min.js
@@ -1,6 +1,7 @@
-/*! dj 0.6.0 | @link github.com/ryanve/dj | @author ryanve | @license MIT */
-(function(k,h,l){"undefined"!=typeof module&&module.exports?module.exports=l():k[h]=k[h]||l()})(this,"dj",function(){function k(a,c,d,e){var b;if(null==a)throw new TypeError("@expand");if(null==c)return a;d=!0===d;e=!0===e?p:e;for(b in c)if(d||null==a[b]&&null!=c[b])if(!e||e.call(c,b))a[b]=c[b];return a}function h(a,c,d){var e,b,f;if(a&&n(this)){c=!0===c;d="function"==typeof d||"object"==typeof d?d:a;for(b in this)if(e=this[b],"function"==typeof e||"object"==typeof e&&e)if("fn"===b&&e!==this)h.call(e,
-a[b],c,d);else if(c?a[b]!==a&&a[b]!==d:null==a[b])f=e.relay,"function"==typeof f&&(f=f.call(e,d,a[b])),!1!==f&&(a[b]=f||e);return a}}function l(){function a(b,f){var i,g,h,b="function"==typeof b?b.call(this,a()):b;if("string"==typeof b||"number"==typeof b){if(void 0===f)return d[b];e&&("function"==typeof f||"object"==typeof f&&"function"!=typeof c[b]?f&&!1!==e[b]&&(d[b]=f,c[b]=c[b]||f):!1===f?e[b]=f:!0===f&&(d[b]=c[b]));return null===f?!1!==e[b]:n(this)||d[b]}if("boolean"==typeof b){if(b){if(e)for(i in d=
-j(null),c)d[i]=c[i]}else e=c=null;b=void 0}if(void 0===b){g=j(null);for(i in d)g[i]=d[i];return g}if(null===b)return!!e;if(e)for(i in h="string"==typeof f?f:"",g="boolean"==typeof f,b)a(h+i,b[i]),g&&a(h+i,f);return n(this)||void 0}var c=j(null),d=j(null),e=j(null);a.remix=l;return a}var r=Object.prototype,p=r.hasOwnProperty,n=function(){var a=this||window;return function(c){return null==c||c===a?0:c}}(),o;var m=Object,q=function(){},g;q.k="object";try{g=m.create(null),o=!g||g.toString||null!==m.getPrototypeOf(g)||
-!m.create([]).pop||!(g=m.create(q))?!1:typeof g===g.k&&m.getPrototypeOf(g)===q}catch(t){o=!1}var s=o&&Object.getPrototypeOf||function(a){return void 0!==a.__proto__?a.__proto__:a.constructor?a.constructor.prototype:r},j=o&&Object.create||function(a){function c(){}var d;if(null===a)return{__proto__:null};c.prototype=a;d=new c;d.__proto__=a;return d};h.relay=!0;return{hook:l(),owns:p,pro:s,nu:j,bridge:h,resample:function(a,c){var d,e;if(!0===a||!arguments.length)a=this;void 0===c&&(c=s(a));e=j(c);for(d in a){if(!p.call(a,
-d))break;e[d]=a[d]}return e},expand:k,mixin:function(a,c,d){if(!n(this))throw new TypeError("@mixin");return k(this,a,c,!1!==d)},submix:function(a,c){return h.call(a,this,c)}}});
+/*! dj 0.7.0 | @link github.com/ryanve/dj | @author ryanve | @license MIT */
+(function(l,g,m){"undefined"!=typeof module&&module.exports?module.exports=m():l[g]=l[g]||m()})(this,"dj",function(){function l(a){if(a&&!("object"!=typeof a||0<a.nodeType||a===window))if("number"==typeof(a=a.length)&&a===a)return a}function g(a,d){return new m(a,d)}function m(a,d){var c;this.length=0;"string"==typeof a&&(a=n("select")(this.selector=a,d));if(null==a)return this;if("function"==typeof a)n("closure")(a,d);else if(null==(c=l(a)))this[this.length++]=a;else for(this.length=c=0<c?c>>0:0;c--;)this[c]=
+a[c]}function v(a,d,c,e){var b;if(null==a)throw new TypeError("@expand");if(null==d)return a;c=!0===c;e=!0===e?t:e;for(b in d)if(c||null==a[b]&&null!=d[b])if(!e||e.call(d,b))a[b]=d[b];return a}function w(a,d,c){if(!q(this))throw new TypeError("@mixin");return v(this,a,d,!1!==c)}function r(a,d,c){var e,b,f;if(a&&q(this)){d=!0===d;c="function"==typeof c||"object"==typeof c?c:a;for(b in this)if(e=this[b],"function"==typeof e||"object"==typeof e&&e)if("fn"===b&&e!==this)r.call(e,a[b],d,c);else if(d?a[b]!==
+a&&a[b]!==c:null==a[b])f=e.relay,"function"==typeof f&&(f=f.call(e,c,a[b])),!1!==f&&(a[b]=f||e);return a}}function x(){function a(b,f){var j,g,h;b="function"==typeof b?b.call(this,a()):b;if("string"==typeof b||"number"==typeof b){if(void 0===f)return c[b];e&&("function"==typeof f||"object"==typeof f&&"function"!=typeof d[b]?f&&!1!==e[b]&&(c[b]=f,d[b]=d[b]||f):!1===f?e[b]=f:!0===f&&(c[b]=d[b]));return null===f?!1!==e[b]:q(this)||c[b]}if("boolean"==typeof b){if(b){if(e)for(j in c=k(null),d)c[j]=d[j]}else e=
+d=null;b=void 0}if(void 0===b){g=k(null);for(j in c)g[j]=c[j];return g}if(null===b)return!!e;if(e)for(j in h="string"==typeof f?f:"",g="boolean"==typeof f,b)a(h+j,b[j]),g&&a(h+j,f);return q(this)||void 0}var d=k(null),c=k(null),e=k(null);a.remix=x;return a}var n,y=Object.prototype,t=y.hasOwnProperty,q=function(){var a=this||window;return function(d){return null==d||d===a?0:d}}(),s;var p=Object,u=function(){},h;u.k="object";try{h=p.create(null),s=!h||h.toString||null!==p.getPrototypeOf(h)||!p.create([]).pop||
+!(h=p.create(u))?!1:typeof h===h.k&&p.getPrototypeOf(h)===u}catch(A){s=!1}var z=s&&Object.getPrototypeOf||function(a){return void 0!==a.__proto__?a.__proto__:a.constructor?a.constructor.prototype:y},k=s&&Object.create||function(a){function d(){}var c;if(null===a)return{__proto__:null};d.prototype=a;c=new d;c.__proto__=a;return c};g.prototype=g.fn=m.prototype={};g.fn.$=g;r.relay=!0;n=x();w(g,{hook:n,owns:t,pro:z,count:l,nu:k,bridge:r,resample:function(a,d){var c,e;if(!0===a||!arguments.length)a=this;
+void 0===d&&(d=z(a));e=k(d);for(c in a){if(!t.call(a,c))break;e[c]=a[c]}return e},expand:v,mixin:w,submix:function(a,d){return r.call(a,this,d)}},!0);return n("dj",g)});
View
2 ender.js
@@ -1,2 +1,2 @@
-// bridge file for ender.no.de
+// bridge file for ender.jit.su
require('dj')['bridge'](ender);
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "dj",
"description": "remixable hook/bridge/relay API for writing extendable modular JavaScript",
- "version": "0.6.1",
+ "version": "0.7.0",
"homepage": "https://github.com/ryanve/dj",
"author": "Ryan Van Etten <@ryanve>",
"keywords": ["extension", "integration", "hook", "bridge", "ender", "jam", "javascript", "js"],

0 comments on commit 9e2a5da

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