Google maps window: open once per click
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 2 Dec 2012 19:07:01 +0000 (20:07 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 2 Dec 2012 19:07:01 +0000 (20:07 +0100)
Bonus: now you can edit directly the coordinates without opening an annoying new window every time
you click in the GPS coodinates box. After closing the goolge maps window it can be opened agais just clicking
again in the GPS coordinates box.

apps/companyfront/modules/ad/templates/_form.php
apps/companyfront/modules/admap/templates/admapSuccess.php
apps/companyfront/modules/admap/templates/officemapSuccess.php
apps/companyfront/modules/office/templates/_formCustomOffice.php

index e8f0041..789be45 100644 (file)
@@ -2,30 +2,35 @@
 <?php use_javascripts_for_form($form) ?>
 
 <script type="text/javascript">
+    var alreadyOpened = false;
 
     $(document).ready(function(){
-        var longitude = document.getElementById('ad_longitude');
-        var latitude = document.getElementById('ad_latitude');
-        var adMapURL = 'http://localhost/companyfront_dev.php/admap/admap?latitude='+latitude.value+'&longitude='+longitude.value;
         $('#ad_longitude').click(function() {
-        newwindow=window.open(adMapURL, '', 'menubar=no,height=600,width=600');
-            if (window.focus) {
-                newwindow.focus()
+            if (!window.alreadyOpened) {
+                window.alreadyOpened = true;
+                var longitude = document.getElementById('ad_longitude');
+                var latitude = document.getElementById('ad_latitude');
+                var adMapURL = 'http://localhost/companyfront_dev.php/admap/admap?latitude='+latitude.value+'&longitude='+longitude.value;
+                newwindow=window.open(adMapURL, '', 'menubar=no,height=600,width=600');
+                if (window.focus) {
+                    newwindow.focus()
+                }
             }
-            return false;
         });
     });
 
     $(document).ready(function(){
-        var longitude = document.getElementById('ad_longitude');
-        var latitude = document.getElementById('ad_latitude');
-        var adMapURL = 'http://localhost/companyfront_dev.php/admap/admap?latitude='+latitude.value+'&longitude='+longitude.value;
         $('#ad_latitude').click(function() {
-        newwindow=window.open(adMapURL, '', 'menubar=no,height=600,width=600');
-            if (window.focus) {
-                newwindow.focus()
+            if (!window.alreadyOpened) {
+                window.alreadyOpened = true;
+                var longitude = document.getElementById('ad_longitude');
+                var latitude = document.getElementById('ad_latitude');
+                var adMapURL = 'http://localhost/companyfront_dev.php/admap/admap?latitude='+latitude.value+'&longitude='+longitude.value;
+                newwindow=window.open(adMapURL, '', 'menubar=no,height=600,width=600');
+                if (window.focus) {
+                    newwindow.focus()
+                }
             }
-            return false;
         });
     });
 
index 54be0ca..5381521 100644 (file)
             document.body.appendChild(script);
         }
 
+        function taskOnExit() {
+            self.opener.alreadyOpened = false;
+        }
+
         window.onload = loadScript;
 
-        google.maps.event.addDomListener(window, 'load', initialize);
+        window.onbeforeunload = taskOnExit;
     </script>
   </head>
 
index 4f23690..a8737a6 100644 (file)
             document.body.appendChild(script);
         }
 
+        function taskOnExit() {
+            self.opener.alreadyOpened = false;
+        }
+
         window.onload = loadScript;
 
-        google.maps.event.addDomListener(window, 'load', initialize);
+        window.onbeforeunload = taskOnExit;
+
     </script>
   </head>
 
index f2f5054..b5793b3 100644 (file)
 </script>
 
 <script type="text/javascript">
+    var alreadyOpened = false;
 
     $(document).ready(function(){
-        var longitude = document.getElementById('office_longitude');
-        var latitude = document.getElementById('office_latitude');
-        var adMapURL = 'http://localhost/companyfront_dev.php/admap/officemap?latitude='+latitude.value+'&longitude='+longitude.value;
         $('#office_longitude').click(function() {
-            newwindow=window.open(adMapURL, '', 'menubar=no,height=600,width=600');
-            if (window.focus) {
-                newwindow.focus()
+            if (!window.alreadyOpened) {
+                window.alreadyOpened = true;
+                var longitude = document.getElementById('office_longitude');
+                var latitude = document.getElementById('office_latitude');
+                var adMapURL = 'http://localhost/companyfront_dev.php/admap/officemap?latitude='+latitude.value+'&longitude='+longitude.value;
+                newwindow=window.open(adMapURL, '', 'menubar=no,height=600,width=600');
+                if (window.focus) {
+                    newwindow.focus()
+                }
             }
         });
     });
 
     $(document).ready(function(){
-        var longitude = document.getElementById('office_longitude');
-        var latitude = document.getElementById('office_latitude');
-        var adMapURL = 'http://localhost/companyfront.php/admap/officemap?latitude='+latitude.value+'&longitude='+longitude.value;
         $('#office_latitude').click(function() {
-            newwindow=window.open(adMapURL, '', 'menubar=no,height=600,width=600');
-            if (window.focus) {
-                newwindow.focus()
+            if (!window.alreadyOpened) {
+                window.alreadyOpened = true;
+                var longitude = document.getElementById('office_longitude');
+                var latitude = document.getElementById('office_latitude');
+                var adMapURL = 'http://localhost/companyfront_dev.php/admap/officemap?latitude='+latitude.value+'&longitude='+longitude.value;
+                newwindow=window.open(adMapURL, '', 'menubar=no,height=600,width=600');
+                if (window.focus) {
+                    newwindow.focus()
+                }
             }
         });
     });