Skip to content

Instantly share code, notes, and snippets.

Chase Isley theonlychase

Block or report user

Report or block theonlychase

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@theonlychase
theonlychase / 0_reuse_code.js
Created Jul 13, 2017
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@theonlychase
theonlychase / add-remove
Created Jan 15, 2018
getElementsByClassName and add/remove class based on scroll position of the page
View add-remove
var scrollpos = window.scrollY;
var headerShip = document.getElementById("header-ship");
var custLink = document.getElementsByClassName('cust-link');
function add_class_on_scroll() {
headerShip.classList.add("hide-h");
for(var i = 0; i < custLink.length; i++)
{
custLink[i].classList.add("custLinkHide");
}
@theonlychase
theonlychase / add-class-on-hover
Created Jan 31, 2018
Adds a class to a child element on hover
View add-class-on-hover
$("li.header-links").hover(function() {
$(this).children('div.drop-nav-container').toggleClass('showmenu');
});
@theonlychase
theonlychase / nav-width
Created Feb 26, 2018
Here, the width of the navigation changes based on if the window width is greater than 1024px or less than 1320px
View nav-width
var winWidth = 1280;
var newwidth = jQuery(window).width();
// Width of Sticky Nav
if (newwidth <= 1320 && newwidth >= 1024) {
jQuery(".sticky-wrap-nav-holder .nav-holder").width(newwidth - 40);
} else if (newwidth <= 1024) {
jQuery(".sticky-wrap-nav-holder .nav-holder").width(newwidth);
} else {
jQuery(".sticky-wrap-nav-holder .nav-holder").width(winWidth);
@theonlychase
theonlychase / loop-insert
Last active Jun 18, 2018
Script needed to move only the specific child of each looped element, otherwise it would move every single child element.
View loop-insert
nextQuery("body.nextProductList .tileContent").each(function() {
nextQuery(this).find(".nextPrice").insertBefore(nextQuery(this).find(".nextStatus"));
});
@theonlychase
theonlychase / jquery-snip
Last active Jul 25, 2018
:contains() .closest() .find()
View jquery-snip
if(nextQuery('body.nextProductDetail').has('.nextAttributeLabel label:contains("Personalized")')){
function ourSelect() {
nextQuery('.nextAttributeLabel label:contains("Personalized")').closest('tr').find('select').addClass('ourSelect');
nextQuery('.nextWriteInLabel label:contains("Enter Text")').closest('tr').addClass('ourWriteIn');
nextQuery('.ourSelect').change(function() {
showHide()
});
}
function showHide() {
@theonlychase
theonlychase / array-some-every
Last active Sep 28, 2018
Actually not a part of ES6. returns true or false
View array-some-every
//Array.some() - will check the data in an array if some meet what you are looking for
const ages = [32, 15, 19, 12];
// is there at least one adult in the group?
const adultPresent = ages.some(age => age >= 18);
console.log(adultPresent);
//Array.every() will check the data in an array if all of the items meet what you are looking for
// is everyone old enough to drink?
View map-filter-reduce
// All three avoids mutation of the original array
// Map()
const arr = [1, 2, 3, 4];
// takes in the value, the index, and the array itself
const arrTimesTwo = arr.map((value, index, arr) => {
return value * 2;
});
// Filter()
View spread-operator
// Turns an array into a list of arguments
// The spread operator is used to pass an array to functions that normally require a list of many arguments.
const arr = [1, 3, 5, 5, 3];
const func = (...arr) => {
console.log(arr);
}
func(arr);
@theonlychase
theonlychase / import-and-require
Last active Sep 28, 2018
Import and export are non-browser features
View import-and-require
// require() is used to import functions and code from external files
// The problem is, if the file is large and has many functions, it imports the whole file. Not handy if
// you're only wanting to import one or two functions.
// ------------ //
// -- Import -- //
// ------------ //
// we can choose which parts of a module or file to load into a given file, saving time and memory.
import { countItems } from "math_array_functions"
import { variable } from "file_path_goes_here" // imports a variable
You can’t perform that action at this time.