pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Javascript pastebin - collaborative debugging tool View Help


Posted by psichron on Thu 3 Jul 00:57
report abuse | download | new post

  1. // import Nevow.Athena
  2.  
  3. MyModule = {};
  4.  
  5. MyModule.MyWidget = Nevow.Athena.Widget.subclass('MyModule.MyWidget');
  6.  
  7. MyModule.MyWidget.methods(
  8.     function __init__(self,node) {
  9.         MyModule.MyWidget.upcall(self, '__init__', node);
  10.         self.fadeInItems = [];
  11.         self.fadeTimer = null;
  12.         self.fadeSteps = 50;
  13.         self.timeStep = 50;
  14.     },
  15.  
  16.     function serviceFadeInItems(self) {      
  17.         var newColorValue;
  18.  
  19.         if (self.fadeInItems.length == 0) {
  20.             clearInterval(self.fadeTimer); //Stop the fadeIn timer.
  21.             return;
  22.         }
  23.         for (var i=self.fadeInItems.length-1; i >= 0; i--) {
  24.             var item = self.fadeInItems[i][0];
  25.             var targetRGBvals = self.fadeInItems[i][1];      
  26.             var currentRGBvals = self.fadeInItems[i][2];
  27.             var RGBSteps = self.fadeInItems[i][3];
  28.        
  29.             for (var c=0; c < 3; c++) {            
  30.                 newColorValue = currentRGBvals[c] - RGBSteps[c];
  31.            
  32.                 if (newColorValue <= targetRGBvals[c]) {                
  33.                     currentRGBvals[c] = targetRGBvals[c];
  34.                 } else {              
  35.                     currentRGBvals[c] = Math.floor(newColorValue);
  36.                 }
  37.             }
  38.             if (currentRGBvals[0] == targetRGBvals[0]
  39.                     && currentRGBvals[1] == targetRGBvals[1]
  40.                     && currentRGBvals[2] == targetRGBvals[2])
  41.             {
  42.                 self.fadeInItems.splice(i,1);
  43.             }
  44.             item.style.backgroundColor = "rgb("+currentRGBvals.join(",")+")";
  45.         }    
  46.     },
  47.  
  48.     function fadeIn(self, item, targetRGBVals) {
  49.         var RGBSteps = [(255-targetRGBVals[0])/self.fadeSteps,(255-targetRGBVals[1])/self.fadeSteps,(255-targetRGBVals[2])/self.fadeSteps];
  50.         var newFadeItem = [item,targetRGBVals,[255,255,255],RGBSteps];
  51.         self.fadeInItems.push(newFadeItem); //item, targetColor, currentColor
  52.         if (self.fadeInItems.length == 1) //If this is the only item, start the timer.
  53.         {
  54.             self.fadeTimer = setInterval(function () {self.serviceFadeInItems()}, self.timeStep)            
  55.         }
  56.     },
  57.  
  58.        
  59.     function addRow(self, eventID) {
  60.         var table = self.nodeById('colorTableId');
  61.         var newRow = table.insertRow(-1);
  62.         newRow.insertCell(0).innerHTML = eventID;
  63.         self.fadeIn(newRow, [194,228,177]);
  64.         return eventID;
  65.     },
  66.  
  67.     function echo(self, argument) {
  68.         alert("Echoing " + argument);
  69.         return argument;
  70.     }
  71.  
  72.     );

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me