Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
1 lines (1 sloc) 5.13 KB
var bigpicture=function(){"use strict";function e(e){e.style.fontSize=$(e).data("size")/s.zoom+"px",e.style.left=($(e).data("x")-s.x)/s.zoom-u.x+"px",e.style.top=($(e).data("y")-s.y)/s.zoom-u.y+"px"}function t(t,o,n,i){var a=document.createElement("div");return a.className="text",a.contentEditable=!0,a.innerHTML=i,$(a).data("x",t).data("y",o).data("size",n),e(a),u.appendChild(a),a}function o(t,o,n,i,a){o="undefined"==typeof o?s.x+window.innerWidth/2*s.zoom:o,n="undefined"==typeof n?s.y+window.innerHeight/2*s.zoom:n,i="undefined"==typeof i?window.innerWidth/2:i,a="undefined"==typeof a?window.innerHeight/2:a,u.style.transitionDuration="0.2s",u.x=0,u.y=0,u.updateContainerPosition(),s.x=o-i*t,s.y=n-a*t,s.zoom=t,$(".text").each(function(){e(this)}),v=!1}function n(e){o($(e).data("size")/20,$(e).data("x"),$(e).data("y"))}function i(e){function t(){var e=1/0,t=-1/0,o=1/0,n=-1/0,i=document.getElementsByClassName("text");return[].forEach.call(i,function(i){var a=i.getBoundingClientRect(),l={left:$(i).data("x"),top:$(i).data("y"),right:a.width>2&&a.width<1e4?s.x+a.right*s.zoom:$(i).data("x")+300*$(i).data("size")/20,bottom:a.height>2&&a.height<1e4?s.y+a.bottom*s.zoom:$(i).data("y")+100*$(i).data("size")/20};l.left<e&&(e=l.left),l.right>t&&(t=l.right),l.top<o&&(o=l.top),l.bottom>n&&(n=l.bottom)}),{minX:e,maxX:t,minY:o,maxY:n}}e.preventDefault(),document.activeElement.blur();var i=document.getElementsByClassName("text");if(0!==i.length){if(1===i.length)return void n(i[0]);if(v)o(p.zoom,p.x,p.y,0,0),v=!1;else{p={x:s.x,y:s.y,zoom:s.zoom};var a=t(),l=1.1*Math.max((a.maxX-a.minX)/window.innerWidth,(a.maxY-a.minY)/window.innerHeight);o(l,(a.minX+a.maxX)/2,(a.minY+a.maxY)/2),v=!0}}}function a(e){w={index:-1,elements:[],text:e},$(".text").each(function(){-1!=$(this).text().toLowerCase().indexOf(e.toLowerCase())&&w.elements.push(this)}),w.elements.length>0&&(w.index=0)}function l(e){if(e&&""!==e.replace(/^\s+|\s+$/g,"")){if(-1==w.index||w.text!=e||C){if(a(e),-1==w.index)return;C=!1}var t=w.elements[w.index];n(t),w.index+=1,w.index==w.elements.length&&(w.index=0)}}function d(e,t){for(;e&&e.tagName;){if(e.classList.contains(t))return!0;e=e.parentNode}return!1}function r(e){for(var t=window.location.search.substring(1).split("&"),o=0;o<t.length;o++){var n=t[o].split("=");if(n[0]==e)return n[1]}return!1}var m=document.getElementById("bigpicture-container"),u=document.getElementById("bigpicture");if(u){u.setAttribute("spellcheck",!1);var c={x:r("x"),y:r("y"),zoom:r("zoom")},s={};s.x=c.x?parseFloat(c.x):$(u).data("x"),s.y=c.y?parseFloat(c.y):$(u).data("y"),s.zoom=c.zoom?parseFloat(c.zoom):$(u).data("zoom"),u.x=0,u.y=0,u.updateContainerPosition=function(){u.style.left=u.x+"px",u.style.top=u.y+"px"},$(".text").each(function(){e(this)}),$(u).on("blur",".text",function(){""===$(this).text().replace(/^\s+|\s+$/g,"")&&$(this).remove()}),$(u).on("input",".text",function(){C=!0}),m.onclick=function(e){d(e.target,"text")||t(s.x+e.clientX*s.zoom,s.y+e.clientY*s.zoom,20*s.zoom,"").focus()};var y,x=null,f=!1;m.onmousedown=function(e){$(e.target).hasClass("text")&&(e.ctrlKey||e.metaKey)?(x=e.target,x.className="text noselect notransition"):(x=null,f=!0),v=!1,y={x:e.pageX,y:e.pageY}},window.onmouseup=function(){f=!1,x&&(x.className="text"),x=null},m.ondragstart=function(e){e.preventDefault()},m.onmousemove=function(t){f&&!t.shiftKey&&(u.style.transitionDuration="0s",u.x+=t.pageX-y.x,u.y+=t.pageY-y.y,u.updateContainerPosition(),s.x-=(t.pageX-y.x)*s.zoom,s.y-=(t.pageY-y.y)*s.zoom,y={x:t.pageX,y:t.pageY}),x&&($(x).data("x",$(x).data("x")+(t.pageX-y.x)*s.zoom),$(x).data("y",$(x).data("y")+(t.pageY-y.y)*s.zoom),e(x),y={x:t.pageX,y:t.pageY})},m.ondblclick=function(e){e.preventDefault(),o(e.ctrlKey||e.metaKey?1.7*s.zoom*1.7:s.zoom/1.7/1.7,s.x+e.clientX*s.zoom,s.y+e.clientY*s.zoom,e.clientX,e.clientY)};var p,h,g,z,v=!1,w={index:-1,elements:[],text:""},C=!0,k=0,X=null;return z=-1!=navigator.appVersion.indexOf("Mac")?function(e){e.preventDefault(),k+=Math.max(-1,Math.min(1,e.wheelDelta||-e.detail)),g=e,X||(X=setTimeout(function(){o(k>0?s.zoom/1.7:1.7*s.zoom,s.x+g.clientX*s.zoom,s.y+g.clientY*s.zoom,g.clientX,g.clientY),k=0,X=null},70))}:function(e){e.preventDefault();var t=Math.max(-1,Math.min(1,e.wheelDelta||-e.detail));o(t>0?s.zoom/1.7:1.7*s.zoom,s.x+e.clientX*s.zoom,s.y+e.clientY*s.zoom,e.clientX,e.clientY)},"onmousewheel"in document?m.onmousewheel=z:m.addEventListener("DOMMouseScroll",z,!1),window.onkeydown=function(e){return(e.ctrlKey&&!e.altKey||e.metaKey)&&(61==e.keyCode||187==e.keyCode||171==e.keyCode||107==e.keyCode||"+"==e.key||"="==e.key)||34==e.keyCode?(e.preventDefault(),void o(s.zoom/1.7)):(e.ctrlKey&&!e.altKey||e.metaKey)&&(54==e.keyCode||189==e.keyCode||173==e.keyCode||167==e.keyCode||109==e.keyCode||169==e.keyCode||219==e.keyCode||"-"==e.key)||33==e.keyCode?(e.preventDefault(),void o(1.7*s.zoom)):(e.ctrlKey&&!e.altKey||e.metaKey)&&70==e.keyCode?(e.preventDefault(),void setTimeout(function(){h=window.prompt("What are you looking for?",""),l(h)},10)):114==e.keyCode?(e.preventDefault(),void(-1==w.index?setTimeout(function(){h=window.prompt("What are you looking for?",""),l(h)},10):l(h))):113==e.keyCode?(e.preventDefault(),void i(e)):void 0},{newText:t,current:s,updateTextPosition:e}}}();