Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,623 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var gulp = require('gulp'); | ||
var rename = require('gulp-rename'); | ||
var uglify = require('gulp-uglify'); | ||
var uglifycss = require('gulp-uglifycss'); | ||
var pump = require('pump'); | ||
|
||
gulp.task('default', function (cb) { | ||
pump( | ||
[ | ||
gulp.src('src/**/*'), | ||
gulp.dest('dist'), | ||
gulp.src('src/**/*.js'), | ||
uglify(), | ||
rename(function (path) { | ||
path.basename += ".min"; | ||
}), | ||
gulp.dest('dist'), | ||
gulp.src('src/**/*.css'), | ||
uglifycss({ | ||
"maxLineLen": 80, | ||
"uglyComments": true | ||
}), | ||
rename(function (path) { | ||
path.basename += ".min"; | ||
}), | ||
gulp.dest('dist'), | ||
], | ||
cb | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.nice-number { | ||
display: inline-flex; | ||
justify-content: stretch; | ||
} | ||
|
||
.nice-number input { | ||
vertical-align: middle; | ||
-moz-appearance: textfield; | ||
box-sizing: content-box; | ||
margin: 0; | ||
text-align: center; | ||
} | ||
|
||
.nice-number input::-webkit-inner-spin-button, | ||
.nice-number input::-webkit-outer-spin-button { | ||
-webkit-appearance: none; | ||
margin: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
(function ($) { | ||
$.fn.niceNumber = function(options) { | ||
var settings = $.extend({ | ||
autoSize: true, | ||
autoSizeBuffer: 1, | ||
buttonDecrement: '-', | ||
buttonIncrement: "+", | ||
buttonPosition: 'around' | ||
}, options); | ||
|
||
return this.each(function(){ | ||
var currentInput = this; | ||
|
||
// Generate container | ||
var $inputContainer = $('<div/>',{ | ||
class: 'nice-number' | ||
}) | ||
.insertAfter(currentInput); | ||
|
||
// Generate interval (object so it is passed by reference) | ||
var interval = {}; | ||
|
||
// Generate buttons | ||
var $minusButton = $('<button/>') | ||
.attr('type', 'button') | ||
.html(settings.buttonDecrement) | ||
.on('mousedown mouseup mouseleave', function(event){ | ||
changeInterval(event.type, interval, function(){ | ||
currentInput.value--; | ||
}); | ||
|
||
// Trigger the input event here to avoid event spam | ||
if (event.type == 'mouseup' | ||
|| event.type == 'mouseleave') { | ||
|
||
$(currentInput).trigger('input'); | ||
} | ||
}); | ||
|
||
var $plusButton = $('<button/>') | ||
.attr('type', 'button') | ||
.html(settings.buttonIncrement) | ||
.on('mousedown mouseup mouseleave', function(event){ | ||
changeInterval(event.type, interval, function(){ | ||
currentInput.value++; | ||
}); | ||
|
||
// Trigger the input event here to avoid event spam | ||
if (event.type == 'mouseup' | ||
|| event.type == 'mouseleave') { | ||
|
||
$(currentInput).trigger('input'); | ||
} | ||
}); | ||
|
||
// Append elements | ||
switch (settings.buttonPosition) { | ||
case 'left': | ||
$minusButton.appendTo($inputContainer); | ||
$plusButton.appendTo($inputContainer); | ||
$(currentInput).appendTo($inputContainer); | ||
break; | ||
case 'right': | ||
$(currentInput).appendTo($inputContainer); | ||
$minusButton.appendTo($inputContainer); | ||
$plusButton.appendTo($inputContainer); | ||
break; | ||
case 'around': | ||
default: | ||
$minusButton.appendTo($inputContainer); | ||
$(currentInput).appendTo($inputContainer); | ||
$plusButton.appendTo($inputContainer); | ||
break; | ||
} | ||
|
||
// Nicely size input | ||
if (settings.autoSize) { | ||
$(currentInput).width($(currentInput).val().length+settings.autoSizeBuffer+"ch"); | ||
$(currentInput).on('keyup input',function(){ | ||
$(currentInput).animate({ | ||
'width': $(currentInput).val().length+settings.autoSizeBuffer+"ch" | ||
}, 200); | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
function changeInterval(eventType, interval, callback) { | ||
if (eventType == "mousedown") { | ||
interval.timeout = setTimeout(function(){ | ||
interval.actualInterval = setInterval(function(){ | ||
callback(); | ||
}, 100); | ||
}, 200); | ||
callback(); | ||
} else { | ||
if (interval.timeout) { | ||
clearTimeout(interval.timeout); | ||
} | ||
if (interval.actualInterval) { | ||
clearInterval(interval.actualInterval); | ||
} | ||
} | ||
} | ||
}(jQuery)); |
Oops, something went wrong.