diff options
author | pluralcafe-docker <docker@plural.cafe> | 2018-08-26 04:00:46 +0000 |
---|---|---|
committer | pluralcafe-docker <docker@plural.cafe> | 2018-08-26 04:00:46 +0000 |
commit | 395164add468b1079669699dfe8eeaab73f69c15 (patch) | |
tree | a3e14f9b8d4eff7debeb167660a5bbdc717e193d /app/javascript/flavours | |
parent | 0fa521de89168ef33423fc7306a33d4a1c3badf3 (diff) | |
parent | 0ddf439999b05b5dfd6d5a5257327fa7d3565e65 (diff) |
Merge branch 'glitch'
Diffstat (limited to 'app/javascript/flavours')
4 files changed, 47 insertions, 3 deletions
diff --git a/app/javascript/flavours/glitch/components/dropdown_menu.js b/app/javascript/flavours/glitch/components/dropdown_menu.js index 27b2586e5..1c2b0bf25 100644 --- a/app/javascript/flavours/glitch/components/dropdown_menu.js +++ b/app/javascript/flavours/glitch/components/dropdown_menu.js @@ -225,6 +225,12 @@ export default class Dropdown extends React.PureComponent { return this.target; } + componentWillUnmount = () => { + if (this.state.id === this.props.openDropdownId) { + this.handleClose(); + } + } + render () { const { icon, items, size, ariaLabel, disabled, dropdownPlacement, openDropdownId } = this.props; const open = this.state.id === openDropdownId; diff --git a/app/javascript/flavours/glitch/util/base64.js b/app/javascript/flavours/glitch/util/base64.js new file mode 100644 index 000000000..8226e2c54 --- /dev/null +++ b/app/javascript/flavours/glitch/util/base64.js @@ -0,0 +1,10 @@ +export const decode = base64 => { + const rawData = window.atob(base64); + const outputArray = new Uint8Array(rawData.length); + + for (let i = 0; i < rawData.length; ++i) { + outputArray[i] = rawData.charCodeAt(i); + } + + return outputArray; +}; diff --git a/app/javascript/flavours/glitch/util/base_polyfills.js b/app/javascript/flavours/glitch/util/base_polyfills.js index 7856b26f9..ad023eb73 100644 --- a/app/javascript/flavours/glitch/util/base_polyfills.js +++ b/app/javascript/flavours/glitch/util/base_polyfills.js @@ -3,7 +3,9 @@ import 'intl/locale-data/jsonp/en'; import 'es6-symbol/implement'; import includes from 'array-includes'; import assign from 'object-assign'; +import values from 'object.values'; import isNaN from 'is-nan'; +import { decode as decodeBase64 } from './base64'; if (!Array.prototype.includes) { includes.shim(); @@ -13,6 +15,30 @@ if (!Object.assign) { Object.assign = assign; } +if (!Object.values) { + values.shim(); +} + if (!Number.isNaN) { Number.isNaN = isNaN; } + +if (!HTMLCanvasElement.prototype.toBlob) { + const BASE64_MARKER = ';base64,'; + + Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', { + value(callback, type = 'image/png', quality) { + const dataURL = this.toDataURL(type, quality); + let data; + + if (dataURL.indexOf(BASE64_MARKER) >= 0) { + const [, base64] = dataURL.split(BASE64_MARKER); + data = decodeBase64(base64); + } else { + [, data] = dataURL.split(','); + } + + callback(new Blob([data], { type })); + }, + }); +} diff --git a/app/javascript/flavours/glitch/util/load_polyfills.js b/app/javascript/flavours/glitch/util/load_polyfills.js index 8927b7358..8cb81c1a6 100644 --- a/app/javascript/flavours/glitch/util/load_polyfills.js +++ b/app/javascript/flavours/glitch/util/load_polyfills.js @@ -12,11 +12,13 @@ function importExtraPolyfills() { function loadPolyfills() { const needsBasePolyfills = !( + Array.prototype.includes && + HTMLCanvasElement.prototype.toBlob && window.Intl && - Object.assign && Number.isNaN && - window.Symbol && - Array.prototype.includes + Object.assign && + Object.values && + window.Symbol ); // Latest version of Firefox and Safari do not have IntersectionObserver. |