Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement for plug-in: Wordpress #1342

Merged
merged 1 commit into from
May 1, 2024
Merged
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
61 changes: 31 additions & 30 deletions plugins/wordpress_a.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
var hoverZoomPlugins = hoverZoomPlugins || [];
hoverZoomPlugins.push({
name:'Wordpress',
version:'2.4',
version:'2.5',
favicon:'worldpress.svg',
prepareImgLinks:function (callback) {

var res = [];

$('img[src*="wp-content"]').each(function () {
let img = $(this),
// sample: https://globalvoices.org/wp-content/uploads/2018/11/Migrants_in_Hungary_2015_Aug_018-800x450-400x300.jpg
// -> https://globalvoices.org/wp-content/uploads/2018/11/Migrants_in_Hungary_2015_Aug_018.jpg
// sample: https://www.ece.fr/ecole-ingenieur/wp-content/uploads/2013/08/prepa-integree-ecole-ingenieur-454x240-c-default.jpg
// -> https://www.ece.fr/ecole-ingenieur/wp-content/uploads/2013/08/prepa-integree-ecole-ingenieur.jpg
// sample: https://blind.com/wp-content/uploads/2016/09/motion_animation2-640x0-cropped.jpg
// -> https://blind.com/wp-content/uploads/2016/09/motion_animation2.jpg
//re = /-\d\d+x\d\d+/ig,
re = /-\d+x\d+/ig,
src = this.src;
if (src.match(re)) {
src = src.replace('-cropped', '').replace('-c-default', '').replace(re, '');
img.data().hoverZoomSrc = [src, src.replace(/jpg$/, 'jpeg')];
res.push(img);
// sample: https://globalvoices.org/wp-content/uploads/2018/11/Migrants_in_Hungary_2015_Aug_018-800x450-400x300.jpg
// -> https://globalvoices.org/wp-content/uploads/2018/11/Migrants_in_Hungary_2015_Aug_018.jpg
// sample: https://www.ece.fr/ecole-ingenieur/wp-content/uploads/2013/08/prepa-integree-ecole-ingenieur-454x240-c-default.jpg
// -> https://www.ece.fr/ecole-ingenieur/wp-content/uploads/2013/08/prepa-integree-ecole-ingenieur.jpg
// sample: https://blind.com/wp-content/uploads/2016/09/motion_animation2-640x0-cropped.jpg
// -> https://blind.com/wp-content/uploads/2016/09/motion_animation2.jpg
// sample: https://www.pariszigzag.fr/wp-content/uploads/2023/05/[email protected]
// -> https://www.pariszigzag.fr/wp-content/uploads/2023/05/[email protected]
const re = /-\d+x\d+/ig;
const re2 = /-e[0-9]{13}/;
const re3 = /-(cropped|c-default|scaled)/;

$('img[src*="wp-content/"]').each(function () {
const src = this.src;
const fullsizeUrl = src.replace(re, '').replace(re2, '').replace(re3, '');
if (fullsizeUrl !== src) {
var link = $(this);
link.data().hoverZoomSrc = [fullsizeUrl, fullsizeUrl.replace(/jpg$/, 'jpeg')];
res.push(link);
}
});

// background images
$('[style]').each(function() {
// extract url from style
// e.g: style="background-image: url(https://globalvoices.org/wp-content/uploads/2019/01/20160507_KAR5877-400x300.jpg)"
let backgroundImage = this.style.backgroundImage;
if (backgroundImage && backgroundImage.indexOf('wp-content') !== -1) {
const reUrl = /.*url\s*\(\s*(.*)\s*\).*/i;
let backgroundImageUrl = backgroundImage.replace(reUrl, '$1');
var backgroundImage = this.style.backgroundImage;
if (backgroundImage && backgroundImage.indexOf('/wp-content/') != -1) {
const reUrl = /.*url\s*\(\s*(.*)\s*\).*/i
backgroundImage = backgroundImage.replace(reUrl, '$1');
// remove leading & trailing quotes
backgroundImageUrl = backgroundImageUrl.replace(/^['"]/, "").replace(/['"]+$/, "");
//const reThumb = /-\d\d+x\d\d+/ig;
const reThumb = /-\d+x\d+/ig;
const fullsizeUrl = backgroundImageUrl.replace('-cropped', '').replace('-c-default', '').replace(reThumb, '');
var backgroundImageUrl = backgroundImage.replace(/^['"]/,"").replace(/['"]+$/,"");
const fullsizeUrl = backgroundImageUrl.replace(re, '').replace(re2, '').replace(re3, '');
if (fullsizeUrl !== backgroundImageUrl) {
const link = $(this);
if (link.data().hoverZoomSrc === undefined) { link.data().hoverZoomSrc = [] }
if (link.data().hoverZoomSrc.indexOf(fullsizeUrl) === -1) {
link.data().hoverZoomSrc.unshift(fullsizeUrl);
res.push(link);
}
var link = $(this);
link.data().hoverZoomSrc = [fullsizeUrl, fullsizeUrl.replace(/jpg$/, 'jpeg')];
res.push(link);
}
}
});
Expand Down