Skip to content

Commit

Permalink
Add Polyfills for IE11.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentaudebert authored and Loic Teixeira committed Jul 13, 2017
1 parent e982b2f commit 3cc1159
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ $virtualenv.tar.gz
*.log
*.pot
bin

.vscode/
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@
}
},
"dependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2",
"draft-js": "^0.10.0",
"draftail": "^0.6.0",
"promise": "^8.0.0",
"prop-types": "^15.5.8",
"react": "^15.4.2",
"react-autosuggest": "^3.7.4",
"draft-js": "^0.10.0",
"draftail": "^0.6.0"
"react-dom": "^15.4.2",
"whatwg-fetch": "^2.0.3"
},
"devDependencies": {
"babel-core": "^6.22.1",
Expand All @@ -82,5 +84,5 @@
"start": "webpack --config wagtailmodelchoosers/client/webpack.config.dev.js --watch",
"dist": "webpack --config wagtailmodelchoosers/client/webpack.config.prod.js",
"lint": "eslint wagtailmodelchoosers/client"
}
}
}
66 changes: 66 additions & 0 deletions wagtailmodelchoosers/client/polyfills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* This file is automatically included in the JS bundle.
* Don't import it manually.
*/

if (typeof Promise === 'undefined') {
// Rejection tracking prevents a common issue where React gets into an
// inconsistent state due to an error, but it gets swallowed by a Promise,
// and the user has no idea what causes React's erratic future behavior.
/* eslint-disable global-require */
require('promise/lib/rejection-tracking').enable();
window.Promise = require('promise/lib/es6-extensions.js');
/* eslint-enable */
}

// fetch() polyfill for making API calls.
// Uncomment this line to use fetch in your code.
// It is left out by default, because the polyfill is big.
require('whatwg-fetch');

/* eslint-disable */
// https://tc39.github.io/ecma262/#sec-array.prototype.find
if (!Array.prototype.find) {
Object.defineProperty(Array.prototype, 'find', {
value: function(predicate) {
// 1. Let O be ? ToObject(this value).
if (this == null) {
throw new TypeError('"this" is null or not defined');
}

var o = Object(this);

// 2. Let len be ? ToLength(? Get(O, "length")).
var len = o.length >>> 0;

// 3. If IsCallable(predicate) is false, throw a TypeError exception.
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}

// 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
var thisArg = arguments[1];

// 5. Let k be 0.
var k = 0;

// 6. Repeat, while k < len
while (k < len) {
// a. Let Pk be ! ToString(k).
// b. Let kValue be ? Get(O, Pk).
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
// d. If testResult is true, return kValue.
var kValue = o[k];
if (predicate.call(thisArg, kValue, k, o)) {
return kValue;
}
// e. Increase k by 1.
k++;
}

// 7. Return undefined.
return undefined;
}
});
}
/* eslint-enable */
1 change: 1 addition & 0 deletions wagtailmodelchoosers/client/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const outputPath = path.join(__dirname, '..', 'static', 'wagtailmodelchoosers');
module.exports = {
entry: {
wagtailmodelchoosers: './wagtailmodelchoosers/client/wagtailmodelchoosers.js',
polyfills: './wagtailmodelchoosers/client/polyfills.js',
},
output: {
path: outputPath,
Expand Down
12 changes: 9 additions & 3 deletions wagtailmodelchoosers/wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf.urls import url
from django.contrib.staticfiles.templatetags.staticfiles import static
from django.utils.html import format_html
from django.utils.html import format_html, format_html_join

from wagtail.wagtailcore import hooks

Expand All @@ -17,10 +17,16 @@ def wagtailmodelchoosers_admin_css():

@hooks.register('insert_editor_js')
def wagtailmodelchoosers_admin_js():
return format_html(
js_files = (
'wagtailmodelchoosers/wagtailmodelchoosers.js',
'wagtailmodelchoosers/polyfills.js',
)
js_includes = format_html_join(
'\n',
'<script src="{}"></script>',
static('wagtailmodelchoosers/wagtailmodelchoosers.js')
((static(filename),) for filename in js_files)
)
return js_includes


@hooks.register('register_admin_urls')
Expand Down

0 comments on commit 3cc1159

Please sign in to comment.