Scan to open on your phone
Point a camera at the QR code - it opens this exact paste, no app needed.
https://codepastes.com/zzgrwvty56j241d3actor_photo_zoom.jsJavaScript
/*
* Lampa plugin: actor photo zoom
* On the actor (person) page the photo becomes focusable (remote / touch / mouse).
* Press OK / tap -> the photo opens proportionally at full screen height.
* Back / OK / tap closes it.
*
* ES5 only, so it works on old Tizen / WebOS TV browsers.
*/
(function () {
'use strict';
if (window.actor_photo_zoom_plugin) return;
window.actor_photo_zoom_plugin = true;
var CONTROLLER = 'actor_photo_zoom';
var viewer = null; // overlay element (jQuery) while open
var prev_controller = 'content';
var timer = null;
function addStyle() {
if ($('#actor-photo-zoom-style').length) return;
$('head').append(
'<style id="actor-photo-zoom-style">' +
'.person-start__poster.actor-photo-zoom{cursor:pointer;display:inline-block;border-radius:1em;}' +
'.person-start__poster.actor-photo-zoom.focus .person-start__img{box-shadow:0 0 0 0.25em #fff;}' +
'.actor-photo-viewer{position:fixed;left:0;top:0;width:100%;height:100%;z-index:10000;' +
'background:rgba(0,0,0,0.93);display:flex;align-items:center;justify-content:center;' +
'opacity:0;transition:opacity .25s;}' +
'.actor-photo-viewer.actor-photo-viewer--show{opacity:1;}' +
'.actor-photo-viewer img{height:100%;width:auto;max-width:100%;object-fit:contain;display:block;}' +
'</style>'
);
}
function bigUrl(src) {
// TMDB image path: .../t/p/w500/abc.jpg -> .../t/p/original/abc.jpg
if (!src || !/\/t\/p\/[^\/]+\//.test(src)) return src;
return src.replace(/\/t\/p\/[^\/]+\//, '/t/p/original/');
}
function close() {
if (!viewer) return;
var v = viewer;
viewer = null;
v.removeClass('actor-photo-viewer--show');
setTimeout(function () { v.remove(); }, 250);
try { Lampa.Controller.toggle(prev_controller || 'content'); } catch (e) {}
}
function registerController() {
Lampa.Controller.add(CONTROLLER, {
invisible: true,
toggle: function () {
Lampa.Controller.clear();
},
enter: close,
back: close,
up: close,
down: close,
left: close,
right: close
});
}
function open(src) {
if (viewer || !src) return;
var big = bigUrl(src);
var img = $('<img />');
img.attr('src', src); // show the already loaded thumbnail instantly
viewer = $('<div class="actor-photo-viewer"></div>').append(img);
viewer.on('click', close);
$('body').append(viewer);
// upgrade to the large version when it is loaded
if (big && big !== src) {
var pre = new Image();
pre.onload = function () { if (viewer && img.parent().length) img.attr('src', big); };
pre.src = big;
}
setTimeout(function () { if (viewer) viewer.addClass('actor-photo-viewer--show'); }, 20);
try {
var cur = Lampa.Controller.enabled();
prev_controller = cur && cur.name ? cur.name : 'content';
} catch (e) { prev_controller = 'content'; }
Lampa.Controller.toggle(CONTROLLER);
}
function isActorPage() {
try {
var a = Lampa.Activity.active();
return !!(a && a.component === 'actor');
} catch (e) { return false; }
}
function process() {
if (!isActorPage()) return;
$('.person-start__poster').each(function () {
var poster = $(this);
if (poster.attr('data-photo-zoom')) return;
poster.attr('data-photo-zoom', '1');
poster.addClass('selector actor-photo-zoom');
poster.on('hover:enter', function () {
var src = poster.find('img').attr('src');
open(src);
});
// if the page has already taken focus, rebuild the navigation list once
try {
if (Lampa.Controller.enabled().name === 'items_line') {
var scroll = poster.closest('.scroll');
if (scroll.length) {
var focused = scroll.find('.focus')[0] || false;
Lampa.Controller.collectionSet(scroll[0]);
Lampa.Controller.collectionFocus(focused, scroll[0]);
}
}
} catch (e) {}
});
}
function schedule() {
if (timer) clearTimeout(timer);
timer = setTimeout(process, 100);
}
function start() {
addStyle();
registerController();
try {
Lampa.Listener.follow('activity', function (e) {
if (e && (e.type === 'start' || e.type === 'archive')) schedule();
});
} catch (e) {}
if (window.MutationObserver) {
new MutationObserver(schedule).observe(document.body, { childList: true, subtree: true });
} else {
setInterval(process, 1000);
}
schedule();
}
if (window.appready) start();
else {
Lampa.Listener.follow('app', function (e) {
if (e.type === 'ready') start();
});
}
})();5,323 chars · codepastes.com