[ Index ] |
|
Code source de SPIP Agora 1.4 |
1 // Barre de raccourcis 2 // derive du: 3 // bbCode control by subBlue design : www.subBlue.com 4 5 // Startup variables 6 var theSelection = false; 7 8 // Check for Browser & Platform for PC & IE specific bits 9 // More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html 10 var clientPC = navigator.userAgent.toLowerCase(); // Get client info 11 var clientVer = parseInt(navigator.appVersion); // Get browser version 12 13 var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1)); 14 var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1) 15 && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1) 16 && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1)); 17 var is_moz = 0; 18 19 var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1)); 20 var is_mac = (clientPC.indexOf("mac")!=-1); 21 22 23 function barre_raccourci(debut,fin,champ) { 24 var txtarea = champ; 25 26 txtarea.focus(); 27 donotinsert = false; 28 theSelection = false; 29 bblast = 0; 30 31 if ((clientVer >= 4) && is_ie && is_win) 32 { 33 theSelection = document.selection.createRange().text; // Get text selection 34 if (theSelection) { 35 36 while (theSelection.substring(theSelection.length-1, theSelection.length) == ' ') 37 { 38 theSelection = theSelection.substring(0, theSelection.length-1); 39 fin = fin + " "; 40 } 41 if (theSelection.substring(0,1) == '{' && debut.substring(0,1) == '{') 42 { 43 debut = debut + " "; 44 } 45 if (theSelection.substring(theSelection.length-1, theSelection.length) == '}' && fin.substring(0,1) == '}') 46 { 47 fin = " " + fin; 48 } 49 50 // Add tags around selection 51 document.selection.createRange().text = debut + theSelection + fin; 52 txtarea.focus(); 53 theSelection = ''; 54 return; 55 } 56 } 57 else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0)) 58 { 59 mozWrap(txtarea, debut, fin); 60 return; 61 } 62 } 63 64 function barre_demande(debut,milieu,fin,affich,champ) { 65 var inserer = prompt(affich); 66 67 if (inserer != null) { 68 if (inserer == "") {inserer = "xxx"; } 69 70 barre_raccourci(debut, milieu+inserer+fin, champ); 71 } 72 } 73 74 function barre_inserer(text,champ) { 75 var txtarea = champ; 76 77 if (txtarea.createTextRange && txtarea.caretPos) { 78 var caretPos = txtarea.caretPos; 79 caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text; 80 txtarea.focus(); 81 } else { 82 //txtarea.value += text; 83 //txtarea.focus(); 84 mozWrap(txtarea, '', text); 85 return; 86 } 87 } 88 89 90 // D'apres Nicolas Hoizey 91 function barre_tableau(toolbarfield) { 92 var txtarea = toolbarfield; 93 txtarea.focus(); 94 var cols = prompt("Nombre de colonnes du tableau :", ""); 95 var rows = prompt("Nombre de lignes du tableau :", ""); 96 if (cols != null && rows != null) { 97 var tbl = ''; 98 var ligne = '|'; 99 var caption = '|| titre | resumé ||'; 100 var entete = '|'; 101 for(i = 0; i < cols; i++) { 102 ligne = ligne + ' valeur |'; 103 entete = entete + ' {{entête}} |'; 104 } 105 for (i = 0; i < rows; i++) { 106 tbl = tbl + ligne + '\n'; 107 } 108 if (confirm('Utiliser la première ligne du tableau comme en-tête des colonnes ?')) { 109 if (confirm('Voulez-vous ajouter un titre et un résumé au tableau ?')) { 110 tbl = caption + '\n' + entete + '\n' + tbl; 111 } else{ 112 tbl = entete + '\n' + tbl; 113 } 114 } else { 115 if (confirm('Voulez-vous ajouter un titre et un résumé au tableau ?')) { 116 tbl = caption + '\n' + tbl; 117 } 118 } 119 120 if ((clientVer >= 4) && is_ie && is_win) { 121 var str = document.selection.createRange().text; 122 var sel = document.selection.createRange(); 123 sel.text = str + '\n\n' + tbl + '\n\n'; 124 } else { 125 mozWrap(txtarea, '', "\n\n" + tbl + "\n\n"); 126 } 127 } 128 return; 129 } 130 131 132 133 // Shows the help messages in the helpline window 134 function helpline(help, champ) { 135 champ.value = help; 136 } 137 138 139 function setCaretToEnd (input) { 140 setSelectionRange(input, input.value.length, input.value.length); 141 } 142 143 144 function setSelectionRange(input, selectionStart, selectionEnd) { 145 if (input.setSelectionRange) { 146 input.focus(); 147 input.setSelectionRange(selectionStart, selectionEnd); 148 } 149 else if (input.createTextRange) { 150 var range = input.createTextRange(); 151 range.collapse(true); 152 range.moveEnd('character', selectionEnd); 153 range.moveStart('character', selectionStart); 154 range.select(); 155 } 156 } 157 158 // From http://www.massless.org/mozedit/ 159 function mozWrap(txtarea, open, close) { 160 var selLength = txtarea.textLength; 161 var selStart = txtarea.selectionStart; 162 var selEnd = txtarea.selectionEnd; 163 if (selEnd == 1 || selEnd == 2) 164 selEnd = selLength; 165 var selTop = txtarea.scrollTop; 166 167 // Raccourcir la selection par double-clic si dernier caractere est espace 168 if (selEnd - selStart > 0 && (txtarea.value).substring(selEnd-1,selEnd) == ' ') selEnd = selEnd-1; 169 170 var s1 = (txtarea.value).substring(0,selStart); 171 var s2 = (txtarea.value).substring(selStart, selEnd) 172 var s3 = (txtarea.value).substring(selEnd, selLength); 173 174 // Eviter melange bold-italic-intertitre 175 if ((txtarea.value).substring(selEnd,selEnd+1) == '}' && close.substring(0,1) == "}") close = close + " "; 176 if ((txtarea.value).substring(selEnd-1,selEnd) == '}' && close.substring(0,1) == "}") close = " " + close; 177 if ((txtarea.value).substring(selStart-1,selStart) == '{' && open.substring(0,1) == "{") open = " " + open; 178 if ((txtarea.value).substring(selStart,selStart+1) == '{' && open.substring(0,1) == "{") open = open + " "; 179 180 txtarea.value = s1 + open + s2 + close + s3; 181 selDeb = selStart + open.length; 182 selFin = selEnd + close.length; 183 window.setSelectionRange(txtarea, selDeb, selFin); 184 txtarea.scrollTop = selTop; 185 txtarea.focus(); 186 187 return; 188 } 189 190 // Insert at Claret position. Code from 191 // http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130 192 function storeCaret (textEl) { 193 if (textEl.createTextRange) 194 textEl.caretPos = document.selection.createRange().duplicate(); 195 } 196 197 function galerie(toolbarfieldname) { 198 window.open('documents_tous.php?field='+toolbarfieldname, 'galerie', 'width=550,height=400,menubar=no,scrollbars=yes'); 199 return; 200 } 201 202 function popup(mylink, windowname) { 203 if (! window.focus)return true; 204 var href; 205 if (typeof(mylink) == 'string') 206 href=mylink; 207 else 208 href=mylink.href; 209 popup_handle = window.open(href, windowname, 'width=800,height=600,scrollbars=yes,resizable=1,status=1,toolbar=1'); 210 popup_handle.focus(); 211 return false; 212 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 14:40:03 2007 | par Balluche grâce à PHPXref 0.7 |