summaryrefslogtreecommitdiff
path: root/src/scaladoc/scala/tools/nsc/doc/html/resource/lib/diagrams.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/scaladoc/scala/tools/nsc/doc/html/resource/lib/diagrams.js')
-rw-r--r--src/scaladoc/scala/tools/nsc/doc/html/resource/lib/diagrams.js216
1 files changed, 66 insertions, 150 deletions
diff --git a/src/scaladoc/scala/tools/nsc/doc/html/resource/lib/diagrams.js b/src/scaladoc/scala/tools/nsc/doc/html/resource/lib/diagrams.js
index 680ead7a59..b13732760a 100644
--- a/src/scaladoc/scala/tools/nsc/doc/html/resource/lib/diagrams.js
+++ b/src/scaladoc/scala/tools/nsc/doc/html/resource/lib/diagrams.js
@@ -1,6 +1,6 @@
/**
* JavaScript functions enhancing the SVG diagrams.
- *
+ *
* @author Damien Obrist
*/
@@ -15,10 +15,6 @@ $(document).ready(function()
if(Modernizr && !Modernizr.inlinesvg)
return;
- // only execute this in the main window
- if(diagrams.isPopup)
- return;
-
if($("#content-diagram").length)
$("#inheritance-diagram").css("padding-bottom", "20px");
@@ -31,7 +27,7 @@ $(document).ready(function()
// store unscaled clone of SVG element
$(this).data("svg", $(this).get(0).childNodes[0].cloneNode(true));
});
-
+
// make diagram visible, hide container
$(".diagram").css("display", "none");
$(".diagram svg").css({
@@ -62,41 +58,16 @@ $(document).ready(function()
});
diagrams.initHighlighting();
-});
-/**
- * Initializes the diagrams in the popup.
- */
-diagrams.initPopup = function(id)
-{
- // copy diagram from main window
- if(!jQuery.browser.msie)
- $("body").append(opener.$("#" + id).data("svg"));
+ $("button#diagram-fs").click(function() {
+ $(".diagram-container").toggleClass("full-screen");
+ $(".diagram-container > div.diagram").css({
+ height: $("svg").height() + "pt"
+ });
- // positioning
- $("svg").css("position", "absolute");
- $(window).resize(function()
- {
- var svg_w = $("svg").css("width").replace("px", "");
- var svg_h = $("svg").css("height").replace("px", "");
- var x = $(window).width() / 2 - svg_w / 2;
- if(x < 0) x = 0;
- var y = $(window).height() / 2 - svg_h / 2;
- if(y < 0) y = 0;
- $("svg").css("left", x + "px");
- $("svg").css("top", y + "px");
- });
- $(window).resize();
-
- diagrams.initHighlighting();
- $("svg a").click(function(e) {
- opener.diagrams.redirectFromPopup(this.href.baseVal);
- window.close();
- });
- $(document).keyup(function(e) {
- if (e.keyCode == 27) window.close();
- });
-}
+ $panzoom.panzoom("reset", { animate: false, contain: false });
+ });
+});
/**
* Initializes highlighting for nodes and edges.
@@ -159,7 +130,7 @@ diagrams.initHighlighting = function()
toggleClass($(this));
});
});
-
+
// implicit outgoing nodes
hover($("svg .node.implicit-outgoing"), function(evt){
@@ -182,39 +153,29 @@ diagrams.initHighlighting = function()
/**
* Resizes the diagrams according to the available width.
*/
-diagrams.resize = function()
-{
- // available width
- var availableWidth = $("body").width() - 20;
-
- $(".diagram-container").each(function() {
- // unregister click event on whole div
- $(".diagram", this).unbind("click");
- var diagramWidth = $(".diagram", this).data("width");
- var diagramHeight = $(".diagram", this).data("height");
-
- if(diagramWidth > availableWidth)
- {
- // resize diagram
- var height = diagramHeight / diagramWidth * availableWidth;
- $(".diagram svg", this).width(availableWidth);
- $(".diagram svg", this).height(height);
-
- // register click event on whole div
- $(".diagram", this).click(function() {
- diagrams.popup($(this));
- });
- $(".diagram", this).addClass("magnifying");
- }
- else
- {
- // restore full size of diagram
- $(".diagram svg", this).width(diagramWidth);
- $(".diagram svg", this).height(diagramHeight);
- // don't show custom cursor any more
- $(".diagram", this).removeClass("magnifying");
- }
- });
+diagrams.resize = function() {
+ // available width
+ var availableWidth = $(".diagram-container").width();
+
+ $(".diagram-container").each(function() {
+ // unregister click event on whole div
+ $(".diagram", this).unbind("click");
+ var diagramWidth = $(".diagram", this).data("width");
+ var diagramHeight = $(".diagram", this).data("height");
+
+ if (diagramWidth > availableWidth) {
+ // resize diagram
+ var height = diagramHeight / diagramWidth * availableWidth;
+ $(".diagram svg", this).width(availableWidth);
+ $(".diagram svg", this).height(height);
+ } else {
+ // restore full size of diagram
+ $(".diagram svg", this).width(diagramWidth);
+ $(".diagram svg", this).height(diagramHeight);
+ // don't show custom cursor any more
+ $(".diagram", this).removeClass("magnifying");
+ }
+ });
};
/**
@@ -222,82 +183,38 @@ diagrams.resize = function()
*/
diagrams.toggle = function(container, dontAnimate)
{
- // change class of link
- $(".diagram-link", container).toggleClass("open");
- // get element to show / hide
- var div = $(".diagram", container);
- if (div.is(':visible'))
- {
- $(".diagram-help", container).hide();
- div.unbind("click");
- div.removeClass("magnifying");
- div.slideUp(100);
- }
- else
- {
- diagrams.resize();
- if(dontAnimate)
- div.show();
- else
- div.slideDown(100);
- $(".diagram-help", container).show();
- }
-};
-
-/**
- * Opens a popup containing a copy of a diagram.
- */
-diagrams.windows = {};
-diagrams.popup = function(diagram)
-{
- var id = diagram.attr("id");
- if(!diagrams.windows[id] || diagrams.windows[id].closed) {
- var title = $(".symbol .name", $("#signature")).text();
- // cloning from parent window to popup somehow doesn't work in IE
- // therefore include the SVG as a string into the HTML
- var svgIE = jQuery.browser.msie ? $("<div />").append(diagram.data("svg")).html() : "";
- var html = '' +
- '<?xml version="1.0" encoding="UTF-8"?>\n' +
- '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\n' +
- '<html>\n' +
- ' <head>\n' +
- ' <title>' + title + '</title>\n' +
- ' <link href="' + $("#diagrams-css").attr("href") + '" media="screen" type="text/css" rel="stylesheet" />\n' +
- ' <script type="text/javascript" src="' + $("#jquery-js").attr("src") + '"></script>\n' +
- ' <script type="text/javascript" src="' + $("#diagrams-js").attr("src") + '"></script>\n' +
- ' <script type="text/javascript">\n' +
- ' diagrams.isPopup = true;\n' +
- ' </script>\n' +
- ' </head>\n' +
- ' <body onload="diagrams.initPopup(\'' + id + '\');">\n' +
- ' <a href="#" onclick="window.close();" id="close-link">Close this window</a>\n' +
- ' ' + svgIE + '\n' +
- ' </body>\n' +
- '</html>';
-
- var padding = 30;
- var screenHeight = screen.availHeight;
- var screenWidth = screen.availWidth;
- var w = Math.min(screenWidth, diagram.data("width") + 2 * padding);
- var h = Math.min(screenHeight, diagram.data("height") + 2 * padding);
- var left = (screenWidth - w) / 2;
- var top = (screenHeight - h) / 2;
- var parameters = "height=" + h + ", width=" + w + ", left=" + left + ", top=" + top + ", scrollbars=yes, location=no, resizable=yes";
- var win = window.open("about:blank", "_blank", parameters);
- win.document.open();
- win.document.write(html);
- win.document.close();
- diagrams.windows[id] = win;
- }
- win.focus();
-};
-
-/**
- * This method is called from within the popup when a node is clicked.
- */
-diagrams.redirectFromPopup = function(url)
-{
- window.location = url;
+ // change class of link
+ $(".diagram-link", container).toggleClass("open");
+ // get element to show / hide
+ var div = $(".diagram", container);
+ if (div.is(':visible')) {
+ $(".diagram-help", container).hide();
+ div.unbind("click");
+ div.slideUp(100);
+
+ $("#diagram-controls", container).hide();
+ $("#inheritance-diagram-container").unbind('mousewheel.focal');
+ } else {
+ diagrams.resize();
+ if(dontAnimate)
+ div.show();
+ else
+ div.slideDown(100);
+ $(".diagram-help", container).show();
+
+ $("#diagram-controls", container).show();
+
+ $(".diagram-container").on('mousewheel.focal', function(e) {
+ e.preventDefault();
+ var delta = e.delta || e.originalEvent.wheelDelta;
+ var zoomOut = delta ? delta < 0 : e.originalEvent.deltaY > 0;
+ $panzoom.panzoom('zoom', zoomOut, {
+ increment: 0.1,
+ animate: true,
+ focal: e
+ });
+ });
+ }
};
/**
@@ -321,4 +238,3 @@ diagrams.removeClass = function(svgElem, oldClass) {
classes = $.grep(classes.split(/\s+/), function(n, i) { return n != oldClass; }).join(' ');
svgElem.attr("class", classes);
};
-