Skip to content

Commit

Permalink
Minimizing references to dojo "global", refs #13101 tangentially, !st…
Browse files Browse the repository at this point in the history
…rict

git-svn-id: http://svn.dojotoolkit.org/src/dojo/trunk@28615 560b804f-0ae3-0310-86f3-f6aa0a117693
  • Loading branch information
wkeese committed May 21, 2012
1 parent 37f9223 commit e10e6d4
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 114 deletions.
64 changes: 32 additions & 32 deletions _base/Color.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ define(["./kernel", "./lang", "./array", "./config"], function(dojo, lang, Array
var Color = dojo.Color = function(/*Array|String|Object*/ color){
// summary:
// Takes a named string, hex string, array of rgb or rgba values,
// an object with r, g, b, and a properties, or another `dojo.Color` object
// an object with r, g, b, and a properties, or another `Color` object
// and creates a new Color instance to work from.
//
// example:
// Work with a Color instance:
// | var c = new dojo.Color();
// | var c = new Color();
// | c.setColor([0,0,0]); // black
// | var hex = c.toHex(); // #000000
//
// example:
// Work with a node's color:
// | var color = dojo.style("someNode", "backgroundColor");
// | var n = new dojo.Color(color);
// | var n = new Color(color);
// | // adjust the color some
// | n.r *= .5;
// | console.log(n.toString()); // rgb(128, 255, 255);
Expand Down Expand Up @@ -55,11 +55,11 @@ define(["./kernel", "./lang", "./array", "./config"], function(dojo, lang, Array
setColor: function(/*Array|String|Object*/ color){
// summary:
// Takes a named string, hex string, array of rgb or rgba values,
// an object with r, g, b, and a properties, or another `dojo.Color` object
// an object with r, g, b, and a properties, or another `Color` object
// and sets this color instance to that value.
//
// example:
// | var c = new dojo.Color(); // no color
// | var c = new Color(); // no color
// | c.setColor("#ededed"); // greyish
if(lang.isString(color)){
Color.fromString(color, this);
Expand All @@ -69,21 +69,21 @@ define(["./kernel", "./lang", "./array", "./config"], function(dojo, lang, Array
this._set(color.r, color.g, color.b, color.a);
if(!(color instanceof Color)){ this.sanitize(); }
}
return this; // dojo.Color
return this; // Color
},
sanitize: function(){
// summary:
// Ensures the object has correct attributes
// description:
// the default implementation does nothing, include dojo.colors to
// augment it with real checks
return this; // dojo.Color
return this; // Color
},
toRgb: function(){
// summary:
// Returns 3 component array of rgb values
// example:
// | var c = new dojo.Color("#000000");
// | var c = new Color("#000000");
// | console.log(c.toRgb()); // [0,0,0]
var t = this;
return [t.r, t.g, t.b]; // Array
Expand All @@ -99,7 +99,7 @@ define(["./kernel", "./lang", "./array", "./config"], function(dojo, lang, Array
// summary:
// Returns a CSS color string in hexadecimal representation
// example:
// | console.log(new dojo.Color([0,0,0]).toHex()); // #000000
// | console.log(new Color([0,0,0]).toHex()); // #000000
var arr = ArrayUtil.map(["r", "g", "b"], function(x){
var s = this[x].toString(16);
return s.length < 2 ? "0" + s : s;
Expand All @@ -110,7 +110,7 @@ define(["./kernel", "./lang", "./array", "./config"], function(dojo, lang, Array
// summary:
// Returns a css color string in rgb(a) representation
// example:
// | var c = new dojo.Color("#FFF").toCss();
// | var c = new Color("#FFF").toCss();
// | console.log(c); // rgb('255','255','255')
var t = this, rgb = t.r + ", " + t.g + ", " + t.b;
return (includeAlpha ? "rgba(" + rgb + ", " + t.a : "rgb(" + rgb) + ")"; // String
Expand All @@ -123,42 +123,42 @@ define(["./kernel", "./lang", "./array", "./config"], function(dojo, lang, Array
});

Color.blendColors = dojo.blendColors = function(
/*dojo.Color*/ start,
/*dojo.Color*/ end,
/*Color*/ start,
/*Color*/ end,
/*Number*/ weight,
/*dojo.Color?*/ obj
/*Color?*/ obj
){
// summary:
// Blend colors end and start with weight from 0 to 1, 0.5 being a 50/50 blend,
// can reuse a previously allocated dojo.Color object for the result
// can reuse a previously allocated Color object for the result
var t = obj || new Color();
ArrayUtil.forEach(["r", "g", "b", "a"], function(x){
t[x] = start[x] + (end[x] - start[x]) * weight;
if(x != "a"){ t[x] = Math.round(t[x]); }
});
return t.sanitize(); // dojo.Color
return t.sanitize(); // Color
};

Color.fromRgb = dojo.colorFromRgb = function(/*String*/ color, /*dojo.Color?*/ obj){
Color.fromRgb = dojo.colorFromRgb = function(/*String*/ color, /*Color?*/ obj){
// summary:
// Returns a `dojo.Color` instance from a string of the form
// "rgb(...)" or "rgba(...)". Optionally accepts a `dojo.Color`
// Returns a `Color` instance from a string of the form
// "rgb(...)" or "rgba(...)". Optionally accepts a `Color`
// object to update with the parsed value and return instead of
// creating a new object.
// returns:
// A dojo.Color object. If obj is passed, it will be the return value.
// A Color object. If obj is passed, it will be the return value.
var m = color.toLowerCase().match(/^rgba?\(([\s\.,0-9]+)\)/);
return m && Color.fromArray(m[1].split(/\s*,\s*/), obj); // dojo.Color
return m && Color.fromArray(m[1].split(/\s*,\s*/), obj); // Color
};

Color.fromHex = dojo.colorFromHex = function(/*String*/ color, /*dojo.Color?*/ obj){
Color.fromHex = dojo.colorFromHex = function(/*String*/ color, /*Color?*/ obj){
// summary:
// Converts a hex string with a '#' prefix to a color object.
// Supports 12-bit #rgb shorthand. Optionally accepts a
// `dojo.Color` object to update with the parsed value.
// `Color` object to update with the parsed value.
//
// returns:
// A dojo.Color object. If obj is passed, it will be the return value.
// A Color object. If obj is passed, it will be the return value.
//
// example:
// | var thing = dojo.colorFromHex("#ededed"); // grey, longhand
Expand All @@ -170,32 +170,32 @@ define(["./kernel", "./lang", "./array", "./config"], function(dojo, lang, Array
mask = (1 << bits) - 1;
color = Number("0x" + color.substr(1));
if(isNaN(color)){
return null; // dojo.Color
return null; // Color
}
ArrayUtil.forEach(["b", "g", "r"], function(x){
var c = color & mask;
color >>= bits;
t[x] = bits == 4 ? 17 * c : c;
});
t.a = 1;
return t; // dojo.Color
return t; // Color
};

Color.fromArray = dojo.colorFromArray = function(/*Array*/ a, /*dojo.Color?*/ obj){
Color.fromArray = dojo.colorFromArray = function(/*Array*/ a, /*Color?*/ obj){
// summary:
// Builds a `dojo.Color` from a 3 or 4 element array, mapping each
// Builds a `Color` from a 3 or 4 element array, mapping each
// element in sequence to the rgb(a) values of the color.
// example:
// | var myColor = dojo.colorFromArray([237,237,237,0.5]); // grey, 50% alpha
// returns:
// A dojo.Color object. If obj is passed, it will be the return value.
// A Color object. If obj is passed, it will be the return value.
var t = obj || new Color();
t._set(Number(a[0]), Number(a[1]), Number(a[2]), Number(a[3]));
if(isNaN(t.a)){ t.a = 1; }
return t.sanitize(); // dojo.Color
return t.sanitize(); // Color
};

Color.fromString = dojo.colorFromString = function(/*String*/ str, /*dojo.Color?*/ obj){
Color.fromString = dojo.colorFromString = function(/*String*/ str, /*Color?*/ obj){
// summary:
// Parses `str` for a color value. Accepts hex, rgb, and rgba
// style color values.
Expand All @@ -205,9 +205,9 @@ define(["./kernel", "./lang", "./array", "./config"], function(dojo, lang, Array
// rgb or rgba strings such as "rgb(133, 200, 16)" or "rgba(10, 10,
// 10, 50)"
// returns:
// A dojo.Color object. If obj is passed, it will be the return value.
// A Color object. If obj is passed, it will be the return value.
var a = Color.named[str];
return a && Color.fromArray(a, obj) || Color.fromRgb(str, obj) || Color.fromHex(str, obj); // dojo.Color
return a && Color.fromArray(a, obj) || Color.fromRgb(str, obj) || Color.fromHex(str, obj); // Color
};

return Color;
Expand Down
51 changes: 30 additions & 21 deletions _base/NodeList.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
define(["./kernel", "../query", "./array", "./html", "../NodeList-dom"], function(dojo, query, array){
// module:
// dojo/_base/NodeList
// summary:
// This module defines dojo.NodeList.
// module:
// dojo/_base/NodeList
// summary:
// This module extends dojo/query/NodeList with the legacy connect(), coords(),
// blur(), focus(), change(), click(), error(), keydown(), keypress(),
// keyup(), load(), mousedown(), mouseenter(), mouseleave(), mousemove(),
// mouseout(), mouseover(), mouseup(), and submit() methods.

var NodeList = query.NodeList;
var NodeList = query.NodeList,
nlp = NodeList.prototype;

nlp.connect = NodeList._adaptAsForEach(function(){
// don't bind early to dojo.connect since we no longer explicitly depend on it
return dojo.connect.apply(this, arguments);
});
/*=====
NodeList.prototype.connect = function(methodName, objOrFunc, funcName){
nlp.connect = function(methodName, objOrFunc, funcName){
// summary:
// attach event handlers to every item of the NodeList. Uses dojo.connect()
// so event properties are normalized
// Attach event handlers to every item of the NodeList. Uses dojo.connect()
// so event properties are normalized.
//
// Application must manually require() "dojo/_base/connect" before using this method.
// methodName: String
// the name of the method to attach to. For DOM events, this should be
// the lower-case name of the event
Expand All @@ -25,31 +35,30 @@ define(["./kernel", "../query", "./array", "./html", "../NodeList-dom"], functio
// event. May also be a function reference.
// example:
// add an onclick handler to every button on the page
// | dojo.query("div:nth-child(odd)").connect("onclick", function(e){
// | query("div:nth-child(odd)").connect("onclick", function(e){
// | console.log("clicked!");
// | });
// example:
// attach foo.bar() to every odd div's onmouseover
// | dojo.query("div:nth-child(odd)").connect("onmouseover", foo, "bar");
// | query("div:nth-child(odd)").connect("onmouseover", foo, "bar");
return null; // NodeList
};
NodeList.prototype.coords = function(){
=====*/

nlp.coords = NodeList._adaptAsMap(dojo.coords);
/*=====
nlp.coords = function(){
// summary:
// Deprecated: Use position() for border-box x/y/w/h
// or marginBox() for margin-box w/h/l/t.
// Returns the box objects of all elements in a node list as
// an Array (*not* a NodeList). Acts like `dojo.coords`, though assumes
// an Array (*not* a NodeList). Acts like `domGeom.coords`, though assumes
// the node passed is each node in this list.
return dojo.map(this, dojo.coords); // Array
return []; // Array
};
=====*/
var nlp = NodeList.prototype;

// don't bind early to dojo.connect since we no longer explicitly depend on it
nlp.connect = NodeList._adaptAsForEach(function(){
return dojo.connect.apply(this, arguments);
});
nlp.coords = NodeList._adaptAsMap(dojo.coords);

NodeList.events = [
// summary:
Expand Down Expand Up @@ -92,5 +101,5 @@ define(["./kernel", "../query", "./array", "./html", "../NodeList-dom"], functio
);

dojo.NodeList = NodeList;
return dojo.NodeList;
return NodeList;
});
Loading

0 comments on commit e10e6d4

Please sign in to comment.