This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Dropdown(toggle, menu) { | |
this.toggle = toggle; | |
this.menu = menu; | |
this.menuPlacement = { | |
top: menu.classList.contains('dropdown-menu-top'), | |
end: menu.classList.contains('dropdown-menu-end') | |
}; | |
this.toggle.addEventListener('click', this.clickHandler.bind(this)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A validation script for use with a "naked" Mailchimp embedded form. | |
* | |
* credit to this post on CSS-Tricks: | |
* https://css-tricks.com/form-validation-part-4-validating-mailchimp-subscribe-form/ | |
* | |
* I added a couple of minor Bootstrap 4 classes | |
**/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Function does something... | |
* @param obj $obj object with required and optional properties. | |
*/ | |
function something($obj) { | |
// bail if required properties aren't set | |
if( !isset($obj->req_prop_1) || !isset($obj->req_prop_1) ) { return ''; } | |
$opt_prop_1 = $obj->opt_prop_1; | |
$opt_prop_2 = $obj->opt_prop_2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Determines if a form is dirty by comparing the current value of each element | |
* with its default value. Nicely done on StackOverflow: https://stackoverflow.com/a/155812/1558564 | |
* | |
* @param {Form} form the form to be checked. | |
* @return {Boolean} true if the form is dirty, false if it's not. | |
*/ | |
function formIsDirty(form) { | |
for (var i = 0; i < form.elements.length; i++) { | |
var element = form.elements[i]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* thanks to @mathias for this. https://twitter.com/mathias/status/922460187671216129 */ | |
const fetchAndDisplay = async function(url, element) { | |
showLoadingSpinner(); | |
try { | |
const response = await fetch(url); | |
const text = await response.text(); | |
element.textContent = text; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function largestLessThanMaxLimit(limit = 10) { | |
var maxLimit = limit; | |
return function largestLessThanMaxLimit(...args) { | |
return args.reduce( function(acc, val) { | |
if( val > acc && val < maxLimit ) { | |
return val; | |
} | |
else { | |
return acc; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myModule = (function () { | |
var privateMethod = function () { | |
console.log('A private method'); | |
}, | |
someMethod = function () { | |
console.log('A public method'); | |
}, | |
anotherMethod = function () { | |
console.log('Another public method'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validate domain (only letter, numbers, and hypens... and must start with a letter) | |
^[a-zA-Z]+[a-zA-Z0-9\-]*$ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function formInputsToJson(form) { | |
var $form = $(form); | |
var fArr = $form.serializeArray() | |
var fObj = {}; | |
for (var i in fArr) { | |
fObj[fArr[i].name] = fArr[i].value; | |
} | |
return fObj; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//todo: de-jquery this | |
function showRandomItem(list) { | |
// random ad on refresh. Each a element should have style="display:none" | |
var items = $(list).children('li'), | |
tot = items.length; | |
if (tot > 1) { | |
var randNum = Math.round(Math.random()*(tot-1)); | |
items.eq(randNum).show(); | |
} else { | |
$(items).show(); |
NewerOlder