Fixed issue 213 by allowing a custom function as a step parameter to jQuerySpinBtn.js
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@819 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
7a784ad87c
commit
1f7b1f19f5
|
@ -33,6 +33,7 @@
|
||||||
* v1.3a 28 Sep 2006 - George Adamson - Minor enhancements
|
* v1.3a 28 Sep 2006 - George Adamson - Minor enhancements
|
||||||
* v1.4 18 Jun 2009 - Jeff Schiller - Added callback function
|
* v1.4 18 Jun 2009 - Jeff Schiller - Added callback function
|
||||||
* v1.5 06 Jul 2009 - Jeff Schiller - Fixes for Opera.
|
* v1.5 06 Jul 2009 - Jeff Schiller - Fixes for Opera.
|
||||||
|
* v1.6 13 Oct 2009 - Alexis Deveria - Added stepfunc function
|
||||||
* Fast-repeat for keys and live updating as you type.
|
* Fast-repeat for keys and live updating as you type.
|
||||||
|
|
||||||
Sample usage:
|
Sample usage:
|
||||||
|
@ -68,6 +69,7 @@ $.fn.SpinButton = function(cfg){
|
||||||
min: cfg && !isNaN(parseFloat(cfg.min)) ? Number(cfg.min) : null, // Fixes bug with min:0
|
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,
|
max: cfg && !isNaN(parseFloat(cfg.max)) ? Number(cfg.max) : null,
|
||||||
step: cfg && cfg.step ? Number(cfg.step) : 1,
|
step: cfg && cfg.step ? Number(cfg.step) : 1,
|
||||||
|
stepfunc: cfg && cfg.stepfunc ? cfg.stepfunc : false,
|
||||||
page: cfg && cfg.page ? Number(cfg.page) : 10,
|
page: cfg && cfg.page ? Number(cfg.page) : 10,
|
||||||
upClass: cfg && cfg.upClass ? cfg.upClass : 'up',
|
upClass: cfg && cfg.upClass ? cfg.upClass : 'up',
|
||||||
downClass: cfg && cfg.downClass ? cfg.downClass : 'down',
|
downClass: cfg && cfg.downClass ? cfg.downClass : 'down',
|
||||||
|
@ -82,8 +84,16 @@ $.fn.SpinButton = function(cfg){
|
||||||
callback: cfg && cfg.callback ? cfg.callback : null,
|
callback: cfg && cfg.callback ? cfg.callback : null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
this.adjustValue = function(i){
|
this.adjustValue = function(i){
|
||||||
var v = (isNaN(this.value) ? this.spinCfg.reset : Number(this.value)) + Number(i);
|
var v;
|
||||||
|
if(isNaN(this.value)) {
|
||||||
|
v = this.spinCfg.reset;
|
||||||
|
} else if($.isFunction(this.spinCfg.stepfunc)) {
|
||||||
|
v = this.spinCfg.stepfunc(this, i);
|
||||||
|
} else {
|
||||||
|
v = Number(this.value) + Number(i);
|
||||||
|
}
|
||||||
if (this.spinCfg.min !== null) v = Math.max(v, this.spinCfg.min);
|
if (this.spinCfg.min !== null) v = Math.max(v, this.spinCfg.min);
|
||||||
if (this.spinCfg.max !== null) v = Math.min(v, this.spinCfg.max);
|
if (this.spinCfg.max !== null) v = Math.min(v, this.spinCfg.max);
|
||||||
this.value = v;
|
this.value = v;
|
||||||
|
|
|
@ -88,8 +88,8 @@ function svg_edit_setup() {
|
||||||
var zoomChanged = function(window, bbox) {
|
var zoomChanged = function(window, bbox) {
|
||||||
var scrbar = 15;
|
var scrbar = 15;
|
||||||
var res = svgCanvas.getResolution();
|
var res = svgCanvas.getResolution();
|
||||||
|
|
||||||
var w_area = $('#workarea');
|
var w_area = $('#workarea');
|
||||||
|
var canvas_pos = $('#svgcanvas').position();
|
||||||
w_area.css('cursor','auto');
|
w_area.css('cursor','auto');
|
||||||
var z_info = svgCanvas.setBBoxZoom(bbox, w_area.width()-scrbar, w_area.height()-scrbar);
|
var z_info = svgCanvas.setBBoxZoom(bbox, w_area.width()-scrbar, w_area.height()-scrbar);
|
||||||
if(!z_info) return;
|
if(!z_info) return;
|
||||||
|
@ -99,10 +99,10 @@ function svg_edit_setup() {
|
||||||
setResolution(res.w * zoomlevel, res.h * zoomlevel);
|
setResolution(res.w * zoomlevel, res.h * zoomlevel);
|
||||||
var scrLeft = bb.x * zoomlevel;
|
var scrLeft = bb.x * zoomlevel;
|
||||||
var scrOffX = w_area.width()/2 - (bb.width * zoomlevel)/2;
|
var scrOffX = w_area.width()/2 - (bb.width * zoomlevel)/2;
|
||||||
w_area[0].scrollLeft = Math.max(0,scrLeft - scrOffX);
|
w_area[0].scrollLeft = Math.max(0,scrLeft - scrOffX) + Math.max(0,canvas_pos.left);
|
||||||
var scrTop = bb.y * zoomlevel;
|
var scrTop = bb.y * zoomlevel;
|
||||||
var scrOffY = w_area.height()/2 - (bb.height * zoomlevel)/2;
|
var scrOffY = w_area.height()/2 - (bb.height * zoomlevel)/2;
|
||||||
w_area[0].scrollTop = Math.max(0,scrTop - scrOffY);
|
w_area[0].scrollTop = Math.max(0,scrTop - scrOffY) + Math.max(0,canvas_pos.top);
|
||||||
clickSelect();
|
clickSelect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1349,6 +1349,21 @@ function svg_edit_setup() {
|
||||||
|
|
||||||
$(window).resize( centerCanvasIfNeeded );
|
$(window).resize( centerCanvasIfNeeded );
|
||||||
|
|
||||||
|
function stepZoom(elem, step) {
|
||||||
|
var orig_val = elem.value-0;
|
||||||
|
var sug_val = orig_val + step;
|
||||||
|
|
||||||
|
if(orig_val >= 100) {
|
||||||
|
return sug_val;
|
||||||
|
} else {
|
||||||
|
if(sug_val >= orig_val) {
|
||||||
|
return orig_val * 2;
|
||||||
|
} else {
|
||||||
|
return orig_val / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setResolution(w, h, center) {
|
function setResolution(w, h, center) {
|
||||||
w-=0; h-=0;
|
w-=0; h-=0;
|
||||||
$('#svgcanvas').css( { 'width': w, 'height': h } );
|
$('#svgcanvas').css( { 'width': w, 'height': h } );
|
||||||
|
@ -1357,8 +1372,13 @@ function svg_edit_setup() {
|
||||||
|
|
||||||
centerCanvasIfNeeded();
|
centerCanvasIfNeeded();
|
||||||
|
|
||||||
|
var res = svgCanvas.getResolution();
|
||||||
|
|
||||||
if(center) {
|
if(center) {
|
||||||
var w_area = $('#workarea');
|
var w_area = $('#workarea');
|
||||||
|
// console.log(w_area[0].scrollLeft); // 1677
|
||||||
|
// console.log('w',w_area.width()); // 875 // zoom: 4.67
|
||||||
|
// Want: 1942 (+265)
|
||||||
var scroll_y = h/2 - w_area.height()/2;
|
var scroll_y = h/2 - w_area.height()/2;
|
||||||
var scroll_x = w/2 - w_area.width()/2;
|
var scroll_x = w/2 - w_area.width()/2;
|
||||||
w_area[0].scrollTop = scroll_y;
|
w_area[0].scrollTop = scroll_y;
|
||||||
|
@ -1389,7 +1409,7 @@ function svg_edit_setup() {
|
||||||
$('#rect_rx').SpinButton({ min: 0, max: 1000, step: 1, callback: changeRectRadius });
|
$('#rect_rx').SpinButton({ min: 0, max: 1000, step: 1, callback: changeRectRadius });
|
||||||
$('#stroke_width').SpinButton({ min: 0, max: 99, step: 1, callback: changeStrokeWidth });
|
$('#stroke_width').SpinButton({ min: 0, max: 99, step: 1, callback: changeStrokeWidth });
|
||||||
$('#angle').SpinButton({ min: -180, max: 180, step: 5, callback: changeRotationAngle });
|
$('#angle').SpinButton({ min: -180, max: 180, step: 5, callback: changeRotationAngle });
|
||||||
$('#zoom').SpinButton({ min: 10, max: 10000, step: 50, callback: changeZoom });
|
$('#zoom').SpinButton({ min: 0.1, max: 10000, step: 50, stepfunc: stepZoom, callback: changeZoom });
|
||||||
|
|
||||||
svgCanvas.setCustomHandlers = function(opts) {
|
svgCanvas.setCustomHandlers = function(opts) {
|
||||||
if(opts.open) {
|
if(opts.open) {
|
||||||
|
|
Loading…
Reference in New Issue