Support for javascript only divs/pages
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 19 Jul 2008 18:30:42 +0000 (18:30 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 19 Jul 2008 18:30:42 +0000 (18:30 +0000)
includes/main.inc
includes/ui/ui_controls.inc
js/inserts.js

index 2f0481334175c3e29b4104f86ca9ddaaabfb5bbb..19279f04d74a68c5b85524907024de65f9ad8af8 100644 (file)
@@ -15,7 +15,7 @@
     include_once($path_to_root . "/includes/ui/ui_view.inc");
     include_once($path_to_root . "/includes/ui/ui_controls.inc");
        
-    function page($title, $no_menu=false, $is_index=false, $onload="", $js="")
+    function page($title, $no_menu=false, $is_index=false, $onload="", $js="", $script_only=false)
     {
 
        global $path_to_root;
 
        page_header($title, $no_menu, $is_index, $onload, $js);
                error_box();
-               div_start('_page_body'); // whole page content for ajax reloading
+               if($script_only) {              
+                       echo '<noscript>';
+                       echo display_heading(_('This page is usable only with javascript enabled browsers.'));
+                       echo '</noscript>';
+                       div_start('_page_body', null, true);
+               } else {
+                       div_start('_page_body'); // whole page content for ajax reloading
+               }
     }
 
     function end_page($no_menu=false, $is_index=false)
index 09b6e0e673b0f18af01ebfbe30316ee70ee884e7..f67fd29bb29d407441a83271bc43eb081396d979 100644 (file)
@@ -192,13 +192,18 @@ function br($num=1)
 
 $ajax_divs = array();
 
-function div_start($id='', $trigger=null)
+function div_start($id='', $trigger=null, $non_ajax=false)
 {
     global $ajax_divs;
 
-    array_push($ajax_divs, array($id, $trigger===null ? $id : $trigger));
-    echo "<div ". ($id !='' ? "id='$id'" : '').">";
-    ob_start();
+       if ($non_ajax) { // div for non-ajax elements
+               array_push($ajax_divs, array($id, null));
+               echo "<div style='display:none' class='js_only' ".($id !='' ? "id='$id'" : '').">";
+       } else { // ajax ready div
+               array_push($ajax_divs, array($id, $trigger===null ? $id : $trigger));
+               echo "<div ". ($id !='' ? "id='$id'" : '').">";
+               ob_start();
+       }
 }
 
 function div_end()
@@ -208,7 +213,8 @@ function div_end()
     if (count($ajax_divs))
     {
                $div = array_pop($ajax_divs);
-               $Ajax->addUpdate($div[1], $div[0], ob_get_flush());
+               if ($div[1] !== null) 
+                       $Ajax->addUpdate($div[1], $div[0], ob_get_flush());
                echo "</div>";
     }
 }
index ec1626a0b23388a111905887905c0b66d93eb6b1..ff479f30da60f652b708d94eee55a6453b3d6999 100644 (file)
@@ -8,10 +8,11 @@ function debug(msg) {
 function progbar() {
        box = document.getElementById('msgbox');
     box.innerHTML= "<center><table width='98%' border='1' cellpadding=3 "
-       +"style='border-collapse: collapse' bordercolor='#007700'>"
+       +"bordercolor='#007700' style='border-collapse: collapse'>"
        +"<tr><td align='center' bgcolor='#ccffcc' >"
                +"<img src='"+user.theme+"images/progressbar.gif' alt='"
                +user.loadtxt+"' /></td></tr></table></center><br>";
+       box.style.display = 'block';
 }
 
 function save_focus(e) {
@@ -161,6 +162,11 @@ var inserts = {
            // this hides search button for js enabled browsers
            e.style.display = 'none';
        },
+       'div.js_only': 
+       function(e) {
+           // this shows divs for js enabled browsers only
+           e.style.display = 'block';
+       },
        'input.ajaxsubmit,input.editbutton,input.navibutton': 
        function(e) {
            e.onclick = function() {