-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use regular favicon URLs to be x-browser compliant
Firefox does not have a favicon API for extensions, and it errors when seeing the non-standard `"chrome://favicon/"` in the `"permissions"` Array of the manifest. Replace it with the previously used `LazyImage` so this extension will build and run in both Chrome and in Firefox. Addresses #185 This reverts commit e7afdb7.
- Loading branch information
Showing
10 changed files
with
176 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ body { | |
.favicon { | ||
display: inline-block; | ||
height: 16px; | ||
vertical-align: middle; | ||
width: 16px; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.lazy-image-container { | ||
position: relative; | ||
vertical-align: middle; | ||
} | ||
|
||
/** | ||
* Transitions for fading out LazyImage placeholders and fading in the images. | ||
*/ | ||
.lazy-image-enter { | ||
opacity: 0.01; | ||
} | ||
|
||
.lazy-image-enter.lazy-image-enter-active { | ||
opacity: 1; | ||
transition: opacity 250ms ease-in; | ||
} | ||
|
||
/** | ||
* Position the placeholder absolutely when starting to leave so the `<img>` is in the page flow to | ||
* maintain the height of the container and so this gray fades out on top of the `<img>`. | ||
*/ | ||
.lazy-image-leave { | ||
left: 0; | ||
opacity: 1; | ||
position: absolute; | ||
top: 0; | ||
} | ||
|
||
.lazy-image-leave.lazy-image-leave-active { | ||
opacity: 0.01; | ||
transition: opacity 100000ms ease-in; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* @flow */ | ||
|
||
import './LazyImage.css'; | ||
import ColorHash from 'color-hash'; | ||
import React from 'react'; | ||
import ReactCSSTransitionGroup from 'react-addons-css-transition-group'; | ||
|
||
const loadedSrcs = new Set(); | ||
const pendingLazyImages = new Set(); | ||
|
||
function checkShouldLoadLazyImages() { | ||
for (const lazyImage of pendingLazyImages) { | ||
lazyImage.checkShouldLoad(); | ||
} | ||
} | ||
|
||
// Begin the loading process a full second after initial execution to allow the popup to open | ||
// before loading images. If images begin to load too soon after the popup opens, Chrome waits | ||
// for them to fully load before showing the popup. | ||
let shouldCheck = false; | ||
setTimeout(() => { | ||
shouldCheck = true; | ||
checkShouldLoadLazyImages(); | ||
}, 1000); | ||
|
||
interface Props { | ||
className?: string; | ||
height: number; | ||
src: ?string; | ||
style?: Object; | ||
width: number; | ||
} | ||
|
||
interface State { | ||
loaded: boolean; | ||
} | ||
|
||
const colorHash = new ColorHash(); | ||
|
||
export default class LazyImage extends React.PureComponent<Props, State> { | ||
_img: ?Image; | ||
_placeholder: ?HTMLDivElement; | ||
|
||
constructor(props: Props) { | ||
super(props); | ||
this.state = { | ||
loaded: this.props.src == null || loadedSrcs.has(this.props.src), | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
if (!this.state.loaded) { | ||
pendingLazyImages.add(this); | ||
if (shouldCheck) this.checkShouldLoad(); | ||
} | ||
} | ||
|
||
componentWillUnmount() { | ||
if (pendingLazyImages.has(this)) { | ||
pendingLazyImages.delete(this); | ||
} | ||
|
||
// Ensure the loading image does not try to call this soon-to-be-unmounted component. | ||
if (this._img != null) { | ||
this._img.onload = null; | ||
this._img = null; | ||
} | ||
} | ||
|
||
checkShouldLoad() { | ||
if (!shouldCheck) return; | ||
|
||
const {src} = this.props; | ||
|
||
if (src == null || !this._placeholder) return; | ||
|
||
this._img = new Image(); | ||
this._img.onload = this.setLoaded; | ||
this._img.src = src; | ||
pendingLazyImages.delete(this); | ||
} | ||
|
||
setLoaded = () => { | ||
this._img = null; | ||
loadedSrcs.add(this.props.src); | ||
this.setState({loaded: true}); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<ReactCSSTransitionGroup | ||
className="lazy-image-container" | ||
component="div" | ||
transitionEnterTimeout={250} | ||
transitionLeaveTimeout={250} | ||
transitionName="lazy-image"> | ||
{(this.props.src != null && this.state.loaded) ? | ||
<img | ||
className={this.props.className} | ||
height={this.props.height} | ||
key="img" | ||
src={this.props.src} | ||
style={this.props.style} | ||
width={this.props.width} | ||
/> : | ||
<div | ||
className={this.props.className} | ||
key="placeholder" | ||
ref={(placeholder: ?HTMLDivElement) => { this._placeholder = placeholder; }} | ||
style={Object.assign({}, this.props.style, { | ||
background: colorHash.hex(this.props.src), | ||
borderRadius: `${this.props.height / 2}px`, | ||
height: `${this.props.height}px`, | ||
width: `${this.props.width}px`, | ||
})} | ||
/> | ||
} | ||
</ReactCSSTransitionGroup> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters