Skip to content

Instantly share code, notes, and snippets.

@06b
06b / <a href="#"> page jump prevention
Created August 20, 2012 14:07
Prevent sending the user back to the top of the page when using hash(#) within the anchor tag
$('a[href$="#"]').on("click", function(e) {
e.preventDefault(); // to remove # from address bar
});
@06b
06b / Input autocapitalize='off' script
Created September 4, 2012 02:21
Some mobile browsers autocapitalize inputs, This applies the autocapitalize='off' option to all inputs with a specific class, so it won't autocapitalize them.
<script>
//Description: Some mobile browsers autocapitalize inputs, This applies the autocapitalize='off' option to all inputs with a specific class, so it won't autocapitalize them.
//Author: Andrew Nesbitt
$(document).ready(function(){
// disable autocapitalize on .url, .email fields
unautocapitalize('url');
unautocapitalize('email');
});
@06b
06b / Image 404 hide
Created September 21, 2012 13:21 — forked from Mansyn/Image 404 hide
Hide images that don't load (404)
$(document).ready(function () {
// Hide any image that 404
$('img').bind('error', function () {
$(this).hide();
});
});
@06b
06b / Kendo UI Menu direction change
Created October 18, 2012 16:46
The Kendo Menu does not present the .Direction() method, in order to change the direction of the menu use this script
<script>
$(document).ready(function () {
var original = $("#kMenu").clone(true);
var menu = $("#kMenu"),
clone = original.clone(true);
menu.replaceWith(clone);
var initMenu = function () {
@06b
06b / Override Unobtrusive Client Side Validation
Created October 18, 2012 19:40
Override the jQuery validation settings in ASP.NET MVC 3 to validate hidden input elements
<script>
$(document).ready(function () {
$(function () {
var settings = $.data($(‘form’)[0], ‘validator’).settings;
settings.ignore = “”
settings.onkeyup = false;
settings.onfocusout = false;
});
});
</script>
@06b
06b / Time = Total Time in Seconds.js
Created November 5, 2012 21:46
Covert seconds to hours, minutes and seconds
// Time = Total Time in Seconds
// Minutes and seconds
var mins = ~~(time / 60);
var secs = time % 60;
// Hours, minutes and seconds
var hrs = ~~ (time / 3600);
var mins = ~~ ((time % 3600) / 60);
var secs = time % 60;
@06b
06b / jquery.requiredfields.js
Created November 12, 2012 14:49
Detect inputs & textareas that use the required data annotation, attaches an asterisk to labels associated with them & replaces the legend indicating the asterisk's meaning.
/*
* jquery.requiredfields.js
* Copyright (c) 2012 Adrian D. Alvarez
* Licensed under the MIT, GPL licenses.
*/
(function ($) {
var requiredlegend = "Essential information is marked with an asterisk (<abbr title='Required' class='required'>*</abbr>)";
var requiredlegendset = false;
@06b
06b / unwanted.focus.js
Created November 14, 2012 14:57
Removed Unwanted focus styles from mouse events, but keeps them for tabbed navigation.
// Unobtrusive JavaScript: Remove Unwanted Link Border Outlines
// http://www.mikesmullin.com/2006/06/16/removing-the-dotted-outline-from-focused-links
var runOnLoad = [];
window.onload = function () {
'use strict';
for (var i = 0; i < runOnLoad.length; i++) {
runOnLoad[i]();
}
};
@06b
06b / PutCursorAtEnd.js
Created March 14, 2013 17:55
Put the cursor at the end of a textbox
// jQuery plugin: PutCursorAtEnd 1.0
// http://plugins.jquery.com/project/PutCursorAtEnd
// by teedyay
//
// Puts the cursor at the end of a textbox/ textarea
// codesnippet: 691e18b1-f4f9-41b4-8fe8-bc8ee51b48d4
(function($)
{
jQuery.fn.putCursorAtEnd = function()
{
@06b
06b / QueryString.js
Last active August 29, 2015 13:56
Get Query String Values
// http://stackoverflow.com/a/3855394
var qs = (function(a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i)
{
var p=a[i].split('=');
if (p.length != 2) continue;
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}