Skip to content

Instantly share code, notes, and snippets.

@FLYBYME
Created April 21, 2011 06:16
Show Gist options
  • Save FLYBYME/933836 to your computer and use it in GitHub Desktop.
Save FLYBYME/933836 to your computer and use it in GitHub Desktop.
Snippet
/* This is the format a typtical snippet will be in. */
/* This infinate loop will prevent CSRF attacks but causeing the script to become unresponsive
if someone tries to load an ajax request into a script tag. The infinate loop and comment wrapped
json object will have to be parsed out before you can parse the json object.
*/
for(;;);
/* For added secuity the whole json object is wrapped in a comment */
/*
{
/* a unique request id for send and recieving multiple request for snippets. all api's in the system will work this way.*/
ruid:'1234',
/* The id of the elements that this content will be placed into.
ie. the content from the 'content' object in this request will
be placed into <div id="example_placeholder"></div>
*/
id:'example_placeholder',
/* A unique name for the snippet */
name:'example_snippet'
/* This is the boot load order for snippets. Basically all the snippets in a specific order have
to be processed before snippets in another order. For example. if there is 4 snippets. 2 have and order of 2
and 2 of them have an order of 2. The snippets in order=1 will be handled first, then an event will be triggered
that reports that order 1 is complete and then order=2 is processed.
*/
order:1,
/* If an attachement is present then these files have to be loaded first before the content can be put in
the placeholded. and before the onload event is called. attachments that are loaded should be registered.
so they are not loaded again.
*/
attach:{
css:[/*...*/],
js:[/*...*/]
},
/* This is basically the content that is placed in the elements with the placeholder id */
content:'<p>some html content here</p>',
/* The function that should be called after the snippet is loaded. this could be an actual function the has
to be called. */
onload: function(){/*...*/},
/* if this option exists. and set to false then the snippet loader will not wait for the dom to be loaded in
order to run it. by default all snippets wait for the dom to be ready before any of them a processed.
*/
onready: true
},
*/
/* Example of a clean single snippet response */
{
ruid:'1234',
id:'example_placeholder',
name:'example_snippet',
order:1,
attach:{
css:['example.css', 'feed.css'],
js:['example.js']
},
content:'<p>some html content here</p>',
onload: function(){ if( something ){ do_something_awesome(); } },
onready: true
},
/* Example of a clean multiple snippet response
** NOTE for security the resonse is not wrapped with [] on the first node
*/
{
snippets:[
{
ruid:'1234',
id:'feed-container',
name:'feed',
order:1,
attach:{
css:['example.css', 'feed.css'],
js:['example.js']
},
content:'<p>some html content here</p>',
onload: function(){ if( something ){ do_something_awesome(); } },
onready: true
},
{
ruid:'12323345',
id:'main-naviation-container',
name:'main_nav',
order:1,
attach:{
css:['example.css', 'nav.css'],
js:['nav.js']
},
content:'<p>some html content here</p>',
onload: function(){ initNav(); },
onready: true
},
{
ruid:'0948509485',
id:'feed-header',
name:'feed_header',
order:2,
attach:{
css:['example.css', 'feed.css']
},
content:'<p>some html content here</p>',
onload: function(){ initFeedHeader(); }
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment