8 require
'../../../../../mainfile.php';
9 XoopsLogger::getInstance()->activated =
false;
10 XoopsLogger::getInstance()->renderingEnabled =
false;
11 $lang = is_file(
ABSPATH.
'/api/editors/exmcode/language/'.EXMLANG.
'.js') ? EXMLANG :
'en_US';
21 var fieldSelection = {
23 getSelection:
function() {
25 var e = this.jquery ?
this[0] :
this;
30 (
'selectionStart' in e &&
function() {
31 var l = e.selectionEnd - e.selectionStart;
32 return { start: e.selectionStart, end: e.selectionEnd, length: l, text: e.value.substr(e.selectionStart, l) };
36 (document.selection &&
function() {
40 var r = document.selection.createRange();
42 return { start: 0, end: e.value.length, length: 0 }
45 var re = e.createTextRange();
46 var rc = re.duplicate();
47 re.moveToBookmark(r.getBookmark());
48 rc.setEndPoint(
'EndToStart', re);
50 return { start: rc.text.length, end: rc.text.length + r.text.length, length: r.text.length, text: r.text };
55 return { start: 0, end: e.value.length, length: 0 };
62 replaceSelection:
function() {
64 var e = this.jquery ?
this[0] :
this;
65 var text = arguments[0] ||
'';
70 (
'selectionStart' in e &&
function() {
71 e.value = e.value.substr(0, e.selectionStart) + text + e.value.substr(e.selectionEnd, e.value.length);
76 (document.selection &&
function() {
78 document.selection.createRange().text = text;
94 jQuery.each(fieldSelection,
function(i) { jQuery.fn[i] =
this; });
100 var editor_path =
'';
101 var top_buttons =
'';
102 var bottom_buttons =
'';
104 var exmCode<?php echo ucfirst($id); ?> = {
106 init:
function(path, lang){
108 x.url =
'<?php echo RMCURL.'/api/editors/exmcode
'; ?>';
109 x.editor_path = x.url;
110 x.ed =
'<?php echo $id; ?>';
111 x.name =
'exmCode<?php echo ucfirst($id); ?>';
117 while(FALSE !== (
$file = readdir(
$dir))){
120 if (!is_file(
$path.
'/'.
$file.
'/plugin.js'))
continue;
132 x.add_button(
'bottom', {
134 title :
'Show bottom toolbar',
135 alt :
'Bottom toolbar',
136 icon : x.editor_path+
'/images/show.png',
139 $(
"#<?php echo $id; ?>-ec-container .row_bottom").slideDown(
'fast');
140 $(
"#<?php echo $id; ?>-bottom").hide();
144 x.add_button(
'top', {
146 title :
'Hide toolbar',
147 alt :
'Hide toolbar',
148 icon : x.editor_path+
'/images/hide.png',
151 $(
"#<?php echo $id; ?>-ec-container .row_bottom").slideUp(
'fast');
152 $(
"#<?php echo $id; ?>-bottom").show();
158 var buttons =
new Array();
159 buttons = buttons.concat(<?php echo
$id; ?>_buttons.split(
','));
160 plugs = <?php echo
$id; ?>_plugins;
162 for(i=0;i<buttons.length;i++){
164 buttons[i] = buttons[i].replace(/^\s*|\s*$/g,
"");
166 if (buttons[i]==
'separator_t' || buttons[i]==
'separator_b'){
167 x.add_separator(buttons[i]==
'separator_t'?
'top':
'bottom');
171 if (x.buttons[buttons[i]]==undefined)
continue;
172 d = x.buttons[buttons[i]];
174 if (d.plugin!=undefined && plugs[d.plugin]==undefined)
continue;
176 var b =
'<span class="buttons" id="<?php echo $id; ?>-'+d.name+
'" accesskey="'+d.key+
'" title="'+d.title+
'" onclick="'+x.name+
'.button_press(\''+d.name+
'\');
">';
178 if (d.icon!=undefined){
179 b += "<img src=
'"+d.icon+"' alt=
'' />
";
181 if (d.type=='dropdown'){
182 b += "<span
class=
'dropdown'><img src=
'"+x.editor_path+"/images/down.png' alt=
'' /></span>
";
184 b += (d.text!=undefined ? d.text : '')+"</span>
";
188 $("#<?php echo
$id; ?>-ec-container .row_top
").append(b);
190 $("#<?php echo
$id; ?>-ec-container .row_bottom
").append(b);
196 add_button : function(n,d){
199 x.buttons = x.buttons || {};
203 add_separator : function(w){
205 $("#<?php echo
$id; ?>-ec-container .row_top
").append('<span class="separator
"></span>');
207 $("#<?php echo
$id; ?>-ec-container .row_bottom
").append('<span class="separator
"></span>');
210 add_plugin : function(n,d){
212 if (x[n]!=undefined) return;
214 plugs = <?php echo $id; ?>_plugins;
215 if (plugs[n]==undefined) return;
219 if (x[n].init!=undefined) x[n].init(x);
222 button_press : function(n){
224 if (x.buttons[n]=='undefined') return;
226 if (x.buttons[n].cmd_type=='auto'){
231 plugin = x.buttons[n].plugin;
232 x.command(plugin, x.buttons[n].cmd);
235 command : function(n, c, p){
238 if (x[n]==undefined) return;
240 eval("x.
"+n+".
"+c+"(x,p)
");
242 execute : function(c){
246 selection: function(){
248 return $("#
"+x.ed).getSelection();
250 insertText: function(what){
252 var e = document.getElementById(x.ed);
253 var scrollTop = e.scrollTop;
254 selected = $("#
"+x.ed).getSelection();
255 if(selected.text==null)
258 text = what.replace('%replace%', selected.text);
259 $("#
"+x.ed).replaceSelection(text, true);
262 if (selected.text==''){
263 cursorPos = selected.start + what.indexOf("%replace%
");
265 cursorPos = selected.start + text.length;
268 cursorPos = cursorPos<0 || cursorPos<=selected.start ? (selected.start + text.length) : cursorPos;
270 e.selectionEnd = cursorPos;
271 e.scrollTop = scrollTop;
277 if ($("#
"+x.ed+"-ed-container .popup
").length<=0){
278 var pop = '<div class="popblocker
"></div><div class="popup
">';
279 pop += '<div class="titlebar
">';
280 pop += '<span class="buttons
">';
281 pop += '<span class="close
" onclick="'+x.name+'.closePopup()
"><span>Close</span></span>';
282 pop += '<span class="maximize
" onclick="'+x.name+'.maximize()
"><span>Maximize</span></span>';
283 pop += '<span class="restore
"><span>Restore</span></span>';
285 pop += '<span class="title
"></span></div>';
286 pop += '<div class="content
"><iframe src=""></iframe></div></div>';
287 $("#
"+x.ed+"-ed-container
").append(pop);
289 var pn = "#
"+x.ed+"-ed-container .popup
";
290 var w = d.width!=undefined?d.width:300;
291 var h = d.height!=undefined?d.height:300;
292 $(pn).css('width', w+'px');
293 $(pn).css('height', h+'px');
297 'margin-left': '-'+(w/2)+'px',
298 'margin-top': '-'+(h/2)+'px',
301 $(pn+' .title').html(d.title!=undefined?d.title:'');
302 $(pn+' .content').css('height',(h-39)+'px');
305 d.url = encodeURIComponent(d.url).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
306 var url = encodeURIComponent(x.url).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
308 var params = '&id='+x.ed+'&name='+x.name+'&eurl='+url+'&lang=<?php echo _LANGCODE; ?>';
309 params += '&theme=<?php echo $rmc_config['theme']; ?>';
310 params += '&version=<?php echo RMCVERSION; ?>';
312 $(pn+' iframe').attr('src', x.url+'/urls.php?url='+d.url+params);
315 var con = d.url.indexOf('?') != -1 ? '&' : '?';
317 $(pn+' iframe').attr('src', d.url+con+'type=exmcode&name='+x.name);
319 if (d.maximizable!=undefined&&d.maximizable) $(pn+' .maximize').show();
321 $("#
"+x.ed+"-ed-container .popblocker
").show(10, function(){
328 $(pn+' .restore').click(function(){
332 closePopup: function(){
334 var pn = "#
"+x.ed+"-ed-container .popup
";
335 $(pn+' iframe').attr('src', '');
336 $("#
"+x.ed+"-ed-container .popup
").hide();
337 $("#
"+x.ed+"-ed-container .popblocker
").hide();
339 maximize: function(){
341 var pn = "#
"+x.ed+"-ed-container .popup
";
342 $(pn+' .maximize').hide();
343 $(pn+' .restore').show();
351 }, 500, '', function(){
352 $(pn+' .content').css('height',$(window).height()-39+'px');
354 $(pn).addClass('maximized');
357 restore: function(w,h){
359 var pn = "#
"+x.ed+"-ed-container .popup
";
360 $(pn+' .maximize').show();
361 $(pn+' .restore').hide();
368 }, 500, '', function(){
369 $(pn+' .content').css('height',(h-39)+'px');
370 $(pn).css({'margin-left': '-'+(w/2)+'px',
371 'margin-top': '-'+(h/2)+'px', 'display':'fixed'});
373 $(pn).removeClass('maximized');
377 $(document).ready(function(){
378 exmCode<?php echo ucfirst($id); ?>.init();
379 //exmCode.make_buttons('<?php echo rmc_server_var($_GET, 'id'); ?>');
380 $("#<?php echo
rmc_server_var($_GET,
'id'); ?>
").css('width', ($("#<?php echo
rmc_server_var($_GET,
'id'); ?>-ec-container
").width()-6)+'px');