Skip to content

Instantly share code, notes, and snippets.

View jorgepinon's full-sized avatar

Jorge Luis Piñon jorgepinon

View GitHub Profile
@jorgepinon
jorgepinon / gist:a2ffcd9a7c33083dd433f57f3c86c7fc
Created October 23, 2017 14:03
Promise with async/await structure
/* 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;
@jorgepinon
jorgepinon / formIsDirty()
Created November 7, 2017 03:35
javascript function to check if a form has inputs that have been changed
/**
* 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];
@jorgepinon
jorgepinon / php_function_arguement_defaults.php
Last active January 5, 2018 18:57
php pattern : test if properties exists and set defaults
/**
* 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;
@jorgepinon
jorgepinon / validateAjaxMailchimpForm.js
Last active December 8, 2020 09:11
Mailchimp Validation Script
/**
* 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
**/
@jorgepinon
jorgepinon / Dropdown.js
Last active July 23, 2022 22:33
Dropdown class
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));