add support for anchor-based permalink, p=sbrunner, r=me (closes #2785)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@11170 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -35,6 +35,16 @@ OpenLayers.Control.Permalink = OpenLayers.Class(OpenLayers.Control, {
|
||||
*/
|
||||
element: null,
|
||||
|
||||
/**
|
||||
* APIProperty: anchor
|
||||
* {Boolean} This option changes 3 things:
|
||||
* the character '#' is used in place of the character '?',
|
||||
* the window.href is updated if no element is provided.
|
||||
* When this option is set to true it's not recommend to provide
|
||||
* a base without provide an element.
|
||||
*/
|
||||
anchor: false,
|
||||
|
||||
/**
|
||||
* APIProperty: base
|
||||
* {String}
|
||||
@@ -59,14 +69,27 @@ OpenLayers.Control.Permalink = OpenLayers.Class(OpenLayers.Control, {
|
||||
* Parameters:
|
||||
* element - {DOMElement}
|
||||
* base - {String}
|
||||
* options - {Object} options to the control.
|
||||
* options - {Object} options to the control.
|
||||
*
|
||||
* Or for anchor:
|
||||
* options - {Object} options to the control.
|
||||
*/
|
||||
initialize: function(element, base, options) {
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
this.element = OpenLayers.Util.getElement(element);
|
||||
this.base = base || document.location.href;
|
||||
if (element !== null && typeof element == 'object' && !OpenLayers.Util.isElement(element)) {
|
||||
options = element;
|
||||
this.base = document.location.href;
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
if (this.element != null) {
|
||||
this.element = OpenLayers.Util.getElement(this.element);
|
||||
}
|
||||
}
|
||||
else {
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
this.element = OpenLayers.Util.getElement(element);
|
||||
this.base = base || document.location.href;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* APIMethod: destroy
|
||||
*/
|
||||
@@ -122,7 +145,7 @@ OpenLayers.Control.Permalink = OpenLayers.Class(OpenLayers.Control, {
|
||||
draw: function() {
|
||||
OpenLayers.Control.prototype.draw.apply(this, arguments);
|
||||
|
||||
if (!this.element) {
|
||||
if (!this.element && !this.anchor) {
|
||||
this.element = document.createElement("a");
|
||||
this.element.innerHTML = OpenLayers.i18n("permalink");
|
||||
this.element.href="";
|
||||
@@ -146,13 +169,19 @@ OpenLayers.Control.Permalink = OpenLayers.Class(OpenLayers.Control, {
|
||||
* Method: updateLink
|
||||
*/
|
||||
updateLink: function() {
|
||||
var separator = this.anchor ? '#' : '?';
|
||||
var href = this.base;
|
||||
if (href.indexOf('?') != -1) {
|
||||
href = href.substring( 0, href.indexOf('?') );
|
||||
if (href.indexOf(separator) != -1) {
|
||||
href = href.substring( 0, href.indexOf(separator) );
|
||||
}
|
||||
|
||||
href += '?' + OpenLayers.Util.getParameterString(this.createParams());
|
||||
this.element.href = href;
|
||||
href += separator + OpenLayers.Util.getParameterString(this.createParams());
|
||||
if (this.anchor && !this.element) {
|
||||
window.location.href = href;
|
||||
}
|
||||
else {
|
||||
this.element.href = href;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user