-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1328 from GrosPoulet/master
Fix for GitLab plug-in + new plug-ins (Nature, opendata)
- Loading branch information
Showing
4 changed files
with
113 additions
and
4 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
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,47 @@ | ||
var hoverZoomPlugins = hoverZoomPlugins || []; | ||
hoverZoomPlugins.push({ | ||
name:'nature', | ||
version:'0.1', | ||
prepareImgLinks:function (callback) { | ||
var res = []; | ||
|
||
// sample: https://media.springernature.com/lw685/springer-static/image/art%3A10.1038%2Fs41586-024-07053-4/MediaObjects/41586_2024_7053_Fig1_HTML.png?as=webp | ||
// -> https://media.springernature.com/full/springer-static/image/art%3A10.1038%2Fs41586-024-07053-4/MediaObjects/41586_2024_7053_Fig1_HTML.png?as=webp | ||
// sample: https://images.nature.com/w140h79/magazine-assets/d41586-024-01036-1/d41586-024-01036-1_26947866.jpg | ||
// -> https://images.nature.com/original/magazine-assets/d41586-024-01036-1/d41586-024-01036-1_26947866.jpg | ||
|
||
const reFind1 = /\.nature.com\/l?[hw]\d+.*?\//; | ||
const reReplace1 = '.nature.com/original/'; | ||
const reFind2 = /springernature.com\/l?[hw]\d+.*?\//; | ||
const reReplace2 = 'springernature.com/full/'; | ||
|
||
function findFullsizeUrl(link, src) { | ||
let fullsizeUrl = src.replace(reFind1, reReplace1).replace(reFind2, reReplace2); | ||
if (fullsizeUrl == src) return; | ||
|
||
if (link.data().hoverZoomSrc == undefined) { link.data().hoverZoomSrc = [] } | ||
if (link.data().hoverZoomSrc.indexOf(fullsizeUrl) == -1) { | ||
link.data().hoverZoomSrc.unshift(fullsizeUrl); | ||
res.push(link); | ||
} | ||
} | ||
|
||
$('img[src]').each(function() { | ||
findFullsizeUrl($(this), this.src); | ||
}); | ||
|
||
$('[style*=url]').each(function() { | ||
// extract url from style | ||
var backgroundImage = this.style.backgroundImage; | ||
const reUrl = /.*url\s*\(\s*(.*)\s*\).*/i | ||
backgroundImage = backgroundImage.replace(reUrl, '$1'); | ||
// remove leading & trailing quotes | ||
var backgroundImageUrl = backgroundImage.replace(/^['"]/, '').replace(/['"]+$/, ''); | ||
findFullsizeUrl($(this), backgroundImageUrl); | ||
}); | ||
|
||
if (res.length) { | ||
callback($(res), this.name); | ||
} | ||
} | ||
}); |
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,54 @@ | ||
var hoverZoomPlugins = hoverZoomPlugins || []; | ||
hoverZoomPlugins.push({ | ||
name:'opendata92', | ||
version:'0.1', | ||
prepareImgLinks:function (callback) { | ||
var res = []; | ||
|
||
// sample: https://opendata.hauts-de-seine.fr/explore/dataset/fr-229200506-plans-de-carrieres/files/aea63b50e86f1ed8d3f5f26b3a39c0af/300/ | ||
// -> https://opendata.hauts-de-seine.fr/explore/dataset/fr-229200506-plans-de-carrieres/files/aea63b50e86f1ed8d3f5f26b3a39c0af/download/ | ||
|
||
const reFind = '/300/'; | ||
const reReplace = '/download/'; | ||
|
||
function findFullsizeUrl(link, src) { | ||
let fullsizeUrl = src.replace(reFind, reReplace); | ||
if (fullsizeUrl == src) return; | ||
|
||
if (link.data().hoverZoomSrc == undefined) { link.data().hoverZoomSrc = [] } | ||
if (link.data().hoverZoomSrc.indexOf(fullsizeUrl) == -1) { | ||
link.data().hoverZoomSrc.unshift(fullsizeUrl); | ||
res.push(link); | ||
} | ||
} | ||
|
||
$('img[src*="/300/"]').each(function() { | ||
findFullsizeUrl($(this), this.src); | ||
}); | ||
|
||
$('[style*=url]').filter(function() { return /\/300\//.test(this.style.backgroundImage) }).each(function() { | ||
// extract url from style | ||
var backgroundImage = this.style.backgroundImage; | ||
const reUrl = /.*url\s*\(\s*(.*)\s*\).*/i | ||
backgroundImage = backgroundImage.replace(reUrl, '$1'); | ||
// remove leading & trailing quotes | ||
var backgroundImageUrl = backgroundImage.replace(/^['"]/, '').replace(/['"]+$/, ''); | ||
findFullsizeUrl($(this), backgroundImageUrl); | ||
}); | ||
|
||
$('a[href*="/download/"]').each(function() { | ||
let link = $(this); | ||
let fullsizeUrl = this.href; | ||
|
||
if (link.data().hoverZoomSrc == undefined) { link.data().hoverZoomSrc = [] } | ||
if (link.data().hoverZoomSrc.indexOf(fullsizeUrl) == -1) { | ||
link.data().hoverZoomSrc.unshift(fullsizeUrl); | ||
res.push(link); | ||
} | ||
}); | ||
|
||
if (res.length) { | ||
callback($(res), this.name); | ||
} | ||
} | ||
}); |