Changeset 36242

Show
Ignore:
Timestamp:
12/23/09 00:38:08 (3 years ago)
Author:
whym
Message:

* add 'all-node' command.
* fix set-pin and unset-pin for correctly displaying/hiding pins

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/userscripts/ldrize.user.js

    r36074 r36242  
    247247                  { name: 'current-link', 
    248248                        command: function(stdin){return self.getCurrentLink() || []}}, 
     249                  { name: 'all-node', 
     250                        command: function(stdin){ 
     251                                return self.getParagraphes().list.map(function(i){return i.node;});}}, 
    249252                  { name: 'clear-pin', 
    250253                        command: function(stdin){if(!!stdin) self.clearPinlist(); return stdin}}, 
     
    476479  setPin: function(nodes){ 
    477480          var self = this; 
    478           this.togglePin(nodes, function(node){self.addPinToPinList(node)}); 
     481          this.togglePin(nodes, function(node){return self.addPinToPinList(node);}); 
    479482  }, 
    480483  unsetPin: function(nodes){ 
    481484          var self = this; 
    482           this.togglePin(nodes, function(node){self.removePinFromPinList(node)}); 
     485          this.togglePin(nodes, function(node){return self.removePinFromPinList(node);}); 
    483486  }, 
    484487  togglePin: function(nodes, fn){ 
     
    486489          if(typeof fn == 'undefined'){ 
    487490                  fn = function(node){ 
    488                           self.removePinFromPinList(node) || self.addPinToPinList(node); 
     491                          return self.removePinFromPinList(node) || self.addPinToPinList(node); 
    489492                  } 
    490493          } 
    491494          toArray(nodes).forEach(function(node){ 
    492                   fn(node); 
    493                   self.toggleClassForPin(node); 
     495                  if ( fn(node) ) { 
     496                          self.toggleClassForPin(node); 
     497                  } 
    494498          }); 
    495499          var a = this.html.pinlist_number; 
     
    542546                          xpath = '(descendant-or-self::img | descendant::text()[normalize-space(self::text()) != ""])'; 
    543547                          matches = $X(xpath, node); 
    544                           if(!matches.length) return; 
     548                          if(!matches.length) return false; 
    545549                          var height = new Paragraph(matches[0]).y; 
    546550                          res = []; 
     
    568572          } 
    569573          this.html.pinlist_container.appendChild(paragraph.html); 
     574          return true; 
    570575  }, 
    571576  removePinFromPinList: function(node){ 
    572577          var para = this.getParagraphes().find(function(para){return node == para.node}); 
    573578          var view = para.html; 
    574           if(!view) return; 
     579          if(!view) return false; 
    575580          var children = toArray(this.html.pinlist_container.childNodes); 
    576581          var html = children.find(function(arg){return arg == view}); 
    577           if(!html) return; 
     582          if(!html) return false; 
    578583          this.html.pinlist_container.removeChild(html); 
    579584          return true;