Skip to content

Instantly share code, notes, and snippets.

@Macagare
Macagare / gist:4160867
Created November 28, 2012 12:24
Jquery: Disable “Enter” key in forms
$("#form").keypress(function(e) {
if (e.which == 13) {
return false;
}
});
@Macagare
Macagare / gist:4160860
Created November 28, 2012 12:22
Jquery: Find is a checkbox is checked
// Find out if a single checkbox is checked or not.
// The function will returns true or false:
$('#checkBox').attr('checked');
@Macagare
Macagare / gist:4160859
Created November 28, 2012 12:22
Javascript: Prevent multiple submit of your form
$(document).ready(function() {
$('form').submit(function() {
if(typeof jQuery.data(this, "disabledOnSubmit") == 'undefined') {
jQuery.data(this, "disabledOnSubmit", { submited: true });
$('input[type=submit], input[type=button]', this).each(function() {
$(this).attr("disabled", "disabled");
});
return true;
}
else
@Macagare
Macagare / gist:4160856
Created November 28, 2012 12:21
Javascript: mooth scrolling to an anchor
$(document).ready(function() {
$("a.topLink").click(function() {
$("html, body").animate({
scrollTop: $($(this).attr("href")).offset().top + "px"
}, {
duration: 500,
easing: "swing"
});
return false;
});
@Macagare
Macagare / gist:4134400
Last active April 22, 2019 09:59
Javascript: Google Analytics Snipper + Google Analytics JS Logging
var _gaq = _gaq || [['_setAccount', 'UA-xxxxxxx-1'], ['_trackPageview']];
; (function ($, n, d, t, w, s, undefined) {
//Google Analytics Snipper
var g = d.createElement(t); g.type = 'text/javascript'; g.async = true;
g.src = ('https:' == d.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var b = d.getElementsByTagName(t)[0]; b.parentNode.insertBefore(g, b);
@Macagare
Macagare / session_test.cfm
Created November 22, 2012 13:14
Coldfusion: session test on multiple servers
<cfscript>
writeOutput("You are on server: " & cgi.local_host & "<br/>");
if( structKeyExists(url, "action") ) {
if ( url.action eq "new" ) {
createSessionTest();
}
} else {
if( not structKeyExists(session, "test") ){
writeOutput("Sorry, but there is no session test");
}
@Macagare
Macagare / gist:4129901
Created November 22, 2012 08:01
Javascript: Check if jquery exists
if (jQuery) {
// jQuery is loaded
} else {
// jQuery is not loaded
}
if (typeof jQuery == 'undefined') {
// jQuery is not loaded
} else {
// jQuery is loaded
@Macagare
Macagare / Normalize
Created November 21, 2012 10:16 — forked from cybermarinella/Normalize
CSS: Normalize
/*! normalize.css 2012-03-11T12:53 UTC - http://github.com/necolas/normalize.css */
/* =============================================================================
HTML5 display definitions
========================================================================== */
/*
* Corrects block display not defined in IE6/7/8/9 & FF3
*/
@Macagare
Macagare / gist:4123671
Created November 21, 2012 07:47
Javascript: Browser history back
<a href='#' onClick='window.history.go(-1);return false;'>BACK</a>
@Macagare
Macagare / gist:4099552
Created November 17, 2012 20:03
Javascript: Mobile detection
/**
* jQuery.browser.mobile (http://detectmobilebrowser.com/)
*
* jQuery.browser.mobile will be true if the browser is a mobile device
*
**/
(function(a){jQuery.browser.mobile=/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s