Ticket #1061: patch-1061-A2.diff
| File patch-1061-A2.diff, 7.2 kB (added by elemoine, 1 year ago) |
|---|
-
tests/test_Popup.html
old new 29 29 } 30 30 31 31 function test_02_Popup_constructor (t) { 32 t.plan( 5);32 t.plan( 8 ); 33 33 34 34 var id = "chicken"; 35 35 var w = 500; … … 39 39 var lat = 40; 40 40 var ll = new OpenLayers.LonLat(lon, lat); 41 41 var content = "foo"; 42 var closePopupCallback = function(e) {}; 42 43 44 OpenLayers.Function.bindAsEventListener = function(func, obj) { return func }; 43 45 popup = new OpenLayers.Popup(id, 44 46 ll, 45 47 sz, 46 content); 48 content, 49 true, 50 closePopupCallback); 47 51 48 52 t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" ); 49 53 t.eq(popup.id, id, "popup.id set correctly"); 50 54 t.ok(popup.lonlat.equals(ll), "popup.lonlat set correctly"); 51 55 t.ok(popup.size.equals(sz), "popup.size set correctly"); 52 56 t.eq(popup.contentHTML, content, "contentHTML porpoerty of set correctly"); 57 // test that a browser event is registered on click on popup closebox 58 var map = new OpenLayers.Map('map'); 59 map.addPopup(popup); 60 var ok = false; 61 var closeImgDiv = document.getElementById(popup.id + "_close"); 62 var cacheID = closeImgDiv._eventCacheID; 63 for (var i = 0; i < OpenLayers.Event.observers[cacheID].length; i++) { 64 var observer = OpenLayers.Event.observers[cacheID][i]; 65 if (observer.element == closeImgDiv) { 66 t.ok(true, "An event was registered for the close box element"); 67 t.eq(observer.name, "click", "A click event was registered for the close box element"); 68 t.ok(observer.observer == closePopupCallback, 69 "The proper callback function was registered for the close box element"); 70 ok = true; 71 break; 72 } 73 } 74 if (!ok) { 75 t.fail("No event was registered for the close box element"); 76 } 53 77 } 54 78 55 79 function test_Popup_updatePosition(t) { -
lib/OpenLayers/Popup/AnchoredBubble.js
old new 32 32 * a 'size' (<OpenLayers.Size>) and 'offset' (<OpenLayers.Pixel>) 33 33 * (Note that this is generally an <OpenLayers.Icon>). 34 34 * closeBox - {Boolean} 35 * closeBoxCallback - {Function} Function to be called on closeBox click. 35 36 */ 36 initialize:function(id, lonlat, size, contentHTML, anchor, closeBox) { 37 initialize:function(id, lonlat, size, contentHTML, anchor, closeBox, 38 closeBoxCallback) { 37 39 OpenLayers.Popup.Anchored.prototype.initialize.apply(this, arguments); 38 40 }, 39 41 -
lib/OpenLayers/Popup/Anchored.js
old new 38 38 * anchor - {Object} Object which must expose a 'size' <OpenLayers.Size> 39 39 * and 'offset' <OpenLayers.Pixel> (generally an <OpenLayers.Icon>). 40 40 * closeBox - {Boolean} 41 * closeBoxCallback - {Function} Function to be called on closeBox click. 41 42 */ 42 initialize:function(id, lonlat, size, contentHTML, anchor, closeBox) { 43 var newArguments = new Array(id, lonlat, size, contentHTML, closeBox); 43 initialize:function(id, lonlat, size, contentHTML, anchor, closeBox, 44 closeBoxCallback) { 45 var newArguments = new Array(id, lonlat, size, contentHTML, closeBox, 46 closeBoxCallback); 44 47 OpenLayers.Popup.prototype.initialize.apply(this, newArguments); 45 48 46 49 this.anchor = (anchor != null) ? anchor -
lib/OpenLayers/Popup.js
old new 117 117 * contentHTML - {String} The HTML content to display inside the 118 118 * popup. 119 119 * closeBox - {Boolean} Whether to display a close box inside 120 * the popup. 120 * the popup. 121 * closeBoxCallback - {Function} Function to be called on closeBox click. 121 122 */ 122 initialize:function(id, lonlat, size, contentHTML, closeBox ) {123 initialize:function(id, lonlat, size, contentHTML, closeBox, closeBoxCallback) { 123 124 if (id == null) { 124 125 id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); 125 126 } … … 165 166 closeImg.style.top = this.padding + "px"; 166 167 this.groupDiv.appendChild(closeImg); 167 168 168 var closePopup = function(e) {169 var closePopup = closeBoxCallback || function(e) { 169 170 this.hide(); 170 171 OpenLayers.Event.stop(e); 171 172 } -
examples/select-feature-openpopup.html
old new 12 12 </style> 13 13 <script src="../lib/OpenLayers.js"></script> 14 14 <script type="text/javascript"> 15 var map, drawControls, select; 15 var map, drawControls, selectControl, selectedFeature; 16 function onPopupClose(evt) { 17 selectControl.unselect(selectedFeature); 18 } 16 19 function onFeatureSelect(feature) { 20 selectedFeature = feature; 17 21 popup = new OpenLayers.Popup.Anchored("chicken", 18 22 feature.geometry.getBounds().getCenterLonLat(), 19 23 new OpenLayers.Size(250,75), 20 24 "<div style='font-size:.8em'>Feature: " + feature.id +"<br />Area: " + feature.geometry.getArea()+"</div>", 21 null, true );25 null, true, onPopupClose); 22 26 feature.popup = popup; 23 27 map.addPopup(popup); 24 28 } … … 38 42 map.addControl(new OpenLayers.Control.LayerSwitcher()); 39 43 map.addControl(new OpenLayers.Control.MousePosition()); 40 44 45 selectControl = new OpenLayers.Control.SelectFeature(polygonLayer, 46 {onSelect: onFeatureSelect, onUnselect: onFeatureUnselect}); 41 47 drawControls = { 42 48 polygon: new OpenLayers.Control.DrawFeature(polygonLayer, 43 49 OpenLayers.Handler.Polygon), 44 select: new OpenLayers.Control.SelectFeature(polygonLayer, 45 {onSelect: onFeatureSelect, 46 onUnselect: onFeatureUnselect 47 }) 50 select: selectControl 48 51 }; 49 52 50 53 for(var key in drawControls) {
