- Breaking change: Rename "svgutils.js" to "utilities.js" (make in conformity with JSDoc module naming convention) - Breaking change: Rename "svgedit.js" to "namespaces.js" (to make clear purpose and avoid confusing with editor) - Breaking change: Rename "jquery-svg.js" to "jQuery.attr.js" - Breaking change: Rename "jquery.contextMenu.js" to "jQuery.contextMenu.js" - Breaking change: Rename "jquery.jpicker.js" to "jQuery.jPicker.js" - Breaking change: Rename "JQuerySpinBtn.css" to "jQuery.SpinButton.css" - Breaking change: Rename "JQuerySpinBtn.js" to "jQuery.SpinButton.js" (to have file name more closely reflect name) - Breaking change: Rename "jquery.svgicons.js" to "jQuery.svgIcons.js" - Breaking change: Rename "jquery.jgraduate.js" to "jQuery.jGraduate.js" - Breaking change: Rename "pathseg.js" to "svgpathseg.js" (as it is a poyfill of SVGPathSeg) - Breaking change: Rename `addSvgElementFromJson()` to `addSVGElementFromJson` for consistency - Breaking change: Rename `changeSvgContent()` to `changeSVGContent()` for consistency - Breaking change: Have `exportPDF` resolve with `output` and `outputType` rather than `dataurlstring` (as type may vary) - Breaking change: Rename `extensions/mathjax/MathJax.js` to `extensions/mathjax/MathJax.min.js` - Breaking change: Avoid recent change to have editor ready callbacks return Promises (we're not using and advantageous to keep sequential) - Breaking change: Avoid recent addition of locale-side function in ext-imagelib for l10n - Breaking change: Change name of ext-arrows.js from `Arrows` to `arrows` for sake of file path (not localized anyways). - Breaking change: Change `addlangData` extension event to `addLangData` for consistency with method name - Breaking change: Have `readLang` return lang and data but do not call `setLang` - Fix: Have general locales load first so extensions may use - Fix: Provide `importLocale` to extensions `init` so it may delay adding of the extension until locale data loaded - Fix: Ensure call to `rasterExport` without `imgType` properly sets MIME type to PNG - Fix: Wrong name for moinsave - Update: Update WebAppFind per new API changes - Enhancement: Make `setStrings` public on editor for late setting (used by `ext-shapes.js`) - Enhancement: Add `extensions_added` event - Enhancement: Add `message` event (Relay messages including those which have been been received prior to extension load) - Enhancement: Allow SVGEdit to work out of the box--avoid need for copying sample config file. Should also help with Github-based file servers - Enhancement: Allow avoiding "name" in extension export (just extract out of file name) - Enhancement: Add stack blur to canvg by default (and refactoring it) - Enhancement: Return `Promise` for `embedImage` (as with some other loading methods) - Enhancement: Supply `importLocale` to `langReady` to facilitate extension locale loading - Enhancement: Recover if an extension fails to load (just log and otherwise ignore) - Enhancement: More i18n of extensions (also fixed issue with some console warnings about missing locale strings); i18nize Hello World too - Enhancement: Allowing importing of locales within `addLangData` - npm: Update devDeps - Docs: Migrate copies of all old wiki pages to docs/from-old-wiki folder; intended for a possible move to Markdown, so raw HTML (with formatting) was not preserved, though named links had their absolute URL links preserved - Docs: Begin deleting `SvgCanvas.md` as ensuring jsdoc has replacements - Docs: Add Edtior doc file for help to general users - Docs: Clarify/simplify install instructions - npm/Docs (JSDoc): Add script to check for overly generic types - Docs (JSDoc): For config/prefs and extension creating, link to tutorials (moved tutorials to own directory to avoid recursion problems by jsdoc) - Docs (JSDoc): Add modules (upper case for usual main entrance files or regular names) - Docs (JSDoc): Fill out missing areas; indicate return of `undefined`; consistency with `@returns` - Docs (JSDoc): Add our own layout template to support overflow - Docs (JSDoc): Use cleverLinks and disallow unknown tags - Docs (JSDoc): Insist on "pedantic" flag; put output directory in config - Docs (JSDoc): Use more precise Integer/Float over number, the specific type of array/function/object - Docs (JSDoc): Use `@throws`, `@enum`, `@event`/`@fires`/`@listens` - Docs: Generally update/improve docs (fixes #92) - Docs: Update links to `latest` path (Avoid needing to update such references upon each release) - Docs: 80 chars max - Refactoring: Drop code for extension as function (already requiring export to be an object) - Refactoring: Object destructuring, `Object.entries`, Object shorthand, array extras, more camelCase variable names - Refactoring: Add a `Command` base class - Refactoring: Simplify svgicons `callback` ready detection - Refactoring: Put `let` or `const` closer to scope - Refactoring: Remove unneeded `delimiter` from regex escaping utility - Refactoring: Clearer variable names - Refactoring: Use (non-deprecated) Event constructors - Testing: Use new Sinon
157 lines
6.6 KiB
JavaScript
157 lines
6.6 KiB
JavaScript
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;
|
|
|
|
}());
|