diff --git a/docs/assets/js/src/customizer.js b/docs/assets/js/src/customizer.js index b0fefb0f03..407427a15d 100644 --- a/docs/assets/js/src/customizer.js +++ b/docs/assets/js/src/customizer.js @@ -361,32 +361,26 @@ window.onload = function () { // wait for load in a dumb way because B-0 var file = (e.originalEvent.hasOwnProperty('dataTransfer')) ? e.originalEvent.dataTransfer.files[0] : e.originalEvent.target.files[0] - if (!file.type.match('application/json')) { - return showAlert('danger', 'Ruh roh. We can only read .json files. Please try again.', importDropTarget) - } - var reader = new FileReader() - reader.onload = (function () { - return function (e) { - var text = e.target.result + reader.onload = function (e) { + var text = e.target.result - try { - var json = JSON.parse(text) + try { + var json = JSON.parse(text) - if (typeof json != 'object') { - throw new Error('JSON data from config file is not an object.') - } - - updateCustomizerFromJson(json) - showAlert('success', 'Woohoo! Your configuration was successfully uploaded. Tweak your settings, then hit Download.', importDropTarget) - } catch (err) { - return showAlert('danger', 'Shucks. We can only read valid .json files. Please try again.', importDropTarget) + if (!$.isPlainObject(json)) { + throw new Error('JSON data from config file is not an object.') } - } - })(file) - reader.readAsText(file) + updateCustomizerFromJson(json) + showAlert('success', 'Woohoo! Your configuration was successfully uploaded. Tweak your settings, then hit Download.', importDropTarget) + } catch (err) { + return showAlert('danger', 'Shucks. We can only read valid .json files. Please try again.', importDropTarget) + } + } + + reader.readAsText(file, 'utf-8') } function handleConfigDragOver(e) {