Skip to content

Instantly share code, notes, and snippets.

View rumblestrut's full-sized avatar

Eric J. Gruber rumblestrut

View GitHub Profile
@rumblestrut
rumblestrut / Drupal PHP to JS
Created December 20, 2016 20:39
Drupal JS with drupal_add_Js
drupal_add_js(
"var example = \"$example\";",
array('type' => 'inline', 'scope' => 'header', 'weight' => 10)
);
@rumblestrut
rumblestrut / U.S. States Array
Created December 16, 2016 15:19
It's an array of U.S. States.
function stateOrProvince() {
$array = array(
'' => '',
'AL' => 'Alabama',
'AK' => 'Alaska',
'AZ' => 'Arizona',
'AR' => 'Arkansas',
'CA' => 'California',
'CO' => 'Colorado',
'CT' => 'Connecticut',
@rumblestrut
rumblestrut / stopprop.js
Created May 3, 2016 14:10
This is for me to remember that events bubble up in the DOM, and that I need to stopPropagation or else things get all wonky.
module.exports = (function($) {
var trigger_element = '.menu__user--primary__sub-menu';
var open_class = 'menu__user--primary__sub-menu__toggle';
// Toggle the user menu when the username is clicked.
$('.menu__user--primary__item__label').click(function(e) {
$(trigger_element).toggleClass(open_class);
e.stopPropagation();
});
const OLD_TAX_RATE = 0.061;
const NEW_TAX_RATE = 0.065;
function calculateOldPurchase(amt) {
amt = amt + (amt * OLD_TAX_RATE);
return amt;
}
function calculateNewPurchase(amt) {
amt = amt + (amt * NEW_TAX_RATE);
@rumblestrut
rumblestrut / FlashyTitle.js
Created February 10, 2015 17:53
Flashy Title
/* Stolen from www.slimframework.com */
function() {
var a=document.title;
window.onblur=function(){
document.title="♬ Baby come back! Any kind of fool could see... ♬"
},
window.onfocus=function(){document.title=a}
}
@rumblestrut
rumblestrut / hiddentext.html
Created January 7, 2015 21:59
Hidden Text
<!DOCTYPE html>
<html>
<head>
<title>Hiding Text</title>
<script>
function expandLoris() {
var expandedParagraph = "Slow lorises are a group of several species of trepsirrhine primates which make up the genus Nycticebus. They have a round head, narrow snout, large eyes, and a variety of distinctive coloration patterns that are species-dependent. The hands and feet of slow lorises have several adaptations that give them a pincer-like grip and enable them to grasp branches for long periods of time. Slow lorises have a toxic bite, a rare trait among mammals.";
document.getElementById("slowLoris").innerHTML = expandedParagraph;
}
</script>
<!DOCTYPE html>
<html>
<head>
<title>Form</title>
<script>
function fieldFocus() {
document.getElementsByTagName("input")[0].style.backgroundColor='yellow';
}
function noFocus() {
@rumblestrut
rumblestrut / fieldfocus.html
Created January 6, 2015 23:02
Field focus with JavaScript
<!DOCTYPE html>
<html>
<head>
<title>Form</title>
<script>
function fieldFocus() {
document.getElementById("input").style.backgroundColor='yellow';
}
function noFocus() {
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>No Mobile</title>
</head>
<body>
<p>We're sorry, but this content isn't available on mobile devices.</p>
</body>
@rumblestrut
rumblestrut / eligibleVoter.js
Last active August 29, 2015 14:12
Eligible to Vote?
var currentAge = prompt("Enter your age.");
var yearsEligibleToVote <= currentAge - 18;
if (yearsEligibleToVote > 17) {
alert("You have been eligible to vote for " + yearsEligibleToVote + " years.");
} else {
alert("You are not yet elibige to vote. Come back when you're 18 years old.");
};