Advertisement
Guest User

Untitled

a guest
Aug 10th, 2012
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function CreateBadge(btext, post_id)
  2. {
  3.     // Function for inserting a badge
  4.     var post_path = "post_"+post_id;
  5.     $j("div#"+post_path+" div.user_badge div.name").append("<div style='background-color:#269469; padding:2px; color:white;'>"+btext+"</div>");
  6. }
  7.  
  8. function DefineBadge(tags, post_id)
  9. {
  10.     // Function define badge by tags
  11.     if (tags.toLowerCase().indexOf("badge_gurudeveloper") >= 0)
  12.     {
  13.         CreateBadge("The Best Dev!", post_id);             
  14.     }
  15. }
  16.  
  17.  
  18. // Get current url
  19. var s_url=window.location.pathname;
  20. var s_urlparts = s_url.split('/');
  21. var s_section = s_urlparts[1];
  22.  
  23. // Run if we in the "entries" section
  24. if (s_section=='entries')
  25. {
  26.     // Get topic id
  27.     var s_topicID = s_urlparts[2].split('-')[0];
  28.     // Use new awesome API
  29.     var s_zurl = "/api/v2/topics/"+s_topicID+"/comments.json";
  30.    
  31.     new Ajax.Request(s_zurl,
  32.     {
  33.         method:'GET',asynchronous: true,onSuccess: function(transport)
  34.         {
  35.             var obj = transport.responseText.evalJSON();
  36.             $j.each(obj.topic_comments, function () {
  37.                 var post_id=this.id;
  38.                 var user_id = this.user_id;
  39.                
  40.                 //Get user data    
  41.  
  42.                 //Call server. Use old API =);
  43.                 var s_zurl_u = "/users/"+user_id+".json";
  44.                 new Ajax.Request(s_zurl_u,
  45.                 {
  46.                     method:'GET',asynchronous: false,onSuccess: function(transport)
  47.                     {
  48.                         var obj = transport.responseText.evalJSON();
  49.                         tags = obj['current_tags'];
  50.        
  51.                         DefineBadge(tags, post_id);
  52.                     }
  53.                 });
  54.  
  55.             });
  56.         }
  57.     });
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement