Skip to content

Instantly share code, notes, and snippets.

View nanna-dk's full-sized avatar

Nanna nanna-dk

View GitHub Profile
@nanna-dk
nanna-dk / filter-and-pagination.js
Last active June 24, 2025 08:55
Filter, sort and paginate a list of items. Handles special characters as well.
document.addEventListener('DOMContentLoaded', () => {
'use strict';
/**
* Script to handle filtering, sorting and pagination out of a list of items
*/
const pagination = (el) => {
// Get current html document language
const lang = document.documentElement.lang;
/**
* Source: https://codyhouse.co/ds/components/info/swipe-content
* To activate the touch gesture detection for a specific element, add the js-swipe class to that element.
*/
const runSwipeContent = () => {
const swipeEl = document.querySelectorAll('.js-swipe');
class SwipeContent {
constructor(element) {
@nanna-dk
nanna-dk / parseFeed.php
Last active June 24, 2025 09:15
PHP proxy for xml/rss feeds - sets headers (domains and subdomains) to fix CORS issues. Works with POST and GET.
<?php
/*
* PHP Proxy
* Responds to both HTTP GET and POST requests
* Usage:
* https://this-url/parseFeed.php?url=" + encodeURIComponent(external-source) + "&amp;mimeType=application/rss+xml.
*/
$url = $_POST['url'] ?? ($_GET['url'] ?? null);
$mimeType = $_POST['mimeType'] ?? ($_GET['mimeType'] ?? null);
$isPost = isset($_POST['url']);
@nanna-dk
nanna-dk / Scroll-progress-indicator.js
Last active September 17, 2021 11:33
Accessible scroll progress indicator
<script>
document.addEventListener('DOMContentLoaded', () => {
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
if (reduceMotion.matches) {
return;
}
let scrollPosition = 0;
let tick = false;
const scrollProgress = () => {
document.addEventListener('DOMContentLoaded', function() {
var lang = document.documentElement.lang;
var translations;
if (lang == 'da') {
translations = {
'pause': 'Stop afspilning (brug Enter tast)',
'play': 'Afspil (brug Enter tast)'
}
} else {
translations = {
@nanna-dk
nanna-dk / secondsToHms.js
Created April 28, 2021 11:17
Seconds to hours, minutes and seconds
var lang = navigator.language || navigator.userLanguage;
if (lang == 'da' || lang == 'da-DK') {
t = {
"hr": "time",
"hrs": "timer",
"min": "minut",
"mins": "minutter",
"sec": "sekund",
"secs": "sekunder"
}
@nanna-dk
nanna-dk / 23video-events.js
Created October 29, 2020 13:19 — forked from steffentchr/23video-events.js
A sample script for GlueFrame, illustrating how to implement a generic analytics tag, which listens to events from 23 Video player.
(function(){
var identifiedFrames = [];
// Method to run any reporting
var report = function(Player, event, playing, duration) {
Player.get('currentTime', function(currentTime){
Player.get('duration', function(duration){
console.log(event, playing, currentTime, duration);
});
});
@nanna-dk
nanna-dk / multiple-slick-slideshows.js
Created January 29, 2020 14:22
Multiple slick sliders
$(function () {
var $slideshow = $(".carousel");
$slideshow.each(function () {
if ($(this).is(".type-one-carousel")) {
$(this).slick({
dots: true,
infinite: true,
slidesToShow: 2
@nanna-dk
nanna-dk / get-average-color-from-image.js
Last active September 24, 2019 09:15
Get average color of image via Javascript
Setting the BODY's background to the average color in the following image:
<img id="i" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QBKRXhpZgAASUkqAAgAAAADABoBBQABAAAAMgAAABsBBQABAAAAOgAAACgBAwABAAAAAgAAAAAAAAAAcDg5gJaYAABwODmAlpgA/9sAQwAFAwQEBAMFBAQEBQUFBgcMCAcHBwcPCwsJDBEPEhIRDxERExYcFxMUGhURERghGBodHR8fHxMXIiQiHiQcHh8e/9sAQwEFBQUHBgcOCAgOHhQRFB4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4e/8AAEQgAqgDiAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX2
@nanna-dk
nanna-dk / svg.html
Created March 12, 2019 10:09
Change opacity of an area based on mouse position
<!DOCTYPE html>
<html>
<head>
<style> .one{
opacity:.5;
}
</style>
</head>