Skip to content

Instantly share code, notes, and snippets.

@Fedia
Fedia / event_extension.js
Created November 16, 2012 17:47
Extending Deployd Event's domain
(function(Script) {
var _run = Script.prototype.run;
Script.prototype.run = function(ctx, domain, fn) {
if (typeof domain === 'object') {
domain.require = function(module) {
return require(module);
};
domain.context = function() { // access Context via context()
return ctx;
};
// window.saveAs
// Shims the saveAs method, using saveBlob in IE10.
// And for when Chrome and FireFox get round to implementing saveAs we have their vendor prefixes ready.
// But otherwise this creates a object URL resource and opens it on an anchor tag which contains the "download" attribute (Chrome)
// ... or opens it in a new tab (FireFox)
// @author Andrew Dodson
// @copyright MIT, BSD. Free to clone, modify and distribute for commercial and personal use.
window.saveAs || ( window.saveAs = (window.navigator.msSaveBlob ? function(b,n){ return window.navigator.msSaveBlob(b,n); } : false) || window.webkitSaveAs || window.mozSaveAs || window.msSaveAs || (function(){
@Fedia
Fedia / LICENSE.txt
Last active November 28, 2023 18:31 — forked from 140bytes/LICENSE.txt
John Resig's Micro-Templating in 140 bytes
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2015 Fedia <[email protected]>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
/**
* Batshit crazy DOM serializer in 140byt.es fashion (138)
* Ships with a predefined limit of 99 childNodes
*
*/
function (a,b,c){for(b=Array(99),c=0;c<99;b[c]=c++);return JSON.stringify(a,['nodeName','nodeValue','attributes','childNodes'].concat(b))}
/**
* Refactored
* http://stackoverflow.com/questions/17678843/cant-restore-selection-after-html-modify-even-if-its-the-same-html
*/
function saveSelection(el) {
var win = el.ownerDocument.defaultView;
var range = win.getSelection().getRangeAt(0);
var prefixRange = range.cloneRange();
prefixRange.selectNodeContents(el);
@Fedia
Fedia / loader.js
Last active January 4, 2017 10:00
Dynamic loading of external CSS and Javascript files. 287 bytes minified.
/**
* Dynamic loading of external CSS and Javascript files. 287 bytes minified. Usage:
* load(['some.css', 'lib.js'], function() { console.log('loaded!') });
*/
var load = function (urls, done) {
var doc = document;
var cnt = urls.length;
var head = doc.getElementsByTagName('head')[0];
var onload = function () {
@Fedia
Fedia / index.js
Last active January 30, 2017 23:59
🌀 Eddy: Static Websites For The Rest of Us
//- polyfills
'use strict';
(function (p) {
if (!p.matches) p.matches = p.webkitMatchesSelector || p.mozMatchesSelector || p.msMatchesSelector;
})(Element.prototype);
if (typeof window.CustomEvent !== 'function') {
window.CustomEvent = function (name, p) {
p = p || {};
// Hacky Rollup plugin to remove source maps from Svelte components compiled for SSR
const killSSRmaps = {
renderChunk(code) {
return {
code: code.replace(/,[\s\n]*map:\s*(["'])\{.+?\}\1/g, ""),
};
},
};