Skip to content

Instantly share code, notes, and snippets.

View KATT's full-sized avatar
🌴
On vacation

Alex / KATT KATT

🌴
On vacation
View GitHub Profile
@KATT
KATT / handlebar_helper_or.js
Created June 26, 2013 11:37
Handlebar helper `or` - grabs the first *truthy* argument that you send in and outputs it. See running example at http://cdpn.io/mxBjE
// Handlebar helper
Handlebars.registerHelper('or', function () {
var args = arguments;
for (var i in args) {
if (args[i]) {
return args[i];
}
}
return null;
@KATT
KATT / background-image2x.scss
Last active December 26, 2015 07:29
SCSS mixin for retina background images
@mixin background-image2x($image, $extension: 'png') {
$imageOrig: "#{$image}.#{$extension}";
$image2x: "#{$image}@2x.#{$extension}";
$width: image-width($imageOrig);
$height: image-height($imageOrig);
background-image: image-url($imageOrig);
@mixin responsive-full-width-image($image) {
@include box-sizing(content-box);
width: 100%;
padding-top: percentage(image-height($image) / image-width($image));
background-image: image-url($image);
background-repeat: no-repeat;
background-size: contain;
// declare in your variables-file
$relative-image-path = '../images/';
$retina = '(-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi)';
responsive-image($image) {
$path = $relative-image-path + $image;
$ext = extname($path);
@KATT
KATT / A-Pen-by-Alexander-Johansson.markdown
Created November 25, 2013 07:43
A Pen by Alexander Johansson.
@KATT
KATT / menu.coffee
Last active December 29, 2015 16:39
Find the bug.
class Menu
constructor: (@$el) ->
@isOpen = false
@$el.on 'click', '.menu-toggle', => @toggleMenu()
toggleMenu:
@$el.toggleClass 'open', !@isOpen
@isOpen = !@isOpen
<img src="images/header.png" data-srcorig="images/[email protected]">
@KATT
KATT / responsive-image.styl
Last active January 2, 2016 09:29
Uses CSS hack in order to make an element maintain the aspect ratio of supplied background-image. Demo: http://codepen.io/KATT/pen/yBrni
// Uses CSS hack in order to make an element maintain the aspect ratio of supplied background-image
// Latest version available @ https://gist.github.com/KATT/8283246
// Demo @ http://codepen.io/KATT/pen/yBrni
responsive-image($image, $width = false, $height = false) {
$external = match('^https?:\/\/', $image);
error('expect width and height on external images') if $external and !($width or $height)
unless $width and $height {
$size = image-size($image);
@KATT
KATT / US2TapFriendlyButton.h
Last active January 3, 2016 05:59
Makes UIButtons tap-friendly by making the hitbox a minimum of 44x44pt.
//
// US2TapFriendlyButton.h
//
// Created by Alexander Johansson on 14/01/2014.
//
//
#import <UIKit/UIKit.h>
@interface US2TapFriendlyButton : UIButton
background-x2image($image) {
$ext = extname($image);
$image2x = pathjoin(dirname($image), basename($image, $ext) + '@2x' + $ext);
background-image: url($public-image-path + $image);
@media $retina {
background-image: url($public-image-path + $image2x);
}
}