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

View File

@ -5,6 +5,9 @@ import Regexper from './regexper.js';
regexper.bindListeners(); regexper.bindListeners();
setTimeout(() => { 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() { doneRender() {
var evt, deferred = Q.defer();
if (maxCounter === 0) { if (maxCounter === 0) {
maxCounter = renderCounter; maxCounter = renderCounter;
} }
renderCounter--; renderCounter--;
document.body.dispatchEvent(new CustomEvent('updateStatus', {
detail: { evt = document.createEvent('Event');
percentage: (maxCounter - renderCounter) / maxCounter evt.initEvent('updateStatus', true, true);
} evt.detail = {
})); percentage: (maxCounter - renderCounter) / maxCounter
};
document.body.dispatchEvent(evt);
if (renderCounter === 0) { if (renderCounter === 0) {
maxCounter = 0; maxCounter = 0;
} }
setTimeout(deferred.resolve.bind(deferred), 1);
return deferred.promise;
}, },
render(container) { render(container) {

View File

@ -18,21 +18,42 @@ export default class Regexper {
} }
keypressListener(event) { keypressListener(event) {
var evt;
if (event.shiftKey && event.keyCode === 13) { if (event.shiftKey && event.keyCode === 13) {
event.preventDefault(); event.returnValue = false;
this.form.dispatchEvent(new Event('submit')); if (event.preventDefault) {
event.preventDefault();
}
evt = document.createEvent('Event');
evt.initEvent('submit', true, true);
this.form.dispatchEvent(evt);
} }
} }
submitListener(event) { submitListener(event) {
event.preventDefault(); 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() { hashchangeListener() {
var expression = decodeURIComponent(location.hash.slice(1)); var expression = decodeURIComponent(location.hash.slice(1));
this.showExpression(expression);
}
showExpression(expression) {
if (expression !== '') { if (expression !== '') {
this.field.value = expression; this.field.value = expression;
@ -62,10 +83,7 @@ export default class Regexper {
} }
setState(state) { setState(state) {
var classList = this.root.classList; this.root.className = state;
classList.remove('is-loading', 'has-results', 'has-error');
classList.add(state);
} }
showError(message) { showError(message) {
@ -79,11 +97,25 @@ export default class Regexper {
updateLinks() { updateLinks() {
var blob, url; var blob, url;
blob = new Blob([this.svg.outerHTML], { type: 'image/svg+xml' }); try {
url = URL.createObjectURL(blob); 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.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) { renderRegexp(expression) {