]> git.mjollnir.org Git - moodle.git/commitdiff
javascript cleanup: MDL-16583 clean up the close_window function in weblib.php.
authortjhunt <tjhunt>
Wed, 10 Dec 2008 08:57:50 +0000 (08:57 +0000)
committertjhunt <tjhunt>
Wed, 10 Dec 2008 08:57:50 +0000 (08:57 +0000)
lang/en_utf8/moodle.php
lib/javascript-static.js
lib/weblib.php

index 17f79aa23fe325942c67652949a1244030702990..35604f57d3df9593dc8810d79ea5a8505d2df047 100644 (file)
@@ -1686,6 +1686,7 @@ within the course so that we can learn more about you:
   $a->profileurl';
 $string['whattocallzip'] = 'What do you want to call the zip file?';
 $string['whattodo'] = 'What to do';
+$string['windowclosing'] = 'This window should close automatically. If not, please close it now.';
 $string['withchosenfiles'] = 'With chosen files';
 $string['withoutuserdata'] = 'without user data';
 $string['withselectedusers'] = 'With selected users...';
index 2e832727515cd5f1f96852dbdd880f49a87997bb..db921e740eeddc071c358777d20fc7faf3f30f9a 100644 (file)
@@ -731,4 +731,20 @@ collapsible_region.prototype.handle_animation_complete = function() {
     if (this.collapsed) {
         this.div.className += ' collapsed';
     }
+}
+
+/** Close the current browser window. */
+function close_window() {
+    window.close();
+}
+
+/**
+ * Close the current browser window, forcing the window/tab that opened this
+ * popup to reload itself. */
+function close_window_reloading_opener() {
+    if (window.opener) {
+        window.opener.location.reload(1);
+        close_window();
+        // Intentionally, only try to close the window if there is some evidence we are in a popup.
+    }
 }
\ No newline at end of file
index 09786b657b9d0fb226c32461e0f3f9f4c68a404c..16a8d152b7d9cdaa37cd41f3b1762d2f0c07723a 100644 (file)
@@ -675,26 +675,31 @@ function close_window_button($name='closewindow', $return=false, $reloadopener =
 }
 
 /*
- * Try and close the current window immediately using Javascript
- * @param int $delay the delay in seconds before closing the window
+ * Try and close the current window using JavaScript, either immediately, or after a delay.
+ * @param integer $delay a delay in seconds before closing the window. Default 0.
+ * @param boolean $reloadopener if true, we will see if this window was a pop-up, and try
+ *      to reload the parent window before this one closes.
  */
-function close_window($delay=0) {
-?>
-<script type="text/javascript">
-//<![CDATA[
-    function close_this_window() {
-        self.close();
+function close_window($delay = 0, $reloadopener = false) {
+    global $THEME;
+
+    if (!defined('HEADER_PRINTED')) {
+        print_header(get_string('closewindow'));
+    } else {
+        print_container_end_all(false, $THEME->open_header_containers);
     }
-    setTimeout("close_this_window()", <?php echo $delay * 1000 ?>);
-//]]>
-</script>
-<noscript><center>
-<?php print_string('pleaseclose') ?>
-</center></noscript>
-<?php
-    die;
-}
 
+    if ($reloadopener) {
+        $function = 'close_window_reloading_opener';
+    } else {
+        $function = 'close_window';
+    }
+    echo '<p class="centerpara">' . get_string('windowclosing') . '</p>';
+    print_delayed_js_call($delay, $function);
+
+    print_footer('empty');
+    exit;
+}
 
 /**
  * Given an array of values, output the HTML for a select element with those options.