| 135 | | |
|---|
| 136 | | wpEditorInit = function() { |
|---|
| 137 | | // Activate tinyMCE if it's the user's default editor |
|---|
| 138 | | if ( ( 'undefined' == typeof wpTinyMCEConfig ) || 'tinymce' == wpTinyMCEConfig.defaultEditor ) { |
|---|
| 139 | | document.getElementById('editorcontainer').style.padding = '0px'; |
|---|
| 140 | | tinyMCE.execCommand("mceAddControl", true, "content"); |
|---|
| 141 | | } else { |
|---|
| 142 | | var H; |
|---|
| 143 | | if ( H = tinymce.util.Cookie.getHash("TinyMCE_content_size") ) |
|---|
| 144 | | document.getElementById('content').style.height = H.ch - 30 + 'px'; |
|---|
| 145 | | } |
|---|
| 146 | | }; |
|---|
| 147 | | |
|---|
| 148 | | switchEditors = { |
|---|
| 149 | | |
|---|
| 150 | | saveCallback : function(el, content, body) { |
|---|
| 151 | | |
|---|
| 152 | | document.getElementById(el).style.color = '#fff'; |
|---|
| 153 | | if ( tinyMCE.activeEditor.isHidden() ) |
|---|
| 154 | | content = document.getElementById(el).value; |
|---|
| 155 | | else |
|---|
| 156 | | content = this.pre_wpautop(content); |
|---|
| 157 | | |
|---|
| 158 | | return content; |
|---|
| 159 | | }, |
|---|
| 160 | | |
|---|
| 161 | | pre_wpautop : function(content) { |
|---|
| 162 | | // We have a TON of cleanup to do. |
|---|
| 163 | | |
|---|
| 164 | | // content = content.replace(/\n|\r/g, ' '); |
|---|
| 165 | | // Remove anonymous, empty paragraphs. |
|---|
| 166 | | content = content.replace(new RegExp('<p>(\\s| |<br>)*</p>', 'mg'), ''); |
|---|
| 167 | | |
|---|
| 168 | | // Mark </p> if it has any attributes. |
|---|
| 169 | | content = content.replace(new RegExp('(<p[^>]+>.*?)</p>', 'mg'), '$1</p#>'); |
|---|
| 170 | | |
|---|
| 171 | | // Get it ready for wpautop. |
|---|
| 172 | | content = content.replace(new RegExp('\\s*<p>', 'mgi'), ''); |
|---|
| 173 | | content = content.replace(new RegExp('\\s*</p>\\s*', 'mgi'), '\n\n'); |
|---|
| 174 | | content = content.replace(new RegExp('\\n\\s*\\n', 'mgi'), '\n\n'); |
|---|
| 175 | | content = content.replace(new RegExp('\\s*<br ?/?>\\s*', 'gi'), '\n'); |
|---|
| 176 | | |
|---|
| 177 | | // Fix some block element newline issues |
|---|
| 178 | | var blocklist = 'blockquote|ul|ol|li|table|thead|tr|th|td|div|h\\d|pre'; |
|---|
| 179 | | content = content.replace(new RegExp('\\s*<(('+blocklist+') ?[^>]*)\\s*>', 'mg'), '\n<$1>'); |
|---|
| 180 | | content = content.replace(new RegExp('\\s*</('+blocklist+')>\\s*', 'mg'), '</$1>\n'); |
|---|
| 181 | | content = content.replace(new RegExp('<li>', 'g'), '\t<li>'); |
|---|
| 182 | | |
|---|
| 183 | | if ( content.indexOf('<object') != -1 ) { |
|---|
| 184 | | content = content.replace(new RegExp('\\s*<param([^>]*)>\\s*', 'g'), "<param$1>"); // no pee inside object/embed |
|---|
| 185 | | content = content.replace(new RegExp('\\s*</embed>\\s*', 'g'), '</embed>'); |
|---|
| 186 | | } |
|---|
| 187 | | |
|---|
| 188 | | // Unmark special paragraph closing tags |
|---|
| 189 | | content = content.replace(new RegExp('</p#>', 'g'), '</p>\n'); |
|---|
| 190 | | content = content.replace(new RegExp('\\s*(<p[^>]+>.*</p>)', 'mg'), '\n$1'); |
|---|
| 191 | | |
|---|
| 192 | | // Trim trailing whitespace |
|---|
| 193 | | content = content.replace(new RegExp('\\s*$', ''), ''); |
|---|
| 194 | | |
|---|
| 195 | | // Hope. |
|---|
| 196 | | return content; |
|---|
| 197 | | }, |
|---|
| 198 | | |
|---|
| 199 | | go : function(id) { |
|---|
| 200 | | var ed = tinyMCE.get(id); |
|---|
| 201 | | var qt = document.getElementById('quicktags'); |
|---|
| 202 | | var H = document.getElementById('edButtonHTML'); |
|---|
| 203 | | var P = document.getElementById('edButtonPreview'); |
|---|
| 204 | | var ta = document.getElementById(id); |
|---|
| 205 | | var ec = document.getElementById('editorcontainer'); |
|---|
| 206 | | |
|---|
| 207 | | if ( ! ed || ed.isHidden() ) { |
|---|
| 208 | | ta.style.color = '#fff'; |
|---|
| 209 | | |
|---|
| 210 | | this.edToggle(P, H); |
|---|
| 211 | | edCloseAllTags(); // :-( |
|---|
| 212 | | |
|---|
| 213 | | qt.style.display = 'none'; |
|---|
| 214 | | ec.style.padding = '0px'; |
|---|
| 215 | | |
|---|
| 216 | | ta.value = this.wpautop(ta.value); |
|---|
| 217 | | |
|---|
| 218 | | if ( ed ) ed.show(); |
|---|
| 219 | | else tinyMCE.execCommand("mceAddControl", false, id); |
|---|
| 220 | | |
|---|
| 221 | | this.wpSetDefaultEditor( 'tinymce' ); |
|---|
| 222 | | } else { |
|---|
| 223 | | this.edToggle(H, P); |
|---|
| 224 | | tinyMCE.triggerSave(); |
|---|
| 225 | | ta.style.height = tinyMCE.activeEditor.contentAreaContainer.offsetHeight + 6 + 'px'; |
|---|
| 226 | | |
|---|
| 227 | | if ( tinymce.isIE6 ) |
|---|
| 228 | | ta.style.width = tinyMCE.activeEditor.contentAreaContainer.offsetWidth - 12 + 'px'; |
|---|
| 229 | | |
|---|
| 230 | | ed.hide(); |
|---|
| 231 | | ta.value = this.pre_wpautop(ta.value); |
|---|
| 232 | | |
|---|
| 233 | | qt.style.display = 'block'; |
|---|
| 234 | | ec.style.padding = '6px'; |
|---|
| 235 | | ta.style.color = ''; |
|---|
| 236 | | |
|---|
| 237 | | this.wpSetDefaultEditor( 'html' ); |
|---|
| 238 | | } |
|---|
| 239 | | }, |
|---|
| 240 | | |
|---|
| 241 | | edToggle : function(A, B) { |
|---|
| 242 | | A.className = 'active'; |
|---|
| 243 | | B.className = ''; |
|---|
| 244 | | |
|---|
| 245 | | B.onclick = A.onclick; |
|---|
| 246 | | A.onclick = null; |
|---|
| 247 | | }, |
|---|
| 248 | | |
|---|
| 249 | | wpSetDefaultEditor : function( editor ) { |
|---|
| 250 | | try { |
|---|
| 251 | | editor = escape( editor.toString() ); |
|---|
| 252 | | } catch(err) { |
|---|
| 253 | | editor = 'tinymce'; |
|---|
| 254 | | } |
|---|
| 255 | | |
|---|
| 256 | | var userID = document.getElementById('user-id'); |
|---|
| 257 | | var date = new Date(); |
|---|
| 258 | | date.setTime(date.getTime()+(10*365*24*60*60*1000)); |
|---|
| 259 | | document.cookie = "wordpress_editor_" + userID.value + "=" + editor + "; expires=" + date.toGMTString(); |
|---|
| 260 | | }, |
|---|
| 261 | | |
|---|
| 262 | | wpautop : function(pee) { |
|---|
| 263 | | 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]'; |
|---|
| 264 | | |
|---|
| 265 | | pee = pee + "\n\n"; |
|---|
| 266 | | pee = pee.replace(new RegExp('<br />\\s*<br />', 'gi'), "\n\n"); |
|---|
| 267 | | pee = pee.replace(new RegExp('(<(?:'+blocklist+')[^>]*>)', 'gi'), "\n$1"); |
|---|
| 268 | | pee = pee.replace(new RegExp('(</(?:'+blocklist+')>)', 'gi'), "$1\n\n"); |
|---|
| 269 | | pee = pee.replace(new RegExp("\\r\\n|\\r", 'g'), "\n"); |
|---|
| 270 | | pee = pee.replace(new RegExp("\\n\\s*\\n+", 'g'), "\n\n"); |
|---|
| 271 | | pee = pee.replace(new RegExp('([\\s\\S]+?)\\n\\n', 'mg'), "<p>$1</p>\n"); |
|---|
| 272 | | pee = pee.replace(new RegExp('<p>\\s*?</p>', 'gi'), ''); |
|---|
| 273 | | pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')[^>]*>)\\s*</p>', 'gi'), "$1"); |
|---|
| 274 | | pee = pee.replace(new RegExp("<p>(<li.+?)</p>", 'gi'), "$1"); |
|---|
| 275 | | pee = pee.replace(new RegExp('<p><blockquote([^>]*)>', 'gi'), "<blockquote$1><p>"); |
|---|
| 276 | | pee = pee.replace(new RegExp('</blockquote></p>', 'gi'), '</p></blockquote>'); |
|---|
| 277 | | pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')[^>]*>)', 'gi'), "$1"); |
|---|
| 278 | | pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*</p>', 'gi'), "$1"); |
|---|
| 279 | | pee = pee.replace(new RegExp('\\s*\\n', 'gi'), "<br />\n"); |
|---|
| 280 | | pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*<br />', 'gi'), "$1"); |
|---|
| 281 | | pee = pee.replace(new RegExp('<br />(\\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)', 'gi'), '$1'); |
|---|
| 282 | | pee = pee.replace(new RegExp('^((?: )*)\\s', 'mg'), '$1 '); |
|---|
| 283 | | //pee = pee.replace(new RegExp('(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') . stripslashes(clean_pre('$2')) . '</pre>' "); // Hmm... |
|---|
| 284 | | return pee; |
|---|
| 285 | | } |
|---|
| 286 | | } |
|---|