Skip to content

Instantly share code, notes, and snippets.

View jennatollerson's full-sized avatar

Jenna Tollerson jennatollerson

View GitHub Profile
@jennatollerson
jennatollerson / SettingsForm.php
Last active March 1, 2022 03:06
Drupal Form API, add an image field that includes a preview and an alt text field to your custom module's configuration form.
<?php
// src/Form/SettingsForm.php
/* Include theses dependencies in my_custom_module.info.yml
dependencies:
- drupal:file
- drupal:image
*/
namespace Drupal\my_custom_module\Form;
@jennatollerson
jennatollerson / track_outbound_links.js
Last active September 25, 2023 18:21
Tracking outbound links in Google Analytics (Universal/GA3) without adding onclick attributes to all your anchors
@jennatollerson
jennatollerson / check_if_pymChild.js
Created October 29, 2020 00:01
Check if a page is iframed, add iframe specific enhancements.
// This is meant to be included on child frames created with http://blog.apps.npr.org/pym.js/
// This script checks if our page is iframed, and if so, induces it to cooperate.
// This can allow us to use the same template for all pages on a site, and make being a child iframe an option for any page.
document.addEventListener('DOMContentLoaded', function () {
var inIFrame = (window.location != window.parent.location) ? true : false;
if(inIFrame) {
// If this page is in a iframe...
// ... Load pym.js into this page.
var pymjs = document.createElement('script');
pymjs.src = 'https://pym.nprapps.org/pym.v1.min.js';