Skip to content

Instantly share code, notes, and snippets.

View phloe's full-sized avatar

Rasmus Fløe phloe

View GitHub Profile
@phloe
phloe / css
Created October 9, 2012 13:15
for placeholder-less lazyloading
.figure {
width: 25%;
float: left;
position: relative;
background-color: red;
margin: 0;
overflow: hidden;
}
.figure:before {
content: "";
@phloe
phloe / combine-layout.md
Last active July 27, 2020 07:23
combine-layout - float/inline-block layout technique

combine-layout

The following outlines a technique combining floating blocks and inline-blocks allowing for fairly interesting layouts without the need to use nested rows and avoids some problems when using pure floats.

The technique itself only uses three classnames:

  • combine-layout - defines the containing element.
  • break - starts a new row when in floating block context.
  • divide - starts off the inline-block context.
_amoeba(function ($, $$, _) {
var link = $("link[href$='base-static.css']");
if (link) {
link.el.href = link.el.href.replace("-static.css", ".css");
var viewport = $("meta[name='viewport']");
if (!viewport) {
viewport = _.create("meta", {name: "viewport"}, document.head, "top");
}
@phloe
phloe / Bake Cookies
Last active December 10, 2015 18:49
var bake_cookie = (function () {
function decode (string) {
return decodeURIComponent(
string.replace(/%2[1789A]/gi, function(d){
return String.fromCharCode(parseInt(d.slice(1), 16));
})
);
}
@phloe
phloe / srcoptions.md
Last active December 24, 2015 01:59
Responsive image syntax through a "srcoptions" attribute

TL;DR

<img src="/path/to/foo-320w-240h-1x.jpg" width="320" height="240"
    srcoptions="/path/to/foo-{width}-{height}-{dpr}.{format},
    320w 480w 640w, 1x 1.33x 2x, webp jpg"/>
  • DRY - Expose url pattern and avaliable options for images - not full urls - in markup. Browser picks best options - builds url.
  • Responsive images need CSS to get layout. Browser preloading is a pre-RWD optimization. Preloading doesn't make sense with upcoming postpone and lazyload attributes anyway.
  • Client Hints can't be used exclusively. Has server requirement and needs alt. way of handling CH - anyway - when server req. can't be met.
@phloe
phloe / drhtml.html
Last active December 30, 2015 00:09
DR-HTML
<dr-section headline="Prioriterede nyheder" muteheading>
<dr-layout span="12">
<dr-layoutcolumn span="8">
<dr-teaser span="8" imagespan="8" model="" />
</dr-layoutcolumn>
<dr-layoutcolumn span="4">
<dr-teaser span="4" imagespan="4" model="" />
<dr-teaser span="4" imagespan="4" model="" />
</dr-layoutcolumn>
</dr-layout>

A nice clean example of the revamped picture proposal:

<figure>
	<picture>
		<source media="(min-width: 45em)" srcset="large-1.jpg, large-2.jpg 2x">
		<source media="(min-width: 18em)" srcset="med-1.jpg, med-2.jpg 2x">
		<source srcset="small-1.jpg, small-2.jpg 2x">
		<img src="small-1.jpg" alt="" width="200" height="200">
	</picture>
@phloe
phloe / dr-battle-snippet.js
Last active August 29, 2015 14:00
Snippet to get live data from ESC DR Battle
(function (global, doc) {
// expose a function to recieve data via JSONP
global.getBattle = function getBattle (data) {
// calculate ranks of songs. ("questions" are songs)
var rankedData = rankData(data.reply.battle.questions);
// make the data more readable...
var sanetizedData = sanetizeData(rankedData);
// do stuff with sanetizedData here...

Proper separation of concerns

Let's say you need to add a button to a subscription form.

The naive pee-your-pants way

<button style="background-color: red; width: 200px;">Subscribe</button>
{
"articleHits": 25,
"totalHits": "25",
"articles": [
{
"origId": "5f9a0b76-8621-4605-a232-355082314ce2",
"imageId": null,
"title": "Dansk og svensk forsvar vil samarbejde",
"tags": [