2018-05-16 00:53:27 +00:00
|
|
|
/* eslint-disable no-var */
|
|
|
|
/* globals svgEditor, svgedit, $ */
|
2013-09-23 18:55:52 +00:00
|
|
|
/*
|
|
|
|
* ext-overview_window.js
|
|
|
|
*
|
|
|
|
* Licensed under the MIT License
|
|
|
|
*
|
|
|
|
* Copyright(c) 2013 James Sacksteder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-02-12 09:38:38 +00:00
|
|
|
var overviewWindowGlobals = {};
|
2018-05-16 00:53:27 +00:00
|
|
|
svgEditor.addExtension('overview_window', function () {
|
|
|
|
'use strict';
|
2015-12-07 15:53:28 +00:00
|
|
|
// Disabled in Chrome 48-, see https://github.com/SVG-Edit/svgedit/issues/26 and
|
2015-12-04 01:25:18 +00:00
|
|
|
// https://code.google.com/p/chromium/issues/detail?id=565120.
|
|
|
|
if (svgedit.browser.isChrome()) {
|
2018-05-16 00:53:27 +00:00
|
|
|
var verIndex = navigator.userAgent.indexOf('Chrome/') + 7;
|
2015-12-07 15:53:28 +00:00
|
|
|
var chromeVersion = parseInt(navigator.userAgent.substring(verIndex), 10);
|
|
|
|
if (chromeVersion < 49) {
|
|
|
|
return;
|
|
|
|
}
|
2015-12-04 01:25:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Define and insert the base html element.
|
2018-05-16 00:53:27 +00:00
|
|
|
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);
|
2014-02-16 03:21:15 +00:00
|
|
|
|
2015-12-04 01:25:18 +00:00
|
|
|
// Define dynamic animation of the view box.
|
2018-05-16 00:53:27 +00:00
|
|
|
var updateViewBox = function () {
|
|
|
|
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');
|
2013-09-23 18:55:52 +00:00
|
|
|
};
|
2018-05-16 00:53:27 +00:00
|
|
|
$('#workarea').scroll(function () {
|
|
|
|
if (!(overviewWindowGlobals.viewBoxDragging)) {
|
2014-02-12 09:38:38 +00:00
|
|
|
updateViewBox();
|
2013-09-23 18:55:52 +00:00
|
|
|
}
|
|
|
|
});
|
2018-05-16 00:53:27 +00:00
|
|
|
$('#workarea').resize(updateViewBox);
|
2013-09-23 18:55:52 +00:00
|
|
|
updateViewBox();
|
2018-05-16 00:53:27 +00:00
|
|
|
|
2015-12-04 01:25:18 +00:00
|
|
|
// Compensate for changes in zoom and canvas size.
|
2018-05-16 00:53:27 +00:00
|
|
|
var updateViewDimensions = function () {
|
|
|
|
var viewWidth = $('#svgroot').attr('width');
|
|
|
|
var viewHeight = $('#svgroot').attr('height');
|
|
|
|
var viewX = 640;
|
|
|
|
var viewY = 480;
|
|
|
|
|
|
|
|
if (svgedit.browser.isIE()) {
|
2015-12-04 01:25:18 +00:00
|
|
|
// 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.
|
2018-05-16 00:53:27 +00:00
|
|
|
// TAG:HACK
|
|
|
|
// TAG:VERSION_DEPENDENT
|
|
|
|
// TAG:BROWSER_SNIFFING
|
|
|
|
viewX = 0;
|
|
|
|
viewY = 0;
|
2013-09-23 18:55:52 +00:00
|
|
|
}
|
2018-05-16 00:53:27 +00:00
|
|
|
|
|
|
|
var svgWidthOld = $('#overviewMiniView').attr('width');
|
|
|
|
var svgHeightNew = viewHeight / viewWidth * svgWidthOld;
|
|
|
|
$('#overviewMiniView').attr('viewBox', viewX + ' ' + viewY + ' ' + viewWidth + ' ' + viewHeight);
|
|
|
|
$('#overviewMiniView').attr('height', svgHeightNew);
|
2013-09-23 18:55:52 +00:00
|
|
|
updateViewBox();
|
|
|
|
};
|
|
|
|
updateViewDimensions();
|
2018-05-16 00:53:27 +00:00
|
|
|
|
2015-12-04 01:25:18 +00:00
|
|
|
// Set up the overview window as a controller for the view port.
|
2018-05-16 00:53:27 +00:00
|
|
|
overviewWindowGlobals.viewBoxDragging = false;
|
|
|
|
var updateViewPortFromViewBox = function () {
|
|
|
|
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'));
|
2013-09-23 18:55:52 +00:00
|
|
|
|
2018-05-16 00:53:27 +00:00
|
|
|
var portX = viewBoxX / overviewWidth * windowWidth;
|
|
|
|
var portY = viewBoxY / overviewHeight * windowHeight;
|
|
|
|
|
|
|
|
$('#workarea').scrollLeft(portX);
|
|
|
|
$('#workarea').scrollTop(portY);
|
2013-09-23 18:55:52 +00:00
|
|
|
};
|
2018-05-16 00:53:27 +00:00
|
|
|
$('#overview_window_view_box').draggable({
|
|
|
|
containment: 'parent',
|
|
|
|
drag: updateViewPortFromViewBox,
|
|
|
|
start: function () { overviewWindowGlobals.viewBoxDragging = true; },
|
|
|
|
stop: function () { overviewWindowGlobals.viewBoxDragging = false; }
|
|
|
|
});
|
|
|
|
$('#overviewMiniView').click(function (evt) {
|
2015-12-04 01:25:18 +00:00
|
|
|
// Firefox doesn't support evt.offsetX and evt.offsetY.
|
2018-05-16 00:53:27 +00:00
|
|
|
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;
|
2013-09-23 18:55:52 +00:00
|
|
|
}
|
2018-05-16 00:53:27 +00:00
|
|
|
if (viewBoxY < 0) {
|
|
|
|
viewBoxY = 0;
|
2013-09-23 18:55:52 +00:00
|
|
|
}
|
2018-05-16 00:53:27 +00:00
|
|
|
if (viewBoxX + viewBoxWidth > overviewWidth) {
|
|
|
|
viewBoxX = overviewWidth - viewBoxWidth;
|
2013-09-23 18:55:52 +00:00
|
|
|
}
|
2018-05-16 00:53:27 +00:00
|
|
|
if (viewBoxY + viewBoxHeight > overviewHeight) {
|
|
|
|
viewBoxY = overviewHeight - viewBoxHeight;
|
2013-09-23 18:55:52 +00:00
|
|
|
}
|
2018-05-16 00:53:27 +00:00
|
|
|
|
|
|
|
$('#overview_window_view_box').css('top', viewBoxY + 'px');
|
|
|
|
$('#overview_window_view_box').css('left', viewBoxX + 'px');
|
2013-09-23 18:55:52 +00:00
|
|
|
updateViewPortFromViewBox();
|
|
|
|
});
|
2018-05-16 00:53:27 +00:00
|
|
|
|
2014-04-09 03:44:19 +00:00
|
|
|
return {
|
2018-05-16 00:53:27 +00:00
|
|
|
name: 'overview window',
|
2014-04-09 03:44:19 +00:00
|
|
|
canvasUpdated: updateViewDimensions,
|
|
|
|
workareaResized: updateViewBox
|
2013-09-23 18:55:52 +00:00
|
|
|
};
|
|
|
|
});
|