Getting Data from Multiple .then Statements in Javascript

I always have a hard time pulling data through multiple .then statements in javascript. This method works sufficiently well. Basically, define an array/object, and then as data is collected, add content to that array. All of the collected content should be available in the final .then statement. Something like this (all the data is collected […]

Read More

Gulp Minify Javascript

This will put a copy of the minified js file in the same folder in which it was found. It will require the following: useref, gulpif gulp.task(‘jsminify’, function() {   return gulp.src([     “!node_modules/**/*.js”,     “**/wp-content/themes/**/*.js”,     “!**/**.min.js”   ], { base: “./” })   .pipe(useref())   .pipe(gulpIf(‘*.js’, uglify()))   .pipe(rename({suffix: ‘.min’}))   .pipe(gulp.dest(‘./’)); });

Read More

Get Current Clicked on Element in Javascript

event.currentTarget

Read More

Javascript Does String Contain Substring

var str = “Some haystack text goes here that contains needlestring”;   str.includes(‘needlestring’); If you get an error, like “TypeError: e.includes is not a function”, it probably means that you’re trying to do a search on something that isn’t a string or an array.   Fix this by converting the variable to a string, like: element.toString().includes(“#”);

Read More

Javascript Replace String in String

let text = “The dogs barked loudly”; let result = text.replace(“dogs”, “cats”); Replace all instances: let text = “The dogs barked loudly”; let result = text.replace(“dogs/g”, “cats”);

Read More

Javascript Capture Camera on Phone Doesn’t Work on iPhone

On an iphone you need to add a ‘playsinline’ parameter. I think it works by placing it either in the javascript, or as part of the HTML tag — I just added it to both to be safe, and it resolved the issue so I called it good. In javascript as part of the getUserMedia […]

Read More

Document Ready in Vanilla Javascript

To wait until the document is ready, similiar to the $(document).ready functionality in jQuery, just do this: document.addEventListener( ‘DOMContentLoaded’, function(e) {    Stuff Here })

Read More

Javascript – Show or Hide an Element

Showing or hiding an element with javascript: (use “#” for elements by ID, or “.” for elements by class) document.querySelector(“#element”).style.display = ‘block’; document.querySelector(“#element”).style.display = ‘none’;

Read More

PHP JSON Returned As Object Instead of Array

I was returning, what I thought was an array from PHP, but it kept returning it as a json object, so I had something like: $listItem[0][0] = “Jan 1”; $listItem[0][1] = 100; $listItem[1][0] = “Jan 2”; $listItem[1][1] = 120; $listItem[2][0] = “Jan 2”; $listItem[2][1] = 120; …etc… This would return in javascript those an array, […]

Read More

A Simple Slideout Menu

I just wanted an easy slideout menu.  Click on a link, and the menu slides out from the left side of the screen.  Click on the link again, or somewhere else on the page, and the menu slides back in.  Here it is: HTML Code data-openwidth is the width in pixels of however wide you […]

Read More