From 76929280fac03dd0289f836a549efb8bf5b04814 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Tue, 6 Nov 2018 22:04:04 +1300 Subject: [PATCH 1/5] Migrate plain text file to markdown --- readme => readme.md | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) rename readme => readme.md (70%) diff --git a/readme b/readme.md similarity index 70% rename from readme rename to readme.md index 5161746..ca99591 100644 --- a/readme +++ b/readme.md @@ -1,28 +1,38 @@ +# docready + docReady is a single plain javascript function that provides a method of scheduling one or more javascript functions to run at some later point when the DOM has finished loading. -It works similarly to jQuery's $(document).ready(), but this is a small +It works similarly to [jQuery](https://jquery.com/)'s `$(document).ready()`, but this is a small single standalone function that does not require jQuery in any way. These are various forms of usage: +```js // pass a function reference docReady(fn); +``` +```js // use an anonymous function docReady(function() { // code here }); +``` +```js // pass a function reference and a context // the context will be passed to the function as the first argument docReady(fn, context); +``` +```js // use an anonymous function with a context docReady(function(ctx) { // code here that can use the context argument that was passed to docReady }, context); +``` docReady(fn) can be called as many times as desired and each callback function will be called in order when the DOM is done being parsed and is ready for manipulation. @@ -32,12 +42,12 @@ as soon as the current thread of execution finishes by using setTimeout(fn, 1). It has been tested in the following browser configurations: -IE6 and up -Firefox 3.6 and up -Chrome 14 and up -Safari 5.1 and up -Opera 11.6 and up -Multiple iOS devices -Multiple Android devices +- IE6 and up +- Firefox 3.6 and up +- Chrome 14 and up +- Safari 5.1 and up +- Opera 11.6 and up +- Multiple iOS devices +- Multiple Android devices -Other discussion can be found here: http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the/9899701#9899701 +Other discussions can be found [here](http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the/9899701#9899701). From ffd0b6c177798348d702a9ca964f4e6445bb3759 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Tue, 6 Nov 2018 22:11:59 +1300 Subject: [PATCH 2/5] Add section headers and usage --- readme.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/readme.md b/readme.md index ca99591..5f88fa6 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,7 @@ # docready +## Summary + docReady is a single plain javascript function that provides a method of scheduling one or more javascript functions to run at some later point when the DOM has finished loading. @@ -7,6 +9,8 @@ point when the DOM has finished loading. It works similarly to [jQuery](https://jquery.com/)'s `$(document).ready()`, but this is a small single standalone function that does not require jQuery in any way. +## Examples + These are various forms of usage: ```js @@ -34,12 +38,16 @@ docReady(function(ctx) { }, context); ``` +## Side notes + docReady(fn) can be called as many times as desired and each callback function will be called in order when the DOM is done being parsed and is ready for manipulation. If you call docReady(fn) after the DOM is already ready, the callback with be executed as soon as the current thread of execution finishes by using setTimeout(fn, 1). +## Browser compatibility + It has been tested in the following browser configurations: - IE6 and up @@ -50,4 +58,12 @@ It has been tested in the following browser configurations: - Multiple iOS devices - Multiple Android devices +## Usage + +Simply load the script via a script tag: + +```html + +``` + Other discussions can be found [here](http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the/9899701#9899701). From 8a6f61efedc2c4263366f793b23e69523a390484 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Tue, 6 Nov 2018 22:12:40 +1300 Subject: [PATCH 3/5] formatted discussion section --- readme.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 5f88fa6..ab80bda 100644 --- a/readme.md +++ b/readme.md @@ -66,4 +66,7 @@ Simply load the script via a script tag: ``` -Other discussions can be found [here](http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the/9899701#9899701). +## Discussion + +The discussion can be found [here](http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the/9899701#9899701). + From 857e5d10399bc631dc23f168970284eb1a4a7e57 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Tue, 6 Nov 2018 22:14:56 +1300 Subject: [PATCH 4/5] Update readme.md --- readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/readme.md b/readme.md index ab80bda..6007170 100644 --- a/readme.md +++ b/readme.md @@ -58,6 +58,10 @@ It has been tested in the following browser configurations: - Multiple iOS devices - Multiple Android devices +## Demo + +You can demo the script [here](https://raw.githack.com/jfriend00/docReady/master/docreadytest.html) + ## Usage Simply load the script via a script tag: From 19d831ebcd698a261f1607d752523b32d55688e2 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Mon, 3 Oct 2022 11:54:37 +1300 Subject: [PATCH 5/5] Refactor --- readme.md | 81 ++++++++++++++++++------------------------------------- 1 file changed, 26 insertions(+), 55 deletions(-) diff --git a/readme.md b/readme.md index 6007170..c95ba37 100644 --- a/readme.md +++ b/readme.md @@ -1,76 +1,47 @@ # docready -## Summary +Run a function when the DOM finishes loading. -docReady is a single plain javascript function that provides a method of -scheduling one or more javascript functions to run at some later -point when the DOM has finished loading. +Similar to [jQuery](https://jquery.com/)'s [`$(document).ready()`](https://api.jquery.com/ready/), but as a small, standalone function. -It works similarly to [jQuery](https://jquery.com/)'s `$(document).ready()`, but this is a small -single standalone function that does not require jQuery in any way. +[Demo](https://raw.githack.com/jfriend00/docReady/master/docreadytest.html) -## Examples +## Install -These are various forms of usage: +With a script tag: -```js -// pass a function reference -docReady(fn); +```html + ``` -```js -// use an anonymous function -docReady(function() { - // code here -}); -``` +## Usage ```js -// pass a function reference and a context -// the context will be passed to the function as the first argument -docReady(fn, context); +docReady(() => { + // Document is ready +}); ``` ```js -// use an anonymous function with a context -docReady(function(ctx) { - // code here that can use the context argument that was passed to docReady -}, context); +// Pass a value to the function +docReady(unicorn => { + // Document is ready + // unicorn === '🦄' +}, '🦄'); ``` -## Side notes - -docReady(fn) can be called as many times as desired and each callback function will be -called in order when the DOM is done being parsed and is ready for manipulation. - -If you call docReady(fn) after the DOM is already ready, the callback with be executed -as soon as the current thread of execution finishes by using setTimeout(fn, 1). +## API -## Browser compatibility +Each function will be called in the order that they are provided to `docReady()` when the DOM has fininshed being parsed and is ready for manipulation. -It has been tested in the following browser configurations: - -- IE6 and up -- Firefox 3.6 and up -- Chrome 14 and up -- Safari 5.1 and up -- Opera 11.6 and up -- Multiple iOS devices -- Multiple Android devices - -## Demo - -You can demo the script [here](https://raw.githack.com/jfriend00/docReady/master/docreadytest.html) - -## Usage - -Simply load the script via a script tag: - -```html - -``` +If you call `docReady()` while the DOM is already ready, the callback with be executed as soon as the current thread of execution finishes by using `setTimeout(fn, 1)`. -## Discussion +## Browser support -The discussion can be found [here](http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the/9899701#9899701). +Tested to be working in the following browsers: +- IE6+ +- Firefox 3.6+ +- Chrome 14+ +- Safari 5.1+ +- Opera 11.6+