changeset 1425:b1c380a4cdb0

move some js to common.js
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 26 Aug 2006 22:53:58 +0200
parents aa8490f722fa
children 33852c180bd5
files MoinMoin/theme/__init__.py wiki/htdocs/common/js/common.js
diffstat 2 files changed, 68 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/theme/__init__.py	Sat Aug 26 14:59:04 2006 +0200
+++ b/MoinMoin/theme/__init__.py	Sat Aug 26 22:53:58 2006 +0200
@@ -739,12 +739,6 @@
     def headscript(self, d):
         """ Return html head script with common functions
 
-        TODO: put these on common.js instead, so they can be downloaded
-        only once.
-
-        TODO: actionMenuInit should be called once, from body onload,
-        but currently body is not written by theme.
-
         @param d: parameter dictionary
         @rtype: unicode
         @return: script for html head
@@ -755,71 +749,9 @@
 
         _ = self.request.getText
         script = u"""
-<script type=\"text/javascript\">
-<!--// common functions
-
-// We keep here the state of the search box
-searchIsDisabled = false;
-
-function searchChange(e) {
-    // Update search buttons status according to search box content.
-    // Ignore empty or whitespace search term.
-    var value = e.value.replace(/\s+/, '');
-    if (value == '' || searchIsDisabled) { 
-        searchSetDisabled(true);
-    } else {
-        searchSetDisabled(false);
-    }
-}
-
-function searchSetDisabled(flag) {
-    // Enable or disable search
-    document.getElementById('fullsearch').disabled = flag;
-    document.getElementById('titlesearch').disabled = flag;
-}
-
-function searchFocus(e) {
-    // Update search input content on focus
-    if (e.value == '%(search_hint)s') {
-        e.value = '';
-        e.className = '';
-        searchIsDisabled = false;
-    }
-}
-
-function searchBlur(e) {
-    // Update search input content on blur
-    if (e.value == '') {
-        e.value = '%(search_hint)s';
-        e.className = 'disabled';
-        searchIsDisabled = true;
-    }
-}
-
-function actionsMenuInit(title) {
-    // Initialize action menu
-    for (i = 0; i < document.forms.length; i++) {
-        var form = document.forms[i];
-        if (form.className == 'actionsmenu') {
-            // Check if this form needs update
-            var div = form.getElementsByTagName('div')[0];
-            var label = div.getElementsByTagName('label')[0];
-            if (label) {
-                // This is the first time: remove label and do buton.
-                div.removeChild(label);
-                var dobutton = div.getElementsByTagName('input')[0];
-                div.removeChild(dobutton);
-                // and add menu title
-                var select = div.getElementsByTagName('select')[0];
-                var item = document.createElement('option');
-                item.appendChild(document.createTextNode(title));
-                item.value = 'show';
-                select.insertBefore(item, select.options[0]);
-                select.selectedIndex = 0;
-            }
-        }
-    }
-}
+<script type="text/javascript">
+<!--
+var search_hint = "%(search_hint)s";
 //-->
 </script>
 """ % {
@@ -1165,8 +1097,10 @@
         _ = self.request.getText
         return """\
 <script type="text/javascript">
+<!-- // GUI edit link and i18n
 var gui_editor_link_href = "%(url)s";
 var gui_editor_link_text = "%(text)s";
+//-->
 </script>        
 """ % {'url': page.url(self.request, querystr={'action': 'edit', 'editor': 'gui', }, escape=0),
        'text': _('Edit (GUI)', formatted=False),
--- a/wiki/htdocs/common/js/common.js	Sat Aug 26 14:59:04 2006 +0200
+++ b/wiki/htdocs/common/js/common.js	Sat Aug 26 22:53:58 2006 +0200
@@ -2,6 +2,69 @@
 // MoinMoin commonly used JavaScript functions
 //
 
+// We keep here the state of the search box
+searchIsDisabled = false;
+
+function searchChange(e) {
+    // Update search buttons status according to search box content.
+    // Ignore empty or whitespace search term.
+    var value = e.value.replace(/\s+/, '');
+    if (value == '' || searchIsDisabled) { 
+        searchSetDisabled(true);
+    } else {
+        searchSetDisabled(false);
+    }
+}
+
+function searchSetDisabled(flag) {
+    // Enable or disable search
+    document.getElementById('fullsearch').disabled = flag;
+    document.getElementById('titlesearch').disabled = flag;
+}
+
+function searchFocus(e) {
+    // Update search input content on focus
+    if (e.value == search_hint) {
+        e.value = '';
+        e.className = '';
+        searchIsDisabled = false;
+    }
+}
+
+function searchBlur(e) {
+    // Update search input content on blur
+    if (e.value == '') {
+        e.value = search_hint;
+        e.className = 'disabled';
+        searchIsDisabled = true;
+    }
+}
+
+function actionsMenuInit(title) {
+    // Initialize action menu
+    for (i = 0; i < document.forms.length; i++) {
+        var form = document.forms[i];
+        if (form.className == 'actionsmenu') {
+            // Check if this form needs update
+            var div = form.getElementsByTagName('div')[0];
+            var label = div.getElementsByTagName('label')[0];
+            if (label) {
+                // This is the first time: remove label and do buton.
+                div.removeChild(label);
+                var dobutton = div.getElementsByTagName('input')[0];
+                div.removeChild(dobutton);
+                // and add menu title
+                var select = div.getElementsByTagName('select')[0];
+                var item = document.createElement('option');
+                item.appendChild(document.createTextNode(title));
+                item.value = 'show';
+                select.insertBefore(item, select.options[0]);
+                select.selectedIndex = 0;
+            }
+        }
+    }
+}
+
 // use this instead of assigning to window.onload directly:
 function addLoadEvent(func) {
   // alert("addLoadEvent " + func)