Skip to content
This repository was archived by the owner on Jan 22, 2018. It is now read-only.

Commit 22a9458

Browse files
author
Kamil Kisiela
committed
refactor(mdTheme): use ngModelAttrsManipulator
1 parent 2966e6b commit 22a9458

File tree

1 file changed

+8
-38
lines changed

1 file changed

+8
-38
lines changed

src/runs/md-theme-manipulator.js

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,10 @@
1-
export default (formlyConfigProvider) => {
2-
3-
function addIfNotPresent(nodes, attr, val) {
4-
angular.forEach(nodes, (node) => {
5-
if (!node.getAttribute(attr)) {
6-
node.setAttribute(attr, val)
7-
}
8-
});
9-
}
1+
import {ngModelAttrsManipulator} from './../helpers/index.js';
102

11-
function getNgModelNodes(node) {
12-
const query = "[ng-model], [data-ng-model]";
13-
14-
return node.querySelectorAll(query)
3+
export default (formlyConfigProvider) => {
4+
formlyConfigProvider.templateManipulators.preWrapper.push((template, options) => {
5+
if (angular.isDefined(options.templateOptions.theme)) {
6+
return ngModelAttrsManipulator(template, options, 'md-theme', options.templateOptions.theme);
157
}
16-
17-
formlyConfigProvider.templateManipulators.preWrapper.push((template, options) => {
18-
if (angular.isDefined(options.templateOptions.theme)) {
19-
const node = document.createElement('div');
20-
const skip = options.extras && options.extras.skipNgModelAttrsManipulator;
21-
22-
if (skip === true) {
23-
return template
24-
}
25-
node.innerHTML = template;
26-
const modelNodes = getNgModelNodes(node);
27-
28-
if (!modelNodes || !modelNodes.length) {
29-
return template;
30-
}
31-
32-
addIfNotPresent(modelNodes, 'md-theme', options.templateOptions.theme);
33-
34-
return node.innerHTML;
35-
36-
}
37-
return template;
38-
});
39-
40-
}
8+
return template;
9+
});
10+
};

0 commit comments

Comments
 (0)