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

Commit 3f5be21

Browse files
author
Kamil Kisiela
committed
Merge branch 'release/v0.5.2'
2 parents 3625afa + 6e2e25a commit 3f5be21

20 files changed

+1312
-58
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [0.5.2] - 2015-11-19
6+
### Fixed
7+
- missing md-theme attribute when using templateOptions.theme
8+
9+
### Added
10+
- Tests of all currently available functionality
11+
12+
### Removed
13+
- deprecated **mdInputContainer** wrapper. Use **inputContainer**
14+
- deprecated **mdMessages** wrapper. Use **messages**
15+
516
## [0.5.1] - 2015-11-18
617
### Changed
718
- Refactor all files to use Strict Dependency Injection
@@ -18,7 +29,6 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1829
### Deprecated
1930
- **mdInputContainer** wrapper. Use **inputContainer**
2031
- **mdMessages** wrapper. Use **messages**
21-
- **mdLabel** wrapper. Use **label**
2232

2333
## [0.3.0] - 2015-11-17
2434
### Added
@@ -60,6 +70,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
6070

6171
## 0.0.1 - 2015-11-06
6272

73+
[0.5.2]: https://github.com/wieldo/angular-formly-templates-material/compare/v0.5.1...v0.5.2
6374
[0.5.1]: https://github.com/wieldo/angular-formly-templates-material/compare/v0.5.0...v0.5.1
6475
[0.5.0]: https://github.com/wieldo/angular-formly-templates-material/compare/v0.4.0...v0.5.0
6576
[0.4.0]: https://github.com/wieldo/angular-formly-templates-material/compare/v0.3.0...v0.4.0

lib/client/run/md-theme-manipulator.js

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,26 @@ var {SetModule} = angular2now;
33
SetModule('formlyMaterial')
44
.config(['formlyConfigProvider', (formlyConfigProvider) => {
55

6-
const addIfNotPresent = (nodes, attr, val) => {
7-
angular.forEach((nodes, node) => {
6+
function addIfNotPresent(nodes, attr, val) {
7+
angular.forEach(nodes, (node) => {
88
if (!node.getAttribute(attr)) {
99
node.setAttribute(attr, val)
1010
}
11-
})
12-
};
11+
});
12+
}
1313

14-
const nodeMatches = (node, selector) => {
14+
function nodeMatches(node, selector) {
1515
const div = document.createElement('div');
1616

1717
div.innerHTML = node.outerHTML;
1818
return div.querySelector(selector)
19-
};
19+
}
2020

21-
const getNgModelNodes = (node, skip) => {
22-
const selectorNot = angular.isString(skip) ? `:not(${skip})` : '';
23-
const skipNot = ':not([formly-skip-ng-model-attrs-manipulator])';
24-
const query = `[ng-model]${selectorNot}${skipNot}, [data-ng-model]${selectorNot}${skipNot}`;
21+
function getNgModelNodes(node) {
22+
const query = "[ng-model], [data-ng-model]";
2523

26-
try {
27-
return node.querySelectorAll(query)
28-
} catch (e) {
29-
//this code is needed for IE8, as it does not support the CSS3 ':not' selector
30-
//it should be removed when IE8 support is dropped
31-
return getNgModelNodesFallback(node, skip)
32-
}
33-
};
34-
35-
const getNgModelNodesFallback = (node, skip) => {
36-
const allNgModelNodes = node.querySelectorAll('[ng-model], [data-ng-model]');
37-
const matchingNgModelNodes = [];
38-
39-
//make sure this array is compatible with NodeList type by adding an 'item' function
40-
matchingNgModelNodes.item = function (i) {
41-
return this[i]
42-
};
43-
44-
for (let i = 0; i < allNgModelNodes.length; i++) {
45-
const ngModelNode = allNgModelNodes[i];
46-
47-
if (!ngModelNode.hasAttribute('formly-skip-ng-model-attrs-manipulator') && !(angular.isString(skip) && nodeMatches(ngModelNode, skip))) {
48-
matchingNgModelNodes.push(ngModelNode)
49-
}
50-
}
51-
52-
return matchingNgModelNodes
53-
};
24+
return node.querySelectorAll(query)
25+
}
5426

5527
formlyConfigProvider.templateManipulators.preWrapper.push((template, options) => {
5628
if (angular.isDefined(options.templateOptions.theme)) {
@@ -61,7 +33,7 @@ SetModule('formlyMaterial')
6133
return template
6234
}
6335
node.innerHTML = template;
64-
const modelNodes = getNgModelNodes(node, skip);
36+
const modelNodes = getNgModelNodes(node);
6537

6638
if (!modelNodes || !modelNodes.length) {
6739
return template;

lib/client/wrappers/input-container/input-container.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ var {SetModule} = angular2now;
33
SetModule('formlyMaterial')
44
.config(['formlyConfigProvider', 'formlyMaterialProvider', (formlyConfigProvider, formlyMaterialProvider) => {
55

6-
/**
7-
* @deprecated since version 0.4.0
8-
*/
9-
formlyConfigProvider.setWrapper({
10-
name: 'mdInputContainer',
11-
templateUrl: formlyMaterialProvider.templateUrl('lib/client/wrappers/input-container/input-container.ng.html')
12-
});
13-
146
formlyConfigProvider.setWrapper({
157
name: 'inputContainer',
168
templateUrl: formlyMaterialProvider.templateUrl('lib/client/wrappers/input-container/input-container.ng.html')

lib/client/wrappers/messages/messages.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ var {SetModule} = angular2now;
33
SetModule('formlyMaterial')
44
.config(['formlyConfigProvider', 'formlyMaterialProvider', (formlyConfigProvider, formlyMaterialProvider) => {
55

6-
/**
7-
* @deprecated since version 0.4.0
8-
*/
9-
formlyConfigProvider.setWrapper({
10-
name: 'mdMessages',
11-
templateUrl: formlyMaterialProvider.templateUrl('lib/client/wrappers/messages/messages.ng.html')
12-
});
13-
146
formlyConfigProvider.setWrapper({
157
name: 'messages',
168
templateUrl: formlyMaterialProvider.templateUrl('lib/client/wrappers/messages/messages.ng.html')

package.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var client = 'client';
33
Package.describe({
44
name: "wieldo:angular-formly-templates-material",
55
summary: "Material design templates for angular-formly",
6-
version: "0.5.1",
6+
version: "0.5.2",
77

88
documentation: 'README.md',
99
git: 'https://github.com/wieldo/angular-formly-templates-material.git'
@@ -109,11 +109,30 @@ Package.onTest(function(api) {
109109
110110
'velocity:helpers',
111111
'velocity:console-reporter',
112+
'jquery',
112113
'angular:[email protected]',
113114
'wieldo:angular-formly-templates-material'
114115
]);
115116

116117
api.addFiles([
117-
'tests/client/formly-material-spec.js'
118+
'tests/client/test-utils.js',
119+
'tests/client/angular-material-mocks.js',
120+
'tests/client/formly-material-spec.js',
121+
// run
122+
'tests/client/run/md-theme-manipulator-spec.js',
123+
// wrappers
124+
'tests/client/wrappers/input-container-spec.js',
125+
'tests/client/wrappers/label-spec.js',
126+
'tests/client/wrappers/messages-spec.js',
127+
// types
128+
'tests/client/types/checkbox-spec.js',
129+
'tests/client/types/chips-spec.js',
130+
'tests/client/types/datepicker-spec.js',
131+
'tests/client/types/input-spec.js',
132+
'tests/client/types/radio-spec.js',
133+
'tests/client/types/select-spec.js',
134+
'tests/client/types/slider-spec.js',
135+
'tests/client/types/switch-spec.js',
136+
'tests/client/types/textarea-spec.js'
118137
], client);
119138
});
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
(function(window, angular, undefined) {
2+
3+
'use strict';
4+
5+
/**
6+
* @ngdoc module
7+
* @name ngMaterial-mock
8+
* @packageName angular-material-mocks
9+
*
10+
* @description
11+
*
12+
* The `ngMaterial-mock` module provides support
13+
*
14+
*/
15+
angular.module('ngMaterial-mock', [
16+
'ngMock',
17+
'ngAnimateMock',
18+
'material.core'
19+
])
20+
.config(['$provide', function($provide) {
21+
22+
$provide.factory('$material', ['$animate', '$timeout', function($animate, $timeout) {
23+
return {
24+
flushOutstandingAnimations: function() {
25+
// this code is placed in a try-catch statement
26+
// since 1.3 and 1.4 handle their animations differently
27+
// and there may be situations where follow-up animations
28+
// are run in one version and not the other
29+
try { $animate.flush(); } catch(e) {}
30+
},
31+
flushInterimElement: function() {
32+
this.flushOutstandingAnimations();
33+
$timeout.flush();
34+
this.flushOutstandingAnimations();
35+
$timeout.flush();
36+
this.flushOutstandingAnimations();
37+
$timeout.flush();
38+
}
39+
};
40+
}]);
41+
42+
/**
43+
* Angular Material dynamically generates Style tags
44+
* based on themes and palletes; for each ng-app.
45+
*
46+
* For testing, we want to disable generation and
47+
* <style> DOM injections. So we clear the huge THEME
48+
* styles while testing...
49+
*/
50+
$provide.constant('$MD_THEME_CSS', '/**/');
51+
52+
/**
53+
* Intercept to make .expectWithText() to be synchronous
54+
*/
55+
$provide.decorator('$mdAria', function($delegate){
56+
57+
$delegate.expectWithText = function(element, attrName){
58+
$delegate.expect(element, attrName, element.text().trim());
59+
};
60+
61+
return $delegate;
62+
});
63+
64+
/**
65+
* Add throttle() and wrap .flush() to catch `no callbacks present`
66+
* errors
67+
*/
68+
$provide.decorator('$$rAF', function throttleInjector($delegate){
69+
70+
$delegate.throttle = function(cb) {
71+
return function() {
72+
cb.apply(this, arguments);
73+
};
74+
};
75+
76+
var ngFlush = $delegate.flush;
77+
$delegate.flush = function() {
78+
try { ngFlush(); }
79+
catch(e) { ; }
80+
};
81+
82+
return $delegate;
83+
});
84+
85+
/**
86+
* Capture $timeout.flush() errors: "No deferred tasks to be flushed"
87+
* errors
88+
*/
89+
$provide.decorator('$timeout', function throttleInjector($delegate){
90+
91+
var ngFlush = $delegate.flush;
92+
$delegate.flush = function() {
93+
var args = Array.prototype.slice.call(arguments);
94+
try { ngFlush.apply($delegate, args); }
95+
catch(e) { ; }
96+
};
97+
98+
return $delegate;
99+
});
100+
101+
}])
102+
103+
/**
104+
* Stylesheet Mocks used by `animateCss.spec.js`
105+
*/
106+
window.createMockStyleSheet = function createMockStyleSheet(doc, wind) {
107+
doc = doc ? doc[0] : window.document;
108+
wind = wind || window;
109+
110+
var node = doc.createElement('style');
111+
var head = doc.getElementsByTagName('head')[0];
112+
head.appendChild(node);
113+
114+
var ss = doc.styleSheets[doc.styleSheets.length - 1];
115+
116+
return {
117+
addRule: function(selector, styles) {
118+
styles = addVendorPrefix(styles);
119+
120+
try {
121+
ss.insertRule(selector + '{ ' + styles + '}', 0);
122+
}
123+
catch (e) {
124+
try {
125+
ss.addRule(selector, styles);
126+
}
127+
catch (e2) {}
128+
}
129+
},
130+
131+
destroy: function() {
132+
head.removeChild(node);
133+
}
134+
};
135+
136+
/**
137+
* Decompose styles, attached specific vendor prefixes
138+
* and recompose...
139+
* e.g.
140+
* 'transition:0.5s linear all; font-size:100px;'
141+
* becomes
142+
* '-webkit-transition:0.5s linear all; transition:0.5s linear all; font-size:100px;'
143+
*/
144+
function addVendorPrefix(styles) {
145+
var cache = { };
146+
147+
// Decompose into cache registry
148+
styles
149+
.match(/([\-A-Za-z]*)\w\:\w*([A-Za-z0-9\.\-\s]*)/gi)
150+
.forEach(function(style){
151+
var pair = style.split(":");
152+
var key = pair[0];
153+
154+
switch(key) {
155+
case 'transition':
156+
case 'transform':
157+
case 'animation':
158+
case 'transition-duration':
159+
case 'animation-duration':
160+
cache[key] = cache['-webkit-' + key] = pair[1];
161+
break;
162+
default:
163+
cache[key] = pair[1];
164+
}
165+
});
166+
167+
// Recompose full style object (as string)
168+
styles = "";
169+
angular.forEach(cache, function(value, key) {
170+
styles = styles + key + ":" + value + "; ";
171+
});
172+
173+
return styles;
174+
}
175+
176+
};
177+
178+
})(window, window.angular);

0 commit comments

Comments
 (0)