changeset 126:89bd64a1dc95

show gui editor links when it can be used, reformat common.js imported from: moin--main--1.5--patch-128
author Nir Soffer <nirs@freeshell.org>
date Fri, 21 Oct 2005 00:33:09 +0000
parents 2e94b859f3ce
children df23ca172546
files MoinMoin/PageEditor.py wiki/htdocs/common/js/common.js wiki/htdocs/modern/css/screen.css
diffstat 3 files changed, 49 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/PageEditor.py	Thu Oct 20 21:54:29 2005 +0000
+++ b/MoinMoin/PageEditor.py	Fri Oct 21 00:33:09 2005 +0000
@@ -25,6 +25,8 @@
 
 # This code is internal to allow I18N, else we'd use a .js file;
 # we avoid the "--" operator to make this XHTML happy!
+# TODO: move to external js file, send the translations when we load or
+# set the them as global variables.
 _countdown_js = """
 <script type="text/javascript">
 var timeout_min = %(lock_timeout)s;
@@ -70,7 +72,7 @@
     counter -= step
 
     // Set timer for next update
-    setTimeout("countdown()", delay)
+    setTimeout("countdown()", delay);    
 }
 </script>
 """
@@ -274,7 +276,6 @@
             title % {'pagename': self.split_title(self.request),},
             page=self,
             pagename=self.page_name, msg=status,
-            body_onload=self.lock.locktype and 'countdown()' or '', # broken / bug in Mozilla 1.5, when using #preview
             html_head=self.lock.locktype and (
                 _countdown_js % {
                      'lock_timeout': lock_timeout,
@@ -360,7 +361,8 @@
         self.request.write('''
 <input class="button" type="submit" name="button_save" value="%s">
 <input class="button" type="submit" name="button_preview" value="%s">
-<input class="button" type="submit" name="button_switch" value="%s" id="switch2gui">
+<input id="switch2gui" style="display: none;" class="button" type="submit"     
+    name="button_switch" value="%s">
 %s
 <input class="button" type="submit" name="button_cancel" value="%s">
 <input type="hidden" name="editor" value="text">
--- a/wiki/htdocs/common/js/common.js	Thu Oct 20 21:54:29 2005 +0000
+++ b/wiki/htdocs/common/js/common.js	Fri Oct 21 00:33:09 2005 +0000
@@ -1,42 +1,52 @@
 //
 // MoinMoin commonly used JavaScript functions
 //
-function check_gui_editor(){
- var sAgent = navigator.userAgent.toLowerCase()
- // Internet Explorer
- if ( sAgent.indexOf("msie") != -1 && sAgent.indexOf("mac") == -1 && sAgent.indexOf("opera") == -1 ){
-  var sBrowserVersion = navigator.appVersion.match(/MSIE (.\..)/)[1]
-  return ( sBrowserVersion >= 5.5 )
- }
- // Gecko
- else if ( navigator.product == "Gecko" && navigator.productSub >= 20030210 )
-  return true
- // Safari
- else if ( sAgent.indexOf("safari") != -1 )
-  return ( sAgent.match( /safari\/(\d+)/ )[1] >= 312 ) // Build must be at least 312 (1.3)
- else
-  return false
+
+function can_use_gui_editor() {
+    var sAgent = navigator.userAgent.toLowerCase();
+ 
+    if (sAgent.indexOf("msie") != -1 && sAgent.indexOf("mac") == -1 &&
+        sAgent.indexOf("opera") == -1 ) {
+        // Internet Explorer
+        var sBrowserVersion = navigator.appVersion.match(/MSIE (.\..)/)[1];
+        return ( sBrowserVersion >= 5.5 );
+    } else if (navigator.product == "Gecko" && 
+               navigator.productSub >= 20030210) {
+        // Gecko
+        return true;
+    } else if (sAgent.indexOf("safari") != -1 ) {
+        // Safari - build must be at least 312 (1.3)
+        return (sAgent.match( /safari\/(\d+)/ )[1] >= 312 );
+    } else {
+        // Unknown browser, assume gui editor is not compatible
+        return false;
+    }
 }
 
-function onload(){
- var enable_gui_editor = check_gui_editor()
- if ( enable_gui_editor){
-  guieditlink = document.getElementById("guieditlink")
-  if ( guieditlink ){
-   guieditlink.style.display = 'inline'
-  }
-  editlink = document.getElementById("editlink")
-  if ( editlink ){
-   href = editlink.href.replace('editor=textonly', 'editor=guipossible')
-   editlink.href = href
-  }
-  switch2gui = document.getElementById("switch2gui")
-  if ( switch2gui ){
-   // TODO by some js coder: make the (invisible) "GUI editor" button visible.
-  }
- }
+function update_ui() {
+    if (can_use_gui_editor()) {
+        guieditlink = document.getElementById("guieditlink");
+        if (guieditlink) {
+            guieditlink.style.display = 'inline';
+        }
+        editlink = document.getElementById("editlink")
+        if (editlink) {
+            href = editlink.href.replace('editor=textonly',
+                                         'editor=guipossible');
+            editlink.href = href;
+        }
+        switch2gui = document.getElementById('switch2gui')
+        if (switch2gui) {
+            switch2gui.style.display = 'inline';
+        }
+    }
+}
+
+function onload() {
+    update_ui();    
+    // countdown is available when editing
+    try {countdown()} catch (e) {}
 }
 
 // Initialize after loading the page
-window.onload = onload
-
+window.onload = onload;
--- a/wiki/htdocs/modern/css/screen.css	Thu Oct 20 21:54:29 2005 +0000
+++ b/wiki/htdocs/modern/css/screen.css	Fri Oct 21 00:33:09 2005 +0000
@@ -231,9 +231,6 @@
 
 .editbar a, .editbar a:visited {color: #0044B3;}
 
-#guieditlink { display: none; } // will be enabled by JS (if we have JS)
-#switch2gui { visibility: hidden; } // will be enabled by JS (if we have JS)
-
 #message {
 	clear: both;
 	margin: 0;