MDL-21400 converted iplookup to YUI3, removed in_head()
authorPetr Skoda <skodak@moodle.org>
Sat, 6 Feb 2010 12:12:23 +0000 (12:12 +0000)
committerPetr Skoda <skodak@moodle.org>
Sat, 6 Feb 2010 12:12:23 +0000 (12:12 +0000)
iplookup/index.php
iplookup/module.js [moved from iplookup/functions.js with 84% similarity]

index c43e151..f2d2231 100644 (file)
@@ -153,10 +153,9 @@ if (empty($CFG->googlemapkey)) {
     $info = implode(' - ', $info);
     $note = implode('<br />', $note);
 
-    $PAGE->requires->js("http://maps.google.com/maps?file=api&amp;v=2&amp;key=$CFG->googlemapkey", true)->in_head();
-    $PAGE->requires->js('/iplookup/functions.js')->in_head();
-    $PAGE->requires->yui2_lib('event');
-    $PAGE->requires->js_function_call('iplookup_load', array($latitude, $longitude));
+    $PAGE->requires->js(new moodle_url("http://maps.google.com/maps?file=api&v=2&key=$CFG->googlemapkey"));
+    $module = array('name'=>'core_iplookup', 'fullpath'=>'/iplookup/module.js');
+    $PAGE->requires->js_init_call('M.core_iplookup.init', array($latitude, $longitude), true, $module);
 
     $PAGE->set_title(get_string('iplookup', 'admin').': '.$info);
     $PAGE->set_heading($info);
similarity index 84%
rename from iplookup/functions.js
rename to iplookup/module.js
index 529e010..bf76d87 100644 (file)
@@ -22,7 +22,9 @@
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-function iplookup_load(latitude, longitude) {
+M.core_iplookup = {};
+
+M.core_iplookup.init = function(Y, latitude, longitude) {
     if (GBrowserIsCompatible()) {
         var map = new GMap2(document.getElementById("map"));
         map.addControl(new GSmallMapControl());
@@ -32,12 +34,10 @@ function iplookup_load(latitude, longitude) {
         map.addOverlay(new GMarker(point));
         map.setMapType(G_HYBRID_MAP);
 
-        YAHOO.utils.Event.addListener(document.body, 'unload', iplookup_unload);
-    }
-}
-
-function iplookup_unload() {
-    if (GBrowserIsCompatible()) {
-        GUnload();
-    }
+        Y.on('unload', function() {
+            if (GBrowserIsCompatible()) {
+                GUnload();
+            }
+        }, document.body);
+    }          
 }