Skip to content

Instantly share code, notes, and snippets.

View benald's full-sized avatar

Benald benald

  • Perth, Australia
View GitHub Profile
@benald
benald / Cross-browser viewport height and width JS variables
Created September 20, 2019 01:27
An accurate cross browser / device viewport measurement
// Set cross-browser viewport height and width variable
viewHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
viewWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
// Viewport detection
//
//
//
define([
"jquery"
],
function ($) {
var module = {
HTML:
<button type="button" class="uk-button" (click)="toggleControls()" [class.active]="show">toggle Controls</button>
TS:
// Define property in Component Class
public show = false;
// Define Toggle Function
toggleControls() {
this.show = !this.show;
TS:
// OnInit
ngOnInit() {
this.addBodyClass();
}
// Function: Add class to body
addBodyClass() {
const bodyTag = document.body;
@benald
benald / nunjucks-multilevel-navigation
Created November 29, 2018 00:45
Nunjucks Multi Level Navigation Template
// JSON Structure
[{
"title": "Home",
"name": "index"
},
{
"title": "Find a service",
"name": "find a service"
},
{
<root available-locales="en_AU" default-locale="en_AU">
<dynamic-element fieldNamespace="ddm" indexType="keyword" localizable="true" name="Article" readOnly="false" repeatable="false" required="false" showLabel="true" type="ddm-separator" width="">
<dynamic-element fieldNamespace="ddm" indexType="keyword" localizable="true" name="openingGroupSection" readOnly="false" repeatable="false" required="false" showLabel="true" type="ddm-separator" width="">
<dynamic-element dataType="string" indexType="keyword" localizable="true" name="openingSectionLead" readOnly="false" repeatable="false" required="false" showLabel="true" type="textarea" width="small">
<meta-data locale="en_AU">
<entry name="label">
<![CDATA[openingSectionLead]]>
</entry>
<entry name="predefinedValue">
<![CDATA[]]>
<#assign imageManagerService = serviceLocator.findService('IMAGE_MANAGER','helper') />
<div class="eds-c-panel">
<div class="inner-wrapper eds-c-content-view">
<#if Article.getSiblings()?has_content>
<#list Article.openingGroupSection.getSiblings() as cur_openingGroupSection>
<div class="row">
<div class="col-md-10 col-md-offset-1 eds-u-flush">
<#if cur_openingGroupSection.openingSectionLead.getData()?has_content && cur_openingGroupSection.openingSectionLead.getData() != '<p>&nbsp;</p>'>
<p class="eds-c-feature-paragraph">${cur_openingGroupSection.openingSectionLead.getData()}</p>
</#if>
@benald
benald / gulpfile.js
Last active September 20, 2019 01:46
/*
SET UP:
Open Terminal / CMD, run the following
1. npm i -g gulp (install GULP globally!)
2. install the gulp dependancies:
a. NPM: npm install --save-dev gulp gulp-concat gulp-uglify gulp-autoprefixer gulp-rename gulp-minify-css gulp-cssnano gulp-sass gulp-sourcemaps del gulp-imagemin gulp-plumber gulp-cache gulp-bootlint gulp-notify browser-sync
a. YARN: yarn add gulp gulp-concat gulp-uglify gulp-autoprefixer gulp-rename gulp-minify-css gulp-cssnano gulp-sass gulp-sourcemaps del gulp-imagemin gulp-plumber gulp-cache gulp-bootlint gulp-notify browser-sync --dev
3. Configure the location variables in the gulpfile.js to point to your CSS/SCSS/SASS directories that you are using.
4. run gulp to start
*/
@benald
benald / FiltersPage.php
Created December 1, 2017 04:40
SIlverstripe 3.5 filters page
<?php
class FiltersPage extends Page {
private static $has_many = array (
'Types' => 'Type',
'Services' => 'Service',
'Industries' => 'Industry',
'Approaches' => 'Approach',