This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//count elements, return jQuery object if more than specified, else return empty object to 'stop' chaining | |
// usage: $('myElement').atLeast(2).fadeOut(); fadeOut will only execute on elements when 2 or more have been found | |
(function ($) { | |
"use strict"; | |
$.fn.atLeast = function (count) { | |
if (this.length >= count) { | |
//return the objects | |
return this; | |
} else { | |
//return empty jquery object to 'break' the chain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.isVisible = function() { | |
// Am I visible? | |
// Height and Width are not explicitly necessary in visibility detection, the bottom, right, top and left are the | |
// essential checks. If an image is 0x0, it is technically not visible, so it should not be marked as such. | |
// That is why either width or height have to be > 0. | |
var rect = this[0].getBoundingClientRect(); | |
return ( | |
(rect.height > 0 || rect.width > 0) && | |
rect.bottom > 0 && | |
rect.right > 0 && |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function valBetween($val, $min, $max) { | |
return (Math.min($max, Math.max($min, $val))); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.checkStuck = function (className) { | |
$(this).each(function() { | |
var t = $(this); //preselect | |
t.toggleClass(className, (parseInt(t.css('top'), 10) === t[0].getBoundingClientRect().top)); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).on('click', '#MyDoubleClickElement', function () { | |
var t = $(this), doubleClickInterval = 500; //set up base vars | |
var lastTouch = t.data('lastTouch') || 0, time = new Date().getTime(); //check when this element has been clicked last | |
t.data('lastTouch', time); //store this click time | |
if (time - lastTouch < doubleClickInterval && lastTouch !== 0) { //check if time between this and previous click exceeds the threshhold. If there is no last click registered, don't handle the callback | |
//do your stuff here (execute a callback) | |
alert("Double click!"); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* PRIME - Progressive-Responsive Image Enabler - v2.2.10 - 8/10/2020 | |
* http://code.hnldesign.nl/demo/hnl.prime.html | |
* | |
* Copyright (c) 2014-2020 HN Leussink | |
* Dual licensed under the MIT and GPL licenses. | |
* | |
* Example: http://code.hnldesign.nl/demo/hnl.prime.html | |
* | |
* Feature notes: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* | |
* DEPRECATED, SEE NEW VERSION AT https://gist.github.com/c-kick/d359fce36257cf4c9fb5ea5f2c0033b6 | |
* | |
* | |
* JavaScript function prototype debouncer 3.0 - hnldesign.nl | |
* Based on code by Paul Irish and the original debouncing function from John Hann | |
* http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/ | |
* Register deBouncer as a function prototype. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* CSP Generator v0.2 (C) 2020-10-12 hnldesign.nl / Klaas Leussink | |
* @param array $rules | |
* Rules, specified as an array with rulesets (array) or rules (string). Note that 'hosts' are specified as an array inside the ruleset: | |
* note: it's easier to define hosts in the $domains array (see second param) | |
* array( | |
* 'default-src' => array ( | |
* 'self', | |
* 'data', | |
* 'unsafe-eval', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//26-5-2020 update: possibly shorter, and better, since 'click' now fires on a tap, and is not prevented by the previous script. | |
//Also: more concatenation. | |
$(document).on('touchstart, click', 'a.taphover', function (e) { | |
if (!$(this).hasClass('hover')) { e.preventDefault(); } | |
$('.taphover').not($(this).toggleClass('hover')).removeClass('hover'); | |
}); | |
//the previous version: | |
//taphover - a solution to the lack of hover on touch devices. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** This script adds the current breakpoint-name (as specified in the 'breakpoints' const) | |
* to the body class and notifies anyone listening of the change via the 'breakPointChanged' event. | |
* | |
* Default breakpoint names and cutoff pixel values taken from Bootstrap 5's default responsive breakpoints: | |
* https://getbootstrap.com/docs/5.0/layout/breakpoints/ | |
* | |
* Usage: | |
* - include the script into your page and the class is updated, and will continue to update whenever | |
* the width of the window changes enough to trigger another breakpoint. | |
* - optionally listen for the event via: |
OlderNewer