HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<span id="searchLabelText" class="searchLabelText">Here's to the crazy ones. The misfits. The rebels. The troublemakers. The round pegs in the square holes</span>
#searchLabelText {
font-size:250%;
}
/* rainbows going from red to green to blue. I use a script to
create the later rainbows from the previous ones. The script
calculates the 'in-between' colors */
var rainbowOfDarkStrongColors3InCycle = [
'rgb(255,0,0)',
'rgb(0,128,0)',
'rgb(0,0,255)'
];
var rainbowOfDarkStrongColors6InCycle = [
'rgb(0,0,255)',
'rgb(128,0,128)',
'rgb(255,0,0)',
'rgb(128,64,0)',
'rgb(0,128,0)',
'rgb(0,64,128)'
];
var rainbowOfDarkStrongColors12InCycle = [
'rgb(0,64,128)',
'rgb(0,32,192)',
'rgb(0,0,255)',
'rgb(64,0,192)',
'rgb(128,0,128)',
'rgb(192,0,64)',
'rgb(255,0,0)',
'rgb(192,32,0)',
'rgb(128,64,0)',
'rgb(64,96,0)',
'rgb(0,128,0)',
'rgb(0,96,64)'
];
var rainbowOfDarkStrongColors24InCycle = [
'rgb(0,96,64)',
'rgb(0,80,96)',
'rgb(0,64,128)',
'rgb(0,48,160)',
'rgb(0,32,192)',
'rgb(0,16,224)',
'rgb(0,0,255)',
'rgb(32,0,224)',
'rgb(64,0,192)',
'rgb(96,0,160)',
'rgb(128,0,128)',
'rgb(160,0,96)',
'rgb(192,0,64)',
'rgb(224,0,32)',
'rgb(255,0,0)',
'rgb(224,16,0)',
'rgb(192,32,0)',
'rgb(160,48,0)',
'rgb(128,64,0)',
'rgb(96,80,0)',
'rgb(64,96,0)',
'rgb(32,112,0)',
'rgb(0,128,0)',
'rgb(0,112,32)'
];
var rainbowOfDarkStrongColors48InCycle = [
'rgb(0,112,32)',
'rgb(0,104,48)',
'rgb(0,96,64)',
'rgb(0,88,80)',
'rgb(0,80,96)',
'rgb(0,72,112)',
'rgb(0,64,128)',
'rgb(0,56,144)',
'rgb(0,48,160)',
'rgb(0,40,176)',
'rgb(0,32,192)',
'rgb(0,24,208)',
'rgb(0,16,224)',
'rgb(0,8,240)',
'rgb(0,0,255)',
'rgb(16,0,240)',
'rgb(32,0,224)',
'rgb(48,0,208)',
'rgb(64,0,192)',
'rgb(80,0,176)',
'rgb(96,0,160)',
'rgb(112,0,144)',
'rgb(128,0,128)',
'rgb(144,0,112)',
'rgb(160,0,96)',
'rgb(176,0,80)',
'rgb(192,0,64)',
'rgb(208,0,48)',
'rgb(224,0,32)',
'rgb(240,0,16)',
'rgb(255,0,0)',
'rgb(240,8,0)',
'rgb(224,16,0)',
'rgb(208,24,0)',
'rgb(192,32,0)',
'rgb(176,40,0)',
'rgb(160,48,0)',
'rgb(144,56,0)',
'rgb(128,64,0)',
'rgb(112,72,0)',
'rgb(96,80,0)',
'rgb(80,88,0)',
'rgb(64,96,0)',
'rgb(48,104,0)',
'rgb(32,112,0)',
'rgb(16,120,0)',
'rgb(0,128,0)',
'rgb(0,120,16)'
];
var rainbowOfDarkStrongColors96InCycle = [
'rgb(0,120,16)',
'rgb(0,116,24)',
'rgb(0,112,32)',
'rgb(0,108,40)',
'rgb(0,104,48)',
'rgb(0,100,56)',
'rgb(0,96,64)',
'rgb(0,92,72)',
'rgb(0,88,80)',
'rgb(0,84,88)',
'rgb(0,80,96)',
'rgb(0,76,104)',
'rgb(0,72,112)',
'rgb(0,68,120)',
'rgb(0,64,128)',
'rgb(0,60,136)',
'rgb(0,56,144)',
'rgb(0,52,152)',
'rgb(0,48,160)',
'rgb(0,44,168)',
'rgb(0,40,176)',
'rgb(0,36,184)',
'rgb(0,32,192)',
'rgb(0,28,200)',
'rgb(0,24,208)',
'rgb(0,20,216)',
'rgb(0,16,224)',
'rgb(0,12,232)',
'rgb(0,8,240)',
'rgb(0,4,248)',
'rgb(0,0,255)',
'rgb(8,0,248)',
'rgb(16,0,240)',
'rgb(24,0,232)',
'rgb(32,0,224)',
'rgb(40,0,216)',
'rgb(48,0,208)',
'rgb(56,0,200)',
'rgb(64,0,192)',
'rgb(72,0,184)',
'rgb(80,0,176)',
'rgb(88,0,168)',
'rgb(96,0,160)',
'rgb(104,0,152)',
'rgb(112,0,144)',
'rgb(120,0,136)',
'rgb(128,0,128)',
'rgb(136,0,120)',
'rgb(144,0,112)',
'rgb(152,0,104)',
'rgb(160,0,96)',
'rgb(168,0,88)',
'rgb(176,0,80)',
'rgb(184,0,72)',
'rgb(192,0,64)',
'rgb(200,0,56)',
'rgb(208,0,48)',
'rgb(216,0,40)',
'rgb(224,0,32)',
'rgb(232,0,24)',
'rgb(240,0,16)',
'rgb(248,0,8)',
'rgb(255,0,0)',
'rgb(248,4,0)',
'rgb(240,8,0)',
'rgb(232,12,0)',
'rgb(224,16,0)',
'rgb(216,20,0)',
'rgb(208,24,0)',
'rgb(200,28,0)',
'rgb(192,32,0)',
'rgb(184,36,0)',
'rgb(176,40,0)',
'rgb(168,44,0)',
'rgb(160,48,0)',
'rgb(152,52,0)',
'rgb(144,56,0)',
'rgb(136,60,0)',
'rgb(128,64,0)',
'rgb(120,68,0)',
'rgb(112,72,0)',
'rgb(104,76,0)',
'rgb(96,80,0)',
'rgb(88,84,0)',
'rgb(80,88,0)',
'rgb(72,92,0)',
'rgb(64,96,0)',
'rgb(56,100,0)',
'rgb(48,104,0)',
'rgb(40,108,0)',
'rgb(32,112,0)',
'rgb(24,116,0)',
'rgb(16,120,0)',
'rgb(8,124,0)',
'rgb(0,128,0)',
'rgb(0,124,8)'
];
var _Array_prototype = Array.prototype;
/**
* @constructor
*/
function IndexandElement(index, eLement)
{
this.index = index;
this.element = eLement;
}
_Array_prototype.myGetRandomIndexAndElement = function()
{
var countElementsInArray = this.length;
var randomIndexAndElement = null;
switch(countElementsInArray) {
case 0:
randomIndexAndElement = null;
break;
case 1:
randomIndexAndElement = new IndexandElement(0, this[0]);
break;
default:
var randomIndexInArray = Math.floor(Math.random() *
countElementsInArray);
var randomElementInArray = this[randomIndexInArray];
randomIndexAndElement = new IndexandElement(
randomIndexInArray,
randomElementInArray);
break;
}
return randomIndexAndElement;
};
_Array_prototype.myGetRandomIndx = function()
{
var randomIndex;
var randomIndexAndElement = this.myGetRandomIndexAndElement();
if (randomIndexAndElement === null) {
randomIndex = null;
} else {
randomIndex = randomIndexAndElement.index;
}
return randomIndex;
};
_Array_prototype.myGetRandomElemnt = function()
{
var randomElement;
var randomIndexAndElement = this.myGetRandomIndexAndElement();
if (randomIndexAndElement === null) {
randomElement = null;
} else {
randomElement = randomIndexAndElement.element;
}
return randomElement;
};
/* Class to get a random number from a given set of numbers */
/**
* @constructor
*/
function RandomNumbersFromSet(lowest, highest /*, numToExclude */
/* or setOfNumbers (array) [ , copyArray (true/false) ] ) */ )
{
if (lowest instanceof Array) {
var setOfNumbers = lowest;
if (arguments.length > 1 && arguments[1] === false) {
this.setOfNumbers = setOfNumbers;
} else {
this.setOfNumbers = [];
this.setOfNumbers = this.setOfNumbers.concat(setOfNumbers);
}
this.countSetOfNumbers = this.setOfNumbers.length;
return;
}
this.setOfNumbers = [];
var excludeNum = false;
var numToExclude;
if (arguments.length > 2 && arguments[2] !== null &&
lowest !== highest ) {
excludeNum = true;
numToExclude = arguments[2];
}
for (var i = lowest; i <= highest; i++) {
if (excludeNum && i === numToExclude) {
// skip
} else {
this.setOfNumbers.push(i);
}
}
this.countSetOfNumbers = this.setOfNumbers.length;
} /* end of RandomNumbersFromSet class */
//var RandomElementsFromSet = RandomNumbersFromSet;
RandomNumbersFromSet.prototype.getnumber = function()
{
var number;
if (this.countSetOfNumbers === 0) {
number = null;
} else if (this.countSetOfNumbers === 1) {
number = this.setOfNumbers[0];
this.setOfNumbers.length = 0;
this.countSetOfNumbers--;
} else {
var index = Math.floor(Math.random() * this.countSetOfNumbers);
number = this.setOfNumbers[index];
this.setOfNumbers.splice(index, 1); // remove item
this.countSetOfNumbers--;
}
return number;
};
RandomNumbersFromSet.prototype.getElmnt =
RandomNumbersFromSet.prototype.getnumber;
RandomNumbersFromSet.prototype.isEmpty = function()
{
return this.countSetOfNumbers === 0;
};
RandomNumbersFromSet.prototype.rnfsGetNumbersLeft = function()
{
return this.setOfNumbers;
};
/* class to get random numbers from a given set of numbers and not
repeat a number. In fact, goes through all the numbers in the set
and then starts afresh. Uses the class 'RandomNumbersFromSet' */
/**
* @constructor
*/
//TODO: gotoplanb
function RandomElementsfromArrayWithNoRepeats(
theArray /* or lowestNumber, highestNumber */ )
{
if (typeof theArray === 'number' && arguments.length >= 2) {
var lowest = theArray;
var heighest = arguments[1];
this.theArray = [];
for (var i = lowest; i <= heighest; i++) {
this.theArray.push(i);
}
} else {
this.theArray = theArray;
}
this.randomNumbersFromSet = null;
this.lastNumber = null;
this.renrSetup();
} /* end of RandomElementsfromArrayWithNoRepeats class */
/**
* @constructor
*/
RandomElementsfromArrayWithNoRepeats.prototype.renrSetup = function()
{
this.randomNumbersFromSet =
new RandomNumbersFromSet(0, this.theArray.length - 1,
this.lastNumber);
};
RandomElementsfromArrayWithNoRepeats.prototype.getelement = function()
{
if (this.randomNumbersFromSet === null ||
this.randomNumbersFromSet.isEmpty() ) {
this.renrSetup();
}
var arrayIndex = this.randomNumbersFromSet.getnumber();
this.lastNumber = arrayIndex;
return this.theArray[arrayIndex];
};
RandomElementsfromArrayWithNoRepeats.prototype.isEmpty = function()
{
return this.randomNumbersFromSet.isEmpty();
};
function ElementsFromArrayInOrder(a, startonEven, startOnOdd, increment /* , debug */)
/* Notes:
- 'startonEven' means starting on element 0, 2, 4 etc */
{
this.a = a;
this.l = a.length;
this.i = 0;
this.startOnEven = startonEven;
this.startOnOdd = startOnOdd;
if (increment === undefined) {
increment = 1;
}
//TODO: rm else {}
else {
//window.alert('sinc: ' + increment);
}
this.increment = increment;
//TODO: rm
//this.debug = debug;
this.setRandomStart();
}
ElementsFromArrayInOrder.prototype.setRandomStart = function()
{
var si = Math.floor(Math.random() * this.l);
// TODO: rm
//if (this.debug) {
// window.alert('raw:' + si);
//}
if (this.startOnEven) {
si = Math.floor(si / 2) * 2;
} else if (this.startOnOdd) {
var isEven = si % 2 == 0;
if (isEven) {
var isLast = si === this.l - 1;
if (isLast) {
si--;
} else if (si === 0) {
si++;
} else {
var goUp = Math.random() < 0.5;
if (goUp) {
si++;
} else {
si--;
}
}
}
}
/* TODO: rm
if (this.debug) {
window.alert('mod:' + si);
}
*/
this.s = si;
this.i = si;
this.inc = (Math.random() < 0.5) ? 1 : -1;
this.sinc = (Math.random() < 0.5) ?
this.increment : -this.increment;
};
ElementsFromArrayInOrder.prototype.incrementStart = function()
{
this.s += this.sinc;
if (this.s >= this.l) {
this.s = this.s - this.l; // 0
} else if (this.s < 0) {
this.s = this.l + this.s; //this.l - 1
}
this.i = this.s;
};
ElementsFromArrayInOrder.prototype.get = function()
{
if (this.i >= this.l) {
this.i = 0;
} else if (this.i < 0) {
this.i = this.l - 1;
}
var ret = this.a[this.i];
/* TODO: rm
if (this.debug) {
window.alert('get:' + this.i + ',' + this.a + ',' + ret);
}
*/
this.i += this.inc;
return ret;
};
function myAddSpanAroundEachTextChar(s, cssClass)
{
var len = s.length;
var i;
var chr;
var ss = '';
var openTag = '<span class="' + cssClass + '">';
for (i = 0; i < len; i++) {
chr = s[i];
if (chr === ' ') {
ss += chr;
} else {
//TODO: rm
//ss += '<span>' + chr + '</span>';
ss += openTag + chr + '</span>';
}
}
return ss;
}
function myGetSpanElementsAroundText(firstNode)
{
var a = [];
var n;
for (n = firstNode; n ; n = n.nextSibling) {
if (n.nodeName === 'SPAN') {
a.push(n);
}
}
return a;
}
var isIntersectionObserver =
typeof IntersectionObserver !== 'undefined';
function SetupObserverCommon(indexImage, targetElementId, indexImage2)
{
this.indexImage = indexImage;
this.targetElementId = targetElementId;
this.indexImage2 = indexImage2;
this.isRunning = false;
} // end class SetupObserverCommon()
SetupObserverCommon.prototype.start = function()
{
this.isRunning = false;
var that = this;
function callback (entries)
{
var i;
var c = entries.length;
var e;
for (i = 0; i < c; i++) {
e = entries[i];
//alert(e.isIntersecting);
var isVisible = e.isIntersecting;
if (isVisible) {
if (!that.isRunning) {
/*
if (that.isRunning === undefined) {
//alert('initialise');
//that.indexImage2.obsInitialise();
}
*/
//alert('start:'+that.targetElementId);
that.indexImage.obsStart();
if (that.indexImage2) {
that.indexImage2.obsStart();
}
that.isRunning = true;
}
} else /* not visible */ {
if (that.isRunning) {
//alert('stop:'+that.targetElementId);
that.indexImage.obsStop();
if (that.indexImage2) {
that.indexImage2.obsStop();
}
that.isRunning = false;
}
}
}
}
//alert('initialise@setup:'+that.targetElementId);
that.indexImage.obsInitialise();
if (that.indexImage2) {
that.indexImage2.obsInitialise();
}
var options = {
root: null,
rootMargin: '0px',
threshold: 0.1
};
var observer = new IntersectionObserver(callback, options);
//var target = document.getElementById('freesoundList');
var target = document.getElementById(that.targetElementId);
observer.observe(target);
}; // end method SetupObserverCommo.start()
function setupObserverCommon(indexImage, targetElementId, indexImage2)
{
var myObserver =
new SetupObserverCommon(indexImage, targetElementId,
indexImage2);
myObserver.start();
}
function TickerForTwinkleTextCommon(setFunction, minTimeBetweenUpdates, maxTimeBetweenUpdates, defaultTimeBetweenUpdates, isCreateTransStyle, delayBetweenAddColorandCreateTwinkleStylesheetAtStart, doc, headElement, envForSetFunction, stopFunction, twinkleCSSClass, debugLabel)
{
var udef;
this.setFunction = setFunction;
this.stopFunction = stopFunction;
this.minTimeBetweenUpdates = minTimeBetweenUpdates;
this.maxTimeBetweenUpdates = maxTimeBetweenUpdates;
this.defaultTimeBetweenUpdates = defaultTimeBetweenUpdates;
this.isCreateTransStyle = isCreateTransStyle;
this.delayBetweenAddColorandCreateTwinkleStylesheetAtStart =
delayBetweenAddColorandCreateTwinkleStylesheetAtStart;
this.doc = doc;
this.headElement = headElement;
this.envForSetFunction = envForSetFunction;
this.debugLabel = debugLabel;
this.mTimeBetweenUpdatesForTickerForTwinkleText = udef;
this.mTimeoutIdForNext = null;
this.mTimeoutIdForDelayCreateStyleReadyNext = null;
this.firstTime = true;
this.twinkleCSSClass = twinkleCSSClass;
}
// TickerForTwinkleTextCommon.prototype.initialise = function()
// {
// }
TickerForTwinkleTextCommon.prototype.setRandomTimeBetweenUpdates = function()
{
var intervalForTimeBetweenUpdates =
this.maxTimeBetweenUpdates -
this.minTimeBetweenUpdates;
var randomIntervalForTimeBetweenUpdates =
Math.random() * intervalForTimeBetweenUpdates;
var timeBetweenUpdates =
this.minTimeBetweenUpdates +
randomIntervalForTimeBetweenUpdates;
this.mTimeBetweenUpdatesForTickerForTwinkleText =
timeBetweenUpdates;
//TODO: rm
/*
window.alert('warntckr:setNxtTm:' +
mTimeBetweenUpdatesForTickerForTwinkleText);
*/
};
TickerForTwinkleTextCommon.prototype.createTransitionStylesheet = function(transitionDuration)
{
if (transitionDuration === undefined) {
transitionDuration =
this.mTimeBetweenUpdatesForTickerForTwinkleText;
}
//TODO: rm
//removeAnyTransitionStylesheet();
var transitionStylesheet = this.doc.createElement('style');
var transitionDurationInCSS = Math.floor(transitionDuration);
var endOFTransition =
transitionDurationInCSS + 'ms linear';
var wholeColorTransition =
'color ' + endOFTransition + ', ' +
'border-color ' + endOFTransition + ';';
var twinkleCSSClass = this.twinkleCSSClass;
if (!twinkleCSSClass) {
twinkleCSSClass = 'Twinkle';
}
var transitionCSS =
//'.Twinkle ' +
'.' + twinkleCSSClass + ' ' +
'{ ' +
' -moz-transition: ' + wholeColorTransition +
' -khtml-transition: ' + wholeColorTransition +
' -webkit-transition: ' + wholeColorTransition +
' -ms-transition: ' + wholeColorTransition +
' -o-transition: ' + wholeColorTransition +
' transition: ' + wholeColorTransition +
// TODO: rm
//' background-color: aqua; ' +
//' color: aqua; ' +
//' border: 1px solid red; ' +
' } ';
// 'a { ' +
// ' color: rgb(70,70,255); ' +
// '} ' +
// 'a:hover { ' +
// ' color: rgb(0,175,0); ' +
// '} ' +
// 'a:active { ' +
// ' color: rgb(210, 210, 210); ' +
// '} ';
transitionStylesheet.innerHTML = transitionCSS;
//TODO: rm
//window.alert('tckrStyl:' + transitionStylesheet.innerHTML);
//TODO: rm
//mTransitionStylesheet = transitionStylesheet;
this.headElement.appendChild(transitionStylesheet);
};
TickerForTwinkleTextCommon.prototype.set = function()
{
if (this.envForSetFunction) {
this.setFunction.call(this.envForSetFunction);
} else {
this.setFunction();
}
};
TickerForTwinkleTextCommon.prototype.setReadyNext = function()
{
this.set();
this.getReadyNext();
};
TickerForTwinkleTextCommon.prototype.getReadyNext = function(timeDelay)
{
var that = this;
function callSetReadyNext()
{
that.setReadyNext();
}
if (timeDelay === undefined) {
timeDelay =
this.mTimeBetweenUpdatesForTickerForTwinkleText;
}
//setTimeout(this.setReadyNext, timeDelay);
this.mTimeoutIdForNext =
setTimeout(callSetReadyNext, timeDelay);
};
TickerForTwinkleTextCommon.prototype.createTransStyleAndReadyNext = function()
{
if (this.isCreateTransStyle) {
this.createTransitionStylesheet();
}
this.firstTime = false;
var timeDelay =
this.mTimeBetweenUpdatesForTickerForTwinkleText -
this.delayBetweenAddColorandCreateTwinkleStylesheetAtStart;
this.getReadyNext(timeDelay);
};
TickerForTwinkleTextCommon.prototype.callCreateTransStyleReadyNextAfterTimeout = function()
{
var that = this;
function callCreateTransStyleAndReadyNext()
{
that.createTransStyleAndReadyNext();
}
//setTimeout(this.createTransStyleAndReadyNext,
this.mTimeoutIdForDelayCreateStyleReadyNext =
setTimeout(callCreateTransStyleAndReadyNext,
this.delayBetweenAddColorandCreateTwinkleStylesheetAtStart);
//TODO: rm
//mTimeoutIdsForCreateTransStyle = timeoutId;
};
TickerForTwinkleTextCommon.prototype.stop = function()
{
clearTimeout(this.mTimeoutIdForNext);
clearTimeout(this.mTimeoutIdForDelayCreateStyleReadyNext);
this.stopFunction.call(this.envForSetFunction);
};
TickerForTwinkleTextCommon.prototype.obsStop = function()
{
this.stop();
//alert('txtColr:obsStop:'+this.debugLabel);
};
TickerForTwinkleTextCommon.prototype.start = function()
{
if (this.firstTime) {
this.setRandomTimeBetweenUpdates();
this.callCreateTransStyleReadyNextAfterTimeout();
} else {
this.setReadyNext();
}
};
TickerForTwinkleTextCommon.prototype.obsStart = function()
{
this.start();
//alert('txtColr:obsStart:'+this.debugLabel);
};
TickerForTwinkleTextCommon.prototype.obsInitialise = function()
{
//alert('txtColr:obsInit');
};
function AddTextColorsToTwinkleTextCommon(stepInterval, numberOfstepsWanted /*setFunction, minTimeBetweenUpdates, maxTimeBetweenUpdates, defaultTimeBetweenUpdates, isCreateTransStyle, delayBetweenAddColorandCreateTwinkleStylesheetAtStart, doc, headElement*/)
{
// var udef;
//
// this.setFunction = setFunction;
// this.minTimeBetweenUpdates = minTimeBetweenUpdates;
// this.maxTimeBetweenUpdates = maxTimeBetweenUpdates;
// this.defaultTimeBetweenUpdates = defaultTimeBetweenUpdates;
// this.isCreateTransStyle = isCreateTransStyle;
// this.delayBetweenAddColorandCreateTwinkleStylesheetAtStart =
// delayBetweenAddColorandCreateTwinkleStylesheetAtStart;
// this.doc = doc;
// this.headElement = headElement;
//
// this.mTimeBetweenUpdatesForTickerForTwinkleText = udef;
if (!stepInterval) {
stepInterval = 500;
}
this.mStepInterval = stepInterval;
this.mNumberOfstepsWanted = numberOfstepsWanted;
this.mRainbowofDarkStrongColors3InCycle =
window.rainbowOfDarkStrongColors3InCycle;
this.mRainbowofDarkStrongColors6InCycle =
window.rainbowOfDarkStrongColors6InCycle;
this.mRainbowofDarkStrongColors12InCycle =
window.rainbowOfDarkStrongColors12InCycle;
this.mRainbowofDarkStrongColors24InCycle =
window.rainbowOfDarkStrongColors24InCycle;
this.mRainbowofDarkStrongColors48InCycle =
window.rainbowOfDarkStrongColors48InCycle;
this.mRainbowofDarkStrongColors96InCycle =
window.rainbowOfDarkStrongColors96InCycle;
this.mListOfListsOfElements = [];
this.mListOfSelectors = [];
this.mIsBorderColor = [];
this.mStepTimeoutId = null;
}
AddTextColorsToTwinkleTextCommon.prototype.setOneColor = function(twinkleTextelements, selectorforTextColorOfTwinkleTexts, isBorderColor)
{
if (!twinkleTextelements) {
return;
}
var countTwinkleTextElements =
twinkleTextelements.length;
var indexIntoTwinkleTextElements;
var twinkleTextElement;
var textColorOfTwinkleText;
for(indexIntoTwinkleTextElements = 0;
indexIntoTwinkleTextElements <
countTwinkleTextElements;
indexIntoTwinkleTextElements++) {
twinkleTextElement =
twinkleTextelements[
indexIntoTwinkleTextElements];
textColorOfTwinkleText =
selectorforTextColorOfTwinkleTexts.get();
if (isBorderColor) {
twinkleTextElement.style.borderColor =
textColorOfTwinkleText;
} else {
twinkleTextElement.style.color =
textColorOfTwinkleText;
}
}
selectorforTextColorOfTwinkleTexts.incrementStart();
};
AddTextColorsToTwinkleTextCommon.prototype.setElements = function(twinkleTextElements, doSetColor, isBorderColor)
{
var lengthElements = twinkleTextElements.length;
if (!twinkleTextElements) {
return;
}
var colorsForSelector;
var incrementForSelector;
if (lengthElements >= 80) {
colorsForSelector =
this.mRainbowofDarkStrongColors96InCycle;
incrementForSelector = 16;
} else if (lengthElements >= 40) {
colorsForSelector =
this.mRainbowofDarkStrongColors48InCycle;
incrementForSelector = 8;
} else if (lengthElements >= 20) {
colorsForSelector =
this.mRainbowofDarkStrongColors24InCycle;
incrementForSelector = 4;
} else if (lengthElements >= 10) {
colorsForSelector =
this.mRainbowofDarkStrongColors12InCycle;
incrementForSelector = 2;
} else if (lengthElements >= 5) {
colorsForSelector =
this.mRainbowofDarkStrongColors6InCycle;
} else {
colorsForSelector =
this.mRainbowofDarkStrongColors3InCycle;
}
var selectorForTextColorOfTwinkleTexts;
selectorForTextColorOfTwinkleTexts =
new ElementsFromArrayInOrder(
colorsForSelector,
false /* startonEven */,
false /* startOnOdd */,
incrementForSelector);
this.mListOfListsOfElements.
push(twinkleTextElements);
this.mListOfSelectors.
push(selectorForTextColorOfTwinkleTexts);
this.mIsBorderColor.push(isBorderColor);
if (doSetColor === undefined) {
doSetColor = true;
}
if (doSetColor) {
this.setOneColor(twinkleTextElements,
selectorForTextColorOfTwinkleTexts,
isBorderColor);
}
};
AddTextColorsToTwinkleTextCommon.prototype.setColorStepSetCommon = function(startCountLists, endCountLists)
{
var listOfSelectors = this.mListOfSelectors;
var listOfListsOfElements = this.mListOfListsOfElements;
var isBorderColors = this.mIsBorderColor;
var li;
var listOfElements;
var selector;
var setoneColor = this.setOneColor;
var isBorderColor;
for (li = startCountLists; li < endCountLists; li++) {
listOfElements = listOfListsOfElements[li];
selector = listOfSelectors[li];
isBorderColor = isBorderColors[li];
setoneColor(listOfElements, selector,
isBorderColor);
}
};
AddTextColorsToTwinkleTextCommon.prototype.setColorStep2 = function()
{
var listOfSelectors = this.mListOfSelectors;
var countLists = listOfSelectors.length;
var startCountLists = Math.floor(countLists / 8);
var endCountLists = Math.floor(countLists / 4);
this.setColorStepSetCommon(startCountLists, endCountLists);
//setTimeout(setColorStep3, 2000);
var that = this;
function callsetColorStep3()
{
that.setColorStep3();
}
this.mStepTimeoutId = setTimeout(callsetColorStep3,
this.mStepInterval);
};
AddTextColorsToTwinkleTextCommon.prototype.setColorStep3 = function()
{
var listOfSelectors = this.mListOfSelectors;
var countLists = listOfSelectors.length;
var startCountLists = Math.floor(countLists / 4);
var endCountLists = Math.floor(countLists * 3 / 8);
this.setColorStepSetCommon(startCountLists, endCountLists);
//setTimeout(setColorStep4, 2000);
var that = this;
function callsetColorStep4()
{
that.setColorStep4();
}
this.mStepTimeoutId = setTimeout(callsetColorStep4,
this.mStepInterval);
};
AddTextColorsToTwinkleTextCommon.prototype.setColorStep4 = function()
{
var listOfSelectors = this.mListOfSelectors;
var countLists = listOfSelectors.length;
var startCountLists = Math.floor(countLists * 3 / 8);
var endCountLists = Math.floor(countLists / 2);
this.setColorStepSetCommon(startCountLists, endCountLists);
//setTimeout(setColorStep5, 2000);
var that = this;
function callsetColorStep5()
{
that.setColorStep5();
}
this.mStepTimeoutId = setTimeout(callsetColorStep5,
this.mStepInterval);
};
AddTextColorsToTwinkleTextCommon.prototype.setColorStep5 = function()
{
var listOfSelectors = this.mListOfSelectors;
var countLists = listOfSelectors.length;
var startCountLists = Math.floor(countLists / 2 );
var endCountLists = Math.floor(countLists * 5 / 8);
this.setColorStepSetCommon(startCountLists, endCountLists);
//setTimeout(setColorStep6, 2000);
var that = this;
function callsetColorStep6()
{
that.setColorStep6();
}
this.mStepTimeoutId = setTimeout(callsetColorStep6,
this.mStepInterval);
};
AddTextColorsToTwinkleTextCommon.prototype.setColorStep6 = function()
{
var listOfSelectors = this.mListOfSelectors;
var countLists = listOfSelectors.length;
var startCountLists = Math.floor(countLists * 5 / 8 );
var endCountLists = Math.floor(countLists * 3 / 4);
this.setColorStepSetCommon(startCountLists, endCountLists);
//setTimeout(setColorStep7, 2000);
var that = this;
function callsetColorStep7()
{
that.setColorStep7();
}
this.mStepTimeoutId = setTimeout(callsetColorStep7,
this.mStepInterval);
};
AddTextColorsToTwinkleTextCommon.prototype.setColorStep7 = function()
{
var listOfSelectors = this.mListOfSelectors;
var countLists = listOfSelectors.length;
var startCountLists = Math.floor(countLists * 3 / 4 );
var endCountLists = Math.floor(countLists * 7 / 8);
this.setColorStepSetCommon(startCountLists, endCountLists);
//setTimeout(setColorStep8, 2000);
var that = this;
function callsetColorStep8()
{
that.setColorStep8();
}
this.mStepTimeoutId = setTimeout(callsetColorStep8,
this.mStepInterval);
};
AddTextColorsToTwinkleTextCommon.prototype.setColorStep8 = function()
{
var listOfSelectors = this.mListOfSelectors;
var countLists = listOfSelectors.length;
var startCountLists = Math.floor(countLists * 7 / 8);
this.setColorStepSetCommon(startCountLists, countLists);
};
AddTextColorsToTwinkleTextCommon.prototype.setColorStep1 = function()
{
var listOfSelectors = this.mListOfSelectors;
var countLists = Math.floor(listOfSelectors.length / 8);
/*
if (countLists === 0) {
return;
}
*/
this.setColorStepSetCommon(0, countLists);
var that = this;
function callsetColorStep2()
{
that.setColorStep2();
}
this.mStepTimeoutId = setTimeout(callsetColorStep2,
this.mStepInterval);
};
AddTextColorsToTwinkleTextCommon.prototype.setColorOneStep = function()
{
var listOfSelectors = this.mListOfSelectors;
var countLists = listOfSelectors.length;
this.setColorStepSetCommon(0, countLists);
//alert('atxttt:setColorOneStep');
};
AddTextColorsToTwinkleTextCommon.prototype.setColorTwoSteps2 = function()
{
var listOfSelectors = this.mListOfSelectors;
var countLists = listOfSelectors.length;
var startCountLists = Math.floor(countLists / 2);
this.setColorStepSetCommon(startCountLists, countLists);
};
AddTextColorsToTwinkleTextCommon.prototype.setColorTwoSteps1 = function()
{
var listOfSelectors = this.mListOfSelectors;
var countLists = listOfSelectors.length;
var endCountLists = Math.floor(countLists / 2);
this.setColorStepSetCommon(0, endCountLists);
var that = this;
function callsetColorTwoSteps2()
{
that.setColorTwoSteps2();
}
this.mStepTimeoutId = setTimeout(callsetColorTwoSteps2,
this.mStepInterval);
//alert('setColorTwoSteps1:intv:'+this.mStepInterval);
};
AddTextColorsToTwinkleTextCommon.prototype.setColorTwoSteps = function()
{
this.setColorTwoSteps1();
//alert('atxttt:setColorTwoSteps');
};
AddTextColorsToTwinkleTextCommon.prototype.setColorFourSteps1 = function()
{
var listOfSelectors = this.mListOfSelectors;
var countLists = listOfSelectors.length;
var endCountLists = Math.floor(countLists / 4);
this.setColorStepSetCommon(0, endCountLists);
var that = this;
function callsetColorFourSteps2()
{
that.setColorFourSteps2();
}
this.mStepTimeoutId = setTimeout(callsetColorFourSteps2,
this.mStepInterval);
};
AddTextColorsToTwinkleTextCommon.prototype.setColorFourSteps2 = function()
{
var listOfSelectors = this.mListOfSelectors;
var countLists = listOfSelectors.length;
var startCountLists = Math.floor(countLists / 4);
var endCountLists = Math.floor(countLists / 2);
this.setColorStepSetCommon(startCountLists, endCountLists);
var that = this;
function callsetColorFourSteps3()
{
that.setColorFourSteps3();
}
this.mStepTimeoutId = setTimeout(callsetColorFourSteps3,
this.mStepInterval);
};
AddTextColorsToTwinkleTextCommon.prototype.setColorFourSteps3 = function()
{
var listOfSelectors = this.mListOfSelectors;
var countLists = listOfSelectors.length;
var startCountLists = Math.floor(countLists / 2);
var endCountLists = Math.floor(countLists * 3 / 4);
this.setColorStepSetCommon(startCountLists, endCountLists);
var that = this;
function callsetColorFourSteps4()
{
that.setColorFourSteps4();
}
this.mStepTimeoutId = setTimeout(callsetColorFourSteps4,
this.mStepInterval);
};
AddTextColorsToTwinkleTextCommon.prototype.setColorFourSteps4 = function()
{
var listOfSelectors = this.mListOfSelectors;
var countLists = listOfSelectors.length;
var startCountLists = Math.floor(countLists * 3 / 4);
this.setColorStepSetCommon(startCountLists, countLists);
//alert('s44:'+startCountLists+','+countLists);
};
AddTextColorsToTwinkleTextCommon.prototype.setColorFourSteps = function()
{
this.setColorFourSteps1();
//alert('atxttt:setColorFourSteps');
};
AddTextColorsToTwinkleTextCommon.prototype.setColor = function()
{
var numberOfSteps = this.mNumberOfstepsWanted;
if (!numberOfSteps) {
var listOfSelectors = this.mListOfSelectors;
var countLists = listOfSelectors.length;
numberOfSteps = countLists;
}
//alert('atctttc:setColor:#steps'+numberOfSteps);
if (numberOfSteps === 1) {
this.setColorOneStep();
} else if (numberOfSteps === 2) {
this.setColorTwoSteps();
} else if (numberOfSteps <= 4) {
this.setColorFourSteps();
} else {
this.setColorStep1();
}
};
AddTextColorsToTwinkleTextCommon.prototype.stop = function()
{
clearTimeout(this.mStepTimeoutId);
};
function setupAddTextColorForLineOfText(
textElementId,
twinkleClass,
cDefaultTimeBetweenUpdatesForTicker,
cMinTimeBetweenUpdatesForTicker,
cMaxTimeBetweenUpdatesForTicker,
gDelayBetweenAddColorandCreateTwinkleStylesheetAtStart,
isintersectionObserver,
debugLabel
)
{
// if (!isAPowerfulComputer) {
// //alert('no ii1');
// return;
// }
/* how often does the timer 'wake-up'. The color of the words
changes when the timer 'wakes up'. This value is given in
milliseconds. There is a default value which is used
when a random value has not yet been set. Normally,
a random value is chosen which is between a minimum and
maximum value */
/*
var cDefaultTimeBetweenUpdatesForTicker = 3000; //#BCON
var cMinTimeBetweenUpdatesForTicker = 2500; //#BCON
var cMaxTimeBetweenUpdatesForTicker = 3500; //#BCON
*/
// var cDefaultTimeBetweenUpdatesForTicker = 20000; //#BCON
//
// var cMinTimeBetweenUpdatesForTicker = 17000; //#BCON
//
// var cMaxTimeBetweenUpdatesForTicker = 23000; //#BCON
// /* CSS transitions are not added until after HTML elements have been
// coloured. A time delay lets the browser reflow the page.
// This means that the first colouring happens right away.
// Afterwards, when the colour changes, a CSS transition makes
// the colour change slowly. This is for elements whose colour
// changes just after the page has loaded. The time is longer as
// the time taken to load the page may count towards this
// time delay. This is because the 'setTimeout' may run in the
// middle of the page loading. The longer delay makes sure
// the colouring does not happen immediately after page load. I am
// worried (un-necessarily) that a browser like Firefox will not
// cause a delay and the first black-to-color change will
// slowly transition */
//
// var gDelayBetweenAddColorandCreateTwinkleStylesheetAtStart = 1000; //#BCON
var addTextColorsToTwinkleText =
new AddTextColorsToTwinkleTextCommon();
var TickerForTwinkleText;
// var isintersectionObserver = isIntersectionObserver;
function setupTickerForTwinkleText(doc, headelement)
{
//var tickerForTwinkleText;
var isCreateTransStyleValue = false;
var twinkleClassValue = null;
if (isintersectionObserver) {
isCreateTransStyleValue = true;
twinkleClassValue = twinkleClass;
}
TickerForTwinkleText =
new TickerForTwinkleTextCommon(
addTextColorsToTwinkleText.setColor,
cMinTimeBetweenUpdatesForTicker,
cMaxTimeBetweenUpdatesForTicker,
cDefaultTimeBetweenUpdatesForTicker,
isCreateTransStyleValue /*isCreateTransStyle*/,
gDelayBetweenAddColorandCreateTwinkleStylesheetAtStart,
doc,
headelement,
addTextColorsToTwinkleText,
addTextColorsToTwinkleText.stop,
twinkleClassValue,
debugLabel );
} // end of Session setupTickerForTwinkleText function
var doc = document;
function step2b()
{
//var elems = [
// doc.getElementById(textElementId)
// ];
var elem;
//var countElems = elems.length;
//var ei;
var strWithSpans;
var spanElems;
//var twinkleClass;
var str;
//for (ei = 0; ei < countElems; ei++) {
//elem = elems[ei];
elem = doc.getElementById(textElementId);
str = elem.innerHTML;
//twinkleClass = ei === 0 ? 'Twinkle2' : 'twinkle';
strWithSpans = myAddSpanAroundEachTextChar(str, twinkleClass);
//strWithSpans = myAddSpanAroundEachTextChar(str, twinkleClass);
elem.innerHTML = strWithSpans;
spanElems = myGetSpanElementsAroundText(elem.firstChild);
addTextColorsToTwinkleText.setElements(spanElems);
//}
setTimeout(step4, 250);
} // end function step2b
function step4()
{
var headElement = doc.getElementsByTagName('head')[0];
/* start the timer that 'wakes up' to change the colors of some
of the text */
setupTickerForTwinkleText(doc, headElement);
if (isintersectionObserver) {
setupObserverCommon(TickerForTwinkleText, textElementId);
} else {
TickerForTwinkleText.setRandomTimeBetweenUpdates();
TickerForTwinkleText.
callCreateTransStyleReadyNextAfterTimeout();
}
} // end function step4
step2b();
} // end function setupAddTextColorForLineOfText
setupAddTextColorForLineOfText(
'searchLabelText',
'Twinkle2',
20000,
17000,
23000,
1000,
isIntersectionObserver,
'wowsSearch'
);
Also see: Tab Triggers