-
Notifications
You must be signed in to change notification settings - Fork 178
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 #1099 from GrosPoulet/master
New plug-in for: geograph.org
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
var hoverZoomPlugins = hoverZoomPlugins || []; | ||
hoverZoomPlugins.push({ | ||
name:'geograph', | ||
version:'0.1', | ||
prepareImgLinks:function (callback) { | ||
var res = []; | ||
|
||
hoverZoom.urlReplace(res, | ||
'img[src], [style*="url"]', | ||
[/_\d+x\d+/, /_\d+XX\d+/], | ||
['', ''] | ||
); | ||
|
||
hoverZoom.urlReplace(res, | ||
'img[src], [style*="url"]', | ||
[/_\d+x\d+/, /_\d+XX\d+/], | ||
['_1024x1024', '_1024x1024'] | ||
); | ||
|
||
// sample: https://s0.geograph.org.uk/geophotos/02/50/43/2504372_3398f781_120x120.jpg | ||
// fullsize: https://s0.geograph.org.uk/geophotos/02/50/43/2504372_3398f781_original.jpg (NSFW !) | ||
hoverZoom.urlReplace(res, | ||
'img[src], [style*="url"]', | ||
[/_\d+x\d+/, /_\d+XX\d+/], | ||
['_original', '_original'] | ||
); | ||
|
||
$('[href*="/photo/"], [href*="/gridref/"]').one('mouseenter', function() { | ||
if ($(this).find('img').length) return; | ||
var link = $(this); | ||
// clean previous result | ||
link.data().hoverZoomSrc = []; | ||
link.data().hoverZoomGallerySrc = []; | ||
link.data().hoverZoomGalleryCaption = []; | ||
hoverZoom.prepareFromDocument($(this), this.href, function(doc, callback) { | ||
console.log(link); | ||
let imgs = doc.querySelectorAll('img[src*="photos/"]'); | ||
if (imgs) { | ||
var gallery = []; | ||
$(imgs).each(function() { | ||
console.log(this.src); | ||
gallery.push([this.src.replace(/_\d+x\d+/, '').replace(/_\d+XX\d+/, '')]); | ||
link.data().hoverZoomGalleryCaption.push([this.alt]); | ||
}); | ||
callback(gallery); | ||
hoverZoom.displayPicFromElement(link); | ||
} | ||
}, true); // get source async | ||
}); | ||
|
||
callback($(res), this.name); | ||
} | ||
}); |