Skip to content

Instantly share code, notes, and snippets.

@karlgroves
karlgroves / textOnly.js
Created Jan 20, 2016
Strip CSS classes, style attributes, and stylesheets and replace images with their alt attributes
View textOnly.js
$(document).ready(function(){
$('*').removeClass();
$('*').removeAttr('style');
$('link[rel="stylesheet"]').remove();
$('img').each(function () {
$(this).replaceWith(
$(this).attr('alt')
@karlgroves
karlgroves / gist:cdd532edbe957851f719
Created Jun 24, 2015
Uncompressed Tenon Bookmarklet
View gist:cdd532edbe957851f719
javascript:(function () {
var html = document.documentElement.innerHTML;
/**
* the iframe's onload event is triggered twice: once when appending it to the document,
* and once when the form finishes submitting and the new URL is loaded
*/
var loaded = 0;
var iframe = document.createElement('iframe');
@karlgroves
karlgroves / gist:1d73f80f2a0dcc78f82f
Created Jun 24, 2015
*Super* rudimentary bookmarklet for testing document source with Tenon
View gist:1d73f80f2a0dcc78f82f
javascript:(function(){var html=document.documentElement.innerHTML;var loaded=0;var iframe=document.createElement('iframe');iframe.name='bookmarklet-'+Math.floor((Math.random()*10000)+1);iframe.style.display='none';iframe.onload=function(){if(++loaded==1){return}document.body.removeChild(iframe)};var form=document.createElement('form');form.method="POST";form.action="https://tenon.io/api/";form.target=iframe.name;var hidden=document.createElement('input');hidden.type='hidden';hidden.name='key';hidden.value='ADD_YOUR_API_KEY_HERE';var store=document.createElement('input');store.type='hidden';store.name='store';store.value='1';var textarea=document.createElement('textarea');textarea.name='src';textarea.value=html;form.appendChild(hidden);form.appendChild(store);form.appendChild(textarea);iframe.appendChild(form);document.body.appendChild(iframe);form.submit()})();
@karlgroves
karlgroves / Focus Bookmarklet
Created Jan 31, 2014
Add this bookmarklet to your browser. Activate the bookmarklet and as you tab through the site you should see a red border around whatever gets focus
View Focus Bookmarklet
javascript:(function(){var%20ua=navigator.userAgent.toLowerCase(),ie=ua.indexOf(%22msie%22)!=-1?ua.substr(ie+5,1):0,outlineProp=ie%3C8?%22border%22:%22outline%22,activeItem;function%20styleFocus(e){if(activeItem){activeItem.style[outlineProp]=%22%22;}activeItem=e.target||e.srcElement;if(activeItem){activeItem.style[outlineProp]=%22solid%202px%20red%22;}}if(document.addEventListener){document.addEventListener(%22focus%22,styleFocus,true);}else{document.attachEvent(%22onfocusin%22,styleFocus);}}());
@karlgroves
karlgroves / focusable
Created Dec 24, 2013
Found this and thought it looked interesting. I saw it at http://test.cita.illinois.edu/aria/tabpanel/tabpanel2.php#lsc1 and in that page they cite "ajpiano on the jQuery forums." Untested but seems sane
View focusable
// focusable is a small jQuery extension to add a :focusable selector. Credit to ajpiano on the jQuery forums.
//
$.extend($.expr[':'], {
focusable: function(element) {
var nodeName = element.nodeName.toLowerCase();
var tabIndex = $(element).attr('tabindex');
// the element and all of its ancestors must be visible
if (($(element)[(nodeName == 'area' ? 'parents' : 'closest')](':hidden').length) == true) {
return false;
View pathauto_cleanstring
/**
* cleans up strings so they can be used in URLS
* @author "Borek" - attributed to a post located at:
* http://drupal.org/node/63924
* @param string $string the string we're cleaning
* @return string the input string, ready to go
*/
function pathauto_cleanstring($string)
{
@karlgroves
karlgroves / gist:7545632
Created Nov 19, 2013
PHP function to get the MIME type of a remote file.
View gist:7545632
function getRemoteMimeType($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
# get the content type
return curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
}
@karlgroves
karlgroves / gist:7544592
Created Nov 19, 2013
Get DOM path of an element
View gist:7544592
function getDomPath(el) {
var stack = [];
while ( el.parentNode != null ) {
console.log(el.nodeName);
var sibCount = 0;
var sibIndex = 0;
for ( var i = 0; i < el.parentNode.childNodes.length; i++ ) {
var sib = el.parentNode.childNodes[i];
if ( sib.nodeName == el.nodeName ) {
if ( sib === el ) {
@karlgroves
karlgroves / gist:7544535
Created Nov 19, 2013
jQuery empty() doesn't tell you if something is blank, it tells you whether something is truly empty - having no other nodes inside it. This function tells whether a string is blank. It returns true in cases where there are no printable text characters are in the string.
View gist:7544535
function isBlank(str){
return str.replace(/\W/gi, '') == '';
}
@karlgroves
karlgroves / StripeTutorialPage.html
Last active Mar 13, 2018 — forked from briancollins/StripeTutorialPage.html
I really hate seeing "examples" that contain accessibility errors, esp. when they're so easy to fix. This forks a tutorial for the Stripe API and makes some relatively minor adjustments to make it much more accessible. Still not perfect but way better than the original.
View StripeTutorialPage.html
<!--// Fixed for accessibility by Karl Groves 22-Oct 2013. Original Gist @ https://gist.github.com/briancollins/6365455 //-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Stripe Getting Started Form</title>
<!-- The required Stripe lib -->
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
You can’t perform that action at this time.