Advertisement
Guest User

Parashuram

a guest
Jan 28th, 2008
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Sez =
  2. {
  3.     BASE_URL : "http://scraps.geekstimeout.com/out/",
  4.    
  5.     init : function()
  6.     {
  7.         this.commentsDiv = document.getElementById("comments");
  8.         if (typeof(this.commentsDiv) == "undefined")
  9.         {
  10.             return;
  11.         }
  12.         console.log("Sez Initialized");
  13.         this.loadScripts(this.onAllScriptsLoaded);
  14.     },
  15.    
  16.     loadScripts : function(callbackHandler)
  17.     {  
  18.         var includeScripts =
  19.         [
  20.             "http://yui.yahooapis.com/2.4.1/build/yahoo/yahoo-min.js",
  21.             "http://yui.yahooapis.com/2.4.1/build/event/event-min.js",
  22.             "http://yui.yahooapis.com/2.4.1/build/yahoo-dom-event/yahoo-dom-event.js",
  23.             "http://yui.yahooapis.com/2.4.1/build/dragdrop/dragdrop-min.js",
  24.             "http://yui.yahooapis.com/2.4.1/build/get/get-beta-min.js",
  25.             "http://yui.yahooapis.com/2.4.1/build/animation/animation-min.js",
  26.         ];
  27.         var loadedScripts = 0;
  28.         var currentObject = this;
  29.        
  30.         for (var i = 0; i < includeScripts.length; i++)
  31.         {
  32.             var scriptTag = document.createElement("script");
  33.             scriptTag.src = includeScripts[i];
  34.            
  35.             scriptTag.onreadystatechange = function()
  36.             {
  37.                 var rs = this.readyState;
  38.                 if ("loaded" === rs || "complete" === rs)
  39.                 {
  40.                     console.log(this.src + " loaded");
  41.                     loadedScripts++;
  42.                     if (loadedScripts >= includeScripts.length)
  43.                     {
  44.                         callbackHandler.call(currentObject);
  45.                     }
  46.                 }
  47.             }
  48.            
  49.             scriptTag.onload = function()
  50.             {
  51.                     console.log(this.src + " loaded");
  52.                     loadedScripts++;
  53.                     if (loadedScripts >= includeScripts.length)
  54.                     {
  55.                         callbackHandler.call(currentObject);
  56.                     }
  57.             }
  58.             document.body.appendChild(scriptTag);
  59.         }
  60.     },
  61.  
  62.  
  63.     /**
  64.      * Callback handler called when all the specified scripts have completed loaded
  65.      */
  66.     onAllScriptsLoaded : function()
  67.     {
  68.         console.log("All scripts have been loaded");
  69.         this.placeButtons();
  70.     },
  71.    
  72.     placeButtons : function()
  73.     {
  74.         var commentBlock = document.getElementById("comments-block");
  75.         console.log("Placing SezWho buttons");
  76.        
  77.         this.userRating = {};
  78.        
  79.         var brandingButton = document.createElement("div");
  80.         brandingButton.innerHTML = "Powered by <img src = 'http://www.sezwho.com/img/branding.png'>"
  81.         commentBlock.appendChild(brandingButton);
  82.        
  83.         var commentators = commentBlock.getElementsByTagName("dt");
  84.         for (var i = 0; i < commentators.length; i++)
  85.         {
  86.             var cName = commentators[i].getElementsByTagName("a");
  87.             if (cName.length <=1 )
  88.             {
  89.                 // This is a comment by anonymous, so no use of using it
  90.                 console.log("Anonymouse comment")
  91.                 continue;
  92.             }
  93.  
  94.             console.log("Checking for comments by " + cName[1]);
  95.             var params =
  96.             {
  97.                 onSuccess : this.getRatingHandler,
  98.                 onFailure : this.onGetRatingFailed,
  99.                 scope : this,
  100.                 autopurge : true,
  101.                 data : {'field' : commentators[i], 'userId' : cName[1].toString()}
  102.                
  103.             }
  104.             YAHOO.util.Get.script(Sez.BASE_URL + "getRating.js?userId=" + escape(cName[1]), params)
  105.            
  106.         }
  107.     },
  108.    
  109.     getRatingHandler : function(o)
  110.     {
  111.         console.log("Setting ratings for " + o.data.userId);
  112.         var ratingButton = document.createElement("div");
  113.         ratingButton.style.fontSize = "12px";
  114.         ratingButton.style.border = "SOLID 1px GREY";
  115.         ratingButton.style.padding = "5px";
  116.        
  117.         var docPos = "Rating : ";
  118.         for (var i = 0; i < parseInt(this.userRating[escape(o.data.userId)]); i++)
  119.         {
  120.             docPos += "<img src = 'http://www.gamefools.com/images/star_empty.gif'>";
  121.         }
  122.         docPos += "<br>Was this comment useful to you ? <a style = 'padding : 2px; border : SOLID 1px BLACK; background-color : GREY'>Yes </a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a style = 'padding : 2px; border : SOLID 1px BLACK; background-color : GREY'>No</a>"
  123.         ratingButton.innerHTML = docPos;
  124.         console.log(o.data.field);
  125.         o.data.field.appendChild(ratingButton);
  126.     },
  127.    
  128.     onGetRatingFailed : function(o)
  129.     {
  130.         console.log("Call handler failed");
  131.     }
  132. };
  133.  
  134. Sez.init();
  135.  
  136. if (typeof(console) == undefined)
  137. {
  138.     var console = {}
  139.     console.log = function(){};
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement