Skip to content

Instantly share code, notes, and snippets.

View dutchcelt's full-sized avatar

Egor Kloos dutchcelt

View GitHub Profile
@dutchcelt
dutchcelt / column-containers.css
Last active September 15, 2015 12:07
blocks in columns
/**
* Example:
* http://jsfiddle.net/dutchcelt/e4ak3gs6/1/
*/
.column-container {
-webkit-column-count: 3;
}
.column-item {
display: inline-block;
@dutchcelt
dutchcelt / emptyModule.js
Last active February 11, 2024 20:32
AMD module
/**
* AMD module
*/
!function( name, factory ){
if ( typeof define == 'function' && typeof define.amd == 'object' ) {
// Add dependencies here
define([ 'jquery', 'dutchcelt/Dater' ], factory);
} else {
// Not called as an AMD module?
@dutchcelt
dutchcelt / mustard
Created August 18, 2015 07:07
Cut the mustard
if('querySelector' in document
&& 'localStorage' in window
&& 'addEventListener' in window) {
// bootstrap the javascript application
}
@dutchcelt
dutchcelt / getPseudoContent
Created July 15, 2015 19:07
Read the content of a pseudo element
window.getComputedStyle(document.querySelector('#element'),':after').getPropertyValue('content')
@dutchcelt
dutchcelt / listToArray
Last active February 11, 2024 20:36
Convert node lists to an Array
/**
* Convert a list of nodes or arguments to an array.
* @param {object} list - Reference to a node or arguments.
*/
var listToArray = function( list ) {
return [].map.call( list, function(element) {
return element;
});
};
@dutchcelt
dutchcelt / dotNotationStringToObject
Created October 31, 2014 08:08
Convert a string to an object and add its value
/**
* Convert a string to an object and add its value
* "formItem.address" -> {"formItem":{"address":"address value"}}
* @param {string} dotNotationString - A string that contains dots that whould map to an object key.
* @param {string} val - Value to be added to the key
*/
var dotNotationStringToObject = function( dotNotationString, val ){
var str = "{";
var strEnd = "}";
var obj = {};
function extend(){
for(var i=1; i<arguments.length; i++) {
for(var key in arguments[i]){
if(arguments[i].hasOwnProperty(key)) {
arguments[0][key] = arguments[i][key];
}
}
}
return arguments[0];
}
@dutchcelt
dutchcelt / polyfill_object-create.js
Last active February 11, 2024 20:37
Object_Create
// Object.create
if (typeof Object.create != 'function') {
(function () {
var F = function () {};
Object.create = function (o) {
if (arguments.length > 1) { throw Error('Second argument not supported');}
if (o === null) { throw Error('Cannot set a null [[Prototype]]');}
if (typeof o != 'object') { throw TypeError('Argument must be an object');}
F.prototype = o;
return new F();
@dutchcelt
dutchcelt / Hasher
Last active February 11, 2024 20:37
Hash location and stay put!
var hashThis = function( $elem, cb ){
var scrollLocation;
$( $elem ).on( "click", function( event ){
event.preventDefault();
scrollLocation = $( window ).scrollTop();
window.location.hash = $( event.target ).attr('href').substr(1);
});
$( window ).on( "hashchange", function( event ){
event.preventDefault();
$( window ).scrollTop( scrollLocation );
@dutchcelt
dutchcelt / Auto Column mixin
Last active February 11, 2024 20:37
Using LESS to create multiple columns with equal gutter and content widths.
.box-to-grid( @columns; @gutter-size: 2em ){
@responsiveColumn: ( 100 / @columns );
@columnAdjust: ( ( ( @columns - 1 ) * @gutter-size ) / @columns ) ;
vertical-align: top;
display: inline-block;
margin-left: @gutter-size;
width: calc( ~"@{responsiveColumn}% - @{columnAdjust}" ) ;
&:nth-of-type( @{columns}n+1 ){
margin-left: 0;
}