Skip to content

Instantly share code, notes, and snippets.

function getStyle(elem)
{
return (elem.currentStyle || window.getComputedStyle(elem, false));
}
function setStyle( elem, propertyObject )
{
for (var property in propertyObject)
{
elem.style[property] = propertyObject[property];
}
}
@danbrianwhite
danbrianwhite / gist:38515b9f1397f04ac310
Last active December 13, 2015 17:18
scrollbarWidth
function scrollbarWidth()
{
var $inner = jQuery('<div style="width: 100%; height:200px;">test</div>'),
$outer = jQuery('<div style="width:200px;height:150px; position: absolute; top: 0; left: 0; visibility: hidden; overflow:hidden;"></div>').append($inner),
inner = $inner[0],
outer = $outer[0];
jQuery('body').append(outer);
var width1 = inner.offsetWidth;
$outer.css('overflow', 'scroll');
@danbrianwhite
danbrianwhite / gist:be7709cc5e1ba23d7c69
Last active December 6, 2018 09:33
JavaScript Factorial using strings for larger calculations. (Can get quite slow)
var add = function(strNumOne, strNumTwo)
{
var first;
var second;
var tempNumber = new Array();
if(strNumOne.length >= strNumTwo.length)
{
first = strNumOne;
@danbrianwhite
danbrianwhite / gist:7d4c0b4be601ed67d30c
Last active December 16, 2015 03:49
isFlashEnabled
function isFlashEnabled()
{
    var hasFlash = false;
    try
    {
        var flashObject = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
        if(flashObject) hasFlash = true;
    }
    catch(e)
    {
@danbrianwhite
danbrianwhite / filePath.js
Last active December 16, 2015 03:59
filePath
var filePath = function()
{
//grab the path of this js file (must include name of file)
var _scripts = document.getElementsByTagName("script");
var _pattern = /^(.*?)\/js\/filePath.js/i;
var _path;
for (var i = _scripts.length - 1; i >= 0; i--)
@danbrianwhite
danbrianwhite / gist:bcdd7fbd6d775a4e0dc0
Last active December 16, 2015 05:28
polyfill window.offsetWidth and window.offsetHeight
//polyfill window.offsetWidth and window.offsetHeight
var windowOffset = function()
{
var getOffset = function()
{
if(typeof(_cacheResize) === "function")
{
_cacheResize
}
@danbrianwhite
danbrianwhite / gist:bbc74dabeb2292077c2c
Created April 14, 2013 21:35
fillView - resize an element inside of a container to entirely fill the whole container
var fillViewList = {};
var fillViewAdd = function(element)
{
element.style.width = "auto";
element.style.height = "auto";
var _width = element.offsetWidth;
var _height = element.offsetHeight;
fillViewList[element] = {width: _width, height: _height};
@danbrianwhite
danbrianwhite / gist:03b2f52bdbfa977c1fdb
Last active September 16, 2016 15:26
parallelShuffleArrays shuffleArrayOfArrays
function parallelShuffleArrays(arrays)
{
var itemsLeft;
var selectedItemIndex;
var temporaryItem;
var array;
function useObject()
{
//check to see if all arrays are equal lengths
@danbrianwhite
danbrianwhite / gist:fc0cf6d3e1d117cca4e2
Created April 15, 2013 01:45
get number of items in object or array
function getNumberItemsObject(arrays)
{
var itemsLeft;
for (property in arrays)
{
if (typeof(itemsLeft) === "undefined")
{
itemsLeft = arrays[property].length;
}