Created
April 11, 2014 01:43
-
-
Save anonymous/10436595 to your computer and use it in GitHub Desktop.
Viewloader rewrite
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
var views = { | |
foo: function($el, el, props) { | |
console.log(props); | |
}, | |
bar: function($el, el, props) { | |
console.log(props); | |
} | |
}; | |
viewloader.execute(views); | |
// -> bar | |
// -> {foo: "bar"} | |
// -> {bar: "baz"} | |
// -> {bar: "foo"} |
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
window.viewloader = { | |
execute: function(views, $scope) { | |
for(var view in views) { | |
var selector = "[data-view-" + view + "]"; | |
$els = $scope ? $scope.find(selector) : $(selector); | |
$els.each(function(i, el) { | |
var $el = $(el); | |
views[view]($el, el, $el.data("view-" + view)); | |
}); | |
}; | |
} | |
}; |
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
<div data-view-foo="bar" data-view-bar='{"bar":"baz"}'/> | |
<div data-view-foo='{"foo":"bar"}'/> | |
<div data-view-bar='{"bar":"foo"}'/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment