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