Skip to content

Instantly share code, notes, and snippets.

View matijs's full-sized avatar
:dependabot:
Scouting turtles

matijs matijs

:dependabot:
Scouting turtles
View GitHub Profile
@matijs
matijs / postforms.js
Last active August 29, 2015 13:57 — forked from adactio/postforms.js
/*
Show a progress element for any form submission via POST.
Prevent the form element from being submitted twice.
*/
(function ( win, doc ) {
'use strict';
if ( !win.addEventListener ) {
// doesn't cut the mustard.
return;
}

Keybase proof

I hereby claim:

  • I am matijs on github.
  • I am matijs (https://keybase.io/matijs) on keybase.
  • I have a public key whose fingerprint is F561 2602 AC9A 189A 0894 19D2 1D57 5FD0 310D EF84

To claim this, I am signing this object:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Overlay modals</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="main.css">
</head>
<body>
<div class="overlay align-top">
@matijs
matijs / hasTransforms.js
Created August 6, 2014 13:26
feature detect css transforms
var hasTransforms = (function() {
var propNames = ["transform", "MozTransform", "webkitTransform", "msTransform"];
var i = 0;
var length = propNames.length;
for (; i < length; i++) {
if (typeof document.documentElement.style[propNames[i]] === "string") return true;
}
return false;
}());
/*
* How to get the scrolling element in charge of scrolling the viewport:
*
* - in Quirks mode the scrolling element is the "body"
* - in Standard mode the scrolling element is the "documentElement"
*
* webkit based browsers always use the "body" element disrespectfull of the specifications:
* http://dev.w3.org/csswg/cssom-view/#dom-element-scrolltop
*/
function getScrollingElement() {
@matijs
matijs / click-handler.js
Last active August 29, 2015 14:09
jQuery-based method for handling clicks declared with a data-attribute
$(function() {
'use strict';
// generic click handler
$(document).on('click', '[data-handler]', function(event) {
var handler = this.getAttribute('data-handler');
// honour default behaviour when using modifier keys when clicking
// for example:
// cmd + click / ctrl + click opens a link in a new tab
// shift + click opens a link in a new window
if (this.tagName === 'A' && (event.metaKey || event.ctrlKey || event.shiftKey)) {
@matijs
matijs / enhancer.js
Created November 18, 2014 08:57
jQuery-based enhancing of components / elements declared with a data-attribute
$(function() {
'use strict';
// kick off js enhancements
$('[data-enhancer]').each(function() {
var enhancer = this.getAttribute('data-enhancer');
if (enhancers && typeof enhancers[enhancer] === 'function') {
enhancers[enhancer].call(this);
}
else {
if (window.console && typeof console.log === 'function') {
@matijs
matijs / loadCSS.js
Created February 23, 2015 11:28
load CSS using JS
function loadCSS(href, options){
'use strict';
options = options || {};
var styleSheet = document.createElement('link');
var ref = options.before || document.getElementsByTagName('script')[0];
styleSheet.media = 'not all';
styleSheet.rel = 'stylesheet';
styleSheet.href = href;
styleSheet.onload = function () {
styleSheet.onload = null; // only run once
@matijs
matijs / slow_server.py
Created February 25, 2015 13:28
Enhanced Python SimpleHTTPServer to slowly serve a specific mimetypes
"""Simple HTTP Server.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
"""
__version__ = "0.6"
<p>
<a href="#" class="button">Foo Bar</a>
<button type="button" class="button">Baz Quux</button>
</p>