Skip to content

Instantly share code, notes, and snippets.

View abrjagad's full-sized avatar

Abraham Jagadeesh abrjagad

View GitHub Profile
@abrjagad
abrjagad / Close Mobile Menu on click outside
Created February 11, 2014 07:57
Close Mobile Menu on click outside, used when doing responsive page, for small screens
$(".small-menu").click(function (event) {
event.stopPropagation();
$(".fixed-nav-header").fadeToggle();
})
$(document).click(function () {
if ($(".fixed-nav-header").is(":visible")) {
$(".fixed-nav-header").fadeOut();
}
});
@abrjagad
abrjagad / Jquery Validation
Created February 11, 2014 08:02
Common Jquery validation plugin Method
//Global validation message
jQuery.extend(jQuery.validator.messages, {
required: "تعبئة هذا الحقل إجباري"
});
// New Method like email; this one to check Emirates Id
jQuery.validator.addMethod('emiratesId', function (value) {
return /^\d{3}-?\d{4}-?\d{7}-?\d{1}$/.test(value);
}, 'Please enter a valid Emirates ID number');
// common initialisation
@abrjagad
abrjagad / Invocation with the apply() and call() methods
Created February 13, 2014 08:54
Explaining Call and Apply; basically call and apply Invoke a Function with the given set of arguments
//Invocation with the apply() and call() methods
// create a plain function
function juggle() {
var result = 0;
for (var n = 0; n < arguments.length; n++) {
result += arguments[n];
}
//this.result = result;
console.log(result)
//Invocation as a constructor
//Ninja is a Constructor
//should start with Capital letter
//creates a emply object{}
function Ninja() {
this.skulk = function () {
return this;
//Invocation as a function
//this refers to window
function creep() {
return this;
}
console.log(creep() === window, "Creeping in the window");
@abrjagad
abrjagad / css browser hacks
Created March 16, 2014 05:12
css browser hacks
@media screen and (-webkit-min-device-pixel-ratio:0) { // for chrome
}
@abrjagad
abrjagad / allow only one check box checked in group
Created March 18, 2014 08:20
allow only one check box checked in group
$(".accord_table").on("change",'.currentTable :checkbox',function(event){
var group = $(this).closest(".currentTable").find(":checkbox");
group.not($(this)).removeProp("checked");
})
@abrjagad
abrjagad / example for call and apply
Created April 27, 2014 13:17
example for call and apply
var log_this_and_message = function (message) {
console.log(message+this.name);
};
var thing = {
name: 'Big Hairy Thing'
};
log_this_and_message.call(thing, 'Hello!');
function upTo(element, myclassName) {
do {
element = element.parentNode;
if (element.className.indexOf(myclassName) > -1) {
return element;
}
} while (element);
return null;
}
upTo(this, "level-dt");
$(document).keydown(function (e) {
if (e.keyCode == 27)
{ $(".box_tube,.over_wrapper").fadeOut(500); }
});