$(function() { // our document model - stores the datastructure generated from docurium var Docurium = Backbone.Model.extend({ defaults: {'version': 'unknown'}, initialize: function() { this.loadVersions() }, loadVersions: function() { $.getJSON("project.json", function(data) { docurium.set({'versions': data.versions, 'github': data.github, 'signatures': data.signatures, 'name': data.name}) if(data.name) { $('#site-title').text(data.name + ' API') document.title = data.name + ' API' } docurium.setVersionPicker() docurium.setVersion() }) }, setVersionPicker: function () { vers = docurium.get('versions') $('#version-list').empty().hide() for(var i in vers) { version = vers[i] vlink = $('').attr('href', '#' + version).append(version).click( function() { $('#version-list').hide(100) }) $('#version-list').append($('
  • ').append(vlink)) } vlink = $('').attr('href', '#' + 'p/changelog').append("Changelog").click ( function () { $('#version-list').hide(100) }) $('#version-list').append($('
  • ').append(vlink)) }, setVersion: function (version) { if(!version) { version = _.first(docurium.get('versions')) } if(docurium.get('version') != version) { docurium.set({'version': version}) $('#site-title').attr('href', '#' + version) docurium.loadDoc() } }, loadDoc: function() { version = this.get('version') $.ajax({ url: version + '.json', context: this, dataType: 'json', success: function(data){ this.set({'data': data}) Backbone.history.start() } }) }, collapseSection: function(data) { $(this).next().toggle(100) return false }, showIndexPage: function() { version = docurium.get('version') ws.saveLocation(version) data = docurium.get('data') content = $('.content') content.empty() content.append($('

    ').append("Public API Functions")) sigHist = docurium.get('signatures') // Function Groups for (var i in data['groups']) { group = data['groups'][i] content.append($('

    ').addClass('funcGroup').append(group[0])) list = $('

    ').addClass('functionList') for(var j in group[1]) { fun = group[1][j] link = $('').attr('href', '#' + groupLink(group[0], fun)).append(fun) if(sigHist[fun].changes[version]) { link.addClass('changed') } if(version == _.first(sigHist[fun].exists)) { link.addClass('introd') } list.append(link) if(j < group[1].length - 1) { list.append(', ') } } content.append(list) } }, showFun: function(gname, fname) { id = '#groupItem' + gname ref = parseInt($(id).attr('ref')) group = docurium.get('data')['groups'][ref] fdata = docurium.get('data')['functions'] gname = group[0] functions = group[1] content = $('.content') content.empty() // Show Function Name content.append($('

    ').addClass('funcTitle').append(fname)) if(fdata[fname]['description']) { sub = content.append($('

    ').addClass('funcDesc').append( ' ' + fdata[fname]['description'] )) } // Show Function Arguments argtable = $('').addClass('funcTable') args = fdata[fname]['args'] for(var i=0; i') row.append($('
    ').attr('valign', 'top').attr('nowrap', true).append(this.hotLink(arg.type))) row.append($('').attr('valign', 'top').addClass('var').append(arg.name)) row.append($('').addClass('comment').append(arg.comment)) argtable.append(row) } content.append(argtable) // Show Function Return Value retdiv = $('
    ').addClass('returns') retdiv.append($('

    ').append("returns")) rettable = $('').addClass('funcTable') retrow = $('') rettable.append(retrow) retdiv.append(rettable) ret = fdata[fname]['return'] retrow.append($('
    ').attr('valign', 'top').append(this.hotLink(ret.type))) if(ret.comment) { retrow.append($('').addClass('comment').append(ret.comment)) } content.append(retdiv) // Show Non-Parsed Function Comments if (fdata[fname]['comments']) { content.append($('
    ').append(fdata[fname]['comments']))
          }
    
          // Show Function Signature
          ex = $('').addClass('params')
          ex.append(this.hotLink(fdata[fname]['return']['type'] + ' ' + fname + '(' + fdata[fname]['argline'] + ');'))
          example = $('
    ').addClass('example') example.append($('

    ').append("signature")) example.append(ex) content.append(example) // Show Function History sigs = $('
    ').addClass('signatures') sigs.append($('

    ').append("versions")) sigHist = docurium.get('signatures')[fname] for(var i in sigHist.exists) { ver = sigHist.exists[i] link = $('').attr('href', '#' + groupLink(gname, fname, ver)).append(ver) if(sigHist.changes[ver]) { link.addClass('changed') } if(ver == docurium.get('version')) { link.addClass('current') } sigs.append(link) } content.append(sigs) // Link to Function Def on GitHub link = this.github_file(fdata[fname].file, fdata[fname].line, fdata[fname].lineto) flink = $('').attr('target', 'github').attr('href', link).append(fdata[fname].file) content.append($('
    ').addClass('fileLink').append("Defined in: ").append(flink)) // Show other functions in this group also = $('
    ').addClass('also') flink = $('' + group[0] + '') flink.click( docurium.showGroup ) also.append("Also in ") also.append(flink) also.append(" group:
    ") for(i=0; i').attr('href', '#' + groupLink(gname, f)).append(f) also.append(link) also.append(', ') } content.append(also) this.addHotlinks() }, showChangeLog: function() { content = $('.content') content.empty() content.append($('

    ').append("Function Changelog")) // for every version, show which functions added, removed, changed - from HEAD down versions = docurium.get('versions') sigHist = docurium.get('signatures') lastVer = _.first(versions) // fill changelog struct changelog = {} for(var i in versions) { version = versions[i] changelog[version] = {'deletes': [], 'changes': [], 'adds': []} } // figure out the adds, deletes and changes for(var func in sigHist) { lastv = _.last(sigHist[func].exists) firstv = _.first(sigHist[func].exists) if (func != '__attribute__') { changelog[firstv]['adds'].push(func) } if(lastv && (lastv != lastVer)) { vi = _.indexOf(versions, lastv) delv = versions[vi - 1] changelog[delv]['deletes'].push(func) } for(var v in sigHist[func].changes) { changelog[v]['changes'].push(func) } } // display the data for(var i in versions) { version = versions[i] content.append($('

    ').append(version)) cl = $('
    ').addClass('changelog') for(var type in changelog[version]) { adds = changelog[version][type] adds.sort() addsection = $('

    ') for(var j in adds) { add = adds[j] gname = docurium.groupOf(add) if(type != 'deletes') { addlink = $('').attr('href', '#' + groupLink(gname, add, version)).append(add) } else { addlink = add } addsection.append($('

  • ').addClass(type).append(addlink)) } cl.append(addsection) } content.append(cl) } }, showType: function(data, manual) { if(manual) { id = '#typeItem' + domSafe(manual) ref = parseInt($(id).attr('ref')) } else { ref = parseInt($(this).attr('ref')) } tdata = docurium.get('data')['types'][ref] tname = tdata[0] data = tdata[1] ws.saveLocation(typeLink(tname)) content = $('.content') content.empty() content.append($('

    ').addClass('funcTitle').append(tname).append($("").append(data.type))) content.append($('

    ').append(data.value)) if(data.block) { content.append($('

    ').append(data.block))
          }
    
          var ret = data.used.returns
          if (ret.length > 0) {
            content.append($('

    ').append('Returns')) } for(var i=0; i').attr('href', '#' + groupLink(gname, ret[i])).append(ret[i]) flink.click( docurium.showFun ) content.append(flink) content.append(', ') } var needs = data.used.needs if (needs.length > 0) { content.append($('

    ').append('Argument In')) } for(var i=0; i').attr('href', '#' + groupLink(gname, needs[i])).append(needs[i]) flink.click( docurium.showFun ) content.append(flink) content.append(', ') } link = docurium.github_file(data.file, data.line, data.lineto) flink = $('').attr('target', 'github').attr('href', link).append(data.file) content.append($('
    ').addClass('fileLink').append("Defined in: ").append(flink)) return false }, showGroup: function(data, manual, flink) { if(manual) { id = '#groupItem' + manual ref = parseInt($(id).attr('ref')) } else { ref = parseInt($(this).attr('ref')) } group = docurium.get('data')['groups'][ref] fdata = docurium.get('data')['functions'] gname = group[0] ws.saveLocation(groupLink(gname)); functions = group[1] $('.content').empty() $('.content').append($('

    ').append(gname + ' functions')) table = $('').addClass('methods') for(i=0; i') row.append($('
    ').attr('nowrap', true).attr('valign', 'top').append(d['return']['type'].substring(0, 20))) link = $('').attr('href', '#' + groupLink(gname, f)).append(f) row.append($('').attr('valign', 'top').addClass('methodName').append( link )) args = d['args'] argtd = $('') for(j=0; j')) } row.append(argtd) table.append(row) } $('.content').append(table) for(var i=0; i').attr('href', '#' + groupLink(gname, f)).append(f) $('.content').append($('

    ').append(link).append($('').append(argsText))) $('.content').append($('
    ').append(fdata[f]['rawComments']))
          }
          return false
        },
    
        // look for structs and link them 
        hotLink: function(text) {
          types = this.get('data')['types']
          for(var i=0; i' + typeName + ' '
            text = text.replace(re, link)
          }
          return text
        },
    
        groupHash: false,
        groupOf: function (func) {
          if(!this.groupHash) {
            this.groupHash = {}
            data = this.get('data')
            for(var i=0; i')
          title = $('

    Functions

    ').click( this.collapseSection ) menu.append(title) list = $('