You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							39 lines
						
					
					
						
							932 B
						
					
					
				
			
		
		
	
	
							39 lines
						
					
					
						
							932 B
						
					
					
				import BrowserSprite from 'svg-baker-runtime/src/browser-sprite'; | 
						|
import domready from 'domready'; | 
						|
 | 
						|
const spriteNodeId = '__SVG_SPRITE_NODE__'; | 
						|
const spriteGlobalVarName = '__SVG_SPRITE__'; | 
						|
const isSpriteExists = !!window[spriteGlobalVarName]; | 
						|
 | 
						|
// eslint-disable-next-line import/no-mutable-exports | 
						|
let sprite; | 
						|
 | 
						|
if (isSpriteExists) { | 
						|
  sprite = window[spriteGlobalVarName]; | 
						|
} else { | 
						|
  sprite = new BrowserSprite({ attrs: { id: spriteNodeId } }); | 
						|
  window[spriteGlobalVarName] = sprite; | 
						|
} | 
						|
 | 
						|
const loadSprite = () => { | 
						|
  /** | 
						|
   * Check for page already contains sprite node | 
						|
   * If found - attach to and reuse it's content | 
						|
   * If not - render and mount the new sprite | 
						|
   */ | 
						|
  const existing = document.getElementById(spriteNodeId); | 
						|
 | 
						|
  if (existing) { | 
						|
    sprite.attach(existing); | 
						|
  } else { | 
						|
    sprite.mount(document.body, true); | 
						|
  } | 
						|
}; | 
						|
 | 
						|
if (document.body) { | 
						|
  loadSprite(); | 
						|
} else { | 
						|
  domready(loadSprite); | 
						|
} | 
						|
 | 
						|
export default sprite;
 | 
						|
 |