Skip to content

Instantly share code, notes, and snippets.

View kieranstartup's full-sized avatar

Kieran Startup kieranstartup

View GitHub Profile
// Credit to https://gist.github.com/apapirovski/2580052
// Calculate luma (brightness) of a hexadecimal colour
// ---------------------------------------------------
// You can use this to calculate whether two colours
// are suitable to be used as a background and text
function hex2luma(hex) {
return (
(parseInt(hex.substring(0, 2), 16) * 299) +
(parseInt(hex.substring(2, 4), 16) * 587) +
@kieranstartup
kieranstartup / fix-slick-slider-outline.css
Created November 20, 2017 15:09
Hide slick slides when they have the attribute data-lazy which means they have no loaded yet and causes a FOUC with grey outline. This attribute is then removed once the image has loaded.
img[data-lazy]{
opacity: 0;
}
// This is useful for dumb single page WordPress webapps which contain multiple Custom Post Types on a single page and need to link
// i.e. smooth scroll to those sections on page load as you can't share URL's with hashes in them
var pathnameMatch;
var urlPathname = window.location.href;
var sanitized = urlPathname
.replace(/^http\:\/\//, '') // remove the leading http:// (temporarily)
.replace(/\/+/g, '/') // replace consecutive slashes with a single slash
.replace(/\/+$/, ''); // remove trailing slashes
urlPathname = 'http://' + sanitized;
@kieranstartup
kieranstartup / nicer-font-rendering.css
Created July 12, 2017 09:57
Render fonts nicer than they are by default in browsers
* {
text-shadow: 1px 1px 1px rgba(0,0,0,.004);
text-rendering: optimizeLegibility!important;
-webkit-font-smoothing: antialiased!important;
-webkit-tap-highlight-color: transparent;
}
@kieranstartup
kieranstartup / craft-cms-element-api-matrix-field-example.php
Last active April 10, 2017 17:10
Gist showing how to access matrix fields in craft cms element api
<?php
'api/faq.json' => [
'elementType' => 'Entry',
'criteria' => ['section' => 'faq'],
'transformer' => function(EntryModel $entry) {
// Array for storing your Matrix Fields
$arrayToStoreMatrixFields = [];
foreach ($entry->matrixFieldHandle as $block) {
switch ($block->type->handle) {
@kieranstartup
kieranstartup / apply-localstorage-class.js
Created August 22, 2016 21:02
Store a class from another page using localstorage and call it again on a specific template page
jQuery(document).ready(function() {
if (localStorage) {
// LocalStorage is supported!
var firstClass, secondClass, thirdClass;
//get the class of the div that's just been clicked
jQuery('.col-1-6').click(function() {
localStorage.clear();
@kieranstartup
kieranstartup / image-orientation-class.php
Created August 15, 2016 10:36
Add class to portrait or landscape image and container based on image dimensions. Works with ACF 'Image Array' setting.
<?php
$image = get_field('project_image');
if( !empty($image) ):
// thumbnail
$size = 'large';
$thumb = $image['sizes'][ $size ];
$width = $image['sizes'][ $size . '-width' ];
$height = $image['sizes'][ $size . '-height' ];
@kieranstartup
kieranstartup / remove-wordpress-emojis.php
Last active August 8, 2016 14:36
Remove WordPress Emoji's - place this code into functions.php
/**
* Disable Emoji Script From Being Loaded
*/
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
@kieranstartup
kieranstartup / skip-first-row-of-repeater-field.php
Created February 16, 2016 17:37
ACF skip first row of repeater field
<?php if(get_field('slides')): $i = 0; while(has_sub_field('slides')): $i++; if ($i != 1): ?>
<!-- Do Stuff Here -->
<?php endif; endwhile; endif; ?>
<!-- http://support.advancedcustomfields.com/forums/topic/repeater-skip-first-row/ -->