[ Index ]

PHP Cross Reference of Wordpress 2.7.1

title

Body

[close]

/wp-includes/js/tinymce/plugins/wordpress/ -> editor_plugin.js (source)

   1  /**
   2   * WordPress plugin.
   3   */
   4  
   5  (function() {
   6      var DOM = tinymce.DOM;
   7  
   8      // Load plugin specific language pack
   9      tinymce.PluginManager.requireLangPack('wordpress');
  10  
  11      tinymce.create('tinymce.plugins.WordPress', {
  12          init : function(ed, url) {
  13              var t = this, tbId = ed.getParam('wordpress_adv_toolbar', 'toolbar2');
  14              var moreHTML = '<img src="' + url + '/img/trans.gif" class="mceWPmore mceItemNoResize" title="'+ed.getLang('wordpress.wp_more_alt')+'" />';
  15              var nextpageHTML = '<img src="' + url + '/img/trans.gif" class="mceWPnextpage mceItemNoResize" title="'+ed.getLang('wordpress.wp_page_alt')+'" />';
  16  
  17              if ( getUserSetting('hidetb', '0') == '1' )
  18                  ed.settings.wordpress_adv_hidden = 0;
  19  
  20              // Hides the specified toolbar and resizes the iframe
  21              ed.onPostRender.add(function() {
  22                  if ( ed.getParam('wordpress_adv_hidden', 1) ) {
  23                      DOM.hide(ed.controlManager.get(tbId).id);
  24                      t._resizeIframe(ed, tbId, 28);
  25                  }
  26              });
  27  
  28              // Register commands
  29              ed.addCommand('WP_More', function() {
  30                  ed.execCommand('mceInsertContent', 0, moreHTML);
  31              });
  32  
  33              ed.addCommand('WP_Page', function() {
  34                  ed.execCommand('mceInsertContent', 0, nextpageHTML);
  35              });
  36  
  37              ed.addCommand('WP_Help', function() {
  38                      ed.windowManager.open({
  39                          url : tinymce.baseURL + '/wp-mce-help.php',
  40                          width : 450,
  41                          height : 420,
  42                          inline : 1
  43                      });
  44                  });
  45  
  46              ed.addCommand('WP_Adv', function() {
  47                  var id = ed.controlManager.get(tbId).id, cm = ed.controlManager;
  48  
  49                  if (DOM.isHidden(id)) {
  50                      cm.setActive('wp_adv', 1);
  51                      DOM.show(id);
  52                      t._resizeIframe(ed, tbId, -28);
  53                      ed.settings.wordpress_adv_hidden = 0;
  54                      setUserSetting('hidetb', '1');
  55                  } else {
  56                      cm.setActive('wp_adv', 0);
  57                      DOM.hide(id);
  58                      t._resizeIframe(ed, tbId, 28);
  59                      ed.settings.wordpress_adv_hidden = 1;
  60                      setUserSetting('hidetb', '0');
  61                  }
  62              });
  63  
  64              // Register buttons
  65              ed.addButton('wp_more', {
  66                  title : 'wordpress.wp_more_desc',
  67                  image : url + '/img/more.gif',
  68                  cmd : 'WP_More'
  69              });
  70  
  71              ed.addButton('wp_page', {
  72                  title : 'wordpress.wp_page_desc',
  73                  image : url + '/img/page.gif',
  74                  cmd : 'WP_Page'
  75              });
  76  
  77              ed.addButton('wp_help', {
  78                  title : 'wordpress.wp_help_desc',
  79                  image : url + '/img/help.gif',
  80                  cmd : 'WP_Help'
  81              });
  82  
  83              ed.addButton('wp_adv', {
  84                  title : 'wordpress.wp_adv_desc',
  85                  image : url + '/img/toolbars.gif',
  86                  cmd : 'WP_Adv'
  87              });
  88  
  89              // Add Media buttons
  90              ed.addButton('add_media', {
  91                  title : 'wordpress.add_media',
  92                  image : url + '/img/media.gif',
  93                  onclick : function() {
  94                      tb_show('', tinymce.DOM.get('add_media').href);
  95                      tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
  96                  }
  97              });
  98  
  99              ed.addButton('add_image', {
 100                  title : 'wordpress.add_image',
 101                  image : url + '/img/image.gif',
 102                  onclick : function() {
 103                      tb_show('', tinymce.DOM.get('add_image').href);
 104                      tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
 105                  }
 106              });
 107  
 108              ed.addButton('add_video', {
 109                  title : 'wordpress.add_video',
 110                  image : url + '/img/video.gif',
 111                  onclick : function() {
 112                      tb_show('', tinymce.DOM.get('add_video').href);
 113                      tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
 114                  }
 115              });
 116  
 117              ed.addButton('add_audio', {
 118                  title : 'wordpress.add_audio',
 119                  image : url + '/img/audio.gif',
 120                  onclick : function() {
 121                      tb_show('', tinymce.DOM.get('add_audio').href);
 122                      tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
 123                  }
 124              });
 125  
 126              // Add Media buttons to fullscreen
 127              ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) {
 128                  if ( 'mceFullScreen' != cmd ) return;
 129                  if ( 'mce_fullscreen' != ed.id )
 130                      ed.settings.theme_advanced_buttons1 += ',|,add_image,add_video,add_audio,add_media';
 131              });
 132  
 133              // Add class "alignleft", "alignright" and "aligncenter" when selecting align for images.
 134              ed.addCommand('JustifyLeft', function() {
 135                  var n = ed.selection.getNode();
 136  
 137                  if ( n.nodeName != 'IMG' )
 138                      ed.editorCommands.mceJustify('JustifyLeft', 'left');
 139                  else ed.plugins.wordpress.do_align(n, 'alignleft');
 140              });
 141  
 142              ed.addCommand('JustifyRight', function() {
 143                  var n = ed.selection.getNode();
 144  
 145                  if ( n.nodeName != 'IMG' )
 146                      ed.editorCommands.mceJustify('JustifyRight', 'right');
 147                  else ed.plugins.wordpress.do_align(n, 'alignright');
 148              });
 149  
 150              ed.addCommand('JustifyCenter', function() {
 151                  var n = ed.selection.getNode(), P = ed.dom.getParent(n, 'p'), DL = ed.dom.getParent(n, 'dl');
 152  
 153                  if ( n.nodeName == 'IMG' && ( P || DL ) )
 154                      ed.plugins.wordpress.do_align(n, 'aligncenter');
 155                  else ed.editorCommands.mceJustify('JustifyCenter', 'center');
 156              });
 157  
 158              // Word count if script is loaded
 159              if ( 'undefined' != typeof wpWordCount ) {
 160                  var last = 0;
 161                  ed.onKeyUp.add(function(ed, e) {
 162                      if ( e.keyCode == last ) return;
 163                      if ( 13 == e.keyCode || 8 == last || 46 == last ) wpWordCount.wc( ed.getContent({format : 'raw'}) );
 164                      last = e.keyCode;
 165                  });
 166              };
 167  
 168              // Add listeners to handle more break
 169              t._handleMoreBreak(ed, url);
 170  
 171              // Add custom shortcuts
 172              ed.addShortcut('alt+shift+c', ed.getLang('justifycenter_desc'), 'JustifyCenter');
 173              ed.addShortcut('alt+shift+r', ed.getLang('justifyright_desc'), 'JustifyRight');
 174              ed.addShortcut('alt+shift+l', ed.getLang('justifyleft_desc'), 'JustifyLeft');
 175              ed.addShortcut('alt+shift+j', ed.getLang('justifyfull_desc'), 'JustifyFull');
 176              ed.addShortcut('alt+shift+q', ed.getLang('blockquote_desc'), 'mceBlockQuote');
 177              ed.addShortcut('alt+shift+u', ed.getLang('bullist_desc'), 'InsertUnorderedList');
 178              ed.addShortcut('alt+shift+o', ed.getLang('numlist_desc'), 'InsertOrderedList');
 179              ed.addShortcut('alt+shift+d', ed.getLang('striketrough_desc'), 'Strikethrough');
 180              ed.addShortcut('alt+shift+n', ed.getLang('spellchecker.desc'), 'mceSpellCheck');
 181              ed.addShortcut('alt+shift+a', ed.getLang('link_desc'), 'mceLink');
 182              ed.addShortcut('alt+shift+s', ed.getLang('unlink_desc'), 'unlink');
 183              ed.addShortcut('alt+shift+m', ed.getLang('image_desc'), 'mceImage');
 184              ed.addShortcut('alt+shift+g', ed.getLang('fullscreen.desc'), 'mceFullScreen');
 185              ed.addShortcut('alt+shift+z', ed.getLang('wp_adv_desc'), 'WP_Adv');
 186              ed.addShortcut('alt+shift+h', ed.getLang('help_desc'), 'WP_Help');
 187              ed.addShortcut('alt+shift+t', ed.getLang('wp_more_desc'), 'WP_More');
 188              ed.addShortcut('alt+shift+p', ed.getLang('wp_page_desc'), 'WP_Page');
 189  
 190              if ( tinymce.isWebKit ) {
 191                  ed.addShortcut('alt+shift+b', ed.getLang('bold_desc'), 'Bold');
 192                  ed.addShortcut('alt+shift+i', ed.getLang('italic_desc'), 'Italic');
 193              }
 194          },
 195  
 196          getInfo : function() {
 197              return {
 198                  longname : 'WordPress Plugin',
 199                  author : 'WordPress', // add Moxiecode?
 200                  authorurl : 'http://wordpress.org',
 201                  infourl : 'http://wordpress.org',
 202                  version : '3.0'
 203              };
 204          },
 205  
 206          // Internal functions
 207          do_align : function(n, a) {
 208              var P, DL, DIV, cls, c, ed = tinyMCE.activeEditor;
 209  
 210              if ( /^(mceItemFlash|mceItemShockWave|mceItemWindowsMedia|mceItemQuickTime|mceItemRealMedia)$/.test(n.className) )
 211                  return;
 212  
 213              P = ed.dom.getParent(n, 'p');
 214              DL = ed.dom.getParent(n, 'dl');
 215              DIV = ed.dom.getParent(n, 'div');
 216  
 217              if ( DL && DIV ) {
 218                  cls = ed.dom.hasClass(DL, a) ? 'alignnone' : a;
 219                  DL.className = DL.className.replace(/align[^ '"]+\s?/g, '');
 220                  ed.dom.addClass(DL, cls);
 221                  c = (cls == 'aligncenter') ? ed.dom.addClass(DIV, 'mceIEcenter') : ed.dom.removeClass(DIV, 'mceIEcenter');
 222              } else if ( P ) {
 223                  cls = ed.dom.hasClass(n, a) ? 'alignnone' : a;
 224                  n.className = n.className.replace(/align[^ '"]+\s?/g, '');
 225                  ed.dom.addClass(n, cls);
 226                  if ( cls == 'aligncenter' )
 227                      ed.dom.setStyle(P, 'textAlign', 'center');
 228                  else if (P.style && P.style.textAlign == 'center')
 229                      ed.dom.setStyle(P, 'textAlign', '');
 230              }
 231  
 232              ed.execCommand('mceRepaint');
 233          },
 234  
 235          // Resizes the iframe by a relative height value
 236          _resizeIframe : function(ed, tb_id, dy) {
 237              var ifr = ed.getContentAreaContainer().firstChild;
 238  
 239              DOM.setStyle(ifr, 'height', ifr.clientHeight + dy); // Resize iframe
 240              ed.theme.deltaHeight += dy; // For resize cookie
 241          },
 242  
 243          _handleMoreBreak : function(ed, url) {
 244              var moreHTML = '<img src="' + url + '/img/trans.gif" alt="$1" class="mceWPmore mceItemNoResize" title="'+ed.getLang('wordpress.wp_more_alt')+'" />';
 245              var nextpageHTML = '<img src="' + url + '/img/trans.gif" class="mceWPnextpage mceItemNoResize" title="'+ed.getLang('wordpress.wp_page_alt')+'" />';
 246  
 247              // Load plugin specific CSS into editor
 248              ed.onInit.add(function() {
 249                  ed.dom.loadCSS(url + '/css/content.css');
 250              });
 251  
 252              // Display morebreak instead if img in element path
 253              ed.onPostRender.add(function() {
 254                  if (ed.theme.onResolveName) {
 255                      ed.theme.onResolveName.add(function(th, o) {
 256                          if (o.node.nodeName == 'IMG') {
 257                              if ( ed.dom.hasClass(o.node, 'mceWPmore') )
 258                                  o.name = 'wpmore';
 259                              if ( ed.dom.hasClass(o.node, 'mceWPnextpage') )
 260                                  o.name = 'wppage';
 261                          }
 262  
 263                      });
 264                  }
 265              });
 266  
 267              // Replace morebreak with images
 268              ed.onBeforeSetContent.add(function(ed, o) {
 269                  o.content = o.content.replace(/<!--more(.*?)-->/g, moreHTML);
 270                  o.content = o.content.replace(/<!--nextpage-->/g, nextpageHTML);
 271              });
 272  
 273              // Replace images with morebreak
 274              ed.onPostProcess.add(function(ed, o) {
 275                  if (o.get)
 276                      o.content = o.content.replace(/<img[^>]+>/g, function(im) {
 277                          if (im.indexOf('class="mceWPmore') !== -1) {
 278                              var m, moretext = (m = im.match(/alt="(.*?)"/)) ? m[1] : '';
 279                              im = '<!--more'+moretext+'-->';
 280                          }
 281                          if (im.indexOf('class="mceWPnextpage') !== -1)
 282                              im = '<!--nextpage-->';
 283  
 284                          return im;
 285                      });
 286              });
 287  
 288              // Set active buttons if user selected pagebreak or more break
 289              ed.onNodeChange.add(function(ed, cm, n) {
 290                  cm.setActive('wp_page', n.nodeName === 'IMG' && ed.dom.hasClass(n, 'mceWPnextpage'));
 291                  cm.setActive('wp_more', n.nodeName === 'IMG' && ed.dom.hasClass(n, 'mceWPmore'));
 292              });
 293          }
 294      });
 295  
 296      // Register plugin
 297      tinymce.PluginManager.add('wordpress', tinymce.plugins.WordPress);
 298  })();


Generated: Mon Mar 23 16:23:02 2009 Cross-referenced by PHPXref 0.7