Last active
February 3, 2019 19:52
-
-
Save Kcko/f1402dc9b1bdf91bb77d to your computer and use it in GitHub Desktop.
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
/* Calendar - step 3 | |
---------------------------------------------------------------------------------------------------- */ | |
function Calendar(el) | |
{ | |
this.el = $(el); | |
this.header = $('thead', this.el); | |
this.body = $('tbody', this.el); | |
this.open = function() { | |
this.el.removeClass().addClass('open calendar'); | |
this.showBody(); | |
}; | |
this.close = function() { | |
this.el.removeClass().addClass('calendar'); | |
this.hideBody(); | |
}; | |
this.showBody = function() { | |
this.body.show(); | |
}; | |
this.hideBody = function() { | |
this.body.hide(); | |
}; | |
this.toggle = function() { | |
this.body.is(':visible') ? this.close() : this.open(); | |
}; | |
this.selectDate = function(date) { | |
this.header.find('th').text(date); | |
}; | |
} | |
// var calendar = { | |
// init: function(el) | |
// { | |
// this.el = $(el); | |
// this.header = $('thead', this.el); | |
// this.body = $('tbody', this.el); | |
// }, | |
// open: function() { | |
// this.header.removeClass().addClass('open'); | |
// this.showBody(); | |
// }, | |
// close: function() { | |
// this.header.removeClass(); | |
// this.hideBody(); | |
// }, | |
// showBody: function() { | |
// this.body.show(); | |
// }, | |
// hideBody: function() { | |
// this.body.hide(); | |
// } | |
// }; | |
var calendar = new Calendar('#calendar'); | |
calendar.header.click(function(){ | |
calendar.toggle(); | |
}); | |
calendar.body.find('td.num').click(function(){ | |
calendar.selectDate($(this).data('date')); | |
}); |
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
/* Mobile version, MENU | |
---------------------------------------------------------------------------------------------------- */ | |
var hamburger = { | |
init: function(el) { | |
this.elements = {}; | |
this.elements.el = $(el); | |
this.elements.header = $('#header-mobile'); | |
this.elements.closeButton = $('.hamburger-close'); | |
}, | |
open: function(e) { | |
this.elements.header.fadeIn(); | |
e.preventDefault(); | |
}, | |
close: function(e) { | |
this.elements.header.fadeOut(); | |
e.preventDefault(); | |
}, | |
getElement: function(el) | |
{ | |
return this.elements[el]; | |
} | |
}; | |
// init | |
hamburger.init('.hamburger'); | |
// open | |
hamburger.getElement('el').click(function(e){ | |
hamburger.open(e); | |
$('#bg-overlay').show(); | |
}); | |
// close | |
hamburger.getElement('closeButton').click(function(e){ | |
hamburger.close(e); | |
$('#bg-overlay').hide(); | |
}); | |
$(document).click(function(e){ | |
var $hamburgerLink = $('a.hamburger .icon-11'); | |
var $mobileNav = $('.navigation--mobile'); | |
if ($hamburgerLink.is(e.target)) | |
{ | |
// nic | |
} | |
else if (!$mobileNav.is(e.target) | |
&& $mobileNav.has(e.target).length === 0) | |
{ | |
if ($('#bg-overlay').is(':visible') && $('#header-mobile').is(':visible')) | |
{ | |
$('#bg-overlay').hide(); | |
hamburger.close(e); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment