Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { Component } from '@mangoweb/scripts-base'

interface ShapesData {
interface ShapesIEData {
url: string
}

/**
* Shapes component class
* ShapesIE component class (Internet Explorer fallback)
*
* - injects SVG sprite into body
*/
export default class Shapes extends Component<ShapesData> {
export default class ShapesIE extends Component<ShapesIEData> {

static componentName = 'Shapes'
static componentName = 'ShapesIE'

init() {
document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#BasicStructure', '1.1') && this.injectSprite()
if (window.navigator.userAgent.indexOf('MSIE ') < 0 && !navigator.userAgent.match(/Trident.*rv\:11\./)) {
return
}

this.injectSprite()
}

injectSprite(): void {
Expand All @@ -34,7 +38,8 @@ export default class Shapes extends Component<ShapesData> {
if (el) {
body.insertBefore(el, body.firstChild)
}
}).catch(() => {
}).catch((error) => {
console.error(error)
setTimeout(() => this.injectSprite(), 1e4)
})
}
Expand Down
6 changes: 3 additions & 3 deletions src/scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { initializeComponents } from '@mangoweb/scripts-base'
import './plugins'

import Example from './components/Example'
import Shapes from './components/Shapes'
import ShapesIE from './components/ShapesIE'


// Sort the components alphabetically…
initializeComponents([
Example,
Shapes,
], 'initComponents')
ShapesIE,
])
2 changes: 1 addition & 1 deletion src/sprites/plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 1 addition & 3 deletions src/styles/parts/shape.sass
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

// Shapes default dimensions
&-plus
+size(20px)
stroke: #000
fill: #000
+size(em(21px))


// ... here comes other shape dimensions
Expand Down
2 changes: 1 addition & 1 deletion src/templates/layouts/default.pug
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ html(lang=manifest.lang)
// Queue of JS components to initialize
script.
initComponents = [
{ name: 'Shapes', data: { url: '#{assetPath}/sprites/shapes.svg' } }
{ name: 'ShapesIE', data: { url: '#{assetPath}/sprites/shapes.svg' } }
]

//- Application init
Expand Down
5 changes: 4 additions & 1 deletion src/templates/mixins/shape.pug
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ mixin shape(name, title)
if title
title= title

use(xlink:href='#shape-' + name)
use(xlink:href=`${assetPath}/sprites/shapes.svg#shape-${name}`)

//- IE fallback
use(xlink:href=`#shape-${name}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The polyfill code should handle this case (replace all occurences of en external resource to local one) and it should not be included in the HTML twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This way the code can be easily used in lazy loaded html content.
  2. IE is very bad at handling high JavaScript load. Scanning a whole page can do unnecessary harm during the page load while other work needs to be done too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enzy What do you think? Is the double use justified?