Ticket #1589: FisheyeList.js.patch

File FisheyeList.js.patch, 8.4 kB (added by werner.punz@…, 2 years ago)

javascript patch

  • .

     
    6060 
    6161        enableCrappySvgSupport: false, 
    6262 
     63        maxNoDisplayItems:10000, //all items 
     64        scrollerBegin: 0, //first item beginning item 
     65        visibleWindow:5, 
    6366 
     67        persist: true,          // save splitter positions in a cookie 
     68         
    6469        // 
    6570        // 
    6671        // 
     
    129134        }, 
    130135         
    131136        postCreate: function(args, frag) { 
     137         
     138                if(this.persist){ 
     139                        this.restoreState(); 
     140                } 
     141                if(this.visibleWindow > this.children.length) { 
     142                        this.visibleWindow = this.children.length; 
     143                } 
     144                if(this.scrollerBegin > this.children.length) { 
     145                        this.scrollerBegin = this.children.length - this.visibleWindow; 
     146                }        
    132147                this.initializePositioning(); 
    133148 
    134149                // 
     
    141156                // Deactivate the menu if mouse is moved off screen (doesn't work for FF?) 
    142157                dojo.event.connect(document.documentElement, "onmouseout", this, "onBodyOut"); 
    143158                dojo.event.connect(this, "addChild", this, "initializePositioning"); 
     159         
     160        }, 
     161 
     162         
     163        onRightScroll: function(ev) { 
     164                this.scrollerBegin = (this.scrollerBegin + this.visibleWindow < this.itemCount? (this.scrollerBegin + 1): this.scrollerBegin); 
     165                this.initializePositioning(); 
     166 
    144167        }, 
    145168 
     169        onLeftScroll: function(ev) { 
     170                this.scrollerBegin = (this.scrollerBegin > 0 ? (this.scrollerBegin - 1): 0); 
     171                this.initializePositioning(); 
     172         
     173        }, 
     174         
     175        calcScrollerEnd : function() { 
     176                return ((this.scrollerBegin + this.visibleWindow) > this.children.length ?  
     177                        this.children.length  : this.scrollerBegin+this.visibleWindow); 
     178        }, 
     179         
    146180        initializePositioning: function(){ 
     181                if(this.persist){ 
     182                        this.saveState(this); 
     183                } 
     184                 
     185                 
     186                 
    147187                this.itemCount = this.children.length; 
    148188 
    149                 this.barWidth  = (this.isHorizontal ? this.itemCount : 1) * this.itemWidth; 
     189                var scrollerEnd = this.calcScrollerEnd(); 
     190 
     191                var barItemCount = (this.itemCount > this.maxNoDisplayItems ? this.maxNoDisplayItems: this.itemCount); 
     192                 
     193 
     194                this.barWidth  = (this.isHorizontal ? this.visibleWindow : 1) * this.itemWidth; 
    150195                this.barHeight = (this.isHorizontal ? 1 : this.itemCount) * this.itemHeight; 
    151196 
    152197                this.totalWidth  = this.proximityLeft + this.proximityRight  + this.barWidth; 
     
    152197                this.totalWidth  = this.proximityLeft + this.proximityRight  + this.barWidth; 
    153198                this.totalHeight = this.proximityTop  + this.proximityBottom + this.barHeight; 
    154199 
     200                 
    155201                // 
    156202                // calculate effect ranges for each item 
    157203                // 
     204                for(var i=0; i<(this.scrollerBegin); i+=1) { 
     205                        this.children[i].posX = 1000; 
     206                        this.children[i].posY = 1000; 
     207                } 
     208 
     209                for(var i=scrollerEnd; i<(this.children.length); i+=1) { 
     210                        this.children[i].posX = 1000; 
     211                        this.children[i].posY = 1000; 
     212                } 
    158213 
    159                 for (var i=0; i<this.children.length; i++){ 
     214                for (var i=this.scrollerBegin; i<scrollerEnd; i+=1){ 
    160215 
    161                         this.children[i].posX = this.itemWidth  * (this.isHorizontal ? i : 0); 
     216                        this.children[i].posX = this.itemWidth  * (this.isHorizontal ? (i - this.scrollerBegin) : 0); 
    162217                        this.children[i].posY = this.itemHeight * (this.isHorizontal ? 0 : i); 
    163218 
    164219                        this.children[i].cenX = this.children[i].posX + (this.itemWidth  / 2); 
     
    184239                } 
    185240 
    186241 
     242 
     243 
    187244                // 
    188245                // create the bar 
    189246                // 
     
    195252                // 
    196253                // position the items 
    197254                // 
    198                 for (var i=0; i<this.children.length; i++){ 
     255                for(var i=0; i<this.scrollerBegin; i+=1) { 
    199256                        var itm = this.children[i]; 
    200257                        var elm = itm.domNode; 
    201                         elm.style.left   = itm.posX + 'px'; 
     258                        //elm.style.left   = 8000 + 'px'; 
     259                        //elm.style.top    = 8000 + 'px'; 
     260                        elm.style.visibility = "hidden"; 
     261                } 
     262 
     263                for(var i=scrollerEnd; i<(this.children.length); i+=1) { 
     264                        var itm = this.children[i]; 
     265                        var elm = itm.domNode; 
     266                        //elm.style.left   = 8000 + 'px'; 
     267                        //elm.style.top    = 8000 + 'px'; 
     268                        elm.style.visibility = "hidden"; 
     269                } 
     270 
     271                 
     272                for (var i=this.scrollerBegin; i<scrollerEnd; i+=1){ 
     273                        var itm = this.children[i]; 
     274                        var elm = itm.domNode; 
     275                        elm.style.left   = itm.posX  + 'px'; 
    202276                        elm.style.top    = itm.posY + 'px'; 
    203277                        elm.style.width  = this.itemWidth + 'px'; 
    204278                        elm.style.height = this.itemHeight + 'px'; 
    205                          
     279                        elm.style.visibility = "visible"; 
    206280                        if ( itm.svgNode ) { 
    207281                                itm.svgNode.style.position = 'absolute'; 
    208282                                itm.svgNode.style.left = this.itemPadding+'%'; 
     
    279353                }else{ 
    280354                        if (this.isOver){ 
    281355                                this.setDormant(e); 
     356                                this.initializePositioning(); 
    282357                        } 
    283358                } 
    284359        }, 
     
    297372                var y=this.pos.y; 
    298373 
    299374                if( this.itemCount <= 0 ){ return; } 
     375                var scrollerEnd = this.calcScrollerEnd(); 
    300376 
    301377                // 
    302378                // figure out our main index 
     
    309385                        (1.0-this.timerScale)*this.itemWidth + this.timerScale*this.itemMaxWidth : 
    310386                        (1.0-this.timerScale)*this.itemHeight + this.timerScale*this.itemMaxHeight ; 
    311387 
    312                 var cen = ((pos - prx) / siz) - 0.5; 
     388                var cen = ((pos - prx) / siz) - 0.5 + this.scrollerBegin; 
    313389                var max_off_cen = (sim / siz) - 0.5; 
    314390 
    315391                if (max_off_cen > this.effectUnits){ max_off_cen = this.effectUnits; } 
     
    357433                // set the sizes 
    358434                // 
    359435 
    360                 for(var i=0; i<this.itemCount; i++){ 
     436                for(var i=this.scrollerBegin; i<scrollerEnd; i+=1){ 
    361437 
    362438                        var weight = this.weightAt(cen, i); 
    363439 
     
    371447                // 
    372448 
    373449                var main_p = Math.round(cen); 
     450                 
     451                 
     452                if(main_p < this.scrollerBegin) 
     453                        main_p = this.scrollerBegin; 
     454                if(cen > 0 && cen  < this.scrollerBegin) 
     455                        cen = this.scrollerBegin; 
     456                 
    374457                var offset = 0; 
    375458 
    376                 if (cen < 0){ 
    377                         main_p = 0; 
     459                var scrollerEnd = this.calcScrollerEnd(); 
    378460 
    379                 }else if (cen > this.itemCount - 1){ 
    380  
    381                         main_p = this.itemCount -1; 
    382  
     461                if (cen < this.scrollerBegin){ 
     462                        main_p = this.scrollerBegin; 
     463                } else if (cen > scrollerEnd - 1){ 
     464                        main_p = scrollerEnd - 1; 
    383465                }else{ 
    384  
    385466                        offset = (cen - main_p) * ((this.isHorizontal ? this.itemWidth : this.itemHeight) - this.children[main_p].sizeMain); 
    386467                } 
    387468 
     
    406487                this.setitemsize(p, w); 
    407488 
    408489                var wx = w; 
    409                 for(var i=p; i<this.itemCount; i++){ 
     490                 
     491                for(var i=p; i<this.itemCount; i+=1){ 
    410492                        wx = 0.8 * wx; 
    411493                        this.setitemsize(i, wx); 
    412494                } 
     
    412494                } 
    413495 
    414496                var wx = w; 
     497                 
    415498                for(var i=p; i>=0; i--){ 
    416499                        wx = 0.8 * wx; 
    417500                        this.setitemsize(i, wx); 
     
    451534                        this.children[p].domNode.style.top  = y + 'px'; 
    452535 
    453536                        this.children[p].domNode.style.left  = this.children[p].usualX + 'px'; 
    454  
     537                         
    455538                }else{ 
    456539 
    457540                        this.children[p].sizeW = w; 
     
    489572        }, 
    490573 
    491574        positionElementsFrom: function(p, offset){ 
    492  
    493575                var pos = 0; 
     576                var scrollerEnd = this.calcScrollerEnd();; 
    494577 
     578         
    495579                if (this.isHorizontal){ 
    496580                        pos = Math.round(this.children[p].usualX + offset); 
    497581                        this.children[p].domNode.style.left = pos + 'px'; 
     
    508592 
    509593                var bpos = pos; 
    510594 
    511                 for(var i=p-1; i>=0; i--){ 
     595                for(var y=p-1; y>=this.scrollerBegin; y-=1){ 
    512596 
    513                         bpos -= this.children[i].sizeMain; 
     597                        bpos -= this.children[y].sizeMain; 
    514598 
    515599                        if (this.isHorizontal){ 
    516                                 this.children[i].domNode.style.left = bpos + 'px'; 
     600                                this.children[y].domNode.style.left = bpos + 'px'; 
    517601                        }else{ 
    518                                 this.children[i].domNode.style.top = bpos + 'px'; 
     602                                this.children[y].domNode.style.top = bpos + 'px'; 
    519603                        } 
    520                         this.positionLabel(this.children[i]); 
     604                        this.positionLabel(this.children[y]); 
    521605                } 
    522606 
    523607                // 
     
    526610 
    527611                var apos = pos; 
    528612 
    529                 for(var i=p+1; i<this.itemCount; i++){ 
     613                for(var i=p+1; i< scrollerEnd;  i+=1){ 
    530614 
    531615                        apos += this.children[i-1].sizeMain; 
    532616 
     
    596680                        dojo.lang.setTimeout(this, "expandSlowly", 10); 
    597681                } 
    598682        }, 
     683         
     684        _getCookieName: function(i) { 
     685                return this.widgetId + "_" + i; 
     686        }, 
    599687 
     688        restoreState: function () { 
     689                var cookieName = this._getCookieName(0); 
     690                var cookieValue = dojo.io.cookie.getCookie(cookieName); 
     691                if(cookieValue == null) return; 
     692                //dojo.debug("val"+cookieValue); 
     693                this.scrollerBegin = parseInt(cookieValue); 
     694                 
     695        }, 
     696 
     697        saveState: function (){ 
     698                var cookieName = this._getCookieName(0); 
     699                dojo.io.cookie.setCookie(cookieName,this.scrollerBegin, null, null, null, null); 
     700        }, 
     701 
     702 
    600703        destroy: function(){ 
    601704                // need to disconnect when we destroy 
    602705                dojo.event.disconnect(document.documentElement, "onmouseout", this, "onBodyOut"); 
     
    608711dojo.widget.defineWidget( 
    609712        "dojo.widget.FisheyeListItem", 
    610713        dojo.widget.HtmlWidget, 
    611 { 
     714{        
    612715        // Constructor arguments 
    613716        iconSrc: "", 
    614717        svgSrc: "", 
     
    700803                        var scale_x = w / this.zeroWidth; 
    701804                        var scale_y = h / this.zeroHeight; 
    702805 
    703                         for(var i=0; i<this.svgDoc.childNodes.length; i++){ 
     806                        for(var i=0; i<this.svgDoc.childNodes.length; i+=1){ 
    704807                                if (this.svgDoc.childNodes[i].setAttribute){ 
    705808                                        this.svgDoc.childNodes[i].setAttribute( "transform", "scale("+scale_x+","+scale_y+")" ); 
    706809                                }