Skip to content

Instantly share code, notes, and snippets.

View mateuszkocz's full-sized avatar
✌️

Mateusz Kocz mateuszkocz

✌️
View GitHub Profile
@mateuszkocz
mateuszkocz / matchMedia.js
Created September 27, 2013 18:43
Checks the media query screen size.
if (window.matchMedia("(min-width: 40em)").matches) {
/* do something here, load supplementary content or something. */
}
document.addEventListener("touchstart", function(){}, true)
.btn {
-webkit-tap-highlight-color: rgba(0,0,0,0);
&:active {
/* some props */
}
}
// Simple execution
window["functionName"](arguments);
// Nested exection.
window["My"]["Namespace"]["functionName"](arguments);
// Helper function.
function executeFunctionByName(functionName, context /*, args */) {
var args = Array.prototype.slice.call(arguments).splice(2);
var namespaces = functionName.split(".");
@mateuszkocz
mateuszkocz / tables.js
Created September 15, 2013 16:19
Create tables dynamically.
var table = document.createElement('table'),
tbody = document.createElement('tbody'),
i, rowcount;
table.appendChild(tbody);
for (i = 0; i <= 9; i++) {
rowcount = i + 1;
tbody.insertRow(i);
tbody.rows[i].insertCell(0);
@mateuszkocz
mateuszkocz / support.js
Created September 3, 2013 05:19
Supports for CSS properties in JavaScript. Source: http://ryanmorr.com/detecting-css-style-support
(function(win){
"use strict";
var el = win.document.createElement('div'),
camelRe = /-([a-z]|[0-9])/ig,
cache = {},
support,
camel,
key;
var start = null;
var d = document.getElementById("SomeElementYouWantToAnimate");
function step(timestamp) {
var progress;
if (start === null) start = timestamp;
progress = timestamp - start;
d.style.left = Math.min(progress/10, 200) + "px";
if (progress < 2000) {
@iterations: 6;
.h(@index) when (@index > 0) {
h@{index} {
font-size: 72px - @index*10;
}
.h(@index - 1);
}
.h(0) {}
.h(@iterations);
var mergeTo = [4,5,6];
var mergeFrom = [7,8,9];
Array.prototype.push.apply(mergeTo, mergeFrom);
mergeTo; // is: [4, 5, 6, 7, 8, 9]
@mateuszkocz
mateuszkocz / canvas-to-image.js
Created August 7, 2013 19:06
Canvas to image
// Set canvas as an image's source.
var data = canvas.toDataURL();
img.src = data; // img implied
// Create image.
var jpg = canvas.toDataURL('image/jpeg',.7); // .7 is compression
@mateuszkocz
mateuszkocz / drag-drop.js
Created August 6, 2013 17:14
Drag & Drop, Canvas resize and upload a file. Source: http://davidwalsh.name/resize-image-canvas
var target = document.getElementById("drop-target");
target.addEventListener("dragover", function(e){e.preventDefault();}, true);
target.addEventListener("drop", function(e){
e.preventDefault();
loadImage(e.dataTransfer.files[0]);
}, true);