Revert previous commit; move urlencode to plugin.

This commit is contained in:
Mike Bostock 2012-09-19 18:54:36 -07:00
Родитель f6c8059dd5
Коммит 1bfd9a48d3
6 изменённых файлов: 6 добавлений и 117 удалений

Просмотреть файл

@ -66,7 +66,6 @@ d3.core.js: \
src/core/range.js \
src/core/requote.js \
src/core/round.js \
src/core/urlencode.js \
src/core/xhr.js \
src/core/text.js \
src/core/json.js \

21
d3.v2.js поставляемый
Просмотреть файл

@ -57,9 +57,6 @@
while (x * k % 1) k *= 10;
return k;
}
function d3_urlencode(value) {
return encodeURIComponent(value).replace(/%20/g, "+");
}
function d3_xhr_fixCallback(callback) {
return callback.length === 1 ? function(error, request) {
callback(error == null ? request : null);
@ -2943,21 +2940,6 @@
d3.round = function(x, n) {
return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
};
d3.urlencode = function(name, value) {
var array = [];
d3_arraySubclass(array, d3_urlencodePrototype);
return arguments.length ? array.and(name, value) : array;
};
var d3_urlencodePrototype = d3.urlencode.prototype = [];
d3_urlencodePrototype.type = "application/x-www-form-urlencoded;charset=utf-8";
d3_urlencodePrototype.and = function(name, value) {
name = d3_urlencode(name);
this.push(value == null ? name : name + "=" + d3_urlencode(value));
return this;
};
d3_urlencodePrototype.toString = function() {
return this.join("&");
};
d3.xhr = function(url, mimeType, callback) {
var xhr = {}, dispatch = d3.dispatch("progress", "load", "error"), headers = {}, response = d3_identity, request = new XMLHttpRequest;
request.onreadystatechange = function() {
@ -2999,13 +2981,12 @@
if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
request.open(method, url, true);
if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
if (data == null) data = null; else if (data.type != null && !("content-type" in headers)) headers["content-type"] = data.type;
for (var name in headers) request.setRequestHeader(name, headers[name]);
if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
if (callback != null) xhr.on("error", callback).on("load", function(request) {
callback(null, request);
});
request.send(data);
request.send(data == null ? null : data);
return xhr;
};
xhr.abort = function() {

8
d3.v2.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -1,23 +0,0 @@
d3.urlencode = function(name, value) {
var array = [];
d3_arraySubclass(array, d3_urlencodePrototype);
return arguments.length ? array.and(name, value) : array;
};
var d3_urlencodePrototype = d3.urlencode.prototype = [];
d3_urlencodePrototype.type = "application/x-www-form-urlencoded;charset=utf-8";
d3_urlencodePrototype.and = function(name, value) {
name = d3_urlencode(name);
this.push(value == null ? name : name + "=" + d3_urlencode(value));
return this;
};
d3_urlencodePrototype.toString = function() {
return this.join("&");
};
function d3_urlencode(value) {
return encodeURIComponent(value).replace(/%20/g, "+");
}

Просмотреть файл

@ -55,11 +55,10 @@ d3.xhr = function(url, mimeType, callback) {
if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
request.open(method, url, true);
if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
if (data == null) data = null; else if (data.type != null && !("content-type" in headers)) headers["content-type"] = data.type;
for (var name in headers) request.setRequestHeader(name, headers[name]);
if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
if (callback != null) xhr.on("error", callback).on("load", function(request) { callback(null, request); });
request.send(data);
request.send(data == null ? null : data);
return xhr;
};

Просмотреть файл

@ -1,67 +0,0 @@
require("../env");
var vows = require("vows"),
assert = require("assert");
var suite = vows.describe("d3.urlencode");
suite.addBatch({
"urlencode": {
topic: function() {
return d3.urlencode;
},
"returns an instanceof d3.urlencode": function(urlencode) {
assert.instanceOf(urlencode(), d3.urlencode);
},
"returns an array": function(urlencode) {
assert.isArray(urlencode(), d3.urlencode);
assert.deepEqual(urlencode("foo", 2).and("bar"), ["foo=2", "bar"]);
},
"can be empty": function(urlencode) {
assert.strictEqual(urlencode() + "", "");
},
"can be modified via array methods, albeit unsafely": function(urlencode) {
var u = urlencode("foo", 1).and("bar", 2).and("baz", 3);
u.splice(1, 1);
u.push("unsafe=true")
u.sort();
assert.strictEqual(u + "", "baz=3&foo=1&unsafe=true");
},
"has the type application/x-www-form-urlencoded;charset=utf-8": function(urlencode) {
assert.strictEqual(urlencode().type, "application/x-www-form-urlencoded;charset=utf-8");
},
"encodes the name and value per the HTML 4.01 specification": function(urlencode) {
assert.strictEqual(urlencode("foo", "bar") + "", "foo=bar");
assert.strictEqual(urlencode("f o", "b r") + "", "f+o=b+r"); // not %20
assert.strictEqual(urlencode("foo", "bär") + "", "foo=b%C3%A4r"); // UTF-8 bytes
},
"coerces the name and value to strings": function(urlencode) {
var foo = {toString: function() { return "foo"; }},
bar = new String("bar");
assert.strictEqual(urlencode(foo, bar) + "", "foo=bar");
},
"and": {
"modifies the urlencode in-place": function(urlencode) {
var u = urlencode("foo", "bar");
assert.strictEqual(u.and("baz"), u);
assert.strictEqual(u + "", "foo=bar&baz");
},
"supports multiple values with the same name": function(urlencode) {
assert.strictEqual(urlencode("foo", 1).and("foo", 2) + "", "foo=1&foo=2");
}
},
"ignores the value if null or undefined": function(urlencode) {
assert.strictEqual(urlencode("foo") + "", "foo");
assert.strictEqual(urlencode("foo", null) + "", "foo");
assert.strictEqual(urlencode("foo", undefined) + "", "foo");
},
"does not ignore the value if the empty string": function(urlencode) {
assert.strictEqual(urlencode("foo", "") + "", "foo=");
},
"does not ignore the value if falsey": function(urlencode) {
assert.strictEqual(urlencode("foo", 0).and("bar", false) + "", "foo=0&bar=false");
}
}
});
suite.export(module);