-
-
Save atk/1034863 to your computer and use it in GitHub Desktop.
elementready in 94 bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function( | |
i, // id of element which needs to be selectable until callback can be executed | |
c, // callback to be executed in the elements scope | |
t // placeholder for timed out function | |
){ | |
// create function t | |
(t = function(e){ | |
// try to select node by ID (i) | |
(e = document.getElementById(i)) ? | |
// if we get an result, call callback in its scope | |
c.call(e) : | |
// otherwise let it set itself with a 45ms timeout | |
setTimeout(t,45) | |
// and execute itself immediately | |
})() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function r(i,c,t){(t=function(e){(e=document.getElementById(i))?c.call(e):setTimeout(t,45)})()} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 Alex Kloss <alexhtkloss@web.de> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "elementready", | |
"description": "Waits until an element selectable by ID is available and then runs a callback in the elements scope.", | |
"keywords": [ | |
"element", | |
"ready" | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<title>Element Ready</title> | |
<div>Expected value: <b>works</b></div> | |
<script> | |
var er = function (i,c,t){(t=function(e){(e=document.getElementById(i))?c.call(e):setTimeout(t,45)})()}; | |
// b#ret is not yet available, so lets wait for it. | |
er('ret', function(){ this.innerHTML = 'works' }); | |
</script> | |
<div>Actual value: <b id="ret"></b></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One could save another 5 bytes by replacing c.call(e) with c(e) - but in this case, the callback would receive the node as argument instead of scope.