Skip to content

Commit

Permalink
Got through the basics of the request functions. Hit d3.ns as well but
Browse files Browse the repository at this point in the history
will probably loop back around.
  • Loading branch information
zmaril committed Jul 16, 2012
1 parent 9974b4d commit 3712116
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/html.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//A wrapper around d3.text that sets the MIME type to HTML and then handles the edge case of the responseText being empty.
d3.html = function(url, callback) {
d3.text(url, "text/html", function(text) {
if (text != null) { // Treat empty string as valid HTML.
Expand Down
1 change: 1 addition & 0 deletions src/core/json.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//A wrapper around d3.text that sets the MIME type to JSON and then parses the JSON before passing it to the callback.
d3.json = function(url, callback) {
d3.text(url, "application/json", function(text) {
callback(text ? JSON.parse(text) : null);
Expand Down
2 changes: 2 additions & 0 deletions src/core/ns.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//Used for SVG namespacing. Mostly an internal method that is used before appending SVG elements to the page.
//TODO: better explanation of what is going on.
var d3_nsPrefix = {
svg: "http://www.w3.org/2000/svg",
xhtml: "http://www.w3.org/1999/xhtml",
Expand Down
1 change: 1 addition & 0 deletions src/core/text.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//A wrapper around d3.xhr that passes back the responseText of the response to the callback.
d3.text = function(url, mime, callback) {
function ready(req) {
callback(req && req.responseText);
Expand Down
1 change: 1 addition & 0 deletions src/core/xml.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//A wrapper around d3.xhr that grabs the responseXML from the response and then calls the callback. Similiar to d3.text in terms of scope.
d3.xml = function(url, mime, callback) {
function ready(req) {
callback(req && req.responseXML);
Expand Down

0 comments on commit 3712116

Please sign in to comment.