Skip to content

Instantly share code, notes, and snippets.

@buzzedword
Created March 22, 2011 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buzzedword/881674 to your computer and use it in GitHub Desktop.
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.
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"
}
}
}
}
}
);
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]);
}
}
}
}
$.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