[ Index ]
 

Code source de Plume CMS 1.2.2

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/manager/tools/visualedit/js/ -> jsToolBar.dotclear.js (source)

   1  /* Change link button actions
   2  -------------------------------------------------------- */
   3  jsToolBar.prototype.elements.link.data = {};
   4  jsToolBar.prototype.elements.link.fncall = {};
   5  jsToolBar.prototype.elements.link.open_url = 'tools/visualedit/index.php';
   6  
   7  jsToolBar.prototype.elements.link.popup = function (args) {
   8      window.the_toolbar = this;
   9      args = args || '';
  10      
  11      var url = this.elements.link.open_url+args;
  12      
  13      var p_win = window.open(url,'dc_popup',
  14      'alwaysRaised=yes,dependent=yes,toolbar=yes,height=350,width=600,'+
  15      'menubar=no,resizable=yes,scrollbars=yes,status=no');
  16  };
  17  
  18  jsToolBar.prototype.elements.link.fn.wiki = function() {
  19      this.elements.link.popup.call(this,'?hreflang='+this.elements.link.default_hreflang);
  20  };
  21  jsToolBar.prototype.elements.link.fncall.wiki = function() {
  22      var data = this.elements.link.data;
  23      
  24      if (data.href == '') { return; }
  25      
  26      var etag = '|'+data.href;
  27      if (data.hreflang) { etag += '|'+data.hreflang; }
  28      
  29      if (data.title) {
  30          if (!data.hreflang) { etag += '|'; }
  31          etag += '|'+data.title;
  32      }
  33      
  34      this.encloseSelection('[',etag+']');
  35  };
  36  
  37  jsToolBar.prototype.elements.link.fn.xhtml = function() {
  38      this.elements.link.popup.call(this,'?hreflang='+this.elements.link.default_hreflang);
  39  };
  40  jsToolBar.prototype.elements.link.fncall.xhtml = function() {
  41      var data = this.elements.link.data;
  42      
  43      if (data.href == '') { return; }
  44      
  45      var stag = '<a href="'+data.href+'"';
  46      
  47      if (data.hreflang) { stag += ' hreflang="'+data.hreflang+'"'; }
  48      if (data.title) { stag += ' title="'+data.title+'"'; }
  49      stag += '>';
  50      var etag = '</a>';
  51      
  52      this.encloseSelection(stag,'</a>');
  53  };
  54  
  55  jsToolBar.prototype.elements.link.fn.wysiwyg = function() {
  56      var href, title, hreflang;
  57      href = title = hreflang = '';
  58      hreflang = this.elements.link.default_hreflang;
  59      
  60      var a = this.getAncestor();
  61      
  62      if (a.tagName == 'a') {
  63          href= a.tag.href || '';
  64          title = a.tag.title || '';
  65          hreflang = a.tag.hreflang || '';
  66      }
  67      
  68      this.elements.link.popup.call(this,'?href='+href+'&hreflang='+hreflang+'&title='+title);
  69  };
  70  jsToolBar.prototype.elements.link.fncall.wysiwyg = function() {
  71      var data = this.elements.link.data;
  72      var a = this.getAncestor();
  73      
  74      if (a.tagName == 'a') {
  75          if (data.href == '') {
  76              // Remove link
  77              this.iwin.document.execCommand('unlink',false,null);
  78              this.iwin.focus();
  79              return;
  80          } else {
  81              // Update link
  82              a.tag.href = data.href;
  83              if (data.hreflang) {
  84                  a.tag.setAttribute('hreflang',data.hreflang);
  85              } else {
  86                  a.tag.removeAttribute('hreflang');
  87              }
  88              if (data.title) {
  89                  a.tag.setAttribute('title',data.title);
  90              } else {
  91                  a.tag.removeAttribute('title');
  92              }
  93              return;
  94          }
  95      }
  96      
  97      // Create link
  98      var n = this.getSelectedNode();
  99      var a = this.iwin.document.createElement('a');
 100      a.href = data.href;
 101      if (data.title) a.setAttribute('title',data.title);
 102      if (data.hreflang) a.setAttribute('hreflang',data.hreflang);
 103      a.appendChild(n);
 104      this.insertNode(a);
 105  };
 106  jsToolBar.prototype.getAncestor = function() {
 107      var res = {};
 108      var range, commonAncestorContainer;
 109      
 110      if (this.iwin.getSelection) { //gecko
 111          var selection = this.iwin.getSelection();
 112          range = selection.getRangeAt(0);
 113          commonAncestorContainer = range.commonAncestorContainer;
 114          while (commonAncestorContainer.nodeType != 1) {
 115              commonAncestorContainer = commonAncestorContainer.parentNode;
 116          }
 117      } else { //ie
 118          range = this.iwin.document.selection.createRange();
 119          commonAncestorContainer = range.parentElement();
 120      }
 121      
 122      var ancestorTagName = commonAncestorContainer.tagName.toLowerCase();
 123      while (ancestorTagName!='a' && ancestorTagName!='body') {
 124          commonAncestorContainer = commonAncestorContainer.parentNode;
 125          ancestorTagName = commonAncestorContainer.tagName.toLowerCase();
 126      }
 127      
 128      res.tag = commonAncestorContainer
 129      res.tagName = ancestorTagName;
 130      
 131      return res;
 132  };
 133  
 134  /* Image selector
 135  -------------------------------------------------------- */
 136  jsToolBar.prototype.elements.img_select = {
 137      type: 'button',
 138      title: 'Image chooser',
 139      fn: {},
 140      fncall: {},
 141      open_url: 'xmedia.php?mode=popup',
 142      data: {},
 143      popup: function() {
 144          window.the_toolbar = this;
 145          var p_win = window.open(this.elements.img_select.open_url,'dc_popup',
 146          'alwaysRaised=yes,dependent=yes,toolbar=yes,height=500,width=760,'+
 147          'menubar=no,resizable=yes,scrollbars=yes,status=no');
 148      }
 149  };
 150  jsToolBar.prototype.elements.img_select.fn.wiki = function() {
 151      this.elements.img_select.popup.call(this);
 152  };
 153  jsToolBar.prototype.elements.img_select.fncall.wiki = function() {
 154      var d = this.elements.img_select.data;
 155      if (d.src == undefined) { return; }
 156      
 157      this.encloseSelection('','',function(str) {
 158          var alt = (str) ? str : d.title;
 159          var res = '(('+d.src+'|'+alt;
 160          
 161          if (d.alignment == 'left') {
 162              res += '|L';
 163          } else if (d.alignment == 'right') {
 164              res += '|R';
 165          }
 166          res += '))';
 167          
 168          if (d.link) {
 169              res = '['+res+'|'+d.url+']';
 170          }
 171          
 172          return res;
 173      });
 174  };
 175  jsToolBar.prototype.elements.img_select.fn.xhtml = function() {
 176      this.elements.img_select.popup.call(this);
 177  };
 178  jsToolBar.prototype.elements.img_select.fncall.xhtml = function() {
 179      var d = this.elements.img_select.data;
 180      if (d.src == undefined) { return; }
 181      
 182      this.encloseSelection('','',function(str) {
 183          var alt = (str) ? str : d.title;
 184          var res = '<img src="'+d.src+'" alt="'+alt+'"';
 185          
 186          if (d.alignment == 'left') {
 187              res += ' style="float: left; margin: 0 1em 1em 0;"';
 188          } else if (d.alignment == 'right') {
 189              res += ' style="float: right; margin: 0 0 1em 1em;"';
 190          }
 191          res += ' />';
 192          
 193          if (d.link) {
 194              res = '<a href="'+d.url+'">'+res+'</a>';
 195          }
 196          
 197          return res;
 198      });
 199  };
 200  
 201  jsToolBar.prototype.elements.img.fn.wysiwyg = function() {
 202      var src = this.elements.img.prompt.call(this);
 203      if (!src) { return; }
 204      
 205      var img = this.iwin.document.createElement('img');
 206      img.src = src;
 207      img.setAttribute('alt',this.getSelectedText());
 208      
 209      this.insertNode(img);
 210  };
 211  
 212  jsToolBar.prototype.elements.img_select.fn.wysiwyg = function() {
 213      this.elements.img_select.popup.call(this);
 214  };
 215  jsToolBar.prototype.elements.img_select.fncall.wysiwyg = function() {
 216      var d = this.elements.img_select.data;
 217      if (d.src == undefined) { return; }
 218      
 219      var img = this.iwin.document.createElement('img');
 220      img.src = d.src;
 221      img.setAttribute('alt',this.getSelectedText());
 222      
 223      
 224      if (d.alignment == 'left') {
 225          if (img.style.styleFloat != undefined) {
 226              img.style.styleFloat = 'left';
 227          } else {
 228              img.style.cssFloat = 'left';
 229          }
 230          img.style.marginTop = 0;
 231          img.style.marginRight = '1em';
 232          img.style.marginBottom = '1em';
 233          img.style.marginLeft = 0;
 234      } else if (d.alignment == 'right') {
 235          if (img.style.styleFloat != undefined) {
 236              img.style.styleFloat = 'right';
 237          } else {
 238              img.style.cssFloat = 'right';
 239          }
 240          img.style.marginTop = 0;
 241          img.style.marginRight = 0;
 242          img.style.marginBottom = '1em';
 243          img.style.marginLeft = '1em';
 244      }
 245      
 246      if (d.link) {
 247          var a = this.iwin.document.createElement('a');
 248          a.href = d.url;
 249          a.appendChild(img);
 250          this.insertNode(a);
 251      } else {
 252          this.insertNode(img);
 253      }
 254  };
 255  
 256  // Last space element
 257  jsToolBar.prototype.elements.space3 = {type: 'space'}


Généré le : Mon Nov 26 11:57:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics