Skip to content

Instantly share code, notes, and snippets.

@advitum
advitum / Lingering Hover.js
Last active September 28, 2016 12:21
You know how it is sometimes very hard to use a multi-level website navigation because it immediately closes when you accidentally move your mouse out of the navigation element and you have to start over? This script just adds a "lingering" class to the element, so your navigation can wait half a second before closing again.
$element.on('mouseenter', function(event) {
window.clearTimeout($(this).data('hover-timeout'));
$(this).addClass('hover').siblings('.hover').removeClass('hover');
}).on('mouseleave', function(event) {
(function($element) {
$element.data('hover-timeout', window.setTimeout(function() {
$element.removeClass('hover');
}, 500));
})($(this));
});
@advitum
advitum / Mixed Compass Mixins.scss
Last active November 2, 2016 09:44
Just some random useful Compass mixins I have written and collected over the time.
// Proper clearfix without overflow:hidden
@mixin clearfix {
&:after {
content: "";
width: 100%;
height: 0;
display: block;
clear: both;
}
}
@advitum
advitum / datepicker.js
Created September 7, 2015 12:15
Very simple datepicker using jQuery.
function Datepicker($input) {
var datepicker = this;
datepicker.$input = $input;
$input.on('click', function(event) {
event.stopPropagation();
}).on('focus', function() {
datepicker.open();
});
@advitum
advitum / cookiePolicy.js
Last active August 29, 2015 14:26
Alert the user that this website is using cookies.
(function(messageContent) {
var cookieName = 'cookiePolicyHide';
function hideMessage() {
message.parentNode.removeChild(message);
document.cookie = cookieName + '=1;path=/';
}
function messageHidden() {
var cookies = document.cookie.split(';');
for(var index = 0; index < cookies.length; index++) {
while(cookies[index].charAt(0) === ' ') {
@advitum
advitum / createSvgElement.js
Created July 24, 2015 14:09
Creating SVG elements with correct namespace.
function createSvgElement(tag, attributes) {
var element = document.createElementNS('http://www.w3.org/2000/svg', tag);
for(var k in attributes) {
element.setAttribute(k, attributes[k]);
}
return element;
}
@advitum
advitum / home.php
Created February 9, 2015 09:21
Display the pages content on a WP custom home-page.
<?php
global $post;
$page = get_option('page_for_posts');
$post = get_page($page);
setup_postdata($post);
?>
@advitum
advitum / grid.scss
Last active August 29, 2015 14:07
Fluid SCSS Grid
$gridColumnCount: 12;
$gridGutterWidth: 40px;
$gridMaxWidth: 1400px;
@mixin clearfix {
&::after {
clear: both;
content: "";
display: block;
height: 0px;
@advitum
advitum / cake-backend.markdown
Last active August 29, 2015 14:07
Quick backend in CakePHP

Add a quick backend to CakePHP

Add to config/core.php:

<?php
Configure::write('Routing.prefixes', array('admin'));
@advitum
advitum / google-map.js
Last active August 29, 2015 14:05
How to display a google map.
//http://maps.google.com/maps/api/js?sensor=false
var position = [xxx, xxx];
$('#map').each(function() {
var map;
var latlng = new google.maps.LatLng(position[0], position[1]);
var center = new google.maps.LatLng(position[0], position[1]);
map = new google.maps.Map($(this).get(0), {
@advitum
advitum / grid.scss
Last active August 29, 2015 14:04
SCSS grid system using box-sizing
$columnCount: 12;
$columnWidth: 64px;
$gutterWidth: 20px;
@mixin clear {
&::after {
content: "";
width: 100%;
height: 0px;
display: block;