Created
July 11, 2012 20:43
-
-
Save newsomc/3093254 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
var PersonPageManager = (function(){ | |
var personPage = { | |
freebaseBio : $('#freebase-bio'), | |
bibliocommonsBlock : $('#block-block-123').find('.content'), | |
freebaseMID : Drupal.settings.nypl_new.freebase_mid, | |
personName : Drupal.settings.nypl_new.person_name, | |
personType : Drupal.settings.nypl_new.person_type, | |
baseURL : Drupal.settings.nypl_new.base_url, | |
freebaseURL : this.baseURL + '/nypl_freebase' + this.freebaseMID, | |
bibliocommonsURL : this.baseURL + '/nypl_bibliocommons/titles/' + this.personName, | |
isbn: '', | |
upcs: '', | |
itemTitle : null, | |
abstract_ajax_call: function(uri, cb){ | |
$.ajax({ | |
url: uri, | |
dataType: 'json', | |
success: cb | |
}); | |
}, | |
getFreebaseBio : function(cb){ | |
this.abstract_ajax_call(this.freebaseURL, cb); | |
}, | |
getBibliocommonsList : function(cb){ | |
this.abstract_ajax_call(this.bibliocommonsURL, cb); | |
}, | |
formatBibliocommonsImageLink : function(type, detailsURL, imageRef){ | |
switch(type){ | |
case 'isbn': | |
return '<a href="'+ this.detailsURL +'"><img src="http://www.syndetics.com/index.aspx?isbn=' + this.imageRef + '/MC.GIF&client=913-495-2400&type=xw12&oclc=ocn641997517&upc=""/></a>'; | |
break; | |
case 'upcs': | |
return '<a href="'+ this.detailsURL +'"><img src="http://www.syndetics.com/index.aspx?isbn=/MC.GIF&client=913-495-2400&type=xw12&oclc=ocn641997517&upc=' + this.imageRef + '"/></a>'; | |
break; | |
} | |
}, | |
formatBibliocommonsImageLink : function(type, detailsURL, imageRef){ | |
switch(this.type){ | |
case 'isbn': | |
return '<a href="'+ this.detailsURL +'"><img src="http://www.syndetics.com/index.aspx?isbn=' + this.imageRef + '/MC.GIF&client=913-495-2400&type=xw12&oclc=ocn641997517&upc=""/></a>'; | |
break; | |
case 'upcs': | |
return '<a href="'+ this.detailsURL +'"><img src="http://www.syndetics.com/index.aspx?isbn=/MC.GIF&client=913-495-2400&type=xw12&oclc=ocn641997517&upc=' + this.imageRef + '"/></a>'; | |
break; | |
} | |
}, | |
formatBibliocommonsDIV : function(detailsURL, title, subtitle, image_url){ | |
if(this.image_url){ | |
return '<div><a href="' + this.detailsURL + '">' + this.title + '</a></div>' + '<div>' + this.subtitle + '</div><div>' + this.image_url + '</div>'; | |
}else{ | |
return '<div><a href="' + this.detailsURL + '">' + this.title + '</a></div>' + '<div>' + this.subtitle + '</div>'; | |
} | |
}, | |
}; | |
return function(){ | |
personPage.getFreebaseBio(function(data, status){ | |
personPage.freebaseBio.prepend(data.result.description); | |
}); | |
personPage.getBibliocommonsList(function(data, status){ | |
for (var i in data.titles) { | |
var record = data.titles[i]; | |
if(record.hasOwnProperty("sub_title")){ | |
var subtitle = record.sub_title; | |
}else{ | |
var subtitle = ''; | |
} | |
if(!personPage.itemTitle || personPage.itemTitle != record.title){ | |
if(record.hasOwnProperty("isbns")){ | |
if(record.isbns[0]){ | |
personPage.isbn = record.isbns[0]; | |
}else{ | |
personPage.isbn = record.isbns[1]; | |
} | |
imageURL = personPage.formatBibliocommonsImageLink("isbn", record.details_url, personPage.isbn); | |
personPage.bibliocommonsBlock.append(personPage.formatBibliocommonsDIV(record.details_url, record.title, subtitle, imageURL)); | |
} | |
else if(record.hasOwnProperty("upcs")){ | |
if(record.upcs[0]){ | |
personPage.upcs = record.upcs[0]; | |
}else{ | |
personPage.upcs = record.upcs[1]; | |
} | |
imageURL = personPage.formatBibliocommonsImageLink("upcs", record.details_url, personPage.upcs); | |
personPage.bibliocommonsBlock.append(personPage.formatBibliocommonsDIV(record.details_url, record.title, subtitle, imageURL)); | |
} | |
else{ | |
bibliocommonsBlock.append(formatBibliocommonsDIV(record.details_url, record.title, subtitle)); | |
} | |
personPage.itemTitle = record.title; | |
} | |
} | |
}); | |
}; | |
})(); | |
PersonPageManager(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment