Skip to content

Instantly share code, notes, and snippets.

View pazguille's full-sized avatar

Guille Paz pazguille

View GitHub Profile
@pazguille
pazguille / dabblet.html
Created November 4, 2013 13:40
Untitled
<!-- content to be placed inside <body>…</body> -->
@pazguille
pazguille / parseScript.js
Last active January 3, 2016 03:09
This function can be used to execute the JavaScript code received in the Ajax response.
function parseScript(code) {
var script = document.createElement('script');
// script.insertAdjacentText('beforeend', code); Don't work on FF
script.innerHTML = code;
document.body.appendChild(script);
}
var fileInput = document.getElementById('file');
fileInput.addEventListener('change', function () {
var img = document.createElement('img');
img.width = "200";
img.src = URL.createObjectURL(fileInput.files[0]);
document.body.appendChild(img);
});
@pazguille
pazguille / index.html
Last active August 29, 2015 13:57
Conditional comments
<!doctype html>
<!-- Conditional comment for mobile ie7 http://blogs.msdn.com/b/iemobile/ -->
<!--[if IEMobile 7 ]><html class="iem7"><![endif]-->
<!--[if IE 8]><html class="ie8 lt-ie10"><![endif]-->
<!--[if IE 9]><html class="ie9 lt-ie10"><![endif]-->
<!--[if gt IE 9]><!--><html><!--<![endif]-->
@pazguille
pazguille / index.html
Created March 21, 2014 18:08
Conditional Comments (jQuery or Zepto)
<!--[if lte IE 9]><script src="http://code.jquery.com/jquery-1.11.0.min.js"></script><![endif]-->
<!--[if gt IE 9]><!--><script src="http://cdnjs.cloudflare.com/ajax/libs/zepto/1.1.3/zepto.min.js"></script><!--<![endif]-->
(function (window, n) {
'use strict';
var storage = window.localStorage;
var count = parseInt(storage.getItem('gkcounter'), 10) || 0;
if (count >= n) {
alert('Create a new instance of gesturekit');
return;
}
<link rel="shortcut icon" href="favicon.ico">

NodeList vs Array

A NodeList is a reference to a collection of objects, and if that collection changes (for example, elements are added or removed) the NodeList will automatically update to reflect that change; conversely our array is a static snapshot of the collection at one point in time, and so won’t update in response to changes in the DOM. Depending on your application, that could be significant.

Source: Sitepoint

function offline() {
document.body.innerHTML = 'You are offline :(';
}
function online() {
document.body.innerHTML = 'You are online :)';
}
window.addEventListener('load', function(e) {
if (navigator.onLine) {