Merge pull request #429 from flamandro/permalink
Fix Trac #3381. Applied patch from ticket #3381 to Permalink tests and updated Permalink.js to pass the tests by maintaining anchors in links.
This commit is contained in:
@@ -172,11 +172,18 @@ OpenLayers.Control.Permalink = OpenLayers.Class(OpenLayers.Control, {
|
||||
updateLink: function() {
|
||||
var separator = this.anchor ? '#' : '?';
|
||||
var href = this.base;
|
||||
var anchor = null;
|
||||
if (href.indexOf("#") != -1 && this.anchor == false) {
|
||||
anchor = href.substring( href.indexOf("#"), href.length);
|
||||
}
|
||||
if (href.indexOf(separator) != -1) {
|
||||
href = href.substring( 0, href.indexOf(separator) );
|
||||
}
|
||||
|
||||
href += separator + OpenLayers.Util.getParameterString(this.createParams());
|
||||
var splits = href.split("#");
|
||||
href = splits[0] + separator+ OpenLayers.Util.getParameterString(this.createParams());
|
||||
if (anchor) {
|
||||
href += anchor;
|
||||
}
|
||||
if (this.anchor && !this.element) {
|
||||
window.location.href = href;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
}
|
||||
function test_Control_Permalink_base_with_query (t) {
|
||||
t.plan( 3 );
|
||||
|
||||
|
||||
control = new OpenLayers.Control.Permalink('permalink', "./edit.html?foo=bar" );
|
||||
map = new OpenLayers.Map('map');
|
||||
layer = new OpenLayers.Layer.WMS('Test Layer', "http://example.com" );
|
||||
@@ -162,7 +162,38 @@
|
||||
map.pan(-5, 0, {animate:false});
|
||||
t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and querystring ending with '?'");
|
||||
map.destroy();
|
||||
}
|
||||
|
||||
function test_Control_Permalink_base_with_anchor (t) {
|
||||
t.plan( 4 );
|
||||
control = new OpenLayers.Control.Permalink('permalink', "./edit.html#foo" );
|
||||
map = new OpenLayers.Map('map');
|
||||
layer = new OpenLayers.Layer.WMS('Test Layer', "http://example.com" );
|
||||
map.addLayer(layer);
|
||||
if (!map.getCenter()) map.zoomToMaxExtent();
|
||||
map.addControl(control);
|
||||
map.pan(5, 0, {animate:false});
|
||||
OpenLayers.Util.getElement('edit_permalink').href = './edit.html?zoom=2&lat=0&lon=1.75781&layers=B#foo';
|
||||
t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and anchor");
|
||||
|
||||
control = new OpenLayers.Control.Permalink('permalink', "./edit.html#" );
|
||||
map.addControl(control);
|
||||
map.pan(0, 0, {animate:false});
|
||||
OpenLayers.Util.getElement('edit_permalink').href = './edit.html?zoom=2&lat=0&lon=1.75781&layers=B#';
|
||||
t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and an empty anchor");
|
||||
|
||||
control = new OpenLayers.Control.Permalink('permalink', "./edit.html?foo=bar#test" );
|
||||
OpenLayers.Util.getElement('edit_permalink').href = './edit.html?foo=bar&zoom=2&lat=0&lon=1.75781&layers=B#test';
|
||||
map.addControl(control);
|
||||
map.pan(5, 0, {animate:false});
|
||||
map.pan(-5, 0, {animate:false});
|
||||
t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base, querystring and an anchor");
|
||||
|
||||
control = new OpenLayers.Control.Permalink('permalink', "./edit.html#foo", {anchor : true} );
|
||||
map.addControl(control);
|
||||
map.pan(0, 0, {animate:false});
|
||||
OpenLayers.Util.getElement('edit_permalink').href = './edit.html#zoom=2&lat=0&lon=1.75781&layers=B';
|
||||
t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and an empty anchor");
|
||||
}
|
||||
|
||||
function test_Control_Permalink_nonRepeating (t) {
|
||||
|
||||
Reference in New Issue
Block a user