Fixed smart scrolling as intended for svg divs. refs #2919
[arvados.git] / apps / workbench / app / assets / javascripts / sizing.js
1 function graph_zoom(divId, svgId, scale) {
2     var pg = document.getElementById(divId);
3     vcenter = (pg.scrollTop + (pg.scrollHeight - pg.scrollTopMax)/2.0) / pg.scrollHeight;
4     hcenter = (pg.scrollLeft + (pg.scrollWidth - pg.scrollLeftMax)/2.0) / pg.scrollWidth;
5     var g = document.getElementById(svgId);
6     g.setAttribute("height", parseFloat(g.getAttribute("height")) * scale);
7     g.setAttribute("width", parseFloat(g.getAttribute("width")) * scale);
8     pg.scrollTop = (vcenter * pg.scrollHeight) - (pg.scrollHeight - pg.scrollTopMax)/2.0;
9     pg.scrollLeft = (hcenter * pg.scrollWidth) - (pg.scrollWidth - pg.scrollLeftMax)/2.0;
10     smart_scroll_fixup();
11 }
12
13 function smart_scroll_fixup(s) {
14
15     if (s != null && s.type == 'shown.bs.tab') {
16         s = [s.target];
17     }
18     else {
19         s = $(".smart-scroll");
20     }
21
22     s.each(function(i, a) {
23         var h = window.innerHeight - $(a).offset().top;
24         height = String(h) + "px";
25         $(a).css('max-height', height);
26     });
27 }
28
29 $(window).on('load ready resize scroll ajax:complete', smart_scroll_fixup);