fix: keep the show parameter in the frame navigation links when the scale changes refs #5850

This commit is contained in:
Jash committed 2026-11-14 19:09:33 +05:30
1 parent 4fd5ae5982
commit be430b0ff7
2 files changed
+70 -1

No files matched your search

+69
View File
@@ -0,0 +1,69 @@
'use strict';
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const vm = require('vm');
const src = fs.readFileSync(
path.join(__dirname, '../../web/skins/classic/views/js/frame.js'), 'utf8');
function makeAnchor(href) {
return {
href: href,
prop: function(name, value) {
if (value === undefined) return this[name];
this[name] = value;
return this;
},
};
}
function load(anchors) {
const stub = {
val: () => '200',
css: () => stub,
prop: () => stub,
off: () => stub,
on: () => stub,
width: () => 2000,
is: () => true,
toggle: () => stub,
ready: () => stub,
};
const globals = {
$j: Object.assign(function(selector) {
if (selector === '#nextLink') return anchors.next;
if (selector === '#prevLink') return anchors.prev;
if (selector === '#firstLink') return anchors.first;
if (selector === '#lastLink') return anchors.last;
return stub;
}, {each: (obj, fn) => Object.keys(obj).forEach((k) => fn(k, obj[k]))}),
SCALE_BASE: 100,
setCookie: () => {},
scaleToFit: () => ({width: 1, height: 1, autoScale: 0}),
endOfResize: () => {},
document: {referrer: ''},
window: {},
console: {log() {}},
};
vm.createContext(globals);
vm.runInContext(src, globals, {filename: 'frame.js'});
return globals;
}
const base = '?view=frame&eid=7&scale=100&show=capture&fid=';
const anchors = {
next: makeAnchor(base + '5'),
prev: makeAnchor(base + '3'),
first: makeAnchor(base + '1'),
last: makeAnchor(base + '9'),
};
const ctx = load(anchors);
ctx.changeScale();
assert.strictEqual(anchors.next.href, '?view=frame&eid=7&scale=200&show=capture&fid=5');
assert.strictEqual(anchors.prev.href, '?view=frame&eid=7&scale=200&show=capture&fid=3');
assert.strictEqual(anchors.first.href, '?view=frame&eid=7&scale=200&show=capture&fid=1');
assert.strictEqual(anchors.last.href, '?view=frame&eid=7&scale=200&show=capture&fid=9');
console.log(' ok changing the scale keeps the show parameter in the frame links');
+1 -1
View File
@@ -31,7 +31,7 @@ function changeScale() {
setCookie('zmWatchScale', scale);
$j.each(controlsLinks, function(k, anchor) { // Make frames respect scale choices
if (anchor) {
anchor.prop('href', anchor.prop('href').replace(/scale=.*&/, 'scale=' + scale + '&'));
anchor.prop('href', anchor.prop('href').replace(/scale=[^&]*/, 'scale=' + scale));
}
});