site/js/docurium.js in docurium-0.4.0 vs site/js/docurium.js in docurium-0.4.1
- old
+ new
@@ -211,46 +211,58 @@
initialize: function() {
var gname = this.get('gname')
var fname = this.get('fname')
var docurium = this.get('docurium')
+ var isCallback = gname === 'callback'
var group = docurium.getGroup(gname)
var fdata = docurium.get('data')['functions']
- var functions = group[1]
+ var ldata = fdata
+ if (isCallback) {
+ var cdata = docurium.get('data')['callbacks']
+ ldata = cdata
+ } else {
+ var functions = group[1]
+ }
+
// Function Arguments
- var args = _.map(fdata[fname]['args'], function(arg) {
+ var args = _.map(ldata[fname]['args'], function(arg) {
return {link: this.hotLink(arg.type), name: arg.name, comment: arg.comment}
}, docurium)
- var data = fdata[fname]
+ var data = ldata[fname]
// function return value
var ret = data['return']
var returns = {link: docurium.hotLink(ret.type), comment: ret.comment}
// function signature
var sig = docurium.hotLink(ret.type) + ' ' + fname + '(' + data['argline'] + ');'
// version history
- var sigHist = docurium.get('signatures')[fname]
- var version = docurium.get('version')
- var sigs = _.map(sigHist.exists, function(ver) {
- var klass = []
- if (sigHist.changes[ver])
- klass.push('changed')
- if (ver == version)
- klass.push('current')
+ if (!isCallback) {
+ var sigHist = docurium.get('signatures')[fname]
+ var version = docurium.get('version')
+ var sigs = _.map(sigHist.exists, function(ver) {
+ var klass = []
+ if (sigHist.changes[ver])
+ klass.push('changed')
+ if (ver == version)
+ klass.push('current')
- return {url: '#' + functionLink(gname, fname, ver), name: ver, klass: klass.join(' ')}
- })
+ return {url: '#' + functionLink(gname, fname, ver), name: ver, klass: klass.join(' ')}
+ })
+ }
// GitHub link
var fileLink = docurium.github_file(data.file, data.line, data.lineto)
// link to the group
- var version = docurium.get('version')
- var alsoGroup = '#' + groupLink(group[0], version)
- var alsoLinks = _.map(functions, function(f) {
- return {url: '#' + functionLink(gname, f, version), name: f}
- })
+ if (!isCallback) {
+ var version = docurium.get('version')
+ var alsoGroup = '#' + groupLink(group[0], version)
+ var alsoLinks = _.map(functions, function(f) {
+ return {url: '#' + functionLink(gname, f, version), name: f}
+ })
+ }
this.set('data', {name: fname, data: data, args: args, returns: returns, sig: sig,
sigs: sigs, fileLink: fileLink, groupName: gname,
alsoGroup: alsoGroup, alsoLinks: alsoLinks})
}
@@ -302,17 +314,12 @@
})
var MainListView = Backbone.View.extend({
template: _.template($('#index-template').html()),
- initialize: function() {
- this.listenTo(this.collection, 'reset', this.render)
- },
-
render: function() {
this.el = this.template({groups: this.collection.toJSON()})
- this.trigger('redraw')
return this
},
})
var TypeModel = Backbone.Model.extend({
@@ -379,10 +386,11 @@
initialize: function(o) {
var group = o.group
var gname = group[0]
var fdata = o.functions
+ var cdata = o.callbacks
var version = o.version
this.functions = _.map(group[1], function(name) {
var url = '#' + functionLink(gname, name, version)
var d = fdata[name]
@@ -469,10 +477,20 @@
if (name.search(value) > -1) {
searchResults.push({url: url, name: name, match: type[1].type, navigate: tl})
}
})
+ // look for callbacks
+ _.each(data.callbacks, function(f, name) {
+ if (name.search(value) > -1) {
+ var gl = functionLink('callback', name, version)
+ var url = '#' + gl
+ searchResults.push({url: url, name: name, match: 'callback', navigate: gl})
+ return
+ }
+ })
+
this.reset(searchResults)
},
})
var SearchView = Backbone.View.extend({
@@ -529,20 +547,31 @@
docurium.set({'versions': data.versions, 'github': data.github, 'signatures': data.signatures, 'name': data.name})
docurium.setVersion()
})
},
- setVersion: function (version) {
+ setVersion: function (version, success) {
if(!version) {
version = _.first(docurium.get('versions'))
}
+
+ current = docurium.get('version')
+ if (current == version) {
+ if (success)
+ success();
+ return;
+ }
+
docurium.set({version: version})
+ p = this.loadDoc()
+ if (success)
+ p.then(success)
},
loadDoc: function() {
version = this.get('version')
- $.getJSON(version + '.json').then(function(data) {
+ return $.getJSON(version + '.json').then(function(data) {
docurium.set({data: data})
})
},
getGroup: function(gname) {
@@ -554,18 +583,27 @@
// look for structs and link them
hotLink: function(text) {
types = this.get('data')['types']
var version = this.get('version')
+
for(var i=0; i<types.length; i++) {
type = types[i]
typeName = type[0]
typeData = type[1]
- re = new RegExp(typeName + ' ', 'gi');
+ re = new RegExp(typeName + '\\s', 'gi');
var link = $('<a>').attr('href', '#' + typeLink(typeName, version)).append(typeName)[0]
text = text.replace(re, link.outerHTML + ' ')
}
+
+ var callbacks = this.get('data')['callbacks']
+ _.each(callbacks, function(cb, typeName) {
+ re = new RegExp(typeName + '$', 'gi');
+ var link = $('<a>').attr('href', '#' + functionLink('callback', typeName, version)).append(typeName)[0]
+ text = text.replace(re, link.outerHTML + ' ')
+ });
+
return text
},
groupOf: function (func) {
return this.get('data')['functions'][func]['group']
@@ -613,52 +651,64 @@
// and replate our URL with it, to avoid a back-button loop
this.navigate(this.doc.get('version'), {replace: true, trigger: true})
},
main: function(version) {
- this.doc.setVersion(version)
- var view = new MainListView({collection: this.groups})
- this.mainView.setActive(view)
+ var self = this
+ this.doc.setVersion(version, function() {
+ var view = new MainListView({collection: self.groups})
+ self.mainView.setActive(view)
+ })
},
group: function(version, gname) {
- this.doc.setVersion(version)
- var group = this.doc.getGroup(gname)
- var fdata = this.doc.get('data')['functions']
- var version = this.doc.get('version')
- var view = new GroupView({group: group, functions: fdata, version: version})
- this.mainView.setActive(view)
+ var self = this
+ this.doc.setVersion(version, function() {
+ var group = self.doc.getGroup(gname)
+ var fdata = self.doc.get('data')['functions']
+ var cdata = self.doc.get('data')['callbacks']
+ var version = self.doc.get('version')
+ var view = new GroupView({group: group, functions: fdata, callbacks: cdata, version: version})
+ self.mainView.setActive(view)
+ });
},
groupFun: function(version, gname, fname) {
- this.doc.setVersion(version)
- var model = new FunctionModel({docurium: this.doc, gname: gname, fname: fname})
- var view = new FunctionView({model: model})
- this.mainView.setActive(view)
+ var self = this
+ this.doc.setVersion(version, function() {
+ var model = new FunctionModel({docurium: self.doc, gname: gname, fname: fname})
+ var view = new FunctionView({model: model})
+ self.mainView.setActive(view)
+ })
},
showtype: function(version, tname) {
- this.doc.setVersion(version)
- var model = new TypeModel({docurium: this.doc, typename: tname})
- var view = new TypeView({model: model})
- this.mainView.setActive(view)
+ var self = this
+ this.doc.setVersion(version, function() {
+ var model = new TypeModel({docurium: self.doc, typename: tname})
+ var view = new TypeView({model: model})
+ self.mainView.setActive(view)
+ })
},
search: function(version, query) {
- this.doc.setVersion(version)
- var view = new SearchView({collection: this.search})
- $('#search-field').val(query).keyup()
- this.mainView.setActive(view)
+ var self = this
+ this.doc.setVersion(version, function() {
+ var view = new SearchView({collection: self.search})
+ $('#search-field').val(query).keyup()
+ self.mainView.setActive(view)
+ })
},
changelog: function(version, tname) {
// let's wait to process it until it's asked, and let's only do
// it once
if (this.changelogView == undefined) {
this.changelogView = new ChangelogView({model: this.doc})
}
- this.doc.setVersion()
- this.mainView.setActive(this.changelogView)
+ this.doc.setVersion(undefined, function() {
+ this.mainView.setActive(this.changelogView)
+ })
},
});
function functionLink(gname, fname, version) {
return version + "/group/" + gname + '/' + fname