You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What I needed was to trigger some things when the icons were loaded, eg. making a skeleton layout like facebook or slack.
constsvg4everybody=require('svg4everybody');constmodernizr=require('modernizr');letxhrOnOpen=XMLHttpRequest.prototype.open;functiononStateChange(event){// fires on every readystatechange ever// use `this` to determine which XHR object fired the change event.if(this.responseURL&&'.svg'===this.responseURL.slice(-4)){if('function'!==typeofEvent){if('function'!==document.createEvent){// IE8 => not supported for now.return;}// Fallback case for IE, not supporting new Event.varevent=document.createEvent('Event');event.initEvent('done.svg4everybody',true,true);returndocument.dispatchEvent(event);}event=newEvent('done.svg4everybody');document.body.dispatchEvent(event);}}XMLHttpRequest.prototype.open=function(){if(modernizr.eventlistener){this.addEventListener('load',onStateChange);}elseif('function'===typeofwindow.attachEvent){// Fallback case for IE, not supporting addEventListener.this.attachEvent('load',onStateChange);}xhrOnOpen.apply(this,arguments);}
It's vanilla javascript and taking only IE9+ into account. Could have done better, I'll improve it when I'll be able to do extended test on IE8.
It's not a very elegant way to do it and I'd love to find a way to implement it inside svg4everybody. What I don't know is, "Would it be better to..."
make the xhr object available from the outside (public) ? Meh.
add some public API to add / remove listener to the xhr object ?
work with events as I've "done" here ?
Any thoughts guys ?
The text was updated successfully, but these errors were encountered:
adrienrn
changed the title
API or events for completion of the Ajax
API or events for completion of the completion of the ajax query
Dec 12, 2017
What I needed was to trigger some things when the icons were loaded, eg. making a skeleton layout like facebook or slack.
It's vanilla javascript and taking only IE9+ into account. Could have done better, I'll improve it when I'll be able to do extended test on IE8.
It's not a very elegant way to do it and I'd love to find a way to implement it inside svg4everybody. What I don't know is, "Would it be better to..."
Any thoughts guys ?
The text was updated successfully, but these errors were encountered: