]> dev.renevier.net Git - syp.git/blobdiff - js/syp.js
do not display popup when there is no content at all
[syp.git] / js / syp.js
index 3228e62b5a7aeecbf70bb1f94c615b1b8aa13f94..d83b1fefe44801cfb69318dc671cac378c54820d 100644 (file)
--- a/js/syp.js
+++ b/js/syp.js
@@ -3,7 +3,7 @@
 
 OpenLayers.Control.SypAttribution = OpenLayers.Class (OpenLayers.Control.Attribution, {
     updateAttribution: function() {
-        var attributions = ['propulsed by <a href="http://syp.renevier.net">syp</a>'];
+        var attributions = [SypStrings.propulsedByLink];
         if (this.map && this.map.layers) {
             for(var i=0, len=this.map.layers.length; i<len; i++) {
                 var layer = this.map.layers[i];
@@ -111,7 +111,7 @@ var SYP = {
     checkForFeatures: function() {
         var features = this.dataLayer.features;
         if (features.length == 0) {
-            var message = "Il n'y a aucune image enregistrĂ©e sur le site.";
+            var message = SypStrings.noImageRegistered;
             this.Utils.displayUserMessage(message, "warn");
         }
     },
@@ -131,7 +131,16 @@ var SYP = {
     },
 
     onFeatureUnselect: function (feature) {
-        var popup = feature.popup;
+        var map = feature.layer.map;
+        var permaControl = map.getControlsByClass("OpenLayers.Control.Permalink");
+        if (permaControl[0]) {
+            permaControl[0].div.style.display = "";
+        }
+        if (!feature.popup) {
+            this.map.events.unregister("movestart", this, this._unselect);
+            return;
+        }
+        popup = feature.popup;
         if (popup.visible()) {
             popup.hide();
         }
@@ -139,13 +148,17 @@ var SYP = {
 
     onFeatureSelect: function(feature) {
         var map = feature.layer.map;
+        var permaControl = map.getControlsByClass("OpenLayers.Control.Permalink");
+        if (permaControl[0]) {
+            permaControl[0].div.style.display = "none";
+        }
         var popup = feature.popup;
 
         var brCorner = SYP.Utils.brCorner(map, 8);
 
         // we cannot reuse popup; we need to recreate it in order for IE
         // expressions to work. Otherwise, we get a 0x0 image on second view.
-        if (popup) { 
+        if (popup) {
             popup.destroy();
         }
         var contentHTML;
@@ -157,6 +170,10 @@ var SYP = {
         } else {
             contentHTML = feature.attributes.description;
         }
+        if (!contentHTML || !contentHTML.length) {
+            this.map.events.register("movestart", this, this._unselect = function () { this.unselect(feature)});
+            return;
+        }
         popup = SYP.createPopup(brCorner, contentHTML);
         var control = this;
         popup.hide = function () {
@@ -201,6 +218,12 @@ var SYP = {
     }
 };
 
+// if possible, determine language with HTTP_ACCEPT_LANGUAGE instead of
+// navigator.language
+if (OpenLayers.Lang[SypStrings.language]) {
+    OpenLayers.Lang.setCode(SypStrings.language);
+}
+
 // avoid alerts
 OpenLayers.Console.userError = function(error) { 
     SYP.Utils.displayUserMessage(error, "error");