im/public/static/js/zoom-marker.min.js

3 lines
2.3 KiB
JavaScript
Executable File

/*! zoom_marker - v0.0.1 - */
!function(a){var b,c,d=[],e={};a.fn.extend({zoomMarker:function(d){c=a(this);var f={isDrag:!1,x:0,y:0};b=void 0===d?n:a.extend({},n,d),c.context.options=b,null===b.src?console.log("Image resources is not defined."):h(b.src),a(this).bind("mousewheel",function(a,b){return b>0?c.zoomMarker_ZoomIn():c.zoomMarker_ZoomOut(),!1}),a(this).mousedown(function(b){var c=a(this).offset();f.x=-c.left+b.pageX,f.y=-c.top+b.pageY,f.isDrag=!0}),a(this).mouseup(function(a){f.isDrag=!1}),a(this).mouseleave(function(){f.isDrag=!1}),a(this).mousemove(function(b){f.isDrag&&a(this).zoomMarker_Move(b.pageX-f.x,b.pageY-f.y),e.x=b.pageX,e.y=b.pageY})},zoomMarker_LoadImage:function(a){h(a)},zoomMarker_ZoomIn:function(){var b=a(this),c=b.context.options,d=b.offset(),f=b.height(),g=b.width();b.height(f*(1+c.rate)),b.width(g*(1+c.rate)),b.offset({top:e.y-b.height()*(e.y-d.top)/f,left:e.x-b.width()*(e.x-d.left)/g}),k()},zoomMarker_ZoomOut:function(){var b=a(this),c=b.context.options,d=b.offset(),f=b.height(),g=b.width();b.height(f*(1-c.rate)),b.width(g*(1-c.rate)),b.offset({top:e.y-b.height()*(e.y-d.top)/f,left:e.x-b.width()*(e.x-d.left)/g}),k()},zoomMarker_Move:function(b,c){a(this).offset({top:c,left:b}),k()},zoomMarker_AddMarker:function(a){return j(a)},zoomMarker_CleanMarker:function(){l()}});var f=function(a,b){a.onload=function(){b(g(a))},a.complete&&b(g(a))},g=function(a){if(void 0===a.naturalWidth){var b=new Image;b.src=a.src;var c=b.width,d=b.height}else var c=a.naturalWidth,d=a.naturalHeight;return{width:c,height:d}},h=function(a){c.attr("src",a),f(document.getElementsByName(c.attr("name"))[0],function(a){b.imgNaturalSize=a,i(b.markers)})},i=function(b){a(b).each(function(a,b){j(b)})},j=function(b){var e=a("<img class='zoom-marker' draggable='false' style='position: absolute;'/>"),f=void 0===b.size?20:b.size;return b.size=f,e.attr("src",b.src),e.height(f),e.width(f),m(e,b,c.offset()),void 0!==b.click&&e.click(function(){b.click(e)}),c.parent().append(e),d.push({marker:e,param:b}),e},k=function(){var b=c.offset();a(d).each(function(a,c){m(c.marker,c.param,b)})},l=function(){a(d).each(function(a,b){b.marker.unbind(),b.marker.remove()}),d=[],b.markers=[]},m=function(a,d,e){a.offset({left:c.width()*d.x/b.imgNaturalSize.width+e.left-d.size/2,top:c.height()*d.y/b.imgNaturalSize.height+e.top-d.size})},n={rate:.2,src:null,markers:[]}}(window.jQuery);