1 /* Import plugin specific language pack */
\r
2 tinyMCE.importPluginLanguagePack('wordpress', '');
\r
4 function TinyMCE_wordpress_initInstance(inst) {
\r
5 if (!tinyMCE.settings['wordpress_skip_plugin_css'])
\r
6 tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/plugins/wordpress/wordpress.css");
\r
9 function TinyMCE_wordpress_getControlHTML(control_name) {
\r
10 switch (control_name) {
\r
12 var titleMore = tinyMCE.getLang('lang_wordpress_more_button');
\r
13 var titlePage = tinyMCE.getLang('lang_wordpress_page_button');
\r
14 var titleHelp = tinyMCE.getLang('lang_wordpress_help_button');
\r
15 var buttons = '<a href="javascript:tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mcewordpressmore\')" target="_self" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mcewordpressmore\');return false;"><img id="{$editor_id}_wordpress_more" src="{$pluginurl}/images/more.gif" title="'+titleMore+'" width="20" height="20" class="mceButtonNormal" onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');" onmouseout="tinyMCE.restoreClass(this);" onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');" /></a>';
\r
16 // Add this to the buttons var to put the Page button into the toolbar.
\r
17 // '<a href="javascript:tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mcewordpresspage\')" target="_self" onclick="javascript:tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mcewordpresspage\');return false;"><img id="{$editor_id}_wordpress_page" src="{$pluginurl}/images/page.gif" title="'+titlePage+'" width="20" height="20" class="mceButtonNormal" onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');" onmouseout="tinyMCE.restoreClass(this);" onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');" /></a>';
\r
24 function TinyMCE_wordpress_parseAttributes(attribute_string) {
\r
25 var attributeName = "";
\r
26 var attributeValue = "";
\r
29 var attributes = new Array();
\r
30 var whiteSpaceRegExp = new RegExp('^[ \n\r\t]+', 'g');
\r
31 var titleText = tinyMCE.getLang('lang_wordpress_more');
\r
32 var titleTextPage = tinyMCE.getLang('lang_wordpress_page');
\r
34 if (attribute_string == null || attribute_string.length < 2)
\r
37 withInName = withInValue = false;
\r
39 for (var i=0; i<attribute_string.length; i++) {
\r
40 var chr = attribute_string.charAt(i);
\r
42 if ((chr == '"' || chr == "'") && !withInValue)
\r
44 else if ((chr == '"' || chr == "'") && withInValue) {
\r
45 withInValue = false;
\r
47 var pos = attributeName.lastIndexOf(' ');
\r
49 attributeName = attributeName.substring(pos+1);
\r
51 attributes[attributeName.toLowerCase()] = attributeValue.substring(1).toLowerCase();
\r
54 attributeValue = "";
\r
55 } else if (!whiteSpaceRegExp.test(chr) && !withInName && !withInValue)
\r
58 if (chr == '=' && withInName)
\r
62 attributeName += chr;
\r
65 attributeValue += chr;
\r
71 function TinyMCE_wordpress_execCommand(editor_id, element, command, user_interface, value) {
\r
72 var inst = tinyMCE.getInstanceById(editor_id);
\r
73 var focusElm = inst.getFocusElement();
\r
74 var doc = inst.getDoc();
\r
76 function getAttrib(elm, name) {
\r
77 return elm.getAttribute(name) ? elm.getAttribute(name) : "";
\r
82 case "mcewordpressmore":
\r
84 var template = new Array();
\r
85 var altMore = tinyMCE.getLang('lang_wordpress_more_alt');
\r
87 // Is selection a image
\r
88 if (focusElm != null && focusElm.nodeName.toLowerCase() == "img") {
\r
89 flag = getAttrib(focusElm, 'class');
\r
91 if (flag != 'mce_plugin_wordpress_more') // Not a wordpress
\r
98 + '<img src="' + (tinyMCE.getParam("theme_href") + "/images/spacer.gif") + '" '
\r
99 + ' width="100%" height="10px" '
\r
100 + 'alt="'+altMore+'" title="'+altMore+'" class="mce_plugin_wordpress_more" name="mce_plugin_wordpress_more" />';
\r
101 tinyMCE.execCommand("mceInsertContent",true,html);
\r
102 tinyMCE.selectedInstance.repaint();
\r
104 case "mcewordpresspage":
\r
106 var template = new Array();
\r
107 var altPage = tinyMCE.getLang('lang_wordpress_more_alt');
\r
109 // Is selection a image
\r
110 if (focusElm != null && focusElm.nodeName.toLowerCase() == "img") {
\r
111 flag = getAttrib(focusElm, 'name');
\r
113 if (flag != 'mce_plugin_wordpress_page') // Not a wordpress
\r
120 + '<img src="' + (tinyMCE.getParam("theme_href") + "/images/spacer.gif") + '" '
\r
121 + ' width="100%" height="10px" '
\r
122 + 'alt="'+altPage+'" title="'+altPage+'" class="mce_plugin_wordpress_page" name="mce_plugin_wordpress_page" />';
\r
123 tinyMCE.execCommand("mceInsertContent",true,html);
\r
124 tinyMCE.selectedInstance.repaint();
\r
128 // Pass to next handler in chain
\r
132 function TinyMCE_wordpress_cleanup(type, content) {
\r
135 case "insert_to_editor":
\r
137 var altMore = tinyMCE.getLang('lang_wordpress_more_alt');
\r
138 var altPage = tinyMCE.getLang('lang_wordpress_page_alt');
\r
140 // Parse all <!--more--> tags and replace them with images
\r
141 while ((startPos = content.indexOf('<!--more-->', startPos)) != -1) {
\r
143 var contentAfter = content.substring(startPos + 11);
\r
144 content = content.substring(0, startPos);
\r
145 content += '<img src="' + (tinyMCE.getParam("theme_href") + "/images/spacer.gif") + '" ';
\r
146 content += ' width="100%" height="10px" ';
\r
147 content += 'alt="'+altMore+'" title="'+altMore+'" class="mce_plugin_wordpress_more" />';
\r
148 content += contentAfter;
\r
154 // Parse all <!--page--> tags and replace them with images
\r
155 while ((startPos = content.indexOf('<!--nextpage-->', startPos)) != -1) {
\r
157 var contentAfter = content.substring(startPos + 15);
\r
158 content = content.substring(0, startPos);
\r
159 content += '<img src="' + (tinyMCE.getParam("theme_href") + "/images/spacer.gif") + '" ';
\r
160 content += ' width="100%" height="10px" ';
\r
161 content += 'alt="'+altPage+'" title="'+altPage+'" class="mce_plugin_wordpress_page" />';
\r
162 content += contentAfter;
\r
167 // It's supposed to be WYSIWYG, right?
\r
168 content = content.replace(new RegExp('&', 'g'), '&');
\r
172 case "get_from_editor":
\r
173 // Parse all img tags and replace them with <!--more-->
\r
175 while ((startPos = content.indexOf('<img', startPos+1)) != -1) {
\r
176 var endPos = content.indexOf('/>', startPos);
\r
177 var attribs = TinyMCE_wordpress_parseAttributes(content.substring(startPos + 4, endPos));
\r
179 if (attribs['class'] == "mce_plugin_wordpress_more") {
\r
182 var embedHTML = '<!--more-->';
\r
184 // Insert embed/object chunk
\r
185 chunkBefore = content.substring(0, startPos);
\r
186 chunkAfter = content.substring(endPos);
\r
187 content = chunkBefore + embedHTML + chunkAfter;
\r
189 if (attribs['class'] == "mce_plugin_wordpress_page") {
\r
192 var embedHTML = '<!--nextpage-->';
\r
194 // Insert embed/object chunk
\r
195 chunkBefore = content.substring(0, startPos);
\r
196 chunkAfter = content.substring(endPos);
\r
197 content = chunkBefore + embedHTML + chunkAfter;
\r
201 // If it says & in the WYSIWYG editor, it should say & in the html.
\r
202 content = content.replace(new RegExp('&', 'g'), '&');
\r
203 content = content.replace(new RegExp('&nbsp;', 'g'), ' ');
\r
205 // Remove anonymous, empty paragraphs.
\r
206 content = content.replace(new RegExp('<p>(\\s| )*</p>', 'mg'), '');
\r
208 // Handle table badness.
\r
209 content = content.replace(new RegExp('<(table( [^>]*)?)>.*?<((tr|thead)( [^>]*)?)>', 'mg'), '<$1><$3>');
\r
210 content = content.replace(new RegExp('<(tr|thead|tfoot)>.*?<((td|th)( [^>]*)?)>', 'mg'), '<$1><$2>');
\r
211 content = content.replace(new RegExp('</(td|th)>.*?<(td( [^>]*)?|th( [^>]*)?|/tr|/thead|/tfoot)>', 'mg'), '</$1><$2>');
\r
212 content = content.replace(new RegExp('</tr>.*?<(tr|/table)>', 'mg'), '</tr><$1>');
\r
213 content = content.replace(new RegExp('<(/?(table|tbody|tr|th|td)[^>]*)>(\\s*|(<br ?/?>)*)*', 'g'), '<$1>');
\r
215 // Pretty it up for the source editor.
\r
216 var blocklist = 'blockquote|ul|ol|li|table|thead|tr|th|td|div|h\\d|pre|p';
\r
217 content = content.replace(new RegExp('\\s*</('+blocklist+')>\\s*', 'mg'), '</$1>\n');
\r
218 content = content.replace(new RegExp('\\s*<(('+blocklist+')[^>]*)>\\s*', 'mg'), '\n<$1>');
\r
219 content = content.replace(new RegExp('<((li|/?tr|/?thead|/?tfoot)( [^>]*)?)>', 'g'), '\t<$1>');
\r
220 content = content.replace(new RegExp('<((td|th)( [^>]*)?)>', 'g'), '\t\t<$1>');
\r
221 content = content.replace(new RegExp('\\s*<br ?/?>\\s*', 'mg'), '<br />\n');
\r
222 content = content.replace(new RegExp('^\\s*', ''), '');
\r
223 content = content.replace(new RegExp('\\s*$', ''), '');
\r
228 // Pass through to next handler in chain
\r
232 function TinyMCE_wordpress_handleNodeChange(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
\r
233 function getAttrib(elm, name) {
\r
234 return elm.getAttribute(name) ? elm.getAttribute(name) : "";
\r
237 tinyMCE.switchClassSticky(editor_id + '_wordpress_more', 'mceButtonNormal');
\r
238 tinyMCE.switchClassSticky(editor_id + '_wordpress_page', 'mceButtonNormal');
\r
244 if (node.nodeName.toLowerCase() == "img" && getAttrib(node, 'class').indexOf('mce_plugin_wordpress_more') == 0)
\r
245 tinyMCE.switchClassSticky(editor_id + '_wordpress_more', 'mceButtonSelected');
\r
246 if (node.nodeName.toLowerCase() == "img" && getAttrib(node, 'class').indexOf('mce_plugin_wordpress_page') == 0)
\r
247 tinyMCE.switchClassSticky(editor_id + '_wordpress_page', 'mceButtonSelected');
\r
248 } while ((node = node.parentNode));
\r
253 function wp_save_callback(el, content, body) {
\r
254 // We have a TON of cleanup to do.
\r
256 // Mark </p> if it has any attributes.
\r
257 content = content.replace(new RegExp('(<p[^>]+>.*?)</p>', 'mg'), '$1</p#>');
\r
259 // Decode the ampersands of time.
\r
260 content = content.replace(new RegExp('&', 'g'), '&');
\r
262 // Get it ready for wpautop.
\r
263 content = content.replace(new RegExp('[\\s]*<p>[\\s]*', 'mgi'), '');
\r
264 content = content.replace(new RegExp('[\\s]*</p>[\\s]*', 'mgi'), '\n\n');
\r
265 content = content.replace(new RegExp('\\n\\s*\\n\\s*\\n*', 'mgi'), '\n\n');
\r
266 content = content.replace(new RegExp('\\s*<br ?/?>\\s*', 'gi'), '\n');
\r
268 // Fix some block element newline issues
\r
269 var blocklist = 'blockquote|ul|ol|li|table|thead|tr|th|td|div|h\\d|pre';
\r
270 content = content.replace(new RegExp('\\s*<(('+blocklist+') ?[^>]*)\\s*>', 'mg'), '\n<$1>');
\r
271 content = content.replace(new RegExp('\\s*</('+blocklist+')>\\s*', 'mg'), '</$1>\n');
\r
272 content = content.replace(new RegExp('<li>', 'g'), '\t<li>');
\r
274 // Unmark special paragraph closing tags
\r
275 content = content.replace(new RegExp('</p#>', 'g'), '</p>\n');
\r
276 content = content.replace(new RegExp('\\s*(<p[^>]+>.*</p>)', 'mg'), '\n$1');
\r
278 // Trim any whitespace
\r
279 content = content.replace(new RegExp('^\\s*', ''), '');
\r
280 content = content.replace(new RegExp('\\s*$', ''), '');
\r