Last active
August 29, 2015 14:06
-
-
Save falexandre/2927e2443488faf6ab60 to your computer and use it in GitHub Desktop.
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
// 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