diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9fc5ae8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +# This file is for unifying the coding style for different editors and IDEs +# editorconfig.org + +root = true + +[*] +indent_style = tab +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true \ No newline at end of file diff --git a/.gitignore b/.gitignore index b9d6bd9..91dfed8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,215 +1,2 @@ -################# -## Eclipse -################# - -*.pydevproject -.project -.metadata -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.classpath -.settings/ -.loadpath - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# CDT-specific -.cproject - -# PDT-specific -.buildpath - - -################# -## Visual Studio -################# - -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# User-specific files -*.suo -*.user -*.sln.docstates - -# Build results - -[Dd]ebug/ -[Rr]elease/ -x64/ -build/ -[Bb]in/ -[Oo]bj/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -*_i.c -*_p.c -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.log -*.scc - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opensdf -*.sdf -*.cachefile - -# Visual Studio profiler -*.psess -*.vsp -*.vspx - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -*.ncrunch* -.*crunch*.local.xml - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.Publish.xml -*.pubxml - -# NuGet Packages Directory -## TODO: If you have NuGet Package Restore enabled, uncomment the next line -#packages/ - -# Windows Azure Build Output -csx -*.build.csdef - -# Windows Store app package directory -AppPackages/ - -# Others -sql/ -*.Cache -ClientBin/ -[Ss]tyle[Cc]op.* -~$* -*~ -*.dbmdl -*.[Pp]ublish.xml -*.pfx -*.publishsettings - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file to a newer -# Visual Studio version. Backup files are not needed, because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -App_Data/*.mdf -App_Data/*.ldf - -############# -## Windows detritus -############# - -# Windows image file caches -Thumbs.db -ehthumbs.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Mac crap .DS_Store - - -############# -## Python -############# - -*.py[co] - -# Packages -*.egg -*.egg-info -dist/ -build/ -eggs/ -parts/ -var/ -sdist/ -develop-eggs/ -.installed.cfg - -# Installer logs -pip-log.txt - -# Unit test / coverage reports -.coverage -.tox - -#Translations -*.mo - -#Mr Developer -.mr.developer.cfg +node_modules \ No newline at end of file diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..9370e52 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,15 @@ +{ + "boss": true, + "curly": true, + "eqeqeq": true, + "eqnull": true, + "expr": true, + "immed": true, + "noarg": true, + "onevar": true, + "quotmark": "double", + "smarttabs": true, + "trailing": true, + "unused": true, + "node": true +} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..4cee540 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - 0.10 \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100755 index 0000000..d8c25d7 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,62 @@ +module.exports = function(grunt) { + grunt.initConfig({ + pkg: grunt.file.readJSON("docready.json"), + meta: { + banner: "/*\n" + + " * <%= pkg.title || pkg.name %> - v<%= pkg.version %>\n" + + " * <%= pkg.description %>\n" + + " *\n" + + " * <%= pkg.homepage %>\n" + + " *\n" + + " * By: <%= pkg.author.name %> | <%= pkg.author.twitter %>\n" + + " * License: <%= pkg.licenses[0].type %>\n" + + " */\n" + }, + concat: { + dist: { + src: ["src/docready.js"], + dest: "dist/docready.js" + }, + options: { + banner: "<%= meta.banner %>" + } + }, + jshint: { + files: ["src/docready.js"], + options: { + jshintrc: ".jshintrc" + } + }, + uglify: { + my_target: { + src: ["src/docready.js"], + dest: "dist/docready.min.js" + }, + options: { + banner: "<%= meta.banner %>" + } + }, + watch: { + scripts: { + files: ['src/*.js'], + tasks: ['uglify'], + options: { + spawn: false + } + }, + html: { + files: ['dist/*.html'], + }, + tasks: ['default'] + } + }); + + grunt.loadNpmTasks("grunt-contrib-concat"); + grunt.loadNpmTasks("grunt-contrib-jshint"); + grunt.loadNpmTasks("grunt-contrib-uglify"); + grunt.loadNpmTasks("grunt-contrib-watch"); + + grunt.registerTask("default", ["jshint", "concat", "uglify"]); + grunt.registerTask("testjs", ["jshint"]); + +}; diff --git a/dist/docready.js b/dist/docready.js new file mode 100644 index 0000000..3ddf4c2 --- /dev/null +++ b/dist/docready.js @@ -0,0 +1,78 @@ +/* + * Plain JavaScript replacement for jQuery's .ready() - v0.1 + * 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. + * + * https://github.com/jfriend00/docReady + * + * By: jfriend00 | + * License: MIT + */ +(function(funcName, baseObj) { + // The public function name defaults to window.docReady + // but you can pass in your own object and own function name and those will be used + // if you want to put them in a different namespace + funcName = funcName || "docReady"; + baseObj = baseObj || window; + var readyList = []; + var readyFired = false; + var readyEventHandlersInstalled = false; + + // call this when the document is ready + // this function protects itself against being called more than once + function ready() { + if (!readyFired) { + // this must be set to true before we start calling callbacks + readyFired = true; + for (var i = 0; i < readyList.length; i++) { + // if a callback here happens to add new ready handlers, + // the docReady() function will see that it already fired + // and will schedule the callback to run right after + // this event loop finishes so all handlers will still execute + // in order and no new ones will be added to the readyList + // while we are processing the list + readyList[i].fn.call(window, readyList[i].ctx); + } + // allow any closures held by these functions to free + readyList = []; + } + } + + function readyStateChange() { + if ( document.readyState === "complete" ) { + ready(); + } + } + + // This is the one public interface + // docReady(fn, context); + // the context argument is optional - if present, it will be passed + // as an argument to the callback + baseObj[funcName] = function(callback, context) { + // if ready has already fired, then just schedule the callback + // to fire asynchronously, but right away + if (readyFired) { + setTimeout(function() {callback(context);}, 1); + return; + } else { + // add the function and context to the list + readyList.push({fn: callback, ctx: context}); + } + // if document already ready to go, schedule the ready function to run + if (document.readyState === "complete") { + setTimeout(ready, 1); + } else if (!readyEventHandlersInstalled) { + // otherwise if we don't have event handlers installed, install them + if (document.addEventListener) { + // first choice is DOMContentLoaded event + document.addEventListener("DOMContentLoaded", ready, false); + // backup is window load event + window.addEventListener("load", ready, false); + } else { + // must be IE + document.attachEvent("onreadystatechange", readyStateChange); + window.attachEvent("onload", ready); + } + readyEventHandlersInstalled = true; + } + }; +})("docReady", window); \ No newline at end of file diff --git a/dist/docready.min.js b/dist/docready.min.js new file mode 100644 index 0000000..e58005f --- /dev/null +++ b/dist/docready.min.js @@ -0,0 +1,10 @@ +/* + * Plain JavaScript replacement for jQuery's .ready() - v0.1 + * 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. + * + * https://github.com/jfriend00/docReady + * + * By: jfriend00 | + * License: MIT + */ +!function(a,b){function c(){if(!f){f=!0;for(var a=0;a + + + + + + docReady Test Page + + + + + +
+ + \ No newline at end of file diff --git a/docready.json b/docready.json new file mode 100755 index 0000000..ae19326 --- /dev/null +++ b/docready.json @@ -0,0 +1,25 @@ +{ + "name": "docReady", + "title": "Plain JavaScript replacement for jQuery's .ready()", + "homepage": "https://github.com/jfriend00/docReady", + "description": "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.", + "keywords": [ + "javascript", + "domready", + "document ready" + ], + "version": "0.1", + "author": { + "name": "jfriend00", + "url": "https://github.com/jfriend00" + }, + "licenses": [ + { + "type": "MIT", + "url": "https://github.com/jfriend00/docReady/blob/master/license" + } + ], + "bugs": "https://github.com/jfriend00/docReady/issues", + "docs": "https://github.com/jfriend00/docReady#readme", + "download": "https://github.com/jfriend00/docReady/archive/master.zip" +} diff --git a/docreadytest.html b/docreadytest.html deleted file mode 100644 index d01181c..0000000 --- a/docreadytest.html +++ /dev/null @@ -1,162 +0,0 @@ - - - - - - - docReady Test Page - - - - - -
-
- - \ No newline at end of file diff --git a/package.json b/package.json new file mode 100755 index 0000000..5eacae5 --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "private": true, + "devDependencies": { + "grunt": "~0.4.5", + "grunt-cli": "~0.1.13", + "grunt-contrib-concat": "~0.4.0", + "grunt-contrib-jshint": "^0.10.0", + "grunt-contrib-uglify": "~0.4.0", + "grunt-contrib-watch": "^0.6.1" + }, + "scripts": { + "test": "grunt testjs --verbose" + } +} diff --git a/docready.js b/src/docready.js similarity index 99% rename from docready.js rename to src/docready.js index 089dfd6..4dd6992 100644 --- a/docready.js +++ b/src/docready.js @@ -65,5 +65,5 @@ } readyEventHandlersInstalled = true; } - } + }; })("docReady", window); \ No newline at end of file