This repository has been archived by the owner on Feb 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.gridview.min.js
15 lines (15 loc) · 7.44 KB
/
jquery.gridview.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
(function(c){var e={getOptions:function(){return jQuery.extend({},"object"==typeof c(this).data("gridviewoptions")?c(this).data("gridviewoptions"):c.fn.gridview.defaults)},init:function(a){var b=c.extend({},c.fn.gridview.defaults,a);e._checkOpts.apply(this,[b]);this.each(function(){var a=c(this),g=a.children("div"),f={target:a,zoom:b.initialZoom};f.nrChildren=g.size();a.data("gridview",f);a.data("gridviewoptions",b);g.each(function(a){c(this).css({display:"block",overflow:"hidden",position:"absolute"});
"boolean"===typeof b.scrollToZoom&&b.scrollToZoom&&c(this).mousewheel(function(b,d){b.preventDefault();var g=c(this).parent().data("gridview").zoom-(0<d?1:-1);e._zoomTo.apply(this,[a,g])});c(this).mousedown(function(b){b.preventDefault();b.stopPropagation();2===b.which&&(b=c(this).parent().data("gridview"),e._zoomTo.apply(this,[a,b.zoom]));return!1});"function"===typeof c.fn.draggable&&("boolean"!==typeof b.draggable||b.draggable)&&c(this).draggable({addClasses:!1,drag:function(a,b){var d=c(this).data("gridview").offset,
g=b.position,f=g.top-d.top,i=g.left-d.left;c(this).parent().children().each(function(){var a=parseInt(c(this).css("top"))+f,b=parseInt(c(this).css("left"))+i;c(this).css({top:a,left:b}).data("gridview",{offset:c(this).position()})})}})});a.css({display:"block",height:b.height+"px",overflow:"hidden",position:"relative",width:b.width+"px"});a=b.initialChild;a>=g.size()&&(a=g.size()-1);e._zoomTo.apply(g.get(a),[a,b.initialZoom,!1])});return this},refresh:function(){this.each(function(){c(this).children("div").stop(!0,
!1)});e.init.apply(this,[c(this).data("gridviewoptions")]);return this},zoom:function(a){if(null==a||"object"!==typeof a)return(a=c(this).data("gridview"))?a.zoom:0;var b=a.animate,d=a.level,g=a.offset,f="object"==typeof c(this).data("gridviewoptions")?c(this).data("gridviewoptions"):c.extend({},c.fn.gridview.defaults),m=a.onAnimationComplete,j=a.zoomedChild;"undefined"===typeof a.animate&&(b=!0);"undefined"===typeof a.level&&(d=1);"undefined"===typeof a.offset&&(g={x:0,y:0});"function"!==typeof a.onAnimationComplete&&
(m=function(){});"undefined"===typeof a.zoomedChild&&(j=0);return d<f.minZoom||1>d?(e._trigger.apply(this,[101,"Zooming in not allowed"]),this):f.maxZoom<d&&0<f.maxZoom?(e._trigger.apply(this,[102,"Zooming out not allowed"]),this):this.each(function(){var a=c(this),l=a.children("div"),k=a.data("gridview"),n=k.zoom;"undefined"===typeof k&&(a.gridview(),k=a.data("gridview"));k.zoom="number"===typeof d&&0<d?Math.round(d):1;a.data("gridview",k);l.each(function(a){c(this);var d=e._calcNewHeight.apply(this,
[k.zoom]),h=e._calcNewWidth.apply(this,[k.zoom]),h=e._calcXY.apply(this,[a,d,h,n,k.zoom,j]),d=h.x,h=h.y,d=c.extend({height:e._calcNewHeight.apply(this,[k.zoom,true])+"px",left:d+g.x+"px",top:h+g.y+"px",width:e._calcNewWidth.apply(this,[k.zoom,true])+"px"},f.onZoom.apply(this,[n,k.zoom]));if(b)c(this).stop(false,true).animate(d,f.animationSpeed,function(){c(this).data("gridview",{offset:c(this).position()});a==0&&m.call()});else{c(this).css(d).data("gridview",{offset:c(this).position()});a==0&&m.call()}})})},
zoomTo:function(a,b){"undefined"===typeof a&&(a=0);"undefined"===typeof b&&(b=1);if(0>a||c(this).children("div").size()-1<a)return e._trigger.apply(this,[103,"Zoom to not possible"]),this;e._zoomTo.apply(c(this).children("div").get(a),[a,b]);return this},_calcNewHeight:function(a,b){null===b&&(b=!1);!0!==b&&(b=!1);var d=c(this),g=d.parent().data("gridview"),f=d.parent().data("gridviewoptions"),d=Math.floor(f.height/a)-2*f.margin-(b?parseInt(d.css("padding-top"))+parseInt(d.css("padding-bottom")):
0),e={};"function"===typeof f.onZoom&&(e=f.onZoom.apply(this,[g.zoom,a]),"undefined"!==typeof e.height&&(d=e.height));return d},_calcNewWidth:function(a,b){null===b&&(b=!1);!0!==b&&(b=!1);var d=c(this),g=d.parent().data("gridview"),f=d.parent().data("gridviewoptions"),d=Math.floor(f.width/a)-2*f.margin-(b?parseInt(d.css("padding-left"))+parseInt(d.css("padding-right")):0),e={};"function"===typeof f.onZoom&&(e=f.onZoom.apply(this,[g.zoom,a]),"undefined"!==typeof e.width&&(d=e.width));return d},_calcXY:function(a,
b,d,g,f,m){var j={},h=0,l=0,k=!1,n=f,i=c(this).parent().data("gridviewoptions");if("function"===typeof i.onPosition){if(j=i.onPosition.apply(this,[a,m,i.margin,g,f]),"number"==typeof j.x&&"number"==typeof j.y?(h=j.x,l=j.y):e._trigger.apply(this,[104,"Return value onPosition not correct"]),"boolean"===typeof j.noOffset&&j.noOffset&&(k=!0),"number"===typeof j.newZoom&&0<j.newZoom&&j.newZoom>=i.minZoom&&(j.newZoom<=i.maxZoom||0==i.maxZoom))n=j.newZoom}else"simple-vertical"===i.onPosition?(h=i.margin+
a%f*(d+2*i.margin),l=i.margin+(a/f-a%f/f)*(b+2*i.margin)):"simple-horizontal"===i.onPosition?(h=i.margin+(a/f-a%f/f)*(d+2*i.margin),l=i.margin+a%f*(b+2*i.margin)):"intuitive"===i.onPosition&&(g=Math.floor(Math.sqrt(a)),f=g*g,h=i.margin+Math.min(g,2*g+f-a)*(d+2*i.margin),l=i.margin+Math.min(g,a-f)*(b+2*i.margin));return!k?{x:h,y:l,newZoom:n}:{x:h,y:l,noOffset:!0,newZoom:n}},_checkOpts:function(a){c.each(a,function(b,d){switch(b){case "initialChild":case "maxZoom":0>d&&(a[b]=0);break;case "initialZoom":case "minZoom":1>
d&&(a[b]=1)}})},_trigger:function(a,b){var d=c(this).data("gridviewoptions");"function"===typeof d.onError&&d.onError.apply(this,[a,b])},_zoomTo:function(a,b,d){"undefined"===typeof a&&(a=0);"undefined"===typeof b&&(b=1);"boolean"!==typeof d&&(d=!0);var g=c(this).parent(),f=g.data("gridview"),m=e._calcNewHeight.apply(this,[b]),j=e._calcNewWidth.apply(this,[b]),h=c(this).parent().data("gridviewoptions"),l=g.children("div").index(this),a=e._calcXY.apply(this,[a,m,j,f.zoom,b,l]);if("number"===typeof a.newZoom&&
0<a.newZoom&&a.newZoom>=h.minZoom&&(a.newZoom<=h.maxZoom||0==h.maxZoom))b=a.newZoom;"boolean"===typeof a.noOffset&&a.noOffset?a={x:0,y:0}:(a.x=-a.x,a.y=-a.y,a.x+=(h.width-j)/2,a.y+=(h.height-m)/2);g.gridview("zoom",{animate:d,level:b,offset:a,zoomedChild:l});return this}};c.fn.gridview=function(a){var b=c(this).data("gridviewoptions");if(e[a])return e[a].apply(this,Array.prototype.slice.call(arguments,1));if("object"===typeof a||!a)return e.init.apply(this,arguments);if("string"===typeof a&&"undefined"!==
typeof b[a]&&1<arguments.length)return b[a]=arguments[1],this;if("string"===typeof a&&"undefined"!==typeof b[a])return b[a];e._trigger.apply(this,[100,"Method "+a+" does not exist on jQuery.gridview"])};c.fn.gridview.defaults={animationSpeed:200,draggable:!0,height:300,initialChild:0,initialZoom:1,onError:function(){},onPosition:"intuitive",onZoom:function(){return{}},margin:5,maxZoom:0,minZoom:1,scrollToZoom:!0,width:300}})(jQuery);
(function(c){function e(a){var b=a||window.event,f=[].slice.call(arguments,1),e=0,j=0,h=0;return a=c.event.fix(b),a.type="mousewheel",b.wheelDelta&&(e=b.wheelDelta/120),b.detail&&(e=-b.detail/3),h=e,void 0!==b.axis&&b.axis===b.HORIZONTAL_AXIS&&(h=0,j=-1*e),void 0!==b.wheelDeltaY&&(h=b.wheelDeltaY/120),void 0!==b.wheelDeltaX&&(j=-1*b.wheelDeltaX/120),f.unshift(a,e,j,h),(c.event.dispatch||c.event.handle).apply(this,f)}var a=["DOMMouseScroll","mousewheel"];if(c.event.fixHooks)for(var b=a.length;b;)c.event.fixHooks[a[--b]]=
c.event.mouseHooks;c.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var b=a.length;b;)this.addEventListener(a[--b],e,!1);else this.onmousewheel=e},teardown:function(){if(this.removeEventListener)for(var b=a.length;b;)this.removeEventListener(a[--b],e,!1);else this.onmousewheel=null}};c.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery);