Changeset 786 in spip-zone


Ignore:
Timestamp:
Sep 1, 2005, 11:18:26 AM (15 years ago)
Author:
pierre.andrews@…
Message:

les touches marchent enfin, mais ya un truc qui colle pas avec Safari

Location:
_libs_/tag-machine/formulaires
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • _libs_/tag-machine/formulaires/ajax.html

    r781 r786  
    11<B_mots>
    22new Array(
    3 <BOUCLE_mots(MOTS) {titre == ^(#ENV{titre}|preg_quote)} {","}>'#TITRE'</BOUCLE_mots>
     3<BOUCLE_mots(MOTS) {titre == ^#ENV{titre}} {","}>'#TITRE'</BOUCLE_mots>
    44)
    55</B_mots>
  • _libs_/tag-machine/formulaires/ajaxTagMachine.css

    r780 r786  
    1  .suggest_list
     1/*
     2fichier style pour le menu de suggestion ajax
     3a importer ou il faut
     4
     5    Copyright (C) 2005  Pierre ANDREWS
     6
     7    This program is free software; you can redistribute it and/or modify
     8    it under the terms of the GNU General Public License as published by
     9    the Free Software Foundation; either version 2 of the License, or any later version.
     10
     11    This program is distributed in the hope that it will be useful,
     12    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14    GNU General Public License for more details.
     15
     16    You should have received a copy of the GNU General Public License
     17    along with this program; if not, write to the Free Software
     18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     19*/
     20
     21.suggest_list
    222 {
    323         background: white;
    424  border: 1px solid;
    5   padding-left: 4px;
    625}
    726
     
    1332}
    1433
    15 .suggest_list a
    16 {
    17         text-decoration: none;
    18  color: navy;
     34.suggest_list li {
     35  padding-left: 4px;
    1936}
    2037
    2138
    2239.suggest_list li.selected {
    23         background: navy;
     40        background: #0a0aff;
    2441 color: white;
    2542}
     
    2845        color: white;
    2946}
    30 
  • _libs_/tag-machine/formulaires/ajaxTagMachine.js

    r780 r786  
    1 function AjaxSuggestMenu(textfieldID, suggestInID, alertInID) {
    2 this.url_chargee = new Array();
    3 this.xmlhttp = new Array();
    4 
    5 var self = this;
    6 
    7 this.alert = document.getElementById(alertInID);
    8 this.div = document.getElementById(suggestInID);
    9 this.textfield = document.getElementById(textfieldID);
    10 
    11 this.div.style.display= 'none';
    12 this.div.style.width = this.textfield.style.width;
    13 this.alert.innerHTML = "w: "+this.textfield.style.width;
    14 
    15 this.unselectall = function(nodes) {
    16 for(var i=0; i < nodes.length; i++) {
    17 if(nodes[i].childNodes)
    18 self.unselectall(nodes[i].childNodes);
    19 if(nodes[i].className == 'selected')
    20 nodes[i].className = '';
    21 }
    22 }
    23 
    24 this.findSelected = function(nodes) {
    25 for(var i=0; i < nodes.length; i++) {
    26 var iHtml;
    27 if(nodes[i].childNodes)
    28 iHtml = self.findSelected(nodes[i].childNodes);
    29 if((iHtml.innerHTML.length <= 0) && (nodes[i].className == 'selected'))
    30 return nodes[i];
    31 }
    32 
    33 return '';
    34 }
    35 
    36 this.selectUp = function(nodes) {
    37 var selected = false;
    38 for(var i=0; i < nodes.length; i++) {
    39 if(nodes[i].className == 'selected') {
    40 nodes[i].className='';
    41 //self.unselectall(nodes[i].childNodes);
    42 if(i-1 >= 0) {
    43 nodes[i-1].className = 'selected';
    44 selected = true;
    45 }
    46 self.selectUp(nodes[i].childNodes);
    47 break;
    48 }
    49 }
    50 if(!selected && nodes.length > 0) {
    51 nodes[0].className = 'selected';
    52 }
    53 }
    54 
    55 this.selectDown = function(nodes) {
    56 var selected = false;
    57 for(var i=0; i < nodes.length; i++) {
    58 if(nodes[i].className == 'selected') {
    59 nodes[i].className='';
    60 //self.unselectall(nodes[i].childNodes);
    61 if(i+1 < nodes.length) {
    62 nodes[i+1].className = 'selected';
    63 selected = true;
    64 }
    65 self.selectDown(nodes[i].childNodes);
    66 break;
    67 }
    68 }
    69 if(!selected && nodes.length > 0) {
    70 nodes[0].className = 'selected';
    71 }
    72 }
    73 
    74 this.updateSuggest = function(suggestions) {
    75   while(self.div.childNodes.length>0) {
    76   self.div.removeChild(self.div.childNodes[0]);
    77   }
    78 
    79   list = document.createElement("ul");
    80   self.div.appendChild(list);
    81 
    82   for(var sugI=0; sugI<suggestions.length; ++sugI){
    83     var item = document.createElement("li");
    84         item.id = 'item_sugI';
    85         var a = document.createElement("a");
    86         a.innerHTML = suggestions[sugI];
    87         a.onmousedown = function() {self.unselectall(self.div.childNodes);self.textfield.value = this.innerHTML; self.div.style.display = 'none';};
    88         a.onmouseover = function() {self.unselectall(self.div.childNodes); this.parentNode.className = 'selected'}
    89         item.appendChild(a);
    90     list.appendChild(item);
    91   }
    92   self.div.style.display= 'block';
    93 
    94 }
    95 
    96 
    97 this.charger_id_url = function(myUrl) {
    98 this.alert.innerHTML = "<b>updating with '"+myUrl+"'</b>";
    99        
     1/*
     2fichier javascript pour avoir un menu de suggestion a partir d'une url
     3a importer du genre:
     4<div style="position:relative;overflow:visible; width: 10em;">
     5          <input autocomplete="off" type="texte" id="tags_1" name="tags_1" class='forml' cols='40' style="width: 100%;">
     6          <div id="suggest" class="suggest_list" style="width: 100%;"></div>
     7</div>
     8<script  type='text/javascript' src="ajaxTagMachine.js"></script>
     9<script  type='text/javascript'> <!--
     10new AjaxSuggestMenu('ajax.php','tags_1','suggest','status')
     11--></script>
     12
     13le fichier ajax.php doit prendre un parametre url 'titre' et retourner un tableau javascript avec la liste de suggestion. Par exemple:
     14new Array('sugg1','sugg2','sugg3');
     15
     16
     17    Copyright (C) 2005  Pierre ANDREWS
     18
     19    This program is free software; you can redistribute it and/or modify
     20    it under the terms of the GNU General Public License as published by
     21    the Free Software Foundation; either version 2 of the License, or any later version.
     22
     23    This program is distributed in the hope that it will be useful,
     24    but WITHOUT ANY WARRANTY; without even the implied warranty of
     25    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     26    GNU General Public License for more details.
     27
     28    You should have received a copy of the GNU General Public License
     29    along with this program; if not, write to the Free Software
     30    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     31*/
     32
     33
     34function AjaxSuggestMenu(myUrl, textfieldID, suggestInID) {
     35  this.url_chargee = new Array();
     36  this.xmlhttp = new Array();
     37
     38  var self = this;
     39
     40  this.myUrl = myUrl;
     41
     42  this.div = document.getElementById(suggestInID);
     43  this.textfield = document.getElementById(textfieldID);
     44
     45  this.div.style.display= 'none';
     46  this.div.style.width = this.textfield.style.width;
     47
     48  this.escape = function(field) {
     49        if(escape) {
     50          return escape(field)
     51        } else if(encodeURIComponent) {
     52          return encodeURIComponent(field);
     53        }
     54  }
     55
     56  this.findSelected = function() {
     57        var list = document.getElementById('suggested_list');
     58        if(list != null) {
     59          for(var i=0; i < list.childNodes.length; i++) {
     60                if(list.childNodes[i].className == 'selected')
     61                  return list.childNodes[i];
     62          }
     63        }
     64        return null;
     65  }
     66
     67  this.unselectall = function() {
     68        var sel = self.findSelected();
     69        if(sel != null) sel.className = '';
     70  }
     71
     72  this.selectUp = function() {
     73        var selected = self.findSelected();
     74        if(selected != null) {
     75          selected.className = '';
     76          var prev = selected.previousSibling;
     77          if(prev != null)
     78                prev.className = 'selected';
     79          else
     80                selected.parentNode.lastChild.className = 'selected';
     81        } else {
     82          var list = document.getElementById('suggested_list');
     83          if(list != null && list.childNodes.length > 0) {
     84                list.lastChild.className = 'selected';
     85          }
     86        }
     87  }
     88
     89  this.selectDown = function() {
     90                var selected = self.findSelected();
     91        if(selected != null) {
     92          selected.className = '';
     93          var next = selected.nextSibling;
     94          if(next != null)
     95                next.className = 'selected';
     96          else
     97                selected.parentNode.firstChild.className = 'selected';
     98        } else {
     99          var list = document.getElementById('suggested_list');
     100          if(list != null && list.childNodes.length > 0) {
     101                list.firstChild.className = 'selected';
     102          }
     103        }
     104  }
     105
     106  this.updateSuggest = function(suggestions) {
     107        while(self.div.childNodes.length>0) {
     108          self.div.removeChild(self.div.childNodes[0]);
     109        }
     110
     111        list = document.createElement("ul");
     112        list.id = "suggested_list"
     113        self.div.appendChild(list);
     114
     115        for(var sugI=0; sugI<suggestions.length; ++sugI){
     116          var item = document.createElement("li");
     117          var a = document.createElement("a");
     118          a.innerHTML = suggestions[sugI];
     119          a.onmousedown = function() {self.unselectall();self.textfield.value = this.innerHTML; self.div.style.display = 'none';};
     120                  item.onmouseover = function() {
     121                        self.unselectall();
     122                        this.className = 'selected';
     123                  }
     124          item.appendChild(a);
     125          list.appendChild(item);
     126        }
     127        self.div.style.display= 'block';
     128
     129  }
     130
     131
     132  this.charger_id_url = function(myUrl) {
    100133        if (self.xmlhttp[self.textfield.id]) self.xmlhttp[self.textfield.id].abort();
    101134       
    102135        if (self.url_chargee['mem_'+myUrl]) {
    103                 self.updateSuggest(self.url_chargee['mem_'+myUrl]);
     136          self.updateSuggest(self.url_chargee['mem_'+myUrl]);
    104137        } else {
    105         if(window.XMLHttpRequest) {
     138          if(window.XMLHttpRequest) {
    106139        self.xmlhttp[self.textfield.id] = new XMLHttpRequest();
    107         } else if(window.ActiveXObject) {
     140          } else if(window.ActiveXObject) {
    108141        self.xmlhttp[self.textfield.id] = new ActiveXObject("Microsoft.XMLHTTP");
    109                 } else {
    110                 self.alert.innerHTML = "<b>error</b>";
     142          } else {
    111143                return false;
    112         }
    113         self.xmlhttp[self.textfield.id].open("GET", myUrl, true);
    114 
    115         self.xmlhttp[self.textfield.id].onreadystatechange = function() {
    116                 if (self.xmlhttp[self.textfield.id].readyState == 4) {
    117                                 if(self.xmlhttp[self.textfield.id].responseText.length > 0) {
    118                 self.updateSuggest(eval(self.xmlhttp[self.textfield.id].responseText)); // puts the result into the element
    119                                 self.url_chargee['mem_'+myUrl] = eval(self.xmlhttp[self.textfield.id].responseText);
    120                                 self.alert.innerHTML = "<b>done:"+myUrl+"</b>";
    121                                 }
    122                                 }
    123         }
    124         self.xmlhttp[self.textfield.id].send(null);
    125                 return true;
     144          }
     145          self.xmlhttp[self.textfield.id].open("GET", myUrl, true);
     146
     147          self.xmlhttp[self.textfield.id].onreadystatechange = function() {
     148                if (self.xmlhttp[self.textfield.id].readyState == 4) {
     149                  if(self.xmlhttp[self.textfield.id].responseText.length > 0) {
     150                        self.updateSuggest(eval(self.xmlhttp[self.textfield.id].responseText)); // puts the result into the element
     151                        self.url_chargee['mem_'+myUrl] = eval(self.xmlhttp[self.textfield.id].responseText);
     152                  }
     153                }
     154          }
     155          self.xmlhttp[self.textfield.id].send(null);
     156          return true;
    126157    }
    127         self.alert.innerHTML = "<b>error</b>";
    128158        return false;
     159  }
     160
     161
     162  this.textfield.onkeyup = function(ev) {
     163        var myKey = (ev)? ev.keyCode:window.event.keyCode;
     164
     165        switch(myKey) {
     166          case 9: //TAB
     167          case 27: //ESC
     168          case 38: //UP
     169          case 39: //RIGTH
     170          case 40: //DWN
     171                break;
     172
     173          default:
     174                self.charger_id_url(self.myUrl+'?titre='+this.value);
     175        }
     176  }
     177
     178  this.textfield.onkeydown = function(ev) {
     179        var myKey = (ev)? ev.keyCode:window.event.keyCode;
     180
     181        switch(myKey) {
     182          case 9: //TAB
     183                self.textfield.value = self.findSelected().firstChild.innerHTML;
     184                self.div.style.display = 'none';
     185                setTimeout("document.getElementById('"+self.textfield.id+"').focus()",0);
     186                break;
     187          case 27: //ESC
     188                self.div.style.display = 'none';
     189                break;
     190          case 38: //UP
     191                self.selectUp();
     192                break;
     193          case 39: //RIGHT
     194                var sel = self.findSelected();
     195                if(sel != null)
     196                  self.textfield.value = sel.firstChild.innerHTML;
     197                self.div.style.display = 'none';
     198                break;
     199          case 40: //DWN
     200                self.selectDown();
     201                break;
     202
     203          default:
     204                self.charger_id_url(self.myUrl+'?titre='+self.escape(self.textfield.value));
     205
     206        }
     207  }
     208
     209
    129210}
    130 
    131 
    132 this.textfield.onkeyup = function(ev) {
    133 var myKey = (ev)? ev.keyCode:window.event.keyCode;
    134 
    135 switch(myKey) {
    136 case 9: //TAB
    137 case 27: //ESC
    138 case 38: //UP
    139 case 40: //DWN
    140 break;
    141 
    142 default:
    143 self.charger_id_url('ajax.php?titre='+this.value);
    144 
    145 }
    146 }
    147 
    148 this.textfield.onkeydown = function(ev) {
    149 var myKey = (ev)? ev.keyCode:window.event.keyCode;
    150 
    151 switch(myKey) {
    152 case 9: //TAB
    153 self.textfield.value = self.findSelected(self.div.childNodes);
    154 self.textfield.focus();
    155 break;
    156 case 27: //ESC
    157 self.div.style.display = 'none';
    158 break;
    159 case 38: //UP
    160 self.selectUp(self.div.childNodes);
    161 break;
    162 case 40: //DWN
    163 self.selectDown(self.div.childNodes);
    164 break;
    165 
    166 default:
    167 self.charger_id_url('ajax.php?titre='+this.value);
    168 
    169 }
    170 }
    171 
    172 
    173 }
  • _libs_/tag-machine/formulaires/formulaire_tag_forum.html

    r780 r786  
     1<!--
     2    Copyright (C) 2005  Pierre ANDREWS
    13
     4    This program is free software; you can redistribute it and/or modify
     5    it under the terms of the GNU General Public License as published by
     6    the Free Software Foundation; either version 2 of the License, or any later version.
     7
     8    This program is distributed in the hope that it will be useful,
     9    but WITHOUT ANY WARRANTY; without even the implied warranty of
     10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11    GNU General Public License for more details.
     12
     13    You should have received a copy of the GNU General Public License
     14    along with this program; if not, write to the Free Software
     15    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     16-->
    217<form action="[(#ENV{self})]" method="post">
    318      <fieldset class='spip_encadrer' style='color: black; font-size: 90%'>
     
    1732<script  type='text/javascript' src="#DOSSIER_SQUELETTE/ajaxTagMachine.js"></script>
    1833<script  type='text/javascript'> <!--
    19 
    20 new AjaxSuggestMenu('tags_[(#ENV{id})]','suggest','status')
    21 
     34new AjaxSuggestMenu('ajax.php','tags_[(#ENV{id})]','suggest','status')
    2235--></script>
Note: See TracChangeset for help on using the changeset viewer.