Skip to content

Instantly share code, notes, and snippets.

@ixisio
Last active December 12, 2015 09:08
Show Gist options
  • Save ixisio/4748923 to your computer and use it in GitHub Desktop.
Save ixisio/4748923 to your computer and use it in GitHub Desktop.
define( function( require ) {
return JSONLoader = {
load : function(path, onCompleteOptions) {
this.opt = onCompleteOptions || {};
if(typeof jQuery === 'undefined' )
throw new Error('JSONLoader Module requires jQuery Library 1.7.x');
this.getJSON(path, function(obj) {
if(typeof JSONLoader.opt.event !== "undefined"){
JSONLoader.EventController.trigger(JSONLoader.opt.event.name, obj);
} else if(JSONLoader.opt.callback) {
JSONLoader.opt.callback.fn(obj);
}
});
},
getJSON : function(path, cb) {
jQuery.getJSON(path, function(data) {
cb( data );
});
},
set: function(key, value) {
this[key] = value;
}
}
});
var JSONLoader = require('JSONLoader').set('EventController', EventController);
JSONLoader.load('path/to/file.json', {
event: {
name : 'Event:JSONLoaded'
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment