Skip to content

Commit

Permalink
ui: Move the text encoding polyfill to a a proper detecting polyfill (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
johncowen authored Oct 8, 2018
1 parent 26c9476 commit 8ba1c54
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
11 changes: 11 additions & 0 deletions ui-v2/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ <h2>JavaScript Required</h2>
</noscript>
{{content-for "body"}}
<script src="{{rootURL}}assets/vendor.js"></script>
<script>
var appendScript = function(src) {
var $script = document.createElement('script');
$script.src = src;
document.body.appendChild($script);
}
if(!('TextDecoder' in window)) {
appendScript('{{rootURL}}assets/encoding-indexes.js');
appendScript('{{rootURL}}assets/encoding.js');
}
</script>
<script src="{{rootURL}}assets/consul-ui.js"></script>

{{content-for "body-footer"}}
Expand Down
5 changes: 1 addition & 4 deletions ui-v2/app/utils/atob.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import TextEncoding from 'npm:text-encoding';
import base64js from 'npm:base64-js';
export default function(str, encoding = 'utf-8') {
// decode
const bytes = base64js.toByteArray(str);
return new ('TextDecoder' in window ? TextDecoder : TextEncoding.TextDecoder)(encoding).decode(
bytes
);
return new TextDecoder(encoding).decode(bytes);
}
3 changes: 1 addition & 2 deletions ui-v2/app/utils/btoa.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import TextEncoding from 'npm:text-encoding';
import base64js from 'npm:base64-js';
export default function(str, encoding = 'utf-8') {
// encode
const bytes = new ('TextEncoder' in window ? TextEncoder : TextEncoding.TextEncoder)(encoding).encode(str);
const bytes = new TextEncoder(encoding).encode(str);
return base64js.fromByteArray(bytes);
}
2 changes: 2 additions & 0 deletions ui-v2/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ module.exports = function(defaults) {
// modules that you would like to import into your application
// please specify an object with the list of modules as keys
// along with the exports of each module as its value.
app.import('node_modules/text-encoding/lib/encoding-indexes.js', {outputFile: 'assets/encoding-indexes.js'})
app.import('node_modules/text-encoding/lib/encoding.js', {outputFile: 'assets/encoding.js'})
let tree = app.toTree();
return tree;
};

0 comments on commit 8ba1c54

Please sign in to comment.