Created
March 22, 2011 17:51
-
-
Save buzzedword/881674 to your computer and use it in GitHub Desktop.
Proof of concept for encapsulating comments in a JSON string, then cleaning it out on the client side.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jsonp123( | |
{ | |
"//" : "Here comes the callback", | |
"callback": { | |
"//": "This has the first item", | |
"item": { | |
"title": "Databases", | |
"content": { | |
"item": { | |
"//": "Here's where the content is", | |
"ID": "13254", | |
"Technology": "Structured Query Language", | |
"Acronym": "SQL", | |
"Dialects": ["SQL-86", "SQL-89", "SQL-92", "SQL:1999", "SQL:2003", "SQL:2008"], | |
"meta": { | |
"//": "Glossary section", | |
"para": "This article is about the database language.", | |
"GlossSeeAlso": ["San Carlos Airport"] | |
}, | |
"ref": "markup" | |
} | |
} | |
} | |
} | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function recurseSplice(obj){ | |
for (var e in obj){ | |
if (obj.hasOwnProperty(e)){ | |
if (e == "//") { | |
delete obj[e]; | |
} else if (typeof obj[e] == "object") { | |
recurseSplice(obj[e]); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajax({ | |
dataType: 'jsonp', | |
jsonpCallback: 'jsonp123', | |
url: 'https://gist.github.com/raw/881674/fac4825d287abcf0c92b1216e6a05b747fa140d1/comments.json', | |
success: function (data) { | |
var call = $.extend(true, {}, data); | |
$.getScript('https://gist.github.com/raw/881674/ab4ae809ce434d4c9e679d4917dc9610e8906abd/recursive_json_comment_splice.js', function(){ | |
recurseSplice(call); | |
console.log(data, call); | |
}); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment