diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index bf5dc87fb84..9735870e4b6 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -3373,3 +3373,27 @@ function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose' } } +/** + * Prints a simple button to close a window + * + * @deprecated since Moodle 2.0 + * + * @global object + * @param string $name Name of the window to close + * @param boolean $return whether this function should return a string or output it. + * @param boolean $reloadopener if true, clicking the button will also reload + * the page that opend this popup window. + * @return string|void if $return is true, void otherwise + */ +function close_window_button($name='closewindow', $return=false, $reloadopener = false) { + global $OUTPUT; + + // debugging('close_window_button() has been deprecated. Please change your code to use $OUTPUT->close_window_button().'); + $output = $OUTPUT->close_window_button(get_string($name)); + + if ($return) { + return $output; + } else { + echo $output; + } +} diff --git a/lib/outputlib.php b/lib/outputlib.php index 53c14cb14e2..d5189fe25de 100644 --- a/lib/outputlib.php +++ b/lib/outputlib.php @@ -2782,12 +2782,21 @@ class moodle_core_renderer extends moodle_renderer_base { return $output . $this->output_end_tag($tag); } - - public function close_window_button($buttontext = null, $reloadopener = false) { - if (empty($buttontext)) { - $buttontext = get_string('closewindow'); - } - // TODO + + /** + * Prints a simple button to close a window + * + * @global objec)t + * @param string $text The lang string for the button's label (already output from get_string()) + * @return string|void if $return is true, void otherwise + */ + public function close_window_button($text) { + $closeform = new html_form(); + $closeform->url = '#'; + $closeform->button->text = $text; + $closeform->button->add_action('click', 'close_window'); + $closeform->button->prepare(); + return $this->container($this->button($closeform), 'closewindow'); } public function close_window($delay = 0, $reloadopener = false) { diff --git a/lib/weblib.php b/lib/weblib.php index 5b0d574855d..cda54655508 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -587,40 +587,6 @@ function break_up_long_words($string, $maxsize=20, $cutchar=' ') { return $output; } - -/** - * Prints a simple button to close a window - * - * @global object - * @param string $name Name of the window to close - * @param boolean $return whether this function should return a string or output it. - * @param boolean $reloadopener if true, clicking the button will also reload - * the page that opend this popup window. - * @return string|void if $return is true, void otherwise - */ -function close_window_button($name='closewindow', $return=false, $reloadopener = false) { - global $CFG; - - $js = 'self.close();'; - if ($reloadopener) { - $js = 'window.opener.location.reload(1);' . $js; - } - - $output = ''; - - $output .= '