V 0.0.1-alpha
jSnippets is a javasript library that grabs an HTML file that contains different HTML code snippets and allows you to use the snippet element to be appended,prepended or to replace the contents of a given DIV element from the DOM of the current file.
jQuery
Bootstrap
Snippets should be declared in the following form
htmlAlso, the snippets HTML should be ALWAYS defined within a element to avoid multiple elements selection problem so that jquery .find() function can find the targeted divs by their data attribute
jSnippets grabs the html code snippets and uses the data attribute to set different things for the snippet. There are, some reserved data attributes. They are the following:
- data-iterator ~ Represents an element that has child elements that will be iterated within a $.each structure there is only 1 iterator field allowed by now
jsnippets.init(path);
This function is getting the path argument which represents the path to the snippets HTML file. This loads all the snippets within an property of jsnippets object.jsnippets.load(snippet_id);
This represents the snippet ID to load from the file. This will be loaded as the current object to work with within the following methods.jsnippets.unload();
Unloads the current working snippet from the memory.jsnippets.dataload(object);
This receives an object representing the data to be bound to the snippet. Example of an object can be:{iterator:[{name:'alex',field:'test'},{name:'alex',field:'test'},{name:'alex',field:'test'},{name:'alex',field:'test'}],othername:'alex'}
jsnippets.appendTo(div);jsnippets.prependTo(div);jsnippets.replace(div);
Those methods append,prepend, or replace the content of a #div/.div/DOM element with the current loaded snippet. Also, after the snippet is appended/prepended/replaced the library calls jsnippet.unload(); to clear the memory;
- If tag is found within the snippet, jSnippets expects to have an URL of the image to build the image.
- If
<a>
tag is found, jsnippet should expect an object that will have the URL as a key, and TEXT as another key to properly set the<a>
element. - Add multiple iterators to snippets or allow the iterator to be defined in another way.