changeset 124:c97db64bbe7b

enable gui editing link by JS imported from: moin--main--1.5--patch-126
author Thomas Waldmann <tw@waldmann-edv.de>
date Thu, 20 Oct 2005 21:19:05 +0000
parents 0e91f640f242
children 2e94b859f3ce
files MoinMoin/PageEditor.py MoinMoin/theme/__init__.py MoinMoin/wikiaction.py MoinMoin/wikiutil.py wiki/htdocs/common/js/common.js wiki/htdocs/modern/css/screen.css
diffstat 6 files changed, 60 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/PageEditor.py	Thu Oct 20 07:17:51 2005 +0000
+++ b/MoinMoin/PageEditor.py	Thu Oct 20 21:19:05 2005 +0000
@@ -360,7 +360,7 @@
         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">
+<input class="button" type="submit" name="button_switch" value="%s" id="switch2gui">
 %s
 <input class="button" type="submit" name="button_cancel" value="%s">
 <input type="hidden" name="editor" value="text">
--- a/MoinMoin/theme/__init__.py	Thu Oct 20 07:17:51 2005 +0000
+++ b/MoinMoin/theme/__init__.py	Thu Oct 20 21:19:05 2005 +0000
@@ -1031,13 +1031,14 @@
 
         if editor == 'freechoice':
             return [wikiutil.link_tag(self.request, params + '&editor=text', 
-                                      _('Edit (Text)', formatted=False)),
+                                      _('Edit (Text)', formatted=False), attrs='id="texteditlink"'),
                     wikiutil.link_tag(self.request, params + '&editor=gui', 
-                                      _('Edit (GUI)', formatted=False)),]
+                                      _('Edit (GUI)', formatted=False), attrs='id="guieditlink"'),]
         else: # editor == 'theonepreferred'.
             # unspecified editor will use the user prefered edtior.
-            return [wikiutil.link_tag(self.request, params, 
-                                      _('Edit', formatted=False)),]
+            # 'textonly' will be upgraded dynamically to 'guipossible' by JS
+            return [wikiutil.link_tag(self.request, params + '&editor=textonly',
+                                      _('Edit', formatted=False), attrs='id="editlink"'),]
 
     def disabledEdit(self):
         """ Return a disabled edit link """
--- a/MoinMoin/wikiaction.py	Thu Oct 20 07:17:51 2005 +0000
+++ b/MoinMoin/wikiaction.py	Thu Oct 20 21:19:05 2005 +0000
@@ -527,7 +527,13 @@
     if editor not in valideditors:
         editor = request.cfg.editor_default
     
-    editor = lasteditor = request.form.get('editor', [editor])[0]
+    editorparam = request.form.get('editor', [editor])[0]
+    if editorparam == "guipossible":
+        lasteditor = editor
+    elif editorparam == "textonly":
+        editor = lasteditor = 'text'
+    else:
+        editor = lasteditor = editorparam
 
     if request.cfg.editor_force:
         editor = request.cfg.editor_default
--- a/MoinMoin/wikiutil.py	Thu Oct 20 07:17:51 2005 +0000
+++ b/MoinMoin/wikiutil.py	Thu Oct 20 21:19:05 2005 +0000
@@ -1246,6 +1246,8 @@
         '<link rel="Help" href="%s/%s">\n' % (scriptname, quoteWikinameURL(page_help_formatting)),
                   ])
 
+    output.append('<script type="text/javascript" src="%s/common/js/common.js"></script>\n' % request.cfg.url_prefix)
+    
     output.append("</head>\n")
     request.write(''.join(output))
     output = []
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wiki/htdocs/common/js/common.js	Thu Oct 20 21:19:05 2005 +0000
@@ -0,0 +1,42 @@
+//
+// 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 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.
+  }
+ }
+}
+
+// Initialize after loading the page
+window.onload = onload
+
--- a/wiki/htdocs/modern/css/screen.css	Thu Oct 20 07:17:51 2005 +0000
+++ b/wiki/htdocs/modern/css/screen.css	Thu Oct 20 21:19:05 2005 +0000
@@ -231,6 +231,9 @@
 
 .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;