Skip to content

Instantly share code, notes, and snippets.

@jayde
jayde / Check for Empty Select
Created July 4, 2013 16:37
Check to see if a <select> has an empty selection/no value.
// Check to see if a <select> has an empty selection/no value
$.fn.checkEmptySelection = function() {
var emptyClass = 'noselection';
$(this).each(function() {
if( $(this).val() == emptySelection ) {
$(this).addClass(emptyClass);
}
});
@jayde
jayde / Numbers Only
Created July 4, 2013 16:34
Makes sure that <input type="number"> only accepts numbers and not letters.
// make sure that input type="number" only accepts numbers
$.fn.allowNumbersOnly = function() {
$(this).keydown(function (event) {
var num = event.keyCode;
if ((num > 95 && num < 106) || (num > 36 && num < 41) || num == 9) {
return;
}
if (event.shiftKey || event.ctrlKey || event.altKey) {
event.preventDefault();
} else if (num != 8 && num != 46 && num != 109 && num != 110 && num != 188 && num != 189 && num != 190) {
@jayde
jayde / PHP Password Protect Website
Created July 4, 2013 16:32
PHP Basic Site Authentication / Password Protect
<?
header("Content-type: text/html; charset=utf-8");
if(empty($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm=""');
header('HTTP/1.0 401 Unauthorized');
echo 'Login and Password Required';
exit;
} else {
echo "Username: ".$_SERVER['PHP_AUTH_USER']."<br>";
echo "Password: ".$_SERVER['PHP_AUTH_PW']."<p>";
@jayde
jayde / Isolated Scroll
Created June 12, 2013 01:24
Lock body scroll bar while scrolling div
// url: http://stackoverflow.com/questions/7600454/how-to-prevent-page-scrolling-when-scrolling-a-div-element
// function
$.fn.isolatedScroll = function() {
this.bind('mousewheel DOMMouseScroll', function (e) {
var delta = e.wheelDelta || (e.originalEvent && e.originalEvent.wheelDelta) || -e.detail,
bottomOverflow = this.scrollTop + $(this).outerHeight() - this.scrollHeight >= 0,
topOverflow = this.scrollTop <= 0;
if ((delta < 0 && bottomOverflow) || (delta > 0 && topOverflow)) {