bonjour,
j'utilise une toolbox :
le script :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
 * This class is able to manage BBCodes
 */
TextArea = function (name) {
    this._init(name);
}
 
/**
 * TextArea's constructor
 */
TextArea._init = function (name) {
	this.name = name;
	this.textarea = document.getElementById(this.name);
}
 
/**
 * The effective tag operation
 */
TextArea.tag = function (bStart,bEnd) {
	this.textarea.focus();
	if (typeof(document.selection) != 'undefined') {
		return this.tagIE(bStart,bEnd);
	} else {
		return this.tagGecko(bStart,bEnd);
	}
}
 
TextArea.tagIE = function (bStart,bEnd) {
	var range = document.selection.createRange();
	var insText = range.text;
	range.text = bStart + insText + bEnd;
	range = document.selection.createRange();
	if (insText.length == 0) {
		range.move('character', -(bEnd.length));
	} else {
		range.moveStart('character', bStart.length + insText.length + bEnd.length);
	}
	range.select();
}
 
TextArea.tagGecko = function (bStart,bEnd) {
	var start = this.textarea.selectionStart;
	var end = this.textarea.selectionEnd;
	var insText = this.textarea.value.substring(start, end);
	this.textarea.value = this.textarea.value.substr(0, start) + bStart + insText + bEnd + this.textarea.value.substr(end);
	var pos = insText.length ? start + bStart.length + insText.length + bEnd.length : start + bStart.length;
	this.textarea.selectionStart = pos;
	this.textarea.selectionEnd = pos;
}
 
/**
 * Automatically tag start and end by using a simple open/close tag
 */
TextArea.simpleTag = function (tag) {
	var sl = this.textarea.scrollLeft;
	var st = this.textarea.scrollTop;
	this.tag('['+tag+']','[/'+tag+']');
	this.textarea.scrollLeft = sl;
	this.textarea.scrollTop = st;
}
 
/**
 * Automatically tag start and end by using an open/close tag with a param asked to user
 * by a prompt
 */
TextArea.promptTag = function (tag,message) {
	rep = prompt(message);
	if (rep.length)
	{
		var sl = this.textarea.scrollLeft;
		var st = this.textarea.scrollTop;
		this.tag('['+tag+'='+rep+']','[/'+tag+']');
		this.textarea.scrollLeft = sl;
		this.textarea.scrollTop = st;
	}
}
 
/**
 * Smilies
 */
function add_smilie(code) {
	document.getElementById('c_content').value+=' '+code;
}
la toolbox simplifiée :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
<span id="toolbox">
 <input type="button" value="b" onclick="t_content.simpleTag('b');" />
</span>
initialiser la textarea :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
t_content = new TextArea('c_content');
j'ai un problême avec ajax :
lorsque je charge : [ la toolbox suivie de
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
<script language="javascript">
t_content = new TextArea('c_content');
</script>
] - le code précédent étant contenu dans un fichier.js déjà chargé par la page qui appelle ajax -avec ajax, la textarea n'est pas initialisée...
comment celà se fait-il ?
merci
phcorp