Skip to content

Instantly share code, notes, and snippets.

View thedamon's full-sized avatar

Damon Muma thedamon

View GitHub Profile
@thedamon
thedamon / getSections.js
Last active August 31, 2022 14:18
returns the header of the section containing a given element
function getSectionHeader(element, headerDepth = 6){
const headerSelector = Array(headerDepth).fill().map((i,idx) => `h${idx+1}`).join(',');
console.log(headerSelector);
if (element.matches(headerSelector)) {
return element;
}
const tempAttr = 'data-getSectionInTitleElement';
element.setAttribute(tempAttr, "");
const els = document.querySelectorAll(`${headerSelector},[${tempAttr}]`);
@thedamon
thedamon / domInitor.js
Last active November 2, 2018 01:19
Vue components on demand; anywhere in your weird/old/headful CMS
/*
In a large CMS site (or sites), where content authors can add any component to any page at any time, it's sometimes tricky to figure out how to integrate Vue apps and components in a way that plays well together, especially when we don't want to need to bundle all our javascript on pageload and load stuff that's not necessary on one page or another.
Whatever the backend, DomInitor will take care of initializing Vue (and/or JS coomponents) based on data attributes, but only load the javascript it needs for a given page AND work in IE11.
It works by scanning the HTML of your page for data attributes and using the values of them + webpack to asynchronously load all the js chunks.
There is a lot of code specific to my use case here, but it gives a good example of how to achieve the dream of being able to have Vue components built as SFCs and bundled by webpack easily used within a massive 'legacy'/'oldschool' website while only loading the components used on any given page. (Caveat: because this is run onc
@thedamon
thedamon / webpack.config.js
Last active November 5, 2015 03:53
Redux/React/Babel webpack config w production variables
var webpack = require('webpack');
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var sassLoaders = [
'css',
'autoprefixer-loader?browsers=last 2 version',
'sass-loader?includePaths[]=' + __dirname + '/app/styles&sourceMap=true'
];
//set entry-points and plugins that are the same across dev and prod.
@thedamon
thedamon / glozzarizer-test.json
Created June 12, 2015 19:48
Glossarizer testing json file
[
{"term": "black cat", "description":"a black feline"},
{"term": "cat", "description": "meow"}
]
@thedamon
thedamon / backbutton close bootstrap modal
Created February 28, 2014 17:59
Cause back button to close Bootstrap modal windows
$('div.modal').on('show', function() {
var modal = this;
var hash = modal.id;
window.location.hash = hash;
window.onhashchange = function() {
if (!location.hash){
$(modal).modal('hide');
}
}
});
@thedamon
thedamon / MacSublimeKeyboard
Created February 16, 2014 23:17
Mac OS ST3 keyboard mappings diff
["super+alt+up"]: "switch_file", "args": {"extensions": ["cpp", "cxx", "cc", "c", "hpp", "hxx", "h", "ipp", "inl", "m", "mm"]} },
["super+alt+s"]: "save_all" },
["super+ctrl+f"]: "toggle_full_screen" },
["super+ctrl+shift+f"]: "toggle_distraction_free" },
["super+option+v"]: "paste_from_history" },
["ctrl+alt+left"]: "move", "args": {"by": "subwords", "forward": false} },
["ctrl+alt+right"]: "move", "args": {"by": "subword_ends", "forward": true} },
["ctrl+alt+shift+left"]: "move", "args": {"by": "subwords", "forward": false, "extend": true} },
["ctrl+alt+shift+right"]: "move", "args": {"by": "subword_ends", "forward": true, "extend": true} },
["ctrl+left"]: "move", "args": {"by": "subwords", "forward": false} },
@thedamon
thedamon / Preferences.sublime-settings
Created March 8, 2013 18:44
My Sublime Text preferences
{
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"detect_slow_plugins": false,
"font_size": 8,
"highlight_modified_tabs": true,
"ignored_packages":
[
"Vintage",
"TrailingSpaces"
],
@thedamon
thedamon / gist:4158016
Created November 27, 2012 23:48
1px by 1px square transparent png binary
<img width="1" height="1" title="" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAABBJREFUeNpi+P//PwNAgAEACPwC/tuiTRYAAAAASUVORK5CYII=" />
@thedamon
thedamon / inlinelinks.js
Created November 27, 2012 20:02
small jquery function to auto-focus inline-linked inputs. Only works for in-page links so far. Feel like this should be default browser behaviour
@thedamon
thedamon / validationbookmarklet
Created June 28, 2012 20:19
Bookmarklet to validate local file with W3C by RobW (http://stackoverflow.com/u/938089)
javascript:(function(){function c(a,b){var c=document.createElement("textarea");c.name=a;c.value=b;d.appendChild(c)}var e=function(a){for(var b="",a=a.firstChild;a;){switch(a.nodeType){case Node.ELEMENT_NODE:b+=a.outerHTML;break;case Node.TEXT_NODE:b+=a.nodeValue;break;case Node.CDATA_SECTION_NODE:b+="<![CDATA["+a.nodeValue+"]]\>";break;case Node.COMMENT_NODE:b+="<\!--"+a.nodeValue+"--\>";break;case Node.DOCUMENT_TYPE_NODE:b+="<!DOCTYPE "+a.name+(a.publicId?' PUBLIC "'+a.publicId+'"':"")+(!a.publicId&&a.systemId? " SYSTEM":"")+(a.systemId?' "'+a.systemId+'"':"")+">\n"}a=a.nextSibling}return b}(document),d=document.createElement("form");d.method="POST";d.action="http://validator.w3.org/check";d.enctype="multipart/form-data";d.target="_blank";c("fragment",e);c("doctype","HTML5");c("group","0");document.body.appendChild(d);d.submit()})();