wysihat-engine 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/generators/wysihat/templates/css/wysihat.css +14 -0
- data/generators/wysihat/templates/images/icons/cancel.png +0 -0
- data/generators/wysihat/templates/images/icons/text_heading_1.png +0 -0
- data/generators/wysihat/templates/images/icons/text_heading_2.png +0 -0
- data/generators/wysihat/templates/images/icons/text_heading_3.png +0 -0
- data/generators/wysihat/templates/images/icons/text_heading_4.png +0 -0
- data/generators/wysihat/templates/images/icons/text_heading_5.png +0 -0
- data/generators/wysihat/templates/images/icons/text_heading_6.png +0 -0
- data/generators/wysihat/templates/javascripts/wysihat.js +28 -93
- data/generators/wysihat/templates/javascripts/wysihat_engine.js +2 -0
- data/generators/wysihat/templates/javascripts/wysihat_engine_pack.js +1 -1
- data/generators/wysihat/templates/sass/wysihat.sass +23 -2
- data/generators/wysihat/wysihat_generator.rb +7 -0
- data/lib/generators/wysihat_generator.rb +78 -0
- data/lib/wysihat-engine.rb +8 -8
- data/wysihat-engine.gemspec +10 -2
- metadata +10 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.10
|
@@ -37,6 +37,20 @@ div.editor_toolbar span {
|
|
37
37
|
background-image: url('../images/icons/image.png'); }
|
38
38
|
.editor_toolbar .html {
|
39
39
|
background-image: url('../images/icons/page_code.png'); }
|
40
|
+
.editor_toolbar .h1 {
|
41
|
+
background-image: url('../images/icons/text_heading_1.png'); }
|
42
|
+
.editor_toolbar .h2 {
|
43
|
+
background-image: url('../images/icons/text_heading_2.png'); }
|
44
|
+
.editor_toolbar .h3 {
|
45
|
+
background-image: url('../images/icons/text_heading_3.png'); }
|
46
|
+
.editor_toolbar .h4 {
|
47
|
+
background-image: url('../images/icons/text_heading_4.png'); }
|
48
|
+
.editor_toolbar .h5 {
|
49
|
+
background-image: url('../images/icons/text_heading_5.png'); }
|
50
|
+
.editor_toolbar .h6 {
|
51
|
+
background-image: url('../images/icons/text_heading_6.png'); }
|
52
|
+
.editor_toolbar .p {
|
53
|
+
background-image: url('../images/icons/cancel.png'); }
|
40
54
|
|
41
55
|
iframe.editor {
|
42
56
|
border: 1px solid #999;
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -88,29 +88,14 @@ WysiHat.Commands = (function() {
|
|
88
88
|
this.execCommand('fontname', false, font);
|
89
89
|
}
|
90
90
|
|
91
|
-
function fontSelected() {
|
92
|
-
var node = this.selection.getNode();
|
93
|
-
return Element.getStyle(node, 'fontFamily');
|
94
|
-
}
|
95
|
-
|
96
91
|
function fontSizeSelection(fontSize) {
|
97
92
|
this.execCommand('fontsize', false, fontSize);
|
98
93
|
}
|
99
94
|
|
100
|
-
function fontSizeSelected() {
|
101
|
-
var node = this.selection.getNode();
|
102
|
-
return standardizeFontSize(Element.getStyle(node, 'fontSize'));
|
103
|
-
}
|
104
|
-
|
105
95
|
function colorSelection(color) {
|
106
96
|
this.execCommand('forecolor', false, color);
|
107
97
|
}
|
108
98
|
|
109
|
-
function colorSelected() {
|
110
|
-
var node = this.selection.getNode();
|
111
|
-
return standardizeColor(Element.getStyle(node, 'color'));
|
112
|
-
}
|
113
|
-
|
114
99
|
function backgroundColorSelection(color) {
|
115
100
|
if(Prototype.Browser.Gecko) {
|
116
101
|
this.execCommand('hilitecolor', false, color);
|
@@ -119,11 +104,6 @@ WysiHat.Commands = (function() {
|
|
119
104
|
}
|
120
105
|
}
|
121
106
|
|
122
|
-
function backgroundColorSelected() {
|
123
|
-
var node = this.selection.getNode();
|
124
|
-
return standardizeColor(Element.getStyle(node, 'backgroundColor'));
|
125
|
-
}
|
126
|
-
|
127
107
|
function alignSelection(alignment) {
|
128
108
|
this.execCommand('justify' + alignment);
|
129
109
|
}
|
@@ -150,6 +130,10 @@ WysiHat.Commands = (function() {
|
|
150
130
|
return node ? node.tagName.toUpperCase() == 'A' : false;
|
151
131
|
}
|
152
132
|
|
133
|
+
function formatblockSelection(element){
|
134
|
+
this.execCommand('formatblock', false, element);
|
135
|
+
}
|
136
|
+
|
153
137
|
function insertOrderedList() {
|
154
138
|
this.execCommand('insertorderedlist', false, null);
|
155
139
|
}
|
@@ -178,7 +162,7 @@ WysiHat.Commands = (function() {
|
|
178
162
|
|
179
163
|
if (Prototype.Browser.IE) this.selection.restore();
|
180
164
|
|
181
|
-
var handler = this.commands.get(command)
|
165
|
+
var handler = this.commands.get(command);
|
182
166
|
if (handler)
|
183
167
|
handler.bind(this)(value);
|
184
168
|
else
|
@@ -188,77 +172,22 @@ WysiHat.Commands = (function() {
|
|
188
172
|
function queryCommandState(state) {
|
189
173
|
var document = this.getDocument();
|
190
174
|
|
191
|
-
var handler = this.queryCommands.get(state)
|
175
|
+
var handler = this.queryCommands.get(state);
|
192
176
|
if (handler)
|
193
177
|
return handler.bind(this)();
|
194
178
|
else
|
195
179
|
return document.queryCommandState(state);
|
196
180
|
}
|
197
|
-
var fontSizeNames = $w('xxx-small xx-small x-small small medium large x-large xx-large');
|
198
|
-
var fontSizePixels = $w('9px 10px 13px 16px 18px 24px 32px 48px');
|
199
181
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
newSize = fontSizePixels.indexOf(fontSize);
|
210
|
-
if (newSize >= 0) return newSize;
|
211
|
-
return parseInt(fontSize);
|
212
|
-
}
|
213
|
-
|
214
|
-
function standardizeColor(color) {
|
215
|
-
if (!color || color.match(/[0-9a-f]{6}/i)) return color;
|
216
|
-
var m = color.toLowerCase().match(/^(rgba?|hsla?)\(([\s\.\-,%0-9]+)\)/);
|
217
|
-
if(m){
|
218
|
-
var c = m[2].split(/\s*,\s*/), l = c.length, t = m[1];
|
219
|
-
if((t == "rgb" && l == 3) || (t == "rgba" && l == 4)){
|
220
|
-
var r = c[0];
|
221
|
-
if(r.charAt(r.length - 1) == "%"){
|
222
|
-
var a = c.map(function(x){
|
223
|
-
return parseFloat(x) * 2.56;
|
224
|
-
});
|
225
|
-
if(l == 4){ a[3] = c[3]; }
|
226
|
-
return _colorFromArray(a);
|
227
|
-
}
|
228
|
-
return _colorFromArray(c);
|
229
|
-
}
|
230
|
-
if((t == "hsl" && l == 3) || (t == "hsla" && l == 4)){
|
231
|
-
var H = ((parseFloat(c[0]) % 360) + 360) % 360 / 360,
|
232
|
-
S = parseFloat(c[1]) / 100,
|
233
|
-
L = parseFloat(c[2]) / 100,
|
234
|
-
m2 = L <= 0.5 ? L * (S + 1) : L + S - L * S,
|
235
|
-
m1 = 2 * L - m2,
|
236
|
-
a = [_hue2rgb(m1, m2, H + 1 / 3) * 256,
|
237
|
-
_hue2rgb(m1, m2, H) * 256, _hue2rgb(m1, m2, H - 1 / 3) * 256, 1];
|
238
|
-
if(l == 4){ a[3] = c[3]; }
|
239
|
-
return _colorFromArray(a);
|
240
|
-
}
|
241
|
-
}
|
242
|
-
return null; // dojo.Color
|
243
|
-
}
|
244
|
-
|
245
|
-
function _colorFromArray(a) {
|
246
|
-
var arr = a.slice(0, 3).map(function(x){
|
247
|
-
var s = parseInt(x).toString(16);
|
248
|
-
return s.length < 2 ? "0" + s : s;
|
249
|
-
});
|
250
|
-
return "#" + arr.join(""); // String
|
251
|
-
}
|
252
|
-
|
253
|
-
function _hue2rgb(m1, m2, h){
|
254
|
-
if(h < 0){ ++h; }
|
255
|
-
if(h > 1){ --h; }
|
256
|
-
var h6 = 6 * h;
|
257
|
-
if(h6 < 1){ return m1 + (m2 - m1) * h6; }
|
258
|
-
if(2 * h < 1){ return m2; }
|
259
|
-
if(3 * h < 2){ return m1 + (m2 - m1) * (2 / 3 - h) * 6; }
|
260
|
-
return m1;
|
261
|
-
}
|
182
|
+
function getSelectedStyles() {
|
183
|
+
var styles = $H({});
|
184
|
+
var editor = this;
|
185
|
+
editor.styleSelectors.each(function(style){
|
186
|
+
var node = editor.selection.getNode();
|
187
|
+
styles.set(style.first(), Element.getStyle(node, style.last()));
|
188
|
+
});
|
189
|
+
return styles;
|
190
|
+
}
|
262
191
|
|
263
192
|
return {
|
264
193
|
boldSelection: boldSelection,
|
@@ -270,29 +199,35 @@ WysiHat.Commands = (function() {
|
|
270
199
|
strikethroughSelection: strikethroughSelection,
|
271
200
|
blockquoteSelection: blockquoteSelection,
|
272
201
|
fontSelection: fontSelection,
|
273
|
-
fontSelected: fontSelected,
|
274
202
|
fontSizeSelection: fontSizeSelection,
|
275
|
-
fontSizeSelected: fontSizeSelected,
|
276
203
|
colorSelection: colorSelection,
|
277
|
-
colorSelected: colorSelected,
|
278
204
|
backgroundColorSelection: backgroundColorSelection,
|
279
|
-
backgroundColorSelected: backgroundColorSelected,
|
280
205
|
alignSelection: alignSelection,
|
281
206
|
alignSelected: alignSelected,
|
282
207
|
linkSelection: linkSelection,
|
283
208
|
unlinkSelection: unlinkSelection,
|
284
209
|
linkSelected: linkSelected,
|
210
|
+
formatblockSelection: formatblockSelection,
|
285
211
|
insertOrderedList: insertOrderedList,
|
286
212
|
insertUnorderedList: insertUnorderedList,
|
287
213
|
insertImage: insertImage,
|
288
214
|
insertHTML: insertHTML,
|
289
215
|
execCommand: execCommand,
|
290
216
|
queryCommandState: queryCommandState,
|
217
|
+
getSelectedStyles: getSelectedStyles,
|
291
218
|
|
292
219
|
commands: $H({}),
|
293
220
|
|
294
221
|
queryCommands: $H({
|
295
222
|
link: linkSelected
|
223
|
+
}),
|
224
|
+
|
225
|
+
styleSelectors: $H({
|
226
|
+
fontname: 'fontFamily',
|
227
|
+
fontsize: 'fontSize',
|
228
|
+
forecolor: 'color',
|
229
|
+
hilitecolor: 'backgroundColor',
|
230
|
+
backcolor: 'backgroundColor'
|
296
231
|
})
|
297
232
|
};
|
298
233
|
})();
|
@@ -864,7 +799,7 @@ if (typeof Range == 'undefined') {
|
|
864
799
|
this.START_TO_END = 1;
|
865
800
|
this.END_TO_END = 2;
|
866
801
|
this.END_TO_START = 3;
|
867
|
-
}
|
802
|
+
};
|
868
803
|
|
869
804
|
Range.CLONE_CONTENTS = 0;
|
870
805
|
Range.DELETE_CONTENTS = 1;
|
@@ -1519,7 +1454,7 @@ if (!window.getSelection) {
|
|
1519
1454
|
this.isCollapsed = true;
|
1520
1455
|
this.rangeCount = 0;
|
1521
1456
|
this.ranges = [];
|
1522
|
-
}
|
1457
|
+
};
|
1523
1458
|
|
1524
1459
|
Object.extend(SelectionImpl.prototype, (function() {
|
1525
1460
|
function addRange(r) {
|
@@ -1988,7 +1923,7 @@ WysiHat.Toolbar = Class.create((function() {
|
|
1988
1923
|
this.observeButtonClick(button, handler);
|
1989
1924
|
|
1990
1925
|
var handler = this.buttonStateHandler(name, options);
|
1991
|
-
this.observeStateChanges(button, name, handler)
|
1926
|
+
this.observeStateChanges(button, name, handler);
|
1992
1927
|
}
|
1993
1928
|
|
1994
1929
|
function createButtonElement(toolbar, options) {
|
@@ -75,6 +75,8 @@ function wysiHatify(tag_id, buttons){
|
|
75
75
|
break;
|
76
76
|
case 'paste':
|
77
77
|
toolbar.addButton({label : button.gsub('_','-').camelize().capitalize(), handler: function(editor) { return editor.faceboxPaste(editor); }});
|
78
|
+
case 'h1': case 'h2': case 'h3': case 'h4': case 'h5': case 'h6': case 'p':
|
79
|
+
toolbar.addButton({label : button.gsub('_','-').camelize().capitalize(), handler: function(editor) { return editor.formatblockSelection(button.toLowerCase()); }});
|
78
80
|
break;
|
79
81
|
default:
|
80
82
|
toolbar.addButton({label : button.gsub('_','-').camelize().capitalize()});
|
@@ -1 +1 @@
|
|
1
|
-
var Facebox=Class.create({initialize:function(a){this.settings={loading_image:"/images/facebox/loading.gif",close_image:"/images/facebox/closelabel.gif",image_types:new RegExp("."+["png","jpg","jpeg","gif"].join("|")+"$","i"),inited:true,facebox_html:' <div id="facebox" style="display:none;"> <div class="popup"> <table id="facebox_table"> <tbody> <tr> <td class="tl"/><td class="b"/><td class="tr"/> </tr> <tr> <td class="b"/> <td class="body"> <div class="content"> </div> <div class="footer"> <a href="#" class="close"> <img src="/images/facebox/closelabel.gif" title="close" class="close_image" /> </a> </div> </td> <td class="b"/> </tr> <tr> <td class="bl"/><td class="b"/><td class="br"/> </tr> </tbody> </table> </div> </div>'};if(a){Object.extend(this.settings,a)}$(document.body).insert({bottom:this.settings.facebox_html});this.preload=[new Image(),new Image()];this.preload[0].src=this.settings.close_image;this.preload[1].src=this.settings.loading_image;f=this;$$("#facebox .b:first, #facebox .bl, #facebox .br, #facebox .tl, #facebox .tr").each(function(b){f.preload.push(new Image());f.preload.slice(-1).src=b.getStyle("background-image").replace(/url\((.+)\)/,"$1")});this.facebox=$("facebox");this.keyPressListener=this.watchKeyPress.bindAsEventListener(this);this.watchClickEvents();fb=this;Event.observe($$("#facebox .close").first(),"click",function(b){Event.stop(b);fb.close()});Event.observe($$("#facebox .close_image").first(),"click",function(b){Event.stop(b);fb.close()})},watchKeyPress:function(a){if(a.keyCode==27||!Event.element(a).descendantOf(this.facebox)){this.close()}},watchClickEvents:function(b){var a=this;$$("a[rel=facebox]").each(function(d,c){Event.observe(d,"click",function(g){Event.stop(g);a.click_handler(d,g)})})},loading:function(){if($$("#facebox .loading").length==1){return true}contentWrapper=$$("#facebox .content").first();contentWrapper.childElements().each(function(c,b){c.remove()});contentWrapper.insert({bottom:'<div class="loading"><img src="'+this.settings.loading_image+'"/></div>'});var a=document.viewport.getScrollOffsets();this.facebox.setStyle({top:a.top+(document.viewport.getHeight()/10)+"px",left:document.viewport.getWidth()/2-(this.facebox.getWidth()/2)+"px"});Event.observe(document,"keypress",this.keyPressListener);Event.observe(document,"click",this.keyPressListener)},reveal:function(b,a){this.loading();load=$$("#facebox .loading").first();if(load){load.remove()}contentWrapper=$$("#facebox .content").first();if(a){contentWrapper.addClassName(a)}contentWrapper.update(b);$$("#facebox .body").first().childElements().each(function(d,c){d.show()});if(!this.facebox.visible()){new Effect.Appear(this.facebox,{duration:0.3})}this.facebox.setStyle({left:document.viewport.getWidth()/2-(this.facebox.getWidth()/2)+"px"});Event.observe(document,"keypress",this.keyPressListener);Event.observe(document,"click",this.keyPressListener)},close:function(){new Effect.Fade("facebox",{duration:0.3})},click_handler:function(c,i){this.loading();Event.stop(i);var k=c.rel.match(/facebox\[\.(\w+)\]/);if(k){k=k[1]}new Effect.Appear(this.facebox,{duration:0.3});if(c.href.match(/#/)){var a=window.location.href.split("#")[0];var j=c.href.replace(a+"#","");var l=$(j);var h=new Element(l.tagName);h.innerHTML=l.innerHTML;this.reveal(h,k)}else{if(c.href.match(this.settings.image_types)){var g=new Image();b=this;g.onload=function(){b.reveal('<div class="image"><img src="'+g.src+'" /></div>',k)};g.src=c.href}else{var b=this;var a=c.href;new Ajax.Request(a,{method:"get",onFailure:function(d){b.reveal(d.responseText,k)},onSuccess:function(d){b.reveal(d.responseText,k)}})}}}});var facebox;document.observe("dom:loaded",function(){facebox=new Facebox()});var WysiHat={};WysiHat.Editor={attach:function(a,c,e){c=$H(c);a=$(a);a.hide();var b=c.get("model")||WysiHat.iFrame;var d=e;return b.create(a,function(h){var g=h.getDocument();var i=h.getWindow();h.load();Event.observe(i,"focus",function(j){h.focus()});Event.observe(i,"blur",function(j){h.blur()});h._observeEvents();if(Prototype.Browser.Gecko){h.execCommand("undo",false,null)}if(d){d(h)}h.focus()})},include:function(a){this.includedModules=this.includedModules||$A([]);this.includedModules.push(a)},extend:function(b){var a=this.includedModules||$A([]);a.each(function(c){Object.extend(b,c)})}};WysiHat.Commands=(function(){function l(){this.execCommand("bold",false,null)}function w(){return this.queryCommandState("bold")}function H(){this.execCommand("underline",false,null)}function x(){return this.queryCommandState("underline")}function t(){this.execCommand("italic",false,null)}function F(){return this.queryCommandState("italic")}function v(){this.execCommand("strikethrough",false,null)}function g(){this.execCommand("blockquote",false,null)}function q(I){this.execCommand("fontname",false,I)}function m(){var I=this.selection.getNode();return Element.getStyle(I,"fontFamily")}function u(I){this.execCommand("fontsize",false,I)}function c(){var I=this.selection.getNode();return r(Element.getStyle(I,"fontSize"))}function G(I){this.execCommand("forecolor",false,I)}function k(){var I=this.selection.getNode();return y(Element.getStyle(I,"color"))}function p(I){if(Prototype.Browser.Gecko){this.execCommand("hilitecolor",false,I)}else{this.execCommand("backcolor",false,I)}}function a(){var I=this.selection.getNode();return y(Element.getStyle(I,"backgroundColor"))}function E(I){this.execCommand("justify"+I)}function d(){var I=this.selection.getNode();return Element.getStyle(I,"textAlign")}function j(I){this.execCommand("createLink",false,I)}function i(){var I=this.selection.getNode();if(this.linkSelected()){this.selection.selectNode(I)}this.execCommand("unlink",false,null)}function C(){var I=this.selection.getNode();return I?I.tagName.toUpperCase()=="A":false}function o(){this.execCommand("insertorderedlist",false,null)}function n(){this.execCommand("insertunorderedlist",false,null)}function e(I){this.execCommand("insertImage",false,I)}function b(J){if(Prototype.Browser.IE){var I=this._selection.getRange();I.pasteHTML(J);I.collapse(false);I.select()}else{this.execCommand("insertHTML",false,J)}}function A(M,L,K){var I=this.getDocument();if(Prototype.Browser.IE){this.selection.restore()}var J=this.commands.get(M);if(J){J.bind(this)(K)}else{I.execCommand(M,L,K)}}function h(K){var I=this.getDocument();var J=this.queryCommands.get(K);if(J){return J.bind(this)()}else{return I.queryCommandState(K)}}var B=$w("xxx-small xx-small x-small small medium large x-large xx-large");var D=$w("9px 10px 13px 16px 18px 24px 32px 48px");if(Prototype.Browser.WebKit){B.shift();B.push("-webkit-xxx-large")}function r(J){var I=B.indexOf(J);if(I>=0){return I}I=D.indexOf(J);if(I>=0){return I}return parseInt(J)}function y(M){if(!M||M.match(/[0-9a-f]{6}/i)){return M}var J=M.toLowerCase().match(/^(rgba?|hsla?)\(([\s\.\-,%0-9]+)\)/);if(J){var P=J[2].split(/\s*,\s*/),K=P.length,V=J[1];if((V=="rgb"&&K==3)||(V=="rgba"&&K==4)){var I=P[0];if(I.charAt(I.length-1)=="%"){var Q=P.map(function(L){return parseFloat(L)*2.56});if(K==4){Q[3]=P[3]}return z(Q)}return z(P)}if((V=="hsl"&&K==3)||(V=="hsla"&&K==4)){var R=((parseFloat(P[0])%360)+360)%360/360,N=parseFloat(P[1])/100,O=parseFloat(P[2])/100,T=O<=0.5?O*(N+1):O+N-O*N,U=2*O-T,Q=[s(U,T,R+1/3)*256,s(U,T,R)*256,s(U,T,R-1/3)*256,1];if(K==4){Q[3]=P[3]}return z(Q)}}return null}function z(J){var I=J.slice(0,3).map(function(K){var L=parseInt(K).toString(16);return L.length<2?"0"+L:L});return"#"+I.join("")}function s(J,I,K){if(K<0){++K}if(K>1){--K}var L=6*K;if(L<1){return J+(I-J)*L}if(2*K<1){return I}if(3*K<2){return J+(I-J)*(2/3-K)*6}return J}return{boldSelection:l,boldSelected:w,underlineSelection:H,underlineSelected:x,italicSelection:t,italicSelected:F,strikethroughSelection:v,blockquoteSelection:g,fontSelection:q,fontSelected:m,fontSizeSelection:u,fontSizeSelected:c,colorSelection:G,colorSelected:k,backgroundColorSelection:p,backgroundColorSelected:a,alignSelection:E,alignSelected:d,linkSelection:j,unlinkSelection:i,linkSelected:C,insertOrderedList:o,insertUnorderedList:n,insertImage:e,insertHTML:b,execCommand:A,queryCommandState:h,commands:$H({}),queryCommands:$H({link:C})}})();WysiHat.Editor.include(WysiHat.Commands);WysiHat.Events=(function(){var a=["click","dblclick","mousedown","mouseup","mouseover","mousemove","mouseout","keypress","keydown","keyup"];function b(j,k){a.each(function(l){Event.observe(j,l,function(m){k.fire("wysihat:"+l)})})}function g(l,j,k){Event.observe(j,"keydown",function(m){if(m.keyCode==86){k.fire("wysihat:paste")}});Event.observe(l,"paste",function(m){k.fire("wysihat:paste")})}function c(k,j){Event.observe(k,"focus",function(l){j.fire("wysihat:focus")});Event.observe(k,"blur",function(l){j.fire("wysihat:blur")})}function i(j,k){Event.observe(j,"mouseup",function(m){var l=k.selection.getRange();if(!l.collapsed){k.fire("wysihat:select")}})}function e(j,k){var l=k.rawContent();Event.observe(j,"keyup",function(n){var m=k.rawContent();if(l!=m){k.fire("wysihat:change");l=m}})}function d(j,l){var m=l.selection.getRange();var k=function(o){var n=l.selection.getRange();if(m!=n){l.fire("wysihat:cursormove");m=n}};Event.observe(j,"keyup",k);Event.observe(j,"mouseup",k)}function h(){if(this._observers_setup){return}var j=this.getDocument();var k=this.getWindow();b(j,this);g(k,j,this);c(k,this);i(j,this);e(j,this);d(j,this);this._observers_setup=true}return{_observeEvents:h}})();WysiHat.Editor.include(WysiHat.Events);WysiHat.Persistence=(function(){function h(i){return i.formatHTMLOutput()}function a(i){return i.formatHTMLInput()}function e(){return this.outputFilter(this.rawContent())}function d(i){this.setRawContent(this.inputFilter(i))}function c(){this.textarea.value=this.content()}function g(){this.setContent(this.textarea.value)}function b(){this.selection.setBookmark();this.save();this.load();this.selection.moveToBookmark()}return{outputFilter:h,inputFilter:a,content:e,setContent:d,save:c,load:g,reload:b}})();WysiHat.Editor.include(WysiHat.Persistence);WysiHat.Window=(function(){function c(){return this.contentDocument||this.contentWindow.document}function b(){if(this.contentDocument&&this.contentDocument.defaultView){return this.contentDocument.defaultView}else{if(this.contentWindow.document){return this.contentWindow}else{return null}}}function a(){this.getWindow().focus();if(this.hasFocus){return}this.hasFocus=true}function d(){this.hasFocus=false}return{getDocument:c,getWindow:b,focus:a,blur:d}})();WysiHat.Editor.include(WysiHat.Window);WysiHat.iFrame={create:function(a,c){var b=new Element("iframe",{id:a.id+"_editor","class":"editor"});Object.extend(b,WysiHat.iFrame.Methods);WysiHat.Editor.extend(b);b.attach(a,c);a.insert({before:b});return b}};WysiHat.iFrame.Methods={attach:function(a,b){this.textarea=a;this.observe("load",function(){try{var c=this.getDocument()}catch(d){return}this.selection=new WysiHat.Selection(this);if(this.ready&&c.designMode=="on"){return}this.setStyle({});c.designMode="on";b(this);this.ready=true;this.fire("wysihat:ready")})},unattach:function(){this.remove()},whenReady:function(b){if(this.ready){b(this)}else{var a=this;a.observe("wysihat:ready",function(){b(a)})}return this},setStyle:function(e){var a=this.getDocument();var c=this;if(!this.ready){return setTimeout(function(){c.setStyle(e)},1)}if(Prototype.Browser.IE){var d=a.createStyleSheet();d.addRule("body","border: 0");d.addRule("p","margin: 0");$H(e).each(function(h){var g=h.first().underscore().dasherize()+": "+h.last();d.addRule("body",g)})}else{if(Prototype.Browser.Opera){var d=Element("style").update("p { margin: 0; }");var b=a.getElementsByTagName("head")[0];b.appendChild(d)}else{Element.setStyle(a.body,e)}}return this},getStyle:function(b){var a=this.getDocument();return Element.getStyle(a.body,b)},rawContent:function(){var a=this.getDocument();if(a.body){return a.body.innerHTML}else{return""}},setRawContent:function(b){var a=this.getDocument();if(a.body){a.body.innerHTML=b}}};WysiHat.Editable={create:function(a,c){var b=new Element("div",{id:a.id+"_editor","class":"editor",contenteditable:"true"});b.textarea=a;WysiHat.Editor.extend(b);Object.extend(b,WysiHat.Editable.Methods);c(b);a.insert({before:b});return b}};WysiHat.Editable.Methods={getDocument:function(){return document},getWindow:function(){return window},rawContent:function(){return this.innerHTML},setRawContent:function(a){this.innerHTML=a}};Object.extend(String.prototype,(function(){function a(){var k=String(this);k=k.tidyXHTML();if(Prototype.Browser.WebKit){k=k.replace(/(<div>)+/g,"\n");k=k.replace(/(<\/div>)+/g,"");k=k.replace(/<p>\s*<\/p>/g,"");k=k.replace(/<br \/>(\n)*/g,"\n")}else{if(Prototype.Browser.Gecko){k=k.replace(/<p>/g,"");k=k.replace(/<\/p>(\n)?/g,"\n");k=k.replace(/<br \/>(\n)*/g,"\n")}else{if(Prototype.Browser.IE||Prototype.Browser.Opera){k=k.replace(/<p>( | |\s)<\/p>/g,"<p></p>");k=k.replace(/<br \/>/g,"");k=k.replace(/<p>/g,"");k=k.replace(/ /g,"");k=k.replace(/<\/p>(\n)?/g,"\n");k=k.gsub(/^<p>/,"");k=k.gsub(/<\/p>$/,"")}}}k=k.gsub(/<b>/,"<strong>");k=k.gsub(/<\/b>/,"</strong>");k=k.gsub(/<i>/,"<em>");k=k.gsub(/<\/i>/,"</em>");k=k.replace(/\n\n+/g,"</p>\n\n<p>");k=k.gsub(/(([^\n])(\n))(?=([^\n]))/,"#{2}<br />\n");k="<p>"+k+"</p>";k=k.replace(/<p>\s*/g,"<p>");k=k.replace(/\s*<\/p>/g,"</p>");var e=Element("body");e.innerHTML=k;if(Prototype.Browser.WebKit||Prototype.Browser.Gecko){var j;do{j=false;e.select("span").each(function(i){if(i.hasClassName("Apple-style-span")){i.removeClassName("Apple-style-span");if(i.className==""){i.removeAttribute("class")}j=true}else{if(i.getStyle("fontWeight")=="bold"){i.setStyle({fontWeight:""});if(i.style.length==0){i.removeAttribute("style")}i.update("<strong>"+i.innerHTML+"</strong>");j=true}else{if(i.getStyle("fontStyle")=="italic"){i.setStyle({fontStyle:""});if(i.style.length==0){i.removeAttribute("style")}i.update("<em>"+i.innerHTML+"</em>");j=true}else{if(i.getStyle("textDecoration")=="underline"){i.setStyle({textDecoration:""});if(i.style.length==0){i.removeAttribute("style")}i.update("<u>"+i.innerHTML+"</u>");j=true}else{if(i.attributes.length==0){i.replace(i.innerHTML);j=true}}}}}})}while(j)}var h=$A(["BR","IMG"]);for(var d=0;d<e.descendants().length;d++){var g=e.descendants()[d];if(g.innerHTML.blank()&&!h.include(g.nodeName)&&g.id!="bookmark"){g.remove()}}k=e.innerHTML;k=k.tidyXHTML();k=k.replace(/<br \/>(\n)*/g,"<br />\n");k=k.replace(/<\/p>\n<p>/g,"</p>\n\n<p>");k=k.replace(/<p>\s*<\/p>/g,"");k=k.replace(/\s*$/g,"");return k}function b(){var e=String(this);var d=Element("body");d.innerHTML=e;if(Prototype.Browser.Gecko||Prototype.Browser.WebKit){d.select("strong").each(function(g){g.replace('<span style="font-weight: bold;">'+g.innerHTML+"</span>")});d.select("em").each(function(g){g.replace('<span style="font-style: italic;">'+g.innerHTML+"</span>")});d.select("u").each(function(g){g.replace('<span style="text-decoration: underline;">'+g.innerHTML+"</span>")})}if(Prototype.Browser.WebKit){d.select("span").each(function(g){if(g.getStyle("fontWeight")=="bold"){g.addClassName("Apple-style-span")}if(g.getStyle("fontStyle")=="italic"){g.addClassName("Apple-style-span")}if(g.getStyle("textDecoration")=="underline"){g.addClassName("Apple-style-span")}})}e=d.innerHTML;e=e.tidyXHTML();e=e.replace(/<\/p>(\n)*<p>/g,"\n\n");e=e.replace(/(\n)?<br( \/)?>(\n)?/g,"\n");e=e.replace(/^<p>/g,"");e=e.replace(/<\/p>$/g,"");if(Prototype.Browser.Gecko){e=e.replace(/\n/g,"<br>");e=e+"<br>"}else{if(Prototype.Browser.WebKit){e=e.replace(/\n/g,"</div><div>");e="<div>"+e+"</div>";e=e.replace(/<div><\/div>/g,"<div><br></div>")}else{if(Prototype.Browser.IE||Prototype.Browser.Opera){e=e.replace(/\n/g,"</p>\n<p>");e="<p>"+e+"</p>";e=e.replace(/<p><\/p>/g,"<p> </p>");e=e.replace(/(<p> <\/p>)+$/g,"")}}}return e}function c(){var d=String(this);d=d.gsub(/\r\n?/,"\n");d=d.gsub(/<([A-Z]+)([^>]*)>/,function(e){return"<"+e[1].toLowerCase()+e[2]+">"});d=d.gsub(/<\/([A-Z]+)>/,function(e){return"</"+e[1].toLowerCase()+">"});d=d.replace(/<br>/g,"<br />");return d}return{formatHTMLOutput:a,formatHTMLInput:b,tidyXHTML:c}})());Object.extend(String.prototype,{sanitize:function(a){return Element("div").update(this).sanitize(a).innerHTML.tidyXHTML()}});Element.addMethods({sanitize:function(c,b){c=$(c);b=$H(b);var a=$A(b.get("tags")||[]);var d=$A(b.get("attributes")||[]);var e=Element(c.nodeName);$A(c.childNodes).each(function(i){if(i.nodeType==1){var g=$(i).sanitize(b).childNodes;if(a.include(i.nodeName.toLowerCase())){var h=Element(i.nodeName);d.each(function(j){if((value=i.readAttribute(j))){h.writeAttribute(j,value)}});e.appendChild(h);$A(g).each(function(j){h.appendChild(j)})}else{$A(g).each(function(j){e.appendChild(j)})}}else{if(i.nodeType==3){e.appendChild(i)}}});return e}});if(typeof Range=="undefined"){Range=function(a){this.ownerDocument=a;this.startContainer=this.ownerDocument.documentElement;this.startOffset=0;this.endContainer=this.ownerDocument.documentElement;this.endOffset=0;this.collapsed=true;this.commonAncestorContainer=this._commonAncestorContainer(this.startContainer,this.endContainer);this.detached=false;this.START_TO_START=0;this.START_TO_END=1;this.END_TO_END=2;this.END_TO_START=3};Range.CLONE_CONTENTS=0;Range.DELETE_CONTENTS=1;Range.EXTRACT_CONTENTS=2;if(!document.createRange){document.createRange=function(){return new Range(this)}}Object.extend(Range.prototype,(function(){function r(){return e(this,Range.CLONE_CONTENTS)}function x(){try{var z=new Range(this.ownerDocument);z.startContainer=this.startContainer;z.startOffset=this.startOffset;z.endContainer=this.endContainer;z.endOffset=this.endOffset;z.collapsed=this.collapsed;z.commonAncestorContainer=this.commonAncestorContainer;z.detached=this.detached;return z}catch(y){return null}}function b(y){if(y){this.endContainer=this.startContainer;this.endOffset=this.startOffset;this.collapsed=true}else{this.startContainer=this.endContainer;this.startOffset=this.endOffset;this.collapsed=true}}function a(z,E){try{var A,D,C,y;A=this.commonAncestorContainer;D=E.commonAncestorContainer;C=A;while(C.parentNode){C=C.parentNode}y=D;while(y.parentNode){y=y.parentNode}switch(z){case this.START_TO_START:return p(this,this.startContainer,this.startOffset,E.startContainer,E.startOffset);break;case this.START_TO_END:return p(this,this.startContainer,this.startOffset,E.endContainer,E.endOffset);break;case this.END_TO_END:return p(this,this.endContainer,this.endOffset,E.endContainer,E.endOffset);break;case this.END_TO_START:return p(this,this.endContainer,this.endOffset,E.startContainer,E.startOffset);break}}catch(B){}return null}function w(){try{e(this,Range.DELETE_CONTENTS)}catch(y){}}function v(){this.detached=true}function o(){try{return e(this,Range.EXTRACT_CONTENTS)}catch(y){return null}}function k(y){try{var C,z,B;switch(this.startContainer.nodeType){case Node.CDATA_SECTION_NODE:case Node.TEXT_NODE:z=this.startContainer.splitText(this.startOffset);this.startContainer.parentNode.insertBefore(y,z);break;default:if(this.startContainer.childNodes.length==0){B=null}else{B=this.startContainer.childNodes(this.startOffset)}this.startContainer.insertBefore(y,B)}}catch(A){}}function d(y){this.setStartBefore(y);this.setEndAfter(y)}function u(y){this.setStart(y,0);this.setEnd(y,y.childNodes.length)}function q(y,C){try{var z,B;this.startContainer=y;this.startOffset=C;z=this.endContainer;while(z.parentNode){z=z.parentNode}B=this.startContainer;while(B.parentNode){B=B.parentNode}if(B!=z){this.collapse(true)}else{if(p(this,this.startContainer,this.startOffset,this.endContainer,this.endOffset)>0){this.collapse(true)}}this.collapsed=t(this);this.commonAncestorContainer=s(this.startContainer,this.endContainer)}catch(A){}}function n(y){this.setStart(y.parentNode,h(y)+1)}function j(y){this.setStart(y.parentNode,h(y))}function i(y,A){try{this.endContainer=y;this.endOffset=A;endRootContainer=this.endContainer;while(endRootContainer.parentNode){endRootContainer=endRootContainer.parentNode}startRootContainer=this.startContainer;while(startRootContainer.parentNode){startRootContainer=startRootContainer.parentNode}if(startRootContainer!=endRootContainer){this.collapse(false)}else{if(p(this,this.startContainer,this.startOffset,this.endContainer,this.endOffset)>0){this.collapse(false)}}this.collapsed=t(this);this.commonAncestorContainer=s(this.startContainer,this.endContainer)}catch(z){}}function g(y){this.setEnd(y.parentNode,h(y)+1)}function l(y){this.setEnd(y.parentNode,h(y))}function m(z){try{var B,y;while(z.firstChild){z.removeChild(z.firstChild)}y=this.extractContents();this.insertNode(z);z.appendChild(y);this.selectNode(z)}catch(A){}}function p(D,B,E,z,C){var G,A,y,F,H;if(B==z){if(E==C){return 0}else{if(E<C){return -1}else{return 1}}}G=z;while(G&&G.parentNode!=B){G=G.parentNode}if(G){A=0;y=B.firstChild;while(y!=G&&A<E){A++;y=y.nextSibling}if(E<=A){return -1}else{return 1}}G=B;while(G&&G.parentNode!=z){G=G.parentNode}if(G){A=0;y=z.firstChild;while(y!=G&&A<C){A++;y=y.nextSibling}if(A<C){return -1}else{return 1}}F=D._commonAncestorContainer(B,z);H=B;while(H&&H.parentNode!=F){H=H.parentNode}if(!H){H=F}childB=z;while(childB&&childB.parentNode!=F){childB=childB.parentNode}if(!childB){childB=F}if(H==childB){return 0}y=F.firstChild;while(y){if(y==H){return -1}if(y==childB){return 1}y=y.nextSibling}return null}function s(A,z){var B=A,y;while(B){y=z;while(y&&B!=y){y=y.parentNode}if(B==y){break}B=B.parentNode}if(!B&&A.ownerDocument){return A.ownerDocument.documentElement}return B}function t(y){return(y.startContainer==y.endContainer&&y.startOffset==y.endOffset)}function c(y){switch(y.nodeType){case Node.CDATA_SECTION_NODE:case Node.COMMENT_NODE:case Node.ELEMENT_NODE:case Node.PROCESSING_INSTRUCTION_NODE:return true;default:return false}}function e(F,N){try{var E,D=null,A=null,y,K,R,O;var P,H,B;var C,L,z;var J,I;var M,G;if(F.collapsed){return null}E=F.commonAncestorContainer;if(F.startContainer!=E){D=F.startContainer;while(D.parentNode!=E){D=D.parentNode}}if(F.endContainer!=E){A=F.endContainer;while(A.parentNode!=E){A=A.parentNode}}if(N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS){y=F.ownerDocument.createDocumentFragment()}if(F.startContainer==F.endContainer){switch(F.startContainer.nodeType){case Node.CDATA_SECTION_NODE:case Node.COMMENT_NODE:case Node.TEXT_NODE:if(N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS){R=F.startContainer.cloneNode();R.deleteData(F.endOffset,F.startContainer.data.length-F.endOffset);R.deleteData(0,F.startOffset);y.appendChild(R)}if(N==Range.EXTRACT_CONTENTS||N==Range.DELETE_CONTENTS){F.startContainer.deleteData(F.startOffset,F.endOffset-F.startOffset)}break;case Node.PROCESSING_INSTRUCTION_NODE:break;default:K=F.startContainer.firstChild;for(O=0;O<F.startOffset;O++){K=K.nextSibling}while(K&&O<F.endOffset){J=K.nextSibling;if(N==Range.EXTRACT_CONTENTS){y.appendChild(K)}else{if(N==Range.CLONE_CONTENTS){y.appendChild(K.cloneNode())}else{F.startContainer.removeChild(K)}}K=J;O++}}F.collapse(true);return y}if(F.startContainer!=E){switch(F.startContainer.nodeType){case Node.CDATA_SECTION_NODE:case Node.COMMENT_NODE:case Node.TEXT_NODE:if(N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS){R=F.startContainer.cloneNode(true);R.deleteData(0,F.startOffset);P=R}if(N==Range.EXTRACT_CONTENTS||N==Range.DELETE_CONTENTS){F.startContainer.deleteData(F.startOffset,F.startContainer.data.length-F.startOffset)}break;case Node.PROCESSING_INSTRUCTION_NODE:break;default:if(N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS){P=F.startContainer.cloneNode(false)}K=F.startContainer.firstChild;for(O=0;O<F.startOffset;O++){K=K.nextSibling}while(K&&O<F.endOffset){J=K.nextSibling;if(N==Range.EXTRACT_CONTENTS){y.appendChild(K)}else{if(N==Range.CLONE_CONTENTS){y.appendChild(K.cloneNode())}else{F.startContainer.removeChild(K)}}K=J;O++}}H=F.startContainer.parentNode;K=F.startContainer.nextSibling;for(;H!=E;H=H.parentNode){if(N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS){B=H.cloneNode(false);B.appendChild(P);P=B}for(;K;K=J){J=K.nextSibling;if(N==Range.EXTRACT_CONTENTS){P.appendChild(K)}else{if(N==Range.CLONE_CONTENTS){P.appendChild(K.cloneNode(true))}else{H.removeChild(K)}}}K=H.nextSibling}}if(F.endContainer!=E){switch(F.endContainer.nodeType){case Node.CDATA_SECTION_NODE:case Node.COMMENT_NODE:case Node.TEXT_NODE:if(N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS){R=F.endContainer.cloneNode(true);R.deleteData(F.endOffset,F.endContainer.data.length-F.endOffset);C=R}if(N==Range.EXTRACT_CONTENTS||N==Range.DELETE_CONTENTS){F.endContainer.deleteData(0,F.endOffset)}break;case Node.PROCESSING_INSTRUCTION_NODE:break;default:if(N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS){C=F.endContainer.cloneNode(false)}K=F.endContainer.firstChild;if(K&&F.endOffset){for(O=0;O+1<F.endOffset;O++){J=K.nextSibling;if(!J){break}K=J}for(;K;K=I){I=K.previousSibling;if(N==Range.EXTRACT_CONTENTS){C.insertBefore(K,C.firstChild)}else{if(N==Range.CLONE_CONTENTS){C.insertBefore(K.cloneNode(True),C.firstChild)}else{F.endContainer.removeChild(K)}}}}}L=F.endContainer.parentNode;K=F.endContainer.previousSibling;for(;L!=E;L=L.parentNode){if(N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS){z=C.cloneNode(false);z.appendChild(C);C=z}for(;K;K=I){I=K.previousSibling;if(N==Range.EXTRACT_CONTENTS){C.insertBefore(K,C.firstChild)}else{if(N==Range.CLONE_CONTENTS){C.appendChild(K.cloneNode(true),C.firstChild)}else{L.removeChild(K)}}}K=L.previousSibling}}if(F.startContainer==E){M=F.startContainer.firstChild;for(O=0;O<F.startOffset;O++){M=M.nextSibling}}else{M=F.startContainer;while(M.parentNode!=E){M=M.parentNode}M=M.nextSibling}if(F.endContainer==E){G=F.endContainer.firstChild;for(O=0;O<F.endOffset;O++){G=G.nextSibling}}else{G=F.endContainer;while(G.parentNode!=E){G=G.parentNode}}if((N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS)&&P){y.appendChild(P)}if(M){for(K=M;K&&K!=G;K=J){J=K.nextSibling;if(N==Range.EXTRACT_CONTENTS){y.appendChild(K)}else{if(N==Range.CLONE_CONTENTS){y.appendChild(K.cloneNode(true))}else{E.removeChild(K)}}}}if((N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS)&&C){y.appendChild(C)}if(N==Range.EXTRACT_CONTENTS||N==Range.DELETE_CONTENTS){if(!D&&!A){F.collapse(true)}else{if(D){F.startContainer=D.parentNode;F.endContainer=D.parentNode;F.startOffset=F.endOffset=F._nodeIndex(D)+1}else{if(A){F.startContainer=A.parentNode;F.endContainer=A.parentNode;F.startOffset=F.endOffset=F._nodeIndex(A)}}}}return y}catch(Q){return null}}function h(y){var z=0;while(y.previousSibling){z++;y=y.previousSibling}return z}return{setStart:q,setEnd:i,setStartBefore:j,setStartAfter:n,setEndBefore:l,setEndAfter:g,collapse:b,selectNode:d,selectNodeContents:u,compareBoundaryPoints:a,deleteContents:w,extractContents:o,cloneContents:r,insertNode:k,surroundContents:m,cloneRange:x,toString:toString,detach:v,_commonAncestorContainer:s}})())}if(!window.getSelection){window.getSelection=function(){return Selection.getInstance()};SelectionImpl=function(){this.anchorNode=null;this.anchorOffset=0;this.focusNode=null;this.focusOffset=0;this.isCollapsed=true;this.rangeCount=0;this.ranges=[]};Object.extend(SelectionImpl.prototype,(function(){function l(o){return true}function k(){return true}function i(){return true}function h(){return true}function c(){return true}function b(){this.anchorNode=null;this.anchorOffset=0;this.focusNode=null;this.focusOffset=0;this.isCollapsed=true;this.rangeCount=0;this.ranges=[]}function n(t){if(t.startContainer.nodeType!=Node.TEXT_NODE){var v=this._getRightStart(t.startContainer);var o=0}else{var v=t.startContainer;var o=t.startOffset}if(t.endContainer.nodeType!=Node.TEXT_NODE){var p=this._getRightEnd(t.endContainer);var s=p.data.length}else{var p=t.endContainer;var s=t.endOffset}var q=this._selectStart(v,o);var u=this._selectEnd(p,s);q.setEndPoint("EndToStart",u);q.select();document.selection._selectedRange=t}function g(p,o){if(p.nodeType!=Node.TEXT_NODE){if(p.nodeType==Node.ELEMENT_NODE){p=p.childNodes(o)}return a(p)}else{return null}}function m(o,p){if(o.nodeType!=Node.TEXT_NODE){if(o.nodeType==Node.ELEMENT_NODE){o=o.childNodes(p)}return e(o)}else{return null}}function d(v,u){var q=document.body.createTextRange();if(v.nodeType==Node.TEXT_NODE){var s=u,p=v;var o=null,t=true;while(p.previousSibling){switch(p.previousSibling.nodeType){case Node.ELEMENT_NODE:o=p.previousSibling;t=false;break;case Node.TEXT_NODE:s+=p.previousSibling.data.length}if(o!=null){break}p=p.previousSibling}if(o==null){o=v.parentNode}q.moveToElementText(o);q.collapse(t);q.move("Character",s);return q}else{return null}}function j(o,v){var s=document.body.createTextRange(),q=o;if(o.nodeType==3){var t=o.data.length-v;var p=null,u=false;while(q.nextSibling){switch(q.nextSibling.nodeType){case Node.ELEMENT_NODE:p=q.nextSibling;u=true;break;case Node.TEXT_NODE:t+=q.nextSibling.data.length;break}if(p!=null){break}q=q.nextSibling}if(p==null){p=o.parentNode;u=false}switch(p.nodeName.toLowerCase()){case"p":case"div":case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":t++}s.moveToElementText(p);s.collapse(u);s.move("Character",-t);return s}return null}function e(p){var o=[];var q=null;while(p){o=[];q=p;while(q){while(q){if(q.nodeType==3&&q.data.replace(/^\s+|\s+$/,"").length){return q}if(q.previousSibling){o.push(q.previousSibling)}q=q.lastChild}q=o.pop()}p=p.previousSibling}return null}function a(p){var o=[];var q=null;while(p){o=[];q=p;while(q){while(q){if(q.nodeType==3&&q.data.replace(/^\s+|\s+$/,"").length){return q}if(q.nextSibling){o.push(q.nextSibling)}q=q.firstChild}q=o.pop()}p=p.nextSibling}return null}return{removeAllRanges:b,_addRange:n,_getRightStart:g,_getRightEnd:m,_selectStart:d,_selectEnd:j}})());Selection=new function(){var a=null;this.getInstance=function(){if(a==null){return(a=new SelectionImpl())}else{return a}}}}Object.extend(Range.prototype,(function(){function a(){var b=this.commonAncestorContainer;if(this.startContainer==this.endContainer){if(this.startOffset-this.endOffset<2){b=this.startContainer.childNodes[this.startOffset]}}while(b.nodeType==Node.TEXT_NODE){b=b.parentNode}return b}return{getNode:a}})());WysiHat.Selection=Class.create((function(){function g(n){this.window=n.getWindow();this.document=n.getDocument();if(Prototype.Browser.IE){n.observe("wysihat:cursormove",i.bind(this));n.observe("wysihat:focus",m)}}function e(){return this.window.getSelection?this.window.getSelection():this.document.selection}function a(){var n=null,o=this.getSelection();try{if(o.getRangeAt){n=o.getRangeAt(0)}else{n=o.createRange()}}catch(p){return null}if(Prototype.Browser.WebKit){n.setStart(o.baseNode,o.baseOffset);n.setEnd(o.extentNode,o.extentOffset)}return n}function d(p){var o=this.getSelection();if(Prototype.Browser.IE){var n=h(this.document,p);n.select()}else{if(Prototype.Browser.WebKit){o.setBaseAndExtent(p,0,p,p.innerText.length)}else{if(Prototype.Browser.Opera){n=this.document.createRange();n.selectNode(p);o.removeAllRanges();o.addRange(n)}else{var n=h(this.document,p);o.removeAllRanges();o.addRange(n)}}}}function c(){var n=null,s=[],q,p;var t=this.getRange();if(!t){return null}var u;if(t.parentElement){u=t.parentElement()}else{u=t.commonAncestorContainer}if(u){while(u.nodeType!=1){u=u.parentNode}if(u.nodeName.toLowerCase()!="body"){p=u;do{p=p.parentNode;s[s.length]=p}while(p.nodeName.toLowerCase()!="body")}q=u.all||u.getElementsByTagName("*");for(var r=0;r<q.length;r++){s[s.length]=q[r]}n=[u];for(var v=0,o;v<s.length;v++){o=h(this.document,s[v]);if(o&&b(t,o)){n[n.length]=s[v]}}}return n.first()}function h(n,p){if(n.body.createTextRange){var o=n.body.createTextRange();o.moveToElementText(p)}else{if(n.createRange){var o=n.createRange();o.selectNodeContents(p)}}return o}function b(o,n){if(o.compareEndPoints){return !(n.compareEndPoints("StartToStart",o)==1&&n.compareEndPoints("EndToEnd",o)==1&&n.compareEndPoints("StartToEnd",o)==1&&n.compareEndPoints("EndToStart",o)==1||n.compareEndPoints("StartToStart",o)==-1&&n.compareEndPoints("EndToEnd",o)==-1&&n.compareEndPoints("StartToEnd",o)==-1&&n.compareEndPoints("EndToStart",o)==-1)}else{if(o.compareBoundaryPoints){return !(n.compareBoundaryPoints(0,o)==1&&n.compareBoundaryPoints(2,o)==1&&n.compareBoundaryPoints(1,o)==1&&n.compareBoundaryPoints(3,o)==1||n.compareBoundaryPoints(0,o)==-1&&n.compareBoundaryPoints(2,o)==-1&&n.compareBoundaryPoints(1,o)==-1&&n.compareBoundaryPoints(3,o)==-1)}}return null}function l(){var p=this.document.getElementById("bookmark");if(p){p.parentNode.removeChild(p)}p=this.document.createElement("span");p.id="bookmark";p.innerHTML=" ";if(Prototype.Browser.IE){var n=this.document.selection.createRange();var o=this.document.createElement("div");o.appendChild(p);n.collapse();n.pasteHTML(o.innerHTML)}else{var n=this.getRange();n.insertNode(p)}}function k(){var p=this.document.getElementById("bookmark");if(!p){return}if(Prototype.Browser.IE){var n=this.getRange();n.moveToElementText(p);n.collapse();n.select()}else{if(Prototype.Browser.WebKit){var o=this.getSelection();o.setBaseAndExtent(p,0,p,0)}else{var n=this.getRange();n.setStartBefore(p)}}p.parentNode.removeChild(p)}var j=null;function i(){j=this.getRange()}function m(){if(j){j.select()}}return{initialize:g,getSelection:e,getRange:a,getNode:c,selectNode:d,setBookmark:l,moveToBookmark:k,restore:m}})());WysiHat.Toolbar=Class.create((function(){function e(l){this.editor=l;this.element=this.createToolbarElement()}function a(){var l=new Element("div",{"class":"editor_toolbar"});this.editor.insert({before:l});return l}function d(m){var l=this;$A(m).each(function(n){l.addButton(n)})}function j(m,o){m=$H(m);if(!m.get("name")){m.set("name",m.get("label").toLowerCase())}var l=m.get("name");var n=this.createButtonElement(this.element,m);var o=this.buttonHandler(l,m);this.observeButtonClick(n,o);var o=this.buttonStateHandler(l,m);this.observeStateChanges(n,l,o)}function i(n,l){var m=new Element("a",{"class":"button",href:"#"});m.update("<span>"+l.get("label")+"</span>");m.addClassName(l.get("name"));n.appendChild(m);return m}function k(m,l){if(l.handler){return l.handler}else{if(l.get("handler")){return l.get("handler")}else{return function(n){n.execCommand(m)}}}}function g(l,m){var n=this;l.observe("click",function(o){m(n.editor);n.editor.fire("wysihat:change");n.editor.fire("wysihat:cursormove");Event.stop(o)})}function c(m,l){if(l.query){return l.query}else{if(l.get("query")){return l.get("query")}else{return function(n){return n.queryCommandState(m)}}}}function h(n,m,o){var p=this;var l=false;p.editor.observe("wysihat:cursormove",function(q){var r=o(p.editor);if(r!=l){l=r;p.updateButtonState(n,m,r)}})}function b(m,l,n){if(n){m.addClassName("selected")}else{m.removeClassName("selected")}}return{initialize:e,createToolbarElement:a,addButtonSet:d,addButton:j,createButtonElement:i,buttonHandler:k,observeButtonClick:g,buttonStateHandler:c,observeStateChanges:h,updateButtonState:b}})());WysiHat.Toolbar.ButtonSets={};WysiHat.Toolbar.ButtonSets.Basic=$A([{label:"Bold"},{label:"Underline"},{label:"Italic"}]);var editors=[];var WysihatHelper={faceboxFile:function(){facebox.loading();new Effect.Appear($("facebox"),{duration:0.3});var b=facebox;var a="/wysihat_files/?editor="+this.id;new Ajax.Request(a,{method:"get",onFailure:function(c){b.reveal(c.responseText,null)},onSuccess:function(c){b.reveal(c.responseText,null)}})},faceboxLink:function(){if(this.linkSelected()){this.unlinkSelection()}else{facebox.loading();new Effect.Appear($("facebox"),{duration:0.3});iframe=this;facebox.reveal('<input type="text" id="link_field" style="width:100%;"/>',null);Event.observe("link_field","change",function(a){iframe.linkSelection($("link_field").value)})}},faceboxHTML:function(){facebox.loading();new Effect.Appear($("facebox"),{duration:0.3});iframe=this;facebox.reveal('<textarea id="html_editor" style="width:100%; height:400px;">'+iframe.contentWindow.document.body.innerHTML+"</textarea>",null);Event.observe("html_editor","change",function(a){iframe.contentWindow.document.body.innerHTML=$("html_editor").value})}};function wysiHatify(d,c){WysiHat.Editor.include(WysihatHelper);var a=WysiHat.Editor.attach(d);var b=new WysiHat.Toolbar(a);editors.push(a);$$("form").each(function(e){e.onsubmit=function(){editors.each(function(g){g.save()})}});c.each(function(e){switch(e.toLowerCase()){case"image":b.addButton({label:e.gsub("_","-").camelize().capitalize(),handler:function(g){return g.faceboxFile(g)}});break;case"link":b.addButton({label:e.gsub("_","-").camelize().capitalize(),handler:function(g){return g.faceboxLink(g)}});break;case"html":b.addButton({label:e.gsub("_","-").camelize().capitalize(),handler:function(g){return g.faceboxHTML(g)}});break;case"paste":b.addButton({label:e.gsub("_","-").camelize().capitalize(),handler:function(g){return g.faceboxPaste(g)}});break;default:b.addButton({label:e.gsub("_","-").camelize().capitalize()})}})};
|
1
|
+
var Facebox=Class.create({initialize:function(a){this.settings={loading_image:"/images/facebox/loading.gif",close_image:"/images/facebox/closelabel.gif",image_types:new RegExp("."+["png","jpg","jpeg","gif"].join("|")+"$","i"),inited:true,facebox_html:' <div id="facebox" style="display:none;"> <div class="popup"> <table id="facebox_table"> <tbody> <tr> <td class="tl"/><td class="b"/><td class="tr"/> </tr> <tr> <td class="b"/> <td class="body"> <div class="content"> </div> <div class="footer"> <a href="#" class="close"> <img src="/images/facebox/closelabel.gif" title="close" class="close_image" /> </a> </div> </td> <td class="b"/> </tr> <tr> <td class="bl"/><td class="b"/><td class="br"/> </tr> </tbody> </table> </div> </div>'};if(a){Object.extend(this.settings,a)}$(document.body).insert({bottom:this.settings.facebox_html});this.preload=[new Image(),new Image()];this.preload[0].src=this.settings.close_image;this.preload[1].src=this.settings.loading_image;f=this;$$("#facebox .b:first, #facebox .bl, #facebox .br, #facebox .tl, #facebox .tr").each(function(b){f.preload.push(new Image());f.preload.slice(-1).src=b.getStyle("background-image").replace(/url\((.+)\)/,"$1")});this.facebox=$("facebox");this.keyPressListener=this.watchKeyPress.bindAsEventListener(this);this.watchClickEvents();fb=this;Event.observe($$("#facebox .close").first(),"click",function(b){Event.stop(b);fb.close()});Event.observe($$("#facebox .close_image").first(),"click",function(b){Event.stop(b);fb.close()})},watchKeyPress:function(a){if(a.keyCode==27||!Event.element(a).descendantOf(this.facebox)){this.close()}},watchClickEvents:function(b){var a=this;$$("a[rel=facebox]").each(function(d,c){Event.observe(d,"click",function(g){Event.stop(g);a.click_handler(d,g)})})},loading:function(){if($$("#facebox .loading").length==1){return true}contentWrapper=$$("#facebox .content").first();contentWrapper.childElements().each(function(c,b){c.remove()});contentWrapper.insert({bottom:'<div class="loading"><img src="'+this.settings.loading_image+'"/></div>'});var a=document.viewport.getScrollOffsets();this.facebox.setStyle({top:a.top+(document.viewport.getHeight()/10)+"px",left:document.viewport.getWidth()/2-(this.facebox.getWidth()/2)+"px"});Event.observe(document,"keypress",this.keyPressListener);Event.observe(document,"click",this.keyPressListener)},reveal:function(b,a){this.loading();load=$$("#facebox .loading").first();if(load){load.remove()}contentWrapper=$$("#facebox .content").first();if(a){contentWrapper.addClassName(a)}contentWrapper.update(b);$$("#facebox .body").first().childElements().each(function(d,c){d.show()});if(!this.facebox.visible()){new Effect.Appear(this.facebox,{duration:0.3})}this.facebox.setStyle({left:document.viewport.getWidth()/2-(this.facebox.getWidth()/2)+"px"});Event.observe(document,"keypress",this.keyPressListener);Event.observe(document,"click",this.keyPressListener)},close:function(){new Effect.Fade("facebox",{duration:0.3})},click_handler:function(c,i){this.loading();Event.stop(i);var k=c.rel.match(/facebox\[\.(\w+)\]/);if(k){k=k[1]}new Effect.Appear(this.facebox,{duration:0.3});if(c.href.match(/#/)){var a=window.location.href.split("#")[0];var j=c.href.replace(a+"#","");var l=$(j);var h=new Element(l.tagName);h.innerHTML=l.innerHTML;this.reveal(h,k)}else{if(c.href.match(this.settings.image_types)){var g=new Image();b=this;g.onload=function(){b.reveal('<div class="image"><img src="'+g.src+'" /></div>',k)};g.src=c.href}else{var b=this;var a=c.href;new Ajax.Request(a,{method:"get",onFailure:function(d){b.reveal(d.responseText,k)},onSuccess:function(d){b.reveal(d.responseText,k)}})}}}});var facebox;document.observe("dom:loaded",function(){facebox=new Facebox()});var WysiHat={};WysiHat.Editor={attach:function(a,c,e){c=$H(c);a=$(a);a.hide();var b=c.get("model")||WysiHat.iFrame;var d=e;return b.create(a,function(h){var g=h.getDocument();var i=h.getWindow();h.load();Event.observe(i,"focus",function(j){h.focus()});Event.observe(i,"blur",function(j){h.blur()});h._observeEvents();if(Prototype.Browser.Gecko){h.execCommand("undo",false,null)}if(d){d(h)}h.focus()})},include:function(a){this.includedModules=this.includedModules||$A([]);this.includedModules.push(a)},extend:function(b){var a=this.includedModules||$A([]);a.each(function(c){Object.extend(b,c)})}};WysiHat.Commands=(function(){function h(){this.execCommand("bold",false,null)}function r(){return this.queryCommandState("bold")}function z(){this.execCommand("underline",false,null)}function s(){return this.queryCommandState("underline")}function n(){this.execCommand("italic",false,null)}function x(){return this.queryCommandState("italic")}function q(){this.execCommand("strikethrough",false,null)}function d(){this.execCommand("blockquote",false,null)}function m(A){this.execCommand("fontname",false,A)}function p(A){this.execCommand("fontsize",false,A)}function y(A){this.execCommand("forecolor",false,A)}function l(A){if(Prototype.Browser.Gecko){this.execCommand("hilitecolor",false,A)}else{this.execCommand("backcolor",false,A)}}function w(A){this.execCommand("justify"+A)}function b(){var A=this.selection.getNode();return Element.getStyle(A,"textAlign")}function g(A){this.execCommand("createLink",false,A)}function i(){var A=this.selection.getNode();if(this.linkSelected()){this.selection.selectNode(A)}this.execCommand("unlink",false,null)}function v(){var A=this.selection.getNode();return A?A.tagName.toUpperCase()=="A":false}function o(A){this.execCommand("formatblock",false,A)}function k(){this.execCommand("insertorderedlist",false,null)}function j(){this.execCommand("insertunorderedlist",false,null)}function c(A){this.execCommand("insertImage",false,A)}function a(B){if(Prototype.Browser.IE){var A=this._selection.getRange();A.pasteHTML(B);A.collapse(false);A.select()}else{this.execCommand("insertHTML",false,B)}}function t(E,D,C){var A=this.getDocument();if(Prototype.Browser.IE){this.selection.restore()}var B=this.commands.get(E);if(B){B.bind(this)(C)}else{A.execCommand(E,D,C)}}function e(C){var A=this.getDocument();var B=this.queryCommands.get(C);if(B){return B.bind(this)()}else{return A.queryCommandState(C)}}function u(){var B=$H({});var A=this;A.styleSelectors.each(function(C){var D=A.selection.getNode();B.set(C.first(),Element.getStyle(D,C.last()))});return B}return{boldSelection:h,boldSelected:r,underlineSelection:z,underlineSelected:s,italicSelection:n,italicSelected:x,strikethroughSelection:q,blockquoteSelection:d,fontSelection:m,fontSizeSelection:p,colorSelection:y,backgroundColorSelection:l,alignSelection:w,alignSelected:b,linkSelection:g,unlinkSelection:i,linkSelected:v,formatblockSelection:o,insertOrderedList:k,insertUnorderedList:j,insertImage:c,insertHTML:a,execCommand:t,queryCommandState:e,getSelectedStyles:u,commands:$H({}),queryCommands:$H({link:v}),styleSelectors:$H({fontname:"fontFamily",fontsize:"fontSize",forecolor:"color",hilitecolor:"backgroundColor",backcolor:"backgroundColor"})}})();WysiHat.Editor.include(WysiHat.Commands);WysiHat.Events=(function(){var a=["click","dblclick","mousedown","mouseup","mouseover","mousemove","mouseout","keypress","keydown","keyup"];function b(j,k){a.each(function(l){Event.observe(j,l,function(m){k.fire("wysihat:"+l)})})}function g(l,j,k){Event.observe(j,"keydown",function(m){if(m.keyCode==86){k.fire("wysihat:paste")}});Event.observe(l,"paste",function(m){k.fire("wysihat:paste")})}function c(k,j){Event.observe(k,"focus",function(l){j.fire("wysihat:focus")});Event.observe(k,"blur",function(l){j.fire("wysihat:blur")})}function i(j,k){Event.observe(j,"mouseup",function(m){var l=k.selection.getRange();if(!l.collapsed){k.fire("wysihat:select")}})}function e(j,k){var l=k.rawContent();Event.observe(j,"keyup",function(n){var m=k.rawContent();if(l!=m){k.fire("wysihat:change");l=m}})}function d(j,l){var m=l.selection.getRange();var k=function(o){var n=l.selection.getRange();if(m!=n){l.fire("wysihat:cursormove");m=n}};Event.observe(j,"keyup",k);Event.observe(j,"mouseup",k)}function h(){if(this._observers_setup){return}var j=this.getDocument();var k=this.getWindow();b(j,this);g(k,j,this);c(k,this);i(j,this);e(j,this);d(j,this);this._observers_setup=true}return{_observeEvents:h}})();WysiHat.Editor.include(WysiHat.Events);WysiHat.Persistence=(function(){function h(i){return i.formatHTMLOutput()}function a(i){return i.formatHTMLInput()}function e(){return this.outputFilter(this.rawContent())}function d(i){this.setRawContent(this.inputFilter(i))}function c(){this.textarea.value=this.content()}function g(){this.setContent(this.textarea.value)}function b(){this.selection.setBookmark();this.save();this.load();this.selection.moveToBookmark()}return{outputFilter:h,inputFilter:a,content:e,setContent:d,save:c,load:g,reload:b}})();WysiHat.Editor.include(WysiHat.Persistence);WysiHat.Window=(function(){function c(){return this.contentDocument||this.contentWindow.document}function b(){if(this.contentDocument&&this.contentDocument.defaultView){return this.contentDocument.defaultView}else{if(this.contentWindow.document){return this.contentWindow}else{return null}}}function a(){this.getWindow().focus();if(this.hasFocus){return}this.hasFocus=true}function d(){this.hasFocus=false}return{getDocument:c,getWindow:b,focus:a,blur:d}})();WysiHat.Editor.include(WysiHat.Window);WysiHat.iFrame={create:function(a,c){var b=new Element("iframe",{id:a.id+"_editor","class":"editor"});Object.extend(b,WysiHat.iFrame.Methods);WysiHat.Editor.extend(b);b.attach(a,c);a.insert({before:b});return b}};WysiHat.iFrame.Methods={attach:function(a,b){this.textarea=a;this.observe("load",function(){try{var c=this.getDocument()}catch(d){return}this.selection=new WysiHat.Selection(this);if(this.ready&&c.designMode=="on"){return}this.setStyle({});c.designMode="on";b(this);this.ready=true;this.fire("wysihat:ready")})},unattach:function(){this.remove()},whenReady:function(b){if(this.ready){b(this)}else{var a=this;a.observe("wysihat:ready",function(){b(a)})}return this},setStyle:function(e){var a=this.getDocument();var c=this;if(!this.ready){return setTimeout(function(){c.setStyle(e)},1)}if(Prototype.Browser.IE){var d=a.createStyleSheet();d.addRule("body","border: 0");d.addRule("p","margin: 0");$H(e).each(function(h){var g=h.first().underscore().dasherize()+": "+h.last();d.addRule("body",g)})}else{if(Prototype.Browser.Opera){var d=Element("style").update("p { margin: 0; }");var b=a.getElementsByTagName("head")[0];b.appendChild(d)}else{Element.setStyle(a.body,e)}}return this},getStyle:function(b){var a=this.getDocument();return Element.getStyle(a.body,b)},rawContent:function(){var a=this.getDocument();if(a.body){return a.body.innerHTML}else{return""}},setRawContent:function(b){var a=this.getDocument();if(a.body){a.body.innerHTML=b}}};WysiHat.Editable={create:function(a,c){var b=new Element("div",{id:a.id+"_editor","class":"editor",contenteditable:"true"});b.textarea=a;WysiHat.Editor.extend(b);Object.extend(b,WysiHat.Editable.Methods);c(b);a.insert({before:b});return b}};WysiHat.Editable.Methods={getDocument:function(){return document},getWindow:function(){return window},rawContent:function(){return this.innerHTML},setRawContent:function(a){this.innerHTML=a}};Object.extend(String.prototype,(function(){function a(){var k=String(this);k=k.tidyXHTML();if(Prototype.Browser.WebKit){k=k.replace(/(<div>)+/g,"\n");k=k.replace(/(<\/div>)+/g,"");k=k.replace(/<p>\s*<\/p>/g,"");k=k.replace(/<br \/>(\n)*/g,"\n")}else{if(Prototype.Browser.Gecko){k=k.replace(/<p>/g,"");k=k.replace(/<\/p>(\n)?/g,"\n");k=k.replace(/<br \/>(\n)*/g,"\n")}else{if(Prototype.Browser.IE||Prototype.Browser.Opera){k=k.replace(/<p>( | |\s)<\/p>/g,"<p></p>");k=k.replace(/<br \/>/g,"");k=k.replace(/<p>/g,"");k=k.replace(/ /g,"");k=k.replace(/<\/p>(\n)?/g,"\n");k=k.gsub(/^<p>/,"");k=k.gsub(/<\/p>$/,"")}}}k=k.gsub(/<b>/,"<strong>");k=k.gsub(/<\/b>/,"</strong>");k=k.gsub(/<i>/,"<em>");k=k.gsub(/<\/i>/,"</em>");k=k.replace(/\n\n+/g,"</p>\n\n<p>");k=k.gsub(/(([^\n])(\n))(?=([^\n]))/,"#{2}<br />\n");k="<p>"+k+"</p>";k=k.replace(/<p>\s*/g,"<p>");k=k.replace(/\s*<\/p>/g,"</p>");var e=Element("body");e.innerHTML=k;if(Prototype.Browser.WebKit||Prototype.Browser.Gecko){var j;do{j=false;e.select("span").each(function(i){if(i.hasClassName("Apple-style-span")){i.removeClassName("Apple-style-span");if(i.className==""){i.removeAttribute("class")}j=true}else{if(i.getStyle("fontWeight")=="bold"){i.setStyle({fontWeight:""});if(i.style.length==0){i.removeAttribute("style")}i.update("<strong>"+i.innerHTML+"</strong>");j=true}else{if(i.getStyle("fontStyle")=="italic"){i.setStyle({fontStyle:""});if(i.style.length==0){i.removeAttribute("style")}i.update("<em>"+i.innerHTML+"</em>");j=true}else{if(i.getStyle("textDecoration")=="underline"){i.setStyle({textDecoration:""});if(i.style.length==0){i.removeAttribute("style")}i.update("<u>"+i.innerHTML+"</u>");j=true}else{if(i.attributes.length==0){i.replace(i.innerHTML);j=true}}}}}})}while(j)}var h=$A(["BR","IMG"]);for(var d=0;d<e.descendants().length;d++){var g=e.descendants()[d];if(g.innerHTML.blank()&&!h.include(g.nodeName)&&g.id!="bookmark"){g.remove()}}k=e.innerHTML;k=k.tidyXHTML();k=k.replace(/<br \/>(\n)*/g,"<br />\n");k=k.replace(/<\/p>\n<p>/g,"</p>\n\n<p>");k=k.replace(/<p>\s*<\/p>/g,"");k=k.replace(/\s*$/g,"");return k}function b(){var e=String(this);var d=Element("body");d.innerHTML=e;if(Prototype.Browser.Gecko||Prototype.Browser.WebKit){d.select("strong").each(function(g){g.replace('<span style="font-weight: bold;">'+g.innerHTML+"</span>")});d.select("em").each(function(g){g.replace('<span style="font-style: italic;">'+g.innerHTML+"</span>")});d.select("u").each(function(g){g.replace('<span style="text-decoration: underline;">'+g.innerHTML+"</span>")})}if(Prototype.Browser.WebKit){d.select("span").each(function(g){if(g.getStyle("fontWeight")=="bold"){g.addClassName("Apple-style-span")}if(g.getStyle("fontStyle")=="italic"){g.addClassName("Apple-style-span")}if(g.getStyle("textDecoration")=="underline"){g.addClassName("Apple-style-span")}})}e=d.innerHTML;e=e.tidyXHTML();e=e.replace(/<\/p>(\n)*<p>/g,"\n\n");e=e.replace(/(\n)?<br( \/)?>(\n)?/g,"\n");e=e.replace(/^<p>/g,"");e=e.replace(/<\/p>$/g,"");if(Prototype.Browser.Gecko){e=e.replace(/\n/g,"<br>");e=e+"<br>"}else{if(Prototype.Browser.WebKit){e=e.replace(/\n/g,"</div><div>");e="<div>"+e+"</div>";e=e.replace(/<div><\/div>/g,"<div><br></div>")}else{if(Prototype.Browser.IE||Prototype.Browser.Opera){e=e.replace(/\n/g,"</p>\n<p>");e="<p>"+e+"</p>";e=e.replace(/<p><\/p>/g,"<p> </p>");e=e.replace(/(<p> <\/p>)+$/g,"")}}}return e}function c(){var d=String(this);d=d.gsub(/\r\n?/,"\n");d=d.gsub(/<([A-Z]+)([^>]*)>/,function(e){return"<"+e[1].toLowerCase()+e[2]+">"});d=d.gsub(/<\/([A-Z]+)>/,function(e){return"</"+e[1].toLowerCase()+">"});d=d.replace(/<br>/g,"<br />");return d}return{formatHTMLOutput:a,formatHTMLInput:b,tidyXHTML:c}})());Object.extend(String.prototype,{sanitize:function(a){return Element("div").update(this).sanitize(a).innerHTML.tidyXHTML()}});Element.addMethods({sanitize:function(c,b){c=$(c);b=$H(b);var a=$A(b.get("tags")||[]);var d=$A(b.get("attributes")||[]);var e=Element(c.nodeName);$A(c.childNodes).each(function(i){if(i.nodeType==1){var g=$(i).sanitize(b).childNodes;if(a.include(i.nodeName.toLowerCase())){var h=Element(i.nodeName);d.each(function(j){if((value=i.readAttribute(j))){h.writeAttribute(j,value)}});e.appendChild(h);$A(g).each(function(j){h.appendChild(j)})}else{$A(g).each(function(j){e.appendChild(j)})}}else{if(i.nodeType==3){e.appendChild(i)}}});return e}});if(typeof Range=="undefined"){Range=function(a){this.ownerDocument=a;this.startContainer=this.ownerDocument.documentElement;this.startOffset=0;this.endContainer=this.ownerDocument.documentElement;this.endOffset=0;this.collapsed=true;this.commonAncestorContainer=this._commonAncestorContainer(this.startContainer,this.endContainer);this.detached=false;this.START_TO_START=0;this.START_TO_END=1;this.END_TO_END=2;this.END_TO_START=3};Range.CLONE_CONTENTS=0;Range.DELETE_CONTENTS=1;Range.EXTRACT_CONTENTS=2;if(!document.createRange){document.createRange=function(){return new Range(this)}}Object.extend(Range.prototype,(function(){function r(){return e(this,Range.CLONE_CONTENTS)}function x(){try{var z=new Range(this.ownerDocument);z.startContainer=this.startContainer;z.startOffset=this.startOffset;z.endContainer=this.endContainer;z.endOffset=this.endOffset;z.collapsed=this.collapsed;z.commonAncestorContainer=this.commonAncestorContainer;z.detached=this.detached;return z}catch(y){return null}}function b(y){if(y){this.endContainer=this.startContainer;this.endOffset=this.startOffset;this.collapsed=true}else{this.startContainer=this.endContainer;this.startOffset=this.endOffset;this.collapsed=true}}function a(z,E){try{var A,D,C,y;A=this.commonAncestorContainer;D=E.commonAncestorContainer;C=A;while(C.parentNode){C=C.parentNode}y=D;while(y.parentNode){y=y.parentNode}switch(z){case this.START_TO_START:return p(this,this.startContainer,this.startOffset,E.startContainer,E.startOffset);break;case this.START_TO_END:return p(this,this.startContainer,this.startOffset,E.endContainer,E.endOffset);break;case this.END_TO_END:return p(this,this.endContainer,this.endOffset,E.endContainer,E.endOffset);break;case this.END_TO_START:return p(this,this.endContainer,this.endOffset,E.startContainer,E.startOffset);break}}catch(B){}return null}function w(){try{e(this,Range.DELETE_CONTENTS)}catch(y){}}function v(){this.detached=true}function o(){try{return e(this,Range.EXTRACT_CONTENTS)}catch(y){return null}}function k(y){try{var C,z,B;switch(this.startContainer.nodeType){case Node.CDATA_SECTION_NODE:case Node.TEXT_NODE:z=this.startContainer.splitText(this.startOffset);this.startContainer.parentNode.insertBefore(y,z);break;default:if(this.startContainer.childNodes.length==0){B=null}else{B=this.startContainer.childNodes(this.startOffset)}this.startContainer.insertBefore(y,B)}}catch(A){}}function d(y){this.setStartBefore(y);this.setEndAfter(y)}function u(y){this.setStart(y,0);this.setEnd(y,y.childNodes.length)}function q(y,C){try{var z,B;this.startContainer=y;this.startOffset=C;z=this.endContainer;while(z.parentNode){z=z.parentNode}B=this.startContainer;while(B.parentNode){B=B.parentNode}if(B!=z){this.collapse(true)}else{if(p(this,this.startContainer,this.startOffset,this.endContainer,this.endOffset)>0){this.collapse(true)}}this.collapsed=t(this);this.commonAncestorContainer=s(this.startContainer,this.endContainer)}catch(A){}}function n(y){this.setStart(y.parentNode,h(y)+1)}function j(y){this.setStart(y.parentNode,h(y))}function i(y,A){try{this.endContainer=y;this.endOffset=A;endRootContainer=this.endContainer;while(endRootContainer.parentNode){endRootContainer=endRootContainer.parentNode}startRootContainer=this.startContainer;while(startRootContainer.parentNode){startRootContainer=startRootContainer.parentNode}if(startRootContainer!=endRootContainer){this.collapse(false)}else{if(p(this,this.startContainer,this.startOffset,this.endContainer,this.endOffset)>0){this.collapse(false)}}this.collapsed=t(this);this.commonAncestorContainer=s(this.startContainer,this.endContainer)}catch(z){}}function g(y){this.setEnd(y.parentNode,h(y)+1)}function l(y){this.setEnd(y.parentNode,h(y))}function m(z){try{var B,y;while(z.firstChild){z.removeChild(z.firstChild)}y=this.extractContents();this.insertNode(z);z.appendChild(y);this.selectNode(z)}catch(A){}}function p(D,B,E,z,C){var G,A,y,F,H;if(B==z){if(E==C){return 0}else{if(E<C){return -1}else{return 1}}}G=z;while(G&&G.parentNode!=B){G=G.parentNode}if(G){A=0;y=B.firstChild;while(y!=G&&A<E){A++;y=y.nextSibling}if(E<=A){return -1}else{return 1}}G=B;while(G&&G.parentNode!=z){G=G.parentNode}if(G){A=0;y=z.firstChild;while(y!=G&&A<C){A++;y=y.nextSibling}if(A<C){return -1}else{return 1}}F=D._commonAncestorContainer(B,z);H=B;while(H&&H.parentNode!=F){H=H.parentNode}if(!H){H=F}childB=z;while(childB&&childB.parentNode!=F){childB=childB.parentNode}if(!childB){childB=F}if(H==childB){return 0}y=F.firstChild;while(y){if(y==H){return -1}if(y==childB){return 1}y=y.nextSibling}return null}function s(A,z){var B=A,y;while(B){y=z;while(y&&B!=y){y=y.parentNode}if(B==y){break}B=B.parentNode}if(!B&&A.ownerDocument){return A.ownerDocument.documentElement}return B}function t(y){return(y.startContainer==y.endContainer&&y.startOffset==y.endOffset)}function c(y){switch(y.nodeType){case Node.CDATA_SECTION_NODE:case Node.COMMENT_NODE:case Node.ELEMENT_NODE:case Node.PROCESSING_INSTRUCTION_NODE:return true;default:return false}}function e(F,N){try{var E,D=null,A=null,y,K,R,O;var P,H,B;var C,L,z;var J,I;var M,G;if(F.collapsed){return null}E=F.commonAncestorContainer;if(F.startContainer!=E){D=F.startContainer;while(D.parentNode!=E){D=D.parentNode}}if(F.endContainer!=E){A=F.endContainer;while(A.parentNode!=E){A=A.parentNode}}if(N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS){y=F.ownerDocument.createDocumentFragment()}if(F.startContainer==F.endContainer){switch(F.startContainer.nodeType){case Node.CDATA_SECTION_NODE:case Node.COMMENT_NODE:case Node.TEXT_NODE:if(N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS){R=F.startContainer.cloneNode();R.deleteData(F.endOffset,F.startContainer.data.length-F.endOffset);R.deleteData(0,F.startOffset);y.appendChild(R)}if(N==Range.EXTRACT_CONTENTS||N==Range.DELETE_CONTENTS){F.startContainer.deleteData(F.startOffset,F.endOffset-F.startOffset)}break;case Node.PROCESSING_INSTRUCTION_NODE:break;default:K=F.startContainer.firstChild;for(O=0;O<F.startOffset;O++){K=K.nextSibling}while(K&&O<F.endOffset){J=K.nextSibling;if(N==Range.EXTRACT_CONTENTS){y.appendChild(K)}else{if(N==Range.CLONE_CONTENTS){y.appendChild(K.cloneNode())}else{F.startContainer.removeChild(K)}}K=J;O++}}F.collapse(true);return y}if(F.startContainer!=E){switch(F.startContainer.nodeType){case Node.CDATA_SECTION_NODE:case Node.COMMENT_NODE:case Node.TEXT_NODE:if(N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS){R=F.startContainer.cloneNode(true);R.deleteData(0,F.startOffset);P=R}if(N==Range.EXTRACT_CONTENTS||N==Range.DELETE_CONTENTS){F.startContainer.deleteData(F.startOffset,F.startContainer.data.length-F.startOffset)}break;case Node.PROCESSING_INSTRUCTION_NODE:break;default:if(N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS){P=F.startContainer.cloneNode(false)}K=F.startContainer.firstChild;for(O=0;O<F.startOffset;O++){K=K.nextSibling}while(K&&O<F.endOffset){J=K.nextSibling;if(N==Range.EXTRACT_CONTENTS){y.appendChild(K)}else{if(N==Range.CLONE_CONTENTS){y.appendChild(K.cloneNode())}else{F.startContainer.removeChild(K)}}K=J;O++}}H=F.startContainer.parentNode;K=F.startContainer.nextSibling;for(;H!=E;H=H.parentNode){if(N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS){B=H.cloneNode(false);B.appendChild(P);P=B}for(;K;K=J){J=K.nextSibling;if(N==Range.EXTRACT_CONTENTS){P.appendChild(K)}else{if(N==Range.CLONE_CONTENTS){P.appendChild(K.cloneNode(true))}else{H.removeChild(K)}}}K=H.nextSibling}}if(F.endContainer!=E){switch(F.endContainer.nodeType){case Node.CDATA_SECTION_NODE:case Node.COMMENT_NODE:case Node.TEXT_NODE:if(N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS){R=F.endContainer.cloneNode(true);R.deleteData(F.endOffset,F.endContainer.data.length-F.endOffset);C=R}if(N==Range.EXTRACT_CONTENTS||N==Range.DELETE_CONTENTS){F.endContainer.deleteData(0,F.endOffset)}break;case Node.PROCESSING_INSTRUCTION_NODE:break;default:if(N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS){C=F.endContainer.cloneNode(false)}K=F.endContainer.firstChild;if(K&&F.endOffset){for(O=0;O+1<F.endOffset;O++){J=K.nextSibling;if(!J){break}K=J}for(;K;K=I){I=K.previousSibling;if(N==Range.EXTRACT_CONTENTS){C.insertBefore(K,C.firstChild)}else{if(N==Range.CLONE_CONTENTS){C.insertBefore(K.cloneNode(True),C.firstChild)}else{F.endContainer.removeChild(K)}}}}}L=F.endContainer.parentNode;K=F.endContainer.previousSibling;for(;L!=E;L=L.parentNode){if(N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS){z=C.cloneNode(false);z.appendChild(C);C=z}for(;K;K=I){I=K.previousSibling;if(N==Range.EXTRACT_CONTENTS){C.insertBefore(K,C.firstChild)}else{if(N==Range.CLONE_CONTENTS){C.appendChild(K.cloneNode(true),C.firstChild)}else{L.removeChild(K)}}}K=L.previousSibling}}if(F.startContainer==E){M=F.startContainer.firstChild;for(O=0;O<F.startOffset;O++){M=M.nextSibling}}else{M=F.startContainer;while(M.parentNode!=E){M=M.parentNode}M=M.nextSibling}if(F.endContainer==E){G=F.endContainer.firstChild;for(O=0;O<F.endOffset;O++){G=G.nextSibling}}else{G=F.endContainer;while(G.parentNode!=E){G=G.parentNode}}if((N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS)&&P){y.appendChild(P)}if(M){for(K=M;K&&K!=G;K=J){J=K.nextSibling;if(N==Range.EXTRACT_CONTENTS){y.appendChild(K)}else{if(N==Range.CLONE_CONTENTS){y.appendChild(K.cloneNode(true))}else{E.removeChild(K)}}}}if((N==Range.EXTRACT_CONTENTS||N==Range.CLONE_CONTENTS)&&C){y.appendChild(C)}if(N==Range.EXTRACT_CONTENTS||N==Range.DELETE_CONTENTS){if(!D&&!A){F.collapse(true)}else{if(D){F.startContainer=D.parentNode;F.endContainer=D.parentNode;F.startOffset=F.endOffset=F._nodeIndex(D)+1}else{if(A){F.startContainer=A.parentNode;F.endContainer=A.parentNode;F.startOffset=F.endOffset=F._nodeIndex(A)}}}}return y}catch(Q){return null}}function h(y){var z=0;while(y.previousSibling){z++;y=y.previousSibling}return z}return{setStart:q,setEnd:i,setStartBefore:j,setStartAfter:n,setEndBefore:l,setEndAfter:g,collapse:b,selectNode:d,selectNodeContents:u,compareBoundaryPoints:a,deleteContents:w,extractContents:o,cloneContents:r,insertNode:k,surroundContents:m,cloneRange:x,toString:toString,detach:v,_commonAncestorContainer:s}})())}if(!window.getSelection){window.getSelection=function(){return Selection.getInstance()};SelectionImpl=function(){this.anchorNode=null;this.anchorOffset=0;this.focusNode=null;this.focusOffset=0;this.isCollapsed=true;this.rangeCount=0;this.ranges=[]};Object.extend(SelectionImpl.prototype,(function(){function l(o){return true}function k(){return true}function i(){return true}function h(){return true}function c(){return true}function b(){this.anchorNode=null;this.anchorOffset=0;this.focusNode=null;this.focusOffset=0;this.isCollapsed=true;this.rangeCount=0;this.ranges=[]}function n(t){if(t.startContainer.nodeType!=Node.TEXT_NODE){var v=this._getRightStart(t.startContainer);var o=0}else{var v=t.startContainer;var o=t.startOffset}if(t.endContainer.nodeType!=Node.TEXT_NODE){var p=this._getRightEnd(t.endContainer);var s=p.data.length}else{var p=t.endContainer;var s=t.endOffset}var q=this._selectStart(v,o);var u=this._selectEnd(p,s);q.setEndPoint("EndToStart",u);q.select();document.selection._selectedRange=t}function g(p,o){if(p.nodeType!=Node.TEXT_NODE){if(p.nodeType==Node.ELEMENT_NODE){p=p.childNodes(o)}return a(p)}else{return null}}function m(o,p){if(o.nodeType!=Node.TEXT_NODE){if(o.nodeType==Node.ELEMENT_NODE){o=o.childNodes(p)}return e(o)}else{return null}}function d(v,u){var q=document.body.createTextRange();if(v.nodeType==Node.TEXT_NODE){var s=u,p=v;var o=null,t=true;while(p.previousSibling){switch(p.previousSibling.nodeType){case Node.ELEMENT_NODE:o=p.previousSibling;t=false;break;case Node.TEXT_NODE:s+=p.previousSibling.data.length}if(o!=null){break}p=p.previousSibling}if(o==null){o=v.parentNode}q.moveToElementText(o);q.collapse(t);q.move("Character",s);return q}else{return null}}function j(o,v){var s=document.body.createTextRange(),q=o;if(o.nodeType==3){var t=o.data.length-v;var p=null,u=false;while(q.nextSibling){switch(q.nextSibling.nodeType){case Node.ELEMENT_NODE:p=q.nextSibling;u=true;break;case Node.TEXT_NODE:t+=q.nextSibling.data.length;break}if(p!=null){break}q=q.nextSibling}if(p==null){p=o.parentNode;u=false}switch(p.nodeName.toLowerCase()){case"p":case"div":case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":t++}s.moveToElementText(p);s.collapse(u);s.move("Character",-t);return s}return null}function e(p){var o=[];var q=null;while(p){o=[];q=p;while(q){while(q){if(q.nodeType==3&&q.data.replace(/^\s+|\s+$/,"").length){return q}if(q.previousSibling){o.push(q.previousSibling)}q=q.lastChild}q=o.pop()}p=p.previousSibling}return null}function a(p){var o=[];var q=null;while(p){o=[];q=p;while(q){while(q){if(q.nodeType==3&&q.data.replace(/^\s+|\s+$/,"").length){return q}if(q.nextSibling){o.push(q.nextSibling)}q=q.firstChild}q=o.pop()}p=p.nextSibling}return null}return{removeAllRanges:b,_addRange:n,_getRightStart:g,_getRightEnd:m,_selectStart:d,_selectEnd:j}})());Selection=new function(){var a=null;this.getInstance=function(){if(a==null){return(a=new SelectionImpl())}else{return a}}}}Object.extend(Range.prototype,(function(){function a(){var b=this.commonAncestorContainer;if(this.startContainer==this.endContainer){if(this.startOffset-this.endOffset<2){b=this.startContainer.childNodes[this.startOffset]}}while(b.nodeType==Node.TEXT_NODE){b=b.parentNode}return b}return{getNode:a}})());WysiHat.Selection=Class.create((function(){function g(n){this.window=n.getWindow();this.document=n.getDocument();if(Prototype.Browser.IE){n.observe("wysihat:cursormove",i.bind(this));n.observe("wysihat:focus",m)}}function e(){return this.window.getSelection?this.window.getSelection():this.document.selection}function a(){var n=null,o=this.getSelection();try{if(o.getRangeAt){n=o.getRangeAt(0)}else{n=o.createRange()}}catch(p){return null}if(Prototype.Browser.WebKit){n.setStart(o.baseNode,o.baseOffset);n.setEnd(o.extentNode,o.extentOffset)}return n}function d(p){var o=this.getSelection();if(Prototype.Browser.IE){var n=h(this.document,p);n.select()}else{if(Prototype.Browser.WebKit){o.setBaseAndExtent(p,0,p,p.innerText.length)}else{if(Prototype.Browser.Opera){n=this.document.createRange();n.selectNode(p);o.removeAllRanges();o.addRange(n)}else{var n=h(this.document,p);o.removeAllRanges();o.addRange(n)}}}}function c(){var n=null,s=[],q,p;var t=this.getRange();if(!t){return null}var u;if(t.parentElement){u=t.parentElement()}else{u=t.commonAncestorContainer}if(u){while(u.nodeType!=1){u=u.parentNode}if(u.nodeName.toLowerCase()!="body"){p=u;do{p=p.parentNode;s[s.length]=p}while(p.nodeName.toLowerCase()!="body")}q=u.all||u.getElementsByTagName("*");for(var r=0;r<q.length;r++){s[s.length]=q[r]}n=[u];for(var v=0,o;v<s.length;v++){o=h(this.document,s[v]);if(o&&b(t,o)){n[n.length]=s[v]}}}return n.first()}function h(n,p){if(n.body.createTextRange){var o=n.body.createTextRange();o.moveToElementText(p)}else{if(n.createRange){var o=n.createRange();o.selectNodeContents(p)}}return o}function b(o,n){if(o.compareEndPoints){return !(n.compareEndPoints("StartToStart",o)==1&&n.compareEndPoints("EndToEnd",o)==1&&n.compareEndPoints("StartToEnd",o)==1&&n.compareEndPoints("EndToStart",o)==1||n.compareEndPoints("StartToStart",o)==-1&&n.compareEndPoints("EndToEnd",o)==-1&&n.compareEndPoints("StartToEnd",o)==-1&&n.compareEndPoints("EndToStart",o)==-1)}else{if(o.compareBoundaryPoints){return !(n.compareBoundaryPoints(0,o)==1&&n.compareBoundaryPoints(2,o)==1&&n.compareBoundaryPoints(1,o)==1&&n.compareBoundaryPoints(3,o)==1||n.compareBoundaryPoints(0,o)==-1&&n.compareBoundaryPoints(2,o)==-1&&n.compareBoundaryPoints(1,o)==-1&&n.compareBoundaryPoints(3,o)==-1)}}return null}function l(){var p=this.document.getElementById("bookmark");if(p){p.parentNode.removeChild(p)}p=this.document.createElement("span");p.id="bookmark";p.innerHTML=" ";if(Prototype.Browser.IE){var n=this.document.selection.createRange();var o=this.document.createElement("div");o.appendChild(p);n.collapse();n.pasteHTML(o.innerHTML)}else{var n=this.getRange();n.insertNode(p)}}function k(){var p=this.document.getElementById("bookmark");if(!p){return}if(Prototype.Browser.IE){var n=this.getRange();n.moveToElementText(p);n.collapse();n.select()}else{if(Prototype.Browser.WebKit){var o=this.getSelection();o.setBaseAndExtent(p,0,p,0)}else{var n=this.getRange();n.setStartBefore(p)}}p.parentNode.removeChild(p)}var j=null;function i(){j=this.getRange()}function m(){if(j){j.select()}}return{initialize:g,getSelection:e,getRange:a,getNode:c,selectNode:d,setBookmark:l,moveToBookmark:k,restore:m}})());WysiHat.Toolbar=Class.create((function(){function e(l){this.editor=l;this.element=this.createToolbarElement()}function a(){var l=new Element("div",{"class":"editor_toolbar"});this.editor.insert({before:l});return l}function d(m){var l=this;$A(m).each(function(n){l.addButton(n)})}function j(m,o){m=$H(m);if(!m.get("name")){m.set("name",m.get("label").toLowerCase())}var l=m.get("name");var n=this.createButtonElement(this.element,m);var o=this.buttonHandler(l,m);this.observeButtonClick(n,o);var o=this.buttonStateHandler(l,m);this.observeStateChanges(n,l,o)}function i(n,l){var m=new Element("a",{"class":"button",href:"#"});m.update("<span>"+l.get("label")+"</span>");m.addClassName(l.get("name"));n.appendChild(m);return m}function k(m,l){if(l.handler){return l.handler}else{if(l.get("handler")){return l.get("handler")}else{return function(n){n.execCommand(m)}}}}function g(l,m){var n=this;l.observe("click",function(o){m(n.editor);n.editor.fire("wysihat:change");n.editor.fire("wysihat:cursormove");Event.stop(o)})}function c(m,l){if(l.query){return l.query}else{if(l.get("query")){return l.get("query")}else{return function(n){return n.queryCommandState(m)}}}}function h(n,m,o){var p=this;var l=false;p.editor.observe("wysihat:cursormove",function(q){var r=o(p.editor);if(r!=l){l=r;p.updateButtonState(n,m,r)}})}function b(m,l,n){if(n){m.addClassName("selected")}else{m.removeClassName("selected")}}return{initialize:e,createToolbarElement:a,addButtonSet:d,addButton:j,createButtonElement:i,buttonHandler:k,observeButtonClick:g,buttonStateHandler:c,observeStateChanges:h,updateButtonState:b}})());WysiHat.Toolbar.ButtonSets={};WysiHat.Toolbar.ButtonSets.Basic=$A([{label:"Bold"},{label:"Underline"},{label:"Italic"}]);var editors=[];var WysihatHelper={faceboxFile:function(){facebox.loading();new Effect.Appear($("facebox"),{duration:0.3});var b=facebox;var a="/wysihat_files/?editor="+this.id;new Ajax.Request(a,{method:"get",onFailure:function(c){b.reveal(c.responseText,null)},onSuccess:function(c){b.reveal(c.responseText,null)}})},faceboxLink:function(){if(this.linkSelected()){this.unlinkSelection()}else{facebox.loading();new Effect.Appear($("facebox"),{duration:0.3});iframe=this;facebox.reveal('<input type="text" id="link_field" style="width:100%;"/>',null);Event.observe("link_field","change",function(a){iframe.linkSelection($("link_field").value)})}},faceboxHTML:function(){facebox.loading();new Effect.Appear($("facebox"),{duration:0.3});iframe=this;facebox.reveal('<textarea id="html_editor" style="width:100%; height:400px;">'+iframe.contentWindow.document.body.innerHTML+"</textarea>",null);Event.observe("html_editor","change",function(a){iframe.contentWindow.document.body.innerHTML=$("html_editor").value})}};function wysiHatify(d,c){WysiHat.Editor.include(WysihatHelper);var a=WysiHat.Editor.attach(d);var b=new WysiHat.Toolbar(a);editors.push(a);$$("form").each(function(e){e.onsubmit=function(){editors.each(function(g){g.save()})}});c.each(function(e){switch(e.toLowerCase()){case"image":b.addButton({label:e.gsub("_","-").camelize().capitalize(),handler:function(g){return g.faceboxFile(g)}});break;case"link":b.addButton({label:e.gsub("_","-").camelize().capitalize(),handler:function(g){return g.faceboxLink(g)}});break;case"html":b.addButton({label:e.gsub("_","-").camelize().capitalize(),handler:function(g){return g.faceboxHTML(g)}});break;case"paste":b.addButton({label:e.gsub("_","-").camelize().capitalize(),handler:function(g){return g.faceboxPaste(g)}});case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":case"p":b.addButton({label:e.gsub("_","-").camelize().capitalize(),handler:function(g){return g.formatblockSelection(e.toLowerCase())}});break;default:b.addButton({label:e.gsub("_","-").camelize().capitalize()})}})};
|
@@ -55,8 +55,29 @@ div.editor_toolbar
|
|
55
55
|
|
56
56
|
.html
|
57
57
|
background-image: url('../images/icons/page_code.png')
|
58
|
-
|
59
|
-
|
58
|
+
|
59
|
+
.h1
|
60
|
+
background-image: url('../images/icons/text_heading_1.png')
|
61
|
+
|
62
|
+
.h2
|
63
|
+
background-image: url('../images/icons/text_heading_2.png')
|
64
|
+
|
65
|
+
.h3
|
66
|
+
background-image: url('../images/icons/text_heading_3.png')
|
67
|
+
|
68
|
+
.h4
|
69
|
+
background-image: url('../images/icons/text_heading_4.png')
|
70
|
+
|
71
|
+
.h5
|
72
|
+
background-image: url('../images/icons/text_heading_5.png')
|
73
|
+
|
74
|
+
.h6
|
75
|
+
background-image: url('../images/icons/text_heading_6.png')
|
76
|
+
|
77
|
+
.p
|
78
|
+
background-image: url('../images/icons/cancel.png')
|
79
|
+
|
80
|
+
|
60
81
|
iframe.editor
|
61
82
|
border: 1px solid #999
|
62
83
|
height: 400px
|
@@ -55,6 +55,13 @@ class WysihatGenerator < Rails::Generator::Base
|
|
55
55
|
m.file 'images/icons/text_list_numbers.png', 'public/images/icons/text_list_numbers.png'
|
56
56
|
m.file 'images/icons/text_strikethrough.png', 'public/images/icons/text_strikethrough.png'
|
57
57
|
m.file 'images/icons/text_underline.png', 'public/images/icons/text_underline.png'
|
58
|
+
m.file 'images/icons/text_heading_1.png', 'public/images/icons/text_heading_1.png'
|
59
|
+
m.file 'images/icons/text_heading_2.png', 'public/images/icons/text_heading_2.png'
|
60
|
+
m.file 'images/icons/text_heading_3.png', 'public/images/icons/text_heading_3.png'
|
61
|
+
m.file 'images/icons/text_heading_4.png', 'public/images/icons/text_heading_4.png'
|
62
|
+
m.file 'images/icons/text_heading_5.png', 'public/images/icons/text_heading_5.png'
|
63
|
+
m.file 'images/icons/text_heading_6.png', 'public/images/icons/text_heading_6.png'
|
64
|
+
m.file 'images/icons/cancel.png', 'public/images/icons/cancel.png'
|
58
65
|
end
|
59
66
|
|
60
67
|
m.migration_template 'migrations/create_wysihat_files.rb',
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
class WysihatGenerator < Rails::Generators::Base
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
|
6
|
+
def self.source_root
|
7
|
+
File.join(File.dirname(__FILE__), '..', '..', 'generators', 'wysihat', 'templates')
|
8
|
+
end
|
9
|
+
|
10
|
+
def install_wysihat
|
11
|
+
raise options.to_yaml
|
12
|
+
|
13
|
+
copy_file 'javascripts/wysihat_engine_pack.js', 'public/javascripts/wysihat_engine_pack.js'
|
14
|
+
|
15
|
+
# javascript source
|
16
|
+
# TODO: build the --include-js-src option
|
17
|
+
|
18
|
+
# facebox
|
19
|
+
# TODO: build the --sass option
|
20
|
+
|
21
|
+
copy_file 'css/facebox.css', 'public/stylesheets/facebox.css'
|
22
|
+
|
23
|
+
copy_file 'images/facebox/b.png', 'public/images/facebox/b.png'
|
24
|
+
copy_file 'images/facebox/bl.png', 'public/images/facebox/bl.png'
|
25
|
+
copy_file 'images/facebox/br.png', 'public/images/facebox/br.png'
|
26
|
+
copy_file 'images/facebox/closelabel.gif', 'public/images/facebox/closelabel.gif'
|
27
|
+
copy_file 'images/facebox/tl.png', 'public/images/facebox/tl.png'
|
28
|
+
copy_file 'images/facebox/tr.png', 'public/images/facebox/tr.png'
|
29
|
+
copy_file 'images/facebox/loading.gif', 'public/images/facebox/loading.gif'
|
30
|
+
|
31
|
+
# stylesheet
|
32
|
+
# TODO: build the --sass option
|
33
|
+
|
34
|
+
copy_file 'css/wysihat.css', 'public/stylesheets/wysihat.css'
|
35
|
+
|
36
|
+
# icons
|
37
|
+
|
38
|
+
copy_file 'images/icons/arrow_redo.png', 'public/images/icons/arrow_redo.png'
|
39
|
+
copy_file 'images/icons/arrow_undo.png', 'public/images/icons/arrow_undo.png'
|
40
|
+
copy_file 'images/icons/exclamation.png', 'public/images/icons/exclamation.png'
|
41
|
+
copy_file 'images/icons/image.png', 'public/images/icons/image.png'
|
42
|
+
copy_file 'images/icons/link.png', 'public/images/icons/link.png'
|
43
|
+
copy_file 'images/icons/page_code.png', 'public/images/icons/page_code.png'
|
44
|
+
copy_file 'images/icons/text_align_center.png', 'public/images/icons/text_align_center.png'
|
45
|
+
copy_file 'images/icons/text_align_left.png', 'public/images/icons/text_align_left.png'
|
46
|
+
copy_file 'images/icons/text_align_right.png', 'public/images/icons/text_align_right.png'
|
47
|
+
copy_file 'images/icons/text_bold.png', 'public/images/icons/text_bold.png'
|
48
|
+
copy_file 'images/icons/text_italic.png', 'public/images/icons/text_italic.png'
|
49
|
+
copy_file 'images/icons/text_list_bullets.png', 'public/images/icons/text_list_bullets.png'
|
50
|
+
copy_file 'images/icons/text_list_numbers.png', 'public/images/icons/text_list_numbers.png'
|
51
|
+
copy_file 'images/icons/text_strikethrough.png', 'public/images/icons/text_strikethrough.png'
|
52
|
+
copy_file 'images/icons/text_underline.png', 'public/images/icons/text_underline.png'
|
53
|
+
copy_file 'images/icons/text_heading_1.png', 'public/images/icons/text_heading_1.png'
|
54
|
+
copy_file 'images/icons/text_heading_2.png', 'public/images/icons/text_heading_2.png'
|
55
|
+
copy_file 'images/icons/text_heading_3.png', 'public/images/icons/text_heading_3.png'
|
56
|
+
copy_file 'images/icons/text_heading_4.png', 'public/images/icons/text_heading_4.png'
|
57
|
+
copy_file 'images/icons/text_heading_5.png', 'public/images/icons/text_heading_5.png'
|
58
|
+
copy_file 'images/icons/text_heading_6.png', 'public/images/icons/text_heading_6.png'
|
59
|
+
copy_file 'images/icons/cancel.png', 'public/images/icons/cancel.png'
|
60
|
+
|
61
|
+
# migration
|
62
|
+
|
63
|
+
migration_template 'migrations/create_wysihat_files.rb', 'db/migrate/create_wysihat_files.rb'
|
64
|
+
|
65
|
+
# routes
|
66
|
+
|
67
|
+
route 'resource :wysihat_files'
|
68
|
+
|
69
|
+
# install the responds_to_parent plugin
|
70
|
+
|
71
|
+
plugin 'responds_to_parent', :git => 'git://github.com/markcatley/responds_to_parent.git'
|
72
|
+
end
|
73
|
+
|
74
|
+
protected
|
75
|
+
def next_migration_number(dirname) #:nodoc:
|
76
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
77
|
+
end
|
78
|
+
end
|
data/lib/wysihat-engine.rb
CHANGED
@@ -7,30 +7,30 @@ module ActionView
|
|
7
7
|
InstanceTag.new(object_name, method, self, options.delete(:object)).to_wysihat_editor_tag(options)
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
class InstanceTag #:nodoc:
|
12
12
|
def to_wysihat_editor_tag(options = {})
|
13
13
|
options = DEFAULT_TEXT_AREA_OPTIONS.merge(options.stringify_keys)
|
14
14
|
add_default_name_and_id(options)
|
15
|
-
|
15
|
+
|
16
16
|
size = options.delete("size")
|
17
|
-
options["cols"], options["rows"] = size.split("x") if size && size.respond_to?(:split)
|
18
|
-
|
17
|
+
options["cols"], options["rows"] = size.split("x") if size && size.respond_to?(:split)
|
18
|
+
|
19
19
|
if options['buttons'] == nil || options['buttons'] == :all
|
20
|
-
buttons = [:bold, :italic, :underline, :strikethrough, :justify_left, :justify_center, :justify_right, :insert_ordered_list, :insert_unordered_list, :undo, :redo, :link, :html, :image]
|
20
|
+
buttons = [:bold, :italic, :underline, :strikethrough, :h1, :h2, :h3, :p, :justify_left, :justify_center, :justify_right, :insert_ordered_list, :insert_unordered_list, :undo, :redo, :link, :html, :image]
|
21
21
|
else
|
22
22
|
buttons = options['buttons']
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
javascript = "Event.observe(window, 'load', function() {" <<
|
26
26
|
"wysiHatify('#{tag_id}', ['#{buttons.join('\', \'')}']);" <<
|
27
27
|
"});"
|
28
|
-
|
28
|
+
|
29
29
|
content_tag(:script, javascript, :type => 'text/javascript') <<
|
30
30
|
content_tag(:textarea, html_escape(options.delete('value') || value_before_type_cast(object)), options.merge(:class => 'wysihat_editor'))
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
class FormBuilder #:nodoc:
|
35
35
|
def wysihat_editor(method, options = {})
|
36
36
|
@template.wysihat_editor(@object_name, method, options)
|
data/wysihat-engine.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{wysihat-engine}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.10"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jeff Kreeftmeijer"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-01-17}
|
13
13
|
s.description = %q{A Rails engine to help integrate the 37signals WysiHat rich text editor to your application.}
|
14
14
|
s.email = %q{jeff@80beans.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
|
|
42
42
|
"generators/wysihat/templates/images/facebox/tr.png",
|
43
43
|
"generators/wysihat/templates/images/icons/arrow_redo.png",
|
44
44
|
"generators/wysihat/templates/images/icons/arrow_undo.png",
|
45
|
+
"generators/wysihat/templates/images/icons/cancel.png",
|
45
46
|
"generators/wysihat/templates/images/icons/exclamation.png",
|
46
47
|
"generators/wysihat/templates/images/icons/image.png",
|
47
48
|
"generators/wysihat/templates/images/icons/link.png",
|
@@ -50,6 +51,12 @@ Gem::Specification.new do |s|
|
|
50
51
|
"generators/wysihat/templates/images/icons/text_align_left.png",
|
51
52
|
"generators/wysihat/templates/images/icons/text_align_right.png",
|
52
53
|
"generators/wysihat/templates/images/icons/text_bold.png",
|
54
|
+
"generators/wysihat/templates/images/icons/text_heading_1.png",
|
55
|
+
"generators/wysihat/templates/images/icons/text_heading_2.png",
|
56
|
+
"generators/wysihat/templates/images/icons/text_heading_3.png",
|
57
|
+
"generators/wysihat/templates/images/icons/text_heading_4.png",
|
58
|
+
"generators/wysihat/templates/images/icons/text_heading_5.png",
|
59
|
+
"generators/wysihat/templates/images/icons/text_heading_6.png",
|
53
60
|
"generators/wysihat/templates/images/icons/text_italic.png",
|
54
61
|
"generators/wysihat/templates/images/icons/text_list_bullets.png",
|
55
62
|
"generators/wysihat/templates/images/icons/text_list_numbers.png",
|
@@ -63,6 +70,7 @@ Gem::Specification.new do |s|
|
|
63
70
|
"generators/wysihat/templates/sass/facebox.sass",
|
64
71
|
"generators/wysihat/templates/sass/wysihat.sass",
|
65
72
|
"generators/wysihat/wysihat_generator.rb",
|
73
|
+
"lib/generators/wysihat_generator.rb",
|
66
74
|
"lib/wysihat-engine.rb",
|
67
75
|
"wysihat-engine.gemspec"
|
68
76
|
]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wysihat-engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Kreeftmeijer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-17 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- generators/wysihat/templates/images/facebox/tr.png
|
68
68
|
- generators/wysihat/templates/images/icons/arrow_redo.png
|
69
69
|
- generators/wysihat/templates/images/icons/arrow_undo.png
|
70
|
+
- generators/wysihat/templates/images/icons/cancel.png
|
70
71
|
- generators/wysihat/templates/images/icons/exclamation.png
|
71
72
|
- generators/wysihat/templates/images/icons/image.png
|
72
73
|
- generators/wysihat/templates/images/icons/link.png
|
@@ -75,6 +76,12 @@ files:
|
|
75
76
|
- generators/wysihat/templates/images/icons/text_align_left.png
|
76
77
|
- generators/wysihat/templates/images/icons/text_align_right.png
|
77
78
|
- generators/wysihat/templates/images/icons/text_bold.png
|
79
|
+
- generators/wysihat/templates/images/icons/text_heading_1.png
|
80
|
+
- generators/wysihat/templates/images/icons/text_heading_2.png
|
81
|
+
- generators/wysihat/templates/images/icons/text_heading_3.png
|
82
|
+
- generators/wysihat/templates/images/icons/text_heading_4.png
|
83
|
+
- generators/wysihat/templates/images/icons/text_heading_5.png
|
84
|
+
- generators/wysihat/templates/images/icons/text_heading_6.png
|
78
85
|
- generators/wysihat/templates/images/icons/text_italic.png
|
79
86
|
- generators/wysihat/templates/images/icons/text_list_bullets.png
|
80
87
|
- generators/wysihat/templates/images/icons/text_list_numbers.png
|
@@ -88,6 +95,7 @@ files:
|
|
88
95
|
- generators/wysihat/templates/sass/facebox.sass
|
89
96
|
- generators/wysihat/templates/sass/wysihat.sass
|
90
97
|
- generators/wysihat/wysihat_generator.rb
|
98
|
+
- lib/generators/wysihat_generator.rb
|
91
99
|
- lib/wysihat-engine.rb
|
92
100
|
- wysihat-engine.gemspec
|
93
101
|
has_rdoc: true
|