ryanmorr / ready Goto Github PK
View Code? Open in Web Editor NEWDetect element availability on the initial page load and those dynamically appended to the DOM
License: The Unlicense
Detect element availability on the initial page load and those dynamically appended to the DOM
License: The Unlicense
Hey @ryanmorr,
Thank you for this useful utility!
After the recent update (v1.3.0) the ready function name became ryanmorrready.
First - nice tool, much better than the silly HTML date popup!
I have form that has two date fields, on two different lines. If someone opens popup on one, then on the other, they overlap. So, I tweaked code a bit to close any that may be open already when another is opened. Here is what I did, followed by the affected existing code:
`
..
function closeDatePickers(idOfTextBox) // dlc added
// fixes problem where multiple datepickers open
{
var datepickers = document.getElementsByClassName('datepicker');
var textbox;
var any = false;
var me = false;
for(var ix=0; ix< datepickers.length; ix++)
{
textbox = document.getElementById(datepickers[ix].id);
div = textbox.parentNode.getElementsByTagName('div');
for (jx=0;jx<div.length;jx++)
{
if (div[jx].getAttribute('class')=='datepickerdropdown')
{
textbox.parentNode.removeChild(div[jx]);
if (datepickers[ix].id == idOfTextBox) me = true;
any = true;
}
}
}
return me;
}
// This is called when they click the icon next to the date inputbox
function showDatePicker(idOfTextbox) {
var textbox = document.getElementById(idOfTextbox);
if (closeDatePickers(idOfTextbox)) return false; // just closing this one
/*
// See if the date picker is already there, if so, remove it
x = textbox.parentNode.getElementsByTagName('div');
for (i=0;i<x.length;i++) {
if (x[i].getAttribute('class')=='datepickerdropdown') {
textbox.parentNode.removeChild(x[i]);
return false;
}
}
*/
// Grab the date, or use the current date if not valid
..`
Nice job! I came to this project looking for a simpler alternative (and jquery-free) to https://github.com/AdamPietrasiak/jquery.initialize.
Your project seems perfect for it, though just like jquery.initialize, the browser support could be extended to IE9 by using a MutationObserver polyfill, wouldn't it?
What the subject says. Since a ready() persists through lifetime of the page, I'm wondering if there's a way to disconnect/turn off a ready() after it's no longer needed.
Thanks, appreciate the code!
Hey @ryanmorr,
Version 1.3 doesn't work for dynamically added elements after DOM is loaded.
The check() function runs everytime I register a new selector.
I see that's needed to detect for elements already present at the page, but why do you need to run through all listeners, instead of just the selector being registered? Running through the other listeners seems to be unnecessary, and could have a noticeable perform impact as the listeners list grows.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.