Skip to content

Instantly share code, notes, and snippets.

View kfranqueiro's full-sized avatar

Kenneth G. Franqueiro kfranqueiro

View GitHub Profile
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}
// 1A:
bar[foo ? 'doSomething' : 'doSomethingElse'](el);
@kfranqueiro
kfranqueiro / DeferredDeclarativeMenu.js
Created March 13, 2011 21:37
Extension of dijit.Menu which fetches its items from a server endpoint outputting widgets in declarative HTML.
dojo.provide('kgf.widget.DeferredDeclarativeMenu');
dojo.require('dojo.parser');
dojo.require('dojo.string');
dojo.require('dijit.Menu');
dojo.requireLocalization('dijit', 'loading');
dojo.declare('kgf.widget._DeferredDeclarativeMenuMixin', null, {
// src: String
// URL to be loaded when this menu is opened.
@kfranqueiro
kfranqueiro / ParentHierarchical.js
Created March 29, 2011 12:39
Possibly-naive attempt at a generic dojo.store wrapper supporting getChildren, via parent relationships.
/*
NOTE: This wrapper "works", but is sorta incomplete...
* It does not explicitly support deterministic ordering/rearrangement of children.
* For that matter, the way Tree currently achieves this seems sort of obtuse.
Tree makes a blatant assumption on the existence of a children attribute
(since there is no dedicated method to set them), and reconstructs the array
every time children are reordered...
@kfranqueiro
kfranqueiro / test59.html
Created January 5, 2012 04:59
Test page attempting to reproduce dgrid issue #59
<!DOCTYPE html>
<html>
<head>
<title>Test Issue #59</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=570"/>
<style type="text/css">
@import "../../dijit/themes/claro/document.css";
@import "../../dijit/themes/claro/claro.css";
@import "../css/dgrid.css";
@kfranqueiro
kfranqueiro / test.html
Created September 13, 2012 01:01
Test for dgrid #277
<!DOCTYPE html>
<html>
<head>
<style>
#hierarchyTree {
height: 200px;
}
#hierarchyTree .dgrid-cell {
width: 100px;
@kfranqueiro
kfranqueiro / findDep.js
Last active March 1, 2016 22:47
Functions to find what's depending on a loaded Dojo module or what a module depends on (uses ES5 methods)
function findDep(depid) {
return Object.keys(require.modules).map(function(mid) {
return require.modules[mid];
}).filter(function(m) {
return m.deps && m.deps.map(function(dep) {
return dep.mid;
}).indexOf(depid) > -1;
}).map(function(m) {
return m.mid;
});
@kfranqueiro
kfranqueiro / enterUp.js
Created February 22, 2013 21:02
Example of a dojo/on extension event that fires when the enter key is released
function enterUp(node, listener) {
return on(node, "keyup", function(evt) {
if (evt.keyCode === 13) {
listener.call(this, evt);
}
});
}
// Usage with dojo/on: on(element, enterUp, ...)
// Usage with dgrid editor: editor({ editOn: enterUp, ... })
@kfranqueiro
kfranqueiro / MoreMixin.html
Created March 15, 2013 04:22
Example of extending dgrid's `_StoreMixin` to present a list or grid progressively, one page at a time.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../dojo/resources/dojo.css">
<link rel="stylesheet" href="../../dgrid/css/skins/claro.css">
<style>
#list {
border: none;
height: auto;
@kfranqueiro
kfranqueiro / metalsmith-symbolset.js
Created May 13, 2014 02:13
Code that can be run on metalsmith.io to dump the symbolset icons at the bottom of the page, with title-text indicating what `icon` value to use for each one in `plugins.json`.
[
'ss-cursor',
'ss-crosshair',
'ss-search',
'ss-zoomin',
'ss-zoomout',
'ss-view',
'ss-attach',
'ss-link',
'ss-unlink',
@kfranqueiro
kfranqueiro / spot-bookmarklet.txt
Last active October 25, 2019 21:56
spot - a script/bookmarklet providing utility functions for finding unused CSS selectors/classes
javascript:window.spot=function(){function a(a,b){for(var d,c=document.styleSheets,e=0,f=c.length;f>e;e++)if((!b||c[e].href&&-1!==c[e].href.indexOf(b))&&(d=c[e].cssRules,d&&d.length))for(var g=d.length;g--;)d[g].selectorText&&a(d[g].selectorText)}function b(a,c){c||a(document.documentElement);for(var d=(c||document.documentElement).children,e=0,f=d.length;f>e;e++)a(d[e]),b(a,d[e])}function c(a){var b={},c=getComputedStyle(a);for(var d in c)isNaN(d)&&"function"!=typeof c[d]&&(b[d]=c[d]);return b}function d(a,b){var c=Object.keys(a);if(c.length!==Object.keys(b).length)return!1;for(var d=c.length;d--;)if(a[c[d]]!==b[c[d]])return!1;return!0}return{unusedClasses:function(){var a=Array.prototype.slice,e={},f=[];b(function(b){if(b.className){var g,h,f=a.call(b.classList);g=c(b);for(var i=f.length;i--;)h=f[i],e[h]||(b.classList.remove(h),e[h]=!d(g,c(b)),b.classList.add(h))}});for(var g in e)e[g]===!1&&f.push(g);return f},unusedSelectors:function(b){var c={};return a(function(a){document.querySelector(a)||(c[a]=!0)},b