[ Index ]

PHP Cross Reference of Wordpress 2.9.1

title

Body

[close]

/wp-admin/js/ -> editor.dev.js (source)

   1  
   2  jQuery(document).ready(function($){
   3      var h = wpCookies.getHash('TinyMCE_content_size');
   4  
   5      if ( getUserSetting( 'editor' ) == 'html' ) {
   6          if ( h )
   7              $('#content').css('height', h.ch - 15 + 'px');
   8      } else {
   9          if ( typeof tinyMCE != 'object' ) {
  10              $('#content').css('color', '#000');
  11          } else {
  12              $('#quicktags').hide();
  13          }
  14      }
  15  });
  16  
  17  var switchEditors = {
  18  
  19      mode : '',
  20  
  21      I : function(e) {
  22          return document.getElementById(e);
  23      },
  24  
  25      _wp_Nop : function(content) {
  26          var blocklist1, blocklist2;
  27  
  28          // Protect pre|script tags
  29          content = content.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) {
  30              a = a.replace(/<br ?\/?>[\r\n]*/g, '<wp_temp>');
  31              return a.replace(/<\/?p( [^>]*)?>[\r\n]*/g, '<wp_temp>');
  32          });
  33  
  34          // Pretty it up for the source editor
  35          blocklist1 = 'blockquote|ul|ol|li|table|thead|tbody|tfoot|tr|th|td|div|h[1-6]|p|fieldset';
  36          content = content.replace(new RegExp('\\s*</('+blocklist1+')>\\s*', 'g'), '</$1>\n');
  37          content = content.replace(new RegExp('\\s*<(('+blocklist1+')[^>]*)>', 'g'), '\n<$1>');
  38  
  39          // Mark </p> if it has any attributes.
  40          content = content.replace(/(<p [^>]+>.*?)<\/p>/g, '$1</p#>');
  41  
  42          // Sepatate <div> containing <p>
  43          content = content.replace(/<div([^>]*)>\s*<p>/gi, '<div$1>\n\n');
  44  
  45          // Remove <p> and <br />
  46          content = content.replace(/\s*<p>/gi, '');
  47          content = content.replace(/\s*<\/p>\s*/gi, '\n\n');
  48          content = content.replace(/\n[\s\u00a0]+\n/g, '\n\n');
  49          content = content.replace(/\s*<br ?\/?>\s*/gi, '\n');
  50  
  51          // Fix some block element newline issues
  52          content = content.replace(/\s*<div/g, '\n<div');
  53          content = content.replace(/<\/div>\s*/g, '</div>\n');
  54          content = content.replace(/\s*\[caption([^\[]+)\[\/caption\]\s*/gi, '\n\n[caption$1[/caption]\n\n');
  55          content = content.replace(/caption\]\n\n+\[caption/g, 'caption]\n\n[caption');
  56  
  57          blocklist2 = 'blockquote|ul|ol|li|table|thead|tbody|tfoot|tr|th|td|h[1-6]|pre|fieldset';
  58          content = content.replace(new RegExp('\\s*<(('+blocklist2+') ?[^>]*)\\s*>', 'g'), '\n<$1>');
  59          content = content.replace(new RegExp('\\s*</('+blocklist2+')>\\s*', 'g'), '</$1>\n');
  60          content = content.replace(/<li([^>]*)>/g, '\t<li$1>');
  61  
  62          if ( content.indexOf('<object') != -1 ) {
  63              content = content.replace(/<object[\s\S]+?<\/object>/g, function(a){
  64                  return a.replace(/[\r\n]+/g, '');
  65              });
  66          }
  67  
  68          // Unmark special paragraph closing tags
  69          content = content.replace(/<\/p#>/g, '</p>\n');
  70          content = content.replace(/\s*(<p [^>]+>[\s\S]*?<\/p>)/g, '\n$1');
  71  
  72          // Trim whitespace
  73          content = content.replace(/^\s+/, '');
  74          content = content.replace(/[\s\u00a0]+$/, '');
  75  
  76          // put back the line breaks in pre|script
  77          content = content.replace(/<wp_temp>/g, '\n');
  78  
  79          return content;
  80      },
  81  
  82      go : function(id, mode) {
  83          id = id || 'content';
  84          mode = mode || this.mode || '';
  85  
  86          var ed, qt = this.I('quicktags'), H = this.I('edButtonHTML'), P = this.I('edButtonPreview'), ta = this.I(id);
  87  
  88          try { ed = tinyMCE.get(id); }
  89          catch(e) { ed = false; }
  90  
  91          if ( 'tinymce' == mode ) {
  92              if ( ed && ! ed.isHidden() )
  93                  return false;
  94  
  95              setUserSetting( 'editor', 'tinymce' );
  96              this.mode = 'html';
  97  
  98              P.className = 'active';
  99              H.className = '';
 100              edCloseAllTags(); // :-(
 101              qt.style.display = 'none';
 102  
 103              ta.style.color = '#FFF';
 104              ta.value = this.wpautop(ta.value);
 105  
 106              try {
 107                  if ( ed )
 108                      ed.show();
 109                  else
 110                      tinyMCE.execCommand("mceAddControl", false, id);
 111              } catch(e) {}
 112  
 113              ta.style.color = '#000';
 114          } else {
 115              setUserSetting( 'editor', 'html' );
 116              ta.style.color = '#000';
 117              this.mode = 'tinymce';
 118              H.className = 'active';
 119              P.className = '';
 120  
 121              if ( ed && !ed.isHidden() ) {
 122                  ta.style.height = ed.getContentAreaContainer().offsetHeight + 24 + 'px';
 123                  ed.hide();
 124              }
 125  
 126              qt.style.display = 'block';
 127          }
 128          return false;
 129      },
 130  
 131      _wp_Autop : function(pee) {
 132          var blocklist = 'table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6]|fieldset|legend';
 133  
 134          if ( pee.indexOf('<object') != -1 ) {
 135              pee = pee.replace(/<object[\s\S]+?<\/object>/g, function(a){
 136                  return a.replace(/[\r\n]+/g, '');
 137              });
 138          }
 139  
 140          pee = pee.replace(/<[^<>]+>/g, function(a){
 141              return a.replace(/[\r\n]+/g, ' ');
 142          });
 143  
 144          pee = pee + '\n\n';
 145          pee = pee.replace(/<br \/>\s*<br \/>/gi, '\n\n');
 146          pee = pee.replace(new RegExp('(<(?:'+blocklist+')[^>]*>)', 'gi'), '\n$1');
 147          pee = pee.replace(new RegExp('(</(?:'+blocklist+')>)', 'gi'), '$1\n\n');
 148          pee = pee.replace(/\r\n|\r/g, '\n');
 149          pee = pee.replace(/\n\s*\n+/g, '\n\n');
 150          pee = pee.replace(/([\s\S]+?)\n\n/g, '<p>$1</p>\n');
 151          pee = pee.replace(/<p>\s*?<\/p>/gi, '');
 152          pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')[^>]*>)\\s*</p>', 'gi'), "$1");
 153          pee = pee.replace(/<p>(<li.+?)<\/p>/gi, '$1');
 154          pee = pee.replace(/<p>\s*<blockquote([^>]*)>/gi, '<blockquote$1><p>');
 155          pee = pee.replace(/<\/blockquote>\s*<\/p>/gi, '</p></blockquote>');
 156          pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')[^>]*>)', 'gi'), "$1");
 157          pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*</p>', 'gi'), "$1");
 158          pee = pee.replace(/\s*\n/gi, '<br />\n');
 159          pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*<br />', 'gi'), "$1");
 160          pee = pee.replace(/<br \/>(\s*<\/?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)/gi, '$1');
 161          pee = pee.replace(/(?:<p>|<br ?\/?>)*\s*\[caption([^\[]+)\[\/caption\]\s*(?:<\/p>|<br ?\/?>)*/gi, '[caption$1[/caption]');
 162  
 163          pee = pee.replace(/(<(?:div|th|td|form|fieldset|dd)[^>]*>)(.*?)<\/p>/g, function(a, b, c) {
 164              if ( c.match(/<p( [^>]+)?>/) )
 165                  return a;
 166  
 167              return b + '<p>' + c + '</p>';
 168          });
 169  
 170          // Fix the pre|script tags
 171          pee = pee.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) {
 172              a = a.replace(/<br ?\/?>[\r\n]*/g, '\n');
 173              return a.replace(/<\/?p( [^>]*)?>[\r\n]*/g, '\n');
 174          });
 175  
 176          return pee;
 177      },
 178  
 179      pre_wpautop : function(content) {
 180          var t = this, o = { o: t, data: content, unfiltered: content };
 181  
 182          jQuery('body').trigger('beforePreWpautop', [o]);
 183          o.data = t._wp_Nop(o.data);
 184          jQuery('body').trigger('afterPreWpautop', [o]);
 185          return o.data;
 186      },
 187  
 188      wpautop : function(pee) {
 189          var t = this, o = { o: t, data: pee, unfiltered: pee };
 190  
 191          jQuery('body').trigger('beforeWpautop', [o]);
 192          o.data = t._wp_Autop(o.data);
 193          jQuery('body').trigger('afterWpautop', [o]);
 194          return o.data;
 195      }
 196  };


Generated: Fri Jan 8 00:19:48 2010 Cross-referenced by PHPXref 0.7