bootWork
by Edgar Martinez
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-uWxY/CJNBR+1zjPWmfnSnVxwRheevXITnMqoEIeG1LJrdI0GlVs/9cVSyPYXdcSF" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-kQtW33rZJAHjgefvhyyzcGF3C5TFyBQBA13V1RKPf4uH+bwyzQxZ6CmMZHmNBEfJ" crossorigin="anonymous"></script>
<div id='com'>
</div>
<b id="conta">0</b>
<button id='btn'>
DEMO
</button>
t4 e8
CSS
#com{
padding:10px
}
body{
padding:10px
}
JavaScript
(function() {
$.bootWork = {};
var idInput = 0;
var idRange= 0;
$.fn.inputFilter = function(inputFilter) {
return this.on("input keydown keyup mousedown mouseup select contextmenu drop", function() {
if (inputFilter(this.value)) {
this.oldValue = this.value;
this.oldSelectionStart = this.selectionStart;
this.oldSelectionEnd = this.selectionEnd;
} else if (this.hasOwnProperty("oldValue")) {
this.value = this.oldValue;
this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
} else {
this.value = "";
}
});
};
$.bootWork.funciones={};
$.bootWork.input = function(prop) {
idInput++;
var defaultInput = {
id: "bootWork_" + idInput,
readonly: false,
label: "Demo",
small: "",
placeholder:''
}
var config = $.extend(true, {}, defaultInput, prop);
var contenedor = $("<div/>");
contenedor.addClass("form-group");
var label = $("<label/>");
label.html(config.label);
label.attr("for", config.id);
var inputT = $("<input/>");
inputT.attr("type", 'text');
inputT.attr("id", config.id);
if(config.placeholder!=""){
inputT.attr("placeholder",config.placeholder);
}
inputT.addClass("c_" + config.id);
inputT.addClass("form-control");
if (config.readonly) {
inputT.prop("readonly", true);
}
contenedor.append(label);
contenedor.append(inputT);
if (config.small != "") {
var small = $("<small/>");
small.html(config.small);
small.addClass("form-text");
small.addClass("text-muted");
contenedor.append(small);
}
$.bootWork.funciones[config.id] = {};
$.bootWork.funciones[config.id].config = config;
$(document).on("mousemove","#" + config.id,function(){
var id = $(this).attr("id");
var config = $.bootWork.funciones[id].config;
if (config.onlyNumber) {
$(this).inputFilter(function(value)...