~hexmode/+junk/main

« back to all changes in this revision

Viewing changes to install-files/apps/sqlitemanager1.2.0/spaw/class/script_gecko.js.php

  • Committer: Mark A. Hershberger
  • Date: 2008-01-05 19:38:56 UTC
  • Revision ID: hershberger@spawn-xp-20080105193856-6rnzgwa4nehue3qj
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
  // control registration array
 
2
  var spaw_editors = new Array();
 
3
  
 
4
  // returns true if editor is already registered
 
5
  function SPAW_editor_registered(editor)
 
6
  {
 
7
    var found = false;
 
8
    for(var i=0;i<spaw_editors.length;i++)
 
9
    {
 
10
      if (spaw_editors[i] == editor)
 
11
      {
 
12
        found = true;
 
13
        break;
 
14
      }
 
15
    }
 
16
    return(found);
 
17
  }
 
18
  
 
19
  // onsubmit
 
20
  function SPAW_UpdateFields()
 
21
  {
 
22
    for (var i=0; i<spaw_editors.length; i++)
 
23
    {
 
24
      SPAW_updateField(spaw_editors[i], null);
 
25
    }
 
26
  }
 
27
  
 
28
  // adds event handler for the form to update hidden fields
 
29
  function SPAW_addOnSubmitHandler(editor)
 
30
  {
 
31
    thefield = SPAW_getFieldByEditor(editor, null);
 
32
 
 
33
    var sTemp = "";
 
34
    oForm = document.getElementById(thefield).form;
 
35
    if(oForm.onsubmit != null) {
 
36
      sTemp = oForm.onsubmit.toString();
 
37
      iStart = sTemp.indexOf("{") + 2;
 
38
      sTemp = sTemp.substr(iStart,sTemp.length-iStart-2);
 
39
    }
 
40
    if (sTemp.indexOf("SPAW_UpdateFields();") == -1)
 
41
    {
 
42
      oForm.onsubmit = new Function("SPAW_UpdateFields();" + sTemp);
 
43
    }
 
44
  }
 
45
 
 
46
  // editor initialization
 
47
  function SPAW_editorInit(editor, css_stylesheet, direction)
 
48
  {
 
49
    var ed = document.getElementById(editor+'_rEdit');
 
50
    if (!SPAW_editor_registered(editor))
 
51
    {
 
52
      // register the editor 
 
53
      spaw_editors[spaw_editors.length] = editor;
 
54
    
 
55
      // add on submit handler
 
56
      SPAW_addOnSubmitHandler(editor);
 
57
   
 
58
      ed.contentDocument.designMode = 'on';
 
59
      var s_sheet = ed.contentDocument.createElement("link");
 
60
      s_sheet.setAttribute("rel","stylesheet");
 
61
      s_sheet.setAttribute("type","text/css");
 
62
      s_sheet.setAttribute("href",css_stylesheet);
 
63
 
 
64
      var head = ed.contentDocument.getElementsByTagName("head");
 
65
      head[0].appendChild(s_sheet);
 
66
 
 
67
      // set initial value
 
68
      var ta_field = document.getElementById(editor);
 
69
      var html = ta_field.value;
 
70
      if (html != null && html != "\n")
 
71
        ed.contentDocument.body.innerHTML = html;
 
72
        
 
73
     // hookup active toolbar related events
 
74
     ed.contentDocument.addEventListener('keyup', new Function("e","SPAW_onkeyup('"+editor+"',e);"), false);
 
75
     ed.contentDocument.addEventListener('mouseup', new Function("SPAW_update_toolbar('"+editor+"', true);"), false);
 
76
     
 
77
     // initialize toolbar
 
78
     spaw_context_html = "";
 
79
     SPAW_update_toolbar(editor, true);
 
80
 
 
81
     // workaround to missing cursor on first load        
 
82
     ed.contentDocument.designMode = 'on';
 
83
    }
 
84
  } 
 
85
   
 
86
  
 
87
  
 
88
  function SPAW_showColorPicker(editor,curcolor,callback) 
 
89
  {
 
90
    var wnd = window.open('<?php echo $GLOBALS["spaw_dir"]?>dialogs/colorpicker.php?lang=' 
 
91
      + document.getElementById('SPAW_'+editor+'_lang').value + '&theme=' 
 
92
      + document.getElementById('SPAW_'+editor+'_theme').value 
 
93
      + '&editor=' + editor + '&callback=' + callback, "color_picker", 
 
94
      'status=no,modal=yes,width=350,height=250'); 
 
95
    wnd.dialogArguments = curcolor;
 
96
    return wnd;
 
97
  }
 
98
 
 
99
  function SPAW_bold_click(editor, sender)
 
100
  {
 
101
    var ed = document.getElementById(editor+'_rEdit');
 
102
    ed.contentDocument.execCommand('bold', false, null);
 
103
    ed.contentWindow.focus();
 
104
    SPAW_update_toolbar(editor, true);    
 
105
  }
 
106
 
 
107
  function SPAW_italic_click(editor, sender)
 
108
  {
 
109
    var ed = document.getElementById(editor+'_rEdit');
 
110
        ed.contentDocument.execCommand('italic', false, null);
 
111
    ed.contentWindow.focus();
 
112
    SPAW_update_toolbar(editor, true);    
 
113
  }
 
114
 
 
115
  function SPAW_underline_click(editor, sender)
 
116
  {
 
117
    var ed = document.getElementById(editor+'_rEdit');
 
118
        ed.contentDocument.execCommand('underline', false, null);
 
119
    ed.contentWindow.focus();
 
120
    SPAW_update_toolbar(editor, true);    
 
121
  }
 
122
  
 
123
  function SPAW_left_click(editor, sender)
 
124
  {
 
125
    var ed = document.getElementById(editor+'_rEdit');
 
126
        ed.contentDocument.execCommand('justifyleft', false, null);
 
127
    ed.contentWindow.focus();
 
128
    SPAW_update_toolbar(editor, true);    
 
129
  }
 
130
 
 
131
  function SPAW_center_click(editor, sender)
 
132
  {
 
133
    var ed = document.getElementById(editor+'_rEdit');
 
134
        ed.contentDocument.execCommand('justifycenter', false, null);
 
135
    ed.contentWindow.focus();
 
136
    SPAW_update_toolbar(editor, true);    
 
137
  }
 
138
 
 
139
  function SPAW_right_click(editor, sender)
 
140
  {
 
141
    var ed = document.getElementById(editor+'_rEdit');
 
142
        ed.contentDocument.execCommand('justifyright', false, null);
 
143
    ed.contentWindow.focus();
 
144
    SPAW_update_toolbar(editor, true);    
 
145
  }
 
146
 
 
147
  function SPAW_justify_click(editor, sender)
 
148
  {
 
149
    var ed = document.getElementById(editor+'_rEdit');
 
150
        ed.contentDocument.execCommand('justifyfull', false, null);
 
151
    ed.contentWindow.focus();
 
152
    SPAW_update_toolbar(editor, true);    
 
153
  }
 
154
  
 
155
  function SPAW_ordered_list_click(editor, sender)
 
156
  {
 
157
    var ed = document.getElementById(editor+'_rEdit');
 
158
        ed.contentDocument.execCommand('insertorderedlist', false, null);
 
159
    ed.contentWindow.focus();
 
160
    SPAW_update_toolbar(editor, true);    
 
161
  }
 
162
 
 
163
  function SPAW_bulleted_list_click(editor, sender)
 
164
  {
 
165
    var ed = document.getElementById(editor+'_rEdit');
 
166
        ed.contentDocument.execCommand('insertunorderedlist', false, null);
 
167
    ed.contentWindow.focus();
 
168
    SPAW_update_toolbar(editor, true);    
 
169
  }
 
170
  
 
171
  function SPAW_fore_color_click(editor, sender)
 
172
  {
 
173
    var wnd = SPAW_showColorPicker(editor,null,'SPAW_fore_color_click_callback'); 
 
174
  }
 
175
  
 
176
  function SPAW_fore_color_click_callback(editor, sender)
 
177
  {
 
178
    var fCol = sender.returnValue;
 
179
    if (fCol != null)
 
180
    {
 
181
      var ed = document.getElementById(editor+'_rEdit');
 
182
        ed.contentDocument.execCommand('forecolor', false, fCol);
 
183
    }
 
184
    ed.contentWindow.focus();
 
185
  }
 
186
 
 
187
  function SPAW_bg_color_click(editor, sender)
 
188
  {
 
189
    var wnd = SPAW_showColorPicker(editor,null,'SPAW_bg_color_click_callback'); 
 
190
  }
 
191
 
 
192
  function SPAW_bg_color_click_callback(editor, sender)
 
193
  {
 
194
    var fCol = sender.returnValue;
 
195
    if (fCol != null)
 
196
    {
 
197
      var ed = document.getElementById(editor+'_rEdit');
 
198
        ed.contentDocument.execCommand('hilitecolor', false, fCol);
 
199
    }
 
200
    ed.contentWindow.focus();
 
201
  }
 
202
 
 
203
  function SPAW_getA(editor)
 
204
  {
 
205
    var ed = document.getElementById(editor+'_rEdit');
 
206
    var selection = ed.contentWindow.getSelection();
 
207
    var selectedRange;
 
208
    if (selection.rangeCount > 0) {
 
209
      selectedRange = selection.getRangeAt(0);
 
210
    }
 
211
    var aControl = selectedRange.startContainer;
 
212
    while ((aControl.tagName != 'A') && (aControl.tagName != 'BODY'))
 
213
    {
 
214
      aControl = aControl.parentNode;
 
215
    }
 
216
    if (aControl.tagName == 'A')
 
217
      return(aControl);
 
218
    else
 
219
      return(null);
 
220
  }
 
221
 
 
222
  function SPAW_hyperlink_click(editor, sender)
 
223
  {
 
224
    var ed = document.getElementById(editor+'_rEdit');
 
225
    var a = SPAW_getA(editor);
 
226
 
 
227
    var aProps = {};
 
228
    // get anchors on the page
 
229
    aProps.anchors = new Array();
 
230
    var links = ed.contentDocument.getElementsByTagName('A');
 
231
    var aln = 0;
 
232
    if (links != null) aln = links.length;
 
233
    for (var i=0;i<aln;i++)
 
234
    {
 
235
      if (links[i].name != null && links[i].name != '')
 
236
        aProps.anchors[aProps.anchors.length] = links[i].name;
 
237
    }
 
238
 
 
239
    if (a)
 
240
    {
 
241
      aProps.href = a.attributes["href"]?a.attributes["href"].nodeValue:'';
 
242
      aProps.name = a.name;
 
243
      aProps.target = a.target;
 
244
      aProps.title = a.title;
 
245
    }
 
246
    var wnd = window.open('<?php echo $GLOBALS["spaw_dir"]?>dialogs/a.php?lang=' 
 
247
      + document.getElementById('SPAW_'+editor+'_lang').value + '&theme=' 
 
248
      + document.getElementById('SPAW_'+editor+'_theme').value
 
249
      + '&editor=' + editor + '&callback=SPAW_hyperlink_click_callback', "link_window", 
 
250
      'status=no,modal=yes,width=350,height=250'); 
 
251
    wnd.dialogArguments = aProps;
 
252
  }
 
253
  
 
254
 /***********************/
 
255
 function insertNodeAtSelection(win, insertNode)
 
256
  {
 
257
      // get current selection
 
258
      var sel = win.getSelection();
 
259
 
 
260
      // get the first range of the selection
 
261
      // (there's almost always only one range)
 
262
      var range = sel.getRangeAt(0);
 
263
 
 
264
      // deselect everything
 
265
      sel.removeAllRanges();
 
266
 
 
267
      // remove content of current selection from document
 
268
      range.deleteContents();
 
269
 
 
270
      // get location of current selection
 
271
      var container = range.startContainer;
 
272
      var pos = range.startOffset;
 
273
 
 
274
      // make a new range for the new selection
 
275
      range=document.createRange();
 
276
 
 
277
      if (container.nodeType==3 && insertNode.nodeType==3) {
 
278
 
 
279
        // if we insert text in a textnode, do optimized insertion
 
280
        container.insertData(pos, insertNode.nodeValue);
 
281
 
 
282
        // put cursor after inserted text
 
283
        range.setEnd(container, pos+insertNode.length);
 
284
        range.setStart(container, pos+insertNode.length);
 
285
 
 
286
      } else {
 
287
 
 
288
 
 
289
        var afterNode;
 
290
        if (container.nodeType==3) {
 
291
 
 
292
          // when inserting into a textnode
 
293
          // we create 2 new textnodes
 
294
          // and put the insertNode in between
 
295
 
 
296
          var textNode = container;
 
297
          container = textNode.parentNode;
 
298
          var text = textNode.nodeValue;
 
299
 
 
300
          // text before the split
 
301
          var textBefore = text.substr(0,pos);
 
302
          // text after the split
 
303
          var textAfter = text.substr(pos);
 
304
 
 
305
          var beforeNode = document.createTextNode(textBefore);
 
306
          var afterNode = document.createTextNode(textAfter);
 
307
 
 
308
          // insert the 3 new nodes before the old one
 
309
          container.insertBefore(afterNode, textNode);
 
310
          container.insertBefore(insertNode, afterNode);
 
311
          container.insertBefore(beforeNode, insertNode);
 
312
 
 
313
          // remove the old node
 
314
          container.removeChild(textNode);
 
315
 
 
316
        } else {
 
317
 
 
318
          // else simply insert the node
 
319
          afterNode = container.childNodes[pos];
 
320
          container.insertBefore(insertNode, afterNode);
 
321
        }
 
322
 
 
323
        range.setEnd(afterNode, 0);
 
324
        range.setStart(afterNode, 0);
 
325
      }
 
326
 
 
327
      sel.addRange(range);
 
328
      
 
329
      // remove all ranges
 
330
      win.getSelection().removeAllRanges();
 
331
  };
 
332
 /***********************/
 
333
  
 
334
  function SPAW_hyperlink_click_callback(editor, sender)
 
335
  {
 
336
    var naProps = sender.returnValue;
 
337
 
 
338
    var ed = document.getElementById(editor+'_rEdit');
 
339
    var a = SPAW_getA(editor);
 
340
    
 
341
    if (a)
 
342
    {
 
343
      // edit link
 
344
      if (!naProps.href && !naProps.name)
 
345
      {
 
346
        // remove hyperlink
 
347
        a.outerHTML = a.innerHTML;
 
348
      }
 
349
      else
 
350
      {
 
351
        // set link properties
 
352
        if (naProps.href)
 
353
          a.href = naProps.href;
 
354
        else
 
355
          a.removeAttribute('href',0);
 
356
        if (naProps.name)
 
357
          a.name = naProps.name;
 
358
        else
 
359
          a.removeAttribute('name',0);
 
360
        if (naProps.target && naProps.target!='_self')
 
361
          a.target = naProps.target;
 
362
        else
 
363
          a.removeAttribute('target',0);
 
364
        if (naProps.title)
 
365
          a.title = naProps.title;
 
366
        else
 
367
          a.removeAttribute('title',0);
 
368
        
 
369
                        a.removeAttribute('onclick',0);
 
370
      }
 
371
    }
 
372
    else
 
373
    {
 
374
      // new link
 
375
      var a;
 
376
      a = document.createElement('A');
 
377
      if (naProps.name)
 
378
      {
 
379
        a.name = naProps.name;
 
380
      }
 
381
      else
 
382
      if (naProps.href)
 
383
        a.href = naProps.href;
 
384
      if (naProps.target && naProps.target!='_self')
 
385
        a.target = naProps.target;
 
386
      if (naProps.title)
 
387
        a.title = naProps.title;
 
388
      
 
389
      if (ed.contentWindow.getSelection().rangeCount>0 
 
390
      && ed.contentWindow.getSelection().getRangeAt(0).startOffset != ed.contentWindow.getSelection().getRangeAt(0).endOffset)
 
391
      {
 
392
        a.appendChild(ed.contentWindow.getSelection().getRangeAt(0).cloneContents());
 
393
      }
 
394
      else
 
395
      {
 
396
        a.innerHTML = (a.href && a.attributes["href"].nodeValue!='')?a.attributes["href"].nodeValue:a.name;
 
397
      }
 
398
      
 
399
      insertNodeAtSelection(ed.contentWindow, a);        
 
400
        
 
401
    }
 
402
  }
 
403
 
 
404
  function SPAW_internal_link_click(editor, sender)
 
405
  {
 
406
  }
 
407
  
 
408
  function SPAW_image_insert_click(editor, sender)
 
409
  {
 
410
    var wnd = window.open('<?php echo $GLOBALS["spaw_dir"]?>dialogs/img_library.php?lang=' 
 
411
      + document.getElementById('SPAW_'+editor+'_lang').value + '&theme=' 
 
412
      + document.getElementById('SPAW_'+editor+'_theme').value
 
413
      + '&editor=' + editor + '&callback=SPAW_image_insert_click_callback', "img_library", 
 
414
      'status=no,modal=yes,width=420,height=420'); 
 
415
  }
 
416
  
 
417
  function SPAW_image_insert_click_callback(editor, sender)
 
418
  {
 
419
    var imgSrc = sender.returnValue;
 
420
    if (imgSrc != null)
 
421
    {
 
422
      var ed = document.getElementById(editor+'_rEdit');
 
423
        ed.contentDocument.execCommand('insertimage', false, imgSrc);
 
424
    }
 
425
    ed.contentWindow.focus();
 
426
  }
 
427
  
 
428
  function SPAW_image_prop_click(editor, sender)
 
429
  {
 
430
    var im = SPAW_getImg(editor); // current img
 
431
    
 
432
    if (im)
 
433
    {
 
434
      var iProps = {};
 
435
      if (im.attributes["src"])
 
436
        iProps.src = im.attributes["src"].nodeValue;
 
437
      iProps.alt = im.alt;
 
438
      iProps.width = (im.style.width)?im.style.width:im.width;
 
439
      iProps.height = (im.style.height)?im.style.height:im.height;
 
440
      iProps.border = im.border;
 
441
      iProps.align = im.align;
 
442
      if (im.hspace>-1) // (-1 when not set under gecko for some reason)
 
443
        iProps.hspace = im.attributes["hspace"].nodeValue;
 
444
      if (im.vspace>-1)
 
445
        iProps.vspace = im.attributes["vspace"].nodeValue;
 
446
 
 
447
      var wnd = window.open('<?php echo $GLOBALS["spaw_dir"]?>dialogs/img.php?lang=' 
 
448
        + document.getElementById('SPAW_'+editor+'_lang').value + '&theme=' 
 
449
        + document.getElementById('SPAW_'+editor+'_theme').value
 
450
        + '&editor=' + editor + '&callback=SPAW_image_prop_click_callback', "img_prop", 
 
451
        'status=no,modal=yes,width=420,height=420'); 
 
452
      wnd.dialogArguments = iProps;
 
453
    }
 
454
  }
 
455
 
 
456
  function SPAW_image_prop_click_callback(editor, sender)
 
457
  {
 
458
    var ed = document.getElementById(editor+'_rEdit');
 
459
    var niProps = sender.returnValue;
 
460
    var im = SPAW_getImg(editor); // current img
 
461
    
 
462
    if (im && niProps)
 
463
    {
 
464
      im.src = (niProps.src)?niProps.src:'';
 
465
      if (niProps.alt) {
 
466
        im.alt = niProps.alt;
 
467
      }
 
468
      else
 
469
      {
 
470
        im.removeAttribute("alt",0);
 
471
      }
 
472
      im.align = (niProps.align)?niProps.align:'';
 
473
      im.width = (niProps.width)?niProps.width:'';
 
474
      //im.style.width = (niProps.width)?niProps.width:'';
 
475
      im.height = (niProps.height)?niProps.height:'';
 
476
      //im.style.height = (niProps.height)?niProps.height:'';
 
477
      if (niProps.border) {
 
478
        im.border = niProps.border;
 
479
      }
 
480
      else
 
481
      {
 
482
        im.removeAttribute("border",0);
 
483
      }
 
484
      if (niProps.hspace) {
 
485
        im.hspace = niProps.hspace;
 
486
      }
 
487
      else
 
488
      {
 
489
        im.removeAttribute("hspace",0);
 
490
      }
 
491
      if (niProps.vspace) {
 
492
        im.vspace = niProps.vspace;
 
493
      }
 
494
      else
 
495
      {
 
496
        im.removeAttribute("vspace",0);
 
497
      }
 
498
    }    
 
499
  
 
500
    ed.contentWindow.focus();
 
501
  }
 
502
 
 
503
 
 
504
  function SPAW_image_popup_click(editor, sender)
 
505
  {
 
506
    var wnd = window.open('<?php echo $GLOBALS["spaw_dir"]?>dialogs/img_library.php?lang=' 
 
507
      + document.getElementById('SPAW_'+editor+'_lang').value + '&theme=' 
 
508
      + document.getElementById('SPAW_'+editor+'_theme').value
 
509
      + '&editor=' + editor + '&callback=SPAW_image_popup_click_callback', "img_library", 
 
510
      'status=no,modal=yes,width=420,height=420'); 
 
511
  }
 
512
  
 
513
  function SPAW_image_popup_click_callback(editor, sender)
 
514
  {
 
515
    var ed = document.getElementById(editor+'_rEdit');
 
516
        var a = SPAW_getA(editor);
 
517
        var imgSrc = sender.returnValue;
 
518
 
 
519
    if(imgSrc != null)    
 
520
    {
 
521
      if (a)
 
522
      {
 
523
        // edit hyperlink
 
524
        a.href="#";
 
525
        a.setAttribute("onclick","window.open('<?php echo $spaw_img_popup_url?>?img_url="+imgSrc+"','Image','width=500,height=300,scrollbars=no,toolbar=no,location=no,status=no,resizable=yes,screenX=120,screenY=100');return false;");
 
526
      }
 
527
      else
 
528
      {
 
529
        var a;
 
530
        a = document.createElement('A');
 
531
        a.href="#";
 
532
        a.setAttribute("onclick","window.open('<?php echo $spaw_img_popup_url?>?img_url="+imgSrc+"','Image','width=500,height=300,scrollbars=no,toolbar=no,location=no,status=no,resizable=yes,screenX=120,screenY=100');return false;");
 
533
 
 
534
        if (ed.contentWindow.getSelection().rangeCount>0 
 
535
        && ed.contentWindow.getSelection().getRangeAt(0).startOffset != ed.contentWindow.getSelection().getRangeAt(0).endOffset)
 
536
        {
 
537
          a.appendChild(ed.contentWindow.getSelection().getRangeAt(0).cloneContents());
 
538
        }
 
539
        else
 
540
        {
 
541
          a.innerHTML = (a.href && a.attributes["href"].nodeValue!='')?a.attributes["href"].nodeValue:a.name;
 
542
        }
 
543
        
 
544
        insertNodeAtSelection(ed.contentWindow, a);  
 
545
      }      
 
546
                }       
 
547
    ed.contentWindow.focus();
 
548
  }
 
549
  
 
550
  function SPAW_hr_click(editor, sender)
 
551
  {
 
552
    var ed = document.getElementById(editor+'_rEdit');
 
553
        ed.contentDocument.execCommand('inserthorizontalrule', false, null);
 
554
    ed.contentWindow.focus();
 
555
    SPAW_update_toolbar(editor, true);    
 
556
  }
 
557
 
 
558
  function SPAW_copy_click(editor, sender)
 
559
  {
 
560
    // not implemented in gecko
 
561
  }
 
562
 
 
563
  function SPAW_paste_click(editor, sender)
 
564
  {
 
565
    // not implemented in gecko
 
566
  }
 
567
  
 
568
  function SPAW_cut_click(editor, sender)
 
569
  {
 
570
    // not implemented in gecko
 
571
  }
 
572
 
 
573
  function SPAW_delete_click(editor, sender)
 
574
  {
 
575
    // not implemented in gecko
 
576
  }
 
577
 
 
578
  function SPAW_indent_click(editor, sender)
 
579
  {
 
580
    var ed = document.getElementById(editor+'_rEdit');
 
581
        ed.contentDocument.execCommand('indent', false, null);
 
582
    ed.contentWindow.focus();
 
583
    SPAW_update_toolbar(editor, true);    
 
584
  }
 
585
 
 
586
  function SPAW_unindent_click(editor, sender)
 
587
  {
 
588
    var ed = document.getElementById(editor+'_rEdit');
 
589
        ed.contentDocument.execCommand('outdent', false, null);
 
590
    ed.contentWindow.focus();
 
591
    SPAW_update_toolbar(editor, true);    
 
592
  }
 
593
 
 
594
  function SPAW_undo_click(editor, sender)
 
595
  {
 
596
    var ed = document.getElementById(editor+'_rEdit');
 
597
        ed.contentDocument.execCommand('undo','',null);
 
598
    ed.contentWindow.focus();
 
599
    SPAW_update_toolbar(editor, true);    
 
600
  }
 
601
 
 
602
  function SPAW_redo_click(editor, sender)
 
603
  {
 
604
    var ed = document.getElementById(editor+'_rEdit');
 
605
        ed.contentDocument.execCommand('redo', false, null);
 
606
    ed.contentWindow.focus();
 
607
    SPAW_update_toolbar(editor, true);    
 
608
  }
 
609
  
 
610
  
 
611
  function SPAW_getParentTag(editor)
 
612
  {
 
613
    var ed = document.getElementById(editor+'_rEdit');
 
614
    var selection = ed.contentWindow.getSelection();
 
615
    var selectedRange;
 
616
    var aControl;
 
617
    if (selection && selection.rangeCount > 0) {
 
618
      selectedRange = selection.getRangeAt(0);
 
619
      aControl = selectedRange.startContainer;
 
620
      if (aControl.nodeType != 1)
 
621
        aControl = aControl.parentNode;
 
622
    }
 
623
    return aControl;
 
624
 
 
625
  }
 
626
 
 
627
  // trim functions  
 
628
  function SPAW_ltrim(txt)
 
629
  {
 
630
  }
 
631
  function SPAW_rtrim(txt)
 
632
  {
 
633
  }
 
634
  function SPAW_trim(txt)
 
635
  {
 
636
  }
 
637
 
 
638
  
 
639
  // is selected text a full tags inner html?
 
640
  function SPAW_isFoolTag(editor, el)
 
641
  {
 
642
  }
 
643
  
 
644
  function SPAW_style_change(editor, sender)
 
645
  {
 
646
    var ed = document.getElementById(editor+'_rEdit');
 
647
    
 
648
    var classname = sender.options[sender.selectedIndex].value;
 
649
    
 
650
    if (ed.contentWindow.getSelection().rangeCount>0)
 
651
    {
 
652
      var currentRange = ed.contentWindow.getSelection().getRangeAt(0);
 
653
 
 
654
      var parent = currentRange.commonAncestorContainer;
 
655
      if (parent.nodeType != 1)
 
656
        parent = currentRange.commonAncestorContainer.parentNode;
 
657
      
 
658
      if (parent && parent.tagName.toLowerCase() != "body" && parent.tagName.toLowerCase() != "html")
 
659
      {
 
660
        // set class on parent
 
661
        parent.className = classname;
 
662
      }
 
663
      else
 
664
      {
 
665
        // create new container
 
666
        var newSpan = ed.contentDocument.createElement("SPAN");
 
667
        newSpan.className = classname;
 
668
        newSpan.appendChild(currentRange.cloneContents());
 
669
        insertNodeAtSelection(ed.contentWindow, newSpan);
 
670
      }
 
671
    }
 
672
 
 
673
    ed.contentWindow.focus();
 
674
    SPAW_update_toolbar(editor, true);    
 
675
  }
 
676
 
 
677
  function SPAW_font_change(editor, sender)
 
678
  {
 
679
    var ed = document.getElementById(editor+'_rEdit');
 
680
    var fontname = sender.options[sender.selectedIndex].value;
 
681
    
 
682
    if (fontname == null || fontname == '')
 
683
    {
 
684
      ed.contentDocument.execCommand('RemoveFormat', false, null);
 
685
    }
 
686
    else   
 
687
    {
 
688
      ed.contentDocument.execCommand('fontname', false, fontname);
 
689
    }
 
690
 
 
691
    sender.selectedIndex = 0;
 
692
 
 
693
    ed.contentWindow.focus();
 
694
    SPAW_update_toolbar(editor, true);    
 
695
  
 
696
  }
 
697
 
 
698
  function SPAW_fontsize_change(editor, sender)
 
699
  {
 
700
    var ed = document.getElementById(editor+'_rEdit');
 
701
    var fontsize = sender.options[sender.selectedIndex].value;
 
702
 
 
703
    ed.contentDocument.execCommand('fontsize', false, fontsize);
 
704
 
 
705
    sender.selectedIndex = 0;
 
706
    ed.contentWindow.focus();
 
707
    SPAW_update_toolbar(editor, true);    
 
708
  }
 
709
 
 
710
  function SPAW_paragraph_change(editor, sender)
 
711
  {
 
712
    var ed = document.getElementById(editor+'_rEdit');
 
713
    var format = sender.options[sender.selectedIndex].value;
 
714
 
 
715
    ed.contentDocument.execCommand('formatBlock', false, format);
 
716
 
 
717
    sender.selectedIndex = 0;
 
718
    ed.contentWindow.focus();
 
719
    SPAW_update_toolbar(editor, true);    
 
720
  }
 
721
    
 
722
  function SPAW_table_create_click(editor, sender)
 
723
  {
 
724
      var wnd = window.open('<?php echo $GLOBALS["spaw_dir"]?>dialogs/table.php?lang=' 
 
725
      + document.getElementById('SPAW_'+editor+'_lang').value + '&theme=' 
 
726
      + document.getElementById('SPAW_'+editor+'_theme').value
 
727
      + '&editor=' + editor + '&callback=SPAW_table_create_click_callback', "table_prop", 
 
728
      'status=no,modal=yes,width=420,height=420'); 
 
729
  }
 
730
  
 
731
  function SPAW_table_create_click_callback(editor, sender)
 
732
  {
 
733
    var nt = sender.returnValue;
 
734
 
 
735
    var ed = document.getElementById(editor+'_rEdit');
 
736
 
 
737
      if (nt)
 
738
      {
 
739
        var newtable = document.createElement('TABLE');
 
740
        try 
 
741
        {
 
742
          if (nt.width)
 
743
            newtable.width = nt.width;
 
744
          if (nt.height)
 
745
            newtable.height = nt.height;
 
746
          if (nt.border)
 
747
            newtable.border = nt.border;
 
748
          if (nt.cellPadding) 
 
749
            newtable.cellPadding = nt.cellPadding;
 
750
          if (nt.cellSpacing) 
 
751
            newtable.cellSpacing = nt.cellSpacing;
 
752
          if (nt.bgColor)
 
753
            newtable.bgColor = nt.bgColor;
 
754
          if (nt.background)
 
755
            newtable.style.backgroundImage = "url("+nt.background+");";
 
756
          if (nt.className)
 
757
            newtable.className = nt.className;
 
758
          
 
759
          // create rows
 
760
          for (var i=0;i<parseInt(nt.rows);i++)
 
761
          {
 
762
            var newrow = document.createElement('TR');
 
763
            for (var j=0; j<parseInt(nt.cols); j++)
 
764
            {
 
765
              var newcell = document.createElement('TD');
 
766
              newcell.innerHTML = "&nbsp;"; // otherwise it doesn't show cell borders
 
767
              newrow.appendChild(newcell);
 
768
            }
 
769
            newtable.appendChild(newrow);
 
770
          }
 
771
          
 
772
          insertNodeAtSelection(ed.contentWindow, newtable);
 
773
          
 
774
          SPAW_toggle_borders(editor, ed.contentDocument.body, null);
 
775
          SPAW_update_toolbar(editor, true);    
 
776
        }
 
777
        catch (excp)
 
778
        {
 
779
          alert('error');
 
780
        }
 
781
      }
 
782
  }
 
783
  
 
784
  function SPAW_table_prop_click(editor, sender)
 
785
  {
 
786
    var tTable = SPAW_getTable(editor);
 
787
    
 
788
    if (tTable)
 
789
    {
 
790
      var tProps = {};
 
791
      tProps.width = (tTable.style.width)?tTable.style.width:tTable.width;
 
792
      tProps.height = (tTable.style.height)?tTable.style.height:tTable.height;
 
793
      tProps.border = tTable.border;
 
794
      tProps.cellPadding = tTable.cellPadding;
 
795
      tProps.cellSpacing = tTable.cellSpacing;
 
796
      tProps.bgColor = tTable.bgColor;
 
797
      tProps.className = tTable.className;
 
798
      if (tTable.style.backgroundImage != undefined)
 
799
        tProps.background = tTable.style.backgroundImage.substr(4,tTable.style.backgroundImage.length-5);
 
800
      
 
801
      var wnd = window.open('<?php echo $GLOBALS["spaw_dir"]?>dialogs/table.php?lang=' 
 
802
      + document.getElementById('SPAW_'+editor+'_lang').value + '&theme=' 
 
803
      + document.getElementById('SPAW_'+editor+'_theme').value
 
804
      + '&editor=' + editor + '&callback=SPAW_table_prop_click_callback', "table_prop", 
 
805
      'status=no,modal=yes,width=420,height=420'); 
 
806
      wnd.dialogArguments = tProps;
 
807
    }
 
808
    
 
809
  }
 
810
 
 
811
  function SPAW_table_prop_click_callback(editor, sender)
 
812
  {
 
813
    var ntProps = sender.returnValue;
 
814
 
 
815
    var ed = document.getElementById(editor+'_rEdit');
 
816
    
 
817
    var tTable = SPAW_getTable(editor)
 
818
 
 
819
    if (tTable && ntProps)
 
820
    {
 
821
      // set new settings
 
822
      if (ntProps.width)
 
823
        tTable.width = ntProps.width;
 
824
      else
 
825
        tTable.removeAttribute('width',0);
 
826
      if (ntProps.height)
 
827
        tTable.height = ntProps.height
 
828
      else
 
829
        tTable.removeAttribute('height',0);
 
830
      if (ntProps.border)
 
831
        tTable.border = ntProps.border;
 
832
      else
 
833
        tTable.removeAttribute('border',0);
 
834
      if (ntProps.cellPadding) 
 
835
        tTable.cellPadding = ntProps.cellPadding;
 
836
      else
 
837
        tTable.removeAttribute('cellpadding',0);
 
838
      if (ntProps.cellSpacing) 
 
839
        tTable.cellSpacing = ntProps.cellSpacing;
 
840
      else
 
841
        tTable.removeAttribute('cellspacing',0);
 
842
      if (ntProps.bgColor)
 
843
        tTable.bgColor = ntProps.bgColor;
 
844
      else
 
845
        tTable.removeAttribute('bgcolor',0);
 
846
      if (ntProps.background)
 
847
                  tTable.style.backgroundImage = "url("+ntProps.background+")";
 
848
      else
 
849
                  tTable.style.backgroundImage = "";
 
850
      if (ntProps.className)
 
851
        tTable.className = ntProps.className;
 
852
      else
 
853
        tTable.removeAttribute('className',0);
 
854
 
 
855
      SPAW_toggle_borders(editor, tTable, null);
 
856
    }
 
857
 
 
858
    SPAW_update_toolbar(editor, true);    
 
859
  }
 
860
  
 
861
  // edits table cell properties
 
862
  function SPAW_table_cell_prop_click(editor, sender)
 
863
  {
 
864
    var cd = SPAW_getTD(editor);
 
865
    if (cd)
 
866
    {
 
867
      var cProps = {};
 
868
      cProps.width = (cd.style.width)?cd.style.width:cd.width;
 
869
      cProps.height = (cd.style.height)?cd.style.height:cd.height;
 
870
      cProps.bgColor = cd.bgColor;
 
871
      if (cd.style.backgroundImage != undefined)
 
872
        cProps.background = cd.style.backgroundImage.substr(4,cd.style.backgroundImage.length-5);
 
873
 
 
874
      cProps.align = cd.align;
 
875
      cProps.vAlign = cd.vAlign;
 
876
      cProps.className = cd.className;
 
877
      cProps.noWrap = cd.noWrap;
 
878
      cProps.styleOptions = new Array();
 
879
      if (document.getElementById('SPAW_'+editor+'_tb_style') != null)
 
880
      {
 
881
        cProps.styleOptions = document.getElementById('SPAW_'+editor+'_tb_style').options;
 
882
      }
 
883
      
 
884
      var wnd = window.open('<?php echo $GLOBALS["spaw_dir"]?>dialogs/td.php?lang=' 
 
885
      + document.getElementById('SPAW_'+editor+'_lang').value + '&theme=' 
 
886
      + document.getElementById('SPAW_'+editor+'_theme').value
 
887
      + '&editor=' + editor + '&callback=SPAW_table_cell_prop_click_callback', "table_prop", 
 
888
      'status=no,modal=yes,width=420,height=420'); 
 
889
      wnd.dialogArguments = cProps;
 
890
    }    
 
891
  }
 
892
 
 
893
  function SPAW_table_cell_prop_click_callback(editor, sender)
 
894
  {
 
895
    var ncProps = sender.returnValue;
 
896
 
 
897
    var ed = document.getElementById(editor+'_rEdit');
 
898
    
 
899
    var cd = SPAW_getTD(editor)
 
900
 
 
901
    if (cd && ncProps)  
 
902
    {
 
903
      if (ncProps.align)
 
904
        cd.align = ncProps.align;
 
905
      else
 
906
        cd.removeAttribute('align',0);
 
907
      if (ncProps.vAlign)
 
908
        cd.vAlign = ncProps.vAlign;
 
909
      else
 
910
        cd.removeAttribute('valign',0);
 
911
      if (ncProps.width)
 
912
        cd.width = ncProps.width;
 
913
      else
 
914
        cd.removeAttribute('width',0);
 
915
      if (ncProps.height)
 
916
        cd.height = ncProps.height;
 
917
      else
 
918
        cd.removeAttribute('height',0);
 
919
      if (ncProps.bgColor)
 
920
        cd.bgColor = ncProps.bgColor;
 
921
      else
 
922
        cd.removeAttribute('bgcolor',0);
 
923
      if (ncProps.background)
 
924
        cd.style.backgroundImage = "url(" + ncProps.background + ")";
 
925
      else
 
926
        cd.style.backgroundImage = "";
 
927
      if (ncProps.className)
 
928
        cd.className = ncProps.className;
 
929
      else
 
930
        cd.removeAttribute('className',0);
 
931
      if (ncProps.noWrap)
 
932
        cd.noWrap = ncProps.noWrap;
 
933
      else
 
934
        cd.removeAttribute('nowrap',0);
 
935
    }
 
936
    SPAW_update_toolbar(editor, true);    
 
937
  }
 
938
 
 
939
 
 
940
  // returns current table cell  
 
941
  function SPAW_getTD(editor)
 
942
  {
 
943
    var ed = document.getElementById(editor+'_rEdit');
 
944
    var selection = ed.contentWindow.getSelection();
 
945
    var selectedRange;
 
946
    var aControl;
 
947
    if (selection.rangeCount > 0) {
 
948
      selectedRange = selection.getRangeAt(0);
 
949
      aControl = selectedRange.startContainer;
 
950
      if (aControl.nodeType != 1)
 
951
        aControl = aControl.parentNode;
 
952
      while ((aControl.tagName.toLowerCase() != 'td')
 
953
        && (aControl.tagName.toLowerCase() != 'th') 
 
954
        && (aControl.tagName.toLowerCase() != 'table') 
 
955
        && (aControl.tagName.toLowerCase() != 'body'))
 
956
      {
 
957
        aControl = aControl.parentNode;
 
958
      }
 
959
    }
 
960
    if (aControl.tagName.toLowerCase() == 'td' || aControl.tagName.toLowerCase() == 'th')
 
961
      return(aControl);
 
962
    else
 
963
      return(null);
 
964
  }
 
965
 
 
966
  // returns current table row  
 
967
  function SPAW_getTR(editor)
 
968
  {
 
969
    var ed = document.getElementById(editor+'_rEdit');
 
970
    var selection = ed.contentWindow.getSelection();
 
971
    var selectedRange;
 
972
    var aControl;
 
973
    if (selection.rangeCount > 0) {
 
974
      selectedRange = selection.getRangeAt(0);
 
975
      aControl = selectedRange.startContainer;
 
976
      if (aControl.nodeType != 1)
 
977
        aControl = aControl.parentNode;
 
978
      while ((aControl.tagName.toLowerCase() != 'tr')
 
979
        && (aControl.tagName.toLowerCase() != 'table') 
 
980
        && (aControl.tagName.toLowerCase() != 'body'))
 
981
      {
 
982
        aControl = aControl.parentNode;
 
983
      }
 
984
    }
 
985
    if (aControl.tagName.toLowerCase() == 'tr')
 
986
      return(aControl);
 
987
    else
 
988
      return(null);
 
989
  }
 
990
  
 
991
  // returns current table  
 
992
  function SPAW_getTable(editor)
 
993
  {
 
994
    var ed = document.getElementById(editor+'_rEdit');
 
995
    var selection = ed.contentWindow.getSelection();
 
996
    var selectedRange;
 
997
    var aControl = null;
 
998
    if (selection && selection.rangeCount > 0) {
 
999
      selectedRange = selection.getRangeAt(0);
 
1000
      aControl = selectedRange.startContainer;
 
1001
      if (aControl.nodeType != 1)
 
1002
        aControl = aControl.parentNode;
 
1003
      while ((aControl.tagName.toLowerCase() != 'table') && (aControl.tagName.toLowerCase() != 'body'))
 
1004
      {
 
1005
        aControl = aControl.parentNode;
 
1006
      }
 
1007
      if (aControl.tagName.toLowerCase() != 'table')
 
1008
        aControl = null;
 
1009
    }
 
1010
    return(aControl);
 
1011
  }
 
1012
  
 
1013
  // returns selected image
 
1014
  function SPAW_getImg(editor) 
 
1015
  {
 
1016
    var result = null;
 
1017
    var ed = document.getElementById(editor+'_rEdit');
 
1018
    var selection = ed.contentWindow.getSelection();
 
1019
    var selectedRange;
 
1020
    if (selection && selection.rangeCount > 0) {
 
1021
      selectedRange = selection.getRangeAt(0);
 
1022
      if (selectedRange.startContainer.nodeType == 1) // element node
 
1023
      {
 
1024
        var aControl = selectedRange.startContainer.childNodes[selectedRange.startOffset];
 
1025
        if (aControl && aControl.tagName && aControl.tagName.toLowerCase() == 'img')
 
1026
          result = aControl
 
1027
      }
 
1028
    }
 
1029
    return result;
 
1030
  }
 
1031
 
 
1032
  function SPAW_table_row_insert_click(editor, sender)
 
1033
  {
 
1034
  } // insertRow
 
1035
  
 
1036
  function SPAW_formCellMatrix(ct)
 
1037
  {
 
1038
  }
 
1039
  
 
1040
  function SPAW_table_column_insert_click(editor, sender)
 
1041
  {
 
1042
  } // insertColumn
 
1043
  
 
1044
  function SPAW_table_cell_merge_right_click(editor, sender)
 
1045
  {
 
1046
  } // mergeRight
 
1047
 
 
1048
 
 
1049
  function SPAW_table_cell_merge_down_click(editor, sender)
 
1050
  {
 
1051
  } // mergeDown
 
1052
  
 
1053
  function SPAW_table_row_delete_click(editor, sender)
 
1054
  {
 
1055
  } // deleteRow
 
1056
  
 
1057
  function SPAW_table_column_delete_click(editor, sender)
 
1058
  {
 
1059
  } // deleteColumn
 
1060
  
 
1061
  // split cell horizontally
 
1062
  function SPAW_table_cell_split_horizontal_click(editor, sender)
 
1063
  {
 
1064
  } // splitH
 
1065
  
 
1066
  function SPAW_table_cell_split_vertical_click(editor, sender)
 
1067
  {
 
1068
  } // splitV
 
1069
  
 
1070
 
 
1071
  // switch to wysiwyg mode
 
1072
  function SPAW_design_tab_click(editor, sender)
 
1073
  {
 
1074
    var ed = document.getElementById(editor+'_rEdit');
 
1075
    iText = document.getElementById(editor).value;
 
1076
    // mozilla bug? workaround
 
1077
    ed.contentDocument.designMode = "off";
 
1078
    
 
1079
    ed.contentDocument.body.innerHTML = iText;
 
1080
    
 
1081
    document.getElementById('SPAW_'+editor+'_editor_mode').value = 'design';
 
1082
 
 
1083
    // turn off html mode toolbars
 
1084
    document.getElementById('SPAW_'+editor+'_toolbar_top_html').style.display = 'none';
 
1085
    document.getElementById('SPAW_'+editor+'_toolbar_left_html').style.display = 'none';
 
1086
    document.getElementById('SPAW_'+editor+'_toolbar_right_html').style.display = 'none';
 
1087
    document.getElementById('SPAW_'+editor+'_toolbar_bottom_html').style.display = 'none';
 
1088
 
 
1089
    // turn on design mode toolbars
 
1090
    document.getElementById('SPAW_'+editor+'_toolbar_top_design').style.display = '';
 
1091
    document.getElementById('SPAW_'+editor+'_toolbar_left_design').style.display = '';
 
1092
    document.getElementById('SPAW_'+editor+'_toolbar_right_design').style.display = '';
 
1093
    document.getElementById('SPAW_'+editor+'_toolbar_bottom_design').style.display = '';
 
1094
 
 
1095
    // switch editors    
 
1096
    document.getElementById(editor).style.display = "none";
 
1097
    ed.style.display = "";
 
1098
    // workaround mozilla bug with losing design mode
 
1099
    ed.contentDocument.designMode = "on";
 
1100
    //document.getElementById(editor+"_rEdit").contentDocument.body.focus();
 
1101
    
 
1102
    // turn on invisible borders if needed
 
1103
    //SPAW_toggle_borders(editor,ed.contentDocument.body, null);
 
1104
    
 
1105
    SPAW_update_toolbar(editor, true);    
 
1106
  }
 
1107
  
 
1108
  // switch to html mode
 
1109
  function SPAW_html_tab_click(editor, sender)
 
1110
  {
 
1111
    var ed = document.getElementById(editor+'_rEdit');
 
1112
    var iHTML = SPAW_getHtmlValue(editor, null);
 
1113
 
 
1114
    document.getElementById(editor).value = iHTML;
 
1115
    
 
1116
    document.getElementById('SPAW_'+editor+'_editor_mode').value = 'html';
 
1117
 
 
1118
    // turn off design mode toolbars
 
1119
    document.getElementById('SPAW_'+editor+'_toolbar_top_design').style.display = 'none';
 
1120
    document.getElementById('SPAW_'+editor+'_toolbar_left_design').style.display = 'none';
 
1121
    document.getElementById('SPAW_'+editor+'_toolbar_right_design').style.display = 'none';
 
1122
    document.getElementById('SPAW_'+editor+'_toolbar_bottom_design').style.display = 'none';
 
1123
 
 
1124
    // turn on html mode toolbars
 
1125
    document.getElementById('SPAW_'+editor+'_toolbar_top_html').style.display = '';
 
1126
    document.getElementById('SPAW_'+editor+'_toolbar_left_html').style.display = '';
 
1127
    document.getElementById('SPAW_'+editor+'_toolbar_right_html').style.display = '';
 
1128
    document.getElementById('SPAW_'+editor+'_toolbar_bottom_html').style.display = '';
 
1129
 
 
1130
    // switch editors    
 
1131
    document.getElementById(editor+"_rEdit").style.display = "none";
 
1132
    document.getElementById(editor).style.display = "";
 
1133
    //document.getElementById(editor).focus();
 
1134
 
 
1135
    //SPAW_update_toolbar(editor, true);    
 
1136
  }
 
1137
  
 
1138
  function SPAW_getFieldByEditor(editor, field)
 
1139
  {
 
1140
    var thefield;
 
1141
    // get field by editor id
 
1142
    if (field == null || field == "")
 
1143
    {
 
1144
      thefield = document.getElementById(editor).id;
 
1145
    }
 
1146
    else
 
1147
    {
 
1148
      thefield=field;
 
1149
    }
 
1150
    return thefield;
 
1151
  }
 
1152
  
 
1153
  function SPAW_stripAbsoluteUrl(url)
 
1154
  {
 
1155
  }
 
1156
 
 
1157
  function SPAW_stripAbsoluteUrlFromImg(url)
 
1158
  {
 
1159
  }
 
1160
  
 
1161
  function SPAW_getHtmlValue(editor, thefield)
 
1162
  {
 
1163
    // temporary simplified
 
1164
    return document.getElementById(editor+"_rEdit").contentDocument.body.innerHTML;
 
1165
  }
 
1166
  
 
1167
  function SPAW_updateField(editor, field)
 
1168
  {  
 
1169
    var thefield = SPAW_getFieldByEditor(editor, field);
 
1170
    
 
1171
    var htmlvalue = SPAW_getHtmlValue(editor, thefield);
 
1172
 
 
1173
    if (document.getElementById(thefield).value != htmlvalue)
 
1174
    {
 
1175
      // something changed
 
1176
      document.getElementById(thefield).value = htmlvalue;
 
1177
    }
 
1178
  }
 
1179
 
 
1180
  function SPAW_confirm(editor,block,message) 
 
1181
  {
 
1182
  }
 
1183
  
 
1184
  // cleanup html
 
1185
  function SPAW_cleanup_click(editor, sender)
 
1186
  {
 
1187
  } // SPAW_cleanup_click
 
1188
  
 
1189
  // toggle borders worker function
 
1190
  function SPAW_toggle_borders(editor, root, toggle)
 
1191
  {
 
1192
  } // SPAW_toggle_borders
 
1193
  
 
1194
  // toggle borders click event 
 
1195
  function SPAW_toggle_borders_click(editor, sender)
 
1196
  {
 
1197
  } // SPAW_toggle_borders_click
 
1198
  
 
1199
  // returns base toolbar image name
 
1200
  function SPAW_base_image_name(ctrl)
 
1201
  {
 
1202
    var imgname = ctrl.src.substring(0,ctrl.src.lastIndexOf("/"))+"/tb_"+ctrl.id.substr(ctrl.id.lastIndexOf("_tb_")+4, ctrl.id.length);
 
1203
    return imgname;
 
1204
  }
 
1205
 
 
1206
  // update toolbar if cursor moved or some event happened
 
1207
  function SPAW_onkeyup(editor, e)
 
1208
  {
 
1209
    if (e.ctrlKey || (e.keyCode >= 33 && e.keyCode<=40))
 
1210
    {
 
1211
      SPAW_update_toolbar(editor, false);
 
1212
    }
 
1213
  }
 
1214
  
 
1215
  var spaw_context_html = null;
 
1216
  
 
1217
    // update active toolbar state
 
1218
  function SPAW_update_toolbar(editor, force)
 
1219
  {
 
1220
    document.getElementById(editor+'_rEdit').contentWindow.focus();
 
1221
    var pt = SPAW_getParentTag(editor);
 
1222
    if (pt)
 
1223
    {
 
1224
      if (pt.outerHTML == pt && !force)
 
1225
      {
 
1226
        return;
 
1227
      }
 
1228
      else
 
1229
      {
 
1230
        spaw_context_html = pt;
 
1231
      }
 
1232
    }
 
1233
     
 
1234
    // button sets
 
1235
    table_row_items     =  [
 
1236
                            "table_row_insert", 
 
1237
                            "table_row_delete"
 
1238
                          ];
 
1239
    table_cell_items    = [
 
1240
                            "table_cell_prop", 
 
1241
                            "table_column_insert",
 
1242
                            "table_column_delete",
 
1243
                            "table_cell_merge_right",
 
1244
                            "table_cell_merge_down",
 
1245
                            "table_cell_split_horizontal",
 
1246
                            "table_cell_split_vertical"
 
1247
                          ];
 
1248
    table_obj_items     = [
 
1249
                            "table_prop"
 
1250
                          ];
 
1251
    img_obj_items       = [
 
1252
                            "image_prop"
 
1253
                          ];
 
1254
                          
 
1255
    standard_cmd_items  = [ // command,             control id
 
1256
                            ["cut",                 "cut"],
 
1257
                            ["copy",                "copy"],
 
1258
                            ["paste",               "paste"],
 
1259
                            ["undo",                "undo"],
 
1260
                            ["redo",                "redo"],
 
1261
                            ["bold",                "bold"],
 
1262
                            ["italic",              "italic"],
 
1263
                            ["underline",           "underline"],
 
1264
                            ["justifyleft",         "left"],
 
1265
                            ["justifycenter",       "center"],
 
1266
                            ["justifyright",        "right"],
 
1267
                            ["justifyfull",         "justify"],
 
1268
                            ["indent",              "indent"],
 
1269
                            ["outdent",             "unindent"],
 
1270
                            ["forecolor",           "fore_color"],
 
1271
                            ["backcolor",           "bg_color"],
 
1272
                            ["insertorderedlist",   "ordered_list"],
 
1273
                            ["insertunorderedlist", "bulleted_list"],
 
1274
                            ["createlink",          "hyperlink"],
 
1275
                            ["createlink",          "internal_link"],
 
1276
                            ["createlink",          "image_popup"],
 
1277
                            ["inserthorizontalrule","hr"],
 
1278
                            ["subscript",                       "subscript"],
 
1279
                            ["superscript",                     "superscript"]
 
1280
                          ];                          
 
1281
 
 
1282
    togglable_items     = [ // command,             control id
 
1283
                            ["bold",                "bold"],
 
1284
                            ["italic",              "italic"],
 
1285
                            ["underline",           "underline"],
 
1286
                            ["justifyleft",         "left"],
 
1287
                            ["justifycenter",       "center"],
 
1288
                            ["justifyright",        "right"],
 
1289
                            ["justifyfull",         "justify"],
 
1290
                            ["subscript",                       "subscript"],
 
1291
                            ["superscript",                     "superscript"]
 
1292
                          ];        
 
1293
    standard_dropdowns  = [ // command,             control id
 
1294
                            ["fontname",            "font"],
 
1295
                            ["fontsize",            "fontsize"],
 
1296
                            ["formatblock",         "paragraph"]
 
1297
                          ];
 
1298
  
 
1299
    // proceed only if active toolbar is enabled
 
1300
    if (!spaw_active_toolbar) return;
 
1301
    
 
1302
    //window.frames[editor+'_rEdit'].focus();     
 
1303
 
 
1304
    // get object references
 
1305
    var eobj = document.getElementById(editor+'_rEdit'); // editor iframe
 
1306
    var edoc = eobj.contentDocument; // editor docutment
 
1307
    
 
1308
    // enable image insert
 
1309
    SPAW_toggle_tbi(editor,"image_insert", true);
 
1310
    // enable table insert
 
1311
    SPAW_toggle_tbi(editor,"table_create", true);
 
1312
 
 
1313
    // toggle table buttons
 
1314
    // get table
 
1315
    var ct = SPAW_getTable(editor);
 
1316
    if (ct)
 
1317
    {
 
1318
      // table found
 
1319
      // enable table properties
 
1320
      SPAW_toggle_tb_items(editor,table_obj_items, true);
 
1321
      
 
1322
      // get table row
 
1323
      var cr = SPAW_getTR(editor);
 
1324
      if (cr)
 
1325
      {
 
1326
        // enable table row features
 
1327
        SPAW_toggle_tb_items(editor,table_row_items, true);
 
1328
        
 
1329
        // get table cell
 
1330
        var cd = SPAW_getTD(editor);
 
1331
        if (cd)
 
1332
        {
 
1333
          // enable cell features
 
1334
          SPAW_toggle_tb_items(editor,table_cell_items, true);
 
1335
        }
 
1336
        else
 
1337
        {
 
1338
          // disable cell features
 
1339
          SPAW_toggle_tb_items(editor,table_cell_items, false);
 
1340
          // disable image insert
 
1341
          SPAW_toggle_tbi(editor,"image_insert", false);
 
1342
        }
 
1343
      }
 
1344
      else
 
1345
      {
 
1346
        // disable table row and cell features
 
1347
        SPAW_toggle_tb_items(editor,table_cell_items, false);
 
1348
        SPAW_toggle_tb_items(editor,table_row_items, false);
 
1349
        // disable image insert
 
1350
        SPAW_toggle_tbi(editor,"image_insert", false);
 
1351
      }
 
1352
    }
 
1353
    else
 
1354
    {
 
1355
      // disable all available table related buttons
 
1356
      SPAW_toggle_tb_items(editor,table_obj_items, false);
 
1357
      SPAW_toggle_tb_items(editor,table_row_items, false);
 
1358
      SPAW_toggle_tb_items(editor,table_cell_items, false);
 
1359
    }
 
1360
    // end table buttons
 
1361
 
 
1362
    // image buttons
 
1363
    // get image
 
1364
    var im = SPAW_getImg(editor);    
 
1365
    if (im)
 
1366
    {
 
1367
      // enable image buttons
 
1368
      SPAW_toggle_tb_items(editor,img_obj_items, true);
 
1369
      // disable table insert
 
1370
      SPAW_toggle_tbi(editor,"table_create", false);
 
1371
    }
 
1372
    else
 
1373
    {
 
1374
      // disable image buttons
 
1375
      SPAW_toggle_tb_items(editor,img_obj_items, false);
 
1376
    }
 
1377
    // end image buttons
 
1378
    
 
1379
    // set state and enable/disable standard command buttons
 
1380
    for (var i=0; i<togglable_items.length; i++)
 
1381
    {
 
1382
      try
 
1383
      {
 
1384
        SPAW_toggle_tbi_state(editor, togglable_items[i][1], edoc.queryCommandState(togglable_items[i][0]));
 
1385
      }
 
1386
      catch (excp) {}
 
1387
    }
 
1388
    for (var i=0; i<standard_cmd_items.length; i++)
 
1389
    {
 
1390
      try
 
1391
      {
 
1392
        SPAW_toggle_tbi(editor, standard_cmd_items[i][1], edoc.queryCommandEnabled(standard_cmd_items[i][0]));
 
1393
      }
 
1394
      catch (excp) {}
 
1395
    }
 
1396
    
 
1397
    // set state of toggle borders button
 
1398
    if (document.getElementById("SPAW_"+editor+"_borders").value == "on")
 
1399
    {
 
1400
      SPAW_toggle_tbi_state(editor, "toggle_borders", true);
 
1401
    }
 
1402
    else
 
1403
    {
 
1404
      SPAW_toggle_tbi_state(editor, "toggle_borders", false);
 
1405
    }
 
1406
    
 
1407
    // dropdowns
 
1408
    for (var i=0; i<standard_dropdowns.length; i++)
 
1409
    {
 
1410
      try
 
1411
      {
 
1412
        SPAW_toggle_tbi_dropdown(editor, standard_dropdowns[i][1], edoc.queryCommandValue(standard_dropdowns[i][0]));
 
1413
      }
 
1414
      catch (excp) {}
 
1415
    }
 
1416
    // style dropdown
 
1417
    var pt = SPAW_getParentTag(editor);
 
1418
    if (pt)
 
1419
      SPAW_toggle_tbi_dropdown(editor, "style", pt.className);
 
1420
  }
 
1421
  
 
1422
  // enable/disable toolbar item
 
1423
  function SPAW_toggle_tb_items(editor, items, enable)
 
1424
  {
 
1425
    for (var i=0; i<items.length; i++)
 
1426
    {
 
1427
      SPAW_toggle_tbi(editor, items[i], enable);
 
1428
    }
 
1429
  }
 
1430
  
 
1431
  // enable/disable toolbar item
 
1432
  function SPAW_toggle_tbi(editor, item, enable)
 
1433
  {
 
1434
    if (document.getElementById("SPAW_"+editor+"_tb_"+item))
 
1435
    {
 
1436
      var ctrl = document.getElementById("SPAW_"+editor+"_tb_"+item);
 
1437
      if (enable)
 
1438
      {
 
1439
        if (ctrl)
 
1440
        {
 
1441
          ctrl.disabled = false;
 
1442
          eval("SPAW_"+document.getElementById("SPAW_"+editor+"_theme").value+"_bt_out(ctrl);");
 
1443
        }
 
1444
      }
 
1445
      else
 
1446
      {
 
1447
        if (ctrl)
 
1448
        {
 
1449
          ctrl.disabled = true;
 
1450
          eval("SPAW_"+document.getElementById("SPAW_"+editor+"_theme").value+"_bt_off(ctrl);");
 
1451
        }
 
1452
      }
 
1453
    }
 
1454
  }
 
1455
  
 
1456
  // set state of the toolbar item
 
1457
  function SPAW_toggle_tbi_state(editor, item, state)
 
1458
  {
 
1459
    if (document.getElementById("SPAW_"+editor+"_tb_"+item))
 
1460
    {
 
1461
      var ctrl = document.getElementById("SPAW_"+editor+"_tb_"+item);
 
1462
      ctrl.setAttribute("spaw_state",state)
 
1463
      eval("SPAW_"+document.getElementById("SPAW_"+editor+"_theme").value+"_bt_out(ctrl);");
 
1464
    }
 
1465
  }
 
1466
  
 
1467
  // set dropdown value
 
1468
  function SPAW_toggle_tbi_dropdown(editor, item, value)
 
1469
  {
 
1470
    if (document.getElementById("SPAW_"+editor+"_tb_"+item))
 
1471
    {
 
1472
      var ctrl = document.getElementById("SPAW_"+editor+"_tb_"+item);
 
1473
      ctrl.options[0].selected = true;
 
1474
      for (var ii=0; ii<ctrl.options.length; ii++)
 
1475
      {
 
1476
        if (ctrl.options[ii].value == value)
 
1477
        {
 
1478
          ctrl.options[ii].selected = true;
 
1479
        }
 
1480
        else
 
1481
        {
 
1482
          ctrl.options[ii].selected = false;
 
1483
        }
 
1484
      }
 
1485
    }
 
1486
  }
 
1487
  
 
1488
  function SPAW_superscript_click(editor, sender)
 
1489
  {
 
1490
    var ed = document.getElementById(editor+'_rEdit');
 
1491
    ed.contentDocument.execCommand('superscript', false, null);
 
1492
    ed.contentWindow.focus();
 
1493
    SPAW_update_toolbar(editor, true);    
 
1494
  }
 
1495
 
 
1496
  function SPAW_subscript_click(editor, sender)
 
1497
  {
 
1498
    var ed = document.getElementById(editor+'_rEdit');
 
1499
    ed.contentDocument.execCommand('subscript', false, null);
 
1500
    ed.contentWindow.focus();
 
1501
    SPAW_update_toolbar(editor, true);    
 
1502
  }