Skip to content

Instantly share code, notes, and snippets.

View FuruholmAnton's full-sized avatar

Anton Furuholm FuruholmAnton

View GitHub Profile
@FuruholmAnton
FuruholmAnton / animate-loading-bar.js
Last active July 5, 2022 16:33
Animates a loading bar with GSAP
'use strict';
import gsap from 'gsap';
let animationDuration = () => { return (Math.sqrt(window.innerWidth) / 9)};
let secoundStartValue;
let secoundStartFn = () => { return animationDuration() * 0.5 }
let colors = ['#daa9ae', '#98b8c1', '#d6deeb', '#acb198'];
/**
<?php
// Check if the flexible content field has rows of data:
if (have_rows('sections')):
// Loop through the rows of data:
while (have_rows('sections')) : the_row();
// Load the corresponding template file:
include(locate_template('templates/'.get_row_layout().'.php'));
endwhile;
endif;
?>
/*---------- VIDEO ----------*/
var video = (function() {
'use strict';
function video(elem) {
// enforces new
if (!(this instanceof video)) {
return new video(elem);
}
this.player = document.querySelector(elem);
// Hide Header on on scroll down
var didScroll;
var lastScrollTop = 0;
var delta = 5;
var navbar = document.querySelector(".site-header");
var navbarHeight = navbar.offsetHeight;
window.addEventListener("scroll", function(){
didScroll = true;
function get_current_url($strip = true) {
// filter function
static $filter;
if ($filter == null) {
$filter = function($input) use($strip) {
$input = str_ireplace(array(
"\0", '%00', "\x0a", '%0a', "\x1a", '%1a'), '', urldecode($input));
if ($strip) {
$input = strip_tags($input);
}
<?php
function my_excerpt($excerpt, $maxLength = 200){
$excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
$fullLength = strlen($excerpt);
$excerpt = substr($excerpt, 0, $maxLength);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
@FuruholmAnton
FuruholmAnton / Gulpfile
Last active June 9, 2016 11:25
SASS Gulp file
var gulp = require('gulp');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var sassdoc = require('sassdoc');
var input = './assets/scss/**/*.scss';
var output = './assets/css';
var sassOptions = {
var getAbsoluteUrl = (function() {
var a;
return function(url) {
if(!a) a = document.createElement('a');
a.href = url;
return a.href;
};
})();
function once(fn, context) {
var result;
return function() {
if(fn) {
result = fn.apply(context || this, arguments);
fn = null;
}
return result;
@FuruholmAnton
FuruholmAnton / Poll
Last active April 6, 2016 07:39
Sometimes you don't get to plug into an event to signify a desired state -- if the event doesn't exist, you need to check for your desired state at intervals: (Source: https://davidwalsh.name/essential-javascript-functions)
function poll(fn, callback, errback, timeout, interval) {
var endTime = Number(new Date()) + (timeout || 2000);
interval = interval || 100;
(function p() {
// If the condition is met, we're done!
if(fn()) {
callback();
}
// If the condition isn't met but the timeout hasn't elapsed, go again