(INCOMPLETE: ES6 Module conversion and linting)
- Breaking change: Require `new` with `EmbeddedSVGEdit` (allows us to use `class` internally)
- Breaking change: If `svgcanvas.setUiStrings` must now be called if not using editor in order
to get strings (for sake of i18n) (and if using path.js alone, must also have its `setUiStrings` called)
- Breaking change (ext-overview-window): Avoid global `overviewWindowGlobals`
- Breaking change (ext-imagelib): Change to object-based encoding for namespacing of
messages (though keep stringifying/parsing ourselves until we remove IE9 support)
- Breaking change: Rename `jquery.js` to `jquery.min.js`
- Breaking change: Remove `scoped` attribute from `style`; it is now deprecated and
obsolete; also move to head (after other stylesheets)
- Enhancement: Make SpinButton plugin independent of SVGEdit via
generic state object for tool_scale
- Enhancement: Remove now unused Python l10n scripts (#238)
- Enhancement: ES6 Modules (including jQuery plugins but not jQuery)
- Enhancement: Further JSDoc (incomplete)
- Enhancement (Optimization): Compress images using imageoptim (and add
npm script) (per #215)
- Fix: i18nize path.js strings and canvas notifications
- Fix: Attempt i18n for ext-markers
- Refactoring (ext-storage): Move locale info to own file imported by the extension (toward modularity; still should be split into separate files by language and *dynamically* imported, but we'll wait for better `import` support to refactor this)
- Refactoring: For imagelib, add local jQuery copy (using old 1.4.4 as had
been using from server)
- Refactoring: For MathJax, add local copy (using old 2.3 as had been using from
server); server had not been working
- Refactoring: Remove `use strict` (implicit in modules)
- Refactoring: Remove trailing whitespace, fix some code within comments
- Refactoring: Expect `jQuery` global rather than `$` for better modularity
(also to adapt line later once available via `import`)
- Refactoring: Prefer `const` (and then `let`)
- Refactoring: Add block scope keywords closer to first block in which they appear
- Refactoring: Use ES6 `class`
- Refactoring `$.isArray` -> `Array.isArray` and avoid some other jQuery core methods
with simple VanillaJS replacements
- Refactoring: Use abbreviated object property syntax
- Refactoring: Object destructuring
- Refactoring: Remove `uiStrings` contents in svg-editor.js (obtains from locale)
- Refactoring: Add favicon to embedded API file
- Refactoring: Use arrow functions for brief functions (incomplete)
- Refactoring: Use `Array.prototype.includes`/`String.prototype.includes`;
`String.prototype.startsWith`, `String.prototype.trim`
- Refactoring: Remove now unnecessary svgutils do/while resetting of variables
- Refactoring: Use shorthand methods for object literals (avoid ": function")
- Refactoring: Avoid quoting object property keys where unnecessary
- Refactoring: Just do truthy/falsey check for lengths in place of comparison to 0
- Refactoring (Testing): Avoid jQuery usage within most test files (defer script,
also in preparation for future switch to ES6 modules for tests)
- Refactoring: Make jpicker variable declaration indent bearable
- Refactoring (Linting): Finish svgcanvas.js
- Docs: Mention in comment no longer an entry file as before
- Docs: Migrate old config, extensions, and FAQ docs
- Licensing: Indicate MIT is license type of rgbcolor; rename/add license file name for
jgraduate and screencast to reflect type (Apache 2.0); rename file to reflect it
contains license information (of type MIT) for Raphael icons
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
/* eslint-disable no-var */
|
||||
/* globals $, svgEditor */
|
||||
/* SpinButton control
|
||||
*
|
||||
* Adds bells and whistles to any ordinary textbox to
|
||||
@@ -43,179 +41,162 @@
|
||||
* Fast-repeat for keys and live updating as you type.
|
||||
* v1.8 12 Jan 2010 - Benjamin Thomas - Fixes for mouseout behavior.
|
||||
* Added smallStep
|
||||
|
||||
* ? 20 May 2018 - Brett Zamir - Avoid SVGEdit dependency via `stateObj` config;
|
||||
convert to ES6 module
|
||||
Sample usage:
|
||||
|
||||
// Create group of settings to initialise spinbutton(s). (Optional)
|
||||
var myOptions = {
|
||||
min: 0, // Set lower limit.
|
||||
max: 100, // Set upper limit.
|
||||
step: 1, // Set increment size.
|
||||
smallStep: 0.5, // Set shift-click increment size.
|
||||
spinClass: mySpinBtnClass, // CSS class to style the spinbutton. (Class also specifies url of the up/down button image.)
|
||||
upClass: mySpinUpClass, // CSS class for style when mouse over up button.
|
||||
downClass: mySpinDnClass // CSS class for style when mouse over down button.
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
const myOptions = {
|
||||
min: 0, // Set lower limit.
|
||||
max: 100, // Set upper limit.
|
||||
step: 1, // Set increment size.
|
||||
smallStep: 0.5, // Set shift-click increment size.
|
||||
stateObj: {tool_scale: 1}, // Object to allow passing in live-updating scale
|
||||
spinClass: mySpinBtnClass, // CSS class to style the spinbutton. (Class also specifies url of the up/down button image.)
|
||||
upClass: mySpinUpClass, // CSS class for style when mouse over up button.
|
||||
downClass: mySpinDnClass // CSS class for style when mouse over down button.
|
||||
};
|
||||
|
||||
$(function () {
|
||||
// Initialise INPUT element(s) as SpinButtons: (passing options if desired)
|
||||
$("#myInputElement").SpinButton(myOptions);
|
||||
|
||||
});
|
||||
|
||||
*/
|
||||
$.fn.SpinButton = function (cfg) {
|
||||
'use strict';
|
||||
function coord (el, prop) {
|
||||
var c = el[prop], b = document.body;
|
||||
export default function ($) {
|
||||
$.fn.SpinButton = function (cfg) {
|
||||
cfg = cfg || {};
|
||||
function coord (el, prop) {
|
||||
const b = document.body;
|
||||
|
||||
while ((el = el.offsetParent) && (el !== b)) {
|
||||
if (!$.browser.msie || (el.currentStyle.position !== 'relative')) {
|
||||
c += el[prop];
|
||||
let c = el[prop];
|
||||
while ((el = el.offsetParent) && (el !== b)) {
|
||||
if (!$.browser.msie || (el.currentStyle.position !== 'relative')) {
|
||||
c += el[prop];
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
return this.each(function () {
|
||||
this.repeating = false;
|
||||
|
||||
return this.each(function () {
|
||||
this.repeating = false;
|
||||
// Apply specified options or defaults:
|
||||
// (Ought to refactor this some day to use $.extend() instead)
|
||||
this.spinCfg = {
|
||||
// min: cfg.min ? Number(cfg.min) : null,
|
||||
// max: cfg.max ? Number(cfg.max) : null,
|
||||
min: !isNaN(parseFloat(cfg.min)) ? Number(cfg.min) : null, // Fixes bug with min:0
|
||||
max: !isNaN(parseFloat(cfg.max)) ? Number(cfg.max) : null,
|
||||
step: cfg.step ? Number(cfg.step) : 1,
|
||||
stepfunc: cfg.stepfunc || false,
|
||||
page: cfg.page ? Number(cfg.page) : 10,
|
||||
upClass: cfg.upClass || 'up',
|
||||
downClass: cfg.downClass || 'down',
|
||||
reset: cfg.reset || this.value,
|
||||
delay: cfg.delay ? Number(cfg.delay) : 500,
|
||||
interval: cfg.interval ? Number(cfg.interval) : 100,
|
||||
_btn_width: 20,
|
||||
_direction: null,
|
||||
_delay: null,
|
||||
_repeat: null,
|
||||
callback: cfg.callback || null
|
||||
};
|
||||
|
||||
// Apply specified options or defaults:
|
||||
// (Ought to refactor this some day to use $.extend() instead)
|
||||
this.spinCfg = {
|
||||
// min: cfg && cfg.min ? Number(cfg.min) : null,
|
||||
// max: cfg && cfg.max ? Number(cfg.max) : null,
|
||||
min: cfg && !isNaN(parseFloat(cfg.min)) ? Number(cfg.min) : null, // Fixes bug with min:0
|
||||
max: cfg && !isNaN(parseFloat(cfg.max)) ? Number(cfg.max) : null,
|
||||
step: cfg && cfg.step ? Number(cfg.step) : 1,
|
||||
stepfunc: cfg && cfg.stepfunc ? cfg.stepfunc : false,
|
||||
page: cfg && cfg.page ? Number(cfg.page) : 10,
|
||||
upClass: cfg && cfg.upClass ? cfg.upClass : 'up',
|
||||
downClass: cfg && cfg.downClass ? cfg.downClass : 'down',
|
||||
reset: cfg && cfg.reset ? cfg.reset : this.value,
|
||||
delay: cfg && cfg.delay ? Number(cfg.delay) : 500,
|
||||
interval: cfg && cfg.interval ? Number(cfg.interval) : 100,
|
||||
_btn_width: 20,
|
||||
_direction: null,
|
||||
_delay: null,
|
||||
_repeat: null,
|
||||
callback: cfg && cfg.callback ? cfg.callback : null
|
||||
};
|
||||
// if a smallStep isn't supplied, use half the regular step
|
||||
this.spinCfg.smallStep = cfg.smallStep || this.spinCfg.step / 2;
|
||||
|
||||
// if a smallStep isn't supplied, use half the regular step
|
||||
this.spinCfg.smallStep = cfg && cfg.smallStep ? cfg.smallStep : this.spinCfg.step / 2;
|
||||
this.adjustValue = function (i) {
|
||||
let v;
|
||||
if (isNaN(this.value)) {
|
||||
v = this.spinCfg.reset;
|
||||
} else if (typeof this.spinCfg.stepfunc === 'function') {
|
||||
v = this.spinCfg.stepfunc(this, i);
|
||||
} else {
|
||||
// weirdest JavaScript bug ever: 5.1 + 0.1 = 5.199999999
|
||||
v = Number((Number(this.value) + Number(i)).toFixed(5));
|
||||
}
|
||||
if (this.spinCfg.min !== null) { v = Math.max(v, this.spinCfg.min); }
|
||||
if (this.spinCfg.max !== null) { v = Math.min(v, this.spinCfg.max); }
|
||||
this.value = v;
|
||||
if (typeof this.spinCfg.callback === 'function') { this.spinCfg.callback(this); }
|
||||
};
|
||||
|
||||
this.adjustValue = function (i) {
|
||||
var v;
|
||||
if (isNaN(this.value)) {
|
||||
v = this.spinCfg.reset;
|
||||
} else if ($.isFunction(this.spinCfg.stepfunc)) {
|
||||
v = this.spinCfg.stepfunc(this, i);
|
||||
} else {
|
||||
// weirdest javascript bug ever: 5.1 + 0.1 = 5.199999999
|
||||
v = Number((Number(this.value) + Number(i)).toFixed(5));
|
||||
}
|
||||
if (this.spinCfg.min !== null) { v = Math.max(v, this.spinCfg.min); }
|
||||
if (this.spinCfg.max !== null) { v = Math.min(v, this.spinCfg.max); }
|
||||
this.value = v;
|
||||
if ($.isFunction(this.spinCfg.callback)) { this.spinCfg.callback(this); }
|
||||
};
|
||||
$(this)
|
||||
.addClass(cfg.spinClass || 'spin-button')
|
||||
|
||||
$(this)
|
||||
.addClass(cfg && cfg.spinClass ? cfg.spinClass : 'spin-button')
|
||||
.mousemove(function (e) {
|
||||
// Determine which button mouse is over, or not (spin direction):
|
||||
const x = e.pageX || e.x;
|
||||
const y = e.pageY || e.y;
|
||||
const el = e.target;
|
||||
const scale = cfg.stateObj.tool_scale || 1;
|
||||
const height = $(el).height() / 2;
|
||||
|
||||
.mousemove(function (e) {
|
||||
// Determine which button mouse is over, or not (spin direction):
|
||||
var x = e.pageX || e.x;
|
||||
var y = e.pageY || e.y;
|
||||
var el = e.target || e.srcElement;
|
||||
var scale = svgEditor.tool_scale || 1;
|
||||
var height = $(el).height() / 2;
|
||||
const direction =
|
||||
(x > coord(el, 'offsetLeft') +
|
||||
el.offsetWidth * scale - this.spinCfg._btn_width)
|
||||
? ((y < coord(el, 'offsetTop') + height * scale) ? 1 : -1) : 0;
|
||||
|
||||
var direction =
|
||||
(x > coord(el, 'offsetLeft') +
|
||||
el.offsetWidth * scale - this.spinCfg._btn_width)
|
||||
? ((y < coord(el, 'offsetTop') + height * scale) ? 1 : -1) : 0;
|
||||
if (direction !== this.spinCfg._direction) {
|
||||
// Style up/down buttons:
|
||||
switch (direction) {
|
||||
case 1: // Up arrow:
|
||||
$(this).removeClass(this.spinCfg.downClass).addClass(this.spinCfg.upClass);
|
||||
break;
|
||||
case -1: // Down arrow:
|
||||
$(this).removeClass(this.spinCfg.upClass).addClass(this.spinCfg.downClass);
|
||||
break;
|
||||
default: // Mouse is elsewhere in the textbox
|
||||
$(this).removeClass(this.spinCfg.upClass).removeClass(this.spinCfg.downClass);
|
||||
}
|
||||
|
||||
if (direction !== this.spinCfg._direction) {
|
||||
// Style up/down buttons:
|
||||
switch (direction) {
|
||||
case 1: // Up arrow:
|
||||
$(this).removeClass(this.spinCfg.downClass).addClass(this.spinCfg.upClass);
|
||||
break;
|
||||
case -1: // Down arrow:
|
||||
$(this).removeClass(this.spinCfg.upClass).addClass(this.spinCfg.downClass);
|
||||
break;
|
||||
default: // Mouse is elsewhere in the textbox
|
||||
$(this).removeClass(this.spinCfg.upClass).removeClass(this.spinCfg.downClass);
|
||||
// Set spin direction:
|
||||
this.spinCfg._direction = direction;
|
||||
}
|
||||
})
|
||||
|
||||
// Set spin direction:
|
||||
this.spinCfg._direction = direction;
|
||||
}
|
||||
})
|
||||
.mouseout(function () {
|
||||
// Reset up/down buttons to their normal appearance when mouse moves away:
|
||||
$(this).removeClass(this.spinCfg.upClass).removeClass(this.spinCfg.downClass);
|
||||
this.spinCfg._direction = null;
|
||||
window.clearInterval(this.spinCfg._repeat);
|
||||
window.clearTimeout(this.spinCfg._delay);
|
||||
})
|
||||
|
||||
.mouseout(function () {
|
||||
// Reset up/down buttons to their normal appearance when mouse moves away:
|
||||
$(this).removeClass(this.spinCfg.upClass).removeClass(this.spinCfg.downClass);
|
||||
this.spinCfg._direction = null;
|
||||
window.clearInterval(this.spinCfg._repeat);
|
||||
window.clearTimeout(this.spinCfg._delay);
|
||||
})
|
||||
.mousedown(function (e) {
|
||||
if (e.button === 0 && this.spinCfg._direction !== 0) {
|
||||
// Respond to click on one of the buttons:
|
||||
const stepSize = e.shiftKey ? this.spinCfg.smallStep : this.spinCfg.step;
|
||||
|
||||
.mousedown(function (e) {
|
||||
if (e.button === 0 && this.spinCfg._direction !== 0) {
|
||||
// Respond to click on one of the buttons:
|
||||
var self = this;
|
||||
var stepSize = e.shiftKey ? self.spinCfg.smallStep : self.spinCfg.step;
|
||||
const adjust = () => {
|
||||
this.adjustValue(this.spinCfg._direction * stepSize);
|
||||
};
|
||||
|
||||
var adjust = function () {
|
||||
self.adjustValue(self.spinCfg._direction * stepSize);
|
||||
};
|
||||
|
||||
adjust();
|
||||
|
||||
// Initial delay before repeating adjustment
|
||||
self.spinCfg._delay = window.setTimeout(function () {
|
||||
adjust();
|
||||
// Repeat adjust at regular intervals
|
||||
self.spinCfg._repeat = window.setInterval(adjust, self.spinCfg.interval);
|
||||
}, self.spinCfg.delay);
|
||||
}
|
||||
})
|
||||
|
||||
.mouseup(function (e) {
|
||||
// Cancel repeating adjustment
|
||||
window.clearInterval(this.spinCfg._repeat);
|
||||
window.clearTimeout(this.spinCfg._delay);
|
||||
})
|
||||
// Initial delay before repeating adjustment
|
||||
this.spinCfg._delay = window.setTimeout(() => {
|
||||
adjust();
|
||||
// Repeat adjust at regular intervals
|
||||
this.spinCfg._repeat = window.setInterval(adjust, this.spinCfg.interval);
|
||||
}, this.spinCfg.delay);
|
||||
}
|
||||
})
|
||||
|
||||
.dblclick(function (e) {
|
||||
if ($.browser.msie) {
|
||||
this.adjustValue(this.spinCfg._direction * this.spinCfg.step);
|
||||
}
|
||||
})
|
||||
.mouseup(function (e) {
|
||||
// Cancel repeating adjustment
|
||||
window.clearInterval(this.spinCfg._repeat);
|
||||
window.clearTimeout(this.spinCfg._delay);
|
||||
})
|
||||
|
||||
.keydown(function (e) {
|
||||
// Respond to up/down arrow keys.
|
||||
switch (e.keyCode) {
|
||||
case 38: this.adjustValue(this.spinCfg.step); break; // Up
|
||||
case 40: this.adjustValue(-this.spinCfg.step); break; // Down
|
||||
case 33: this.adjustValue(this.spinCfg.page); break; // PageUp
|
||||
case 34: this.adjustValue(-this.spinCfg.page); break; // PageDown
|
||||
}
|
||||
})
|
||||
.dblclick(function (e) {
|
||||
if ($.browser.msie) {
|
||||
this.adjustValue(this.spinCfg._direction * this.spinCfg.step);
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
http://unixpapa.com/js/key.html describes the current state-of-affairs for
|
||||
key repeat events:
|
||||
- Safari 3.1 changed their model so that keydown is reliably repeated going forward
|
||||
- Firefox and Opera still only repeat the keypress event, not the keydown
|
||||
*/
|
||||
.keypress(function (e) {
|
||||
if (this.repeating) {
|
||||
.keydown(function (e) {
|
||||
// Respond to up/down arrow keys.
|
||||
switch (e.keyCode) {
|
||||
case 38: this.adjustValue(this.spinCfg.step); break; // Up
|
||||
@@ -223,50 +204,69 @@ $.fn.SpinButton = function (cfg) {
|
||||
case 33: this.adjustValue(this.spinCfg.page); break; // PageUp
|
||||
case 34: this.adjustValue(-this.spinCfg.page); break; // PageDown
|
||||
}
|
||||
// we always ignore the first keypress event (use the keydown instead)
|
||||
} else {
|
||||
this.repeating = true;
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// clear the 'repeating' flag
|
||||
.keyup(function (e) {
|
||||
this.repeating = false;
|
||||
switch (e.keyCode) {
|
||||
case 38: // Up
|
||||
case 40: // Down
|
||||
case 33: // PageUp
|
||||
case 34: // PageDown
|
||||
case 13: this.adjustValue(0); break; // Enter/Return
|
||||
}
|
||||
})
|
||||
/*
|
||||
http://unixpapa.com/js/key.html describes the current state-of-affairs for
|
||||
key repeat events:
|
||||
- Safari 3.1 changed their model so that keydown is reliably repeated going forward
|
||||
- Firefox and Opera still only repeat the keypress event, not the keydown
|
||||
*/
|
||||
.keypress(function (e) {
|
||||
if (this.repeating) {
|
||||
// Respond to up/down arrow keys.
|
||||
switch (e.keyCode) {
|
||||
case 38: this.adjustValue(this.spinCfg.step); break; // Up
|
||||
case 40: this.adjustValue(-this.spinCfg.step); break; // Down
|
||||
case 33: this.adjustValue(this.spinCfg.page); break; // PageUp
|
||||
case 34: this.adjustValue(-this.spinCfg.page); break; // PageDown
|
||||
}
|
||||
// we always ignore the first keypress event (use the keydown instead)
|
||||
} else {
|
||||
this.repeating = true;
|
||||
}
|
||||
})
|
||||
|
||||
.bind('mousewheel', function (e) {
|
||||
// Respond to mouse wheel in IE. (It returns up/dn motion in multiples of 120)
|
||||
if (e.wheelDelta >= 120) {
|
||||
this.adjustValue(this.spinCfg.step);
|
||||
} else if (e.wheelDelta <= -120) {
|
||||
this.adjustValue(-this.spinCfg.step);
|
||||
}
|
||||
// clear the 'repeating' flag
|
||||
.keyup(function (e) {
|
||||
this.repeating = false;
|
||||
switch (e.keyCode) {
|
||||
case 38: // Up
|
||||
case 40: // Down
|
||||
case 33: // PageUp
|
||||
case 34: // PageDown
|
||||
case 13: this.adjustValue(0); break; // Enter/Return
|
||||
}
|
||||
})
|
||||
|
||||
e.preventDefault();
|
||||
})
|
||||
.bind('mousewheel', function (e) {
|
||||
// Respond to mouse wheel in IE. (It returns up/dn motion in multiples of 120)
|
||||
if (e.wheelDelta >= 120) {
|
||||
this.adjustValue(this.spinCfg.step);
|
||||
} else if (e.wheelDelta <= -120) {
|
||||
this.adjustValue(-this.spinCfg.step);
|
||||
}
|
||||
|
||||
.change(function (e) {
|
||||
this.adjustValue(0);
|
||||
});
|
||||
e.preventDefault();
|
||||
})
|
||||
|
||||
if (this.addEventListener) {
|
||||
// Respond to mouse wheel in Firefox
|
||||
this.addEventListener('DOMMouseScroll', function (e) {
|
||||
if (e.detail > 0) {
|
||||
this.adjustValue(-this.spinCfg.step);
|
||||
} else if (e.detail < 0) {
|
||||
this.adjustValue(this.spinCfg.step);
|
||||
}
|
||||
.change(function (e) {
|
||||
this.adjustValue(0);
|
||||
});
|
||||
|
||||
e.preventDefault();
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
};
|
||||
if (this.addEventListener) {
|
||||
// Respond to mouse wheel in Firefox
|
||||
this.addEventListener('DOMMouseScroll', function (e) {
|
||||
if (e.detail > 0) {
|
||||
this.adjustValue(-this.spinCfg.step);
|
||||
} else if (e.detail < 0) {
|
||||
this.adjustValue(this.spinCfg.step);
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
};
|
||||
return $;
|
||||
}
|
||||
|
||||
2
editor/spinbtn/JQuerySpinBtn.min.js
vendored
2
editor/spinbtn/JQuerySpinBtn.min.js
vendored
@@ -1 +1 @@
|
||||
$.fn.SpinButton=function(cfg){"use strict";function coord(el,prop){for(var c=el[prop],b=document.body;(el=el.offsetParent)&&el!==b;)$.browser.msie&&"relative"===el.currentStyle.position||(c+=el[prop]);return c}return this.each(function(){this.repeating=!1,this.spinCfg={min:cfg&&!isNaN(parseFloat(cfg.min))?Number(cfg.min):null,max:cfg&&!isNaN(parseFloat(cfg.max))?Number(cfg.max):null,step:cfg&&cfg.step?Number(cfg.step):1,stepfunc:!(!cfg||!cfg.stepfunc)&&cfg.stepfunc,page:cfg&&cfg.page?Number(cfg.page):10,upClass:cfg&&cfg.upClass?cfg.upClass:"up",downClass:cfg&&cfg.downClass?cfg.downClass:"down",reset:cfg&&cfg.reset?cfg.reset:this.value,delay:cfg&&cfg.delay?Number(cfg.delay):500,interval:cfg&&cfg.interval?Number(cfg.interval):100,_btn_width:20,_direction:null,_delay:null,_repeat:null,callback:cfg&&cfg.callback?cfg.callback:null},this.spinCfg.smallStep=cfg&&cfg.smallStep?cfg.smallStep:this.spinCfg.step/2,this.adjustValue=function(i){var v;v=isNaN(this.value)?this.spinCfg.reset:$.isFunction(this.spinCfg.stepfunc)?this.spinCfg.stepfunc(this,i):Number((Number(this.value)+Number(i)).toFixed(5)),null!==this.spinCfg.min&&(v=Math.max(v,this.spinCfg.min)),null!==this.spinCfg.max&&(v=Math.min(v,this.spinCfg.max)),this.value=v,$.isFunction(this.spinCfg.callback)&&this.spinCfg.callback(this)},$(this).addClass(cfg&&cfg.spinClass?cfg.spinClass:"spin-button").mousemove(function(e){var x=e.pageX||e.x,y=e.pageY||e.y,el=e.target||e.srcElement,scale=svgEditor.tool_scale||1,height=$(el).height()/2,direction=x>coord(el,"offsetLeft")+el.offsetWidth*scale-this.spinCfg._btn_width?y<coord(el,"offsetTop")+height*scale?1:-1:0;if(direction!==this.spinCfg._direction){switch(direction){case 1:$(this).removeClass(this.spinCfg.downClass).addClass(this.spinCfg.upClass);break;case-1:$(this).removeClass(this.spinCfg.upClass).addClass(this.spinCfg.downClass);break;default:$(this).removeClass(this.spinCfg.upClass).removeClass(this.spinCfg.downClass)}this.spinCfg._direction=direction}}).mouseout(function(){$(this).removeClass(this.spinCfg.upClass).removeClass(this.spinCfg.downClass),this.spinCfg._direction=null,window.clearInterval(this.spinCfg._repeat),window.clearTimeout(this.spinCfg._delay)}).mousedown(function(e){if(0===e.button&&0!==this.spinCfg._direction){var self=this,stepSize=e.shiftKey?self.spinCfg.smallStep:self.spinCfg.step,adjust=function(){self.adjustValue(self.spinCfg._direction*stepSize)};adjust(),self.spinCfg._delay=window.setTimeout(function(){adjust(),self.spinCfg._repeat=window.setInterval(adjust,self.spinCfg.interval)},self.spinCfg.delay)}}).mouseup(function(e){window.clearInterval(this.spinCfg._repeat),window.clearTimeout(this.spinCfg._delay)}).dblclick(function(e){$.browser.msie&&this.adjustValue(this.spinCfg._direction*this.spinCfg.step)}).keydown(function(e){switch(e.keyCode){case 38:this.adjustValue(this.spinCfg.step);break;case 40:this.adjustValue(-this.spinCfg.step);break;case 33:this.adjustValue(this.spinCfg.page);break;case 34:this.adjustValue(-this.spinCfg.page)}}).keypress(function(e){if(this.repeating)switch(e.keyCode){case 38:this.adjustValue(this.spinCfg.step);break;case 40:this.adjustValue(-this.spinCfg.step);break;case 33:this.adjustValue(this.spinCfg.page);break;case 34:this.adjustValue(-this.spinCfg.page)}else this.repeating=!0}).keyup(function(e){switch(this.repeating=!1,e.keyCode){case 38:case 40:case 33:case 34:case 13:this.adjustValue(0)}}).bind("mousewheel",function(e){e.wheelDelta>=120?this.adjustValue(this.spinCfg.step):e.wheelDelta<=-120&&this.adjustValue(-this.spinCfg.step),e.preventDefault()}).change(function(e){this.adjustValue(0)}),this.addEventListener&&this.addEventListener("DOMMouseScroll",function(e){e.detail>0?this.adjustValue(-this.spinCfg.step):e.detail<0&&this.adjustValue(this.spinCfg.step),e.preventDefault()},!1)})};
|
||||
const $=jQuery;$.fn.SpinButton=function(cfg){function coord(el,prop){const b=document.body;let c=el[prop];for(;(el=el.offsetParent)&&el!==b;)$.browser.msie&&"relative"===el.currentStyle.position||(c+=el[prop]);return c}return this.each(function(){this.repeating=!1,this.spinCfg={min:cfg&&!isNaN(parseFloat(cfg.min))?Number(cfg.min):null,max:cfg&&!isNaN(parseFloat(cfg.max))?Number(cfg.max):null,step:cfg&&cfg.step?Number(cfg.step):1,stepfunc:!(!cfg||!cfg.stepfunc)&&cfg.stepfunc,page:cfg&&cfg.page?Number(cfg.page):10,upClass:cfg&&cfg.upClass?cfg.upClass:"up",downClass:cfg&&cfg.downClass?cfg.downClass:"down",reset:cfg&&cfg.reset?cfg.reset:this.value,delay:cfg&&cfg.delay?Number(cfg.delay):500,interval:cfg&&cfg.interval?Number(cfg.interval):100,_btn_width:20,_direction:null,_delay:null,_repeat:null,callback:cfg&&cfg.callback?cfg.callback:null},this.spinCfg.smallStep=cfg&&cfg.smallStep?cfg.smallStep:this.spinCfg.step/2,this.adjustValue=function(i){let v;v=isNaN(this.value)?this.spinCfg.reset:$.isFunction(this.spinCfg.stepfunc)?this.spinCfg.stepfunc(this,i):Number((Number(this.value)+Number(i)).toFixed(5)),null!==this.spinCfg.min&&(v=Math.max(v,this.spinCfg.min)),null!==this.spinCfg.max&&(v=Math.min(v,this.spinCfg.max)),this.value=v,$.isFunction(this.spinCfg.callback)&&this.spinCfg.callback(this)},$(this).addClass(cfg&&cfg.spinClass?cfg.spinClass:"spin-button").mousemove(function(e){const x=e.pageX||e.x,y=e.pageY||e.y,el=e.target||e.srcElement,scale=svgEditor.tool_scale||1,height=$(el).height()/2,direction=x>coord(el,"offsetLeft")+el.offsetWidth*scale-this.spinCfg._btn_width?y<coord(el,"offsetTop")+height*scale?1:-1:0;if(direction!==this.spinCfg._direction){switch(direction){case 1:$(this).removeClass(this.spinCfg.downClass).addClass(this.spinCfg.upClass);break;case-1:$(this).removeClass(this.spinCfg.upClass).addClass(this.spinCfg.downClass);break;default:$(this).removeClass(this.spinCfg.upClass).removeClass(this.spinCfg.downClass)}this.spinCfg._direction=direction}}).mouseout(function(){$(this).removeClass(this.spinCfg.upClass).removeClass(this.spinCfg.downClass),this.spinCfg._direction=null,window.clearInterval(this.spinCfg._repeat),window.clearTimeout(this.spinCfg._delay)}).mousedown(function(e){if(0===e.button&&0!==this.spinCfg._direction){const self=this,stepSize=e.shiftKey?self.spinCfg.smallStep:self.spinCfg.step,adjust=function(){self.adjustValue(self.spinCfg._direction*stepSize)};adjust(),self.spinCfg._delay=window.setTimeout(function(){adjust(),self.spinCfg._repeat=window.setInterval(adjust,self.spinCfg.interval)},self.spinCfg.delay)}}).mouseup(function(e){window.clearInterval(this.spinCfg._repeat),window.clearTimeout(this.spinCfg._delay)}).dblclick(function(e){$.browser.msie&&this.adjustValue(this.spinCfg._direction*this.spinCfg.step)}).keydown(function(e){switch(e.keyCode){case 38:this.adjustValue(this.spinCfg.step);break;case 40:this.adjustValue(-this.spinCfg.step);break;case 33:this.adjustValue(this.spinCfg.page);break;case 34:this.adjustValue(-this.spinCfg.page)}}).keypress(function(e){if(this.repeating)switch(e.keyCode){case 38:this.adjustValue(this.spinCfg.step);break;case 40:this.adjustValue(-this.spinCfg.step);break;case 33:this.adjustValue(this.spinCfg.page);break;case 34:this.adjustValue(-this.spinCfg.page)}else this.repeating=!0}).keyup(function(e){switch(this.repeating=!1,e.keyCode){case 38:case 40:case 33:case 34:case 13:this.adjustValue(0)}}).bind("mousewheel",function(e){e.wheelDelta>=120?this.adjustValue(this.spinCfg.step):e.wheelDelta<=-120&&this.adjustValue(-this.spinCfg.step),e.preventDefault()}).change(function(e){this.adjustValue(0)}),this.addEventListener&&this.addEventListener("DOMMouseScroll",function(e){e.detail>0?this.adjustValue(-this.spinCfg.step):e.detail<0&&this.adjustValue(this.spinCfg.step),e.preventDefault()},!1)})};
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 666 B After Width: | Height: | Size: 572 B |
Reference in New Issue
Block a user