OpenLayers OpenLayers

Ticket #1479: pop2.patch

File pop2.patch, 5.1 kB (added by euzuro, 9 months ago)

take two. thanks for the sharp eye, bro

  • lib/OpenLayers/Popup/Framed.js

    old new  
    248248     * Method: createBlocks 
    249249     */ 
    250250    createBlocks: function() { 
    251         if (!this.relativePosition) { 
    252             // this.relativePosition can't be set until we have a map 
    253             // set: if it's not set, we can't create blocks. (See #1479)  
    254             return false;  
    255         }     
    256          
    257251        this.blocks = []; 
    258252 
    259         var position = this.positionBlocks[this.relativePosition]; 
     253        //since all positions contain the same number of blocks, we can  
     254        // just pick the first position and use its blocks array to create 
     255        // our blocks array 
     256        var firstPosition = null; 
     257        for(var key in this.positionBlocks) { 
     258            firstPosition = key; 
     259            break; 
     260        } 
     261         
     262        var position = this.positionBlocks[firstPosition]; 
    260263        for (var i = 0; i < position.blocks.length; i++) { 
    261264 
    262265            var block = {}; 
     
    280283            block.div.appendChild(block.image); 
    281284            this.groupDiv.appendChild(block.div); 
    282285        } 
    283          
    284         return true; 
    285286    }, 
    286287 
    287288    /** 
     
    292293     */ 
    293294    updateBlocks: function() { 
    294295        if (!this.blocks) { 
    295             var cont = this.createBlocks(); 
    296             if (!cont) {  
    297                 return false; 
    298             }      
     296            this.createBlocks(); 
    299297        } 
    300298         
    301          
    302         var position = this.positionBlocks[this.relativePosition]; 
    303         for (var i = 0; i < position.blocks.length; i++) { 
    304  
    305             var positionBlock = position.blocks[i]; 
    306             var block = this.blocks[i]; 
    307  
    308             // adjust sizes 
    309             var l = positionBlock.anchor.left; 
    310             var b = positionBlock.anchor.bottom; 
    311             var r = positionBlock.anchor.right; 
    312             var t = positionBlock.anchor.top; 
    313  
    314             //note that we use the isNaN() test here because if the  
    315             // size object is initialized with a "auto" parameter, the  
    316             // size constructor calls parseFloat() on the string,  
    317             // which will turn it into NaN 
    318             // 
    319             var w = (isNaN(positionBlock.size.w)) ? this.size.w - (r + l)  
    320                                                   : positionBlock.size.w; 
    321  
    322             var h = (isNaN(positionBlock.size.h)) ? this.size.h - (b + t)  
    323                                                   : positionBlock.size.h; 
    324  
    325             block.div.style.width = w + 'px'; 
    326             block.div.style.height = h + 'px'; 
    327  
    328             block.div.style.left = (l != null) ? l + 'px' : ''; 
    329             block.div.style.bottom = (b != null) ? b + 'px' : ''; 
    330             block.div.style.right = (r != null) ? r + 'px' : '';             
    331             block.div.style.top = (t != null) ? t + 'px' : ''; 
    332  
    333             block.image.style.left = positionBlock.position.x + 'px'; 
    334             block.image.style.top = positionBlock.position.y + 'px'; 
     299        if (this.relativePosition) { 
     300            var position = this.positionBlocks[this.relativePosition]; 
     301            for (var i = 0; i < position.blocks.length; i++) { 
     302     
     303                var positionBlock = position.blocks[i]; 
     304                var block = this.blocks[i]; 
     305     
     306                // adjust sizes 
     307                var l = positionBlock.anchor.left; 
     308                var b = positionBlock.anchor.bottom; 
     309                var r = positionBlock.anchor.right; 
     310                var t = positionBlock.anchor.top; 
     311     
     312                //note that we use the isNaN() test here because if the  
     313                // size object is initialized with a "auto" parameter, the  
     314                // size constructor calls parseFloat() on the string,  
     315                // which will turn it into NaN 
     316                // 
     317                var w = (isNaN(positionBlock.size.w)) ? this.size.w - (r + l)  
     318                                                      : positionBlock.size.w; 
     319     
     320                var h = (isNaN(positionBlock.size.h)) ? this.size.h - (b + t)  
     321                                                      : positionBlock.size.h; 
     322     
     323                block.div.style.width = w + 'px'; 
     324                block.div.style.height = h + 'px'; 
     325     
     326                block.div.style.left = (l != null) ? l + 'px' : ''; 
     327                block.div.style.bottom = (b != null) ? b + 'px' : ''; 
     328                block.div.style.right = (r != null) ? r + 'px' : '';             
     329                block.div.style.top = (t != null) ? t + 'px' : ''; 
     330     
     331                block.image.style.left = positionBlock.position.x + 'px'; 
     332                block.image.style.top = positionBlock.position.y + 'px'; 
     333            } 
     334     
     335            this.contentDiv.style.left = this.padding.left + "px"; 
     336            this.contentDiv.style.top = this.padding.top + "px"; 
    335337        } 
    336  
    337         this.contentDiv.style.left = this.padding.left + "px"; 
    338         this.contentDiv.style.top = this.padding.top + "px"; 
    339338    }, 
    340339 
    341340    CLASS_NAME: "OpenLayers.Popup.Framed"