From 5b5a2d93e181ca7e4228306d3f3e8c72f351245e Mon Sep 17 00:00:00 2001 From: Ifeora Okechukwu Date: Thu, 16 Oct 2014 09:20:56 -0700 Subject: [PATCH 1/5] first commit to @ded fork --- dist/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/script.js b/dist/script.js index 649c901..8b0df9a 100644 --- a/dist/script.js +++ b/dist/script.js @@ -109,11 +109,11 @@ delay[key][push](ready) req && req(missing) }(deps.join('|')) - return $script + return this; } $script.done = function (idOrDone) { - $script([null], idOrDone) + this([null], idOrDone) } return $script From cdc0b938dae05477a5c8e6cfb4915d9efc866e13 Mon Sep 17 00:00:00 2001 From: Ifeora Okechukwu Date: Sun, 30 Nov 2014 05:52:32 -0800 Subject: [PATCH 2/5] updated src section --- src/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/script.js b/src/script.js index cb9b585..960110c 100644 --- a/src/script.js +++ b/src/script.js @@ -102,11 +102,11 @@ delay[key][push](ready) req && req(missing) }(deps.join('|')) - return $script + return this; } $script.done = function (idOrDone) { - $script([null], idOrDone) + this([null], idOrDone) } return $script From 830d9b3ece040c5f150e650eaf10b7434c2a0f30 Mon Sep 17 00:00:00 2001 From: Ifeora Okechukwu Date: Sun, 30 Nov 2014 06:01:29 -0800 Subject: [PATCH 3/5] loader attribute update --- dist/script.js | 3 +++ src/script.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/dist/script.js b/dist/script.js index 0460345..e8fd62f 100644 --- a/dist/script.js +++ b/dist/script.js @@ -11,6 +11,9 @@ })('$script', function () { var doc = document , head = doc.getElementsByTagName('head')[0] + , all = doc.getElementsByTagName('script') + , thisfile = all[all.length - 1] + , loaderPath = thisfile.getAttribute('data-setup-loader') , s = 'string' , f = false , push = 'push' diff --git a/src/script.js b/src/script.js index 960110c..379b373 100644 --- a/src/script.js +++ b/src/script.js @@ -5,6 +5,9 @@ })('$script', function () { var doc = document , head = doc.getElementsByTagName('head')[0] + , all = doc.getElementsByTagName('script') + , thisfile = all[all.length - 1] + , loaderPath = thisfile.getAttribute('data-setup-loader') , s = 'string' , f = false , push = 'push' From 2cbf684181efd9bcd0676e758df4b165688b866f Mon Sep 17 00:00:00 2001 From: Ifeora Okechukwu Date: Tue, 9 Dec 2014 00:49:12 -0800 Subject: [PATCH 4/5] setup-main atrribute feature added --- dist/script.js | 52 ++++++++++++++++++++++++++++++++++------- dist/script.min.js | 8 +++++-- src/script.js | 58 +++++++++++++++++++++++++++++++++++++++------- 3 files changed, 98 insertions(+), 20 deletions(-) diff --git a/dist/script.js b/dist/script.js index e8fd62f..63237f3 100644 --- a/dist/script.js +++ b/dist/script.js @@ -4,6 +4,10 @@ * (c) Dustin Diaz 2014 | License MIT */ + /*! + * With permissions from @ded to enable this module load css files asynchrnously as well + * $script.js JS dependency manager & CSS loader + */ (function (name, definition) { if (typeof module != 'undefined' && module.exports) module.exports = definition() else if (typeof define == 'function' && define.amd) define(definition) @@ -13,7 +17,8 @@ , head = doc.getElementsByTagName('head')[0] , all = doc.getElementsByTagName('script') , thisfile = all[all.length - 1] - , loaderPath = thisfile.getAttribute('data-setup-loader') + , tpath = thisfile.src + , loaderPath = thisfile.getAttribute('setup-main') , s = 'string' , f = false , push = 'push' @@ -23,8 +28,16 @@ , ids = {} , delay = {} , scripts = {} - , scriptpath + , scriptpath // = tpath.substring(0, tpath.lastIndexOf('/')+1) , urlArgs + , cwdRgx = /^(\.(?=\/)|[^\.\/]+?\.[a-z]{2,4})/i + , tagMap = { + "js":"script", + "css":"link", + "":"undefined" + } + + console.log("s: "+scriptpath); function every(ar, fn) { for (var i = 0, j = ar.length; i < j; ++i) if (!fn(ar[i])) return f @@ -72,20 +85,37 @@ } function create(path, fn) { - var el = doc.createElement('script'), loaded + var isStr = path.toString() === path, + el = path.nodeType && path || isStr && doc.createElement(tagMap[(path.match(/\.(js|css)$/i) || ["",""])[1]]), + type = el.nodeName.toLowerCase(), + loaded; + if(type == "undefined") return; el.onload = el.onerror = el[onreadystatechange] = function () { if ((el[readyState] && !(/^c|loade/.test(el[readyState]))) || loaded) return; el.onload = el[onreadystatechange] = null loaded = 1 scripts[path] = 2 - fn() + fn && fn() } - el.async = 1 - el.src = urlArgs ? path + (path.indexOf('?') === -1 ? '?' : '&') + urlArgs : path; - head.insertBefore(el, head.lastChild) + switch(type){ + case "script": + el.type = "text/javascript"; + el.async = isStr ? 1 : false ; + path = isStr ? path : tpath ; + el.src = urlArgs ? path + (path.indexOf('?') === -1 ? '?' : '&') + urlArgs : path; + break; + case "link": + el.type = "text/css"; + el.rel = "stylesheet"; + el.href = path; + break; + } + if(isStr) head.insertBefore(el, head.lastChild) } - $script.get = create + $script.get = function(s, done){ + create(String(s), done) + } $script.order = function (scripts, id, done) { (function callback(s) { @@ -117,6 +147,10 @@ $script.done = function (idOrDone) { this([null], idOrDone) } - + + create(thisfile, function(){ + create(loaderPath); + }); + return $script }); diff --git a/dist/script.min.js b/dist/script.min.js index 2bd8f7c..4613dbd 100644 --- a/dist/script.min.js +++ b/dist/script.min.js @@ -1,6 +1,10 @@ -/*! +/*! * $script.js JS loader & dependency manager * https://github.com/ded/script.js * (c) Dustin Diaz 2014 | License MIT */ -(function(e,t){typeof module!="undefined"&&module.exports?module.exports=t():typeof define=="function"&&define.amd?define(t):this[e]=t()})("$script",function(){function p(e,t){for(var n=0,i=e.length;n Date: Tue, 9 Dec 2014 12:00:46 -0800 Subject: [PATCH 5/5] setup-main atrribute feature added --- README.md | 19 +++++++++++++++++++ package.json | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 17cf168..0372d0b 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,25 @@ $script.ready('my-awesome-plugin', function() { }) ``` +### Newly Added Feature - setup-main="" + +You can now add a "setup-main" attribute to the script tag for script.js and load a setup file with all dependencies +appropriately defined based on script.js nuances + +``` js + + + + // in js/test-setup.js + $script(['boo.js, baz.js'], 'stillonit') + $script(['foo.js'], 'almostdone') + $script.ready(['stillonit','almostdone'], function(){ + // all done! + // run more code... + }) + +``` + ### $script.path() Optionally to make working with large projects easier, there is a path variable you can set to set as a base. diff --git a/package.json b/package.json index ed7aed8..11bd7ae 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "jsonp", "loader" ], - "version": "2.5.7", + "version": "2.5.8", "homepage": "https://github.com/ded/script.js", "author": "Dustin Diaz (http://dustindiaz.com)", "contributors": [