Skip to content

Instantly share code, notes, and snippets.

@Loac-fr
Loac-fr / hamburger-anim.scss
Last active August 29, 2015 14:16
Hamburger menu markup
<div id="toggle" class="">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
</div>
<!-- just toggle the "on" class with js :) -->
@Loac-fr
Loac-fr / youmightnotneedjquery_examples.js
Created April 20, 2015 09:32
Lea Verou's add class without jQuery
// http://youmightnotneedjquery.com/
// Returns first element that matches CSS selector {expr}.
// Querying can optionally be restricted to {container}’s descendants
function $(expr, container) {
return typeof expr === "string"? (container || document).querySelector(expr) : expr || null;
}
// Returns all elements that match CSS selector {expr} as an array.
// Querying can optionally be restricted to {container}’s descendants
function $$(expr, container) {
@Loac-fr
Loac-fr / timing.js
Created June 28, 2015 13:51
Measuring task time in Js
console.time("foo");
// do stufff
console.timeEnd("foo");
// http://codepen.io/KK4OXJ/pen/eNyRYr
@Loac-fr
Loac-fr / oncssanimationend.js
Created June 29, 2015 08:48
detect + callback on css animation end
/*
By Osvaldas Valutis, www.osvaldas.info
Available for use under the MIT License
@example :
var item = document.querySelector( '.item' );
item.classList.add( 'disappear' );
item.onCSSAnimationEnd( function()
{
item.parentNode.removeChild( item );
});
@Loac-fr
Loac-fr / wp_excerpt_limit.php
Created July 29, 2015 15:40
Limit length of the excerpt in Wordpress
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
@Loac-fr
Loac-fr / wp_split_gallery.php
Created July 30, 2015 10:57
Wordpress - Split gallery from post content
@Loac-fr
Loac-fr / lazyload_custom.js
Created January 11, 2016 13:18
Lazy load function - adapted from blazy
function loadImages(container){
var $ctn = container,
els = $ctn.find('.tile-background'),
options = {};
options.src = 'data-src';
options.errorClass = 'lazyload--error';
options.successClass = 'lazyload--success';
els.each(function(index){
@Loac-fr
Loac-fr / cf7_checkbox.php
Last active March 29, 2016 14:54
Modify Contact form 7 plugin checkbox behavior
<?php
// to drop in functions.php
// changes occur at line 120
add_action( 'wpcf7_init', 'wpcf7_add_shortcode_checkbox_alt' );
function wpcf7_add_shortcode_checkbox_alt() {
wpcf7_add_shortcode( array( 'checkbox', 'checkbox*', 'radio' ),
'my_checkbox', true );
@Loac-fr
Loac-fr / touchmouse.js
Created February 21, 2017 12:46
Touch and mouse "hack"
// from http://corlan.org/2012/02/15/quick-hack-to-deal-with-touch-and-mouse-events/
// not tested
function init() {
var el = document.getElementById('myDiv');
el.addEventListener('mousemove', onMouseMove);
el.addEventListener('touchmove', onTouchMove);
}
function onMouseMove(e) {
@Loac-fr
Loac-fr / object_fit_polyfill.js
Created June 15, 2017 07:41
IE object-fit "polyfill"
// https://medium.com/@primozcigler/neat-trick-for-css-object-fit-fallback-on-edge-and-other-browsers-afbc53bbb2c3
if ( ! Modernizr.objectfit ) {
$('.post__image-container').each(function () {
var $container = $(this),
imgUrl = $container.find('img').prop('src');
if (imgUrl) {
$container
.css('backgroundImage', 'url(' + imgUrl + ')')
.addClass('compat-object-fit');