- Breaking change: Rename config file to `svgedit-config-iife.js` (or for the module version, `svgedit-config-es.js`);
also expect one directory higher; incorporates #207 (@iuyiuy)
- Breaking change: Separate `extIconsPath` from `extPath` (not copying over icons)
- Breaking change: Don't reference `custom.css` in HTML; can instead be referenced in JavaScript through
the config file (provided in `svgedit-config-sample-iife.js`/`svgedit-config-sample-es.js` as `svgedit-custom.css` for
better namespacing); incorporates #207 (@iuyiuy)
- Breaking change: Remove minified jgraduate/spinbtn files (minified within Rollup routine)
- Fix: Zoom when scrolled; incorporates #169 (@AndrolGenhald), adapting for conventions; also allow avoidance when shift key pressed
- Fix: Update Atom feed reference in HTML
- Fixes related to recent commits: Some path and method name fixes needed, function order, missing methods, variable scope declaration, no need for DOMContentLoaded listeners in modules, switch back to non-default export, avoid trimming nullish, deal with mock tests, fix `math.matrixMultiply`, use jquery-svg where needed for array/SVG attributes; add babel-polyfill and defer script to imagelib; other misc. fixes
- Enhancement: Move config-sample.js out of `editor` directory
- Enhancement: For `callback`-style extensions, also provide config object; add following
to that object: buildCanvgCallback, canvg, decode64, encode64, executeAfterLoads, getTypeMap, isChrome, ieIE, NS, text2xml
- Enhancement: Complete ES6 modules work (extensions, locales, tests), along with Babel;
make Node build routine for converting modular source to non-modular,
use `loadStylesheets` for modular stylehsheet defining (but parallel loading);
- Enhancement: Add `stylesheets` config for modular but parallel stylesheet loading with `@default` option for simple inclusion/exclusion of defaults (if not going with default).
- Refactoring: Clean up `svg-editor.html`: consistent indents; avoid extra lbs, avoid long lines
- Refactoring: Avoid embedded API adding inline JavaScript listener
- Refactoring: Move layers and context code to `draw.js`
- Refactoring: Move `pathActions` from `svgcanvas.js` (though preserve aliases to these methods on `canvas`) and `convertPath` from `svgutils.js` to `path.js`
- Refactoring: Move `getStrokedBBox` from `svgcanvas.js` (while keeping an alias) to `svgutils.js` (as `getStrokedBBoxDefaultVisible` to avoid conflict with existing)
- Docs: Remove "dependencies" comments in code except where summarizing role of jQuery or a non-obvious dependency
- Refactoring/Linting: Enfore `no-extra-semi` and `quote-props` rules
- Refactoring: Further avoidance of quotes on properties (as possible)
- Refactoring: Use `class` in place of functions where intended as classes
- Refactoring: Consistency and granularity in extensions imports
- Testing: Update QUnit to 2.6.1 (node_modules) and Sinon to 5.0.8 (and add sinon-test at 2.1.3) and enforce eslint-plugin-qunit linting rules; update custom extensions
- Testing: Add node-static for automating (and accessing out-of-directory contents)
- Testing: Avoid HTML attributes for styling
- Testing: Add npm `test` script
- Testing: Comment out unused jQuery SVG test
- Testing: Add test1 and svgutils_performance_test to all tests page
- Testing: Due apparently to Path having not been a formal class, the test was calling it without `new`; refactored now with sufficient mock data to take into account it is a class
- npm: Update devDeps
- npm: Add html modules and config build to test script
2018-05-22 10:03:16 +00:00
/* globals jQuery, MathJax */
2013-04-12 19:25:18 +00:00
/ *
* ext - mathjax . js
*
* Licensed under the Apache License
*
* Copyright ( c ) 2013 Jo Segaert
*
* /
- Breaking change: Rename config file to `svgedit-config-iife.js` (or for the module version, `svgedit-config-es.js`);
also expect one directory higher; incorporates #207 (@iuyiuy)
- Breaking change: Separate `extIconsPath` from `extPath` (not copying over icons)
- Breaking change: Don't reference `custom.css` in HTML; can instead be referenced in JavaScript through
the config file (provided in `svgedit-config-sample-iife.js`/`svgedit-config-sample-es.js` as `svgedit-custom.css` for
better namespacing); incorporates #207 (@iuyiuy)
- Breaking change: Remove minified jgraduate/spinbtn files (minified within Rollup routine)
- Fix: Zoom when scrolled; incorporates #169 (@AndrolGenhald), adapting for conventions; also allow avoidance when shift key pressed
- Fix: Update Atom feed reference in HTML
- Fixes related to recent commits: Some path and method name fixes needed, function order, missing methods, variable scope declaration, no need for DOMContentLoaded listeners in modules, switch back to non-default export, avoid trimming nullish, deal with mock tests, fix `math.matrixMultiply`, use jquery-svg where needed for array/SVG attributes; add babel-polyfill and defer script to imagelib; other misc. fixes
- Enhancement: Move config-sample.js out of `editor` directory
- Enhancement: For `callback`-style extensions, also provide config object; add following
to that object: buildCanvgCallback, canvg, decode64, encode64, executeAfterLoads, getTypeMap, isChrome, ieIE, NS, text2xml
- Enhancement: Complete ES6 modules work (extensions, locales, tests), along with Babel;
make Node build routine for converting modular source to non-modular,
use `loadStylesheets` for modular stylehsheet defining (but parallel loading);
- Enhancement: Add `stylesheets` config for modular but parallel stylesheet loading with `@default` option for simple inclusion/exclusion of defaults (if not going with default).
- Refactoring: Clean up `svg-editor.html`: consistent indents; avoid extra lbs, avoid long lines
- Refactoring: Avoid embedded API adding inline JavaScript listener
- Refactoring: Move layers and context code to `draw.js`
- Refactoring: Move `pathActions` from `svgcanvas.js` (though preserve aliases to these methods on `canvas`) and `convertPath` from `svgutils.js` to `path.js`
- Refactoring: Move `getStrokedBBox` from `svgcanvas.js` (while keeping an alias) to `svgutils.js` (as `getStrokedBBoxDefaultVisible` to avoid conflict with existing)
- Docs: Remove "dependencies" comments in code except where summarizing role of jQuery or a non-obvious dependency
- Refactoring/Linting: Enfore `no-extra-semi` and `quote-props` rules
- Refactoring: Further avoidance of quotes on properties (as possible)
- Refactoring: Use `class` in place of functions where intended as classes
- Refactoring: Consistency and granularity in extensions imports
- Testing: Update QUnit to 2.6.1 (node_modules) and Sinon to 5.0.8 (and add sinon-test at 2.1.3) and enforce eslint-plugin-qunit linting rules; update custom extensions
- Testing: Add node-static for automating (and accessing out-of-directory contents)
- Testing: Avoid HTML attributes for styling
- Testing: Add npm `test` script
- Testing: Comment out unused jQuery SVG test
- Testing: Add test1 and svgutils_performance_test to all tests page
- Testing: Due apparently to Path having not been a formal class, the test was calling it without `new`; refactored now with sufficient mock data to take into account it is a class
- npm: Update devDeps
- npm: Add html modules and config build to test script
2018-05-22 10:03:16 +00:00
import svgEditor from '../svg-editor.js' ;
2018-05-16 00:53:27 +00:00
svgEditor . addExtension ( 'mathjax' , function ( ) {
2018-05-18 03:25:45 +00:00
const $ = jQuery ;
- Breaking change: Rename config file to `svgedit-config-iife.js` (or for the module version, `svgedit-config-es.js`);
also expect one directory higher; incorporates #207 (@iuyiuy)
- Breaking change: Separate `extIconsPath` from `extPath` (not copying over icons)
- Breaking change: Don't reference `custom.css` in HTML; can instead be referenced in JavaScript through
the config file (provided in `svgedit-config-sample-iife.js`/`svgedit-config-sample-es.js` as `svgedit-custom.css` for
better namespacing); incorporates #207 (@iuyiuy)
- Breaking change: Remove minified jgraduate/spinbtn files (minified within Rollup routine)
- Fix: Zoom when scrolled; incorporates #169 (@AndrolGenhald), adapting for conventions; also allow avoidance when shift key pressed
- Fix: Update Atom feed reference in HTML
- Fixes related to recent commits: Some path and method name fixes needed, function order, missing methods, variable scope declaration, no need for DOMContentLoaded listeners in modules, switch back to non-default export, avoid trimming nullish, deal with mock tests, fix `math.matrixMultiply`, use jquery-svg where needed for array/SVG attributes; add babel-polyfill and defer script to imagelib; other misc. fixes
- Enhancement: Move config-sample.js out of `editor` directory
- Enhancement: For `callback`-style extensions, also provide config object; add following
to that object: buildCanvgCallback, canvg, decode64, encode64, executeAfterLoads, getTypeMap, isChrome, ieIE, NS, text2xml
- Enhancement: Complete ES6 modules work (extensions, locales, tests), along with Babel;
make Node build routine for converting modular source to non-modular,
use `loadStylesheets` for modular stylehsheet defining (but parallel loading);
- Enhancement: Add `stylesheets` config for modular but parallel stylesheet loading with `@default` option for simple inclusion/exclusion of defaults (if not going with default).
- Refactoring: Clean up `svg-editor.html`: consistent indents; avoid extra lbs, avoid long lines
- Refactoring: Avoid embedded API adding inline JavaScript listener
- Refactoring: Move layers and context code to `draw.js`
- Refactoring: Move `pathActions` from `svgcanvas.js` (though preserve aliases to these methods on `canvas`) and `convertPath` from `svgutils.js` to `path.js`
- Refactoring: Move `getStrokedBBox` from `svgcanvas.js` (while keeping an alias) to `svgutils.js` (as `getStrokedBBoxDefaultVisible` to avoid conflict with existing)
- Docs: Remove "dependencies" comments in code except where summarizing role of jQuery or a non-obvious dependency
- Refactoring/Linting: Enfore `no-extra-semi` and `quote-props` rules
- Refactoring: Further avoidance of quotes on properties (as possible)
- Refactoring: Use `class` in place of functions where intended as classes
- Refactoring: Consistency and granularity in extensions imports
- Testing: Update QUnit to 2.6.1 (node_modules) and Sinon to 5.0.8 (and add sinon-test at 2.1.3) and enforce eslint-plugin-qunit linting rules; update custom extensions
- Testing: Add node-static for automating (and accessing out-of-directory contents)
- Testing: Avoid HTML attributes for styling
- Testing: Add npm `test` script
- Testing: Comment out unused jQuery SVG test
- Testing: Add test1 and svgutils_performance_test to all tests page
- Testing: Due apparently to Path having not been a formal class, the test was calling it without `new`; refactored now with sufficient mock data to take into account it is a class
- npm: Update devDeps
- npm: Add html modules and config build to test script
2018-05-22 10:03:16 +00:00
const svgCanvas = svgEditor . canvas ;
2018-05-18 03:25:45 +00:00
2018-05-18 04:54:31 +00:00
// Configuration of the MathJax extention.
2013-04-12 19:25:18 +00:00
2018-05-18 04:54:31 +00:00
// This will be added to the head tag before MathJax is loaded.
2018-05-18 03:25:45 +00:00
const / * mathjaxConfiguration = ' < script type = "text/x-mathjax-config" > \
2018-05-18 04:54:31 +00:00
MathJax . Hub . Config ( { \
extensions : [ "tex2jax.js" ] , \
jax : [ "input/TeX" , "output/SVG" ] , \
showProcessingMessages : true , \
showMathMenu : false , \
showMathMenuMSIE : false , \
errorSettings : { \
message : [ "[Math Processing Error]" ] , \
style : { color : "#CC0000" , "font-style" : "italic" } \
} , \
elements : [ ] , \
tex2jax : { \
ignoreClass : "tex2jax_ignore2" , processClass : "tex2jax_process2" , \
} , \
TeX : { \
extensions : [ "AMSmath.js" , "AMSsymbols.js" , "noErrors.js" , "noUndefined.js" ] \
} , \
"SVG" : { \
} \
} ) ; \
< /script>', */
// mathjaxSrc = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js',
2018-05-18 03:25:45 +00:00
// Had been on https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_SVG.js
// Obtained Text-AMS-MML_SVG.js from https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.3/config/TeX-AMS-MML_SVG.js
mathjaxSrcSecure = 'mathjax/MathJax.js?config=TeX-AMS-MML_SVG.js' ,
{ uiStrings } = svgEditor ;
let
2018-05-18 04:54:31 +00:00
math ,
locationX ,
locationY ,
2018-05-18 03:25:45 +00:00
mathjaxLoaded = false ;
2013-04-12 19:25:18 +00:00
2018-05-18 04:54:31 +00:00
// TODO: Implement language support. Move these uiStrings to the locale files and the code to the langReady callback.
$ . extend ( uiStrings , {
mathjax : {
embed _svg : 'Save as mathematics' ,
embed _mathml : 'Save as figure' ,
svg _save _warning : 'The math will be transformed into a figure is manipulatable like everything else. You will not be able to manipulate the TeX-code anymore. ' ,
mathml _save _warning : 'Advised. The math will be saved as a figure.' ,
title : 'Mathematics code editor'
}
} ) ;
2013-04-12 19:25:18 +00:00
2018-05-18 04:54:31 +00:00
function saveMath ( ) {
2018-05-18 03:25:45 +00:00
const code = $ ( '#mathjax_code_textarea' ) . val ( ) ;
2018-05-18 04:54:31 +00:00
// displaystyle to force MathJax NOT to use the inline style. Because it is
// less fancy!
MathJax . Hub . queue . Push ( [ 'Text' , math , '\\displaystyle{' + code + '}' ] ) ;
2013-04-12 19:25:18 +00:00
2018-05-18 04:54:31 +00:00
/ *
* The MathJax library doesn ' t want to bloat your webpage so it creates
* every symbol ( glymph ) you need only once . These are saved in a < svg > on
* the top of your html document , just under the body tag . Each glymph has
* its unique id and is saved as a < path > in the < defs > tag of the < svg >
*
* Then when the symbols are needed in the rest of your html document they
* are refferd to by a < use > tag .
* Because of bug 1076 we can ' t just grab the defs tag on the top and add it
* to your formula ' s < svg > and copy the lot . So we have to replace each
* < use > tag by it ' s < path > .
* /
MathJax . Hub . queue . Push (
function ( ) {
2018-05-18 03:25:45 +00:00
const mathjaxMath = $ ( '.MathJax_SVG' ) ;
const svg = $ ( mathjaxMath . html ( ) ) ;
2018-05-18 04:54:31 +00:00
svg . find ( 'use' ) . each ( function ( ) {
// TODO: find a less pragmatic and more elegant solution to this.
2018-05-18 03:25:45 +00:00
const id = $ ( this ) . attr ( 'href' )
? $ ( this ) . attr ( 'href' ) . slice ( 1 ) // Works in Chrome.
: $ ( this ) . attr ( 'xlink:href' ) . slice ( 1 ) ; // Works in Firefox.
const glymph = $ ( '#' + id ) . clone ( ) . removeAttr ( 'id' ) ;
const x = $ ( this ) . attr ( 'x' ) ;
const y = $ ( this ) . attr ( 'y' ) ;
const transform = $ ( this ) . attr ( 'transform' ) ;
2018-05-18 04:54:31 +00:00
if ( transform && ( x || y ) ) {
glymph . attr ( 'transform' , transform + ' translate(' + x + ',' + y + ')' ) ;
} else if ( transform ) {
glymph . attr ( 'transform' , transform ) ;
} else if ( x || y ) {
glymph . attr ( 'transform' , 'translate(' + x + ',' + y + ')' ) ;
}
$ ( this ) . replaceWith ( glymph ) ;
} ) ;
// Remove the style tag because it interferes with SVG-Edit.
svg . removeAttr ( 'style' ) ;
svg . attr ( 'xmlns' , 'http://www.w3.org/2000/svg' ) ;
svgCanvas . importSvgString ( $ ( '<div>' ) . append ( svg . clone ( ) ) . html ( ) , true ) ;
svgCanvas . ungroupSelectedElement ( ) ;
// TODO: To undo the adding of the Formula you now have to undo twice.
// This should only be once!
svgCanvas . moveSelectedElements ( locationX , locationY , true ) ;
}
) ;
}
2013-04-12 19:25:18 +00:00
2018-05-18 04:54:31 +00:00
return {
name : 'MathJax' ,
- Breaking change: Rename config file to `svgedit-config-iife.js` (or for the module version, `svgedit-config-es.js`);
also expect one directory higher; incorporates #207 (@iuyiuy)
- Breaking change: Separate `extIconsPath` from `extPath` (not copying over icons)
- Breaking change: Don't reference `custom.css` in HTML; can instead be referenced in JavaScript through
the config file (provided in `svgedit-config-sample-iife.js`/`svgedit-config-sample-es.js` as `svgedit-custom.css` for
better namespacing); incorporates #207 (@iuyiuy)
- Breaking change: Remove minified jgraduate/spinbtn files (minified within Rollup routine)
- Fix: Zoom when scrolled; incorporates #169 (@AndrolGenhald), adapting for conventions; also allow avoidance when shift key pressed
- Fix: Update Atom feed reference in HTML
- Fixes related to recent commits: Some path and method name fixes needed, function order, missing methods, variable scope declaration, no need for DOMContentLoaded listeners in modules, switch back to non-default export, avoid trimming nullish, deal with mock tests, fix `math.matrixMultiply`, use jquery-svg where needed for array/SVG attributes; add babel-polyfill and defer script to imagelib; other misc. fixes
- Enhancement: Move config-sample.js out of `editor` directory
- Enhancement: For `callback`-style extensions, also provide config object; add following
to that object: buildCanvgCallback, canvg, decode64, encode64, executeAfterLoads, getTypeMap, isChrome, ieIE, NS, text2xml
- Enhancement: Complete ES6 modules work (extensions, locales, tests), along with Babel;
make Node build routine for converting modular source to non-modular,
use `loadStylesheets` for modular stylehsheet defining (but parallel loading);
- Enhancement: Add `stylesheets` config for modular but parallel stylesheet loading with `@default` option for simple inclusion/exclusion of defaults (if not going with default).
- Refactoring: Clean up `svg-editor.html`: consistent indents; avoid extra lbs, avoid long lines
- Refactoring: Avoid embedded API adding inline JavaScript listener
- Refactoring: Move layers and context code to `draw.js`
- Refactoring: Move `pathActions` from `svgcanvas.js` (though preserve aliases to these methods on `canvas`) and `convertPath` from `svgutils.js` to `path.js`
- Refactoring: Move `getStrokedBBox` from `svgcanvas.js` (while keeping an alias) to `svgutils.js` (as `getStrokedBBoxDefaultVisible` to avoid conflict with existing)
- Docs: Remove "dependencies" comments in code except where summarizing role of jQuery or a non-obvious dependency
- Refactoring/Linting: Enfore `no-extra-semi` and `quote-props` rules
- Refactoring: Further avoidance of quotes on properties (as possible)
- Refactoring: Use `class` in place of functions where intended as classes
- Refactoring: Consistency and granularity in extensions imports
- Testing: Update QUnit to 2.6.1 (node_modules) and Sinon to 5.0.8 (and add sinon-test at 2.1.3) and enforce eslint-plugin-qunit linting rules; update custom extensions
- Testing: Add node-static for automating (and accessing out-of-directory contents)
- Testing: Avoid HTML attributes for styling
- Testing: Add npm `test` script
- Testing: Comment out unused jQuery SVG test
- Testing: Add test1 and svgutils_performance_test to all tests page
- Testing: Due apparently to Path having not been a formal class, the test was calling it without `new`; refactored now with sufficient mock data to take into account it is a class
- npm: Update devDeps
- npm: Add html modules and config build to test script
2018-05-22 10:03:16 +00:00
svgicons : svgEditor . curConfig . extIconsPath + 'mathjax-icons.xml' ,
2018-05-18 04:54:31 +00:00
buttons : [ {
id : 'tool_mathjax' ,
type : 'mode' ,
title : 'Add Mathematics' ,
events : {
2018-05-18 03:25:45 +00:00
click ( ) {
2018-05-18 04:54:31 +00:00
// Only load Mathjax when needed, we don't want to strain Svg-Edit any more.
// From this point on it is very probable that it will be needed, so load it.
if ( mathjaxLoaded === false ) {
$ ( '<div id="mathjax">' +
'<!-- Here is where MathJax creates the math -->' +
'<div id="mathjax_creator" class="tex2jax_process" style="display:none">' +
'$${}$$' +
'</div>' +
'<div id="mathjax_overlay"></div>' +
'<div id="mathjax_container">' +
'<div id="tool_mathjax_back" class="toolbar_button">' +
'<button id="tool_mathjax_save">OK</button>' +
'<button id="tool_mathjax_cancel">Cancel</button>' +
'</div>' +
'<fieldset>' +
'<legend id="mathjax_legend">Mathematics Editor</legend>' +
'<label>' +
'<span id="mathjax_explication">Please type your mathematics in ' +
2018-05-18 04:40:50 +00:00
'<a href="https://en.wikipedia.org/wiki/Help:Displaying_a_formula" target="_blank">TeX</a> code.</span></label>' +
2018-05-18 04:54:31 +00:00
'<textarea id="mathjax_code_textarea" spellcheck="false"></textarea>' +
'</fieldset>' +
'</div>' +
'</div>'
) . insertAfter ( '#svg_prefs' ) . hide ( ) ;
2013-04-12 19:25:18 +00:00
2018-05-18 04:54:31 +00:00
// Make the MathEditor draggable.
$ ( '#mathjax_container' ) . draggable ( { cancel : 'button,fieldset' , containment : 'window' } ) ;
2013-04-12 19:25:18 +00:00
2018-05-18 04:54:31 +00:00
// Add functionality and picture to cancel button.
$ ( '#tool_mathjax_cancel' ) . prepend ( $ . getSvgIcon ( 'cancel' , true ) )
. on ( 'click touched' , function ( ) {
$ ( '#mathjax' ) . hide ( ) ;
} ) ;
2013-04-12 19:25:18 +00:00
2018-05-18 04:54:31 +00:00
// Add functionality and picture to the save button.
$ ( '#tool_mathjax_save' ) . prepend ( $ . getSvgIcon ( 'ok' , true ) )
. on ( 'click touched' , function ( ) {
saveMath ( ) ;
$ ( '#mathjax' ) . hide ( ) ;
} ) ;
2013-04-12 19:25:18 +00:00
2018-05-18 04:54:31 +00:00
// MathJax preprocessing has to ignore most of the page.
$ ( 'body' ) . addClass ( 'tex2jax_ignore' ) ;
2013-04-12 19:25:18 +00:00
2018-05-18 04:54:31 +00:00
// Now get (and run) the MathJax Library.
- Breaking change: Rename config file to `svgedit-config-iife.js` (or for the module version, `svgedit-config-es.js`);
also expect one directory higher; incorporates #207 (@iuyiuy)
- Breaking change: Separate `extIconsPath` from `extPath` (not copying over icons)
- Breaking change: Don't reference `custom.css` in HTML; can instead be referenced in JavaScript through
the config file (provided in `svgedit-config-sample-iife.js`/`svgedit-config-sample-es.js` as `svgedit-custom.css` for
better namespacing); incorporates #207 (@iuyiuy)
- Breaking change: Remove minified jgraduate/spinbtn files (minified within Rollup routine)
- Fix: Zoom when scrolled; incorporates #169 (@AndrolGenhald), adapting for conventions; also allow avoidance when shift key pressed
- Fix: Update Atom feed reference in HTML
- Fixes related to recent commits: Some path and method name fixes needed, function order, missing methods, variable scope declaration, no need for DOMContentLoaded listeners in modules, switch back to non-default export, avoid trimming nullish, deal with mock tests, fix `math.matrixMultiply`, use jquery-svg where needed for array/SVG attributes; add babel-polyfill and defer script to imagelib; other misc. fixes
- Enhancement: Move config-sample.js out of `editor` directory
- Enhancement: For `callback`-style extensions, also provide config object; add following
to that object: buildCanvgCallback, canvg, decode64, encode64, executeAfterLoads, getTypeMap, isChrome, ieIE, NS, text2xml
- Enhancement: Complete ES6 modules work (extensions, locales, tests), along with Babel;
make Node build routine for converting modular source to non-modular,
use `loadStylesheets` for modular stylehsheet defining (but parallel loading);
- Enhancement: Add `stylesheets` config for modular but parallel stylesheet loading with `@default` option for simple inclusion/exclusion of defaults (if not going with default).
- Refactoring: Clean up `svg-editor.html`: consistent indents; avoid extra lbs, avoid long lines
- Refactoring: Avoid embedded API adding inline JavaScript listener
- Refactoring: Move layers and context code to `draw.js`
- Refactoring: Move `pathActions` from `svgcanvas.js` (though preserve aliases to these methods on `canvas`) and `convertPath` from `svgutils.js` to `path.js`
- Refactoring: Move `getStrokedBBox` from `svgcanvas.js` (while keeping an alias) to `svgutils.js` (as `getStrokedBBoxDefaultVisible` to avoid conflict with existing)
- Docs: Remove "dependencies" comments in code except where summarizing role of jQuery or a non-obvious dependency
- Refactoring/Linting: Enfore `no-extra-semi` and `quote-props` rules
- Refactoring: Further avoidance of quotes on properties (as possible)
- Refactoring: Use `class` in place of functions where intended as classes
- Refactoring: Consistency and granularity in extensions imports
- Testing: Update QUnit to 2.6.1 (node_modules) and Sinon to 5.0.8 (and add sinon-test at 2.1.3) and enforce eslint-plugin-qunit linting rules; update custom extensions
- Testing: Add node-static for automating (and accessing out-of-directory contents)
- Testing: Avoid HTML attributes for styling
- Testing: Add npm `test` script
- Testing: Comment out unused jQuery SVG test
- Testing: Add test1 and svgutils_performance_test to all tests page
- Testing: Due apparently to Path having not been a formal class, the test was calling it without `new`; refactored now with sufficient mock data to take into account it is a class
- npm: Update devDeps
- npm: Add html modules and config build to test script
2018-05-22 10:03:16 +00:00
// Todo: insert script with modules once widely supported
// and if MathJax (and its `TeX-AMS-MML_SVG.js` dependency) ends up
// providing an ES6 module export: https://github.com/mathjax/MathJax/issues/1998
/ *
const s = document . createElement ( 'script' ) ;
const modularVersion = ! ( 'svgEditor' in window ) ||
! window . svgEditor ||
window . svgEditor . modules !== false ;
if ( modularVersion ) {
s . type = 'module' ; // Make this the default when widely supported
}
s . src = curConfig . extPath + mathjaxSrcSecure ;
// See `executeAfterLoads` in `svgutils.js`
* /
2018-05-28 13:59:39 +00:00
$ . getScript ( svgEditor . curConfig . extIconsPath + mathjaxSrcSecure )
2018-05-18 04:54:31 +00:00
. done ( function ( script , textStatus ) {
// When MathJax is loaded get the div where the math will be rendered.
MathJax . Hub . queue . Push ( function ( ) {
math = MathJax . Hub . getAllJax ( '#mathjax_creator' ) [ 0 ] ;
console . log ( math ) ;
mathjaxLoaded = true ;
console . log ( 'MathJax Loaded' ) ;
} ) ;
} )
// If it fails.
. fail ( function ( ) {
console . log ( 'Failed loadeing MathJax.' ) ;
$ . alert ( 'Failed loading MathJax. You will not be able to change the mathematics.' ) ;
} ) ;
}
// Set the mode.
svgCanvas . setMode ( 'mathjax' ) ;
}
}
} ] ,
2013-04-12 19:25:18 +00:00
2018-05-18 03:25:45 +00:00
mouseDown ( ) {
2018-05-18 04:54:31 +00:00
if ( svgCanvas . getMode ( ) === 'mathjax' ) {
return { started : true } ;
}
} ,
2018-05-18 03:25:45 +00:00
mouseUp ( opts ) {
2018-05-18 04:54:31 +00:00
if ( svgCanvas . getMode ( ) === 'mathjax' ) {
// Get the coordinates from your mouse.
2018-05-18 03:25:45 +00:00
const zoom = svgCanvas . getZoom ( ) ;
2018-05-18 04:54:31 +00:00
// Get the actual coordinate by dividing by the zoom value
locationX = opts . mouse _x / zoom ;
locationY = opts . mouse _y / zoom ;
2013-04-12 19:25:18 +00:00
2018-05-18 04:54:31 +00:00
$ ( '#mathjax' ) . show ( ) ;
return { started : false } ; // Otherwise the last selected object dissapears.
}
} ,
2018-05-18 03:25:45 +00:00
callback ( ) {
2018-05-18 04:54:31 +00:00
$ ( '<style>' ) . text (
'#mathjax fieldset{' +
'padding: 5px;' +
'margin: 5px;' +
'border: 1px solid #DDD;' +
'}' +
'#mathjax label{' +
'display: block;' +
'margin: .5em;' +
'}' +
'#mathjax legend {' +
'max-width:195px;' +
'}' +
'#mathjax_overlay {' +
'position: absolute;' +
'top: 0;' +
'left: 0;' +
'right: 0;' +
'bottom: 0;' +
'background-color: black;' +
'opacity: 0.6;' +
'z-index: 20000;' +
'}' +
'#mathjax_container {' +
'position: absolute;' +
'top: 50px;' +
'padding: 10px;' +
'background-color: #B0B0B0;' +
'border: 1px outset #777;' +
'opacity: 1.0;' +
'font-family: Verdana, Helvetica, sans-serif;' +
'font-size: .8em;' +
'z-index: 20001;' +
'}' +
'#tool_mathjax_back {' +
'margin-left: 1em;' +
'overflow: auto;' +
'}' +
'#mathjax_legend{' +
'font-weight: bold;' +
'font-size:1.1em;' +
'}' +
'#mathjax_code_textarea {\\n' +
'margin: 5px .7em;' +
'overflow: hidden;' +
'width: 416px;' +
'display: block;' +
'height: 100px;' +
'}'
) . appendTo ( 'head' ) ;
2013-04-12 19:25:18 +00:00
2018-05-18 04:54:31 +00:00
// Add the MathJax configuration.
// $(mathjaxConfiguration).appendTo('head');
}
} ;
2014-02-12 03:48:48 +00:00
} ) ;