Fixing various IE-related issues

This commit is contained in:
Jeff Avallone 2014-12-15 18:06:16 -05:00
parent 5a96955419
commit db62743d54
4 changed files with 61 additions and 17 deletions

View File

@ -24,6 +24,7 @@
<div id="error"></div>
<!-- NOTE: Do not put anything in #regexp-render other than the <svg> element -->
<div id="regexp-render">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<style type="text/css">

View File

@ -5,6 +5,9 @@ import Regexper from './regexper.js';
regexper.bindListeners();
setTimeout(() => {
window.dispatchEvent(new Event('hashchange'));
var evt = document.createEvent('Event');
evt.initEvent('hashchange', true, true);
window.dispatchEvent(evt);
});
}());

View File

@ -93,20 +93,28 @@ export default {
},
doneRender() {
var evt, deferred = Q.defer();
if (maxCounter === 0) {
maxCounter = renderCounter;
}
renderCounter--;
document.body.dispatchEvent(new CustomEvent('updateStatus', {
detail: {
evt = document.createEvent('Event');
evt.initEvent('updateStatus', true, true);
evt.detail = {
percentage: (maxCounter - renderCounter) / maxCounter
}
}));
};
document.body.dispatchEvent(evt);
if (renderCounter === 0) {
maxCounter = 0;
}
setTimeout(deferred.resolve.bind(deferred), 1);
return deferred.promise;
},
render(container) {

View File

@ -18,21 +18,42 @@ export default class Regexper {
}
keypressListener(event) {
var evt;
if (event.shiftKey && event.keyCode === 13) {
event.returnValue = false;
if (event.preventDefault) {
event.preventDefault();
this.form.dispatchEvent(new Event('submit'));
}
evt = document.createEvent('Event');
evt.initEvent('submit', true, true);
this.form.dispatchEvent(evt);
}
}
submitListener(event) {
event.preventDefault();
location.hash = encodeURIComponent(this.field.value);
try {
this.disablePermalink = false;
location.hash = this.field.value;
}
catch(e) {
// Most likely failed to set the URL has (probably because the expression
// is too long). Turn off the permalink and just show the expression
this.disablePermalink = true;
this.showExpression(this.field.value);
}
}
hashchangeListener() {
var expression = decodeURIComponent(location.hash.slice(1));
this.showExpression(expression);
}
showExpression(expression) {
if (expression !== '') {
this.field.value = expression;
@ -62,10 +83,7 @@ export default class Regexper {
}
setState(state) {
var classList = this.root.classList;
classList.remove('is-loading', 'has-results', 'has-error');
classList.add(state);
this.root.className = state;
}
showError(message) {
@ -79,11 +97,25 @@ export default class Regexper {
updateLinks() {
var blob, url;
blob = new Blob([this.svg.outerHTML], { type: 'image/svg+xml' });
try {
blob = new Blob([this.svg.parentNode.innerHTML], { type: 'image/svg+xml' });
url = URL.createObjectURL(blob);
window.blob = blob; // Blob object has to stick around for IE
this.download.setAttribute('href', url);
this.permalink.setAttribute('href', location);
}
catch(e) {
// Blobs or URLs created from them don't work here.
// Giving up on the download link
this.download.parentNode.style.display = 'none';
}
if (this.disablePermalink) {
this.permalink.parentNode.style.display = 'none';
} else {
this.permalink.parentNode.style.display = null;
this.permalink.setAttribute('href', location.toString());
}
}
renderRegexp(expression) {