Skip to content

Instantly share code, notes, and snippets.

View hughbris's full-sized avatar

Hugh Barnes hughbris

  • Reidston, New Zealand
  • 18:49 (UTC +12:00)
View GitHub Profile
@hughbris
hughbris / navigation.html.twig
Created May 5, 2018 01:11
Adaptation of Grav navigation partial for menu to show visible modular pages as fragment links
{% macro loop(page) %}
{% set menu_pages = page.children.visible %}
{% for p in menu_pages %}
{% set current_page = (p.active or p.activeChild) ? 'active' : '' %}
{% set has_visible_modular_children = false %}
{% for frag in p.children.modular if frag.header.visible %}
@hughbris
hughbris / form-excerpt.yaml
Last active June 27, 2019 11:50
Grav JQuery datepicker for date field
- name: birthdate
label: Date of Birth
type: text
classes: past lifespan dob datepicker pure-input-1-3
# default: "{{ date('-30years') }}"
size: small
placeholder: 'dd/mm/yyyy' #fallback only, JS resets this
novalidate: true
validate:
required: true
@hughbris
hughbris / form-excerpt.yaml
Created September 11, 2017 23:33
Grav conditional field rendering logic using jQuery and YAML properties rendering as data-* attributes
- name: had-allergies
label: 'Have you ever had any allergies to medicines or other substances (such as Latex)?'
type: radio
options:
yes: Yes
no: No
validate:
required: true
classes: question
@hughbris
hughbris / README-imgur-api-upload-file-js.md
Last active February 8, 2024 20:00
Javascript Imgur API uploading example using type=file

This Gist shows an otherwise (AFAICT) undocumented way to upload images using the Imgur API with type=file.

I did not want to base64 encode (type=base64) the file contents because my use case was within a Cordova app where resources may limited.

The file is taken from the device file system, so no URL is accessible for file=url.

I was unable to find any guidance or examples in online documentation using this method in Javascript (or any language, AFAIR). I emailed(!) the suggested support contact laying out the problem and stressing that I had not found examples in the documentation. The reply came a month later, pointing me to the very docs in which I had told them I found no satisfactory answer or example! Gee, thanks.

It wasn't too hard, playing with cURL, to get a working call from command line:

@hughbris
hughbris / navigation.html.twig
Last active January 19, 2017 01:05
Grav menus including visble modular component links
{% macro loop(page) %}
{% set menu_pages = page.children.visible %}
{# set menu_pages = menu_pages|merge(page.children.modular) #} {# don't know why, but this array merge fails majorly #}
{# set menu_pages = page.evaluate([{'@page.children.visible': '/', '@page.modular':'/'}]) #}
{# so .. #}
{% for frag in page.children.modular if frag.header.visible %}
{% set menu_pages = menu_pages.addPage(frag) %}
{% endfor %}
@hughbris
hughbris / README.md
Last active December 1, 2016 05:11
Patch of user directory from Grav 1.1.8 to reproduce issue #1184
@hughbris
hughbris / Storage.prototype.hasItem.js
Created September 27, 2016 00:13
Test if localStorage has a member
Storage.prototype.hasItem = function(itemName, rejectEmpty) {
var setting = this.getItem(itemName);
return ( (setting !== null) && (rejectEmpty ? setting.length > 0 : true) );
}
/*
testStorageHasItem = function() {
window.localStorage.setItem('test.foo', 'foo');
console.log(window.localStorage.hasItem('test.foo')); // true
console.log(window.localStorage.hasItem('test.foo', false)); // true
console.log(window.localStorage.hasItem('test.foo', true)); // true
@hughbris
hughbris / input.submit.html
Created June 3, 2015 06:40
Design pattern: form submit button
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-NZ" lang="en-NZ"> <!-- bru -->
<head>
<title>Turn it in now</title>
<style type="text/css">
@hughbris
hughbris / form-elaboratedradios.html
Created June 3, 2015 06:28
Design pattern: radio buttons across with aligned pictorial headings and blurb text
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-NZ" lang="en-NZ"> <!-- bru -->
<head>
<title>What will it be? You must choose</title>
<style type="text/css">
@hughbris
hughbris / form-personfields.html
Created June 3, 2015 05:44
Design pattern: personal details fieldset boilerplate for a form
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-NZ" lang="en-NZ"> <!-- bru -->
<head>
<title>Gotta sign up</title>
<style type="text/css">