-
Notifications
You must be signed in to change notification settings - Fork 3
/
jMatrixBrowse-master.min.js
63 lines (63 loc) · 30.4 KB
/
jMatrixBrowse-master.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(function(b){function a(a){if("string"===typeof a.data){var m=a.handler,l=a.data.toLowerCase().split(" ");a.handler=function(a){if(!(this!==a.target&&(/textarea|select/i.test(a.target.nodeName)||"text"===a.target.type))){var k="keypress"!==a.type&&b.hotkeys.specialKeys[a.which],j=String.fromCharCode(a.which).toLowerCase(),f="",d={};a.altKey&&"alt"!==k&&(f+="alt+");a.ctrlKey&&"ctrl"!==k&&(f+="ctrl+");a.metaKey&&(!a.ctrlKey&&"meta"!==k)&&(f+="meta+");a.shiftKey&&"shift"!==k&&(f+="shift+");k?d[f+k]=
!0:(d[f+j]=!0,d[f+b.hotkeys.shiftNums[j]]=!0,"shift+"===f&&(d[b.hotkeys.shiftNums[j]]=!0));k=0;for(j=l.length;k<j;k++)if(d[l[k]])return m.apply(this,arguments)}}}}b.hotkeys={version:"0.8",specialKeys:{8:"backspace",9:"tab",13:"return",16:"shift",17:"ctrl",18:"alt",19:"pause",20:"capslock",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"del",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",
109:"-",110:".",111:"/",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"numlock",145:"scroll",191:"/",224:"meta"},shiftNums:{"`":"~",1:"!",2:"@",3:"#",4:"$",5:"%",6:"^",7:"&",8:"*",9:"(","0":")","-":"_","=":"+",";":": ","'":'"',",":"<",".":">","/":"?","\\":"|"}};b.each(["keydown","keyup","keypress"],function(){b.event.special[this]={add:a}})})(jQuery);(function(b){function a(a){var e=a||window.event,j=[].slice.call(arguments,1),m=0,f=0,d=0,a=b.event.fix(e);a.type="mousewheel";e.wheelDelta&&(m=e.wheelDelta/120);e.detail&&(m=-e.detail/3);d=m;void 0!==e.axis&&e.axis===e.HORIZONTAL_AXIS&&(d=0,f=-1*m);void 0!==e.wheelDeltaY&&(d=e.wheelDeltaY/120);void 0!==e.wheelDeltaX&&(f=-1*e.wheelDeltaX/120);j.unshift(a,m,f,d);return(b.event.dispatch||b.event.handle).apply(this,j)}var j=["DOMMouseScroll","mousewheel"];if(b.event.fixHooks)for(var m=j.length;m;)b.event.fixHooks[j[--m]]=
b.event.mouseHooks;b.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var b=j.length;b;)this.addEventListener(j[--b],a,!1);else this.onmousewheel=a},teardown:function(){if(this.removeEventListener)for(var b=j.length;b;)this.removeEventListener(j[--b],a,!1);else this.onmousewheel=null}};b.fn.extend({mousewheel:function(b){return b?this.bind("mousewheel",b):this.trigger("mousewheel")},unmousewheel:function(b){return this.unbind("mousewheel",b)}})})(jQuery);var jMatrixBrowseNs=jMatrixBrowseNs||{};
jMatrixBrowseNs.Constants={OVERFLOW_LEFT:1,OVERFLOW_RIGHT:2,OVERFLOW_TOP:3,OVERFLOW_BOTTOM:4,OVERFLOW_NONE:-1,CLASS_BASE:"jmatrixbrowse",N_BACKGROUND_CELLS:1,DEFAULT_OPTIONS:{str_initialWindowPosition:"0,0",str_initialWindowSize:"10,10",boo_snap:!1,boo_animate:!1,minVelocityForAnimation:4,animationDuration:2E3,str_api:"test"},DEFAULT_DATA_RELOAD_STRATEGY:1,RELOAD_HTML_REPLACEMENT:1,RELOAD_CELL_REPLACEMENT:2,RELOAD_CELL_POSITION:3,BACKGROUND_DATA_RELOAD_DELAY:2E3,ZOOM_LEVEL_DIFFERENCE:2,ZOOM_MAX_WINDOW_SIZE:{height:10,
width:20}};jMatrixBrowseNs=jMatrixBrowseNs||{};
(function(b,a){a.Configuration=function(j){var m=a.Constants.DEFAULT_DATA_RELOAD_STRATEGY;var l={boo_jMatrixBrowser:"true"===j.attr("data-jmatrix_browser"),str_api:j.attr("data-api"),str_initialWindowSize:j.attr("data-initial-window-size"),str_initialWindowPosition:j.attr("data-initial-window-position"),boo_snap:"true"===j.attr("data-snap"),boo_animate:"true"===j.attr("data-animate"),animationDuration:j.attr("data-deceleration-duration"),minVelocityForAnimation:j.attr("data-min-velocity-for-animation")};j.attr("data-animate");
if(!0!==l.boo_jMatrixBrowser&&!0!==l.boo_jMatrixBrowser)throw"data-jmatrix_browser invalid";if(l.str_initialWindowSize&&!/\s*\d+\s*,\s*\d+\s*/.test(l.str_initialWindowSize))throw"data-initial-window-size invalid.";if(l.str_initialWindowPosition&&!/\s*\d+\s*,\s*\d+\s*/.test(l.str_initialWindowPosition))throw"data-initial-window-size invalid.";var e=b.extend(a.Constants.DEFAULT_OPTIONS,l);this.getSettings=function(){return e};this.getWindowSize=function(){if(e&&e.str_initialWindowSize){var b=a.Utils.parsePosition(e.str_initialWindowSize);
return{height:b.row,width:b.col}}return null};this.setWindowSize=function(b){e.str_initialWindowSize=b.height+","+b.width};this.getWindowPosition=function(){return e&&e.str_initialWindowPosition?a.Utils.parsePosition(e.str_initialWindowPosition):null};this.getApiUrl=function(){return e.str_api};this.getNumberOfBackgroundCells=function(){return a.Constants.N_BACKGROUND_CELLS};this.getDataReloadStrategy=function(){return m};this.isSnapEnabled=function(){return e.boo_snap};this.getAnimationDuration=
function(){return e.animationDuration};this.getMinVelocityForAnimation=function(){return e.minVelocityForAnimation};this.animateEnabled=function(){return e.boo_animate};return this}})(jQuery,jMatrixBrowseNs);jMatrixBrowseNs=jMatrixBrowseNs||{};
(function(b,a){a.jMatrixBrowseRenderer=function(j,m,l){var e,k;function s(){i.row.remove();i.col.remove();y.remove();A.remove()}function f(B,D){var f=b(g[0==o.currentCell.row?1:0][0==o.currentCell.col?1:0]),i=A.offset(),a=f.offset();1>=o.currentCell.row&&(f=D.top+a.top-i.top,0<f&&(B.top-=f));1>=o.currentCell.col&&(a=D.left+a.left-i.left,0<a&&(B.left-=a));f=b(g[g.length-1][g[0].length-1]);a=f.offset();if(o.currentCell.row-n.getNumberOfBackgroundCells()+g.length-1>=t.getMatrixSize().height-1){var c=
i.top+A.height(),d=D.top+a.top+f.height(),c=c-d;0<c&&(B.top+=c)}o.currentCell.col-n.getNumberOfBackgroundCells()+g[0].length-1>=t.getMatrixSize().width-1&&(i=i.left+A.width(),a=D.left+a.left+f.width(),i-=a,0<i&&(B.left+=i));return B}function d(b){var a=t.getMatrixSize();return"up"===b&&1>o.currentCell.row||"down"===b&&o.currentCell.row-n.getNumberOfBackgroundCells()+g.length-1>a.height-1||"right"===b&&o.currentCell.col-n.getNumberOfBackgroundCells()+g[0].length-1>a.width-1||"left"===b&&1>o.currentCell.col?
!1:!0}function h(){for(var f=2*n.getNumberOfBackgroundCells()+1,i=2*n.getNumberOfBackgroundCells()+1,c=[],d=[],o=A.offset(),e=0;e<f&&e<g.length;++e)for(var t=0;t<i&&t<g[e].length;++t){var h=b(g[e][t]).offset();d.push((h.top-o.top)*(h.top-o.top)+(h.left-o.left)*(h.left-o.left));c.push(b(g[e][t]))}return c[a.Utils.findIndexOfMin(d).minIndex]}function q(b){var a=n.getWindowSize().height;if("up"===b){if(b=o.currentCell.row-a,1>b)return Math.max(0,a+b)}else{var b=t.getMatrixSize().height,f=o.currentCell.row+
a+g.length-n.getNumberOfBackgroundCells()-1;if(f>=b-1)return Math.max(0,a-(f-b))}return a}function u(b){var a=n.getWindowSize().width;if("left"===b){if(b=o.currentCell.col-a,0>b)return Math.max(0,a+b)}else{var b=t.getMatrixSize().width,f=o.currentCell.col+a+g[0].length-n.getNumberOfBackgroundCells()-1;if(f>=b)return Math.max(0,a-(f-b))}return a}function r(a,f){if(0!==f){var c=b.extend({},o.currentCell);if("up"===a)for(var d=0;d<f;++d){var n=g.length-1;v.moveRowToTop(n);--o.currentCell.row}else for(d=
0;d<f;++d)n=0,v.moveRowToEnd(n),++o.currentCell.row;d=0;for(n=g.length;d<n;++d)for(var e=0,t=g[d].length;e<t;++e){var h=b(g[d][e]);h.css({top:h.position().top+("up"===a?f:-f)*h.height()})}d=o.currentCell;i.row.children().each(function(a,f){var i=A.offset(),i=b(g[a][0]).offset().top-i.top;b(f).css({top:i})});w.trigger({type:"jMatrixBrowseChange",previousCell:c,currentCell:d,direction:"down"===a?"top":"bottom"})}}function c(a,f){if(0!==f){var d=b.extend({},o.currentCell);if("left"===a)for(var c=0;c<
f;++c){var n=g[0].length-1;v.moveColToLeft(n);--o.currentCell.col}else for(c=0;c<f;++c)n=0,v.moveColToRight(n),++o.currentCell.col;c=0;for(n=g.length;c<n;++c)for(var e=0,t=g[c].length;e<t;++e){var h=b(g[c][e]);h.css({left:h.position().left+("left"===a?f:-f)*h.width()})}c=o.currentCell;i.col.children().each(function(a,f){var i=A.offset(),i=b(g[0][a]).offset().left-i.left;b(f).css({left:i})});w.trigger({type:"jMatrixBrowseChange",previousCell:d,currentCell:c,direction:"left"===a?"right":"left"})}}function p(a,
f){for(var i=a.row1;i<=a.row2;++i)for(var c=f.col1;c<=f.col2;++c)b(g[i][c]).html('<div class="jMatrixBrowse-loading"/>')}var v=this,y,g,i,w,n,t,o,F=!1,A,z=[],C=!1,E=!1;o=v;w=j;n=m;t=l;j.addClass("jmb-matrix-container");this.init=function(c){t.setRenderer(v);var d=w,h=b(document.createElement("div"));h.css({width:"90%",height:"10%",top:"0px",right:"0px","background-color":"red",position:"absolute",overflow:"hidden"});h.addClass(a.Constants.CLASS_BASE+"-col-header");d.append(h);var j=b(document.createElement("div"));
j.css({width:"10%",height:"90%",bottom:"0px","background-color":"green","float":"left",position:"absolute",overflow:"hidden"});j.addClass(a.Constants.CLASS_BASE+"-row-header");d.append(j);i={row:j,col:h};d=w;h=b(document.createElement("div"));h.css({"float":"left",width:"90%",height:"90%",bottom:"0px",right:"0px",position:"absolute",overflow:"hidden"});h.addClass(a.Constants.CLASS_BASE+"-drag-container-container");d.append(h);var m=b(document.createElement("div"));m.draggable({drag:function(b,a){b.type=
"jMatrixBrowseDrag";w.trigger(b);z.push({position:a.position,timestamp:(new Date).getTime()});60<z.length&&z.splice(0,30)},start:function(b){C?(y.stop(),E=!0,C=!1):E=!1;b.type="jMatrixBrowseDragStart";w.trigger(b)},stop:function(a){var c=(new Date).getTime();if(n.animateEnabled()){var i=z.length-1;if(1E3>c-z[i].timestamp){for(var d=c=i;0<d&&z[d].timestamp>z[i].timestamp-100;--d)c=d;if(c!==i&&(d=z[i].timestamp-z[c].timestamp,e=(z[i].position.left-z[c].position.left)/d,k=(z[i].position.top-z[c].position.top)/
d,e=Math.abs(e)<n.getMinVelocityForAnimation()?0:e,k=Math.abs(k)<n.getMinVelocityForAnimation()?0:k,0<Math.abs(e)||0<Math.abs(k)))i=n.getAnimationDuration(),E&&(k*=2,e*=2),y.animate({top:"+="+k*i,left:"+="+e*i},{duration:i,easing:!E?"easeOutCubic":"easeInOutCubic",step:function(b,a){w.trigger({type:"jMatrixBrowseAnimationStep",now:b,fx:a})},complete:function(){C=false;var a=f(b(this).position(),{top:0,left:0},y.draggable().data("draggable"));y.animate(a,{duration:"fast",complete:function(){w.trigger({type:"jMatrixBrowseAnimationComplete"})}})}}),
C=!0}}a.type="jMatrixBrowseDragStop";w.trigger(a)},containment:[0,0,2E3,2E3]});m.draggable().data("draggable")._generatePosition=function(a){var c=m.draggable().data("draggable"),i="absolute"==c.cssPosition&&!(c.scrollParent[0]!=document&&$.ui.contains(c.scrollParent[0],c.offsetParent[0]))?c.offsetParent:c.scrollParent,d=/(html|body)/i.test(i[0].tagName),n=a.pageX,a={top:a.pageY-c.offset.click.top-c.offset.relative.top-c.offset.parent.top+(b.browser.safari&&526>b.browser.version&&"fixed"==c.cssPosition?
0:"fixed"==c.cssPosition?-c.scrollParent.scrollTop():d?0:i.scrollTop()),left:n-c.offset.click.left-c.offset.relative.left-c.offset.parent.left+(b.browser.safari&&526>b.browser.version&&"fixed"==c.cssPosition?0:"fixed"==c.cssPosition?-c.scrollParent.scrollLeft():d?0:i.scrollLeft())},i={top:c._convertPositionTo("absolute",a).top-c.positionAbs.top,left:c._convertPositionTo("absolute",a).left-c.positionAbs.left};return f(a,i,c)};m.addClass(a.Constants.CLASS_BASE+"-drag-container");h.append(m);y=m;A=h;
d=c.row;c=c.col;_cellPosition=b("."+("j-matrix-browse-cell-row"+d+"col"+c)).position();o.currentCell={row:d,col:c};d=y;if(void 0==t.getMatrixSize())console.error("Unable to get matrix size"),_content=null;else{var l=n.getWindowSize();if(void 0==l)console.error("Unable to get window size"),_content=null;else{c=b(document.createElement("div")).addClass("jMatrixBrowse-content");d.append(c);c.css({position:"absolute",top:0,left:0});var d=A.height()/l.height,h=A.width()/l.width,q=n.getWindowPosition();
g=[];for(var j=l.height+2*n.getNumberOfBackgroundCells(),l=l.width+2*n.getNumberOfBackgroundCells(),p=Math.max(0,q.row-n.getNumberOfBackgroundCells()),q=Math.max(0,q.col-n.getNumberOfBackgroundCells()),u=document.createDocumentFragment(),r=p;r<p+j;r++){g.push([]);for(var s=q;s<q+l;s++){var x=document.createElement("div");x.style.backgroundColor=0<r%2+s%2?"#ddd":"whitesmoke";x.style.width=h+"px";x.style.height=d+"px";x.style.position="absolute";x.style.top=(r-p-n.getNumberOfBackgroundCells())*d+"px";
x.style.left=(s-q-n.getNumberOfBackgroundCells())*h+"px";x.style.display="inline-block";x.style.textIndent="6px";x.innerHTML=r+","+s;x.className+=" jMatrixBrowse-cell "+("j-matrix-browse-cell-row"+r+"col"+s);b(x).attr("data-row",r);b(x).attr("data-col",s);u.appendChild(x);g[r-p].push(x)}}c.append(u);w.find(".jMatrixBrowse-cell").click(function(c){if(F)F=!1;else{var a=b(this);c.type="jMatrixBrowseClick";c.row=a.attr("data-row");c.col=a.attr("data-col");w.trigger(c)}});_content=c}}c=i;d=c.row;h=t.getRowHeadersFromTopRow(o.currentCell.row-
n.getNumberOfBackgroundCells());j=document.createDocumentFragment();l=0;for(p=h.length;l<p;++l)u=b(g[l][0]),q=b(document.createElement("div")),q.addClass(a.Constants.CLASS_BASE+"-row-header-cell"),u={width:"100%",height:u.height(),top:u.position().top,left:0,position:"absolute"},q.css(u),q.html(h[l]),j.appendChild(q[0]);d.append(j);c=c.col;d=t.getColHeadersFromLeftCol(o.currentCell.col-n.getNumberOfBackgroundCells());h=document.createDocumentFragment();j=0;for(l=d.length;j<l;++j)q=b(g[0][j]),p=b(document.createElement("div")),
p.addClass(a.Constants.CLASS_BASE+"-col-header-cell"),q={width:q.width(),height:"100%",left:q.position().left,top:0,position:"absolute"},p.css(q),p.html(d[j]),h.appendChild(p[0]);c.append(h);w.trigger("jMatrixBrowseRendererInitialized")};this.getCellElements=function(){return g};this.getHeaders=function(){return i};this.getContainer=function(){return A};this.moveRowToEnd=function(c){var a=g.length,a=0<g[a-1].length?b(g[a-1][0]):void 0;if(void 0===a)return console.error("Unable to move row "+c+" to the end."),
!1;for(var a=a.position().top+a.height(),i=0,f=g[c].length;i<f;++i)b(g[c][i]).css({top:a});c=g.splice(c,1);0<c.length&&g.push(c[0]);p({row1:g.length-1,row2:g.length-1},{col1:0,col2:g[0].length-1});return!0};this.moveRowToTop=function(c){var a=0<g.length&&0<g[0].length?b(g[0][0]):void 0;if(void 0===a)return console.error("Unable to move row "+c+" to top."),!1;for(var a=a.position().top,i=0,f=g[c].length;i<f;++i)b(g[c][i]).css({top:a-b(g[c][i]).height()});c=g.splice(c,1);0<c.length&&g.splice(0,0,c[0]);
p({row1:0,row2:0},{col1:0,col2:g[0].length-1});return!0};this.moveColToRight=function(c){if(0>=g.length||0>=g[0].length)return console.error("Unable to move col "+c+" to right."),!1;for(var a=b(g[0][g[0].length-1]),i=a.position().left+a.width(),a=0,f=g.length;a<f;++a)b(g[a][c]).css({left:i});a=0;for(f=g.length;a<f;++a)i=g[a].splice(c,1),g[a].push(i[0]);p({row1:0,row2:g.length-1},{col1:g[0].length-1,col2:g[0].length-1});return!0};this.moveColToLeft=function(c){if(0>=g.length||0>=g[0].length)return console.error("Unable to move col "+
c+" to left."),!1;for(var a=b(g[0][0]).position().left,i=0,f=g.length;i<f;++i)b(g[i][c]).css({left:a-b(g[i][c]).width()});i=0;for(f=g.length;i<f;++i)a=g[i].splice(c,1),g[i].splice(0,0,a[0]);p({row1:0,row2:g.length-1},{col1:0,col2:0});return!0};this.scrollRight=function(){d("right")&&c("right",1)};this.scrollLeft=function(){d("left")&&c("left",1)};this.scrollUp=function(){d("up")&&r("up",1)};this.scrollDown=function(){d("down")&&r("down",1)};this.pageUp=function(){var c=q("up");r("up",c)};this.pageDown=
function(){var c=q("down");r("down",c)};this.pageLeft=function(){var a=u("left");c("left",a)};this.pageRight=function(){var a=u("right");c("right",a)};this.snapToGrid=function(c,a){if(void 0===c&&void 0===a)o.snapToGrid(h());else{var b=A.offset(),i=c.offset(),f=y.offset();if("top"===a||void 0===a){var d=i.top-b.top;0!==d&&(f.top-=d)}if("left"===a||void 0===a)b=i.left-b.left,0!==b&&(f.left-=b);y.offset(f)}};this.zoomIn=function(){var c=n.getWindowSize();n.setWindowSize({height:Math.max(1,c.height-
a.Constants.ZOOM_LEVEL_DIFFERENCE),width:Math.max(1,c.width-a.Constants.ZOOM_LEVEL_DIFFERENCE)});s();o.init(o.currentCell)};this.zoomOut=function(){var c=n.getWindowSize(),c={height:Math.min(a.Constants.ZOOM_MAX_WINDOW_SIZE.height,t.getMatrixSize().height,c.height+a.Constants.ZOOM_LEVEL_DIFFERENCE),width:Math.min(a.Constants.ZOOM_MAX_WINDOW_SIZE.width,t.getMatrixSize().width,c.width+a.Constants.ZOOM_LEVEL_DIFFERENCE)};n.setWindowSize(c);var b=t.getMatrixSize(),i=o.currentCell,i={row:i.row+c.height>
b.height?b.height-c.height:i.row,col:i.col+c.width>b.width?b.width-c.width:i.col};s();o.init(i)};this.getIsAnimating=function(){return C};return v}})(jQuery,jMatrixBrowseNs);jMatrixBrowseNs=jMatrixBrowseNs||{};
(function(b,a){a.BackgroundDataManager=function(j,m,l){var e,k={row1:0,col1:0,row2:0,col2:0};e=b("<div/>",{className:"jMatrixBrowse-background-data-container"}).appendTo(j);(function f(d){setTimeout(function(){m.getResponseDataAsync(d,function(h){for(var q=0;q<h.length;++q)for(var u=0;u<h[q].length;++u){var r=b("<div/>",{className:"jMatrixBrowse-background-cell","data-row":q+d.row1,"data-col":u+d.col1,html:h[q][u]});l.getDataReloadStrategy===a.Constants.RELOAD_CELL_POSITION?(j.find(".jMatrixBrowse-content").append(r),
r.hide()):e.append(r)}k.row2=d.row2;k.col2=d.col2;h=m.getMatrixSize();if(d.row2<h.height-1)d.row1=Math.min(d.row1+20+1,h.height-1),d.row2=Math.min(d.row2+20+1,h.height-1);else if(d.row1=0,d.row2=20,d.col2<h.width-1)d.col1=Math.min(d.col1+20+1,h.width-1),d.col2=Math.min(d.col2+20+1,h.width-1);else{j.trigger({type:"jMatrixBrowseLoadComplete"});return}f(d)})},a.Constants.BACKGROUND_DATA_RELOAD_DELAY)})({row1:0,row2:20,col1:0,col2:20});this.getCellsForRequest=function(f,d){for(var h=[],e=!1,k=f.col1;k<=
f.col2;++k){for(var r=f.row1;r<=f.row2;++r)if(0==j.find(".jMatrixBrowse-background-cell[data-row="+r+"][data-col="+k+"]").length){h.push({row1:r,col1:k,row2:f.row2,col2:f.col2});e=!0;break}if(e)break}e&&r>f.row1&&(r<f.row2&&k>f.col1&&k<f.col2)&&h.push({row1:f.row1,col1:k+1,row2:r-1,col2:f.col2});if(0<h.length)for(var c=h.length,p=Array(c),e=h.length-1;0<=e;e--)(function(e){m.getResponseDataAsync(h[e],function(m){p[e]=m;--c;if(0==c){for(var m=Array(f.row2-f.row1+1),g=m.length-1;0<=g;g--)m[g]=Array(f.col2-
f.col1+1);for(g=p.length-1;0<=g;--g)for(var i=p[g],w=h[g],n=i.length-1;0<=n;--n)for(var t=i[n].length-1;0<=t;--t){var o=b("<div/>",{className:"jMatrixBrowse-background-cell","data-row":n+w.row1,"data-col":t+w.col1,html:i[n][t]});l.getDataReloadStrategy===a.Constants.RELOAD_CELL_POSITION&&(j.find(".jMatrixBrowse-content").append(o),o.hide());m[n+w.row1-f.row1][t+w.col1-f.col1]=o}for(n=f.col1;n<=h[0].col1;++n)for(g=f.row1;g<=f.row2&&!(n==h[0].col1&&g>=h[0].row1);++g)m[g-f.row1][n-f.col1]=j.find(".jMatrixBrowse-background-cell[data-row="+
g+"][data-col="+n+"]");d.call(this,m)}})})(e);else{k=[];for(e=f.row1;e<=f.row2;++e){k.push([]);for(r=f.col1;r<=f.col2;++r)k[e-f.row1].push(j.find(".jMatrixBrowse-background-cell[data-row="+e+"][data-col="+r+"]"))}d.call(this,k)}};this.getWindowLoaded=function(){return k};return this}})(jQuery,jMatrixBrowseNs);jMatrixBrowseNs=jMatrixBrowseNs||{};
(function(b,a){b.fn.jMatrixBrowse=function(){function j(b){switch(b){case a.Constants.OVERFLOW_TOP:++c.currentCell.row;break;case a.Constants.OVERFLOW_BOTTOM:--c.currentCell.row;break;case a.Constants.OVERFLOW_LEFT:++c.currentCell.col;break;case a.Constants.OVERFLOW_RIGHT:--c.currentCell.col}}function m(b){switch(b){case a.Constants.OVERFLOW_TOP:return c.currentCell.row-p.getNumberOfBackgroundCells()+c.getCellElements().length-1>=v.getMatrixSize().height-1?!1:!0;case a.Constants.OVERFLOW_BOTTOM:return c.currentCell.row<=
0+p.getNumberOfBackgroundCells()?!1:!0;case a.Constants.OVERFLOW_LEFT:return c.currentCell.col-p.getNumberOfBackgroundCells()+c.getCellElements()[0].length-1>=v.getMatrixSize().width-1?!1:!0;case a.Constants.OVERFLOW_RIGHT:return c.currentCell.col<=0+p.getNumberOfBackgroundCells()?!1:!0}}function l(){var b;b=k(c.getCellElements(),c.getContainer(),1,a.Constants.OVERFLOW_TOP)||!1;b=k(c.getCellElements(),c.getContainer(),c.getCellElements().length-2,a.Constants.OVERFLOW_BOTTOM)||b;b=s(c.getCellElements(),
c.getContainer(),1,a.Constants.OVERFLOW_LEFT)||b;if(b=s(c.getCellElements(),c.getContainer(),c.getCellElements()[0].length-2,a.Constants.OVERFLOW_RIGHT)||b)l(),e()}function e(){c.getHeaders().row.children().each(function(a,f){var d=c.getContainer().offset(),d=b(c.getCellElements()[a][0]).offset().top-d.top;b(f).css({top:d})});c.getHeaders().col.children().each(function(a,f){var d=c.getContainer().offset(),d=b(c.getCellElements()[0][a]).offset().left-d.left;b(f).css({left:d})})}function k(f,d,e,h){if(0<
f[e].length&&a.Utils.isOverflowing(b(f[e][0]),d,h)&&m(h)){d=b.extend({},c.currentCell);j(h);var o;switch(h){case a.Constants.OVERFLOW_TOP:o="top";if(!1===c.moveRowToEnd(0))return!1;break;case a.Constants.OVERFLOW_BOTTOM:if(o="bottom",!1===c.moveRowToTop(f.length-1))return!1}g.trigger({type:"jMatrixBrowseChange",previousCell:d,currentCell:c.currentCell,direction:o});return!0}return!1}function s(f,d,e,h){if(a.Utils.isOverflowing(b(f[0][e]),d,h)&&m(h)){d=b.extend({},c.currentCell);j(h);var o;switch(h){case a.Constants.OVERFLOW_LEFT:o=
"left";if(!1===c.moveColToRight(0))return!1;break;case a.Constants.OVERFLOW_RIGHT:if(o="right",!1===c.moveColToLeft(f[0].length-1))return!1}g.trigger({type:"jMatrixBrowseChange",previousCell:d,currentCell:c.currentCell,direction:o});return!0}return!1}function f(a){var f=v.getRowHeadersFromTopRow(a.currentCell.row-p.getNumberOfBackgroundCells());c.getHeaders().row.children().each(function(c,a){c<f.length&&b(a).html(f[c])})}function d(a){var f=v.getColHeadersFromLeftCol(a.currentCell.col-p.getNumberOfBackgroundCells());
c.getHeaders().col.children().each(function(c,a){c<f.length&&b(a).html(f[c])})}function h(a,b){var f=0,d,e=Math.abs(a.currentCell.row-a.previousCell.row),g=a.currentCell.row-p.getNumberOfBackgroundCells(),j=a.currentCell.row-p.getNumberOfBackgroundCells()+c.getCellElements().length-1;if("top"===b){j>=v.getMatrixSize().height&&(f=j-v.getMatrixSize().height+1);if(f===e)return-1;d={row1:j-(e-1),row2:j-f}}else if("bottom"===b){0>g&&(f=-g);if(f===e)return-1;d={row1:g+f,row2:g+(e-1)}}else"both"===b&&(d=
h(a,"top"),e=h(a,"bottom"),-1===d&&(d={row2:j}),-1===e&&(e={row1:g}),d={row1:e.row1,row2:d.row2});d.rowsNotInBound=f;return d}function q(a,b){var f=0,d,e=Math.abs(a.currentCell.col-a.previousCell.col),h=a.currentCell.col-p.getNumberOfBackgroundCells(),g=a.currentCell.col-p.getNumberOfBackgroundCells()+c.getCellElements()[0].length-1;if("left"===b){if(g>=v.getMatrixSize().width&&(f=g-v.getMatrixSize().width+1,f===e))return-1;d={col1:g-(e-1),col2:g}}else if("right"===b){if(0>h&&(f=-h,f===e))return-1;
d={col1:h+f,col2:h+(e-1)}}else"both"===b&&(d=q(a,"left"),e=q(a,"right"),-1===d&&(d={col2:g}),-1===e&&(e={col1:h}),d={col1:e.col1,col2:d.col2});d.colsNotInBound=f;return d}function u(f,d,e){for(var h=f.row1;h<=f.row2;++h){var g=h-c.currentCell.row+p.getNumberOfBackgroundCells();if(!(0>g||g>=c.getCellElements().length))for(var j=c.getCellElements()[g],m=d.col1;m<=d.col2;++m){var l=m-c.currentCell.col+p.getNumberOfBackgroundCells();if(!(0>l||l>=j.length)){var k=b(j[l]),q=g,r=l,s=e[h-f.row1][m-d.col1],
l=h,u=m;p.getDataReloadStrategy()===a.Constants.RELOAD_CELL_REPLACEMENT?(s=s.clone().removeClass("jMatrixBrowse-background-cell").addClass("jMatrixBrowse-cell").css({width:k.css("width"),height:k.css("height"),top:k.css("top"),left:k.css("left"),position:"absolute"}),k.replaceWith(s),c.getCellElements()[q][r]=s):p.getDataReloadStrategy()===a.Constants.RELOAD_HTML_REPLACEMENT?(q=s.html(),k.html(q),k.attr("data-row",l),k.attr("data-col",u)):p.getDataReloadStrategy()===a.Constants.RELOAD_CELL_POSITION&&
(s=s.removeClass("jMatrixBrowse-background-cell").addClass("jMatrixBrowse-cell").css({width:k.css("width"),height:k.css("height"),top:k.css("top"),left:k.css("left"),position:"absolute"}),k.hide(),s.show(),c.getCellElements()[q][r]=s)}}}}var r=this,c,p,v,y,g;this.reloadData=function(){var a;a=c.currentCell;var e=v.getMatrixSize();if(void 0==e)throw"Unable to get matrix size";var h=p.getWindowSize();if(void 0==h)throw"Unable to get window size.";a={row1:a.row-p.getNumberOfBackgroundCells(),col1:a.col-
p.getNumberOfBackgroundCells(),row2:Math.min(a.row+h.height,e.height),col2:Math.min(a.col+h.width,e.width)};void 0==a?console.error("Unable to get cell window."):v.getResponseDataAsync(a,function(a){for(var e=0;e<a.length;++e)for(var h=0;h<a[e].length;++h){var i=a[e][h];b(c.getCellElements()[e][h]).html(i)}f({currentCell:c.currentCell});d({currentCell:c.currentCell})})};this.getPosition=function(){return c.currentCell};g=b("<div/>",{position:"absolute"}).appendTo(this);p=new a.Configuration(this);
v="test"===p.getApiUrl()?new a.APIHandler("test"):new a.APIHandler("networked",p.getApiUrl());c=new a.jMatrixBrowseRenderer(g,p,v);g.bind("jMatrixBrowseRendererInitialized",function(){r.reloadData()});c.init(p.getWindowPosition());g.bind("jMatrixBrowseDrag",function(){l();e()});g.bind("jMatrixBrowseAnimationStep",function(){l();e()});g.bind("jMatrixBrowseDragStop",function(){p.isSnapEnabled()&&!c.getIsAnimating()&&c.snapToGrid();l();e()});g.bind("jMatrixBrowseAnimationComplete",function(){p.isSnapEnabled()&&
c.snapToGrid();l();e()});g.bind("jMatrixBrowseChange",function(a){a={currentCell:a.currentCell,previousCell:a.previousCell,direction:a.direction};"top"===a.direction||"bottom"===a.direction?f(a):d(a);if("top"===a.direction||"bottom"===a.direction){var c=h(a,a.direction);if(-1!==c){var b=q(a,"both");y.getCellsForRequest({row1:c.row1,row2:c.row2,col1:b.col1,col2:b.col2},function(a){u(c,b,a)})}}else{var e=q(a,a.direction);if(-1!==e){var g=h(a,"both");y.getCellsForRequest({row1:g.row1,row2:g.row2,col1:e.col1,
col2:e.col2},function(a){u(g,e,a)})}}});g.bind("jMatrixBrowseClick",function(a){console.log("click: "+a.row+", "+a.col)});b(document).bind("keydown","right",function(a){a.preventDefault();c.scrollRight()});b(document).bind("keydown","left",function(a){a.preventDefault();c.scrollLeft()});b(document).bind("keydown","up",function(a){a.preventDefault();c.scrollUp()});b(document).bind("keydown","down",function(a){a.preventDefault();c.scrollDown()});b(document).bind("keydown","j",function(){c.scrollRight()});
b(document).bind("keydown","h",function(){c.scrollLeft()});b(document).bind("keydown","k",function(){c.scrollUp()});b(document).bind("keydown","l",function(){c.scrollDown()});b(document).bind("keydown","ctrl+up",function(){c.pageUp()});b(document).bind("keydown","ctrl+down",function(){c.pageDown()});b(document).bind("keydown","ctrl+left",function(){c.pageLeft()});b(document).bind("keydown","ctrl+right",function(){c.pageRight()});b(document).bind("keydown","i",function(){console.log("zoom in");c.zoomIn()});
b(document).bind("keydown","o",function(){console.log("zoom out");c.zoomOut()});g.mousewheel(function(a){var b,f,d;a.ctrlKey?(b=c.pageLeft,f=c.pageRight,scrollDown=a.shiftKey?c.pageRight:c.pageDown,d=a.shiftKey?c.pageLeft:c.pageUp):(b=c.scrollLeft,f=c.scrollRight,scrollDown=a.shiftKey?c.scrollRight:c.scrollDown,d=a.shiftKey?c.scrollLeft:c.scrollUp);0<a.originalEvent.wheelDeltaX?b():0>a.originalEvent.wheelDeltaX&&f();0<a.originalEvent.wheelDeltaY?d():0>a.originalEvent.wheelDeltaY&&scrollDown()});y=
new a.BackgroundDataManager(g,v,p);return this}})(jQuery,jMatrixBrowseNs);function MatrixGenerator(b){function a(a){for(var b="",d=0;d<a;++d)b+=Math.random()>j?m[Math.floor(Math.random()*m.length)]:Math.floor(10*Math.random());return b}void 0==b&&(b="random");var j=0.5,m="ABCDEF".split(""),l,e,k;this.init=function(j,f){l=[];e=[];k=[];for(var d=0;d<j;++d){"random"==b?e.push(a(4*Math.random())):e.push("row "+d);l.push([]);for(var h=0;h<f;++h)"random"==b?(0==d&&k.push(a(4*Math.random())),l[d].push(a(4*Math.random()))):(0==d&&k.push("col "+h),l[d].push(d+", "+h))}};this.test_getMatrix=
function(){return l};this.test_getMatrixRowLabels=function(){return e};this.test_getMatrixColumnLabels=function(){return k}};function MockApi(b,a){var j=new MatrixGenerator("sequential");j.init(void 0==b?1E3:b,void 0==a?1E3:a);this.getResponse=function(a){for(var b=j.test_getMatrix(),e=j.test_getMatrixRowLabels(),k=j.test_getMatrixColumnLabels(),s=a.row1,f=a.row2,d=a.col1,a=a.col2,h={matrix:{height:b.length,width:b[0].length},row:{labels:[]},column:{labels:[]},data:[]},q=s;q<=f;++q){h.row.labels.push(e[q]);h.data.push([]);for(var u=d;u<=a;++u)q===s&&h.column.labels.push(k[u]),h.data[q-s].push(b[q][u])}return h};this.getResponseDataAsync=
function(a,b){var e=this.getResponse(a);b.call(this,e.data)};this.getResponseAsync=function(a,b){var e=this.getResponse(a);b.call(this,e)};this.getMatrixSize=function(){var a=this.getResponse({row1:0,col1:0,row2:0,col2:0});if(a)return a.matrix}};jMatrixBrowseNs=jMatrixBrowseNs||{};
jMatrixBrowseNs.Utils={parsePosition:function(b){b=b.split(",");if(2==b.length)return{row:parseInt(b[0]),col:parseInt(b[1])}},isOverflowing:function(b,a,j){var m=a.offset(),l=b.offset(),e=l.top-m.top,m=l.left-m.left,l=b.width(),b=b.height();switch(j){case jMatrixBrowseNs.Constants.OVERFLOW_LEFT:return 0>m+l;case jMatrixBrowseNs.Constants.OVERFLOW_RIGHT:return m>a.width();case jMatrixBrowseNs.Constants.OVERFLOW_TOP:return 0>e+b;case jMatrixBrowseNs.Constants.OVERFLOW_BOTTOM:return e>a.height()}return!1},
findIndexOfMin:function(b){if(b&&b.length){for(var a=b[0],j=0,m=1,l=b.length;m<l;++m)b[m]<a&&(a=b[m],j=m);return{min:a,minIndex:j}}return null}};jMatrixBrowseNs=jMatrixBrowseNs||{};
(function(b,a){a.NetworkedAPI=function(a){var m=this;b.ajax({url:a,dataType:"json",data:{row1:0,col1:0,row2:0,col2:0},async:!1,success:function(a){m.matrixSize=a.matrix}});this.getResponseAsync=function(l,e){b.getJSON(a,l,function(a){e.call(this,a)})};this.getResponseDataAsync=function(l,e){b.getJSON(a,l,function(a){e.call(this,a.data)})};this.getMatrixSize=function(){return this.matrixSize}};a.APIHandler=function(b,m){function l(a,b){for(var h=a.row1;h<=a.row2;++h)e.cache.rowHeaders[h]=b.row.labels[h-
a.row1];for(h=a.col1;h<=a.col2;++h)e.cache.colHeaders[h]=b.column.labels[h-a.col1]}var e=this;e.cache={rowHeaders:[],colHeaders:[]};k="test"===b?new MockApi:new a.NetworkedAPI(m);this.getMatrixSize=function(){return k.getMatrixSize()};this.getRowHeadersFromTopRow=function(a){for(var b=s.getCellElements().length,h=[],j=0;j<b;++j)h.push(e.cache.rowHeaders[a+j]);return h};this.getColHeadersFromLeftCol=function(a){for(var b=s.getCellElements()[0].length,h=[],j=0;j<b;++j)h.push(e.cache.colHeaders[a+j]);
return h};this.getRowDataForCell=function(b){var d=a.Constants.N_BACKGROUND_CELLS,e=[];if((b=k.getResponse({row1:b.row,col1:b.col-d,row2:b.row,col2:b.col-d+s.getCellElements()[0].length}))&&b.data&&1==b.data.length)for(d=0;d<b.data[0].length;++d)e.push(b.data[0][d]);return e};this.getColDataForCell=function(b){var d=a.Constants.N_BACKGROUND_CELLS,e=[];if((b=k.getResponse({row1:b.row-d,col1:b.col,row2:b.row-d+s.getCellElements().length,col2:b.col}))&&b.data)for(d=0;d<b.data.length;++d)e.push(b.data[d][0]);
return e};this.setRenderer=function(a){s=a};this.getResponse=function(a){var b=k.getResponse(a);l(a,b);return b};this.getResponseData=function(a){var b=k.getResponse(a);l(a,b);return b.data};e.getResponseAsync=function(a,b){k.getResponseAsync(a,function(e){l(a,e);b.call(this,e)})};e.getResponseDataAsync=function(a,b){e.getResponseAsync(a,function(a){b.call(e,a.data)})};var k,s;return e}})(jQuery,jMatrixBrowseNs);