448 |
ddelon |
1 |
|
|
|
2 |
/*
|
|
|
3 |
written by chris wetherell
|
|
|
4 |
http://www.massless.org
|
|
|
5 |
chris [THE AT SIGN] massless.org
|
|
|
6 |
warning: it only works for IE4+/Win and Moz1.1+
|
|
|
7 |
feel free to take it for your site
|
|
|
8 |
if there are any problems, let chris know.
|
|
|
9 |
*/
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
var ACEditor; /* make sure to change the onload handler of the
|
|
|
13 |
<body> tag to the form you're using!... */
|
|
|
14 |
|
|
|
15 |
function mozWrap(txtarea, lft, rgt) {
|
|
|
16 |
var selLength = txtarea.textLength;
|
|
|
17 |
var selStart = txtarea.selectionStart;
|
|
|
18 |
var selEnd = txtarea.selectionEnd;
|
|
|
19 |
if (selEnd==1 || selEnd==2) selEnd=selLength;
|
|
|
20 |
var s1 = (txtarea.value).substring(0,selStart);
|
|
|
21 |
var s2 = (txtarea.value).substring(selStart, selEnd)
|
|
|
22 |
var s3 = (txtarea.value).substring(selEnd, selLength);
|
|
|
23 |
txtarea.value = s1 + lft + s2 + rgt + s3;
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
function IEWrap(lft, rgt) {
|
|
|
27 |
strSelection = document.selection.createRange().text;
|
|
|
28 |
if (strSelection!="") {
|
|
|
29 |
document.selection.createRange().text = lft + strSelection + rgt;
|
|
|
30 |
}
|
|
|
31 |
}
|
|
|
32 |
// Cette fonction permet de faire fonctionner l'insertion de tag image dans un textarea de IE sans sélection initiale,
|
|
|
33 |
// à la position du curseur
|
|
|
34 |
|
|
|
35 |
function IEWrap2(txtarea,lft, rgt) {
|
|
|
36 |
txtarea.focus();
|
|
|
37 |
if (document.selection) {
|
|
|
38 |
txtarea.focus();
|
|
|
39 |
sel = document.selection.createRange();
|
|
|
40 |
sel.text = lft+rgt;
|
|
|
41 |
}
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
function wrapSelection(txtarea, lft, rgt) {
|
|
|
45 |
if (document.all) {IEWrap(lft, rgt);}
|
|
|
46 |
else if (document.getElementById) {mozWrap(txtarea, lft, rgt);}
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
function wrapSelectionBis(txtarea, lft, rgt) {
|
|
|
50 |
// pareil que la wrapSelection, avec une différence dans IE
|
|
|
51 |
// qui permet à wrapSelectionBis de pouvoir insérer à l'endroit du curseur même sans avoir sélectionné des caractères !!!
|
|
|
52 |
// Pour mozilla, c'est bien la fonction Wrap standard qui est appelée, aucun changement
|
|
|
53 |
|
|
|
54 |
if (document.all) { // document.all est une infamie de IE, on détecte cette horreur !
|
|
|
55 |
IEWrap2(txtarea,lft, rgt); // Attention, un parametre de plus que IEWrap
|
|
|
56 |
} else if (document.getElementById) {
|
|
|
57 |
mozWrap(txtarea, lft, rgt); // là on est chez les gentils
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
function wrapSelectionWithLink(txtarea) {
|
|
|
62 |
var my_link = prompt("Entrez l'URL: ","http://");
|
|
|
63 |
if (my_link != null) {
|
|
|
64 |
lft="[[" + my_link + " ";
|
|
|
65 |
rgt="]]";
|
|
|
66 |
wrapSelection(txtarea, lft, rgt);
|
|
|
67 |
}
|
|
|
68 |
return;
|
|
|
69 |
}
|
|
|
70 |
/* Aaaxl modif for ACeditor */
|
|
|
71 |
function wrapSelectionWithImage(txtarea) {
|
|
|
72 |
nom = document.ACEditor.filename.value;
|
|
|
73 |
descript = document.ACEditor.description.value;
|
|
|
74 |
align = document.ACEditor.alignment.value;
|
|
|
75 |
|
|
|
76 |
lft= " {{attach file=\"" + nom + "\" desc=\"" + descript + "\" class=\"" + align + "\" }} ";
|
|
|
77 |
rgt = "";
|
|
|
78 |
wrapSelectionBis(txtarea, lft, rgt);
|
|
|
79 |
return;
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
document.onkeypress = function (e) {
|
|
|
83 |
if (document.all) {
|
|
|
84 |
key=event.keyCode; txtarea=thisForm.body;
|
|
|
85 |
if (key == 1) wrapSelectionWithLink(txtarea);
|
|
|
86 |
if (key == 2) wrapSelection(txtarea,'**','**');
|
|
|
87 |
if (key == 20) wrapSelection(txtarea,'//','//');
|
|
|
88 |
}
|
|
|
89 |
else if (document.getElementById) {
|
|
|
90 |
ctrl=e.ctrlKey; shft=e.shiftKey; chr=e.charCode;
|
|
|
91 |
if (ctrl) if (shft) if (chr==65) wrapSelectionWithLink(thisForm.body);
|
|
|
92 |
if (ctrl) if (shft) if (chr==66) wrapSelection(thisForm.body,'**','**');
|
|
|
93 |
if (ctrl) if (shft) if (chr==84) wrapSelection(thisForm.body,'//','//');
|
|
|
94 |
//if (ctrl) if (shft) if (chr==85) wrapSelection(thisForm.body,'__','__');
|
|
|
95 |
}
|
|
|
96 |
return true;
|
|
|
97 |
}
|
|
|
98 |
/* end chris w. script */
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
/*
|
|
|
103 |
written by meg hourihan
|
|
|
104 |
http://www.megnut.com
|
|
|
105 |
meg@megnut.com
|
|
|
106 |
|
|
|
107 |
warning: it only works for IE4+/Win and Moz1.1+
|
|
|
108 |
feel free to take it for your site
|
|
|
109 |
but leave this text in place.
|
|
|
110 |
any problems, let meg know.
|
|
|
111 |
*/
|
|
|
112 |
function mouseover(el) {
|
|
|
113 |
el.className = "raise";
|
|
|
114 |
}
|
|
|
115 |
function mouseout(el) {
|
|
|
116 |
el.className = "buttons";
|
|
|
117 |
}
|
|
|
118 |
function mousedown(el) {
|
|
|
119 |
el.className = "press";
|
|
|
120 |
}
|
|
|
121 |
function mouseup(el) {
|
|
|
122 |
el.className = "raise";
|
|
|
123 |
}
|
|
|
124 |
/* end meg script */
|