// Generated by CoffeeScript 1.10.0 /* (C) 2015 Narazaka : Licensed under The MIT License - http://narazaka.net/license/MIT?2015 */ (function() { var computed_styles, num2px, page_offset, px2num, wheelevent, wheelzoom; px2num = function(px) { return px.substr(0, px.length - 2) - 0; }; num2px = function(num) { return num + 'px'; }; computed_styles = function(element) { var base; return typeof (base = document.defaultView || window).getComputedStyle === "function" ? base.getComputedStyle(element, null) : void 0; }; page_offset = function(element) { var box, docElem, win; docElem = element.ownerDocument.documentElement; box = element.getBoundingClientRect(); win = document.defaultView || element.parentWindow || window; return { top: box.top + (win.pageYOffset || docElem.scrollTop) - (docElem.clientTop || 0), left: box.left + (win.pageXOffset || docElem.scrollLeft) - (docElem.clientLeft || 0) }; }; wheelevent = this.wheelevent; wheelzoom = function(target, parent) { var handler; if (parent == null) { parent = target.parentNode; } target.style.position = 'relative'; target.style.left = '0px'; target.style.top = '0px'; target.setAttribute('data-wheelzoom-scale-factor', 0); handler = function(event, delta) { var height, left, mouse_x, mouse_y, offset, old_height, old_left, old_scale, old_scale_factor, old_target_styles, old_top, old_width, scale, scale_delta, scale_factor, top, width; old_scale_factor = target.getAttribute('data-wheelzoom-scale-factor') - 0; scale_factor = old_scale_factor + (Math.abs(delta) > 80 ? delta / 1000 : delta / 30); old_scale = Math.exp(old_scale_factor); scale = Math.exp(scale_factor); old_left = px2num(target.style.left); old_top = px2num(target.style.top); old_width = target.clientWidth; old_height = target.clientHeight; if (!old_width) { old_target_styles = computed_styles(target); old_width = px2num(old_target_styles.width); old_height = px2num(old_target_styles.height); } offset = page_offset(parent); mouse_x = (event.clientX || window.event.clientX) + parent.ownerDocument.documentElement.scrollLeft - offset.left; mouse_y = (event.clientY || window.event.clientY) + parent.ownerDocument.documentElement.scrollTop - offset.top; scale_delta = scale / old_scale; left = mouse_x - (mouse_x - old_left) * scale_delta; top = mouse_y - (mouse_y - old_top) * scale_delta; width = old_width * scale_delta; height = old_height * scale_delta; target.style.width = num2px(width); target.style.height = num2px(height); target.style.left = num2px(left); target.style.top = num2px(top); target.setAttribute('data-wheelzoom-scale-factor', scale_factor); if (typeof event.preventDefault === "function") { event.preventDefault(); } return false; }; return wheelevent(parent, handler); }; this.wheelzoom = wheelzoom; }).call(this);