Skip to content

Instantly share code, notes, and snippets.

Avatar

Kevin Weber kevinweber

View GitHub Profile
@kevinweber
kevinweber / this.js
Created Jun 24, 2017
JavaScript: Ways to use `this` in callback function
View this.js
// The old way (before ES6)
var _self = this;
this.element.addEventListener('click', function (event) {
_self.doSomething(event);
});
// The new way (ES6)
this.element.addEventListener('click', (event) => {
this.doSomething(event);
});
@kevinweber
kevinweber / e.164.phoneNumber.js
Last active Sep 27, 2018
Convert string to match E.164 phone number pattern (e.g. +1234567890)
View e.164.phoneNumber.js
/**
* 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 / Sightly Pattern "Inline List"
Last active Sep 19, 2018
AEM/HTL: Define a list/array within a HTL template (and avoid redundant code!)
View Sightly Pattern "Inline List"
<!--/* We can define a list within a Sightly template to avoid redundant code */-->
<sly data-sly-test.versions="${['desktop', 'mobile']}"/>
<sly data-sly-list.identifier="${versions}">
<div class="element ${identifier}">Repeated content</div>
</sly>
@kevinweber
kevinweber / _cq_dialog.xml
Last active Sep 19, 2018
AEM: Sling Resource Merging & Includes (dialog, inheriting properties)
View _cq_dialog.xml
<?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 / HTML-CSS-JS-editor.js
Last active Aug 13, 2018
Bookmarks / Search Input Queries
View HTML-CSS-JS-editor.js
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>
@kevinweber
kevinweber / README.md
Created Jul 29, 2018 — forked from spraints/README.md
Set up git-hooks
View README.md

Install git hooks

git-hooks is a tool that makes it easy to re-use hook scripts across projects.

I installed it by cloning the repo and symlinking it into /usr/local/bin.

git clone git://github.com/icefox/git-hooks.git
cd git-hooks
ln -s `pwd`/git-hooks /usr/local/bin/git-hooks
@kevinweber
kevinweber / aem-grid-v2.less
Last active Jul 9, 2018
Collection of AEM CSS/LESS snippets (responsive grid). Get an exemplary grid from the WKND tutorial: https://helpx.adobe.com/experience-manager/kt/sites/using/getting-started-wknd-tutorial-develop/part3.html
View aem-grid-v2.less
/* 6.3 Path to Responsive Grid */
/* @gridpath : "/etc/clientlibs/wcm/foundation/grid"; */
/* 6.4 Path to Responsive Grid */
@gridpath : "/libs/wcm/foundation/clientlibs/grid";
@import "@{gridpath}/grid_base.less";
/* maximum amount of grid cells to be provided */
View aem-6-2-authoring-messaging.md

AEM 6.2 Authoring Editor to Site messaging API

API

/**
 *
 * @param group {String} group identifier name
 * @param [targetWindow=window.parent]
 * @param [origin='*']
 * @constructor
@kevinweber
kevinweber / debounce.js
Last active Apr 25, 2018
Debounce function
View debounce.js
/**
* Debounce function
* based on https://davidwalsh.name/essential-javascript-functions
*/
function debounce(func, wait, immediate) {
var timeout;
return function () {
var context = this,
args = arguments,
@kevinweber
kevinweber / giphy.js
Created Feb 19, 2018
Giphy API Example
View giphy.js
import {
checkStatus,
parseJSON
} from './request';
/**
* Request data Giphy API
* https://developers.giphy.com/explorer/
*/
You can’t perform that action at this time.