2020-03-02 17:12:43 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
2016-09-02 03:34:18 +00:00
|
|
|
function zoom(zoom_type, save_cookie) {
|
|
|
|
save_cookie = save_cookie === undefined ? true : save_cookie;
|
2021-03-14 23:43:50 +00:00
|
|
|
|
2015-06-01 22:38:04 +00:00
|
|
|
var img = $('.shm-main-image');
|
2021-03-14 23:43:50 +00:00
|
|
|
|
|
|
|
if(zoom_type === "full") {
|
2015-06-01 22:38:04 +00:00
|
|
|
img.css('max-width', img.data('width') + 'px');
|
|
|
|
img.css('max-height', img.data('height') + 'px');
|
|
|
|
}
|
2021-03-14 23:43:50 +00:00
|
|
|
if(zoom_type === "width") {
|
2015-06-01 22:38:04 +00:00
|
|
|
img.css('max-width', '95%');
|
|
|
|
img.css('max-height', img.data('height') + 'px');
|
|
|
|
}
|
2021-03-14 23:43:50 +00:00
|
|
|
if(zoom_type === "height") {
|
2015-06-01 22:38:04 +00:00
|
|
|
img.css('max-width', img.data('width') + 'px');
|
|
|
|
img.css('max-height', (window.innerHeight * 0.95) + 'px');
|
|
|
|
}
|
2021-03-14 23:43:50 +00:00
|
|
|
if(zoom_type === "both") {
|
2015-06-01 22:38:04 +00:00
|
|
|
img.css('max-width', '95%');
|
|
|
|
img.css('max-height', (window.innerHeight * 0.95) + 'px');
|
|
|
|
}
|
2021-03-14 23:43:50 +00:00
|
|
|
|
2024-05-31 05:39:48 +00:00
|
|
|
const zoomed_height_diff = Math.round(window.innerHeight * 0.95 - img.height());
|
|
|
|
const zoomed_width_diff = Math.round(img.parent().width() * 0.95 - img.width());
|
|
|
|
|
|
|
|
if (zoomed_height_diff > 0 && zoomed_width_diff > 0) {
|
|
|
|
img.css('cursor', '');
|
|
|
|
} else if (zoom_type == "full") {
|
|
|
|
img.css('cursor', 'zoom-out');
|
|
|
|
} else {
|
|
|
|
img.css('cursor', 'zoom-in');
|
|
|
|
}
|
|
|
|
|
2015-06-01 22:38:04 +00:00
|
|
|
$(".shm-zoomer").val(zoom_type);
|
2021-03-14 23:43:50 +00:00
|
|
|
|
2016-09-02 03:34:18 +00:00
|
|
|
if (save_cookie) {
|
2023-12-30 13:34:00 +00:00
|
|
|
shm_cookie_set("ui-image-zoom", zoom_type);
|
2016-09-02 03:34:18 +00:00
|
|
|
}
|
2015-06-01 22:38:04 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2016-09-02 03:34:18 +00:00
|
|
|
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) {
|
2024-02-21 03:56:10 +00:00
|
|
|
var val = $(".shm-zoomer")[0].value;
|
|
|
|
var cookie = shm_cookie_get("ui-image-zoom");
|
|
|
|
|
|
|
|
if (val == "full" && cookie == "full"){
|
|
|
|
zoom("both", false);
|
|
|
|
}
|
|
|
|
else if (val != "full"){
|
|
|
|
zoom("full", false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
zoom(cookie, false);
|
2012-03-24 23:30:19 +00:00
|
|
|
}
|
2012-03-24 11:16:59 +00:00
|
|
|
});
|
|
|
|
|
2023-12-26 02:36:51 +00:00
|
|
|
if(shm_cookie_get("ui-image-zoom")) {
|
|
|
|
zoom(shm_cookie_get("ui-image-zoom"));
|
2012-03-24 11:16:59 +00:00
|
|
|
}
|
2024-02-21 03:29:36 +00:00
|
|
|
else {
|
|
|
|
zoom("both");
|
|
|
|
}
|
2012-03-24 11:16:59 +00:00
|
|
|
});
|