Skip to content

Instantly share code, notes, and snippets.

@miwebguy
miwebguy / validinputfromdatalist.html
Last active March 25, 2024 16:15
Only allow valid data from html datalist
//https://stackoverflow.com/questions/30499199/html5-datalist-to-select-only-predefined-options
<script>
function peopleCheck(el)
{
// nothing is done if no value selected - allow empty
if (el.value == "") return;
var options = el.list.options;
for (var i = 0; i< options.length; i++) {
if (el.value == options[i].value)
@miwebguy
miwebguy / OutlookExternalEmailAddress.txt
Last active March 11, 2024 15:31
Show External Email Address in Outlook
To add a full-email field:
Click View > Add Columns
In the Show Columns dialog do the following:
Click New Column button
In the New Column dialog specify a name for the new column
@miwebguy
miwebguy / N2.js
Last active February 16, 2024 19:59
Vanilla JS Notify (toast)
class N2 {
// based on Rick Hopkins MooTools Notify
//<button onclick="n2 = new N2({title:'My Title',content:'My body'})">My N2 Notify</button>
//<button onclick="n2 = new N2({text:'MyCombined Title::My combined body',classes:['inlineNotice']})">My N2 text Notify</button>
//<button onclick="n2 = new N2({text:'MyCombined Title::My combined body',classes:['notify-warn']})">My N2 text Warn</button>
//<button onclick="n2 = new N2({text:'MyCombined Title::My combined body',classes:['notify-alert']})">My N2 text Alert</button>
constructor (opts) {
@miwebguy
miwebguy / consentx.js
Last active February 15, 2024 19:20
ConsentX Cookie Consent Banner
class ConsentX {
// based on Creare's 'Implied Consent' EU Cookie Law Banner v:2.4
// Conceived by Robert Kent, James Bavington & Tom Foyster
constructor () {
this.dropCookie = true; // false disables the cookie, allowing you to style the banner
this.cookieDuration = 14; // days before the cookie expires, and the banner reappears
this.cookieName = 'complianceCookie'; // name of our cookie
this.cookieValue = 'on'; // initial value of cookie
@miwebguy
miwebguy / qf2.js
Last active February 15, 2024 19:21
Vanilla JS QuickForm
class QF2 {
// based on MooTools QuickForm, created by Rick Hopkins
//<button onclick="QF = new QF2({title:'This is a Title',content:'Hello'});">QF Content</button>
//<button onclick="QF = new QF2({title:'This is a Title',url:'https://testing0.micore.us/qf2/form.html'});">QF Url</button>
//<button onclick="QF = new QF2({title:'This is a Title',url:'https://testing0.micore.us/qf2/form.html',data:{key:'value'}});">QF Url with Post Data</button>
constructor (opts) {
// clear all previously made QuickForms
var qf = document.querySelector('.quickform');
@miwebguy
miwebguy / jshtmltoword.html
Last active December 26, 2023 19:05
JStoDoc (no Images)
https://stackoverflow.com/questions/63460485/exporting-html-to-word
<script>
//<![CDATA[
function Export2Doc(element, filename = ''){
var preHtml = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'><head> <meta charset='utf-8'><title>Export HTML To Doc</title></head><body>";
var postHtml = "</body></html>";
var html = preHtml+document.getElementById(element).innerHTML+postHtml;
var blob = new Blob(['\ufeff', html], {
type: 'application/msword'
@miwebguy
miwebguy / phoneformat.html
Created December 26, 2023 19:02
Phone Number Formatting
<p>https://stackoverflow.com/questions/30058927/format-a-phone-number-as-a-user-types-using-pure-javascript</p>
<input id="phoneNumber" placeholder="Phone Number" maxlength="16" />
<script>
isNumericInput = (event) => {
const key = event.keyCode;
return ((key >= 48 && key <= 57) || // Allow number line
(key >= 96 && key <= 105) // Allow number pad
@miwebguy
miwebguy / details.html
Last active August 28, 2023 16:42
Open Details on Destkop, Close on mobile
<script>
//<![CDATA[
//open or close details elements based on viewport
function openDesktopDetails()
{
const detailsEls = document.querySelectorAll(".wpc details");
var len = detailsEls.length;
var w = window.innerWidth;
if(w > 1023) {
detailsEls.forEach(function (item) {
@miwebguy
miwebguy / GIMP PSD Layers to PNG
Created February 10, 2023 18:10
Quick Export all layers in GIMP to PNG
GIMP PSD Layers to PNG
Export it as Open Raster (.ora), an open specification for layered-image files.
Export Image as Open Raster (.ora)
File -> Export As ...
myfile.ora
Open myfile.ora as an archive, with a program like file-roller or 7zip.
https://askubuntu.com/questions/485917/gimp-export-every-layer-as-a-separate-png-image
@miwebguy
miwebguy / simpletoc.js
Last active April 21, 2022 17:00
Simple Table of Contents from Headings
//https://stackoverflow.com/questions/187619/is-there-a-javascript-solution-to-generating-a-table-of-contents-for-a-page
window.onload = function () {
var toc = "";
var level = 0;
document.getElementById("VNAArticle").innerHTML =
document.getElementById("VNAArticle").innerHTML.replace(
/<h([\d])>([^<]+)<\/h([\d])>/gi,
function (str, openLevel, titleText, closeLevel) {