From 6a6480181d5a00787ee57dcf25b5a64e7e08f6e4 Mon Sep 17 00:00:00 2001 From: jgen Date: Mon, 1 Jun 2015 15:38:04 -0700 Subject: [PATCH] Move zoom function inside closure so it isn't potentially knocked out by other functions (with same name) in global scope. --- ext/handle_pixel/script.js | 49 +++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/ext/handle_pixel/script.js b/ext/handle_pixel/script.js index 8c3a50dd..83bd56ac 100644 --- a/ext/handle_pixel/script.js +++ b/ext/handle_pixel/script.js @@ -1,4 +1,29 @@ $(function() { + function zoom(zoom_type) { + 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); + + $.cookie("ui-image-zoom", zoom_type, {path: '/', expires: 365}); + } + $(".shm-zoomer").change(function(e) { zoom(this.options[this.selectedIndex].value); }); @@ -14,27 +39,3 @@ $(function() { zoom($.cookie("ui-image-zoom")); } }); - -function zoom(zoom_type) { - 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); - - $.cookie("ui-image-zoom", zoom_type, {path: '/', expires: 365}); -}