Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wolnosciowiec-archive/image-replace
Switches tagged images with a fall back URL on image load failure.
https://github.com/wolnosciowiec-archive/image-replace
hotlink hotlink-verification image-failover image-switcher load-failure verify wolnosciowiec
Last synced: about 2 months ago
JSON representation
Switches tagged images with a fall back URL on image load failure.
- Host: GitHub
- URL: https://github.com/wolnosciowiec-archive/image-replace
- Owner: Wolnosciowiec-Archive
- Created: 2016-12-19T06:08:04.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-28T08:28:14.000Z (almost 8 years ago)
- Last Synced: 2024-10-10T10:22:02.523Z (2 months ago)
- Topics: hotlink, hotlink-verification, image-failover, image-switcher, load-failure, verify, wolnosciowiec
- Language: JavaScript
- Size: 163 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Image Replace
=============Technology: Vanilla JS. NO JQUERY USED.
Switches tagged images with a fall back URL on image load failure.
Example scenario:
- We hotlink a resource, but we have a cache
- Hotlinked resource expired, so we switch to our local cache
- Optionally we could send a report with an ajax call, so the server could verify those resources```
/*
* Wolnościowiec / Image Replace
* -----------------------------
*
* Switches tagged images with a fall back URL on image load failure.
* A part of an anarchist portal - wolnosciowiec.net
*
* Wolnościowiec is a project to integrate the movement
* of people who strive to build a society based on
* solidarity, freedom, equality with a respect for
* individual and cooperation of each other.
*
* We support human rights, animal rights, feminism,
* anti-capitalism (taking over the production by workers),
* anti-racism, and internationalism. We negate
* the political fight and politicians at all.
*
* http://wolnosciowiec.net/en
*
* License: LGPLv3
* Author: Wolnościowiec team
*
* @see https://github.com/Wolnosciowiec/image-replace
*/
```Installation via bower
======================```
bower install wolnosciowiec-image-replace --save
```Usage
=====Include the library
```html
```
Initialize the service *at the beginning* of the document
```js
var imgReplace = new WolnosciowiecImageReplace({
'./not-working-example.jpg': './replacement.jpg'
});
```Add mapping and event
```html
```Optionally add reporting
```html
// on document load send a report
document.addEventListener("DOMContentLoaded", function() {
window.setTimeout('imgReplace.sendErrorReport();', 1000);
});```
## FAQ
1. I have different ajax call parameters, so the `imgReplace.sendErrorReport()` would not work for me
At first you could pass options in second parameter of WolnosciowiecImageReplace constructor.
Example:
```
new WolnosciowiecImageReplace({'img1': 'img-fallback', '...': '...'}, {
'successCallback': function (xhr) { console.info('successCallback', xhr); },
'failureCallback': function (xhr) { console.warn('failureCallback', xhr); },
'url': '/report/images/send',
'method': 'POST'
});
```Other way is to overload the `WolnosciowiecImageReplace.sendErrorReport` method and write your own here.
Suggestion
==========Could be used together with a [file repository](https://github.com/Wolnosciowiec/image-repository) and [remote resource verifier](https://github.com/Wolnosciowiec/remote-resource-verifier)