-
Notifications
You must be signed in to change notification settings - Fork 0
/
rs-container.html
68 lines (56 loc) · 2.13 KB
/
rs-container.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright (c) 2014 Dane O'Connor. All rights reserved.
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
*/
<link rel="import" href="../../bower_components/polymer/polymer.html">
<polymer-element name='rs-container'>
<script>
(function() {
// Cache original polymer createdCallback for later use
var _created = Polymer.api.instance.base.createdCallback;
// Setup RS namespace
var RS = window.RS = window.RS || {};
// Datastore for globally downgraded elements
RS.downgraded = [];
// Add an element to the global downgrade store
RS.downgrade = function(elementName) {
return this.downgraded.push(elementName);
};
// Remove an element from the global downgrade store
RS.upgrade = function(elementName) {
var idx = this.downgraded.indexOf(elementName)
return this.downgraded.splice(idx, 1);
};
/**
* Monkey patch Polymer's createdCallback to support element downgrading.
*
* When an element name is found in the downgrade list, skip polymer
* construction and create a simple HTMLElement; otherwise, continue
* with Polymer * initialization.
*/
Polymer.api.instance.base.createdCallback = function() {
var downgraded = [];
var current = this.parentNode;
var attr = 'downgrade'
var containerName = 'rs-container';
// walk hierarchy for downgrade containers and merge downgrade lists
while(current) {
if (current.localName === containerName) {
if(current.getAttribute(attr)) {
downgraded = downgraded.concat(current.getAttribute(attr).split(' '));
}
}
current = current.parentNode;
}
// merge global downgrade list
downgraded = downgraded.concat(RS.downgraded);
if (downgraded.indexOf(this.localName) >= 0 ) {
// do nothing, effectivley making this polymer element a div
} else {
_created.call(this);
}
}
Polymer({});
})();
</script>
</polymer-element>