Latest 5 titles from Tumblr API using jquery


/ Published in: JavaScript
Save to your folder(s)

Get the latest 5 titles from the Tumblr API using jquery


Copy this code and paste it in your HTML
  1. <!-- Called from an html file: -->
  2.  
  3. <!-- HTML File receiving Output -->
  4.  
  5. <style type="text/css">
  6. #title_list {
  7. background-color:#DEDEDE;
  8. font-family:arial;
  9. margin:auto 0 0;
  10. padding:0;
  11. position:relative;
  12. width:360px;
  13. }
  14. #title_list ul, li {
  15. list-style: none;
  16. display: block;
  17. margin:3px;
  18. }
  19. </style>
  20.  
  21. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  22. <script type="text/javascript" src="title_list.js?url=criticalstocks.com"></script>
  23.  
  24. <!-- End of HTML File -->
  25.  
  26. <!-- title_list.js Javascript file below -->
  27.  
  28. (function () {
  29. var config = new Object();
  30. var start = 0;
  31.  
  32. var scripts = document.getElementsByTagName('script');
  33. var this_script = scripts[scripts.length - 1];
  34. var params = this_script.src.replace(/^[^\?]+\??/,'').split('&');
  35.  
  36. for(var i=0; i<params.length; i++) {
  37. var tmp = params[i].split("=");
  38. config[tmp[0]] = unescape(tmp[1]);
  39. }
  40.  
  41. var url_base = ((typeof(config.url) == 'undefined') ?
  42. ('http://' + document.domain + '/') : ('http://' + config.url + '/'));
  43.  
  44. document.write(
  45. '<div id="titles">' +
  46. '<div id="loading_titles">'+
  47. '<a href="#"><img src="./ajax-loader.gif"> </a>'+
  48. '</div>' +
  49. '<ul id="title_list"></ul>' +
  50. '</div>'
  51. );
  52.  
  53. $(document).ready(function() {
  54. function sortNum(a, b) {return (a - b);}
  55. function sortByValue(keyArray, valueMap) {
  56. return keyArray.sort(function(a,b){return valueMap[a]-valueMap[b];});
  57. }
  58. function getProperties (obj) {
  59. var properties = [];
  60. for (var property in obj) properties.push(property);
  61. return properties;
  62. }
  63. function getTitles() {
  64. $.getJSON(url_base+'api/read/json?callback=?&num=5&start='+start, function(data) {
  65. $(data.posts).each(function(i, post) {
  66. if(typeof(post["regular-title"]) == 'string')
  67. {
  68. title = post["regular-title"];
  69. link = '<a href="'+post["url"]+'" title="'+post["regular-title"]+'">'+post["regular-title"]+'</a>';
  70. output = '<li>'+link+' </li>';
  71. $("#title_list").append(output);
  72. $("#loading_titles").html('');
  73. }
  74. });
  75. });
  76. }
  77. getTitles();
  78. });
  79. })();

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.