source: trunk/www.guidonia.net/wp/wp-admin/js/editor.dev.js@ 44

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