Skip to content

Commit ad2f83f

Browse files
author
Ryan A. Johnson
committed
fix(events): Emit non-bubbling events by default
* (HXElement) Update `$emit()` * Do NOT bubble events by default * Provide capability to override event configuration. * (polyfills) Add source to compile `helix-ui.polyfills*.js` * Add `Object.assign()` polyfill * More polyfills coming soon * (Layouts) Update layout templates to include minified HelixUI polyfill * (docs) include HelixUI polyfill in templates
1 parent fbc4963 commit ad2f83f

File tree

7 files changed

+83
-6
lines changed

7 files changed

+83
-6
lines changed

docs/_templates/partials/after_footer.njk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<script src="dist/scripts/helix-ui.polyfills.js"></script>
12
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
23

34
<!-- intelligently load ES5 Adapter (if needed) -->

docs/components/layouts/horizontal-layout-template.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ <h2>Right Panel</h2>
100100
{% include 'partials/footer_legal.njk' %}
101101
</footer>
102102

103+
<!-- FIXME: point to HelixUI polyfills in node_modules/helix-ui -->
104+
<script src="dist/scripts/helix-ui.polyfills.min.js"></script>
105+
103106
<!-- Browser polyfills (mainly for IE) -->
104107
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
105108

docs/components/layouts/vertical-layout-template.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ <h1>Page Content</h1>
9797
{% include 'partials/footer_legal.njk' %}
9898
</footer>
9999

100+
<!-- FIXME: point to HelixUI polyfills in node_modules/helix-ui -->
101+
<script src="dist/scripts/helix-ui.polyfills.min.js"></script>
102+
100103
<!-- Browser polyfills (mainly for IE) -->
101104
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
102105

rollup.config.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ let lessPlugin = less({
3131
}
3232
});
3333

34+
// Intro/Outro placed INSIDE the applied dependency function
3435
let intro = `window.addEventListener('WebComponentsReady', function () {`;
3536
let outro = `});`;
3637

@@ -114,4 +115,35 @@ export default [
114115
lessPlugin,
115116
],
116117
},
118+
119+
// src/polyfills.js --> dis/helix-ui.polyfills.js (IIFE)
120+
{
121+
input: 'src/polyfills.js',
122+
sourcemap: false,
123+
output: [
124+
{
125+
file: 'dist/scripts/helix-ui.polyfills.js',
126+
format: 'iife',
127+
}
128+
],
129+
plugins: [
130+
babelPlugin,
131+
],
132+
},
133+
134+
// src/polyfills.js --> dis/helix-ui.polyfills.min.js (IIFE)
135+
{
136+
input: 'src/polyfills.js',
137+
sourcemap: false,
138+
output: [
139+
{
140+
file: 'dist/scripts/helix-ui.polyfills.min.js',
141+
format: 'iife',
142+
}
143+
],
144+
plugins: [
145+
babelPlugin,
146+
uglify({}, minify),
147+
],
148+
},
117149
]

src/helix-ui/elements/HXElement.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,14 @@ export class HXElement extends HTMLElement {
8686
}
8787
}//$preventScroll()
8888

89-
$emit (evtName, details) {
90-
let evt = new CustomEvent(evtName, {
89+
$emit (evtName, opts) {
90+
let options = Object.assign({}, {
9191
cancelable: true,
92-
bubbles: true,
93-
detail: details,
94-
});
92+
bubbles: false,
93+
}, opts);
94+
95+
let evt = new CustomEvent(evtName, options);
96+
9597
return this.dispatchEvent(evt);
9698
}//$emit
9799

@@ -106,7 +108,7 @@ export class HXElement extends HTMLElement {
106108
bubbles: oldEvent.bubbles,
107109
cancelable: oldEvent.cancelable,
108110
});
109-
this.dispatchEvent(newEvent);
111+
return this.dispatchEvent(newEvent);
110112
}//$relayEvent()
111113

112114
// TODO: may need a later update to add events based on element name/type

src/polyfills.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Entrypoint for browser polyfills
2+
import './polyfills/Object';

src/polyfills/Object.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* ========== Object ========== */
2+
3+
/* ---------- assign() ---------- */
4+
// Affected Browsers: IE
5+
// Source: (MDN) https://goo.gl/UADxBn
6+
if (typeof Object.assign != 'function') {
7+
// Must be writable: true, enumerable: false, configurable: true
8+
Object.defineProperty(Object, "assign", {
9+
value: function assign(target, varArgs) { // .length of function is 2
10+
'use strict';
11+
if (target == null) { // TypeError if undefined or null
12+
throw new TypeError('Cannot convert undefined or null to object');
13+
}
14+
15+
var to = Object(target);
16+
17+
for (var index = 1; index < arguments.length; index++) {
18+
var nextSource = arguments[index];
19+
20+
if (nextSource != null) { // Skip over if undefined or null
21+
for (var nextKey in nextSource) {
22+
// Avoid bugs when hasOwnProperty is shadowed
23+
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
24+
to[nextKey] = nextSource[nextKey];
25+
}
26+
}
27+
}
28+
}
29+
return to;
30+
},
31+
writable: true,
32+
configurable: true
33+
});
34+
}//Object.assign()

0 commit comments

Comments
 (0)