Return to Snippet

Revision: 34127
at October 17, 2010 21:08 by morningcatmedia


Initial Code
<!-- Called from an html file: -->

<!-- HTML File receiving Output -->

<style type="text/css">
#title_list {
background-color:#DEDEDE;
font-family:arial;
margin:auto 0 0;
padding:0;
position:relative;
width:360px;
}
#title_list ul, li {
list-style: none;
display: block;
margin:3px;
}
</style>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="title_list.js?url=criticalstocks.com"></script>

<!-- End of HTML File -->

<!-- title_list.js Javascript file below -->

(function () {
  var config = new Object();
  var start = 0;

  var scripts = document.getElementsByTagName('script');
  var this_script = scripts[scripts.length - 1];
  var params = this_script.src.replace(/^[^\?]+\??/,'').split('&');

  for(var i=0; i<params.length; i++) {
    var tmp = params[i].split("=");
    config[tmp[0]] = unescape(tmp[1]);
  }

  var url_base = ((typeof(config.url) == 'undefined') ?
    ('http://' + document.domain + '/') : ('http://' + config.url + '/'));

 document.write(
    '<div id="titles">' +
      '<div id="loading_titles">'+
       '<a href="#"><img src="./ajax-loader.gif"> </a>'+
      '</div>' +
      '<ul id="title_list"></ul>' +
    '</div>'
  );

  $(document).ready(function() {
    function sortNum(a, b) {return (a - b);}
    function sortByValue(keyArray, valueMap) {
      return keyArray.sort(function(a,b){return valueMap[a]-valueMap[b];});
    }
    function getProperties (obj) {
      var properties = [];
      for (var property in obj) properties.push(property);
      return properties;
    }
    function getTitles() {
      $.getJSON(url_base+'api/read/json?callback=?&num=5&start='+start, function(data) {
        $(data.posts).each(function(i, post) {
            if(typeof(post["regular-title"]) == 'string')
               {
                title = post["regular-title"];
                link = '<a href="'+post["url"]+'" title="'+post["regular-title"]+'">'+post["regular-title"]+'</a>';
                output = '<li>'+link+' </li>';
                $("#title_list").append(output);
                $("#loading_titles").html('');
                }
        });
      });
    }
   getTitles();
  });
})();

Initial URL

                                

Initial Description
Get the latest 5 titles from the Tumblr API using jquery

Initial Title
Latest 5 titles from Tumblr API using jquery

Initial Tags
jquery, json

Initial Language
JavaScript