Skip to content

Instantly share code, notes, and snippets.

@Sjeiti
Sjeiti / middleEllipsis.html
Last active March 18, 2018 12:17 — forked from anonymous/fiddle.html
Javascript solution for middle ellipsis (see: https://jsfiddle.net/Sjeiti/cxsqv50n/)
<main>
<h1 data-middle-ellipsis>A Javascript solution to middle ellipsis</h1>
<div data-middle-ellipsis>The quick fox</div>
<div data-middle-ellipsis class="inline-block">The lazy dog</div>
<div data-middle-ellipsis>theQuickBrownFoxJumpsOverTheLazyDog</div>
<div data-middle-ellipsis class="bold">The quick brown fox jumps over the lazy dog</div>
<div data-middle-ellipsis class="small">The quick brown fox jumps over the lazy dog</div>
<div data-middle-ellipsis class="small bold">The quick brown fox jumps over the lazy dog</div>
<div data-middle-ellipsis class="large">The quick brown fox jumps over the lazy dog</div>
<div data-middle-ellipsis>The quick brown fox jumps over the lazy dog</div>
@Sjeiti
Sjeiti / index.html
Created March 7, 2017 08:48
Simple HTML / pure JS example for element in viewport detection
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
<body>
<main>
<section data-in-view>
<h3>consectetur</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Amet consequatur consequuntur dolores praesentium quisquam saepe, ut. Adipisci alias commodi consequuntur enim, expedita iusto magni officiis pariatur repellat, sequi temporibus totam.</p>
</section>
@Sjeiti
Sjeiti / gist:1ee7c1054dca8ef6004e
Created July 3, 2015 09:22
querySelectorParents: traverse an elements parentNodes until the selector is matched
function querySelectorParents(elm,selector){
var result;
while ((elm=elm.parentNode)&&elm!==document) {
if (elm.matches(selector)) {
result = elm;
break;
}
}
return result;
}
/**
* Get a random lorem ipsum string
* Set prng by using getLorem.setPrng(lcg)
* @param words
* @param sentences
* @param paragraphs
* @returns {string}
*/
var getLorem = (function(){
var loremList = 'a et at in mi ac id eu ut non dis cum sem dui nam sed est nec sit mus vel leo urna duis quam cras nibh enim quis arcu orci diam nisi nisl nunc elit odio amet eget ante erat eros ipsum morbi nulla neque vitae purus felis justo massa donec metus risus curae dolor etiam fusce lorem augue magna proin mauris nullam rutrum mattis libero tellus cursus lectus varius auctor sociis ornare magnis turpis tortor semper dictum primis ligula mollis luctus congue montes vivamus aliquam integer quisque feugiat viverra sodales gravida laoreet pretium natoque iaculis euismod posuere blandit egestas dapibus cubilia pulvinar bibendum faucibus lobortis ultrices interdum maecenas accumsan vehicula nascetur molestie sagittis eleifend facilisi suscipit volutpat venenatis fringilla elementum tristique penatibus porttitor imperdi
@Sjeiti
Sjeiti / protectedInheritance.js
Last active August 29, 2015 14:15
An example of protected methods and prototypal inheritance
/**
* An example of protected methods and prototypal inheritance
* @requires lodash
* @param {string} name Call it something
* @param {object} extend An object with functions to override
* @returns {object}
*/
var baseFoo = (function(){
var basePrototype = {
protectedMethod: protectedMethod
@Sjeiti
Sjeiti / lcg.js
Last active August 29, 2015 14:15
Implementation of a linear congruential generator.
/**
* Implementation of a linear congruential generator.<br/>
* The linear congruential generator follows this formula: x=(a*x+c)%n where a=multiplier, c=increment and m=modulus.<br/>
* Multiplier, increment and modulus can be set separately or via one of the presets.<br/>
* By default the Lehmer prng is used.
* @summary Linear congruential generator
*/
var lcg = (function(){
'use strict';
var iMultiplier = 48271
@Sjeiti
Sjeiti / Krpano simplexIdle plugin
Created May 29, 2014 19:53
The simplexIdle plugin for Krpano uses Simplex noise to look around and zoom when the panorama is idle. The movement is random but not as random as Brownian motion. Simplex noise, like Perlin noise, interpolates between random numbers. The result is a motion that could be perceived as life-like.
/*global requestAnimFrame*/
/**!
* Krpano simplexIdle plugin
* The simplexIdle plugin uses Simplex noise to look around and zoom when the panorama is idle. The movement is random but not as random as Brownian motion. Simplex noise, like Perlin noise, interpolates between random numbers. The result is a motion that could be perceived as life-like.
* Additional copyrights and acknowlegdements:
* - Simplex noise: Stefan Gustavson, Sean McCullough, Karsten Schmidt, Ron Valstar
* - requestAnimFrame: Paul Irish, mr Doob
* @summary Idle panoramas move around randomly.
* @name simplexIdle
* @version 1.1.4
@Sjeiti
Sjeiti / breakPoints
Last active August 29, 2015 14:01
Find breakPoints by searching through the document.styleSheets
/*global signals, CSSMediaRule*/
window.breakPoints = (function(signal){
'use strict';
window.addEventListener('load',function(){
var forEach = Array.prototype.forEach
,aSizes = [Number.MAX_VALUE]
,iSizes
,iCurrent = -1
;
// loop styleSheets, then cssRules, then media
@Sjeiti
Sjeiti / rootStyle.js
Last active December 3, 2019 09:28
Javascript to manipulate existing stylesheets
/**
* Manipulate existing stylesheets.
* @name rootStyle
*/
window.rootStyle = (function() {
'use strict';
// StyleSheet.addRule shim
if (document.styleSheets[0].addRule===undefined) {
window.StyleSheet.prototype.addRule = function(selector,value){
@Sjeiti
Sjeiti / objectPool.js
Created September 3, 2013 11:49
Simple object pool
if (!window.myObj) {
myObj = (function(){
var aPool = [];
function obj(x,y) {
var fX,fY
,oObj = {
set:set
,drop:drop
}
;