Skip to content

Instantly share code, notes, and snippets.

@falexandre
Last active August 29, 2015 14:06
Show Gist options
  • Save falexandre/2927e2443488faf6ab60 to your computer and use it in GitHub Desktop.
Save falexandre/2927e2443488faf6ab60 to your computer and use it in GitHub Desktop.
// Declares an object
var layout = {};
// Mount function
layout.mount = function (origin, data)
{
// Receives HTML content
var content;
// See if origin block (model) was copied
if (!layout.mount[origin])
{
// Copy model block and remove it
content = layout.mount[origin] = $(origin).html();
$(origin).empty();
}
// If model was already copied
else
content = layout.mount[origin];
// Replace all the data
for (var i in data)
content = content.replace('{{' + i + '}}', data[i]);
// Append replaced data to element
$(origin).append(content);
// Return element DOM
return $(origin);
};
// On ready
$(document).ready(function($)
{
// Print layout
layout.mount('#exemplo',
{
name: 'Fulano',
phone: '3333-3333',
number: n,
}).show();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment