thomascube
2011-03-01 044d6647e060adb88fc56dd687f2ea810d73fdb1
Make it easier to add code to $(document).ready()

3 files modified
23 ■■■■ changed files
program/include/main.inc 3 ●●●● patch | view | raw | blame | history
program/include/rcube_html_page.php 9 ●●●● patch | view | raw | blame | history
program/include/rcube_template.php 11 ●●●●● patch | view | raw | blame | history
program/include/main.inc
@@ -1661,8 +1661,7 @@
  $quota = rcmail_quota_content($attrib);
  $OUTPUT->add_script('$(document).ready(function(){
    rcmail.set_quota('.json_serialize($quota).')});', 'foot');
  $OUTPUT->add_script('rcmail.set_quota('.json_serialize($quota).');', 'docready');
  return html::span($attrib, '');
}
program/include/rcube_html_page.php
@@ -5,7 +5,7 @@
 | program/include/rcube_html_page.php                                   |
 |                                                                       |
 | This file is part of the Roundcube PHP suite                          |
 | Copyright (C) 2005-2009, The Roundcube Dev Team                       |
 | Copyright (C) 2005-2011 The Roundcube Dev Team                       |
 | Licensed under the GNU GPL                                            |
 |                                                                       |
 | CONTENTS:                                                             |
@@ -33,7 +33,7 @@
    protected $charset = RCMAIL_CHARSET;
    protected $script_tag_file = "<script type=\"text/javascript\" src=\"%s\"></script>\n";
    protected $script_tag  =  "<script type=\"text/javascript\">\n/* <![CDATA[ */\n%s\n/* ]]> */\n</script>";
    protected $script_tag  =  "<script type=\"text/javascript\">\n/* <![CDATA[ */\n%s\n/* ]]> */\n</script>\n";
    protected $link_css_file = "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\" />\n";
    protected $default_template = "<html>\n<head><title></title></head>\n<body></body>\n</html>";
@@ -208,6 +208,11 @@
            $page_header .= $this->header;
        }
        // put docready commands into page footer
        if (!empty($this->scripts['docready'])) {
            $this->add_script('$(document).ready(function(){ ' . $this->scripts['docready'] . "\n});", 'foot');
        }
        if (is_array($this->script_files['foot'])) {
            foreach ($this->script_files['foot'] as $file) {
                $page_footer .= sprintf($this->script_tag_file, $file);
program/include/rcube_template.php
@@ -5,7 +5,7 @@
 | program/include/rcube_template.php                                    |
 |                                                                       |
 | This file is part of the Roundcube Webmail client                     |
 | Copyright (C) 2006-2010, The Roundcube Dev Team                       |
 | Copyright (C) 2006-2011, The Roundcube Dev Team                       |
 | Licensed under the GNU GPL                                            |
 |                                                                       |
 | PURPOSE:                                                              |
@@ -57,7 +57,6 @@
    /**
     * Constructor
     *
     * @todo   Use jQuery's $(document).ready() here.
     * @todo   Replace $this->config with the real rcube_config object
     */
    public function __construct($task, $framed = false)
@@ -79,10 +78,9 @@
        $javascript = 'var '.JS_OBJECT_NAME.' = new rcube_webmail();';
        // don't wait for page onload. Call init at the bottom of the page (delayed)
        $javascript_foot = '$(document).ready(function(){ '.JS_OBJECT_NAME.'.init(); });';
        $this->add_script(JS_OBJECT_NAME.'.init();', 'docready');
        $this->add_script($javascript, 'head_top');
        $this->add_script($javascript_foot, 'foot');
        $this->scripts_path = 'program/js/';
        $this->include_script('jquery-1.5.min.js');
        $this->include_script('common.js');
@@ -1152,12 +1150,11 @@
        if (empty($images) || $this->app->task == 'logout')
            return;
        $this->add_script('$(document).ready(function(){
            var images = ' . json_serialize($images) .';
        $this->add_script('var images = ' . json_serialize($images) .';
            for (var i=0; i<images.length; i++) {
                img = new Image();
                img.src = images[i];
            }});', 'foot');
            }', 'docready');
    }