Created
May 29, 2015 15:03
-
-
Save nebulous/c4aabfa5a46183b490f0 to your computer and use it in GitHub Desktop.
Simple jQuery plugin for Jemplate rendering
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
(function($) { | |
/* Simplistic jQuery plugin for Jemplate v0.01 | |
http://github.com/nebulous | |
*/ | |
$.fn.jemplate = function(tmplin, datain) { | |
var data_url; | |
if (typeof(tmplin) == "object") { | |
datain = tmplin.stash || tmplin || {}; | |
tmplin = datain.jemplate || ''; | |
} | |
if (typeof(datain) == "string") { | |
data_url = datain; | |
datain = {}; | |
} | |
return this.each(function(idx, obj) { | |
var $obj = $(obj); | |
var data = $.extend({}, $obj.data(), datain); | |
var tmpl = tmplin || data['jemplate']; | |
var method = data['method'] || 'html'; | |
if (typeof tmpl === undefined) return this; | |
if (data_url) { | |
$.getJSON(data_url, function(data) { | |
var output = Jemplate.process(tmpl, data); | |
$obj[method](output); | |
}); | |
} else { | |
var output = Jemplate.process(tmpl, data); | |
$obj[method](output); | |
} | |
}); | |
} | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment