1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
   | function BBTag(startTag, endTag, textareaId, tagType) {
				var field = document.getElementById(textareaId);
				field.focus();
 
				if (window.ActiveXObject) {
					var textRange = document.selection.createRange();            
					var currentSelection = textRange.text;
				} else {
					var startSelection   = field.value.substring(0, field.selectionStart);
					var currentSelection = field.value.substring(field.selectionStart, field.selectionEnd);
					var endSelection     = field.value.substring(field.selectionEnd);
				}
 
				if (tagType) {
					switch (tagType) {
						case "lien":
								endTag = "[/url]";
								if (currentSelection) {
										if (currentSelection.indexOf("http://") == 0 || currentSelection.indexOf("https://") == 0 || currentSelection.indexOf("ftp://") == 0 || currentSelection.indexOf("www.") == 0) {
												var label = prompt("Quel est le libellé du lien ?") || "";
												startTag = "[url=\"" + currentSelection + "\"]";
												currentSelection = label;
										} else {
												var URL = prompt("Quelle est l'url ?");
												startTag = "[url=" + URL + "]";
										}
								} else {
										var URL = prompt("Quelle est l'url ?") || "";
										var label = prompt("Quel est le libellé du lien ?") || "";
										startTag = "[url=" + URL + "]";
										currentSelection = label;                     
								}
						break; | 
Partager