2 var www_url
= document
.body
.getAttribute('data-url');
4 var css
= document
.createElement('link');
6 css
.rel
= 'stylesheet';
7 css
.href
= www_url
+ 'static/skel_editor.css';
8 document
.head
.appendChild(css
);
10 var save_btn
= document
.querySelector('input[name=save]');
11 save_btn
.type
= 'hidden';
13 var code
= new codeEditor('f_content');
16 search
: "Texte à chercher ?\n(expression régulière autorisée, pour cela commencer par un slash '/')",
17 replace
: "Texte pour le remplacement ?\n(utiliser $1, $2... pour les captures d'expression régulière)",
18 search_selection
: "Texte à chercher dans la sélection ?\n(expression régulière autorisée, pour cela commencer par un slash '/')",
19 replace_result
: "%d occurences trouvées et remplacées.",
20 goto: "Aller à la ligne :",
21 no_search_result
: "Aucun résultat trouvé."
24 code
.origValue
= code
.textarea
.value
;
27 code
.onlinechange = function () {
28 if ((p
= this.parent
.querySelector('nav p')) && this.origValue
!= code
.textarea
.value
)
30 toolbar
.removeChild(p
);
33 var line
= this.getLine(this.current_line
);
36 if (match
= line
.match(/<BOUCLE(\d+|_[a-zA-Z0-9_-]+)\(([A-Z]+)\)(.*?)>/))
38 doc
.push({link
: 'Boucles', title
: 'BOUCLE'});
39 doc
.push({link
: 'Boucle-'+match
[2], title
: match
[2]});
43 if (match
[3].match(/\{".*"\}/))
44 doc
.push({link
: 'Critere-inter', title
: 'Critère inter-résultat {"..."}'});
45 if (match
[3].match(/\{\d+(,\d+)?\}/))
46 doc
.push({link
: 'Critere-de-nombre', title
: 'Critère de nombre {X,Y}'});
47 if (match
[3].match(/\{par\s+.*\}/))
48 doc
.push({link
: 'Critere-d-ordre', title
: 'Critère d\'ordre {par champ}'});
49 if (match
[3].match(/\{inverse\}/))
50 doc
.push({link
: 'Critere-inverse', title
: 'Critère {inverse}'});
54 if (match
= line
.match(/<INCLURE\{(.*?)\}>/))
56 doc
.push({link
: 'Inclure', title
: 'Inclusion du fichier ' + match
[1]});
59 if (match
= line
.match(/#[A-Z0-9_]+(\*?(\|.*?)?\).*?\])?/g))
61 for (var i
= 0; i
< match
.length
; i
++)
63 var tag
= match
[i
].match(/(#[A-Z0-9_]+)(\*?(\|(.*?))?\).*?\])?/);
64 doc
.push({title
: 'Balise ' + tag
[1]});
66 if (typeof tag
[4] != 'undefined')
68 var tag
= tag
[4].split('|');
69 for (var j
= 0; j
< tag
.length
; j
++)
71 var end
= tag
[j
].indexOf('{');
72 end
= (end
== -1) ? tag
[j
].length
: end
;
73 var f
= tag
[j
].substr(0, end
);
74 doc
.push({link
: 'Filtre-'+f
, title
: 'Filtre '+f
});
82 for (var i
= 0; i
< doc
.length
; i
++)
84 help
.innerHTML
+= ' | ';
87 help
.innerHTML
+= '<a href="' + doc_url
+ '#' + doc
[i
].link
+ '" onclick="return !window.open(this.href);">' + doc
[i
].title
+ '</a>';
89 help
.innerHTML
+= '<' + tag
+ '>' + doc
[i
].title
+ '</' + tag
+ '>';
91 help
.innerHTML
+= doc
[i
].title
;
96 code
.saveFile = function (e
)
99 this.textarea
.form
.action
+= '&fullscreen';
101 this.textarea
.form
.submit();
104 code
.loadFile = function (e
)
106 var file
= e
.target
.value
;
108 if (file
== skel_current
) return;
110 if (code
.textarea
.value
!= code
.origValue
&&
111 !window
.confirm("Le fichier a été modifié, abandonner les modifications ?"))
113 for (var i
= 0; i
< e
.target
.options
.length
; i
++)
115 e
.target
.options
[i
].selected
= false;
117 if (e
.target
.options
[i
].value
== skel_current
)
119 e
.target
.options
[i
].selected
= true;
126 var url
= www_url
+ 'config/site.php?edit=' + encodeURIComponent(file
);
128 window
.location
.href
= url
+ (code
.fullscreen
? '#fullscreen' : '');
133 code
.resetFile = function (e
)
135 if (this.textarea
.value
== this.origValue
) return;
136 if (!window
.confirm("Le fichier a été modifié, abandonner les modifications ?")) return;
137 this.textarea
.form
.reset();
140 var help
= document
.createElement('div');
141 help
.className
= 'sk_help';
143 code
.parent
.appendChild(help
);
145 var toolbar
= document
.createElement('nav');
146 toolbar
.className
= 'sk_toolbar';
148 var appendButton = function (name
, title
, action
)
150 var btn
= document
.createElement('input');
152 btn
.value
= btn
.title
= title
;
153 btn
.className
= name
;
154 btn
.onclick = function () { action
.call(code
); return false; };
156 toolbar
.appendChild(btn
);
159 appendButton('save', 'Enregistrer les modifications', code
.saveFile
);
160 appendButton('reset', 'Recharger le fichier (effacer les modifications)', code
.resetFile
);
162 appendButton('search', 'Chercher', code
.search
);
163 appendButton('search_replace', 'Chercher et remplacer', code
.searchAndReplace
);
164 appendButton('gotoline', 'Aller à la ligne', code
.goToLine
);
165 appendButton('fullscreen', 'Plein écran', code
.toggleFullscreen
);
167 var sel
= document
.createElement('select');
168 sel
.title
= 'Charger un autre fichier';
169 sel
.onchange
= code
.loadFile
;
171 for (var i
in skel_list
)
173 if (!skel_list
.hasOwnProperty(i
))
176 var skel
= skel_list
[i
];
177 var opt
= document
.createElement('option');
179 opt
.innerHTML
= skel
;
180 opt
.selected
= (skel
== skel_current
) ? true : false;
181 sel
.appendChild(opt
);
184 toolbar
.appendChild(sel
);
186 code
.parent
.insertBefore(toolbar
, code
.parent
.firstChild
);
188 if (window
.location
.hash
.match(/fullscreen/))
190 code
.toggleFullscreen();
192 if (msg
= document
.querySelector('p.error, p.confirm'))
194 var m
= document
.createElement('p');
195 m
.innerHTML
= msg
.innerHTML
;
196 m
.className
= msg
.className
;
197 toolbar
.appendChild(m
);
198 msg
.parentNode
.removeChild(msg
);
201 window
.location
.hash
= '';