extending implementation

10.3.x-maintenance
cTn 2014-01-22 17:05:34 +01:00
parent 3d5e333c6d
commit 98c587c3d9
1 changed files with 94 additions and 91 deletions

185
main.js
View File

@ -170,100 +170,103 @@ function add_custom_spinners() {
$('input[type="number"]').each(function() {
var input = $(this);
var isInt = true;
if (input.prop('step') == '') {
isInt = true;
} else {
if (input.prop('step').indexOf('.') == -1) {
// only add new spinner if one doesn't already exist
if (!input.next().hasClass('spinner')) {
var isInt = true;
if (input.prop('step') == '') {
isInt = true;
} else {
isInt = false;
if (input.prop('step').indexOf('.') == -1) {
isInt = true;
} else {
isInt = false;
}
}
// make space for spinner
input.width(input.width() - 16);
// add spinner
input.after(spinner_element);
// get spinner refference
var spinner = input.next();
// bind UI hooks to spinner
$('.up', spinner).click(function() {
up();
});
$('.up', spinner).mousedown(function() {
GUI.timeout_add('spinner', function() {
GUI.interval_add('spinner', function() {
up();
}, 100, true);
}, 250);
});
$('.up', spinner).mouseup(function() {
GUI.timeout_remove('spinner');
GUI.interval_remove('spinner');
});
$('.up', spinner).mouseleave(function() {
GUI.timeout_remove('spinner');
GUI.interval_remove('spinner');
});
$('.down', spinner).click(function() {
down();
});
$('.down', spinner).mousedown(function() {
GUI.timeout_add('spinner', function() {
GUI.interval_add('spinner', function() {
down();
}, 100, true);
}, 250);
});
$('.down', spinner).mouseup(function() {
GUI.timeout_remove('spinner');
GUI.interval_remove('spinner');
});
$('.down', spinner).mouseleave(function() {
GUI.timeout_remove('spinner');
GUI.interval_remove('spinner');
});
var up = function() {
if (isInt) {
var current_value = parseInt(input.val());
input.val(current_value + 1);
} else {
var current_value = parseFloat(input.val());
var step = parseFloat(input.prop('step'));
var step_decimals = input.prop('step').length - 2;
input.val((current_value + step).toFixed(step_decimals));
}
input.change();
};
var down = function() {
if (isInt) {
var current_value = parseInt(input.val());
input.val(current_value - 1);
} else {
var current_value = parseFloat(input.val());
var step = parseFloat(input.prop('step'));
var step_decimals = input.prop('step').length - 2;
input.val((current_value - step).toFixed(step_decimals));
}
input.change();
};
}
// make space for spinner
input.width(input.width() - 16);
// add spinner
input.after(spinner_element);
// get spinner refference
var spinner = input.next();
// bind UI hooks to spinner
$('.up', spinner).click(function() {
up();
});
$('.up', spinner).mousedown(function() {
GUI.timeout_add('spinner', function() {
GUI.interval_add('spinner', function() {
up();
}, 100, true);
}, 250);
});
$('.up', spinner).mouseup(function() {
GUI.timeout_remove('spinner');
GUI.interval_remove('spinner');
});
$('.up', spinner).mouseleave(function() {
GUI.timeout_remove('spinner');
GUI.interval_remove('spinner');
});
$('.down', spinner).click(function() {
down();
});
$('.down', spinner).mousedown(function() {
GUI.timeout_add('spinner', function() {
GUI.interval_add('spinner', function() {
down();
}, 100, true);
}, 250);
});
$('.down', spinner).mouseup(function() {
GUI.timeout_remove('spinner');
GUI.interval_remove('spinner');
});
$('.down', spinner).mouseleave(function() {
GUI.timeout_remove('spinner');
GUI.interval_remove('spinner');
});
var up = function() {
if (isInt) {
var current_value = parseInt(input.val());
input.val(current_value + 1);
} else {
var current_value = parseFloat(input.val());
var step = parseFloat(input.prop('step'));
var step_decimals = input.prop('step').length - 2;
input.val((current_value + step).toFixed(step_decimals));
}
input.change();
};
var down = function() {
if (isInt) {
var current_value = parseInt(input.val());
input.val(current_value - 1);
} else {
var current_value = parseFloat(input.val());
var step = parseFloat(input.prop('step'));
var step_decimals = input.prop('step').length - 2;
input.val((current_value - step).toFixed(step_decimals));
}
input.change();
};
});
}