Skip to content

14paxton/JavaScript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quick Tips

Group and object by key and possible subkey

returns {(key to group by) : [{(secondary key) : (key to group by)}]}

groupArrayOfObjectsByKey(Array , String key, [String key2])

java like enum can be used for pointer type function ex. https://dev.to/avalander/union-types-with-javascript-4emo

Union Example

Print separate page from current page

print pre-defined page

Script to fill form example

fill form

Get All CSS for element and children- returns css string

https://gist.github.com/14paxton/70018ca1b4b990db4fbf4edfd1907af8

Create new document and open in new window

https://contest-server.cs.uchicago.edu/ref/JavaScript/developer.mozilla.org/en-US/docs/Web/API/Window/open.html

https://gist.github.com/14paxton/fb7f33fd6f5fa7a15077b6ebf18fca44



get middle of webpage

   const x = window.innerWidth / 2;
const y = window.innerHeight / 2;

const eye = document.documentElement
const {left, top, width, height} = eye.getBoundingClientRect()
const centerX = left + width / 2
const centerY = top + height / 2

run an async await inline

(async () => { await createDataUrls(clonedTableArray, dimensionsObj, additionalSlides, resolveURLCreation, rejectURL)})()

load html into html doc

//************** Add path to files to test **********************//
//path to html file you want to use
const pathToHTML = '/Yuma_Regional/yuma_regional_launch.html';
//path to html file you want to use


//path to css file
const cssFilePath = '01Launch_Page_Default_Template.css'
//path to css file
//************** Add path to files to test **********************//


const cssLink = document.createElement('link')
cssLink.rel = "stylesheet"
cssLink.type = 'text/css'
cssLink.href = cssFilePath
document.querySelector('head').appendChild(cssLink)

window.addEventListener("load", async function () {
    const promise = await fetchHTMLFile(pathToHTML)
    const html = await promise.text()
    document.querySelector('body').innerHTML = html;
}, false);


async function fetchHTMLFile(path) {
    return await fetch(path)
}

Conditionally load scripts included in HTML by manipulating the type attribute

if (conditional === true) {

    const cScripts = document.querySelectorAll('.conditional');

    cScripts.forEach((item) => {

        const script = document.createElement('script');

        const attrs = item.getAttributeNames();

        attrs.forEach((attr) => {

            script.setAttribute(attr, item.getAttribute(attr));

        });

        script.type = 'text/javascript';

        script.async = false;

        item.remove();

        document.head.appendChild(script);

    })

}

About

vanilla js notes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published