Dotclear


Ignore:
Timestamp:
03/19/18 13:30:59 (8 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Code formating and tiny bug fixed in wysiwyg iframe markup

Location:
plugins/dcLegacyEditor/js/jsToolBar
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • plugins/dcLegacyEditor/js/jsToolBar/jsToolBar.dotclear.js

    r3361 r3735  
     1/*global jsToolBar */ 
     2'use strict'; 
     3 
    14/* Change link button actions 
    25-------------------------------------------------------- */ 
     
    69 
    710jsToolBar.prototype.elements.link.popup = function(args) { 
    8      window.the_toolbar = this; 
    9      args = args || ''; 
    10  
    11      this.elements.link.data = {}; 
    12      var url = this.elements.link.open_url+args; 
    13  
    14      var p_win = window.open(url,'dc_popup', 
    15      'alwaysRaised=yes,dependent=yes,toolbar=yes,height=420,width=520,'+ 
    16      'menubar=no,resizable=yes,scrollbars=yes,status=no'); 
     11  window.the_toolbar = this; 
     12  args = args || ''; 
     13 
     14  this.elements.link.data = {}; 
     15  var url = this.elements.link.open_url + args; 
     16 
     17  window.open(url, 'dc_popup', 
     18    'alwaysRaised=yes,dependent=yes,toolbar=yes,height=420,width=520,' + 
     19    'menubar=no,resizable=yes,scrollbars=yes,status=no'); 
    1720}; 
    1821 
    1922jsToolBar.prototype.elements.link.fn.wiki = function() { 
    20      this.elements.link.popup.call(this,'&hreflang='+this.elements.link.default_hreflang); 
     23  this.elements.link.popup.call(this, '&hreflang=' + this.elements.link.default_hreflang); 
    2124}; 
    2225jsToolBar.prototype.elements.link.fncall.wiki = function() { 
    23      var data = this.elements.link.data; 
    24  
    25      if (data.href == '') { return; } 
    26  
    27      var etag = '|'+data.href; 
    28      if (data.hreflang) { etag += '|'+data.hreflang; } 
    29  
    30      if (data.title) { 
    31           if (!data.hreflang) { etag += '|'; } 
    32           etag += '|'+data.title; 
    33      } 
    34  
    35      if (data.content) { 
    36           this.encloseSelection('['+data.content,etag+']'); 
    37      } else { 
    38           this.encloseSelection('[',etag+']'); 
    39      } 
     26  var data = this.elements.link.data; 
     27 
     28  if (data.href == '') { 
     29    return; 
     30  } 
     31 
     32  var etag = '|' + data.href; 
     33  if (data.hreflang) { 
     34    etag += '|' + data.hreflang; 
     35  } 
     36 
     37  if (data.title) { 
     38    if (!data.hreflang) { 
     39      etag += '|'; 
     40    } 
     41    etag += '|' + data.title; 
     42  } 
     43 
     44  if (data.content) { 
     45    this.encloseSelection('[' + data.content, etag + ']'); 
     46  } else { 
     47    this.encloseSelection('[', etag + ']'); 
     48  } 
    4049}; 
    4150 
    4251jsToolBar.prototype.elements.link.fn.xhtml = function() { 
    43      this.elements.link.popup.call(this,'&hreflang='+this.elements.link.default_hreflang); 
     52  this.elements.link.popup.call(this, '&hreflang=' + this.elements.link.default_hreflang); 
    4453}; 
    4554jsToolBar.prototype.elements.link.fncall.xhtml = function() { 
    46      var data = this.elements.link.data; 
    47  
    48      if (data.href == '') { return; } 
    49  
    50      var stag = '<a href="'+data.href+'"'; 
    51  
    52      if (data.hreflang) { stag += ' hreflang="'+data.hreflang+'"'; } 
    53      if (data.title) { stag += ' title="'+data.title+'"'; } 
    54      stag += '>'; 
    55      var etag = '</a>'; 
    56  
    57      if (data.content) { 
    58           this.encloseSelection('','',function() { 
    59                return stag + data.content + etag; 
    60           }); 
    61      } else { 
    62           this.encloseSelection(stag,etag); 
    63      } 
     55  var data = this.elements.link.data; 
     56 
     57  if (data.href == '') { 
     58    return; 
     59  } 
     60 
     61  var stag = '<a href="' + data.href + '"'; 
     62 
     63  if (data.hreflang) { 
     64    stag += ' hreflang="' + data.hreflang + '"'; 
     65  } 
     66  if (data.title) { 
     67    stag += ' title="' + data.title + '"'; 
     68  } 
     69  stag += '>'; 
     70  var etag = '</a>'; 
     71 
     72  if (data.content) { 
     73    this.encloseSelection('', '', function() { 
     74      return stag + data.content + etag; 
     75    }); 
     76  } else { 
     77    this.encloseSelection(stag, etag); 
     78  } 
    6479}; 
    6580 
    6681jsToolBar.prototype.elements.link.fn.wysiwyg = function() { 
    67      var href, title, hreflang; 
    68      href = title = hreflang = ''; 
    69      hreflang = this.elements.link.default_hreflang; 
    70  
    71      var a = this.getAncestor(); 
    72  
    73      if (a.tagName == 'a') { 
    74           href= a.tag.href || ''; 
    75           title = a.tag.title || ''; 
    76           hreflang = a.tag.hreflang || ''; 
    77      } 
    78  
    79      this.elements.link.popup.call(this,'&href='+href+'&hreflang='+hreflang+'&title='+title); 
     82  var href, title, hreflang; 
     83  href = title = hreflang = ''; 
     84  hreflang = this.elements.link.default_hreflang; 
     85 
     86  var a = this.getAncestor(); 
     87 
     88  if (a.tagName == 'a') { 
     89    href = a.tag.href || ''; 
     90    title = a.tag.title || ''; 
     91    hreflang = a.tag.hreflang || ''; 
     92  } 
     93 
     94  this.elements.link.popup.call(this, '&href=' + href + '&hreflang=' + hreflang + '&title=' + title); 
    8095}; 
    8196jsToolBar.prototype.elements.link.fncall.wysiwyg = function() { 
    82      var data = this.elements.link.data; 
    83  
    84      var a = this.getAncestor(); 
    85  
    86      if (a.tagName == 'a') { 
    87           if (data.href == '') { 
    88                // Remove link 
    89                this.replaceNodeByContent(a.tag); 
    90                this.iwin.focus(); 
    91                return; 
    92           } else { 
    93                // Update link 
    94                a.tag.href = data.href; 
    95                if (data.hreflang) { 
    96                     a.tag.setAttribute('hreflang',data.hreflang); 
    97                } else { 
    98                     a.tag.removeAttribute('hreflang'); 
    99                } 
    100                if (data.title) { 
    101                     a.tag.setAttribute('title',data.title); 
    102                } else { 
    103                     a.tag.removeAttribute('title'); 
    104                } 
    105                return; 
    106           } 
    107      } 
    108  
    109      // Create link 
    110      if (data.content) { 
    111           var n = document.createTextNode(data.content); 
    112      } else { 
    113           var n = this.getSelectedNode(); 
    114      } 
    115      var a = this.iwin.document.createElement('a'); 
    116      a.href = data.href; 
    117      if (data.hreflang) a.setAttribute('hreflang',data.hreflang); 
    118      if (data.title) a.setAttribute('title',data.title); 
    119      a.appendChild(n); 
    120      this.insertNode(a); 
     97  var data = this.elements.link.data; 
     98 
     99  var a = this.getAncestor(); 
     100 
     101  if (a.tagName == 'a') { 
     102    if (data.href == '') { 
     103      // Remove link 
     104      this.replaceNodeByContent(a.tag); 
     105      this.iwin.focus(); 
     106      return; 
     107    } else { 
     108      // Update link 
     109      a.tag.href = data.href; 
     110      if (data.hreflang) { 
     111        a.tag.setAttribute('hreflang', data.hreflang); 
     112      } else { 
     113        a.tag.removeAttribute('hreflang'); 
     114      } 
     115      if (data.title) { 
     116        a.tag.setAttribute('title', data.title); 
     117      } else { 
     118        a.tag.removeAttribute('title'); 
     119      } 
     120      return; 
     121    } 
     122  } 
     123 
     124  // Create link 
     125  var n; 
     126  if (data.content) { 
     127    n = document.createTextNode(data.content); 
     128  } else { 
     129    n = this.getSelectedNode(); 
     130  } 
     131  a = this.iwin.document.createElement('a'); 
     132  a.href = data.href; 
     133  if (data.hreflang) a.setAttribute('hreflang', data.hreflang); 
     134  if (data.title) a.setAttribute('title', data.title); 
     135  a.appendChild(n); 
     136  this.insertNode(a); 
    121137}; 
    122138jsToolBar.prototype.getAncestor = function() { 
    123      var res = {}; 
    124      var range, commonAncestorContainer; 
    125  
    126      if (this.iwin.getSelection) { //gecko 
    127           var selection = this.iwin.getSelection(); 
    128           range = selection.getRangeAt(0); 
    129           commonAncestorContainer = range.commonAncestorContainer; 
    130           while (commonAncestorContainer.nodeType != 1) { 
    131                commonAncestorContainer = commonAncestorContainer.parentNode; 
    132           } 
    133      } else { //ie 
    134           range = this.iwin.document.selection.createRange(); 
    135           commonAncestorContainer = range.parentElement(); 
    136      } 
    137  
    138      var ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); 
    139      while (ancestorTagName!='a' && ancestorTagName!='body') { 
    140           commonAncestorContainer = commonAncestorContainer.parentNode; 
    141           ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); 
    142      } 
    143  
    144      res.tag = commonAncestorContainer; 
    145      res.tagName = ancestorTagName; 
    146  
    147      return res; 
     139  var res = {}; 
     140  var range, commonAncestorContainer; 
     141 
     142  if (this.iwin.getSelection) { //gecko 
     143    var selection = this.iwin.getSelection(); 
     144    range = selection.getRangeAt(0); 
     145    commonAncestorContainer = range.commonAncestorContainer; 
     146    while (commonAncestorContainer.nodeType != 1) { 
     147      commonAncestorContainer = commonAncestorContainer.parentNode; 
     148    } 
     149  } else { //ie 
     150    range = this.iwin.document.selection.createRange(); 
     151    commonAncestorContainer = range.parentElement(); 
     152  } 
     153 
     154  var ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); 
     155  while (ancestorTagName != 'a' && ancestorTagName != 'body') { 
     156    commonAncestorContainer = commonAncestorContainer.parentNode; 
     157    ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); 
     158  } 
     159 
     160  res.tag = commonAncestorContainer; 
     161  res.tagName = ancestorTagName; 
     162 
     163  return res; 
    148164}; 
    149165 
     
    151167-------------------------------------------------------- */ 
    152168jsToolBar.prototype.elements.img_select = { 
    153      type: 'button', 
    154      title: 'Image chooser', 
    155      accesskey: 'm', 
    156      fn: {}, 
    157      fncall: {}, 
    158      open_url: 'media.php?popup=1&plugin_id=dcLegacyEditor', 
    159      data: {}, 
    160      popup: function() { 
    161           window.the_toolbar = this; 
    162           this.elements.img_select.data = {}; 
    163  
    164           var p_win = window.open(this.elements.img_select.open_url,'dc_popup', 
    165           'alwaysRaised=yes,dependent=yes,toolbar=yes,height=500,width=760,'+ 
    166           'menubar=no,resizable=yes,scrollbars=yes,status=no'); 
    167      } 
     169  type: 'button', 
     170  title: 'Image chooser', 
     171  accesskey: 'm', 
     172  fn: {}, 
     173  fncall: {}, 
     174  open_url: 'media.php?popup=1&plugin_id=dcLegacyEditor', 
     175  data: {}, 
     176  popup: function() { 
     177    window.the_toolbar = this; 
     178    this.elements.img_select.data = {}; 
     179 
     180    window.open(this.elements.img_select.open_url, 'dc_popup', 
     181      'alwaysRaised=yes,dependent=yes,toolbar=yes,height=500,width=760,' + 
     182      'menubar=no,resizable=yes,scrollbars=yes,status=no'); 
     183  } 
    168184}; 
    169185jsToolBar.prototype.elements.img_select.fn.wiki = function() { 
    170      this.elements.img_select.popup.call(this); 
     186  this.elements.img_select.popup.call(this); 
    171187}; 
    172188jsToolBar.prototype.elements.img_select.fncall.wiki = function() { 
    173      var d = this.elements.img_select.data; 
    174      if (d.src == undefined) { return; } 
    175  
    176      this.encloseSelection('','',function(str) { 
    177           var alt = (str) ? str : d.title; 
    178           var res = '(('+d.src+'|'+alt; 
    179  
    180           if (d.alignment == 'left') { 
    181                res += '|L'; 
    182           } else if (d.alignment == 'right') { 
    183                res += '|R'; 
    184           } else if (d.alignment == 'center') { 
    185                res += '|C'; 
    186           } else if (d.description) { 
    187                res += '|'; 
    188           } 
    189  
    190           if (d.description) { 
    191                res += '|'+d.description; 
    192           } 
    193  
    194           res += '))'; 
    195  
    196           if (d.link) { 
    197                var ltitle = (alt) ? '||'+alt : ''; 
    198                res = '['+res+'|'+d.url+ltitle+']'; 
    199           } 
    200  
    201           return res; 
    202      }); 
     189  var d = this.elements.img_select.data; 
     190  if (d.src == undefined) { 
     191    return; 
     192  } 
     193 
     194  this.encloseSelection('', '', function(str) { 
     195    var alt = (str) ? str : d.title; 
     196    var res = '((' + d.src + '|' + alt; 
     197 
     198    if (d.alignment == 'left') { 
     199      res += '|L'; 
     200    } else if (d.alignment == 'right') { 
     201      res += '|R'; 
     202    } else if (d.alignment == 'center') { 
     203      res += '|C'; 
     204    } else if (d.description) { 
     205      res += '|'; 
     206    } 
     207 
     208    if (d.description) { 
     209      res += '|' + d.description; 
     210    } 
     211 
     212    res += '))'; 
     213 
     214    if (d.link) { 
     215      var ltitle = (alt) ? '||' + alt : ''; 
     216      res = '[' + res + '|' + d.url + ltitle + ']'; 
     217    } 
     218 
     219    return res; 
     220  }); 
    203221}; 
    204222jsToolBar.prototype.elements.img_select.fn.xhtml = function() { 
    205      this.elements.img_select.popup.call(this); 
     223  this.elements.img_select.popup.call(this); 
    206224}; 
    207225jsToolBar.prototype.elements.img_select.fncall.xhtml = function() { 
    208      var d = this.elements.img_select.data; 
    209      if (d.src == undefined) { return; } 
    210  
    211      this.encloseSelection('','',function(str) { 
    212           var alt = (str) ? str : d.title; 
    213           var res = '<img src="'+d.src+'" alt="'+alt.replace('&','&amp;').replace('>','&gt;').replace('<','&lt;').replace('"','&quot;')+'"'; 
    214  
    215           if (d.alignment == 'left') { 
    216                res += ' style="float: left; margin: 0 1em 1em 0;"'; 
    217           } else if (d.alignment == 'right') { 
    218                res += ' style="float: right; margin: 0 0 1em 1em;"'; 
    219           } else if (d.alignment == 'center') { 
    220                res += ' style="margin: 0 auto; display: block;"'; 
    221           } 
    222  
    223           if (d.description) { 
    224                res += ' title="'+d.description.replace('&','&amp;').replace('>','&gt;').replace('<','&lt;').replace('"','&quot;')+'"'; 
    225           } 
    226  
    227           res += ' />'; 
    228  
    229           if (d.link) { 
    230                var ltitle = (alt) ? ' title="'+alt.replace('&','&amp;').replace('>','&gt;').replace('<','&lt;').replace('"','&quot;')+'"' : ''; 
    231                res = '<a href="'+d.url+'"'+ltitle+'>'+res+'</a>'; 
    232           } 
    233  
    234           return res; 
    235      }); 
     226  var d = this.elements.img_select.data; 
     227  if (d.src == undefined) { 
     228    return; 
     229  } 
     230 
     231  this.encloseSelection('', '', function(str) { 
     232    var alt = (str) ? str : d.title; 
     233    var res = '<img src="' + d.src + '" alt="' + alt.replace('&', '&amp;').replace('>', '&gt;').replace('<', '&lt;').replace('"', '&quot;') + '"'; 
     234 
     235    if (d.alignment == 'left') { 
     236      res += ' style="float: left; margin: 0 1em 1em 0;"'; 
     237    } else if (d.alignment == 'right') { 
     238      res += ' style="float: right; margin: 0 0 1em 1em;"'; 
     239    } else if (d.alignment == 'center') { 
     240      res += ' style="margin: 0 auto; display: block;"'; 
     241    } 
     242 
     243    if (d.description) { 
     244      res += ' title="' + d.description.replace('&', '&amp;').replace('>', '&gt;').replace('<', '&lt;').replace('"', '&quot;') + '"'; 
     245    } 
     246 
     247    res += ' />'; 
     248 
     249    if (d.link) { 
     250      var ltitle = (alt) ? ' title="' + alt.replace('&', '&amp;').replace('>', '&gt;').replace('<', '&lt;').replace('"', '&quot;') + '"' : ''; 
     251      res = '<a href="' + d.url + '"' + ltitle + '>' + res + '</a>'; 
     252    } 
     253 
     254    return res; 
     255  }); 
    236256}; 
    237257 
    238258jsToolBar.prototype.elements.img.fn.wysiwyg = function() { 
    239      var src = this.elements.img.prompt.call(this); 
    240      if (!src) { return; } 
    241  
    242      var img = this.iwin.document.createElement('img'); 
    243      img.src = src; 
    244      img.setAttribute('alt',this.getSelectedText()); 
    245  
    246      this.insertNode(img); 
     259  var src = this.elements.img.prompt.call(this); 
     260  if (!src) { 
     261    return; 
     262  } 
     263 
     264  var img = this.iwin.document.createElement('img'); 
     265  img.src = src; 
     266  img.setAttribute('alt', this.getSelectedText()); 
     267 
     268  this.insertNode(img); 
    247269}; 
    248270 
    249271jsToolBar.prototype.elements.img_select.fn.wysiwyg = function() { 
    250      this.elements.img_select.popup.call(this); 
     272  this.elements.img_select.popup.call(this); 
    251273}; 
    252274jsToolBar.prototype.elements.img_select.fncall.wysiwyg = function() { 
    253      var d = this.elements.img_select.data; 
    254      var alt = (this.getSelectedText()) ? this.getSelectedText() : d.title; 
    255      if (d.src == undefined) { return; } 
    256  
    257      var img = this.iwin.document.createElement('img'); 
    258      img.src = d.src; 
    259      img.setAttribute('alt',alt); 
    260  
    261  
    262      if (d.alignment == 'left') { 
    263           if (img.style.styleFloat != undefined) { 
    264                img.style.styleFloat = 'left'; 
    265           } else { 
    266                img.style.cssFloat = 'left'; 
    267           } 
    268           img.style.marginTop = 0; 
    269           img.style.marginRight = '1em'; 
    270           img.style.marginBottom = '1em'; 
    271           img.style.marginLeft = 0; 
    272      } else if (d.alignment == 'right') { 
    273           if (img.style.styleFloat != undefined) { 
    274                img.style.styleFloat = 'right'; 
    275           } else { 
    276                img.style.cssFloat = 'right'; 
    277           } 
    278           img.style.marginTop = 0; 
    279           img.style.marginRight = 0; 
    280           img.style.marginBottom = '1em'; 
    281           img.style.marginLeft = '1em'; 
    282      } else if (d.alignment == 'center') { 
    283           img.style.marginTop = 0; 
    284           img.style.marginRight = 'auto'; 
    285           img.style.marginBottom = 0; 
    286           img.style.marginLeft = 'auto'; 
    287           img.style.display = 'block'; 
    288      } 
    289  
    290      if (d.description) { 
    291           img.setAttribute('title',d.description); 
    292      } 
    293  
    294      if (d.link) { 
    295           var a = this.iwin.document.createElement('a'); 
    296           a.href = d.url; 
    297           if (alt) { 
    298                a.setAttribute('title',alt); 
    299           } 
    300           a.appendChild(img); 
    301           this.insertNode(a); 
    302      } else { 
    303           this.insertNode(img); 
    304      } 
     275  var d = this.elements.img_select.data; 
     276  var alt = (this.getSelectedText()) ? this.getSelectedText() : d.title; 
     277  if (d.src == undefined) { 
     278    return; 
     279  } 
     280 
     281  var img = this.iwin.document.createElement('img'); 
     282  img.src = d.src; 
     283  img.setAttribute('alt', alt); 
     284 
     285  if (d.alignment == 'left') { 
     286    if (img.style.styleFloat != undefined) { 
     287      img.style.styleFloat = 'left'; 
     288    } else { 
     289      img.style.cssFloat = 'left'; 
     290    } 
     291    img.style.marginTop = 0; 
     292    img.style.marginRight = '1em'; 
     293    img.style.marginBottom = '1em'; 
     294    img.style.marginLeft = 0; 
     295  } else if (d.alignment == 'right') { 
     296    if (img.style.styleFloat != undefined) { 
     297      img.style.styleFloat = 'right'; 
     298    } else { 
     299      img.style.cssFloat = 'right'; 
     300    } 
     301    img.style.marginTop = 0; 
     302    img.style.marginRight = 0; 
     303    img.style.marginBottom = '1em'; 
     304    img.style.marginLeft = '1em'; 
     305  } else if (d.alignment == 'center') { 
     306    img.style.marginTop = 0; 
     307    img.style.marginRight = 'auto'; 
     308    img.style.marginBottom = 0; 
     309    img.style.marginLeft = 'auto'; 
     310    img.style.display = 'block'; 
     311  } 
     312 
     313  if (d.description) { 
     314    img.setAttribute('title', d.description); 
     315  } 
     316 
     317  if (d.link) { 
     318    var a = this.iwin.document.createElement('a'); 
     319    a.href = d.url; 
     320    if (alt) { 
     321      a.setAttribute('title', alt); 
     322    } 
     323    a.appendChild(img); 
     324    this.insertNode(a); 
     325  } else { 
     326    this.insertNode(img); 
     327  } 
    305328}; 
    306329 
    307330// MP3 helpers 
    308 jsToolBar.prototype.elements.mp3_insert = { fncall: {}, data: {} }; 
     331jsToolBar.prototype.elements.mp3_insert = { 
     332  fncall: {}, 
     333  data: {} 
     334}; 
    309335jsToolBar.prototype.elements.mp3_insert.fncall.wiki = function() { 
    310      var d = this.elements.mp3_insert.data; 
    311      if (d.player == undefined) { return; } 
    312  
    313      this.encloseSelection('','',function(str) { 
    314           return '\n///html\n' + d.player + '///\n'; 
    315      }); 
     336  var d = this.elements.mp3_insert.data; 
     337  if (d.player == undefined) { 
     338    return; 
     339  } 
     340 
     341  this.encloseSelection('', '', function() { 
     342    return '\n///html\n' + d.player + '///\n'; 
     343  }); 
    316344}; 
    317345jsToolBar.prototype.elements.mp3_insert.fncall.xhtml = function() { 
    318      var d = this.elements.mp3_insert.data; 
    319      if (d.player == undefined) { return; } 
    320  
    321      this.encloseSelection('','',function(str) { 
    322           return '\n' + d.player + '\n'; 
    323      }); 
     346  var d = this.elements.mp3_insert.data; 
     347  if (d.player == undefined) { 
     348    return; 
     349  } 
     350 
     351  this.encloseSelection('', '', function() { 
     352    return '\n' + d.player + '\n'; 
     353  }); 
    324354}; 
    325355jsToolBar.prototype.elements.mp3_insert.fncall.wysiwyg = function() { 
    326      return; 
     356  return; 
    327357}; 
    328358 
    329359// FLV helpers 
    330 jsToolBar.prototype.elements.flv_insert = { fncall: {}, data: {} }; 
     360jsToolBar.prototype.elements.flv_insert = { 
     361  fncall: {}, 
     362  data: {} 
     363}; 
    331364jsToolBar.prototype.elements.flv_insert.fncall.wiki = function() { 
    332      var d = this.elements.flv_insert.data; 
    333      if (d.player == undefined) { return; } 
    334  
    335      this.encloseSelection('','',function(str) { 
    336           return '\n///html\n' + d.player + '///\n'; 
    337      }); 
     365  var d = this.elements.flv_insert.data; 
     366  if (d.player == undefined) { 
     367    return; 
     368  } 
     369 
     370  this.encloseSelection('', '', function() { 
     371    return '\n///html\n' + d.player + '///\n'; 
     372  }); 
    338373}; 
    339374jsToolBar.prototype.elements.flv_insert.fncall.xhtml = function() { 
    340      var d = this.elements.flv_insert.data; 
    341      if (d.player == undefined) { return; } 
    342  
    343      this.encloseSelection('','',function(str) { 
    344           return '\n' + d.player + '\n'; 
    345      }); 
     375  var d = this.elements.flv_insert.data; 
     376  if (d.player == undefined) { 
     377    return; 
     378  } 
     379 
     380  this.encloseSelection('', '', function() { 
     381    return '\n' + d.player + '\n'; 
     382  }); 
    346383}; 
    347384jsToolBar.prototype.elements.flv_insert.fncall.wysiwyg = function() { 
    348      return; 
    349 }; 
    350  
     385  return; 
     386}; 
    351387 
    352388/* Posts selector 
    353389-------------------------------------------------------- */ 
    354390jsToolBar.prototype.elements.post_link = { 
    355      type: 'button', 
    356      title: 'Link to an entry', 
    357      fn: {}, 
    358      open_url: 'popup_posts.php?plugin_id=dcLegacyEditor', 
    359      data: {}, 
    360      popup: function() { 
    361           window.the_toolbar = this; 
    362           this.elements.img_select.data = {}; 
    363  
    364           var p_win = window.open(this.elements.post_link.open_url,'dc_popup', 
    365           'alwaysRaised=yes,dependent=yes,toolbar=yes,height=500,width=760,'+ 
    366           'menubar=no,resizable=yes,scrollbars=yes,status=no'); 
    367      } 
     391  type: 'button', 
     392  title: 'Link to an entry', 
     393  fn: {}, 
     394  open_url: 'popup_posts.php?plugin_id=dcLegacyEditor', 
     395  data: {}, 
     396  popup: function() { 
     397    window.the_toolbar = this; 
     398    this.elements.img_select.data = {}; 
     399 
     400    window.open(this.elements.post_link.open_url, 'dc_popup', 
     401      'alwaysRaised=yes,dependent=yes,toolbar=yes,height=500,width=760,' + 
     402      'menubar=no,resizable=yes,scrollbars=yes,status=no'); 
     403  } 
    368404}; 
    369405jsToolBar.prototype.elements.post_link.fn.wiki = function() { 
    370      this.elements.post_link.popup.call(this); 
     406  this.elements.post_link.popup.call(this); 
    371407}; 
    372408jsToolBar.prototype.elements.post_link.fn.xhtml = function() { 
    373      this.elements.post_link.popup.call(this); 
     409  this.elements.post_link.popup.call(this); 
    374410}; 
    375411jsToolBar.prototype.elements.post_link.fn.wysiwyg = function() { 
    376      this.elements.post_link.popup.call(this); 
     412  this.elements.post_link.popup.call(this); 
    377413}; 
    378414 
    379415// Last space element 
    380416jsToolBar.prototype.elements.space3 = { 
    381      type:'space', 
    382      format:{ 
    383           wysiwyg:true, 
    384           wiki:true, 
    385           xhtml:true 
    386      } 
    387 }; 
     417  type: 'space', 
     418  format: { 
     419    wysiwyg: true, 
     420    wiki: true, 
     421    xhtml: true 
     422  } 
     423}; 
  • plugins/dcLegacyEditor/js/jsToolBar/jsToolBar.js

    r3643 r3735  
     1/*exported jsToolBar */ 
     2'use strict'; 
     3 
    14/* ***** BEGIN LICENSE BLOCK ***** 
    25 * This file is part of DotClear. 
     
    1922 * 
    2023 * ***** END LICENSE BLOCK ***** 
    21 */ 
    22  
    23 function jsToolBar(textarea) { 
    24      if (!document.createElement) { return; } 
    25  
    26      if (!textarea) { return; } 
    27  
    28      if ((typeof(document["selection"]) == "undefined") 
    29      && (typeof(textarea["setSelectionRange"]) == "undefined")) { 
    30           return; 
    31      } 
    32  
    33      this.textarea = textarea; 
    34  
    35      this.editor = document.createElement('div'); 
    36      this.editor.className = 'jstEditor'; 
    37  
    38      this.textarea.parentNode.insertBefore(this.editor,this.textarea); 
    39      this.editor.appendChild(this.textarea); 
    40  
    41      this.toolbar = document.createElement("div"); 
    42      this.toolbar.className = 'jstElements'; 
    43  
    44      if (this.toolbar_bottom) { 
    45           this.editor.parentNode.insertBefore(this.toolbar,this.editor.nextSibling); 
    46      } else { 
    47           this.editor.parentNode.insertBefore(this.toolbar,this.editor); 
    48      } 
    49  
    50      // Dragable resizing (only for gecko) 
    51      if (navigator.appName == 'Microsoft Internet Explorer') 
    52      { 
    53           if (this.editor.addEventListener) 
    54           { 
    55                this.handle = document.createElement('div'); 
    56                this.handle.className = 'jstHandle'; 
    57                var dragStart = this.resizeDragStart; 
    58                var This = this; 
    59                this.handle.addEventListener('mousedown',function(event) { dragStart.call(This,event); },false); 
    60                this.editor.parentNode.insertBefore(this.handle,this.editor.nextSibling); 
    61           } 
    62      } 
    63  
    64      this.context = null; 
    65      this.toolNodes = {}; // lorsque la toolbar est dessinée , cet objet est garni 
    66                          // de raccourcis vers les éléments DOM correspondants aux outils. 
    67 }; 
    68  
    69 function jsButton(title, fn, scope, className, accesskey) { 
    70      this.title = title || null; 
    71      this.fn = fn || function(){}; 
    72      this.scope = scope || null; 
    73      this.className = className || null; 
    74      this.accesskey = accesskey || null; 
     24 */ 
     25 
     26var jsToolBar = function(textarea) { 
     27  if (!document.createElement) { 
     28    return; 
     29  } 
     30 
     31  if (!textarea) { 
     32    return; 
     33  } 
     34 
     35  if ((typeof(document.selection) == "undefined") && (typeof(textarea.setSelectionRange) == "undefined")) { 
     36    return; 
     37  } 
     38 
     39  this.textarea = textarea; 
     40 
     41  this.editor = document.createElement('div'); 
     42  this.editor.className = 'jstEditor'; 
     43 
     44  this.textarea.parentNode.insertBefore(this.editor, this.textarea); 
     45  this.editor.appendChild(this.textarea); 
     46 
     47  this.toolbar = document.createElement("div"); 
     48  this.toolbar.className = 'jstElements'; 
     49 
     50  if (this.toolbar_bottom) { 
     51    this.editor.parentNode.insertBefore(this.toolbar, this.editor.nextSibling); 
     52  } else { 
     53    this.editor.parentNode.insertBefore(this.toolbar, this.editor); 
     54  } 
     55 
     56  // Dragable resizing (only for gecko) 
     57  if (navigator.appName == 'Microsoft Internet Explorer') { 
     58    if (this.editor.addEventListener) { 
     59      this.handle = document.createElement('div'); 
     60      this.handle.className = 'jstHandle'; 
     61      var dragStart = this.resizeDragStart; 
     62      var This = this; 
     63      this.handle.addEventListener('mousedown', function(event) { 
     64        dragStart.call(This, event); 
     65      }, false); 
     66      this.editor.parentNode.insertBefore(this.handle, this.editor.nextSibling); 
     67    } 
     68  } 
     69 
     70  this.context = null; 
     71  this.toolNodes = {}; // lorsque la toolbar est dessinée , cet objet est garni 
     72  // de raccourcis vers les éléments DOM correspondants aux outils. 
     73}; 
     74 
     75var jsButton = function(title, fn, scope, className, accesskey) { 
     76  this.title = title || null; 
     77  this.fn = fn || function() {}; 
     78  this.scope = scope || null; 
     79  this.className = className || null; 
     80  this.accesskey = accesskey || null; 
    7581}; 
    7682jsButton.prototype.draw = function() { 
    77      if (!this.scope) return null; 
    78  
    79      var button = document.createElement('button'); 
    80      button.setAttribute('type','button'); 
    81      if (this.className) button.className = this.className; 
    82      button.title = this.title; 
    83      if (this.accesskey) button.accessKey = this.accesskey; 
    84      var span = document.createElement('span'); 
    85      span.appendChild(document.createTextNode(this.title)); 
    86      button.appendChild(span); 
    87  
    88      if (this.icon != undefined) { 
    89           button.style.backgroundImage = 'url('+this.icon+')'; 
    90      } 
    91      if (typeof(this.fn) == 'function') { 
    92           var This = this; 
    93           button.onclick = function() { try { This.fn.apply(This.scope, arguments) } catch (e) {} return false; }; 
    94      } 
    95      return button; 
    96 }; 
    97  
    98 function jsSpace(id) { 
    99      this.id = id || null; 
    100      this.width = null; 
     83  if (!this.scope) return null; 
     84 
     85  var button = document.createElement('button'); 
     86  button.setAttribute('type', 'button'); 
     87  if (this.className) button.className = this.className; 
     88  button.title = this.title; 
     89  if (this.accesskey) button.accessKey = this.accesskey; 
     90  var span = document.createElement('span'); 
     91  span.appendChild(document.createTextNode(this.title)); 
     92  button.appendChild(span); 
     93 
     94  if (this.icon != undefined) { 
     95    button.style.backgroundImage = 'url(' + this.icon + ')'; 
     96  } 
     97  if (typeof(this.fn) == 'function') { 
     98    var This = this; 
     99    button.onclick = function() { 
     100      try { 
     101        This.fn.apply(This.scope, arguments); 
     102      } catch (e) {} 
     103      return false; 
     104    }; 
     105  } 
     106  return button; 
     107}; 
     108 
     109var jsSpace = function(id) { 
     110  this.id = id || null; 
     111  this.width = null; 
    101112}; 
    102113jsSpace.prototype.draw = function() { 
    103      var span = document.createElement('span'); 
    104      if (this.id) span.id = this.id; 
    105      span.appendChild(document.createTextNode(String.fromCharCode(160))); 
    106      span.className = 'jstSpacer'; 
    107      if (this.width) span.style.marginRight = this.width+'px'; 
    108  
    109      return span; 
    110 }; 
    111  
    112 function jsCombo(title, options, scope, fn, className) { 
    113      this.title = title || null; 
    114      this.options = options || null; 
    115      this.scope = scope || null; 
    116      this.fn = fn || function(){}; 
    117      this.className = className || null; 
     114  var span = document.createElement('span'); 
     115  if (this.id) span.id = this.id; 
     116  span.appendChild(document.createTextNode(String.fromCharCode(160))); 
     117  span.className = 'jstSpacer'; 
     118  if (this.width) span.style.marginRight = this.width + 'px'; 
     119 
     120  return span; 
     121}; 
     122 
     123var jsCombo = function(title, options, scope, fn, className) { 
     124  this.title = title || null; 
     125  this.options = options || null; 
     126  this.scope = scope || null; 
     127  this.fn = fn || function() {}; 
     128  this.className = className || null; 
    118129}; 
    119130jsCombo.prototype.draw = function() { 
    120      if (!this.scope || !this.options) return null; 
    121  
    122      var select = document.createElement('select'); 
    123      if (this.className) select.className = className; 
    124      select.title = this.title; 
    125  
    126      for (var o in this.options) { 
    127           //var opt = this.options[o]; 
    128           var option = document.createElement('option'); 
    129           option.value = o; 
    130           option.appendChild(document.createTextNode(this.options[o])); 
    131           select.appendChild(option); 
    132      } 
    133  
    134      var This = this; 
    135      select.onchange = function() { 
    136           try { 
    137                This.fn.call(This.scope, this.value); 
    138           } catch (e) { alert(e); } 
    139  
    140           return false; 
    141      }; 
    142  
    143      return select; 
    144 }; 
    145  
     131  if (!this.scope || !this.options) return null; 
     132 
     133  var select = document.createElement('select'); 
     134  if (this.className) select.className = this.className; 
     135  select.title = this.title; 
     136 
     137  for (var o in this.options) { 
     138    //var opt = this.options[o]; 
     139    var option = document.createElement('option'); 
     140    option.value = o; 
     141    option.appendChild(document.createTextNode(this.options[o])); 
     142    select.appendChild(option); 
     143  } 
     144 
     145  var This = this; 
     146  select.onchange = function() { 
     147    try { 
     148      This.fn.call(This.scope, this.value); 
     149    } catch (e) { 
     150      window.alert(e); 
     151    } 
     152 
     153    return false; 
     154  }; 
     155 
     156  return select; 
     157}; 
    146158 
    147159jsToolBar.prototype = { 
    148      base_url: '', 
    149      mode: 'xhtml', 
    150      elements: {}, 
    151      toolbar_bottom: false, 
    152  
    153      getMode: function() { 
    154           return this.mode; 
    155      }, 
    156  
    157      setMode: function(mode) { 
    158           this.mode = mode || 'xhtml'; 
    159      }, 
    160  
    161      switchMode: function(mode) { 
    162           mode = mode || 'xhtml'; 
    163           this.draw(mode); 
    164      }, 
    165  
    166      button: function(toolName) { 
    167           var tool = this.elements[toolName]; 
    168           if (typeof tool.fn[this.mode] != 'function') return null; 
    169           var b = new jsButton(tool.title, tool.fn[this.mode], this, 'jstb_'+toolName, tool.accesskey); 
    170           if (tool.icon != undefined) { 
    171                b.icon = tool.icon; 
    172           } 
    173           return b; 
    174      }, 
    175      space: function(toolName) { 
    176           var tool = new jsSpace(toolName); 
    177           if (this.elements[toolName].format != undefined && !this.elements[toolName].format[this.mode]) return null; 
    178           if (this.elements[toolName].width !== undefined) { 
    179                tool.width = this.elements[toolName].width; 
    180           } 
    181           return tool; 
    182      }, 
    183      combo: function(toolName) { 
    184           var tool = this.elements[toolName]; 
    185  
    186           if( tool[this.mode] != undefined) { 
    187  
    188                var length = tool[this.mode].list.length; 
    189  
    190                if (typeof tool[this.mode].fn != 'function' || length == 0) { 
    191                     return null; 
    192                } else { 
    193                     var options = {}; 
    194                     for (var i=0; i < length; i++) { 
    195                          var opt = tool[this.mode].list[i]; 
    196                          options[opt] = tool.options[opt]; 
    197                     } 
    198                     return new jsCombo(tool.title, options, this, tool[this.mode].fn); 
    199                } 
    200  
    201           } 
    202  
    203      }, 
    204      draw: function(mode) { 
    205           this.setMode(mode); 
    206  
    207           // Empty toolbar 
    208           while (this.toolbar.hasChildNodes()) { 
    209                this.toolbar.removeChild(this.toolbar.firstChild) 
    210           } 
    211           this.toolNodes = {}; // vide les raccourcis DOM/**/ 
    212  
    213           // Draw toolbar elements 
    214           var b, tool, newTool; 
    215  
    216           for (var i in this.elements) { 
    217                b = this.elements[i]; 
    218  
    219                var disabled = 
    220                b.type == undefined || b.type == '' 
    221                || (b.disabled != undefined && b.disabled) 
    222                || (b.context != undefined && b.context != null && b.context != this.context); 
    223  
    224                if (!disabled && typeof this[b.type] == 'function') { 
    225                     tool = this[b.type](i); 
    226                     if (tool) newTool = tool.draw(); 
    227                     if (newTool) { 
    228                          this.toolNodes[i] = newTool; //mémorise l'accès DOM pour usage éventuel ultérieur 
    229                          this.toolbar.appendChild(newTool); 
    230                     } 
    231                } 
    232           } 
    233      }, 
    234  
    235      singleTag: function(stag,etag) { 
    236           stag = stag || null; 
    237           etag = etag || stag; 
    238  
    239           if (!stag || !etag) { return; } 
    240  
    241           this.encloseSelection(stag,etag); 
    242      }, 
    243  
    244      encloseSelection: function(prefix, suffix, fn) { 
    245           this.textarea.focus(); 
    246  
    247           prefix = prefix || ''; 
    248           suffix = suffix || ''; 
    249  
    250           var start, end, sel, scrollPos, subst, res; 
    251  
    252           if (typeof(document["selection"]) != "undefined") { 
    253                sel = document.selection.createRange().text; 
    254           } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { 
    255                start = this.textarea.selectionStart; 
    256                end = this.textarea.selectionEnd; 
    257                scrollPos = this.textarea.scrollTop; 
    258                sel = this.textarea.value.substring(start, end); 
    259           } 
    260  
    261           if (sel.match(/ $/)) { // exclude ending space char, if any 
    262                sel = sel.substring(0, sel.length - 1); 
    263                suffix = suffix + " "; 
    264           } 
    265  
    266           if (typeof(fn) == 'function') { 
    267                res = (sel) ? fn.call(this,sel) : fn(''); 
    268           } else { 
    269                res = (sel) ? sel : ''; 
    270           } 
    271  
    272           subst = prefix + res + suffix; 
    273  
    274           if (typeof(document["selection"]) != "undefined") { 
    275                var range = document.selection.createRange().text = subst; 
    276                this.textarea.caretPos -= suffix.length; 
    277           } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { 
    278                this.textarea.value = this.textarea.value.substring(0, start) + subst + 
    279                this.textarea.value.substring(end); 
    280                if (sel) { 
    281                     this.textarea.setSelectionRange(start + subst.length, start + subst.length); 
    282                } else { 
    283                     if (typeof(fn) != 'function') { 
    284                          this.textarea.setSelectionRange(start + prefix.length, start + prefix.length); 
    285                     } 
    286                } 
    287                this.textarea.scrollTop = scrollPos; 
    288           } 
    289      }, 
    290  
    291      stripBaseURL: function(url) { 
    292           if (this.base_url != '') { 
    293                var pos = url.indexOf(this.base_url); 
    294                if (pos == 0) { 
    295                     url = url.substr(this.base_url.length); 
    296                } 
    297           } 
    298  
    299           return url; 
    300      } 
     160  base_url: '', 
     161  mode: 'xhtml', 
     162  elements: {}, 
     163  toolbar_bottom: false, 
     164 
     165  getMode: function() { 
     166    return this.mode; 
     167  }, 
     168 
     169  setMode: function(mode) { 
     170    this.mode = mode || 'xhtml'; 
     171  }, 
     172 
     173  switchMode: function(mode) { 
     174    mode = mode || 'xhtml'; 
     175    this.draw(mode); 
     176  }, 
     177 
     178  button: function(toolName) { 
     179    var tool = this.elements[toolName]; 
     180    if (typeof tool.fn[this.mode] != 'function') return null; 
     181    var b = new jsButton(tool.title, tool.fn[this.mode], this, 'jstb_' + toolName, tool.accesskey); 
     182    if (tool.icon != undefined) { 
     183      b.icon = tool.icon; 
     184    } 
     185    return b; 
     186  }, 
     187  space: function(toolName) { 
     188    var tool = new jsSpace(toolName); 
     189    if (this.elements[toolName].format != undefined && !this.elements[toolName].format[this.mode]) return null; 
     190    if (this.elements[toolName].width !== undefined) { 
     191      tool.width = this.elements[toolName].width; 
     192    } 
     193    return tool; 
     194  }, 
     195  combo: function(toolName) { 
     196    var tool = this.elements[toolName]; 
     197 
     198    if (tool[this.mode] != undefined) { 
     199 
     200      var length = tool[this.mode].list.length; 
     201 
     202      if (typeof tool[this.mode].fn != 'function' || length == 0) { 
     203        return null; 
     204      } else { 
     205        var options = {}; 
     206        for (var i = 0; i < length; i++) { 
     207          var opt = tool[this.mode].list[i]; 
     208          options[opt] = tool.options[opt]; 
     209        } 
     210        return new jsCombo(tool.title, options, this, tool[this.mode].fn); 
     211      } 
     212 
     213    } 
     214 
     215  }, 
     216  draw: function(mode) { 
     217    this.setMode(mode); 
     218 
     219    // Empty toolbar 
     220    while (this.toolbar.hasChildNodes()) { 
     221      this.toolbar.removeChild(this.toolbar.firstChild); 
     222    } 
     223    this.toolNodes = {}; // vide les raccourcis DOM/**/ 
     224 
     225    // Draw toolbar elements 
     226    var b, tool, newTool; 
     227 
     228    for (var i in this.elements) { 
     229      b = this.elements[i]; 
     230 
     231      var disabled = 
     232        b.type == undefined || b.type == '' || 
     233        (b.disabled != undefined && b.disabled) || 
     234        (b.context != undefined && b.context != null && b.context != this.context); 
     235 
     236      if (!disabled && typeof this[b.type] == 'function') { 
     237        tool = this[b.type](i); 
     238        if (tool) newTool = tool.draw(); 
     239        if (newTool) { 
     240          this.toolNodes[i] = newTool; //mémorise l'accès DOM pour usage éventuel ultérieur 
     241          this.toolbar.appendChild(newTool); 
     242        } 
     243      } 
     244    } 
     245  }, 
     246 
     247  singleTag: function(stag, etag) { 
     248    stag = stag || null; 
     249    etag = etag || stag; 
     250 
     251    if (!stag || !etag) { 
     252      return; 
     253    } 
     254 
     255    this.encloseSelection(stag, etag); 
     256  }, 
     257 
     258  encloseSelection: function(prefix, suffix, fn) { 
     259    this.textarea.focus(); 
     260 
     261    prefix = prefix || ''; 
     262    suffix = suffix || ''; 
     263 
     264    var start, end, sel, scrollPos, subst, res; 
     265 
     266    if (typeof(document.selection) != "undefined") { 
     267      sel = document.selection.createRange().text; 
     268    } else if (typeof(this.textarea.setSelectionRange) != "undefined") { 
     269      start = this.textarea.selectionStart; 
     270      end = this.textarea.selectionEnd; 
     271      scrollPos = this.textarea.scrollTop; 
     272      sel = this.textarea.value.substring(start, end); 
     273    } 
     274 
     275    if (sel.match(/ $/)) { // exclude ending space char, if any 
     276      sel = sel.substring(0, sel.length - 1); 
     277      suffix = suffix + " "; 
     278    } 
     279 
     280    if (typeof(fn) == 'function') { 
     281      res = (sel) ? fn.call(this, sel) : fn(''); 
     282    } else { 
     283      res = (sel) ? sel : ''; 
     284    } 
     285 
     286    subst = prefix + res + suffix; 
     287 
     288    if (typeof(document.selection) != "undefined") { 
     289      document.selection.createRange().text = subst; 
     290      this.textarea.caretPos -= suffix.length; 
     291    } else if (typeof(this.textarea.setSelectionRange) != "undefined") { 
     292      this.textarea.value = this.textarea.value.substring(0, start) + subst + 
     293        this.textarea.value.substring(end); 
     294      if (sel) { 
     295        this.textarea.setSelectionRange(start + subst.length, start + subst.length); 
     296      } else { 
     297        if (typeof(fn) != 'function') { 
     298          this.textarea.setSelectionRange(start + prefix.length, start + prefix.length); 
     299        } 
     300      } 
     301      this.textarea.scrollTop = scrollPos; 
     302    } 
     303  }, 
     304 
     305  stripBaseURL: function(url) { 
     306    if (this.base_url != '') { 
     307      var pos = url.indexOf(this.base_url); 
     308      if (pos == 0) { 
     309        url = url.substr(this.base_url.length); 
     310      } 
     311    } 
     312 
     313    return url; 
     314  } 
    301315}; 
    302316 
     
    304318-------------------------------------------------------- */ 
    305319jsToolBar.prototype.resizeSetStartH = function() { 
    306      this.dragStartH = this.textarea.offsetHeight + 0; 
     320  this.dragStartH = this.textarea.offsetHeight + 0; 
    307321}; 
    308322jsToolBar.prototype.resizeDragStart = function(event) { 
    309      var This = this; 
    310      this.dragStartY = event.clientY; 
    311      this.resizeSetStartH(); 
    312      document.addEventListener('mousemove', this.dragMoveHdlr=function(event){This.resizeDragMove(event);}, false); 
    313      document.addEventListener('mouseup', this.dragStopHdlr=function(event){This.resizeDragStop(event);}, false); 
     323  var This = this; 
     324  this.dragStartY = event.clientY; 
     325  this.resizeSetStartH(); 
     326  document.addEventListener('mousemove', this.dragMoveHdlr = function(event) { 
     327    This.resizeDragMove(event); 
     328  }, false); 
     329  document.addEventListener('mouseup', this.dragStopHdlr = function(event) { 
     330    This.resizeDragStop(event); 
     331  }, false); 
    314332}; 
    315333 
    316334jsToolBar.prototype.resizeDragMove = function(event) { 
    317      this.textarea.style.height = (this.dragStartH+event.clientY-this.dragStartY)+'px'; 
    318 }; 
    319  
    320 jsToolBar.prototype.resizeDragStop = function(event) { 
    321      document.removeEventListener('mousemove', this.dragMoveHdlr, false); 
    322      document.removeEventListener('mouseup', this.dragStopHdlr, false); 
     335  this.textarea.style.height = (this.dragStartH + event.clientY - this.dragStartY) + 'px'; 
     336}; 
     337 
     338jsToolBar.prototype.resizeDragStop = function() { 
     339  document.removeEventListener('mousemove', this.dragMoveHdlr, false); 
     340  document.removeEventListener('mouseup', this.dragStopHdlr, false); 
    323341}; 
    324342 
     
    326344// block format (paragraph, headers) 
    327345jsToolBar.prototype.elements.blocks = { 
    328      type: 'combo', 
    329      title: 'block format', 
    330      options: { 
    331           none: '-- none --', // only for wysiwyg mode 
    332           nonebis: '- block format -', // only for xhtml mode 
    333           p: 'Paragraph', 
    334           h1: 'Header 1', 
    335           h2: 'Header 2', 
    336           h3: 'Header 3', 
    337           h4: 'Header 4', 
    338           h5: 'Header 5', 
    339           h6: 'Header 6' 
    340      }, 
    341      xhtml: { 
    342           list: ['nonebis','p','h1','h2','h3','h4','h5','h6'], 
    343           fn: function(opt) { 
    344                if (opt=='nonebis') 
    345                     this.textarea.focus(); 
    346                else 
    347                     try {this.singleTag('<'+opt+'>','</'+opt+'>');} catch(e){}; 
    348                this.toolNodes.blocks.value = 'nonebis'; 
    349           } 
    350      }, 
    351      wiki: { 
    352           list: ['nonebis','h3','h4','h5'], 
    353           fn: function(opt) { 
    354                switch (opt) { 
    355                     case 'nonebis': this.textarea.focus(); break; 
    356                     case 'h3': this.encloseSelection('!!!'); break; 
    357                     case 'h4': this.encloseSelection('!!'); break; 
    358                     case 'h5': this.encloseSelection('!'); break; 
    359                } 
    360                this.toolNodes.blocks.value = 'nonebis'; 
    361           } 
    362      } 
     346  type: 'combo', 
     347  title: 'block format', 
     348  options: { 
     349    none: '-- none --', // only for wysiwyg mode 
     350    nonebis: '- block format -', // only for xhtml mode 
     351    p: 'Paragraph', 
     352    h1: 'Header 1', 
     353    h2: 'Header 2', 
     354    h3: 'Header 3', 
     355    h4: 'Header 4', 
     356    h5: 'Header 5', 
     357    h6: 'Header 6' 
     358  }, 
     359  xhtml: { 
     360    list: ['nonebis', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'], 
     361    fn: function(opt) { 
     362      if (opt == 'nonebis') 
     363        this.textarea.focus(); 
     364      else 
     365        try { 
     366          this.singleTag('<' + opt + '>', '</' + opt + '>'); 
     367        } catch (e) {} 
     368      this.toolNodes.blocks.value = 'nonebis'; 
     369    } 
     370  }, 
     371  wiki: { 
     372    list: ['nonebis', 'h3', 'h4', 'h5'], 
     373    fn: function(opt) { 
     374      switch (opt) { 
     375        case 'nonebis': 
     376          this.textarea.focus(); 
     377          break; 
     378        case 'h3': 
     379          this.encloseSelection('!!!'); 
     380          break; 
     381        case 'h4': 
     382          this.encloseSelection('!!'); 
     383          break; 
     384        case 'h5': 
     385          this.encloseSelection('!'); 
     386          break; 
     387      } 
     388      this.toolNodes.blocks.value = 'nonebis'; 
     389    } 
     390  } 
    363391}; 
    364392 
    365393// spacer 
    366394jsToolBar.prototype.elements.space0 = { 
    367      type:'space', 
    368      format:{ 
    369           wysiwyg:true, 
    370           wiki:true, 
    371           xhtml:true 
    372      } 
     395  type: 'space', 
     396  format: { 
     397    wysiwyg: true, 
     398    wiki: true, 
     399    xhtml: true 
     400  } 
    373401}; 
    374402 
    375403// strong 
    376404jsToolBar.prototype.elements.strong = { 
    377      type: 'button', 
    378      title: 'Strong emphasis', 
    379      fn: { 
    380           wiki: function() { this.singleTag('__') }, 
    381           xhtml: function() { this.singleTag('<strong>','</strong>') } 
    382      } 
     405  type: 'button', 
     406  title: 'Strong emphasis', 
     407  fn: { 
     408    wiki: function() { 
     409      this.singleTag('__'); 
     410    }, 
     411    xhtml: function() { 
     412      this.singleTag('<strong>', '</strong>'); 
     413    } 
     414  } 
    383415}; 
    384416 
    385417// em 
    386418jsToolBar.prototype.elements.em = { 
    387      type: 'button', 
    388      title: 'Emphasis', 
    389      fn: { 
    390           wiki: function() { this.singleTag("''") }, 
    391           xhtml: function() { this.singleTag('<em>','</em>') } 
    392      } 
     419  type: 'button', 
     420  title: 'Emphasis', 
     421  fn: { 
     422    wiki: function() { 
     423      this.singleTag("''"); 
     424    }, 
     425    xhtml: function() { 
     426      this.singleTag('<em>', '</em>'); 
     427    } 
     428  } 
    393429}; 
    394430 
    395431// ins 
    396432jsToolBar.prototype.elements.ins = { 
    397      type: 'button', 
    398      title: 'Inserted', 
    399      fn: { 
    400           wiki: function() { this.singleTag('++') }, 
    401           xhtml: function() { this.singleTag('<ins>','</ins>') } 
    402      } 
     433  type: 'button', 
     434  title: 'Inserted', 
     435  fn: { 
     436    wiki: function() { 
     437      this.singleTag('++'); 
     438    }, 
     439    xhtml: function() { 
     440      this.singleTag('<ins>', '</ins>'); 
     441    } 
     442  } 
    403443}; 
    404444 
    405445// del 
    406446jsToolBar.prototype.elements.del = { 
    407      type: 'button', 
    408      title: 'Deleted', 
    409      fn: { 
    410           wiki: function() { this.singleTag('--') }, 
    411           xhtml: function() { this.singleTag('<del>','</del>') } 
    412      } 
     447  type: 'button', 
     448  title: 'Deleted', 
     449  fn: { 
     450    wiki: function() { 
     451      this.singleTag('--'); 
     452    }, 
     453    xhtml: function() { 
     454      this.singleTag('<del>', '</del>'); 
     455    } 
     456  } 
    413457}; 
    414458 
    415459// quote 
    416460jsToolBar.prototype.elements.quote = { 
    417      type: 'button', 
    418      title: 'Inline quote', 
    419      fn: { 
    420           wiki: function() { this.singleTag('{{','}}') }, 
    421           xhtml: function() { this.singleTag('<q>','</q>') } 
    422      } 
     461  type: 'button', 
     462  title: 'Inline quote', 
     463  fn: { 
     464    wiki: function() { 
     465      this.singleTag('{{', '}}'); 
     466    }, 
     467    xhtml: function() { 
     468      this.singleTag('<q>', '</q>'); 
     469    } 
     470  } 
    423471}; 
    424472 
    425473// code 
    426474jsToolBar.prototype.elements.code = { 
    427      type: 'button', 
    428      title: 'Code', 
    429      fn: { 
    430           wiki: function() { this.singleTag('@@') }, 
    431           xhtml: function() { this.singleTag('<code>','</code>')} 
    432      } 
     475  type: 'button', 
     476  title: 'Code', 
     477  fn: { 
     478    wiki: function() { 
     479      this.singleTag('@@'); 
     480    }, 
     481    xhtml: function() { 
     482      this.singleTag('<code>', '</code>'); 
     483    } 
     484  } 
    433485}; 
    434486 
    435487// code 
    436488jsToolBar.prototype.elements.mark = { 
    437      type: 'button', 
    438      title: 'Mark', 
    439      fn: { 
    440           wiki: function() { this.singleTag('""') }, 
    441           xhtml: function() { this.singleTag('<mark>','</mark>')} 
    442      } 
     489  type: 'button', 
     490  title: 'Mark', 
     491  fn: { 
     492    wiki: function() { 
     493      this.singleTag('""'); 
     494    }, 
     495    xhtml: function() { 
     496      this.singleTag('<mark>', '</mark>'); 
     497    } 
     498  } 
    443499}; 
    444500 
    445501// spacer 
    446502jsToolBar.prototype.elements.space1 = { 
    447      type:'space', 
    448      format:{ 
    449           wysiwyg:true, 
    450           wiki:true, 
    451           xhtml:true 
    452      } 
     503  type: 'space', 
     504  format: { 
     505    wysiwyg: true, 
     506    wiki: true, 
     507    xhtml: true 
     508  } 
    453509}; 
    454510 
    455511// br 
    456512jsToolBar.prototype.elements.br = { 
    457      type: 'button', 
    458      title: 'Line break', 
    459      fn: { 
    460           wiki: function() { this.encloseSelection("%%%\n",'') }, 
    461           xhtml: function() { this.encloseSelection("<br />\n",'')} 
    462      } 
     513  type: 'button', 
     514  title: 'Line break', 
     515  fn: { 
     516    wiki: function() { 
     517      this.encloseSelection("%%%\n", ''); 
     518    }, 
     519    xhtml: function() { 
     520      this.encloseSelection("<br />\n", ''); 
     521    } 
     522  } 
    463523}; 
    464524 
    465525// spacer 
    466526jsToolBar.prototype.elements.space2 = { 
    467      type:'space', 
    468      format:{ 
    469           wysiwyg:true, 
    470           wiki:true, 
    471           xhtml:true 
    472      } 
     527  type: 'space', 
     528  format: { 
     529    wysiwyg: true, 
     530    wiki: true, 
     531    xhtml: true 
     532  } 
    473533}; 
    474534 
    475535// blockquote 
    476536jsToolBar.prototype.elements.blockquote = { 
    477      type: 'button', 
    478      title: 'Blockquote', 
    479      fn: { 
    480           xhtml: function() { this.singleTag('<blockquote>','</blockquote>') }, 
    481           wiki: function() { 
    482                this.encloseSelection("\n",'', 
    483                function(str) { 
    484                     str = str.replace(/\r/g,''); 
    485                     return '> '+str.replace(/\n/g,"\n> "); 
    486                }); 
    487           } 
    488      } 
     537  type: 'button', 
     538  title: 'Blockquote', 
     539  fn: { 
     540    xhtml: function() { 
     541      this.singleTag('<blockquote>', '</blockquote>'); 
     542    }, 
     543    wiki: function() { 
     544      this.encloseSelection("\n", '', 
     545        function(str) { 
     546          str = str.replace(/\r/g, ''); 
     547          return '> ' + str.replace(/\n/g, "\n> "); 
     548        }); 
     549    } 
     550  } 
    489551}; 
    490552 
    491553// pre 
    492554jsToolBar.prototype.elements.pre = { 
    493      type: 'button', 
    494      title: 'Preformated text', 
    495      fn: { 
    496           wiki: function() { this.singleTag("///\n","\n///") }, 
    497           xhtml: function() { this.singleTag('<pre>','</pre>') } 
    498      } 
     555  type: 'button', 
     556  title: 'Preformated text', 
     557  fn: { 
     558    wiki: function() { 
     559      this.singleTag("///\n", "\n///"); 
     560    }, 
     561    xhtml: function() { 
     562      this.singleTag('<pre>', '</pre>'); 
     563    } 
     564  } 
    499565}; 
    500566 
    501567// ul 
    502568jsToolBar.prototype.elements.ul = { 
    503      type: 'button', 
    504      title: 'Unordered list', 
    505      fn: { 
    506           wiki: function() { 
    507                this.encloseSelection('','',function(str) { 
    508                     str = str.replace(/\r/g,''); 
    509                     return '* '+str.replace(/\n/g,"\n* "); 
    510                }); 
    511           }, 
    512           xhtml: function() { 
    513                this.encloseSelection('','',function(str) { 
    514                     str = str.replace(/\r/g,''); 
    515                     str = str.replace(/\n/g,"</li>\n <li>"); 
    516                     return "<ul>\n <li>"+str+"</li>\n</ul>"; 
    517                }); 
    518           } 
    519      } 
     569  type: 'button', 
     570  title: 'Unordered list', 
     571  fn: { 
     572    wiki: function() { 
     573      this.encloseSelection('', '', function(str) { 
     574        str = str.replace(/\r/g, ''); 
     575        return '* ' + str.replace(/\n/g, "\n* "); 
     576      }); 
     577    }, 
     578    xhtml: function() { 
     579      this.encloseSelection('', '', function(str) { 
     580        str = str.replace(/\r/g, ''); 
     581        str = str.replace(/\n/g, "</li>\n <li>"); 
     582        return "<ul>\n <li>" + str + "</li>\n</ul>"; 
     583      }); 
     584    } 
     585  } 
    520586}; 
    521587 
    522588// ol 
    523589jsToolBar.prototype.elements.ol = { 
    524      type: 'button', 
    525      title: 'Ordered list', 
    526      fn: { 
    527           wiki: function() { 
    528                this.encloseSelection('','',function(str) { 
    529                     str = str.replace(/\r/g,''); 
    530                     return '# '+str.replace(/\n/g,"\n# "); 
    531                }); 
    532           }, 
    533           xhtml: function() { 
    534                this.encloseSelection('','',function(str) { 
    535                     str = str.replace(/\r/g,''); 
    536                     str = str.replace(/\n/g,"</li>\n <li>"); 
    537                     return "<ol>\n <li>"+str+"</li>\n</ol>"; 
    538                }); 
    539           } 
    540      } 
     590  type: 'button', 
     591  title: 'Ordered list', 
     592  fn: { 
     593    wiki: function() { 
     594      this.encloseSelection('', '', function(str) { 
     595        str = str.replace(/\r/g, ''); 
     596        return '# ' + str.replace(/\n/g, "\n# "); 
     597      }); 
     598    }, 
     599    xhtml: function() { 
     600      this.encloseSelection('', '', function(str) { 
     601        str = str.replace(/\r/g, ''); 
     602        str = str.replace(/\n/g, "</li>\n <li>"); 
     603        return "<ol>\n <li>" + str + "</li>\n</ol>"; 
     604      }); 
     605    } 
     606  } 
    541607}; 
    542608 
    543609// spacer 
    544610jsToolBar.prototype.elements.space3 = { 
    545      type:'space', 
    546      format:{ 
    547           wysiwyg:true, 
    548           wiki:true, 
    549           xhtml:true 
    550      } 
     611  type: 'space', 
     612  format: { 
     613    wysiwyg: true, 
     614    wiki: true, 
     615    xhtml: true 
     616  } 
    551617}; 
    552618 
    553619// link 
    554620jsToolBar.prototype.elements.link = { 
    555      type: 'button', 
    556      title: 'Link', 
    557      fn: {}, 
    558      accesskey: 'l', 
    559      href_prompt: 'Please give page URL:', 
    560      hreflang_prompt: 'Language of this page:', 
    561      default_hreflang: '', 
    562      prompt: function(href,hreflang) { 
    563           href = href || ''; 
    564           hreflang = hreflang || this.elements.link.default_hreflang; 
    565  
    566           href = window.prompt(this.elements.link.href_prompt,href); 
    567           if (!href) { return false; } 
    568  
    569           hreflang = window.prompt(this.elements.link.hreflang_prompt, 
    570           hreflang); 
    571  
    572           return { href: this.stripBaseURL(href), hreflang: hreflang }; 
    573      } 
     621  type: 'button', 
     622  title: 'Link', 
     623  fn: {}, 
     624  accesskey: 'l', 
     625  href_prompt: 'Please give page URL:', 
     626  hreflang_prompt: 'Language of this page:', 
     627  default_hreflang: '', 
     628  prompt: function(href, hreflang) { 
     629    href = href || ''; 
     630    hreflang = hreflang || this.elements.link.default_hreflang; 
     631 
     632    href = window.prompt(this.elements.link.href_prompt, href); 
     633    if (!href) { 
     634      return false; 
     635    } 
     636 
     637    hreflang = window.prompt(this.elements.link.hreflang_prompt, 
     638      hreflang); 
     639 
     640    return { 
     641      href: this.stripBaseURL(href), 
     642      hreflang: hreflang 
     643    }; 
     644  } 
    574645}; 
    575646 
    576647jsToolBar.prototype.elements.link.fn.xhtml = function() { 
    577      var link = this.elements.link.prompt.call(this); 
    578      if (link) { 
    579           var stag = '<a href="'+link.href+'"'; 
    580           if (link.hreflang) { stag = stag+' hreflang="'+link.hreflang+'"'; } 
    581           stag = stag+'>'; 
    582           var etag = '</a>'; 
    583  
    584           this.encloseSelection(stag,etag); 
    585      } 
     648  var link = this.elements.link.prompt.call(this); 
     649  if (link) { 
     650    var stag = '<a href="' + link.href + '"'; 
     651    if (link.hreflang) { 
     652      stag = stag + ' hreflang="' + link.hreflang + '"'; 
     653    } 
     654    stag = stag + '>'; 
     655    var etag = '</a>'; 
     656 
     657    this.encloseSelection(stag, etag); 
     658  } 
    586659}; 
    587660jsToolBar.prototype.elements.link.fn.wiki = function() { 
    588      var link = this.elements.link.prompt.call(this); 
    589      if (link) { 
    590           var stag = '['; 
    591           var etag = '|'+link.href; 
    592           if (link.hreflang) { etag = etag+'|'+link.hreflang; } 
    593           etag = etag+']'; 
    594  
    595           this.encloseSelection(stag,etag); 
    596      } 
     661  var link = this.elements.link.prompt.call(this); 
     662  if (link) { 
     663    var stag = '['; 
     664    var etag = '|' + link.href; 
     665    if (link.hreflang) { 
     666      etag = etag + '|' + link.hreflang; 
     667    } 
     668    etag = etag + ']'; 
     669 
     670    this.encloseSelection(stag, etag); 
     671  } 
    597672}; 
    598673 
    599674// img 
    600675jsToolBar.prototype.elements.img = { 
    601           type: 'button', 
    602           title: 'External image', 
    603           src_prompt: 'Please give image URL:', 
    604           fn: {}, 
    605           prompt: function(src) { 
    606                src = src || ''; 
    607                return this.stripBaseURL(window.prompt(this.elements.img.src_prompt,src)); 
    608           } 
     676  type: 'button', 
     677  title: 'External image', 
     678  src_prompt: 'Please give image URL:', 
     679  fn: {}, 
     680  prompt: function(src) { 
     681    src = src || ''; 
     682    return this.stripBaseURL(window.prompt(this.elements.img.src_prompt, src)); 
     683  } 
    609684}; 
    610685jsToolBar.prototype.elements.img.fn.xhtml = function() { 
    611      var src = this.elements.img.prompt.call(this); 
    612      if (src) { 
    613           this.encloseSelection('','',function(str) { 
    614                if (str) { 
    615                     return '<img src="'+src+'" alt="'+str+'" />'; 
    616                } else { 
    617                     return '<img src="'+src+'" alt="" />'; 
    618                } 
    619           }); 
    620      } 
     686  var src = this.elements.img.prompt.call(this); 
     687  if (src) { 
     688    this.encloseSelection('', '', function(str) { 
     689      if (str) { 
     690        return '<img src="' + src + '" alt="' + str + '" />'; 
     691      } else { 
     692        return '<img src="' + src + '" alt="" />'; 
     693      } 
     694    }); 
     695  } 
    621696}; 
    622697jsToolBar.prototype.elements.img.fn.wiki = function() { 
    623      var src = this.elements.img.prompt.call(this); 
    624      if (src) { 
    625           this.encloseSelection('','',function(str) { 
    626                if (str) { 
    627                     return '(('+src+'|'+str+'))'; 
    628                } else { 
    629                     return '(('+src+'))'; 
    630                } 
    631           }); 
    632      } 
    633 }; 
     698  var src = this.elements.img.prompt.call(this); 
     699  if (src) { 
     700    this.encloseSelection('', '', function(str) { 
     701      if (str) { 
     702        return '((' + src + '|' + str + '))'; 
     703      } else { 
     704        return '((' + src + '))'; 
     705      } 
     706    }); 
     707  } 
     708}; 
  • plugins/dcLegacyEditor/js/jsToolBar/jsToolBar.wysiwyg.js

    r3669 r3735  
     1/*global jsToolBar, dotclear_htmlFontSize, chainHandler */ 
     2'use strict'; 
     3 
    14/* ***** BEGIN LICENSE BLOCK ***** 
    25 * This file is part of DotClear. 
     
    1922 * 
    2023 * ***** END LICENSE BLOCK ***** 
    21 */ 
     24 */ 
    2225 
    2326jsToolBar.prototype.can_wwg = (document.designMode != undefined); 
     
    3134jsToolBar.prototype.drawToolBar = jsToolBar.prototype.draw; 
    3235jsToolBar.prototype.draw = function(mode) { 
    33      mode = mode || 'xhtml'; 
    34  
    35      if (this.can_wwg) { 
    36           this.mode = 'wysiwyg'; 
    37           this.drawToolBar('wysiwyg'); 
    38           this.initWindow(); 
    39      } else { 
    40           this.drawToolBar(mode); 
    41      } 
     36  mode = mode || 'xhtml'; 
     37 
     38  if (this.can_wwg) { 
     39    this.mode = 'wysiwyg'; 
     40    this.drawToolBar('wysiwyg'); 
     41    this.initWindow(); 
     42  } else { 
     43    this.drawToolBar(mode); 
     44  } 
    4245}; 
    4346 
    4447jsToolBar.prototype.switchMode = function(mode) { 
    45      mode = mode || 'xhtml'; 
    46  
    47      if (mode == 'xhtml') { 
    48           this.wwg_mode = true; 
    49           this.draw(mode); 
    50      } else { 
    51           if (this.wwg_mode) { 
    52                this.syncContents('iframe'); 
    53           } 
    54           this.wwg_mode = false; 
    55           this.removeEditor(); 
    56           this.textarea.style.display = ''; 
    57           this.drawToolBar(mode); 
    58      } 
     48  mode = mode || 'xhtml'; 
     49 
     50  if (mode == 'xhtml') { 
     51    this.wwg_mode = true; 
     52    this.draw(mode); 
     53  } else { 
     54    if (this.wwg_mode) { 
     55      this.syncContents('iframe'); 
     56    } 
     57    this.wwg_mode = false; 
     58    this.removeEditor(); 
     59    this.textarea.style.display = ''; 
     60    this.drawToolBar(mode); 
     61  } 
    5962}; 
    6063 
    6164jsToolBar.prototype.syncContents = function(from) { 
    62      from = from || 'textarea'; 
    63      var This = this; 
    64      if (from == 'textarea') { 
    65           initContent(); 
    66      } else { 
    67           this.validBlockquote(); 
    68           var html = this.applyHtmlFilters(this.ibody.innerHTML); 
    69           if (html == '<br />') { html = '<p></p>'; } 
    70           this.textarea.value = html; 
    71      } 
    72  
    73      function initContent() { 
    74           if (!This.iframe.contentWindow.document || !This.iframe.contentWindow.document.body) { 
    75                setTimeout(initContent, 1); 
    76                return; 
    77           } 
    78           This.ibody = This.iframe.contentWindow.document.body; 
    79  
    80           if (This.textarea.value != '' && This.textarea.value != '<p></p>') { 
    81                This.ibody.innerHTML = This.applyWysiwygFilters(This.textarea.value); 
    82                if (This.ibody.createTextRange) { //cursor at the begin for IE 
    83                     var IErange = This.ibody.createTextRange(); 
    84                     IErange.execCommand("SelectAll"); 
    85                     IErange.collapse(); 
    86                     IErange.select(); 
    87                } 
    88           } else { 
    89                var idoc = This.iwin.document; 
    90                var para = idoc.createElement('p'); 
    91                para.appendChild(idoc.createElement('br')); 
    92                while (idoc.body.hasChildNodes()) { 
    93                     idoc.body.removeChild(idoc.body.lastChild); 
    94                } 
    95                idoc.body.appendChild(para); 
    96           } 
    97      } 
     65  from = from || 'textarea'; 
     66  var This = this; 
     67  if (from == 'textarea') { 
     68    initContent(); 
     69  } else { 
     70    this.validBlockquote(); 
     71    var html = this.applyHtmlFilters(this.ibody.innerHTML); 
     72    if (html == '<br />') { 
     73      html = '<p></p>'; 
     74    } 
     75    this.textarea.value = html; 
     76  } 
     77 
     78  function initContent() { 
     79    if (!This.iframe.contentWindow.document || !This.iframe.contentWindow.document.body) { 
     80      setTimeout(initContent, 1); 
     81      return; 
     82    } 
     83    This.ibody = This.iframe.contentWindow.document.body; 
     84 
     85    if (This.textarea.value != '' && This.textarea.value != '<p></p>') { 
     86      This.ibody.innerHTML = This.applyWysiwygFilters(This.textarea.value); 
     87      if (This.ibody.createTextRange) { //cursor at the begin for IE 
     88        var IErange = This.ibody.createTextRange(); 
     89        IErange.execCommand("SelectAll"); 
     90        IErange.collapse(); 
     91        IErange.select(); 
     92      } 
     93    } else { 
     94      var idoc = This.iwin.document; 
     95      var para = idoc.createElement('p'); 
     96      para.appendChild(idoc.createElement('br')); 
     97      while (idoc.body.hasChildNodes()) { 
     98        idoc.body.removeChild(idoc.body.lastChild); 
     99      } 
     100      idoc.body.appendChild(para); 
     101    } 
     102  } 
    98103}; 
    99104jsToolBar.prototype.htmlFilters = { 
    100      tagsoup: function(str){ 
    101           return this.tagsoup2xhtml(str); 
    102      } 
     105  tagsoup: function(str) { 
     106    return this.tagsoup2xhtml(str); 
     107  } 
    103108}; 
    104109jsToolBar.prototype.applyHtmlFilters = function(str) { 
    105      for (var fn in this.htmlFilters) { 
    106           str = this.htmlFilters[fn].call(this, str); 
    107      } 
    108      return str; 
     110  for (var fn in this.htmlFilters) { 
     111    str = this.htmlFilters[fn].call(this, str); 
     112  } 
     113  return str; 
    109114}; 
    110115jsToolBar.prototype.wysiwygFilters = {}; 
    111 jsToolBar.prototype.applyWysiwygFilters = function( str) { 
    112      for (var fn in this.wysiwygFilters) { 
    113           str = this.wysiwygFilters[fn].call(this, str); 
    114      } 
    115      return str; 
     116jsToolBar.prototype.applyWysiwygFilters = function(str) { 
     117  for (var fn in this.wysiwygFilters) { 
     118    str = this.wysiwygFilters[fn].call(this, str); 
     119  } 
     120  return str; 
    116121}; 
    117122 
    118123jsToolBar.prototype.switchEdit = function() { 
    119      if (this.wwg_mode) { 
    120           this.textarea.style.display = ''; 
    121           this.iframe.style.display = 'none'; 
    122           this.syncContents('iframe'); 
    123           this.drawToolBar('xhtml'); 
    124           this.wwg_mode = false; 
    125           this.focusEditor(); 
    126      } else { 
    127           this.iframe.style.display = ''; 
    128           this.textarea.style.display = 'none'; 
    129           this.syncContents('textarea'); 
    130           this.drawToolBar('wysiwyg'); 
    131           this.wwg_mode = true; 
    132           this.focusEditor(); 
    133      } 
    134      this.setSwitcher(); 
     124  if (this.wwg_mode) { 
     125    this.textarea.style.display = ''; 
     126    this.iframe.style.display = 'none'; 
     127    this.syncContents('iframe'); 
     128    this.drawToolBar('xhtml'); 
     129    this.wwg_mode = false; 
     130    this.focusEditor(); 
     131  } else { 
     132    this.iframe.style.display = ''; 
     133    this.textarea.style.display = 'none'; 
     134    this.syncContents('textarea'); 
     135    this.drawToolBar('wysiwyg'); 
     136    this.wwg_mode = true; 
     137    this.focusEditor(); 
     138  } 
     139  this.setSwitcher(); 
    135140}; 
    136141 
    137142/** Creates iframe for editor, inits a blank document 
    138 */ 
     143 */ 
    139144jsToolBar.prototype.initWindow = function() { 
    140      var This = this; 
    141  
    142      this.iframe = document.createElement('iframe'); 
    143      this.textarea.parentNode.insertBefore(this.iframe,this.textarea.nextSibling); 
    144  
    145      this.switcher = document.createElement('ul'); 
    146      this.switcher.className = 'jstSwitcher'; 
    147      this.editor.appendChild(this.switcher); 
    148  
    149      this.iframe.height = this.textarea.offsetHeight + 0; 
    150      this.iframe.width = this.textarea.offsetWidth + 0; 
    151  
    152      if (this.textarea.tabIndex != undefined) { 
    153           this.iframe.tabIndex = this.textarea.tabIndex; 
    154      } 
    155  
    156      function initIframe() { 
    157           var doc = This.iframe.contentWindow.document; 
    158           if (!doc) { 
    159                setTimeout(initIframe,1); 
    160                return false; 
    161           } 
    162  
    163           doc.open(); 
    164           var html = 
    165           '<html>\n'+ 
    166           '<head>\n'+ 
    167           '<link rel="stylesheet" href="style/default.css" type="text/css" media="screen" />' 
    168           '<style type="text/css">'+This.iframe_css+'</style>\n'+ 
    169           (This.base_url != '' ? '<base href="'+This.base_url+'" />' : '')+ 
    170           '</head>\n'+ 
    171           '<body>\n'+ 
    172           '</body>\n'+ 
    173           '</html>'; 
    174  
    175           doc.write(html); 
    176           doc.close(); 
    177           if (document.all) { // for IE 
    178                doc.designMode = 'on'; 
    179                // warning : doc is now inaccessible for IE6 sp1 
    180           } 
    181  
    182           if (typeof dotclear_htmlFontSize !== 'undefined') { 
    183                doc.documentElement.style.setProperty('--html-font-size',dotclear_htmlFontSize); 
    184           } 
    185  
    186           This.iwin = This.iframe.contentWindow; 
    187  
    188           This.syncContents('textarea'); 
    189  
    190           if (This.wwg_mode == undefined) { 
    191                This.wwg_mode = true; 
    192           } 
    193  
    194           if (This.wwg_mode) { 
    195                This.textarea.style.display = 'none'; 
    196           } else { 
    197                This.iframe.style.display = 'none'; 
    198           } 
    199  
    200           // update textarea on submit 
    201           if (This.textarea.form) { 
    202                chainHandler(This.textarea.form,'onsubmit', function() { 
    203                     if (This.wwg_mode) { 
    204                          This.syncContents('iframe'); 
    205                     } 
    206                }); 
    207           } 
    208  
    209           for (var evt in This.iwinEvents) { 
    210                var event = This.iwinEvents[evt]; 
    211                This.addIwinEvent(This.iframe.contentWindow.document, event.type, event.fn, This); 
    212           } 
    213  
    214           This.setSwitcher(); 
    215           try { This.iwin.document.designMode = 'on'; } catch (e) {}; // Firefox needs this 
    216  
    217           return true; 
    218      } 
    219      initIframe(); 
     145  var This = this; 
     146 
     147  this.iframe = document.createElement('iframe'); 
     148  this.textarea.parentNode.insertBefore(this.iframe, this.textarea.nextSibling); 
     149 
     150  this.switcher = document.createElement('ul'); 
     151  this.switcher.className = 'jstSwitcher'; 
     152  this.editor.appendChild(this.switcher); 
     153 
     154  this.iframe.height = this.textarea.offsetHeight + 0; 
     155  this.iframe.width = this.textarea.offsetWidth + 0; 
     156 
     157  if (this.textarea.tabIndex != undefined) { 
     158    this.iframe.tabIndex = this.textarea.tabIndex; 
     159  } 
     160 
     161  function initIframe() { 
     162    var doc = This.iframe.contentWindow.document; 
     163    if (!doc) { 
     164      setTimeout(initIframe, 1); 
     165      return false; 
     166    } 
     167 
     168    doc.open(); 
     169    var html = 
     170      '<html>\n' + 
     171      '<head>\n' + 
     172      '<link rel="stylesheet" href="style/default.css" type="text/css" media="screen" />' + 
     173      '<style type="text/css">' + This.iframe_css + '</style>\n' + 
     174      (This.base_url != '' ? '<base href="' + This.base_url + '" />' : '') + 
     175      '</head>\n' + 
     176      '<body>\n' + 
     177      '</body>\n' + 
     178      '</html>'; 
     179 
     180    doc.write(html); 
     181    doc.close(); 
     182    if (document.all) { // for IE 
     183      doc.designMode = 'on'; 
     184      // warning : doc is now inaccessible for IE6 sp1 
     185    } 
     186 
     187    if (typeof dotclear_htmlFontSize !== 'undefined') { 
     188      doc.documentElement.style.setProperty('--html-font-size', dotclear_htmlFontSize); 
     189    } 
     190 
     191    This.iwin = This.iframe.contentWindow; 
     192 
     193    This.syncContents('textarea'); 
     194 
     195    if (This.wwg_mode == undefined) { 
     196      This.wwg_mode = true; 
     197    } 
     198 
     199    if (This.wwg_mode) { 
     200      This.textarea.style.display = 'none'; 
     201    } else { 
     202      This.iframe.style.display = 'none'; 
     203    } 
     204 
     205    // update textarea on submit 
     206    if (This.textarea.form) { 
     207      chainHandler(This.textarea.form, 'onsubmit', function() { 
     208        if (This.wwg_mode) { 
     209          This.syncContents('iframe'); 
     210        } 
     211      }); 
     212    } 
     213 
     214    for (var evt in This.iwinEvents) { 
     215      var event = This.iwinEvents[evt]; 
     216      This.addIwinEvent(This.iframe.contentWindow.document, event.type, event.fn, This); 
     217    } 
     218 
     219    This.setSwitcher(); 
     220    try { 
     221      This.iwin.document.designMode = 'on'; 
     222    } catch (e) {} // Firefox needs this 
     223 
     224    return true; 
     225  } 
     226  initIframe(); 
    220227}; 
    221228jsToolBar.prototype.addIwinEvent = function(target, type, fn, scope) { 
    222      var myFn = function(e){fn.call(scope, e)}; 
    223      addEvent(target, type, myFn, true); 
    224      // fix memory leak 
    225      addEvent(scope.iwin, 'unload', function(){ 
    226           removeEvent(target, type, myFn, true); 
    227      }, true); 
     229  var myFn = function(e) { 
     230    fn.call(scope, e); 
     231  }; 
     232  addEvent(target, type, myFn, true); 
     233  // fix memory leak 
     234  addEvent(scope.iwin, 'unload', function() { 
     235    removeEvent(target, type, myFn, true); 
     236  }, true); 
    228237}; 
    229238jsToolBar.prototype.iwinEvents = { 
    230      block1: { 
    231           type: 'mouseup', 
    232           fn: function(){ this.adjustBlockLevelCombo() } 
    233      }, 
    234      block2: { 
    235           type: 'keyup', 
    236           fn: function(){ this.adjustBlockLevelCombo() } 
    237      } 
     239  block1: { 
     240    type: 'mouseup', 
     241    fn: function() { 
     242      this.adjustBlockLevelCombo(); 
     243    } 
     244  }, 
     245  block2: { 
     246    type: 'keyup', 
     247    fn: function() { 
     248      this.adjustBlockLevelCombo(); 
     249    } 
     250  } 
    238251}; 
    239252 
    240253/** Insert a mode switcher after editor area 
    241 */ 
     254 */ 
    242255jsToolBar.prototype.switcher_visual_title = 'visual'; 
    243256jsToolBar.prototype.switcher_source_title = 'source'; 
    244257jsToolBar.prototype.setSwitcher = function() { 
    245      while (this.switcher.hasChildNodes()) { 
    246           this.switcher.removeChild(this.switcher.firstChild); 
    247      } 
    248  
    249      var This = this; 
    250      function setLink(title,link) { 
    251           var li = document.createElement('li'); 
    252           if (link) { 
    253                var a = document.createElement('a'); 
    254                a.href = '#'; 
    255                a.editor = This; 
    256                a.onclick = function() { this.editor.switchEdit(); return false; }; 
    257                a.appendChild(document.createTextNode(title)); 
    258           } else { 
    259                li.className = 'jstSwitcherCurrent'; 
    260                a = document.createTextNode(title); 
    261           } 
    262  
    263           li.appendChild(a); 
    264           This.switcher.appendChild(li); 
    265      } 
    266  
    267      setLink(this.switcher_visual_title,!this.wwg_mode); 
    268      setLink(this.switcher_source_title,this.wwg_mode); 
     258  while (this.switcher.hasChildNodes()) { 
     259    this.switcher.removeChild(this.switcher.firstChild); 
     260  } 
     261 
     262  var This = this; 
     263 
     264  function setLink(title, link) { 
     265    var li = document.createElement('li'); 
     266    var a; 
     267    if (link) { 
     268      a = document.createElement('a'); 
     269      a.href = '#'; 
     270      a.editor = This; 
     271      a.onclick = function() { 
     272        this.editor.switchEdit(); 
     273        return false; 
     274      }; 
     275      a.appendChild(document.createTextNode(title)); 
     276    } else { 
     277      li.className = 'jstSwitcherCurrent'; 
     278      a = document.createTextNode(title); 
     279    } 
     280 
     281    li.appendChild(a); 
     282    This.switcher.appendChild(li); 
     283  } 
     284 
     285  setLink(this.switcher_visual_title, !this.wwg_mode); 
     286  setLink(this.switcher_source_title, this.wwg_mode); 
    269287}; 
    270288 
    271289/** Removes editor area and mode switcher 
    272 */ 
     290 */ 
    273291jsToolBar.prototype.removeEditor = function() { 
    274      if (this.iframe != null) { 
    275           this.iframe.parentNode.removeChild(this.iframe); 
    276           this.iframe = null; 
    277      } 
    278  
    279      if (this.switcher != undefined && this.switcher.parentNode != undefined) { 
    280           this.switcher.parentNode.removeChild(this.switcher); 
    281      } 
     292  if (this.iframe != null) { 
     293    this.iframe.parentNode.removeChild(this.iframe); 
     294    this.iframe = null; 
     295  } 
     296 
     297  if (this.switcher != undefined && this.switcher.parentNode != undefined) { 
     298    this.switcher.parentNode.removeChild(this.switcher); 
     299  } 
    282300}; 
    283301 
    284302/** Focus on the editor area 
    285 */ 
     303 */ 
    286304jsToolBar.prototype.focusEditor = function() { 
    287      if (this.wwg_mode) { 
    288           try { this.iwin.document.designMode = 'on'; } catch (e) {}; // Firefox needs this 
    289           var This = this; 
    290           setTimeout(function() {This.iframe.contentWindow.focus()},1); 
    291      } else { 
    292           this.textarea.focus(); 
    293      } 
     305  if (this.wwg_mode) { 
     306    try { 
     307      this.iwin.document.designMode = 'on'; 
     308    } catch (e) {} // Firefox needs this 
     309    var This = this; 
     310    setTimeout(function() { 
     311      This.iframe.contentWindow.focus(); 
     312    }, 1); 
     313  } else { 
     314    this.textarea.focus(); 
     315  } 
    294316}; 
    295317 
    296318/** Resizer 
    297 */ 
     319 */ 
    298320jsToolBar.prototype.resizeSetStartH = function() { 
    299      if (this.wwg_mode && this.iframe != undefined) { 
    300           this.dragStartH = this.iframe.offsetHeight; 
    301           return; 
    302      } 
    303      this.dragStartH = this.textarea.offsetHeight + 0; 
     321  if (this.wwg_mode && this.iframe != undefined) { 
     322    this.dragStartH = this.iframe.offsetHeight; 
     323    return; 
     324  } 
     325  this.dragStartH = this.textarea.offsetHeight + 0; 
    304326}; 
    305327jsToolBar.prototype.resizeDragMove = function(event) { 
    306      var new_height = (this.dragStartH+event.clientY-this.dragStartY)+'px'; 
    307      if (this.iframe != undefined) { 
    308           this.iframe.style.height = new_height; 
    309      } 
    310      this.textarea.style.height = new_height; 
     328  var new_height = (this.dragStartH + event.clientY - this.dragStartY) + 'px'; 
     329  if (this.iframe != undefined) { 
     330    this.iframe.style.height = new_height; 
     331  } 
     332  this.textarea.style.height = new_height; 
    311333}; 
    312334 
     
    314336-------------------------------------------------------- */ 
    315337/** Replaces current selection by given node 
    316 */ 
     338 */ 
    317339jsToolBar.prototype.insertNode = function(node) { 
    318      var range; 
    319  
    320      if (this.iwin.getSelection) { // Gecko 
    321           var sel = this.iwin.getSelection(); 
    322           range = sel.getRangeAt(0); 
    323  
    324           // deselect all ranges 
    325           sel.removeAllRanges(); 
    326  
    327           // empty range 
    328           range.deleteContents(); 
    329  
    330           // Insert node 
    331           range.insertNode(node); 
    332  
    333           range.selectNodeContents(node); 
    334           range.setEndAfter(node); 
    335           if (range.endContainer.childNodes.length > range.endOffset && 
    336           range.endContainer.nodeType != Node.TEXT_NODE) { 
    337                range.setEnd(range.endContainer.childNodes[range.endOffset], 0); 
    338           } else { 
    339                range.setEnd(range.endContainer.childNodes[0]); 
    340           } 
    341           sel.addRange(range); 
    342  
    343           sel.collapseToEnd(); 
    344      } else { // IE 
    345           // lambda element 
    346           var p = this.iwin.document.createElement('div'); 
    347           p.appendChild(node); 
    348           range = this.iwin.document.selection.createRange(); 
    349           range.execCommand('delete'); 
    350           // insert innerHTML from element 
    351           range.pasteHTML(p.innerHTML); 
    352           range.collapse(false); 
    353           range.select(); 
    354      } 
    355      this.iwin.focus(); 
     340  var range; 
     341 
     342  if (this.iwin.getSelection) { // Gecko 
     343    var sel = this.iwin.getSelection(); 
     344    range = sel.getRangeAt(0); 
     345 
     346    // deselect all ranges 
     347    sel.removeAllRanges(); 
     348 
     349    // empty range 
     350    range.deleteContents(); 
     351 
     352    // Insert node 
     353    range.insertNode(node); 
     354 
     355    range.selectNodeContents(node); 
     356    range.setEndAfter(node); 
     357    if (range.endContainer.childNodes.length > range.endOffset && 
     358      range.endContainer.nodeType != Node.TEXT_NODE) { 
     359      range.setEnd(range.endContainer.childNodes[range.endOffset], 0); 
     360    } else { 
     361      range.setEnd(range.endContainer.childNodes[0]); 
     362    } 
     363    sel.addRange(range); 
     364 
     365    sel.collapseToEnd(); 
     366  } else { // IE 
     367    // lambda element 
     368    var p = this.iwin.document.createElement('div'); 
     369    p.appendChild(node); 
     370    range = this.iwin.document.selection.createRange(); 
     371    range.execCommand('delete'); 
     372    // insert innerHTML from element 
     373    range.pasteHTML(p.innerHTML); 
     374    range.collapse(false); 
     375    range.select(); 
     376  } 
     377  this.iwin.focus(); 
    356378}; 
    357379 
    358380/** Returns a document fragment with selected nodes 
    359 */ 
     381 */ 
    360382jsToolBar.prototype.getSelectedNode = function() { 
    361      if (this.iwin.getSelection) { // Gecko 
    362           var sel = this.iwin.getSelection(); 
    363           var range = sel.getRangeAt(0); 
    364           var content = range.cloneContents(); 
    365      } else { // IE 
    366           var sel = this.iwin.document.selection; 
    367           var d = this.iwin.document.createElement('div'); 
    368           d.innerHTML = sel.createRange().htmlText; 
    369           var content = this.iwin.document.createDocumentFragment(); 
    370           for (var i=0; i < d.childNodes.length; i++) { 
    371                content.appendChild(d.childNodes[i].cloneNode(true)); 
    372           } 
    373      } 
    374      return content; 
     383  var sel; 
     384  var content; 
     385  if (this.iwin.getSelection) { // Gecko 
     386    sel = this.iwin.getSelection(); 
     387    var range = sel.getRangeAt(0); 
     388    content = range.cloneContents(); 
     389  } else { // IE 
     390    sel = this.iwin.document.selection; 
     391    var d = this.iwin.document.createElement('div'); 
     392    d.innerHTML = sel.createRange().htmlText; 
     393    content = this.iwin.document.createDocumentFragment(); 
     394    for (var i = 0; i < d.childNodes.length; i++) { 
     395      content.appendChild(d.childNodes[i].cloneNode(true)); 
     396    } 
     397  } 
     398  return content; 
    375399}; 
    376400 
    377401/** Returns string representation for selected node 
    378 */ 
     402 */ 
    379403jsToolBar.prototype.getSelectedText = function() { 
    380      if (this.iwin.getSelection) { // Gecko 
    381           return this.iwin.getSelection().toString(); 
    382      } else { // IE 
    383           var range = this.iwin.document.selection.createRange(); 
    384           return range.text; 
    385      } 
     404  if (this.iwin.getSelection) { // Gecko 
     405    return this.iwin.getSelection().toString(); 
     406  } else { // IE 
     407    var range = this.iwin.document.selection.createRange(); 
     408    return range.text; 
     409  } 
    386410}; 
    387411 
    388412jsToolBar.prototype.replaceNodeByContent = function(node) { 
    389      var content = this.iwin.document.createDocumentFragment(); 
    390      for (var i=0; i < node.childNodes.length; i++) { 
    391           content.appendChild(node.childNodes[i].cloneNode(true)); 
    392      } 
    393      node.parentNode.replaceChild(content, node); 
     413  var content = this.iwin.document.createDocumentFragment(); 
     414  for (var i = 0; i < node.childNodes.length; i++) { 
     415    content.appendChild(node.childNodes[i].cloneNode(true)); 
     416  } 
     417  node.parentNode.replaceChild(content, node); 
    394418}; 
    395419 
    396420jsToolBar.prototype.getBlockLevel = function() { 
    397      var blockElts = ['p','h1','h2','h3','h4','h5','h6']; 
    398  
    399      var range, commonAncestorContainer; 
    400      if (this.iwin.getSelection) { //gecko 
    401           var selection = this.iwin.getSelection(); 
    402           range = selection.getRangeAt(0); 
    403           commonAncestorContainer = range.commonAncestorContainer; 
    404           while (commonAncestorContainer.nodeType != 1) { 
    405                commonAncestorContainer = commonAncestorContainer.parentNode; 
    406           } 
    407      } else { //ie 
    408           range = this.iwin.document.selection.createRange(); 
    409           commonAncestorContainer = range.parentElement(); 
    410      } 
    411  
    412      var ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); 
    413      while (arrayIndexOf(blockElts, ancestorTagName)==-1 && ancestorTagName!='body') { 
    414           commonAncestorContainer = commonAncestorContainer.parentNode; 
    415           ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); 
    416      } 
    417      if (ancestorTagName == 'body') return null; 
    418      else return commonAncestorContainer; 
     421  var blockElts = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']; 
     422 
     423  var range, commonAncestorContainer; 
     424  if (this.iwin.getSelection) { //gecko 
     425    var selection = this.iwin.getSelection(); 
     426    range = selection.getRangeAt(0); 
     427    commonAncestorContainer = range.commonAncestorContainer; 
     428    while (commonAncestorContainer.nodeType != 1) { 
     429      commonAncestorContainer = commonAncestorContainer.parentNode; 
     430    } 
     431  } else { //ie 
     432    range = this.iwin.document.selection.createRange(); 
     433    commonAncestorContainer = range.parentElement(); 
     434  } 
     435 
     436  var ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); 
     437  while (arrayIndexOf(blockElts, ancestorTagName) == -1 && ancestorTagName != 'body') { 
     438    commonAncestorContainer = commonAncestorContainer.parentNode; 
     439    ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); 
     440  } 
     441  if (ancestorTagName == 'body') return null; 
     442  else return commonAncestorContainer; 
    419443}; 
    420444jsToolBar.prototype.adjustBlockLevelCombo = function() { 
    421      var blockLevel = this.getBlockLevel(); 
    422      if (blockLevel !== null) 
    423           this.toolNodes.blocks.value = blockLevel.tagName.toLowerCase(); 
    424      else { 
    425           if (this.mode == 'wysiwyg') this.toolNodes.blocks.value = 'none'; 
    426           if (this.mode == 'xhtml') this.toolNodes.blocks.value = 'nonebis'; 
    427      } 
     445  var blockLevel = this.getBlockLevel(); 
     446  if (blockLevel !== null) 
     447    this.toolNodes.blocks.value = blockLevel.tagName.toLowerCase(); 
     448  else { 
     449    if (this.mode == 'wysiwyg') this.toolNodes.blocks.value = 'none'; 
     450    if (this.mode == 'xhtml') this.toolNodes.blocks.value = 'nonebis'; 
     451  } 
    428452}; 
    429453 
     
    431455-------------------------------------------------------- */ 
    432456jsToolBar.prototype.simpleCleanRegex = new Array( 
    433      /* Remove every tags we don't need */ 
    434      [/<meta[\w\W]*?>/gim,''], 
    435      [/<style[\w\W]*?>[\w\W]*?<\/style>/gim, ''], 
    436      [/<\/?font[\w\W]*?>/gim, ''], 
    437  
    438  
    439      /* Replacements */ 
    440      [/<(\/?)(B|b|STRONG)([\s>\/])/g, "<$1strong$3"], 
    441      [/<(\/?)(I|i|EM)([\s>\/])/g, "<$1em$3"], 
    442      [/<IMG ([^>]*?[^\/])>/gi, "<img $1 />"], 
    443      [/<INPUT ([^>]*?[^\/])>/gi, "<input $1 />"], 
    444      [/<COL ([^>]*?[^\/])>/gi, "<col $1 />"], 
    445      [/<AREA ([^>]*?[^\/])>/gi, "<area $1 />"], 
    446      [/<PARAM ([^>]*?[^\/])>/gi, "<param $1 />"], 
    447      [/<HR ([^>]*?[^\/])>/gi, "<hr $1/>"], 
    448      [/<BR ([^>]*?[^\/])>/gi, "<br $1/>"], 
    449      [/<(\/?)U([\s>\/])/gi, "<$1ins$2"], 
    450      [/<(\/?)STRIKE([\s>\/])/gi, "<$1del$2"], 
    451      [/<span style="font-weight: normal;">([\w\W]*?)<\/span>/gm, "$1"], 
    452      [/<span style="font-weight: bold;">([\w\W]*?)<\/span>/gm, "<strong>$1</strong>"], 
    453      [/<span style="font-style: italic;">([\w\W]*?)<\/span>/gm, "<em>$1</em>"], 
    454      [/<span style="text-decoration: underline;">([\w\W]*?)<\/span>/gm, "<ins>$1</ins>"], 
    455      [/<span style="text-decoration: line-through;">([\w\W]*?)<\/span>/gm, "<del>$1</del>"], 
    456      [/<span style="text-decoration: underline line-through;">([\w\W]*?)<\/span>/gm, "<del><ins>$1</ins></del>"], 
    457      [/<span style="(font-weight: bold; ?|font-style: italic; ?){2}">([\w\W]*?)<\/span>/gm, "<strong><em>$2</em></strong>"], 
    458      [/<span style="(font-weight: bold; ?|text-decoration: underline; ?){2}">([\w\W]*?)<\/span>/gm, "<ins><strong>$2</strong></ins>"], 
    459      [/<span style="(font-weight: italic; ?|text-decoration: underline; ?){2}">([\w\W]*?)<\/span>/gm, "<ins><em>$2</em></ins>"], 
    460      [/<span style="(font-weight: bold; ?|text-decoration: line-through; ?){2}">([\w\W]*?)<\/span>/gm, "<del><strong>$2</strong></del>"], 
    461      [/<span style="(font-weight: italic; ?|text-decoration: line-through; ?){2}">([\w\W]*?)<\/span>/gm, "<del><em>$2</em></del>"], 
    462      [/<span style="(font-weight: bold; ?|font-style: italic; ?|text-decoration: underline; ?){3}">([\w\W]*?)<\/span>/gm, "<ins><strong><em>$2</em></strong></ins>"], 
    463      [/<span style="(font-weight: bold; ?|font-style: italic; ?|text-decoration: line-through; ?){3}">([\w\W]*?)<\/span>/gm, "<del><strong><em>$2</em></strong></del>"], 
    464      [/<span style="(font-weight: bold; ?|font-style: italic; ?|text-decoration: underline line-through; ?){3}">([\w\W]*?)<\/span>/gm, "<del><ins><strong><em>$2</em></strong></ins></del>"], 
    465      [/<strong style="font-weight: normal;">([\w\W]*?)<\/strong>/gm, "$1"], 
    466      [/<([a-z]+) style="font-weight: normal;">([\w\W]*?)<\/\1>/gm, "<$1>$2</$1>"], 
    467      [/<([a-z]+) style="font-weight: bold;">([\w\W]*?)<\/\1>/gm, "<$1><strong>$2</strong></$1>"], 
    468      [/<([a-z]+) style="font-style: italic;">([\w\W]*?)<\/\1>/gm, "<$1><em>$2</em></$1>"], 
    469      [/<([a-z]+) style="text-decoration: underline;">([\w\W]*?)<\/\1>/gm, "<ins><$1>$2</$1></ins>"], 
    470      [/<([a-z]+) style="text-decoration: line-through;">([\w\W]*?)<\/\1>/gm, "<del><$1>$2</$1></del>"], 
    471      [/<([a-z]+) style="text-decoration: underline line-through;">([\w\W]*?)<\/\1>/gm, "<del><ins><$1>$2</$1></ins></del>"], 
    472      [/<([a-z]+) style="(font-weight: bold; ?|font-style: italic; ?){2}">([\w\W]*?)<\/\1>/gm, "<$1><strong><em>$3</em></strong></$1>"], 
    473      [/<([a-z]+) style="(font-weight: bold; ?|text-decoration: underline; ?){2}">([\w\W]*?)<\/\1>/gm, "<ins><$1><strong>$3</strong></$1></ins>"], 
    474      [/<([a-z]+) style="(font-weight: italic; ?|text-decoration: underline; ?){2}">([\w\W]*?)<\/\1>/gm, "<ins><$1><em>$3</em></$1></ins>"], 
    475      [/<([a-z]+) style="(font-weight: bold; ?|text-decoration: line-through; ?){2}">([\w\W]*?)<\/\1>/gm, "<del><$1><strong>$3</strong></$1></del>"], 
    476      [/<([a-z]+) style="(font-weight: italic; ?|text-decoration: line-through; ?){2}">([\w\W]*?)<\/\1>/gm, "<del><$1><em>$3</em></$1></del>"], 
    477      [/<([a-z]+) style="(font-weight: bold; ?|font-style: italic; ?|text-decoration: underline; ?){3}">([\w\W]*?)<\/\1>/gm, "<ins><$1><strong><em>$3</em></strong></$1></ins>"], 
    478      [/<([a-z]+) style="(font-weight: bold; ?|font-style: italic; ?|text-decoration: line-through; ?){3}">([\w\W]*?)<\/\1>/gm, "<del><$1><strong><em>$3</em></strong></$1></del>"], 
    479      [/<([a-z]+) style="(font-weight: bold; ?|font-style: italic; ?|text-decoration: underline line-through; ?){3}">([\w\W]*?)<\/\1>/gm, "<del><ins><$1><strong><em>$3</em></strong></$1></ins></del>"], 
    480      [/<p><blockquote>(.*)(\n)+<\/blockquote><\/p>/i,"<blockquote>$1</blockquote>\n"], 
    481      /* mise en forme identique contigue */ 
    482      [/<\/(strong|em|ins|del|q|code)>(\s*?)<\1>/gim, "$2"], 
    483      [/<(br|BR)>/g, "<br />"], 
    484      [/<(hr|HR)>/g, "<hr />"], 
    485      /* opera est trop strict ;)) */ 
    486      [/([^\s])\/>/g, "$1 />"], 
    487      /* br intempestifs de fin de block */ 
    488      [/<br \/>\s*<\/(h1|h2|h3|h4|h5|h6|ul|ol|li|p|blockquote|div)/gi, "</$1"], 
    489      [/<\/(h1|h2|h3|h4|h5|h6|ul|ol|li|p|blockquote)>([^\n\u000B\r\f])/gi, "</$1>\n$2"], 
    490      [/<hr style="width: 100%; height: 2px;" \/>/g, "<hr />"] 
     457  /* Remove every tags we don't need */ 
     458  [/<meta[\w\W]*?>/gim, ''], [/<style[\w\W]*?>[\w\W]*?<\/style>/gim, ''], [/<\/?font[\w\W]*?>/gim, ''], 
     459 
     460  /* Replacements */ 
     461  [/<(\/?)(B|b|STRONG)([\s>\/])/g, "<$1strong$3"], [/<(\/?)(I|i|EM)([\s>\/])/g, "<$1em$3"], [/<IMG ([^>]*?[^\/])>/gi, "<img $1 />"], [/<INPUT ([^>]*?[^\/])>/gi, "<input $1 />"], [/<COL ([^>]*?[^\/])>/gi, "<col $1 />"], [/<AREA ([^>]*?[^\/])>/gi, "<area $1 />"], [/<PARAM ([^>]*?[^\/])>/gi, "<param $1 />"], [/<HR ([^>]*?[^\/])>/gi, "<hr $1/>"], [/<BR ([^>]*?[^\/])>/gi, "<br $1/>"], [/<(\/?)U([\s>\/])/gi, "<$1ins$2"], [/<(\/?)STRIKE([\s>\/])/gi, "<$1del$2"], [/<span style="font-weight: normal;">([\w\W]*?)<\/span>/gm, "$1"], [/<span style="font-weight: bold;">([\w\W]*?)<\/span>/gm, "<strong>$1</strong>"], [/<span style="font-style: italic;">([\w\W]*?)<\/span>/gm, "<em>$1</em>"], [/<span style="text-decoration: underline;">([\w\W]*?)<\/span>/gm, "<ins>$1</ins>"], [/<span style="text-decoration: line-through;">([\w\W]*?)<\/span>/gm, "<del>$1</del>"], [/<span style="text-decoration: underline line-through;">([\w\W]*?)<\/span>/gm, "<del><ins>$1</ins></del>"], [/<span style="(font-weight: bold; ?|font-style: italic; ?){2}">([\w\W]*?)<\/span>/gm, "<strong><em>$2</em></strong>"], [/<span style="(font-weight: bold; ?|text-decoration: underline; ?){2}">([\w\W]*?)<\/span>/gm, "<ins><strong>$2</strong></ins>"], [/<span style="(font-weight: italic; ?|text-decoration: underline; ?){2}">([\w\W]*?)<\/span>/gm, "<ins><em>$2</em></ins>"], [/<span style="(font-weight: bold; ?|text-decoration: line-through; ?){2}">([\w\W]*?)<\/span>/gm, "<del><strong>$2</strong></del>"], [/<span style="(font-weight: italic; ?|text-decoration: line-through; ?){2}">([\w\W]*?)<\/span>/gm, "<del><em>$2</em></del>"], [/<span style="(font-weight: bold; ?|font-style: italic; ?|text-decoration: underline; ?){3}">([\w\W]*?)<\/span>/gm, "<ins><strong><em>$2</em></strong></ins>"], [/<span style="(font-weight: bold; ?|font-style: italic; ?|text-decoration: line-through; ?){3}">([\w\W]*?)<\/span>/gm, "<del><strong><em>$2</em></strong></del>"], [/<span style="(font-weight: bold; ?|font-style: italic; ?|text-decoration: underline line-through; ?){3}">([\w\W]*?)<\/span>/gm, "<del><ins><strong><em>$2</em></strong></ins></del>"], [/<strong style="font-weight: normal;">([\w\W]*?)<\/strong>/gm, "$1"], [/<([a-z]+) style="font-weight: normal;">([\w\W]*?)<\/\1>/gm, "<$1>$2</$1>"], [/<([a-z]+) style="font-weight: bold;">([\w\W]*?)<\/\1>/gm, "<$1><strong>$2</strong></$1>"], [/<([a-z]+) style="font-style: italic;">([\w\W]*?)<\/\1>/gm, "<$1><em>$2</em></$1>"], [/<([a-z]+) style="text-decoration: underline;">([\w\W]*?)<\/\1>/gm, "<ins><$1>$2</$1></ins>"], [/<([a-z]+) style="text-decoration: line-through;">([\w\W]*?)<\/\1>/gm, "<del><$1>$2</$1></del>"], [/<([a-z]+) style="text-decoration: underline line-through;">([\w\W]*?)<\/\1>/gm, "<del><ins><$1>$2</$1></ins></del>"], [/<([a-z]+) style="(font-weight: bold; ?|font-style: italic; ?){2}">([\w\W]*?)<\/\1>/gm, "<$1><strong><em>$3</em></strong></$1>"], [/<([a-z]+) style="(font-weight: bold; ?|text-decoration: underline; ?){2}">([\w\W]*?)<\/\1>/gm, "<ins><$1><strong>$3</strong></$1></ins>"], [/<([a-z]+) style="(font-weight: italic; ?|text-decoration: underline; ?){2}">([\w\W]*?)<\/\1>/gm, "<ins><$1><em>$3</em></$1></ins>"], [/<([a-z]+) style="(font-weight: bold; ?|text-decoration: line-through; ?){2}">([\w\W]*?)<\/\1>/gm, "<del><$1><strong>$3</strong></$1></del>"], [/<([a-z]+) style="(font-weight: italic; ?|text-decoration: line-through; ?){2}">([\w\W]*?)<\/\1>/gm, "<del><$1><em>$3</em></$1></del>"], [/<([a-z]+) style="(font-weight: bold; ?|font-style: italic; ?|text-decoration: underline; ?){3}">([\w\W]*?)<\/\1>/gm, "<ins><$1><strong><em>$3</em></strong></$1></ins>"], [/<([a-z]+) style="(font-weight: bold; ?|font-style: italic; ?|text-decoration: line-through; ?){3}">([\w\W]*?)<\/\1>/gm, "<del><$1><strong><em>$3</em></strong></$1></del>"], [/<([a-z]+) style="(font-weight: bold; ?|font-style: italic; ?|text-decoration: underline line-through; ?){3}">([\w\W]*?)<\/\1>/gm, "<del><ins><$1><strong><em>$3</em></strong></$1></ins></del>"], [/<p><blockquote>(.*)(\n)+<\/blockquote><\/p>/i, "<blockquote>$1</blockquote>\n"], 
     462  /* mise en forme identique contigue */ 
     463  [/<\/(strong|em|ins|del|q|code)>(\s*?)<\1>/gim, "$2"], [/<(br|BR)>/g, "<br />"], [/<(hr|HR)>/g, "<hr />"], 
     464  /* opera est trop strict ;)) */ 
     465  [/([^\s])\/>/g, "$1 />"], 
     466  /* br intempestifs de fin de block */ 
     467  [/<br \/>\s*<\/(h1|h2|h3|h4|h5|h6|ul|ol|li|p|blockquote|div)/gi, "</$1"], [/<\/(h1|h2|h3|h4|h5|h6|ul|ol|li|p|blockquote)>([^\n\u000B\r\f])/gi, "</$1>\n$2"], [/<hr style="width: 100%; height: 2px;" \/>/g, "<hr />"] 
    491468); 
    492469 
    493470/** Cleanup HTML code 
    494 */ 
     471 */ 
    495472jsToolBar.prototype.tagsoup2xhtml = function(html) { 
    496      for (var reg in this.simpleCleanRegex) { 
    497           html = html.replace(this.simpleCleanRegex[reg][0], this.simpleCleanRegex[reg][1]); 
    498      } 
    499      /* tags vides */ 
    500      /* note : on tente de ne pas tenir compte des commentaires html, ceux-ci 
    501         permettent entre autre d'inserer des commentaires conditionnels pour ie */ 
    502      while ( /(<[^\/!]>|<[^\/!][^>]*[^\/]>)\s*<\/[^>]*[^-]>/.test(html) ) { 
    503           html = html.replace(/(<[^\/!]>|<[^\/!][^>]*[^\/]>)\s*<\/[^>]*[^-]>/g, ""); 
    504      } 
    505  
    506      /* tous les tags en minuscule */ 
    507      html = html.replace(/<(\/?)([A-Z0-9]+)/g, 
    508                function(match0, match1, match2) { 
    509                     return "<" + match1 + match2.toLowerCase(); 
    510                }); 
    511  
    512      /* IE laisse souvent des attributs sans guillemets */ 
    513      var myRegexp = /<[^>]+((\s+\w+\s*=\s*)([^"'][\w~@+$,%\/:.#?=&;!*()-]*))[^>]*?>/; 
    514      while ( myRegexp.test(html)) { 
    515           html = html.replace( 
    516                myRegexp, 
    517                function (str, val1, val2, val3){ 
    518                     var tamponRegex = new RegExp(regexpEscape(val1)); 
    519                     return str.replace(tamponRegex, val2+'"'+val3+'"'); 
    520                } 
    521           ) 
    522      } 
    523  
    524      /* les navigateurs rajoutent une unite aux longueurs css nulles */ 
    525      /* note: a ameliorer ! */ 
    526      while ( /(<[^>]+style=(["'])[^>]+[\s:]+)0(pt|px)(\2|\s|;)/.test(html)) { 
    527           html = html.replace(/(<[^>]+style=(["'])[^>]+[\s:]+)0(pt|px)(\2|\s|;)/gi, "$1"+"0$4"); 
    528      } 
    529  
    530      /* correction des fins de lignes : le textarea edite contient des \n 
    531      * le wysiwyg des \r\n , et le textarea mis a jour SANS etre affiche des \r\n ! */ 
    532      html = html.replace(/\r\n/g,"\n"); 
    533  
    534      /* Trim only if there's no pre tag */ 
    535      pattern_pre = /<pre>[\s\S]*<\/pre>/gi; 
    536      if (!pattern_pre.test(html)) { 
    537           html = html.replace(/^\s+/gm,''); 
    538           html = html.replace(/\s+$/gm,''); 
    539      } 
    540  
    541      return html; 
     473  for (var reg in this.simpleCleanRegex) { 
     474    html = html.replace(this.simpleCleanRegex[reg][0], this.simpleCleanRegex[reg][1]); 
     475  } 
     476  /* tags vides */ 
     477  /* note : on tente de ne pas tenir compte des commentaires html, ceux-ci 
     478     permettent entre autre d'inserer des commentaires conditionnels pour ie */ 
     479  while (/(<[^\/!]>|<[^\/!][^>]*[^\/]>)\s*<\/[^>]*[^-]>/.test(html)) { 
     480    html = html.replace(/(<[^\/!]>|<[^\/!][^>]*[^\/]>)\s*<\/[^>]*[^-]>/g, ""); 
     481  } 
     482 
     483  /* tous les tags en minuscule */ 
     484  html = html.replace(/<(\/?)([A-Z0-9]+)/g, 
     485    function(match0, match1, match2) { 
     486      return "<" + match1 + match2.toLowerCase(); 
     487    }); 
     488 
     489  /* IE laisse souvent des attributs sans guillemets */ 
     490  var myRegexp = /<[^>]+((\s+\w+\s*=\s*)([^"'][\w~@+$,%\/:.#?=&;!*()-]*))[^>]*?>/; 
     491  while (myRegexp.test(html)) { 
     492    html = html.replace( 
     493      myRegexp, 
     494      function(str, val1, val2, val3) { 
     495        var tamponRegex = new RegExp(regexpEscape(val1)); 
     496        return str.replace(tamponRegex, val2 + '"' + val3 + '"'); 
     497      } 
     498    ); 
     499  } 
     500 
     501  /* les navigateurs rajoutent une unite aux longueurs css nulles */ 
     502  /* note: a ameliorer ! */ 
     503  while (/(<[^>]+style=(["'])[^>]+[\s:]+)0(pt|px)(\2|\s|;)/.test(html)) { 
     504    html = html.replace(/(<[^>]+style=(["'])[^>]+[\s:]+)0(pt|px)(\2|\s|;)/gi, "$1" + "0$4"); 
     505  } 
     506 
     507  /* correction des fins de lignes : le textarea edite contient des \n 
     508   * le wysiwyg des \r\n , et le textarea mis a jour SANS etre affiche des \r\n ! */ 
     509  html = html.replace(/\r\n/g, "\n"); 
     510 
     511  /* Trim only if there's no pre tag */ 
     512  var pattern_pre = /<pre>[\s\S]*<\/pre>/gi; 
     513  if (!pattern_pre.test(html)) { 
     514    html = html.replace(/^\s+/gm, ''); 
     515    html = html.replace(/\s+$/gm, ''); 
     516  } 
     517 
     518  return html; 
    542519}; 
    543520jsToolBar.prototype.validBlockquote = function() { 
    544      var blockElts = ['address','blockquote','dl','div','fieldset','form','h1', 
    545                       'h2','h3','h4','h5','h6','hr','ol','p','pre','table','ul']; 
    546      var BQs = this.iwin.document.getElementsByTagName('blockquote'); 
    547      var bqChilds; 
    548  
    549      for (var bq = 0; bq < BQs.length; bq++) { 
    550           bqChilds = BQs[bq].childNodes; 
    551           var frag = this.iwin.document.createDocumentFragment(); 
    552           for (var i = (bqChilds.length-1); i >= 0; i--) { 
    553                if (bqChilds[i].nodeType == 1 && // Node.ELEMENT_NODE 
    554                    arrayIndexOf(blockElts, bqChilds[i].tagName.toLowerCase()) >= 0) 
    555                { 
    556                     if (frag.childNodes.length > 0) { 
    557                          var p = this.iwin.document.createElement('p'); 
    558                          p.appendChild(frag); 
    559                          BQs[bq].replaceChild(p, bqChilds[i+1]); 
    560                          frag = this.iwin.document.createDocumentFragment(); 
    561                     } 
    562                } else { 
    563                     if (frag.childNodes.length > 0) BQs[bq].removeChild(bqChilds[i+1]); 
    564                     frag.insertBefore(bqChilds[i].cloneNode(true), frag.firstChild); 
    565                } 
    566           } 
    567           if (frag.childNodes.length > 0) { 
    568                var p = this.iwin.document.createElement('p'); 
    569                p.appendChild(frag); 
    570                BQs[bq].replaceChild(p, bqChilds[0]); 
    571           } 
    572      } 
     521  var blockElts = ['address', 'blockquote', 'dl', 'div', 'fieldset', 'form', 'h1', 
     522    'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'ol', 'p', 'pre', 'table', 'ul' 
     523  ]; 
     524  var BQs = this.iwin.document.getElementsByTagName('blockquote'); 
     525  var bqChilds; 
     526  var p; 
     527 
     528  for (var bq = 0; bq < BQs.length; bq++) { 
     529    bqChilds = BQs[bq].childNodes; 
     530    var frag = this.iwin.document.createDocumentFragment(); 
     531    for (var i = (bqChilds.length - 1); i >= 0; i--) { 
     532      if (bqChilds[i].nodeType == 1 && // Node.ELEMENT_NODE 
     533        arrayIndexOf(blockElts, bqChilds[i].tagName.toLowerCase()) >= 0) { 
     534        if (frag.childNodes.length > 0) { 
     535          p = this.iwin.document.createElement('p'); 
     536          p.appendChild(frag); 
     537          BQs[bq].replaceChild(p, bqChilds[i + 1]); 
     538          frag = this.iwin.document.createDocumentFragment(); 
     539        } 
     540      } else { 
     541        if (frag.childNodes.length > 0) BQs[bq].removeChild(bqChilds[i + 1]); 
     542        frag.insertBefore(bqChilds[i].cloneNode(true), frag.firstChild); 
     543      } 
     544    } 
     545    if (frag.childNodes.length > 0) { 
     546      p = this.iwin.document.createElement('p'); 
     547      p.appendChild(frag); 
     548      BQs[bq].replaceChild(p, bqChilds[0]); 
     549    } 
     550  } 
    573551}; 
    574552 
    575553/* Removing text formating */ 
    576554jsToolBar.prototype.removeFormatRegexp = new Array( 
    577      [/(<[a-z][^>]*)margin\s*:[^;]*;/mg, "$1"], 
    578      [/(<[a-z][^>]*)margin-bottom\s*:[^;]*;/mg, "$1"], 
    579      [/(<[a-z][^>]*)margin-left\s*:[^;]*;/mg, "$1"], 
    580      [/(<[a-z][^>]*)margin-right\s*:[^;]*;/mg, "$1"], 
    581      [/(<[a-z][^>]*)margin-top\s*:[^;]*;/mg, "$1"], 
    582  
    583      [/(<[a-z][^>]*)padding\s*:[^;]*;/mg, "$1"], 
    584      [/(<[a-z][^>]*)padding-bottom\s*:[^;]*;/mg, "$1"], 
    585      [/(<[a-z][^>]*)padding-left\s*:[^;]*;/mg, "$1"], 
    586      [/(<[a-z][^>]*)padding-right\s*:[^;]*;/mg, "$1"], 
    587      [/(<[a-z][^>]*)padding-top\s*:[^;]*;/mg, "$1"], 
    588  
    589      [/(<[a-z][^>]*)font\s*:[^;]*;/mg, "$1"], 
    590      [/(<[a-z][^>]*)font-family\s*:[^;]*;/mg, "$1"], 
    591      [/(<[a-z][^>]*)font-size\s*:[^;]*;/mg, "$1"], 
    592      [/(<[a-z][^>]*)font-style\s*:[^;]*;/mg, "$1"], 
    593      [/(<[a-z][^>]*)font-variant\s*:[^;]*;/mg, "$1"], 
    594      [/(<[a-z][^>]*)font-weight\s*:[^;]*;/mg, "$1"], 
    595  
    596      [/(<[a-z][^>]*)color\s*:[^;]*;/mg, "$1"] 
     555  [/(<[a-z][^>]*)margin\s*:[^;]*;/mg, "$1"], [/(<[a-z][^>]*)margin-bottom\s*:[^;]*;/mg, "$1"], [/(<[a-z][^>]*)margin-left\s*:[^;]*;/mg, "$1"], [/(<[a-z][^>]*)margin-right\s*:[^;]*;/mg, "$1"], [/(<[a-z][^>]*)margin-top\s*:[^;]*;/mg, "$1"], 
     556 
     557  [/(<[a-z][^>]*)padding\s*:[^;]*;/mg, "$1"], [/(<[a-z][^>]*)padding-bottom\s*:[^;]*;/mg, "$1"], [/(<[a-z][^>]*)padding-left\s*:[^;]*;/mg, "$1"], [/(<[a-z][^>]*)padding-right\s*:[^;]*;/mg, "$1"], [/(<[a-z][^>]*)padding-top\s*:[^;]*;/mg, "$1"], 
     558 
     559  [/(<[a-z][^>]*)font\s*:[^;]*;/mg, "$1"], [/(<[a-z][^>]*)font-family\s*:[^;]*;/mg, "$1"], [/(<[a-z][^>]*)font-size\s*:[^;]*;/mg, "$1"], [/(<[a-z][^>]*)font-style\s*:[^;]*;/mg, "$1"], [/(<[a-z][^>]*)font-variant\s*:[^;]*;/mg, "$1"], [/(<[a-z][^>]*)font-weight\s*:[^;]*;/mg, "$1"], 
     560 
     561  [/(<[a-z][^>]*)color\s*:[^;]*;/mg, "$1"] 
    597562); 
    598563 
    599564jsToolBar.prototype.removeTextFormating = function(html) { 
    600      for (var reg in this.removeFormatRegexp) { 
    601           html = html.replace(this.removeFormatRegexp[reg][0], this.removeFormatRegexp[reg][1]); 
    602      } 
    603  
    604      html = this.tagsoup2xhtml(html); 
    605      html = html.replace(/style="\s*?"/mgi,''); 
    606      return html; 
     565  for (var reg in this.removeFormatRegexp) { 
     566    html = html.replace(this.removeFormatRegexp[reg][0], this.removeFormatRegexp[reg][1]); 
     567  } 
     568 
     569  html = this.tagsoup2xhtml(html); 
     570  html = html.replace(/style="\s*?"/mgi, ''); 
     571  return html; 
    607572}; 
    608573 
     
    610575-------------------------------------------------------- */ 
    611576jsToolBar.prototype.elements.blocks.wysiwyg = { 
    612      list: ['none','p','h1','h2','h3','h4','h5','h6'], 
    613      fn: function(opt) { 
    614           if (opt=='none') { 
    615                var blockLevel = this.getBlockLevel(); 
    616                if (blockLevel !== null) { 
    617                     this.replaceNodeByContent(blockLevel); 
    618                } 
    619                this.iwin.focus(); 
    620           } else { 
    621                try { this.iwin.document.execCommand('formatblock',false,'<'+opt+'>'); 
    622                } catch(e){}; 
    623                this.iwin.focus(); 
    624           } 
    625      } 
     577  list: ['none', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'], 
     578  fn: function(opt) { 
     579    if (opt == 'none') { 
     580      var blockLevel = this.getBlockLevel(); 
     581      if (blockLevel !== null) { 
     582        this.replaceNodeByContent(blockLevel); 
     583      } 
     584      this.iwin.focus(); 
     585    } else { 
     586      try { 
     587        this.iwin.document.execCommand('formatblock', false, '<' + opt + '>'); 
     588      } catch (e) {} 
     589      this.iwin.focus(); 
     590    } 
     591  } 
    626592}; 
    627593 
    628594jsToolBar.prototype.elements.strong.fn.wysiwyg = function() { 
    629      this.iwin.document.execCommand('bold', false, null); 
    630      this.iwin.focus(); 
     595  this.iwin.document.execCommand('bold', false, null); 
     596  this.iwin.focus(); 
    631597}; 
    632598 
    633599jsToolBar.prototype.elements.em.fn.wysiwyg = function() { 
    634      this.iwin.document.execCommand('italic', false, null); 
    635      this.iwin.focus(); 
     600  this.iwin.document.execCommand('italic', false, null); 
     601  this.iwin.focus(); 
    636602}; 
    637603 
    638604jsToolBar.prototype.elements.ins.fn.wysiwyg = function() { 
    639      this.iwin.document.execCommand('underline', false, null); 
    640      this.iwin.focus(); 
     605  this.iwin.document.execCommand('underline', false, null); 
     606  this.iwin.focus(); 
    641607}; 
    642608 
    643609jsToolBar.prototype.elements.del.fn.wysiwyg = function() { 
    644      this.iwin.document.execCommand('strikethrough', false, null); 
    645      this.iwin.focus(); 
     610  this.iwin.document.execCommand('strikethrough', false, null); 
     611  this.iwin.focus(); 
    646612}; 
    647613 
    648614jsToolBar.prototype.elements.quote.fn.wysiwyg = function() { 
    649      var n = this.getSelectedNode(); 
    650      var q = this.iwin.document.createElement('q'); 
    651      q.appendChild(n); 
    652      this.insertNode(q); 
     615  var n = this.getSelectedNode(); 
     616  var q = this.iwin.document.createElement('q'); 
     617  q.appendChild(n); 
     618  this.insertNode(q); 
    653619}; 
    654620 
    655621jsToolBar.prototype.elements.code.fn.wysiwyg = function() { 
    656      var n = this.getSelectedNode(); 
    657      var code = this.iwin.document.createElement('code'); 
    658      code.appendChild(n); 
    659      this.insertNode(code); 
     622  var n = this.getSelectedNode(); 
     623  var code = this.iwin.document.createElement('code'); 
     624  code.appendChild(n); 
     625  this.insertNode(code); 
    660626}; 
    661627 
    662628jsToolBar.prototype.elements.mark.fn.wysiwyg = function() { 
    663      var n = this.getSelectedNode(); 
    664      var mark = this.iwin.document.createElement('mark'); 
    665      mark.appendChild(n); 
    666      this.insertNode(mark); 
     629  var n = this.getSelectedNode(); 
     630  var mark = this.iwin.document.createElement('mark'); 
     631  mark.appendChild(n); 
     632  this.insertNode(mark); 
    667633}; 
    668634 
    669635jsToolBar.prototype.elements.br.fn.wysiwyg = function() { 
    670      var n = this.iwin.document.createElement('br'); 
    671      this.insertNode(n); 
     636  var n = this.iwin.document.createElement('br'); 
     637  this.insertNode(n); 
    672638}; 
    673639 
    674640jsToolBar.prototype.elements.blockquote.fn.wysiwyg = function() { 
    675      var n = this.getSelectedNode(); 
    676      var q = this.iwin.document.createElement('blockquote'); 
    677      q.appendChild(n); 
    678      this.insertNode(q); 
     641  var n = this.getSelectedNode(); 
     642  var q = this.iwin.document.createElement('blockquote'); 
     643  q.appendChild(n); 
     644  this.insertNode(q); 
    679645}; 
    680646 
    681647jsToolBar.prototype.elements.pre.fn.wysiwyg = function() { 
    682      this.iwin.document.execCommand('formatblock',false,'<pre>'); 
    683      this.iwin.focus(); 
     648  this.iwin.document.execCommand('formatblock', false, '<pre>'); 
     649  this.iwin.focus(); 
    684650}; 
    685651 
    686652jsToolBar.prototype.elements.ul.fn.wysiwyg = function() { 
    687      this.iwin.document.execCommand('insertunorderedlist',false,null); 
    688      this.iwin.focus(); 
     653  this.iwin.document.execCommand('insertunorderedlist', false, null); 
     654  this.iwin.focus(); 
    689655}; 
    690656 
    691657jsToolBar.prototype.elements.ol.fn.wysiwyg = function() { 
    692      this.iwin.document.execCommand('insertorderedlist',false,null); 
    693      this.iwin.focus(); 
     658  this.iwin.document.execCommand('insertorderedlist', false, null); 
     659  this.iwin.focus(); 
    694660}; 
    695661 
    696662jsToolBar.prototype.elements.link.fn.wysiwyg = function() { 
    697      var href, hreflang; 
    698      var range, commonAncestorContainer; 
    699      if (this.iwin.getSelection) { //gecko 
    700           var selection = this.iwin.getSelection(); 
    701           range = selection.getRangeAt(0); 
    702           commonAncestorContainer = range.commonAncestorContainer; 
    703           while (commonAncestorContainer.nodeType != 1) { 
    704                commonAncestorContainer = commonAncestorContainer.parentNode; 
    705           } 
    706      } else { //ie 
    707           range = this.iwin.document.selection.createRange(); 
    708           commonAncestorContainer = range.parentElement(); 
    709      } 
    710  
    711      var ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); 
    712      while (ancestorTagName!='a' && ancestorTagName!='body') { 
    713           commonAncestorContainer = commonAncestorContainer.parentNode; 
    714           ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); 
    715      } 
    716  
    717      // Update or remove link? 
    718      if (ancestorTagName == 'a') { 
    719           href = commonAncestorContainer.href || ''; 
    720           hreflang = commonAncestorContainer.hreflang || ''; 
    721      } 
    722  
    723      href = window.prompt(this.elements.link.href_prompt,href); 
    724  
    725      // Remove link 
    726      if (ancestorTagName == 'a' && href=='') { 
    727           this.replaceNodeByContent(commonAncestorContainer); 
    728      } 
    729      if (!href) return; // user cancel 
    730  
    731      hreflang = window.prompt(this.elements.link.hreflang_prompt, hreflang); 
    732  
    733      // Update link 
    734      if (ancestorTagName == 'a' && href) { 
    735           commonAncestorContainer.setAttribute('href', href); 
    736           if (hreflang) { 
    737                commonAncestorContainer.setAttribute('hreflang', hreflang); 
    738           } else { 
    739                commonAncestorContainer.removeAttribute('hreflang'); 
    740           } 
    741           return; 
    742      } 
    743  
    744      // Create link 
    745      var n = this.getSelectedNode(); 
    746      var a = this.iwin.document.createElement('a'); 
    747      a.href = href; 
    748      if (hreflang) a.setAttribute('hreflang',hreflang); 
    749      a.appendChild(n); 
    750      this.insertNode(a); 
    751 }; 
    752  
    753  
     663  var href, hreflang; 
     664  var range, commonAncestorContainer; 
     665  if (this.iwin.getSelection) { //gecko 
     666    var selection = this.iwin.getSelection(); 
     667    range = selection.getRangeAt(0); 
     668    commonAncestorContainer = range.commonAncestorContainer; 
     669    while (commonAncestorContainer.nodeType != 1) { 
     670      commonAncestorContainer = commonAncestorContainer.parentNode; 
     671    } 
     672  } else { //ie 
     673    range = this.iwin.document.selection.createRange(); 
     674    commonAncestorContainer = range.parentElement(); 
     675  } 
     676 
     677  var ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); 
     678  while (ancestorTagName != 'a' && ancestorTagName != 'body') { 
     679    commonAncestorContainer = commonAncestorContainer.parentNode; 
     680    ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); 
     681  } 
     682 
     683  // Update or remove link? 
     684  if (ancestorTagName == 'a') { 
     685    href = commonAncestorContainer.href || ''; 
     686    hreflang = commonAncestorContainer.hreflang || ''; 
     687  } 
     688 
     689  href = window.prompt(this.elements.link.href_prompt, href); 
     690 
     691  // Remove link 
     692  if (ancestorTagName == 'a' && href == '') { 
     693    this.replaceNodeByContent(commonAncestorContainer); 
     694  } 
     695  if (!href) return; // user cancel 
     696 
     697  hreflang = window.prompt(this.elements.link.hreflang_prompt, hreflang); 
     698 
     699  // Update link 
     700  if (ancestorTagName == 'a' && href) { 
     701    commonAncestorContainer.setAttribute('href', href); 
     702    if (hreflang) { 
     703      commonAncestorContainer.setAttribute('hreflang', hreflang); 
     704    } else { 
     705      commonAncestorContainer.removeAttribute('hreflang'); 
     706    } 
     707    return; 
     708  } 
     709 
     710  // Create link 
     711  var n = this.getSelectedNode(); 
     712  var a = this.iwin.document.createElement('a'); 
     713  a.href = href; 
     714  if (hreflang) a.setAttribute('hreflang', hreflang); 
     715  a.appendChild(n); 
     716  this.insertNode(a); 
     717}; 
    754718 
    755719// Remove format and Toggle 
    756720jsToolBar.prototype.elements.removeFormat = { 
    757      type: 'button', 
    758      title: 'Remove text formating', 
    759      fn: {} 
     721  type: 'button', 
     722  title: 'Remove text formating', 
     723  fn: {} 
    760724}; 
    761725jsToolBar.prototype.elements.removeFormat.disabled = !jsToolBar.prototype.can_wwg; 
    762726jsToolBar.prototype.elements.removeFormat.fn.xhtml = function() { 
    763      var html = this.textarea.value; 
    764      html = this.removeTextFormating(html); 
    765      this.textarea.value = html; 
     727  var html = this.textarea.value; 
     728  html = this.removeTextFormating(html); 
     729  this.textarea.value = html; 
    766730}; 
    767731jsToolBar.prototype.elements.removeFormat.fn.wysiwyg = function() { 
    768      var html = this.iwin.document.body.innerHTML; 
    769      html = this.removeTextFormating(html); 
    770      this.iwin.document.body.innerHTML = html; 
     732  var html = this.iwin.document.body.innerHTML; 
     733  html = this.removeTextFormating(html); 
     734  this.iwin.document.body.innerHTML = html; 
    771735}; 
    772736/** Utilities 
    773737-------------------------------------------------------- */ 
    774 function arrayIndexOf(aArray, aValue){ 
    775      if (typeof Array.indexOf == 'function') { 
    776           return aArray.indexOf(aValue); 
    777      } else { 
    778           var index = -1; 
    779           var l = aArray.length; 
    780           for (var i = 0; i < l ; i++) { 
    781                if (aArray[i] === aValue) { 
    782                     index = i; 
    783                     break; 
    784                } 
    785           } 
    786           return index; 
    787      } 
    788 }; 
     738function arrayIndexOf(aArray, aValue) { 
     739  if (typeof Array.indexOf == 'function') { 
     740    return aArray.indexOf(aValue); 
     741  } else { 
     742    var index = -1; 
     743    var l = aArray.length; 
     744    for (var i = 0; i < l; i++) { 
     745      if (aArray[i] === aValue) { 
     746        index = i; 
     747        break; 
     748      } 
     749    } 
     750    return index; 
     751  } 
     752} 
     753 
    789754function addEvent(obj, evType, fn, useCapture) { 
    790      if (obj.addEventListener){ 
    791           obj.addEventListener(evType, fn, useCapture); 
    792           return true; 
    793      } else if (obj.attachEvent){ 
    794           var r = obj.attachEvent("on"+evType, fn); 
    795           return r; 
    796      } else { 
    797           return false; 
    798      } 
    799 }; 
     755  if (obj.addEventListener) { 
     756    obj.addEventListener(evType, fn, useCapture); 
     757    return true; 
     758  } else if (obj.attachEvent) { 
     759    var r = obj.attachEvent("on" + evType, fn); 
     760    return r; 
     761  } else { 
     762    return false; 
     763  } 
     764} 
     765 
    800766function removeEvent(obj, evType, fn, useCapture) { 
    801      if (obj.removeEventListener){ 
    802           obj.removeEventListener(evType, fn, useCapture); 
    803           return true; 
    804      } else if (obj.detachEvent){ 
    805           var r = obj.detachEvent("on"+evType, fn); 
    806           return r; 
    807      } else { 
    808           return false; 
    809   } 
    810 }; 
     767  if (obj.removeEventListener) { 
     768    obj.removeEventListener(evType, fn, useCapture); 
     769    return true; 
     770  } else if (obj.detachEvent) { 
     771    var r = obj.detachEvent("on" + evType, fn); 
     772    return r; 
     773  } else { 
     774    return false; 
     775  } 
     776} 
     777 
    811778function regexpEscape(s) { 
    812      return s.replace(/([\\\^\$*+[\]?{}.=!:(|)])/g,"\\$1") 
    813 }; 
     779  return s.replace(/([\\\^\$*+[\]?{}.=!:(|)])/g, "\\$1"); 
     780} 
  • plugins/dcLegacyEditor/js/jsToolBar/popup_link.js

    r2614 r3735  
     1/*global $ */ 
     2'use strict'; 
     3 
    14$(function() { 
    25     $('#link-insert-cancel').click(function() { 
  • plugins/dcLegacyEditor/js/jsToolBar/popup_posts.js

    r2614 r3735  
     1/*global $ */ 
     2'use strict'; 
     3 
    14$(function() { 
    25     $('#link-insert-cancel').click(function() { 
Note: See TracChangeset for help on using the changeset viewer.

Sites map