demos/Collage/fabric.js
function loadSVGFromURL(url, callback, reviver) {

     url = url.replace(/^\n\s*/, '').trim();

     svgCache.has(url, function (hasUrl) {
       if (hasUrl) {
         svgCache.get(url, function (value) {
           var enlivedRecord = _enlivenCachedObject(value);
           callback(enlivedRecord.objects, enlivedRecord.options);
         });
       }
       else {
         new fabric.util.request(url, {
           method: 'get',
           onComplete: onComplete
         });
       }
     });

     function onComplete(r) {

       var xml = r.responseXML;
       if (!xml.documentElement && fabric.window.ActiveXObject && r.responseText) {
         xml = new ActiveXObject('Microsoft.XMLDOM');
         xml.async = 'false';
         //IE chokes on DOCTYPE
         xml.loadXML(r.responseText.replace(/<!DOCTYPE[\s\S]*?(\[[\s\S]*\])*?>/i,''));
       }
       if (!xml.documentElement) return;

       fabric.parseSVGDocument(xml.documentElement, function (results, options) {
         svgCache.set(url, {
           objects: fabric.util.array.invoke(results, 'toObject'),
           options: options
         });
         callback(results, options);
       }, reviver);
     }
   }
function loadSVGFromURL(url, callback, reviver) {

     url = url.replace(/^\n\s*/, '').trim();

     svgCache.has(url, function (hasUrl) {
       if (hasUrl) {
         svgCache.get(url, function (value) {
           var enlivedRecord = _enlivenCachedObject(value);
           callback(enlivedRecord.objects, enlivedRecord.options);
         });
       }
       else {
         new fabric.util.request(url, {
           method: 'get',
           onComplete: onComplete
         });
       }
     });

     function onComplete(r) {

       var xml = r.responseXML;
       if (!xml.documentElement && fabric.window.ActiveXObject && r.responseText) {
         xml = new ActiveXObject('Microsoft.XMLDOM');
         xml.async = 'false';
         //IE chokes on DOCTYPE
         xml.loadXML(r.responseText.replace(/<!DOCTYPE[\s\S]*?(\[[\s\S]*\])*?>/i,''));
       }
       if (!xml.documentElement) return;

       fabric.parseSVGDocument(xml.documentElement, function (results, options) {
         svgCache.set(url, {
           objects: fabric.util.array.invoke(results, 'toObject'),
           options: options
         });
         callback(results, options);
       }, reviver);
     }
   }
function loadSVGFromURL ( url , callback , reviver ) { url = url . replace ( / ^\n\s* / , '' ) . trim ( ) ; svgCache . has ( url , function ( hasUrl ) { if ( hasUrl ) { svgCache . get ( url , function ( value ) { var enlivedRecord = _enlivenCachedObject ( value ) ; callback ( enlivedRecord . objects , enlivedRecord . options ) ; } ) ; } else { new fabric . util . request ( url , { method : 'get' , onComplete : onComplete } ) ; } } ) ; function onComplete ( r ) { var xml = r . responseXML ; if ( ! xml . documentElement && fabric . window . ActiveXObject && r . responseText ) { xml = new ActiveXObject ( 'Microsoft.XMLDOM' ) ; xml . async = 'false' ; //IE chokes on DOCTYPE xml . loadXML ( r . responseText . replace ( / <!DOCTYPE[\s\S]*?(\[[\s\S]*\])*?> / i , '' ) ) ; } if ( ! xml . documentElement ) return ; fabric . parseSVGDocument ( xml . documentElement , function ( results , options ) { svgCache . set ( url , { objects : fabric . util . array . invoke ( results , 'toObject' ) , options : options } ) ; callback ( results , options ) ; } , reviver ) ; } }
Takes url corresponding to an SVG document, and parses it into a set of fabric objects
@method loadSVGFromURL
@param {String} url
@param {Function} callback
@param {Function} [reviver] Method for further parsing of SVG elements, called after each fabric object created.
Takes url corresponding to an SVG document and parses it into a set of fabric objects