Skip to content

Commit

Permalink
use worker in ie11
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Feb 14, 2019
1 parent 2cbda35 commit a00ae47
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
18 changes: 7 additions & 11 deletions docs/demo/demo.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
/* globals marked, unfetch, ES6Promise */

var useWorker = !!window.Worker;
if (!window.Promise) {
window.Promise = ES6Promise;
useWorker = false;
}
if (!window.fetch) {
window.fetch = unfetch;
useWorker = false;
}

onunhandledrejection = function (e) {
Expand Down Expand Up @@ -42,9 +39,8 @@ var markedVersions = {
};
var markedVersionCache = {};

var iframeLoaded = false;
$previewIframe.addEventListener('load', function () {
iframeLoaded = true;
lastInput = '';
inputDirty = true;
});

Expand Down Expand Up @@ -188,7 +184,7 @@ $clearElem.addEventListener('click', function () {
}, false);

function setDefaultOptions() {
if (useWorker) {
if (window.Worker) {
messageWorker({
task: 'defaults',
version: markedVersions[$markedVerElem.value]}
Expand Down Expand Up @@ -270,7 +266,7 @@ function updateLink() {
}

function updateVersion() {
if (useWorker) {
if (window.Worker) {
handleInput();
return Promise.resolve();
}
Expand All @@ -297,7 +293,7 @@ function updateVersion() {
var delayTime = 1;
var checkChangeTimeout = null;
function checkForChanges() {
if (inputDirty && (typeof marked !== 'undefined' || (useWorker)) && $markedVerElem.value !== 'commit') {
if (inputDirty && $markedVerElem.value !== 'commit' && (typeof marked !== 'undefined' || window.Worker)) {
inputDirty = false;

updateLink();
Expand All @@ -317,7 +313,7 @@ function checkForChanges() {
var hash = version + markdown + optionsString;
if (lastInput !== hash) {
lastInput = hash;
if (useWorker) {
if (window.Worker) {
delayTime = 100;
messageWorker({
task: 'parse',
Expand Down Expand Up @@ -371,9 +367,9 @@ function setResponseTime(ms) {
}

function setParsed(parsed, lexed) {
if (iframeLoaded) {
try {
$previewIframe.contentDocument.body.innerHTML = parsed;
}
} catch (ex) {}
$htmlElem.value = parsed;
$lexerElem.value = lexed;
}
Expand Down
10 changes: 9 additions & 1 deletion docs/demo/worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
/* global marked */
/* globals marked, unfetch, ES6Promise */
if (!self.Promise) {
self.importScripts('https://cdn.jsdelivr.net/npm/es6-promise/dist/es6-promise.js');
self.Promise = ES6Promise;
}
if (!self.fetch) {
self.importScripts('https://cdn.jsdelivr.net/npm/unfetch/dist/unfetch.umd.js');
self.fetch = unfetch;
}
var versionCache = {};
var currentVersion;
onmessage = function (e) {
Expand Down

0 comments on commit a00ae47

Please sign in to comment.