Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add jQueryUI to libs plus add support for new option in libs JSON config

  • Loading branch information...
commit cd9419ca5894cf5a16eaed411392235aca4db9e7 1 parent 080f0c8
@padolsey authored
View
2  VERSION
@@ -1 +1 @@
-1.1.1
+1.1.2
View
59 app/jsapi/jsapi.sourcehandler.js
@@ -37,29 +37,45 @@ function SourceHandler(requestData, libData) {
this.libData = libData;
- this.loader = new SourceHandler.Loader(requestData, libData);
+ this.loader = new SourceHandler.Loader(
+ requestData.lib + '.' + requestData.ver,
+ libData.url.replace('{VERSION}', requestData.ver),
+ requestData.refresh
+ );
- this.loader
+ this.requires = libData.requires && libData.requires[requestData.ver];
- .on('success', function(source) {
+ if (this.requires) {
- this.source = source;
-
- this.env = new SourceHandler.Environment(this.nullify + this.source);
+ // In the case that this lib requires another file we want
+ // to request the required file and then we can continue with
+ // `setupEnvironment` ...
- this.env.on('ready', function(){
- this.resolver = new SourceHandler.Resolver(this.env, this.source, this.libData);
- this.emit('ready');
- }.bind(this));
+ this.loader
+ .on('success', function(source) {
- this.env.init();
+ log('Loaded lib URL: now loading requirement: ', this.requires);
- }.bind(this))
+ // Load required script:
+ this.requiredLoader = new SourceHandler.Loader(
+ this.requires.match(/\/([^\/]+)$/)[1],
+ this.requires,
+ requestData.refresh
+ ).on('success', function(rSource) {
+ this.setupEnvironment(source, rSource);
+ }.bind(this)).on('failure', function() {
+ this.loader.emit('failure');
+ }.bind(this)).get();
+ }.bind(this));
+
+ } else {
+ this.loader.on('success', this.setupEnvironment.bind(this));
+ }
+ this.loader
.on('failure', function(){
log('Failure on SourceHandler.Loader', arguments);
}.bind(this))
-
.get();
}
@@ -71,6 +87,23 @@ SourceHandler.prototype = new events.EventEmitter;
// EG: @@##__jQuery.fn.data#this.data__##@@
SourceHandler.LINKIFY_MARKER = ['@@##__', '__##@@'];
+SourceHandler.prototype.setupEnvironment = function(source, preRequiredSource) {
+ this.source = source;
+
+ preRequiredSource = preRequiredSource || ''; // e.g. jQuery for jQuery UI (requirement)
+
+ this.env = new SourceHandler.Environment(
+ this.nullify + ';' + preRequiredSource + ';' + this.source
+ );
+
+ this.env.on('ready', function(){
+ this.resolver = new SourceHandler.Resolver(this.env, this.source, this.libData);
+ this.emit('ready');
+ }.bind(this));
+
+ this.env.init();
+};
+
SourceHandler.prototype.findSingleMethod = function(method) {
var resolved = this.resolver.resolve(method),
View
15 app/jsapi/jsapi.sourcehandler.loader.js
@@ -8,14 +8,13 @@ var events = require('events'),
* SourceHandler.Loader
* Takes care of loading source files
*/
-module.exports = Loader = function SHLoader(requestData, libraryData) {
+module.exports = Loader = function SHLoader(filename, uri, refresh) {
events.EventEmitter.call(this);
- this.requestData = requestData;
- this.libraryData = libraryData;
-
- this.filename = './_libs/' + requestData.lib + '.' + requestData.ver + '.js';
+ this.uri = uri;
+ this.filename = './_libs/' + filename + '.js';
+ this.refresh = !!refresh;
};
@@ -25,7 +24,7 @@ Loader.prototype.get = function() {
fs.stat(this.filename, function(err, stats) {
- if (this.requestData.refresh || err && err.code === 'ENOENT') {
+ if (this.refresh || err && err.code === 'ENOENT') {
this.getRemoteSource();
} else if(err) {
this.emit('failure', {error: 'Error on file retrieval, ' + err.code});
@@ -40,9 +39,7 @@ Loader.prototype.get = function() {
Loader.prototype.getRemoteSource = function() {
var me = this,
- libURL = url.parse(
- this.libraryData.url.replace('{VERSION}', this.requestData.ver)
- ),
+ libURL = url.parse(this.uri),
filestream = fs.createWriteStream(this.filename, {
encoding: 'utf8'
});
View
15 app/libs.json
@@ -29,6 +29,21 @@
]
},
+ "jqui": "jqueryui",
+ "$ui": "jqueryui",
+ "jqueryui": {
+ "name": "jQuery UI",
+ "url": "http://ajax.googleapis.com/ajax/libs/jqueryui/{VERSION}/jquery-ui.js",
+ "dom_env": true,
+ "default_version": "1.8.18",
+ "versions": ["1", "1.8", "1.8.18"],
+ "get_real_version": "UI (\\d+\\.\\d+(?:\\.\\d+)?(?:pre)?)",
+ "look_in": ["jQuery.ui", "jQuery.widget", "jQuery.fn"],
+ "requires": {
+ "1.8": "http://code.jquery.com/jquery-1.7.js"
+ }
+ },
+
"mootools": {
"name": "MooTools",
"url": "http://ajax.googleapis.com/ajax/libs/mootools/{VERSION}/mootools.js",
View
1  index.html
@@ -13,6 +13,7 @@
<ul id="explore">
<li><a href="/jquery/">jQuery</a></li>
+ <li><a href="/jqueryui/">jQuery UI</a></li>
<li><a href="/mootools/">MooTools</a></li>
<li><a href="/dojo/">Dojo</a></li>
<li><a href="/underscore/">Underscore</a></li>
View
1  readme.md
@@ -36,3 +36,4 @@ It works by loading the library you specify into an instance of [jsdom](https://
* `1.0.0` - Gotta start somewhere
* `1.1.0` - Add `package.json` to manage dependencies. Linkifies `this.methodName` calls with new *LINK_MARKER* syntax (incl. name of item, e.g. `this.css`, and the full name, e.g. *jQuery.fn.css*). Sorts methods in sidebar by similarity to current method name (done with [similarity.js](https://github.com/jamespadolsey/similarity.js)).
* `1.1.1` - Fixed ?expand option so it doesn't go beyond the end of the source file. Fixed issue where names present in global scope, even if not functions, take precedence in resolver, e.g. window.outerHeight when querying `/jquery/outerHeight`. Fixed this by including a `typeof v == 'function'` check in the embedded resolver function. Also fixed error being thrown when a method can't be found.
+ * `1.1.2` - Added jQueryUI to libs and added a `require` option in the JSON config (currently only used with jQuery UI). Also generalised SHLoader.
Please sign in to comment.
Something went wrong with that request. Please try again.