From 7d8a89a40145002cc29d5aea4d37f096234f5247 Mon Sep 17 00:00:00 2001 From: juanbrujo Date: Fri, 17 Oct 2014 17:17:59 -0300 Subject: [PATCH 1/2] added Grunt and jshint'ed change the repo structure, added grunt and revised with jshint. --- .editorconfig | 11 + .gitignore | 215 +------------------- .jshintrc | 15 ++ .travis.yml | 3 + Gruntfile.js | 62 ++++++ dist/docready.js | 78 +++++++ dist/docready.min.js | 10 + docreadytest.html => dist/docreadytest.html | 0 docready.json | 25 +++ package.json | 14 ++ docready.js => src/docready.js | 2 +- 11 files changed, 220 insertions(+), 215 deletions(-) create mode 100644 .editorconfig create mode 100644 .jshintrc create mode 100644 .travis.yml create mode 100755 Gruntfile.js create mode 100644 dist/docready.js create mode 100644 dist/docready.min.js rename docreadytest.html => dist/docreadytest.html (100%) create mode 100755 docready.json create mode 100755 package.json rename docready.js => src/docready.js (99%) 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 Date: Fri, 17 Oct 2014 17:37:09 -0300 Subject: [PATCH 2/2] fixed demo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit now demo calls the min.js file and they’re more descriptive --- dist/docreadytest.html | 173 +++++++---------------------------------- 1 file changed, 26 insertions(+), 147 deletions(-) diff --git a/dist/docreadytest.html b/dist/docreadytest.html index d01181c..83c32d2 100644 --- a/dist/docreadytest.html +++ b/dist/docreadytest.html @@ -2,161 +2,40 @@ - + - docReady Test Page - + + // test calling docReady after window load and + // docReady has already fired + window.addEventListener("load", function() { + setTimeout(function() { + document.body.appendChild(document.createTextNode(" | test calling docReady after window load")); + + docReady(function(arg) { + document.body.appendChild(document.createTextNode(arg)); + }, " | and docReady has already fired"); + }, 1); + }); + -
-
+
\ No newline at end of file