b2evolution PHP Cross Reference Blogging Systems

Source: /plugins/tinymce_plugin/tiny_mce/themes/advanced/js/image.js - 251 lines - 6074 bytes - Text - Print

   1  var ImageDialog = {
   2      preInit : function() {
   3          var url;
   4  
   5          tinyMCEPopup.requireLangPack();
   6  
   7          if (url = tinyMCEPopup.getParam("external_image_list_url"))
   8              document.write('<script language="javascript" type="text/javascript" src="' + tinyMCEPopup.editor.documentBaseURI.toAbsolute(url) + '"></script>');
   9      },
  10  
  11      init : function() {
  12          var f = document.forms[0], ed = tinyMCEPopup.editor;
  13  
  14          // Setup browse button
  15          document.getElementById('srcbrowsercontainer').innerHTML = getBrowserHTML('srcbrowser','src','image','theme_advanced_image');
  16          if (isVisible('srcbrowser'))
  17              document.getElementById('src').style.width = '180px';
  18  
  19          e = ed.selection.getNode();
  20  
  21          this.fillFileList('image_list', tinyMCEPopup.getParam('external_image_list', 'tinyMCEImageList'));
  22  
  23          if (e.nodeName == 'IMG') {
  24              f.src.value = ed.dom.getAttrib(e, 'src');
  25              f.alt.value = ed.dom.getAttrib(e, 'alt');
  26              f.border.value = this.getAttrib(e, 'border');
  27              f.vspace.value = this.getAttrib(e, 'vspace');
  28              f.hspace.value = this.getAttrib(e, 'hspace');
  29              f.width.value = ed.dom.getAttrib(e, 'width');
  30              f.height.value = ed.dom.getAttrib(e, 'height');
  31              f.insert.value = ed.getLang('update');
  32              this.styleVal = ed.dom.getAttrib(e, 'style');
  33              selectByValue(f, 'image_list', f.src.value);
  34              selectByValue(f, 'align', this.getAttrib(e, 'align'));
  35              this.updateStyle();
  36          }
  37      },
  38  
  39      fillFileList : function(id, l) {
  40          var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
  41  
  42          l = typeof(l) === 'function' ? l() : window[l];
  43  
  44          if (l && l.length > 0) {
  45              lst.options[lst.options.length] = new Option('', '');
  46  
  47              tinymce.each(l, function(o) {
  48                  lst.options[lst.options.length] = new Option(o[0], o[1]);
  49              });
  50          } else
  51              dom.remove(dom.getParent(id, 'tr'));
  52      },
  53  
  54      update : function() {
  55          var f = document.forms[0], nl = f.elements, ed = tinyMCEPopup.editor, args = {}, el;
  56  
  57          tinyMCEPopup.restoreSelection();
  58  
  59          if (f.src.value === '') {
  60              if (ed.selection.getNode().nodeName == 'IMG') {
  61                  ed.dom.remove(ed.selection.getNode());
  62                  ed.execCommand('mceRepaint');
  63              }
  64  
  65              tinyMCEPopup.close();
  66              return;
  67          }
  68  
  69          if (!ed.settings.inline_styles) {
  70              args = tinymce.extend(args, {
  71                  vspace : nl.vspace.value,
  72                  hspace : nl.hspace.value,
  73                  border : nl.border.value,
  74                  align : getSelectValue(f, 'align')
  75              });
  76          } else
  77              args.style = this.styleVal;
  78  
  79          tinymce.extend(args, {
  80              src : f.src.value.replace(/ /g, '%20'),
  81              alt : f.alt.value,
  82              width : f.width.value,
  83              height : f.height.value
  84          });
  85  
  86          el = ed.selection.getNode();
  87  
  88          if (el && el.nodeName == 'IMG') {
  89              ed.dom.setAttribs(el, args);
  90              tinyMCEPopup.editor.execCommand('mceRepaint');
  91              tinyMCEPopup.editor.focus();
  92          } else {
  93              tinymce.each(args, function(value, name) {
  94                  if (value === "") {
  95                      delete args[name];
  96                  }
  97              });
  98  
  99              ed.execCommand('mceInsertContent', false, tinyMCEPopup.editor.dom.createHTML('img', args), {skip_undo : 1});
 100              ed.undoManager.add();
 101          }
 102  
 103          tinyMCEPopup.close();
 104      },
 105  
 106      updateStyle : function() {
 107          var dom = tinyMCEPopup.dom, st, v, f = document.forms[0];
 108  
 109          if (tinyMCEPopup.editor.settings.inline_styles) {
 110              st = tinyMCEPopup.dom.parseStyle(this.styleVal);
 111  
 112              // Handle align
 113              v = getSelectValue(f, 'align');
 114              if (v) {
 115                  if (v == 'left' || v == 'right') {
 116                      st['float'] = v;
 117                      delete st['vertical-align'];
 118                  } else {
 119                      st['vertical-align'] = v;
 120                      delete st['float'];
 121                  }
 122              } else {
 123                  delete st['float'];
 124                  delete st['vertical-align'];
 125              }
 126  
 127              // Handle border
 128              v = f.border.value;
 129              if (v || v == '0') {
 130                  if (v == '0')
 131                      st['border'] = '0';
 132                  else
 133                      st['border'] = v + 'px solid black';
 134              } else
 135                  delete st['border'];
 136  
 137              // Handle hspace
 138              v = f.hspace.value;
 139              if (v) {
 140                  delete st['margin'];
 141                  st['margin-left'] = v + 'px';
 142                  st['margin-right'] = v + 'px';
 143              } else {
 144                  delete st['margin-left'];
 145                  delete st['margin-right'];
 146              }
 147  
 148              // Handle vspace
 149              v = f.vspace.value;
 150              if (v) {
 151                  delete st['margin'];
 152                  st['margin-top'] = v + 'px';
 153                  st['margin-bottom'] = v + 'px';
 154              } else {
 155                  delete st['margin-top'];
 156                  delete st['margin-bottom'];
 157              }
 158  
 159              // Merge
 160              st = tinyMCEPopup.dom.parseStyle(dom.serializeStyle(st), 'img');
 161              this.styleVal = dom.serializeStyle(st, 'img');
 162          }
 163      },
 164  
 165      getAttrib : function(e, at) {
 166          var ed = tinyMCEPopup.editor, dom = ed.dom, v, v2;
 167  
 168          if (ed.settings.inline_styles) {
 169              switch (at) {
 170                  case 'align':
 171                      if (v = dom.getStyle(e, 'float'))
 172                          return v;
 173  
 174                      if (v = dom.getStyle(e, 'vertical-align'))
 175                          return v;
 176  
 177                      break;
 178  
 179                  case 'hspace':
 180                      v = dom.getStyle(e, 'margin-left')
 181                      v2 = dom.getStyle(e, 'margin-right');
 182                      if (v && v == v2)
 183                          return parseInt(v.replace(/[^0-9]/g, ''));
 184  
 185                      break;
 186  
 187                  case 'vspace':
 188                      v = dom.getStyle(e, 'margin-top')
 189                      v2 = dom.getStyle(e, 'margin-bottom');
 190                      if (v && v == v2)
 191                          return parseInt(v.replace(/[^0-9]/g, ''));
 192  
 193                      break;
 194  
 195                  case 'border':
 196                      v = 0;
 197  
 198                      tinymce.each(['top', 'right', 'bottom', 'left'], function(sv) {
 199                          sv = dom.getStyle(e, 'border-' + sv + '-width');
 200  
 201                          // False or not the same as prev
 202                          if (!sv || (sv != v && v !== 0)) {
 203                              v = 0;
 204                              return false;
 205                          }
 206  
 207                          if (sv)
 208                              v = sv;
 209                      });
 210  
 211                      if (v)
 212                          return parseInt(v.replace(/[^0-9]/g, ''));
 213  
 214                      break;
 215              }
 216          }
 217  
 218          if (v = dom.getAttrib(e, at))
 219              return v;
 220  
 221          return '';
 222      },
 223  
 224      resetImageData : function() {
 225          var f = document.forms[0];
 226  
 227          f.width.value = f.height.value = "";    
 228      },
 229  
 230      updateImageData : function() {
 231          var f = document.forms[0], t = ImageDialog;
 232  
 233          if (f.width.value == "")
 234              f.width.value = t.preloadImg.width;
 235  
 236          if (f.height.value == "")
 237              f.height.value = t.preloadImg.height;
 238      },
 239  
 240      getImageData : function() {
 241          var f = document.forms[0];
 242  
 243          this.preloadImg = new Image();
 244          this.preloadImg.onload = this.updateImageData;
 245          this.preloadImg.onerror = this.resetImageData;
 246          this.preloadImg.src = tinyMCEPopup.editor.documentBaseURI.toAbsolute(f.src.value);
 247      }
 248  };
 249  
 250  ImageDialog.preInit();
 251  tinyMCEPopup.onInit.add(ImageDialog.init, ImageDialog);

title

Description

title

Description

title

Description

title

title

Body