Subversion Repositories Sites.tela-botanica.org

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 david 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
{
93
	var txtarea = toolbarfield;
94
	txtarea.focus();
95
	var cols = prompt("Nombre de colonnes du tableau :", "");
96
	var rows = prompt("Nombre de lignes du tableau :", "");
97
	if (cols != null && rows != null) {
98
		var tbl = '';
99
		var ligne = '|';
100
		var entete = '|';
101
		for(i = 0; i < cols; i++) {
102
			ligne = ligne + ' valeur |';
103
			entete = entete + ' {{entete}} |';
104
		}
105
		for (i = 0; i < rows; i++) {
106
			tbl = tbl + ligne + '\n';
107
		}
108
		if (confirm('Voulez vous ajouter une ligne d\'en-tĂȘte ?')) {
109
			tbl = entete + '\n' + tbl;
110
		}
111
		if ((clientVer >= 4) && is_ie && is_win) {
112
			var str = document.selection.createRange().text;
113
			var sel = document.selection.createRange();
114
			sel.text = str + '\n\n' + tbl + '\n\n';
115
		} else {
116
			mozWrap(txtarea, '', "\n\n" + tbl + "\n\n");
117
		}
118
	}
119
	return;
120
}
121
 
122
 
123
 
124
// Shows the help messages in the helpline window
125
function helpline(help, champ) {
126
	champ.value = help;
127
}
128
 
129
 
130
function setCaretToEnd (input) {
131
  setSelectionRange(input, input.value.length, input.value.length);
132
}
133
 
134
 
135
function setSelectionRange(input, selectionStart, selectionEnd) {
136
  if (input.setSelectionRange) {
137
    input.focus();
138
    input.setSelectionRange(selectionStart, selectionEnd);
139
  }
140
  else if (input.createTextRange) {
141
    var range = input.createTextRange();
142
    range.collapse(true);
143
    range.moveEnd('character', selectionEnd);
144
    range.moveStart('character', selectionStart);
145
    range.select();
146
  }
147
}
148
 
149
// From http://www.massless.org/mozedit/
150
function mozWrap(txtarea, open, close)
151
{
152
	var selLength = txtarea.textLength;
153
	var selStart = txtarea.selectionStart;
154
	var selEnd = txtarea.selectionEnd;
155
	if (selEnd == 1 || selEnd == 2)
156
		selEnd = selLength;
157
	var selTop = txtarea.scrollTop;
158
 
159
	// Raccourcir la selection par double-clic si dernier caractere est espace
160
	if (selEnd - selStart > 0 && (txtarea.value).substring(selEnd-1,selEnd) == ' ') selEnd = selEnd-1;
161
 
162
	var s1 = (txtarea.value).substring(0,selStart);
163
	var s2 = (txtarea.value).substring(selStart, selEnd)
164
	var s3 = (txtarea.value).substring(selEnd, selLength);
165
 
166
	// Eviter melange bold-italic-intertitre
167
	if ((txtarea.value).substring(selEnd,selEnd+1) == '}' && close.substring(0,1) == "}") close = close + " ";
168
	if ((txtarea.value).substring(selEnd-1,selEnd) == '}' && close.substring(0,1) == "}") close = " " + close;
169
	if ((txtarea.value).substring(selStart-1,selStart) == '{' && open.substring(0,1) == "{") open = " " + open;
170
	if ((txtarea.value).substring(selStart,selStart+1) == '{' && open.substring(0,1) == "{") open = open + " ";
171
 
172
	txtarea.value = s1 + open + s2 + close + s3;
173
	selDeb = selStart + open.length;
174
	selFin = selEnd + close.length;
175
	window.setSelectionRange(txtarea, selDeb, selFin);
176
	txtarea.scrollTop = selTop;
177
	txtarea.focus();
178
 
179
	return;
180
}
181
 
182
// Insert at Claret position. Code from
183
// http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
184
     function storeCaret (textEl) {
185
       if (textEl.createTextRange)
186
         textEl.caretPos = document.selection.createRange().duplicate();
187
     }
188