Skip to content

Instantly share code, notes, and snippets.

@kevinweber
kevinweber / README.md
Created May 17, 2017 23:18 — forked from toodooleedoo/README.md
#AEM #Sightly #SSJS Server Side JavaScript Use-API Breadcrumbs

###Description Retrieve a Page Object from all pages which are in the Site root then build a breadcrumb component and display the current pages title in a submenu.

###Use case Display a bar under eg a menu which displays the current pages title and functional breadcrumb components o the right.

##Requirements

  • Responsive and which works on all mobile devices and desktop.
  • Current pages title on the left
  • Breadcrumbs on the right
@kevinweber
kevinweber / enforcer.js
Last active October 20, 2017 00:35
Enforcer.js: Address validation
import {
debounce as T_DEBOUNCE,
} from 'utils/methods';
/**
* T-ENFORCER provides methods to validate strings.
* This is developed with input fields in mind, but it shouldn't be limited to them.
*
* Author: Kevin Weber
*
@kevinweber
kevinweber / e.164.phoneNumber.js
Last active April 23, 2021 19:14
Convert string to match E.164 phone number pattern (e.g. +1234567890)
/**
* Convert string to match E.164 phone number pattern (e.g. +1234567890),
* otherwise return empty string.
*/
function enforcePhoneNumberPattern(string) {
let newString = string.match(/[0-9]{0,14}/g);
if (newString === null) {
return '';
}
@kevinweber
kevinweber / createNestedObject.js
Last active February 24, 2017 23:41
Convert dot-notated string or path of object into an object using recursion. This is similar to Lodash's _.zipObject but it doesn't set any values.
/**
* Convert an array into an object where each object gets nested like this:
['string1', 'string2', 'string3']
becomes
{
string1: {
string2: {
@kevinweber
kevinweber / HTML-CSS-JS-editor.js
Last active August 13, 2018 16:59
Bookmarks / Search Input Queries
data:text/html,<body oninput="i.srcdoc=h.value+'<style>'+c.value+'</style><script>'+j.value+'</script>'"><style>textarea,iframe{width:100%;height:50%}body{margin:0}textarea{width:33.33%;font-size:18}</style><textarea placeholder=HTML id=h></textarea><textarea placeholder=CSS id=c></textarea><textarea placeholder=JS id=j></textarea><iframe id=i>
<alignment jcr:primaryType="nt:unstructured"
name="./alignChildren"
fieldLabel="Alignment of components"
required="{Boolean}true"
selectionMode="single"
sling:resourceType="granite/ui/components/coral/foundation/form/buttongroup">
<items jcr:primaryType="nt:unstructured">
<default jcr:primaryType="nt:unstructured"
name="./default"
@kevinweber
kevinweber / _cq_dialog.xml
Last active February 21, 2023 14:44
AEM: Sling Resource Merging & Includes (dialog, inheriting properties)
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="nt:unstructured">
<content jcr:primaryType="nt:unstructured">
<items jcr:primaryType="nt:unstructured">
<basic jcr:primaryType="nt:unstructured">
<items jcr:primaryType="nt:unstructured">
<column jcr:primaryType="nt:unstructured">
@kevinweber
kevinweber / $.js
Last active December 19, 2016 19:13
MiniJQuery using documentSelectorAll - you don't need jQuery!
// Use this:
var $ = function (domSelector) {
return Array.prototype.slice.call(document.querySelectorAll(domSelector));
}
// Or this:
const $ = (domSelector) => [].slice.call(document.querySelectorAll(domSelector));
// And then use $ like this:
@kevinweber
kevinweber / ifTargetPageExists.js
Last active December 9, 2016 13:54
Helper: Check target URL using XMLHttpRequest before we execute a callback accordingly. No Ajax/Promise needed.
/**
* Ensure that target page exists before we actually do something.
*
* @param {string} targetUrl - Absolute target URL to be tested
* @param {function} [successCallback] - Function to be executed on success
* @param {function} [failCallback] - Function to be executed on fail
*/
function checkTargetFirst(targetUrl, successCallback, failCallback) {
var reader = new XMLHttpRequest();
@kevinweber
kevinweber / encodeSvg.js
Created October 31, 2016 05:36
Helper: Convert React component (SVG element) to base64 encoded URL. Useful for adding a background image.
import ReactDOMServer from 'react-dom/server';
export function encodeSvg(reactElement) {
return 'data:image/svg+xml,' + escape(ReactDOMServer.renderToStaticMarkup((reactElement)));
}