Skip to content

Commit

Permalink
removing d --> dojo aliases, plus an unneeded closure, refs #13101 !s…
Browse files Browse the repository at this point in the history
…trict.

git-svn-id: http://svn.dojotoolkit.org/src/dojo/trunk@25327 560b804f-0ae3-0310-86f3-f6aa0a117693
  • Loading branch information
wkeese committed Jun 2, 2011
1 parent df87d5e commit 4b29bee
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 232 deletions.
18 changes: 9 additions & 9 deletions NodeList-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,24 @@ define(["./main"], function(dojo) {
=====*/

var d = dojo, dataCache = {}, x = 0, dataattr = "data-dojo-dataid", nl = d.NodeList,
var dataCache = {}, x = 0, dataattr = "data-dojo-dataid", nl = dojo.NodeList,
dopid = function(node){
// summary: Return a uniqueish ID for the passed node reference
var pid = d.attr(node, dataattr);
var pid = dojo.attr(node, dataattr);
if(!pid){
pid = "pid" + (x++);
d.attr(node, dataattr, pid);
dojo.attr(node, dataattr, pid);
}
return pid;
}
;

//>>excludeStart("debugging", true);
// exposed for unit tests:
d._nodeDataCache = dataCache;
dojo._nodeDataCache = dataCache;
//>>excludeEnd("debugging");

var dodata = d._nodeData = function(node, key, value){
var dodata = dojo._nodeData = function(node, key, value){

var pid = dopid(node), r;
if(!dataCache[pid]){ dataCache[pid] = {}; }
Expand All @@ -103,13 +103,13 @@ define(["./main"], function(dojo) {
}else{
// must be a setter, mix `value` into data hash
// API discrepency: using object as setter works here
r = d._mixin(dataCache[pid], key);
r = dojo._mixin(dataCache[pid], key);
}

return r; // Object|Anything|Nothing
};

var removeData = d._removeNodeData = function(node, key){
var removeData = dojo._removeNodeData = function(node, key){
// summary: Remove some data from this node
// node: String|DomNode
// The node reference to remove data from
Expand All @@ -126,7 +126,7 @@ define(["./main"], function(dojo) {
}
};

d._gcNodeData = function(){
dojo._gcNodeData = function(){
// summary: super expensive: GC all data in the data for nodes that no longer exist in the dom.
// description:
// super expensive: GC all data in the data for nodes that no longer exist in the dom.
Expand All @@ -142,7 +142,7 @@ define(["./main"], function(dojo) {
};

// make nodeData and removeNodeData public on dojo.NodeList:
d.extend(nl, {
dojo.extend(nl, {
data: nl._adaptWithCondition(dodata, function(a){
return a.length === 0 || a.length == 1 && (typeof a[0] == "string");
}),
Expand Down
64 changes: 31 additions & 33 deletions _base/NodeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
// summary:
// This module defines dojo.NodeList.

var d = dojo;

var ap = Array.prototype, aps = ap.slice, apc = ap.concat;

var tnl = function(/*Array*/ a, /*dojo.NodeList?*/ parent, /*Function?*/ NodeListCtor){
Expand All @@ -25,7 +23,7 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
// make sure it's a real array before we pass it on to be wrapped
a = aps.call(a, 0);
}
var ctor = NodeListCtor || this._NodeListCtor || d._NodeListCtor;
var ctor = NodeListCtor || this._NodeListCtor || dojo._NodeListCtor;
a.constructor = ctor;
dojo._mixin(a, ctor.prototype);
a._NodeListCtor = ctor;
Expand All @@ -34,7 +32,7 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){

var loopBody = function(f, a, o){
a = [0].concat(aps.call(a, 0));
o = o || d.global;
o = o || dojo.global;
return function(node){
a[0] = node;
return f.apply(o, a);
Expand Down Expand Up @@ -95,7 +93,7 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
// an optional context for f and g
return function(){
var a = arguments, body = loopBody(f, a, o);
if(g.call(o || d.global, a)){
if(g.call(o || dojo.global, a)){
return this.map(body); // self
}
this.forEach(body);
Expand Down Expand Up @@ -202,9 +200,9 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
};

//Allow things that new up a NodeList to use a delegated or alternate NodeList implementation.
d._NodeListCtor = d.NodeList;
dojo._NodeListCtor = dojo.NodeList;

var nl = d.NodeList, nlp = nl.prototype;
var nl = dojo.NodeList, nlp = nl.prototype;

// expose adapters and the wrapper as private functions

Expand All @@ -217,7 +215,7 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
// mass assignment

// add array redirectors
d.forEach(["slice", "splice"], function(name){
dojo.forEach(["slice", "splice"], function(name){
var f = ap[name];
//Use a copy of the this array via this.slice() to allow .end() to work right in the splice case.
// CANNOT apply ._stash()/end() to splice since it currently modifies
Expand All @@ -228,23 +226,23 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
// concat should be here but some browsers with native NodeList have problems with it

// add array.js redirectors
d.forEach(["indexOf", "lastIndexOf", "every", "some"], function(name){
var f = d[name];
nlp[name] = function(){ return f.apply(d, [this].concat(aps.call(arguments, 0))); };
dojo.forEach(["indexOf", "lastIndexOf", "every", "some"], function(name){
var f = dojo[name];
nlp[name] = function(){ return f.apply(dojo, [this].concat(aps.call(arguments, 0))); };
});

// add conditional methods
d.forEach(["attr", "style"], function(name){
nlp[name] = adaptWithCondition(d[name], magicGuard);
dojo.forEach(["attr", "style"], function(name){
nlp[name] = adaptWithCondition(dojo[name], magicGuard);
});

// add forEach actions
d.forEach(["addClass", "removeClass", "replaceClass", "toggleClass", "empty", "removeAttr"], function(name){
nlp[name] = adaptAsForEach(d[name]);
dojo.forEach(["addClass", "removeClass", "replaceClass", "toggleClass", "empty", "removeAttr"], function(name){
nlp[name] = adaptAsForEach(dojo[name]);
});
// don't bind early to dojo.connect since we no longer explicitly depend on it
nlp.connect = adaptAsForEach(function(){
return d.connect.apply(this, arguments);
return dojo.connect.apply(this, arguments);
});

dojo.extend(dojo.NodeList, {
Expand Down Expand Up @@ -568,9 +566,9 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
// native NodeList and dojo.NodeList in this property to recognize
// the node list.

var t = d.isArray(this) ? this : aps.call(this, 0),
m = d.map(arguments, function(a){
return a && !d.isArray(a) &&
var t = dojo.isArray(this) ? this : aps.call(this, 0),
m = dojo.map(arguments, function(a){
return a && !dojo.isArray(a) &&
(typeof NodeList != "undefined" && a.constructor === NodeList || a.constructor === this._NodeListCtor) ?
aps.call(a, 0) : a;
});
Expand All @@ -583,15 +581,15 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
// array is implicitly this NodeList and the return is a
// dojo.NodeList (a subclass of Array)
///return d.map(this, func, obj, d.NodeList); // dojo.NodeList
return this._wrap(d.map(this, func, obj), this); // dojo.NodeList
return this._wrap(dojo.map(this, func, obj), this); // dojo.NodeList
},

forEach: function(callback, thisObj){
// summary:
// see `dojo.forEach()`. The primary difference is that the acted-on
// array is implicitly this NodeList. If you want the option to break out
// of the forEach loop, use every() or some() instead.
d.forEach(this, callback, thisObj);
dojo.forEach(this, callback, thisObj);
// non-standard return to allow easier chaining
return this; // dojo.NodeList
},
Expand Down Expand Up @@ -724,8 +722,8 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
=====*/

// useful html methods
coords: adaptAsMap(d.coords),
position: adaptAsMap(d.position),
coords: adaptAsMap(dojo.coords),
position: adaptAsMap(dojo.position),

// FIXME: connectPublisher()? connectRunOnce()?

Expand Down Expand Up @@ -755,8 +753,8 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
// | "only"
// | "replace"
// or an offset in the childNodes property
var item = d.query(queryOrNode)[0];
return this.forEach(function(node){ d.place(node, item, position); }); // dojo.NodeList
var item = dojo.query(queryOrNode)[0];
return this.forEach(function(node){ dojo.place(node, item, position); }); // dojo.NodeList
},

orphan: function(/*String?*/ filter){
Expand All @@ -767,7 +765,7 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
// CSS selector like ".foo" or "div > span"
// returns:
// `dojo.NodeList` containing the orphaned elements
return (filter ? d._filterQueryResult(this, filter) : this).forEach(orphan); // dojo.NodeList
return (filter ? dojo._filterQueryResult(this, filter) : this).forEach(orphan); // dojo.NodeList
},

adopt: function(/*String||Array||DomNode*/ queryOrListOrNode, /*String?*/ position){
Expand All @@ -788,7 +786,7 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
// | "only"
// | "replace"
// or an offset in the childNodes property
return d.query(queryOrListOrNode).place(this[0], position)._stash(this); // dojo.NodeList
return dojo.query(queryOrListOrNode).place(this[0], position)._stash(this); // dojo.NodeList
},

// FIXME: do we need this?
Expand Down Expand Up @@ -817,7 +815,7 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
if(!queryStr){ return this; }
var ret = this.map(function(node){
// FIXME: why would we ever get undefined here?
return d.query(queryStr, node).filter(function(subNode){ return subNode !== undefined; });
return dojo.query(queryStr, node).filter(function(subNode){ return subNode !== undefined; });
});
return this._wrap(apc.apply([], ret), this); // dojo.NodeList
},
Expand All @@ -842,15 +840,15 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){

var a = arguments, items = this, start = 0;
if(typeof filter == "string"){ // inline'd type check
items = d._filterQueryResult(this, a[0]);
items = dojo._filterQueryResult(this, a[0]);
if(a.length == 1){
// if we only got a string query, pass back the filtered results
return items._stash(this); // dojo.NodeList
}
// if we got a callback, run it over the filtered items
start = 1;
}
return this._wrap(d.filter(items, a[start], a[start + 1]), this); // dojo.NodeList
return this._wrap(dojo.filter(items, a[start], a[start + 1]), this); // dojo.NodeList
},

/*
Expand Down Expand Up @@ -937,7 +935,7 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
// example:
// Grabs all buttons in the page and converts them to diji.form.Buttons.
// | var buttons = dojo.query("button").instantiate("dijit.form.Button", {showLabel: true});
var c = d.isFunction(declaredClass) ? declaredClass : d.getObject(declaredClass);
var c = dojo.isFunction(declaredClass) ? declaredClass : dojo.getObject(declaredClass);
properties = properties || {};
return this.forEach(function(node){
new c(properties, node);
Expand Down Expand Up @@ -972,7 +970,7 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
// returns:
// dojo.NodeList
var t = new this._NodeListCtor();
d.forEach(arguments, function(i){
dojo.forEach(arguments, function(i){
if(i < 0){ i = this.length + i }
if(this[i]){ t.push(this[i]); }
}, this);
Expand All @@ -992,7 +990,7 @@ define(["./kernel", "../on", "./lang", "./array", "./html"], function(dojo, on){
// FIXME: pseudo-doc the above automatically generated on-event functions

// syntactic sugar for DOM events
d.forEach(nl.events, function(evt){
dojo.forEach(nl.events, function(evt){
var _oe = "on" + evt;
nlp[_oe] = function(a, b){
return this.connect(_oe, a, b);
Expand Down
Loading

0 comments on commit 4b29bee

Please sign in to comment.