ui: Move the text encoding polyfill to a a proper detecting polyfill (#4767)

This commit is contained in:
John Cowen 2018-10-08 17:47:44 +01:00 committed by GitHub
parent 26c94764b8
commit 8ba1c549a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 6 deletions

View File

@ -25,6 +25,17 @@
</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"}}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;
};