Commits

Juan Carlos Picado Herrera committed 71ea09d

Improved object abstraction

Comments (0)

Files changed (3)

enme-js/resources-enme-war/src/main/resources/resource/js/me/core/support/GeolocationSupport.js

    * Geolocation support
    * @method
    */
-  var GeoLocationSupport = function() {
+  var GeoLocationSupport = function(options) {
        var parent = this;
        this.location = null;
        try {
           if (Modernizr.geolocation) {
-              var geo_success = function(position) {
-                  console.info("dddd", position.coords.latitude, position.coords.longitude);
-              };
-
-              var geo_error = function() {
-                  console.error("Sorry, no position available.");
-              };
-
-              var geo_options = {
-                enableHighAccuracy: true,
-                maximumAge        : 30000,
-                timeout           : 27000
-              };
-
-              var wpid = navigator.geolocation.watchPosition(geo_success, geo_error, geo_options);
+              navigator.geolocation.getCurrentPosition(
+                      function(){
+                        options.success.apply(parent, arguments);
+                      },
+                      options.error , {
+                        timeout: 10000
+              });
           } else {
               parent.location = new Location();
+              options.error();
           }
        } catch(error) {
           console.info("error geo object", error);

enme-js/resources-enme-war/src/main/resources/resource/js/me/web/widget/geo/BasicGeoWidget.js

        * @method postCreate
        */
       postCreate : function () {
-         var geolocationSupport = new GeolocationSupport();
-         console.log("geo", geolocationSupport);
-         if (geolocationSupport.isLocated()) {
-             console.log("geolocationSupport", geolocationSupport.getLocation());
-         }
+         var geo = new GeolocationSupport({
+
+          /**
+           *
+           * @method
+           */
+          success: function(p) {
+            console.log("success", arguments);
+            alert(p.coords.latitude);
+          },
+
+          /**
+           *
+           * @method
+           */
+          error: function(){
+            console.log("error", arguments);
+          }
+         });
       }
   });
 });

enme-war/enme-views/src/main/webapp/WEB-INF/views/tweetpoll/decorators/completed.jsp

                     <spring:message code="tweetpoll.votes.link" />
                 </a>
             </div>
-            <!-- <div data-dojo-type="me/web/widget/geo/BasicGeoWidget"> </div> -->
+            <div data-dojo-type="me/web/widget/geo/BasicGeoWidget"> </div>
         </div>
 
     </section>