This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/handle_pixel/script.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-03-02 17:12:43 +00:00
document.addEventListener('DOMContentLoaded', () => {
function zoom(zoom_type, save_cookie) {
save_cookie = save_cookie === undefined ? true : save_cookie;
var img = $('.shm-main-image');
if(zoom_type === "full") {
img.css('max-width', img.data('width') + 'px');
img.css('max-height', img.data('height') + 'px');
}
if(zoom_type === "width") {
img.css('max-width', '95%');
img.css('max-height', img.data('height') + 'px');
}
if(zoom_type === "height") {
img.css('max-width', img.data('width') + 'px');
img.css('max-height', (window.innerHeight * 0.95) + 'px');
}
if(zoom_type === "both") {
img.css('max-width', '95%');
img.css('max-height', (window.innerHeight * 0.95) + 'px');
}
$(".shm-zoomer").val(zoom_type);
if (save_cookie) {
shm_cookie_set("ui-image-zoom", zoom_type, {expires: 365, samesite: "lax", path: "/"});
}
}
2012-08-15 18:46:51 +00:00
$(".shm-zoomer").change(function(e) {
2012-03-24 11:16:59 +00:00
zoom(this.options[this.selectedIndex].value);
2012-03-24 23:30:19 +00:00
});
2016-09-02 02:48:33 +00:00
$(window).resize(function(e) {
$(".shm-zoomer").each(function (e) {
zoom(this.options[this.selectedIndex].value, false)
2016-09-02 02:48:33 +00:00
});
});
2012-03-24 23:30:19 +00:00
2016-09-02 04:36:34 +00:00
$("img.shm-main-image").click(function(e) {
switch(shm_cookie_get("ui-image-zoom")) {
2012-03-24 23:30:19 +00:00
case "full": zoom("width"); break;
default: zoom("full"); break;
}
2012-03-24 11:16:59 +00:00
});
if(shm_cookie_get("ui-image-zoom")) {
zoom(shm_cookie_get("ui-image-zoom"));
2012-03-24 11:16:59 +00:00
}
});