xyc
2025-02-21 664db98c9e8595ce4dd636a27f480e3a08b81ff5
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
var svgEditorExtension_overview_window = (function () {
  'use strict';
 
  /* globals jQuery */
 
  /**
   * ext-overview_window.js
   *
   * @license MIT
   *
   * @copyright 2013 James Sacksteder
   *
   */
  var extOverview_window = {
    name: 'overview_window',
    init: function init(_ref) {
      var isChrome = _ref.isChrome,
          isIE = _ref.isIE;
      var $ = jQuery;
      var overviewWindowGlobals = {}; // Disabled in Chrome 48-, see https://github.com/SVG-Edit/svgedit/issues/26 and
      // https://code.google.com/p/chromium/issues/detail?id=565120.
 
      if (isChrome()) {
        var verIndex = navigator.userAgent.indexOf('Chrome/') + 7;
        var chromeVersion = parseInt(navigator.userAgent.substring(verIndex), 10);
 
        if (chromeVersion < 49) {
          return;
        }
      } // Define and insert the base html element.
 
 
      var propsWindowHtml = '<div id="overview_window_content_pane" style="width:100%; word-wrap:break-word;  display:inline-block; margin-top:20px;">' + '<div id="overview_window_content" style="position:relative; left:12px; top:0px;">' + '<div style="background-color:#A0A0A0; display:inline-block; overflow:visible;">' + '<svg id="overviewMiniView" width="150" height="100" x="0" y="0" viewBox="0 0 4800 3600" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' + '<use x="0" y="0" xlink:href="#svgroot"> </use>' + '</svg>' + '<div id="overview_window_view_box" style="min-width:50px; min-height:50px; position:absolute; top:30px; left:30px; z-index:5; background-color:rgba(255,0,102,0.3);">' + '</div>' + '</div>' + '</div>' + '</div>';
      $('#sidepanels').append(propsWindowHtml); // Define dynamic animation of the view box.
 
      var updateViewBox = function updateViewBox() {
        var portHeight = parseFloat($('#workarea').css('height'));
        var portWidth = parseFloat($('#workarea').css('width'));
        var portX = $('#workarea').scrollLeft();
        var portY = $('#workarea').scrollTop();
        var windowWidth = parseFloat($('#svgcanvas').css('width'));
        var windowHeight = parseFloat($('#svgcanvas').css('height'));
        var overviewWidth = $('#overviewMiniView').attr('width');
        var overviewHeight = $('#overviewMiniView').attr('height');
        var viewBoxX = portX / windowWidth * overviewWidth;
        var viewBoxY = portY / windowHeight * overviewHeight;
        var viewBoxWidth = portWidth / windowWidth * overviewWidth;
        var viewBoxHeight = portHeight / windowHeight * overviewHeight;
        $('#overview_window_view_box').css('min-width', viewBoxWidth + 'px');
        $('#overview_window_view_box').css('min-height', viewBoxHeight + 'px');
        $('#overview_window_view_box').css('top', viewBoxY + 'px');
        $('#overview_window_view_box').css('left', viewBoxX + 'px');
      };
 
      $('#workarea').scroll(function () {
        if (!overviewWindowGlobals.viewBoxDragging) {
          updateViewBox();
        }
      });
      $('#workarea').resize(updateViewBox);
      updateViewBox(); // Compensate for changes in zoom and canvas size.
 
      var updateViewDimensions = function updateViewDimensions() {
        var viewWidth = $('#svgroot').attr('width');
        var viewHeight = $('#svgroot').attr('height');
        var viewX = 640;
        var viewY = 480;
 
        if (isIE()) {
          // This has only been tested with Firefox 10 and IE 9 (without chrome frame).
          // I am not sure if if is Firefox or IE that is being non compliant here.
          // Either way the one that is noncompliant may become more compliant later.
          // TAG:HACK
          // TAG:VERSION_DEPENDENT
          // TAG:BROWSER_SNIFFING
          viewX = 0;
          viewY = 0;
        }
 
        var svgWidthOld = $('#overviewMiniView').attr('width');
        var svgHeightNew = viewHeight / viewWidth * svgWidthOld;
        $('#overviewMiniView').attr('viewBox', viewX + ' ' + viewY + ' ' + viewWidth + ' ' + viewHeight);
        $('#overviewMiniView').attr('height', svgHeightNew);
        updateViewBox();
      };
 
      updateViewDimensions(); // Set up the overview window as a controller for the view port.
 
      overviewWindowGlobals.viewBoxDragging = false;
 
      var updateViewPortFromViewBox = function updateViewPortFromViewBox() {
        var windowWidth = parseFloat($('#svgcanvas').css('width'));
        var windowHeight = parseFloat($('#svgcanvas').css('height'));
        var overviewWidth = $('#overviewMiniView').attr('width');
        var overviewHeight = $('#overviewMiniView').attr('height');
        var viewBoxX = parseFloat($('#overview_window_view_box').css('left'));
        var viewBoxY = parseFloat($('#overview_window_view_box').css('top'));
        var portX = viewBoxX / overviewWidth * windowWidth;
        var portY = viewBoxY / overviewHeight * windowHeight;
        $('#workarea').scrollLeft(portX);
        $('#workarea').scrollTop(portY);
      };
 
      $('#overview_window_view_box').draggable({
        containment: 'parent',
        drag: updateViewPortFromViewBox,
        start: function start() {
          overviewWindowGlobals.viewBoxDragging = true;
        },
        stop: function stop() {
          overviewWindowGlobals.viewBoxDragging = false;
        }
      });
      $('#overviewMiniView').click(function (evt) {
        // Firefox doesn't support evt.offsetX and evt.offsetY.
        var mouseX = evt.offsetX || evt.originalEvent.layerX;
        var mouseY = evt.offsetY || evt.originalEvent.layerY;
        var overviewWidth = $('#overviewMiniView').attr('width');
        var overviewHeight = $('#overviewMiniView').attr('height');
        var viewBoxWidth = parseFloat($('#overview_window_view_box').css('min-width'));
        var viewBoxHeight = parseFloat($('#overview_window_view_box').css('min-height'));
        var viewBoxX = mouseX - 0.5 * viewBoxWidth;
        var viewBoxY = mouseY - 0.5 * viewBoxHeight; // deal with constraints
 
        if (viewBoxX < 0) {
          viewBoxX = 0;
        }
 
        if (viewBoxY < 0) {
          viewBoxY = 0;
        }
 
        if (viewBoxX + viewBoxWidth > overviewWidth) {
          viewBoxX = overviewWidth - viewBoxWidth;
        }
 
        if (viewBoxY + viewBoxHeight > overviewHeight) {
          viewBoxY = overviewHeight - viewBoxHeight;
        }
 
        $('#overview_window_view_box').css('top', viewBoxY + 'px');
        $('#overview_window_view_box').css('left', viewBoxX + 'px');
        updateViewPortFromViewBox();
      });
      return {
        name: 'overview window',
        canvasUpdated: updateViewDimensions,
        workareaResized: updateViewBox
      };
    }
  };
 
  return extOverview_window;
 
}());