-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathviewloader.js
More file actions
23 lines (23 loc) · 778 Bytes
/
viewloader.js
File metadata and controls
23 lines (23 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(function(root, factory) {
root.viewloader = factory({},(root.jQuery || root.Zepto || root.$)); // Browser global
}(this, function(viewloader,$) {
"use strict";
var dasherize = function(s) {
return s.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
};
viewloader.execute = function(views, $scope, includeScope) {
for(var view in views) {
var dashView = dasherize(view),
selector = "[data-view-" + dashView + "]",
$els = $scope ? $scope.find(selector) : $(selector);
if (includeScope === true && $scope) {
$els = $els.add($scope.filter(selector));
}
$els.each(function(i, el) {
var $el = $(el);
views[view]($el, el, $el.data("view-" + dashView));
});
}
};
return viewloader;
}));