Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dijit / _editor / RichText.js

History | View | Annotate | Download (26.6 KB)

1
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6

    
7

    
8
if(!dojo._hasResource["dijit._editor.RichText"]){
9
dojo._hasResource["dijit._editor.RichText"]=true;
10
dojo.provide("dijit._editor.RichText");
11
dojo.require("dijit._Widget");
12
dojo.require("dijit._CssStateMixin");
13
dojo.require("dijit._editor.selection");
14
dojo.require("dijit._editor.range");
15
dojo.require("dijit._editor.html");
16
if(!dojo.config["useXDomain"]||dojo.config["allowXdRichTextSave"]){
17
if(dojo._postLoad){
18
(function(){
19
var _1=dojo.doc.createElement("textarea");
20
_1.id=dijit._scopeName+"._editor.RichText.savedContent";
21
dojo.style(_1,{display:"none",position:"absolute",top:"-100px",height:"3px",width:"3px"});
22
dojo.body().appendChild(_1);
23
})();
24
}else{
25
try{
26
dojo.doc.write("<textarea id=\""+dijit._scopeName+"._editor.RichText.savedContent\" "+"style=\"display:none;position:absolute;top:-100px;left:-100px;height:3px;width:3px;overflow:hidden;\"></textarea>");
27
}
28
catch(e){
29
}
30
}
31
}
32
dojo.declare("dijit._editor.RichText",[dijit._Widget,dijit._CssStateMixin],{constructor:function(_2){
33
this.contentPreFilters=[];
34
this.contentPostFilters=[];
35
this.contentDomPreFilters=[];
36
this.contentDomPostFilters=[];
37
this.editingAreaStyleSheets=[];
38
this.events=[].concat(this.events);
39
this._keyHandlers={};
40
this.contentPreFilters.push(dojo.hitch(this,"_preFixUrlAttributes"));
41
if(dojo.isMoz){
42
this.contentPreFilters.push(this._normalizeFontStyle);
43
this.contentPostFilters.push(this._removeMozBogus);
44
}
45
if(dojo.isWebKit){
46
this.contentPreFilters.push(this._removeWebkitBogus);
47
this.contentPostFilters.push(this._removeWebkitBogus);
48
}
49
if(dojo.isIE){
50
this.contentPostFilters.push(this._normalizeFontStyle);
51
}
52
if(_2&&dojo.isString(_2.value)){
53
this.value=_2.value;
54
}
55
this.onLoadDeferred=new dojo.Deferred();
56
},baseClass:"dijitEditor",inheritWidth:false,focusOnLoad:false,name:"",styleSheets:"",_content:"",height:"300px",minHeight:"1em",isClosed:true,isLoaded:false,_SEPARATOR:"@@**%%__RICHTEXTBOUNDRY__%%**@@",onLoadDeferred:null,isTabIndent:false,disableSpellCheck:false,postCreate:function(){
57
if("textarea"==this.domNode.tagName.toLowerCase()){
58
console.warn("RichText should not be used with the TEXTAREA tag.  See dijit._editor.RichText docs.");
59
}
60
this.inherited(arguments);
61
dojo.publish(dijit._scopeName+"._editor.RichText::init",[this]);
62
this.open();
63
this.setupDefaultShortcuts();
64
},setupDefaultShortcuts:function(){
65
var _3=dojo.hitch(this,function(_4,_5){
66
return function(){
67
return !this.execCommand(_4,_5);
68
};
69
});
70
var _6={b:_3("bold"),i:_3("italic"),u:_3("underline"),a:_3("selectall"),s:function(){
71
this.save(true);
72
},m:function(){
73
this.isTabIndent=!this.isTabIndent;
74
},"1":_3("formatblock","h1"),"2":_3("formatblock","h2"),"3":_3("formatblock","h3"),"4":_3("formatblock","h4"),"\\":_3("insertunorderedlist")};
75
if(!dojo.isIE){
76
_6.Z=_3("redo");
77
}
78
for(var _7 in _6){
79
this.addKeyHandler(_7,true,false,_6[_7]);
80
}
81
},events:["onKeyPress","onKeyDown","onKeyUp","onClick"],captureEvents:[],_editorCommandsLocalized:false,_localizeEditorCommands:function(){
82
if(this._editorCommandsLocalized){
83
return;
84
}
85
this._editorCommandsLocalized=true;
86
var _8=["div","p","pre","h1","h2","h3","h4","h5","h6","ol","ul","address"];
87
var _9="",_a,i=0;
88
while((_a=_8[i++])){
89
if(_a.charAt(1)!="l"){
90
_9+="<"+_a+"><span>content</span></"+_a+"><br/>";
91
}else{
92
_9+="<"+_a+"><li>content</li></"+_a+"><br/>";
93
}
94
}
95
var _b=dojo.doc.createElement("div");
96
dojo.style(_b,{position:"absolute",top:"-2000px"});
97
dojo.doc.body.appendChild(_b);
98
_b.innerHTML=_9;
99
var _c=_b.firstChild;
100
while(_c){
101
dijit._editor.selection.selectElement(_c.firstChild);
102
dojo.withGlobal(this.window,"selectElement",dijit._editor.selection,[_c.firstChild]);
103
var _d=_c.tagName.toLowerCase();
104
this._local2NativeFormatNames[_d]=document.queryCommandValue("formatblock");
105
this._native2LocalFormatNames[this._local2NativeFormatNames[_d]]=_d;
106
_c=_c.nextSibling.nextSibling;
107
}
108
dojo.body().removeChild(_b);
109
},open:function(_e){
110
if(!this.onLoadDeferred||this.onLoadDeferred.fired>=0){
111
this.onLoadDeferred=new dojo.Deferred();
112
}
113
if(!this.isClosed){
114
this.close();
115
}
116
dojo.publish(dijit._scopeName+"._editor.RichText::open",[this]);
117
this._content="";
118
if(arguments.length==1&&_e.nodeName){
119
this.domNode=_e;
120
}
121
var dn=this.domNode;
122
var _f;
123
if(dojo.isString(this.value)){
124
_f=this.value;
125
delete this.value;
126
dn.innerHTML="";
127
}else{
128
if(dn.nodeName&&dn.nodeName.toLowerCase()=="textarea"){
129
var ta=(this.textarea=dn);
130
this.name=ta.name;
131
_f=ta.value;
132
dn=this.domNode=dojo.doc.createElement("div");
133
dn.setAttribute("widgetId",this.id);
134
ta.removeAttribute("widgetId");
135
dn.cssText=ta.cssText;
136
dn.className+=" "+ta.className;
137
dojo.place(dn,ta,"before");
138
var _10=dojo.hitch(this,function(){
139
dojo.style(ta,{display:"block",position:"absolute",top:"-1000px"});
140
if(dojo.isIE){
141
var s=ta.style;
142
this.__overflow=s.overflow;
143
s.overflow="hidden";
144
}
145
});
146
if(dojo.isIE){
147
setTimeout(_10,10);
148
}else{
149
_10();
150
}
151
if(ta.form){
152
dojo.connect(ta.form,"onsubmit",this,function(){
153
ta.value=this.getValue();
154
});
155
}
156
}else{
157
_f=dijit._editor.getChildrenHtml(dn);
158
dn.innerHTML="";
159
}
160
}
161
var _11=dojo.contentBox(dn);
162
this._oldHeight=_11.h;
163
this._oldWidth=_11.w;
164
this.savedContent=_f;
165
if(dn.nodeName&&dn.nodeName=="LI"){
166
dn.innerHTML=" <br>";
167
}
168
this.header=dn.ownerDocument.createElement("div");
169
dn.appendChild(this.header);
170
this.editingArea=dn.ownerDocument.createElement("div");
171
dn.appendChild(this.editingArea);
172
this.footer=dn.ownerDocument.createElement("div");
173
dn.appendChild(this.footer);
174
if(this.name!==""&&(!dojo.config["useXDomain"]||dojo.config["allowXdRichTextSave"])){
175
var _12=dojo.byId(dijit._scopeName+"._editor.RichText.savedContent");
176
if(_12.value!==""){
177
var _13=_12.value.split(this._SEPARATOR),i=0,dat;
178
while((dat=_13[i++])){
179
var _14=dat.split(":");
180
if(_14[0]==this.name){
181
_f=_14[1];
182
_13.splice(i,1);
183
break;
184
}
185
}
186
}
187
dojo.addOnUnload(dojo.hitch(this,"_saveContent"));
188
}
189
this.isClosed=false;
190
var ifr=(this.editorObject=this.iframe=dojo.doc.createElement("iframe"));
191
ifr.id=this.id+"_iframe";
192
this._iframeSrc=this._getIframeDocTxt();
193
ifr.style.border="none";
194
ifr.style.width="100%";
195
if(this._layoutMode){
196
ifr.style.height="100%";
197
}else{
198
if(dojo.isIE>=7){
199
if(this.height){
200
ifr.style.height=this.height;
201
}
202
if(this.minHeight){
203
ifr.style.minHeight=this.minHeight;
204
}
205
}else{
206
ifr.style.height=this.height?this.height:this.minHeight;
207
}
208
}
209
ifr.frameBorder=0;
210
ifr._loadFunc=dojo.hitch(this,function(win){
211
this.window=win;
212
this.document=this.window.document;
213
if(dojo.isIE){
214
this._localizeEditorCommands();
215
}
216
this.onLoad(_f);
217
});
218
var s="javascript:parent."+dijit._scopeName+".byId(\""+this.id+"\")._iframeSrc";
219
ifr.setAttribute("src",s);
220
this.editingArea.appendChild(ifr);
221
if(dn.nodeName=="LI"){
222
dn.lastChild.style.marginTop="-1.2em";
223
}
224
dojo.addClass(this.domNode,this.baseClass);
225
},_local2NativeFormatNames:{},_native2LocalFormatNames:{},_getIframeDocTxt:function(){
226
var _15=dojo.getComputedStyle(this.domNode);
227
var _16="";
228
var _17=true;
229
if(dojo.isIE||(!this.height&&!dojo.isMoz)){
230
_16="<div id='dijitEditorBody'></div>";
231
_17=false;
232
}else{
233
if(dojo.isMoz){
234
this._cursorToStart=true;
235
_16="&nbsp;";
236
}
237
}
238
var _18=[_15.fontWeight,_15.fontSize,_15.fontFamily].join(" ");
239
var _19=_15.lineHeight;
240
if(_19.indexOf("px")>=0){
241
_19=parseFloat(_19)/parseFloat(_15.fontSize);
242
}else{
243
if(_19.indexOf("em")>=0){
244
_19=parseFloat(_19);
245
}else{
246
_19="normal";
247
}
248
}
249
var _1a="";
250
var _1b=this;
251
this.style.replace(/(^|;)\s*(line-|font-?)[^;]+/ig,function(_1c){
252
_1c=_1c.replace(/^;/ig,"")+";";
253
var s=_1c.split(":")[0];
254
if(s){
255
s=dojo.trim(s);
256
s=s.toLowerCase();
257
var i;
258
var sC="";
259
for(i=0;i<s.length;i++){
260
var c=s.charAt(i);
261
switch(c){
262
case "-":
263
i++;
264
c=s.charAt(i).toUpperCase();
265
default:
266
sC+=c;
267
}
268
}
269
dojo.style(_1b.domNode,sC,"");
270
}
271
_1a+=_1c+";";
272
});
273
var _1d=dojo.query("label[for=\""+this.id+"\"]");
274
return [this.isLeftToRight()?"<html>\n<head>\n":"<html dir='rtl'>\n<head>\n",(dojo.isMoz&&_1d.length?"<title>"+_1d[0].innerHTML+"</title>\n":""),"<meta http-equiv='Content-Type' content='text/html'>\n","<style>\n","\tbody,html {\n","\t\tbackground:transparent;\n","\t\tpadding: 1px 0 0 0;\n","\t\tmargin: -1px 0 0 0;\n",((dojo.isWebKit)?"\t\twidth: 100%;\n":""),((dojo.isWebKit)?"\t\theight: 100%;\n":""),"\t}\n","\tbody{\n","\t\ttop:0px;\n","\t\tleft:0px;\n","\t\tright:0px;\n","\t\tfont:",_18,";\n",((this.height||dojo.isOpera)?"":"\t\tposition: fixed;\n"),"\t\tmin-height:",this.minHeight,";\n","\t\tline-height:",_19,";\n","\t}\n","\tp{ margin: 1em 0; }\n",(!_17&&!this.height?"\tbody,html {overflow-y: hidden;}\n":""),"\t#dijitEditorBody{overflow-x: auto; overflow-y:"+(this.height?"auto;":"hidden;")+"}\n","\tli > ul:-moz-first-node, li > ol:-moz-first-node{ padding-top: 1.2em; }\n","\tli{ min-height:1.2em; }\n","</style>\n",this._applyEditingAreaStyleSheets(),"\n","</head>\n<body ",(_17?"id='dijitEditorBody' ":""),"onload='frameElement._loadFunc(window,document)' style='"+_1a+"'>",_16,"</body>\n</html>"].join("");
275
},_applyEditingAreaStyleSheets:function(){
276
var _1e=[];
277
if(this.styleSheets){
278
_1e=this.styleSheets.split(";");
279
this.styleSheets="";
280
}
281
_1e=_1e.concat(this.editingAreaStyleSheets);
282
this.editingAreaStyleSheets=[];
283
var _1f="",i=0,url;
284
while((url=_1e[i++])){
285
var _20=(new dojo._Url(dojo.global.location,url)).toString();
286
this.editingAreaStyleSheets.push(_20);
287
_1f+="<link rel=\"stylesheet\" type=\"text/css\" href=\""+_20+"\"/>";
288
}
289
return _1f;
290
},addStyleSheet:function(uri){
291
var url=uri.toString();
292
if(url.charAt(0)=="."||(url.charAt(0)!="/"&&!uri.host)){
293
url=(new dojo._Url(dojo.global.location,url)).toString();
294
}
295
if(dojo.indexOf(this.editingAreaStyleSheets,url)>-1){
296
return;
297
}
298
this.editingAreaStyleSheets.push(url);
299
this.onLoadDeferred.addCallback(dojo.hitch(function(){
300
if(this.document.createStyleSheet){
301
this.document.createStyleSheet(url);
302
}else{
303
var _21=this.document.getElementsByTagName("head")[0];
304
var _22=this.document.createElement("link");
305
_22.rel="stylesheet";
306
_22.type="text/css";
307
_22.href=url;
308
_21.appendChild(_22);
309
}
310
}));
311
},removeStyleSheet:function(uri){
312
var url=uri.toString();
313
if(url.charAt(0)=="."||(url.charAt(0)!="/"&&!uri.host)){
314
url=(new dojo._Url(dojo.global.location,url)).toString();
315
}
316
var _23=dojo.indexOf(this.editingAreaStyleSheets,url);
317
if(_23==-1){
318
return;
319
}
320
delete this.editingAreaStyleSheets[_23];
321
dojo.withGlobal(this.window,"query",dojo,["link:[href=\""+url+"\"]"]).orphan();
322
},disabled:false,_mozSettingProps:{"styleWithCSS":false},_setDisabledAttr:function(_24){
323
this.disabled=_24;
324
if(!this.isLoaded){
325
return;
326
}
327
_24=!!_24;
328
if(dojo.isIE||dojo.isWebKit||dojo.isOpera){
329
var _25=dojo.isIE&&(this.isLoaded||!this.focusOnLoad);
330
if(_25){
331
this.editNode.unselectable="on";
332
}
333
this.editNode.contentEditable=!_24;
334
if(_25){
335
var _26=this;
336
setTimeout(function(){
337
_26.editNode.unselectable="off";
338
},0);
339
}
340
}else{
341
try{
342
this.document.designMode=(_24?"off":"on");
343
}
344
catch(e){
345
return;
346
}
347
if(!_24&&this._mozSettingProps){
348
var ps=this._mozSettingProps;
349
for(var n in ps){
350
if(ps.hasOwnProperty(n)){
351
try{
352
this.document.execCommand(n,false,ps[n]);
353
}
354
catch(e2){
355
}
356
}
357
}
358
}
359
}
360
this._disabledOK=true;
361
},onLoad:function(_27){
362
if(!this.window.__registeredWindow){
363
this.window.__registeredWindow=true;
364
this._iframeRegHandle=dijit.registerIframe(this.iframe);
365
}
366
if(!dojo.isIE&&(this.height||dojo.isMoz)){
367
this.editNode=this.document.body;
368
}else{
369
this.editNode=this.document.body.firstChild;
370
var _28=this;
371
if(dojo.isIE){
372
var _29=(this.tabStop=dojo.doc.createElement("<div tabIndex=-1>"));
373
this.editingArea.appendChild(_29);
374
this.iframe.onfocus=function(){
375
_28.editNode.setActive();
376
};
377
}
378
}
379
this.focusNode=this.editNode;
380
var _2a=this.events.concat(this.captureEvents);
381
var ap=this.iframe?this.document:this.editNode;
382
dojo.forEach(_2a,function(_2b){
383
this.connect(ap,_2b.toLowerCase(),_2b);
384
},this);
385
if(dojo.isIE){
386
this.connect(this.document,"onmousedown","_onIEMouseDown");
387
this.editNode.style.zoom=1;
388
}else{
389
this.connect(this.document,"onmousedown",function(){
390
delete this._cursorToStart;
391
});
392
}
393
if(dojo.isWebKit){
394
this._webkitListener=this.connect(this.document,"onmouseup","onDisplayChanged");
395
}
396
if(dojo.isIE){
397
try{
398
this.document.execCommand("RespectVisibilityInDesign",true,null);
399
}
400
catch(e){
401
}
402
}
403
this.isLoaded=true;
404
this.set("disabled",this.disabled);
405
var _2c=dojo.hitch(this,function(){
406
this.setValue(_27);
407
if(this.onLoadDeferred){
408
this.onLoadDeferred.callback(true);
409
}
410
this.onDisplayChanged();
411
if(this.focusOnLoad){
412
dojo.addOnLoad(dojo.hitch(this,function(){
413
setTimeout(dojo.hitch(this,"focus"),this.updateInterval);
414
}));
415
}
416
this.savedContent=this.getValue(true);
417
});
418
if(this.setValueDeferred){
419
this.setValueDeferred.addCallback(_2c);
420
}else{
421
_2c();
422
}
423
},onKeyDown:function(e){
424
if(e.keyCode===dojo.keys.TAB&&this.isTabIndent){
425
dojo.stopEvent(e);
426
if(this.queryCommandEnabled((e.shiftKey?"outdent":"indent"))){
427
this.execCommand((e.shiftKey?"outdent":"indent"));
428
}
429
}
430
if(dojo.isIE){
431
if(e.keyCode==dojo.keys.TAB&&!this.isTabIndent){
432
if(e.shiftKey&&!e.ctrlKey&&!e.altKey){
433
this.iframe.focus();
434
}else{
435
if(!e.shiftKey&&!e.ctrlKey&&!e.altKey){
436
this.tabStop.focus();
437
}
438
}
439
}else{
440
if(e.keyCode===dojo.keys.BACKSPACE&&this.document.selection.type==="Control"){
441
dojo.stopEvent(e);
442
this.execCommand("delete");
443
}else{
444
if((65<=e.keyCode&&e.keyCode<=90)||(e.keyCode>=37&&e.keyCode<=40)){
445
e.charCode=e.keyCode;
446
this.onKeyPress(e);
447
}
448
}
449
}
450
}
451
return true;
452
},onKeyUp:function(e){
453
return;
454
},setDisabled:function(_2d){
455
dojo.deprecated("dijit.Editor::setDisabled is deprecated","use dijit.Editor::attr(\"disabled\",boolean) instead",2);
456
this.set("disabled",_2d);
457
},_setValueAttr:function(_2e){
458
this.setValue(_2e);
459
},_setDisableSpellCheckAttr:function(_2f){
460
if(this.document){
461
dojo.attr(this.document.body,"spellcheck",!_2f);
462
}else{
463
this.onLoadDeferred.addCallback(dojo.hitch(this,function(){
464
dojo.attr(this.document.body,"spellcheck",!_2f);
465
}));
466
}
467
this.disableSpellCheck=_2f;
468
},onKeyPress:function(e){
469
var c=(e.keyChar&&e.keyChar.toLowerCase())||e.keyCode,_30=this._keyHandlers[c],_31=arguments;
470
if(_30&&!e.altKey){
471
dojo.some(_30,function(h){
472
if(!(h.shift^e.shiftKey)&&!(h.ctrl^(e.ctrlKey||e.metaKey))){
473
if(!h.handler.apply(this,_31)){
474
e.preventDefault();
475
}
476
return true;
477
}
478
},this);
479
}
480
if(!this._onKeyHitch){
481
this._onKeyHitch=dojo.hitch(this,"onKeyPressed");
482
}
483
setTimeout(this._onKeyHitch,1);
484
return true;
485
},addKeyHandler:function(key,_32,_33,_34){
486
if(!dojo.isArray(this._keyHandlers[key])){
487
this._keyHandlers[key]=[];
488
}
489
this._keyHandlers[key].push({shift:_33||false,ctrl:_32||false,handler:_34});
490
},onKeyPressed:function(){
491
this.onDisplayChanged();
492
},onClick:function(e){
493
this.onDisplayChanged(e);
494
},_onIEMouseDown:function(e){
495
if(!this._focused&&!this.disabled){
496
this.focus();
497
}
498
},_onBlur:function(e){
499
this.inherited(arguments);
500
var _35=this.getValue(true);
501
if(_35!=this.savedContent){
502
this.onChange(_35);
503
this.savedContent=_35;
504
}
505
},_onFocus:function(e){
506
if(!this.disabled){
507
if(!this._disabledOK){
508
this.set("disabled",false);
509
}
510
this.inherited(arguments);
511
}
512
},blur:function(){
513
if(!dojo.isIE&&this.window.document.documentElement&&this.window.document.documentElement.focus){
514
this.window.document.documentElement.focus();
515
}else{
516
if(dojo.doc.body.focus){
517
dojo.doc.body.focus();
518
}
519
}
520
},focus:function(){
521
if(!this.isLoaded){
522
this.focusOnLoad=true;
523
return;
524
}
525
if(this._cursorToStart){
526
delete this._cursorToStart;
527
if(this.editNode.childNodes){
528
this.placeCursorAtStart();
529
return;
530
}
531
}
532
if(!dojo.isIE){
533
dijit.focus(this.iframe);
534
}else{
535
if(this.editNode&&this.editNode.focus){
536
this.iframe.fireEvent("onfocus",document.createEventObject());
537
}
538
}
539
},updateInterval:200,_updateTimer:null,onDisplayChanged:function(e){
540
if(this._updateTimer){
541
clearTimeout(this._updateTimer);
542
}
543
if(!this._updateHandler){
544
this._updateHandler=dojo.hitch(this,"onNormalizedDisplayChanged");
545
}
546
this._updateTimer=setTimeout(this._updateHandler,this.updateInterval);
547
},onNormalizedDisplayChanged:function(){
548
delete this._updateTimer;
549
},onChange:function(_36){
550
},_normalizeCommand:function(cmd,_37){
551
var _38=cmd.toLowerCase();
552
if(_38=="formatblock"){
553
if(dojo.isSafari&&_37===undefined){
554
_38="heading";
555
}
556
}else{
557
if(_38=="hilitecolor"&&!dojo.isMoz){
558
_38="backcolor";
559
}
560
}
561
return _38;
562
},_qcaCache:{},queryCommandAvailable:function(_39){
563
var ca=this._qcaCache[_39];
564
if(ca!==undefined){
565
return ca;
566
}
567
return (this._qcaCache[_39]=this._queryCommandAvailable(_39));
568
},_queryCommandAvailable:function(_3a){
569
var ie=1;
570
var _3b=1<<1;
571
var _3c=1<<2;
572
var _3d=1<<3;
573
var _3e=1<<4;
574
function _3f(_40){
575
return {ie:Boolean(_40&ie),mozilla:Boolean(_40&_3b),webkit:Boolean(_40&_3c),webkit420:Boolean(_40&_3e),opera:Boolean(_40&_3d)};
576
};
577
var _41=null;
578
switch(_3a.toLowerCase()){
579
case "bold":
580
case "italic":
581
case "underline":
582
case "subscript":
583
case "superscript":
584
case "fontname":
585
case "fontsize":
586
case "forecolor":
587
case "hilitecolor":
588
case "justifycenter":
589
case "justifyfull":
590
case "justifyleft":
591
case "justifyright":
592
case "delete":
593
case "selectall":
594
case "toggledir":
595
_41=_3f(_3b|ie|_3c|_3d);
596
break;
597
case "createlink":
598
case "unlink":
599
case "removeformat":
600
case "inserthorizontalrule":
601
case "insertimage":
602
case "insertorderedlist":
603
case "insertunorderedlist":
604
case "indent":
605
case "outdent":
606
case "formatblock":
607
case "inserthtml":
608
case "undo":
609
case "redo":
610
case "strikethrough":
611
case "tabindent":
612
_41=_3f(_3b|ie|_3d|_3e);
613
break;
614
case "blockdirltr":
615
case "blockdirrtl":
616
case "dirltr":
617
case "dirrtl":
618
case "inlinedirltr":
619
case "inlinedirrtl":
620
_41=_3f(ie);
621
break;
622
case "cut":
623
case "copy":
624
case "paste":
625
_41=_3f(ie|_3b|_3e);
626
break;
627
case "inserttable":
628
_41=_3f(_3b|ie);
629
break;
630
case "insertcell":
631
case "insertcol":
632
case "insertrow":
633
case "deletecells":
634
case "deletecols":
635
case "deleterows":
636
case "mergecells":
637
case "splitcell":
638
_41=_3f(ie|_3b);
639
break;
640
default:
641
return false;
642
}
643
return (dojo.isIE&&_41.ie)||(dojo.isMoz&&_41.mozilla)||(dojo.isWebKit&&_41.webkit)||(dojo.isWebKit>420&&_41.webkit420)||(dojo.isOpera&&_41.opera);
644
},execCommand:function(_42,_43){
645
var _44;
646
this.focus();
647
_42=this._normalizeCommand(_42,_43);
648
if(_43!==undefined){
649
if(_42=="heading"){
650
throw new Error("unimplemented");
651
}else{
652
if((_42=="formatblock")&&dojo.isIE){
653
_43="<"+_43+">";
654
}
655
}
656
}
657
var _45="_"+_42+"Impl";
658
if(this[_45]){
659
_44=this[_45](_43);
660
}else{
661
_43=arguments.length>1?_43:null;
662
if(_43||_42!="createlink"){
663
_44=this.document.execCommand(_42,false,_43);
664
}
665
}
666
this.onDisplayChanged();
667
return _44;
668
},queryCommandEnabled:function(_46){
669
if(this.disabled||!this._disabledOK){
670
return false;
671
}
672
_46=this._normalizeCommand(_46);
673
if(dojo.isMoz||dojo.isWebKit){
674
if(_46=="unlink"){
675
return this._sCall("hasAncestorElement",["a"]);
676
}else{
677
if(_46=="inserttable"){
678
return true;
679
}
680
}
681
}
682
if(dojo.isWebKit){
683
if(_46=="copy"){
684
_46="cut";
685
}else{
686
if(_46=="paste"){
687
return true;
688
}
689
}
690
}
691
var _47=dojo.isIE?this.document.selection.createRange():this.document;
692
try{
693
return _47.queryCommandEnabled(_46);
694
}
695
catch(e){
696
return false;
697
}
698
},queryCommandState:function(_48){
699
if(this.disabled||!this._disabledOK){
700
return false;
701
}
702
_48=this._normalizeCommand(_48);
703
try{
704
return this.document.queryCommandState(_48);
705
}
706
catch(e){
707
return false;
708
}
709
},queryCommandValue:function(_49){
710
if(this.disabled||!this._disabledOK){
711
return false;
712
}
713
var r;
714
_49=this._normalizeCommand(_49);
715
if(dojo.isIE&&_49=="formatblock"){
716
r=this._native2LocalFormatNames[this.document.queryCommandValue(_49)];
717
}else{
718
if(dojo.isMoz&&_49==="hilitecolor"){
719
var _4a;
720
try{
721
_4a=this.document.queryCommandValue("styleWithCSS");
722
}
723
catch(e){
724
_4a=false;
725
}
726
this.document.execCommand("styleWithCSS",false,true);
727
r=this.document.queryCommandValue(_49);
728
this.document.execCommand("styleWithCSS",false,_4a);
729
}else{
730
r=this.document.queryCommandValue(_49);
731
}
732
}
733
return r;
734
},_sCall:function(_4b,_4c){
735
return dojo.withGlobal(this.window,_4b,dijit._editor.selection,_4c);
736
},placeCursorAtStart:function(){
737
this.focus();
738
var _4d=false;
739
if(dojo.isMoz){
740
var _4e=this.editNode.firstChild;
741
while(_4e){
742
if(_4e.nodeType==3){
743
if(_4e.nodeValue.replace(/^\s+|\s+$/g,"").length>0){
744
_4d=true;
745
this._sCall("selectElement",[_4e]);
746
break;
747
}
748
}else{
749
if(_4e.nodeType==1){
750
_4d=true;
751
var tg=_4e.tagName?_4e.tagName.toLowerCase():"";
752
if(/br|input|img|base|meta|area|basefont|hr|link/.test(tg)){
753
this._sCall("selectElement",[_4e]);
754
}else{
755
this._sCall("selectElementChildren",[_4e]);
756
}
757
break;
758
}
759
}
760
_4e=_4e.nextSibling;
761
}
762
}else{
763
_4d=true;
764
this._sCall("selectElementChildren",[this.editNode]);
765
}
766
if(_4d){
767
this._sCall("collapse",[true]);
768
}
769
},placeCursorAtEnd:function(){
770
this.focus();
771
var _4f=false;
772
if(dojo.isMoz){
773
var _50=this.editNode.lastChild;
774
while(_50){
775
if(_50.nodeType==3){
776
if(_50.nodeValue.replace(/^\s+|\s+$/g,"").length>0){
777
_4f=true;
778
this._sCall("selectElement",[_50]);
779
break;
780
}
781
}else{
782
if(_50.nodeType==1){
783
_4f=true;
784
if(_50.lastChild){
785
this._sCall("selectElement",[_50.lastChild]);
786
}else{
787
this._sCall("selectElement",[_50]);
788
}
789
break;
790
}
791
}
792
_50=_50.previousSibling;
793
}
794
}else{
795
_4f=true;
796
this._sCall("selectElementChildren",[this.editNode]);
797
}
798
if(_4f){
799
this._sCall("collapse",[false]);
800
}
801
},getValue:function(_51){
802
if(this.textarea){
803
if(this.isClosed||!this.isLoaded){
804
return this.textarea.value;
805
}
806
}
807
return this._postFilterContent(null,_51);
808
},_getValueAttr:function(){
809
return this.getValue(true);
810
},setValue:function(_52){
811
if(!this.isLoaded){
812
this.onLoadDeferred.addCallback(dojo.hitch(this,function(){
813
this.setValue(_52);
814
}));
815
return;
816
}
817
this._cursorToStart=true;
818
if(this.textarea&&(this.isClosed||!this.isLoaded)){
819
this.textarea.value=_52;
820
}else{
821
_52=this._preFilterContent(_52);
822
var _53=this.isClosed?this.domNode:this.editNode;
823
if(!_52&&dojo.isWebKit){
824
_52="&nbsp;";
825
}
826
_53.innerHTML=_52;
827
this._preDomFilterContent(_53);
828
}
829
this.onDisplayChanged();
830
},replaceValue:function(_54){
831
if(this.isClosed){
832
this.setValue(_54);
833
}else{
834
if(this.window&&this.window.getSelection&&!dojo.isMoz){
835
this.setValue(_54);
836
}else{
837
if(this.window&&this.window.getSelection){
838
_54=this._preFilterContent(_54);
839
this.execCommand("selectall");
840
if(!_54){
841
this._cursorToStart=true;
842
_54="&nbsp;";
843
}
844
this.execCommand("inserthtml",_54);
845
this._preDomFilterContent(this.editNode);
846
}else{
847
if(this.document&&this.document.selection){
848
this.setValue(_54);
849
}
850
}
851
}
852
}
853
},_preFilterContent:function(_55){
854
var ec=_55;
855
dojo.forEach(this.contentPreFilters,function(ef){
856
if(ef){
857
ec=ef(ec);
858
}
859
});
860
return ec;
861
},_preDomFilterContent:function(dom){
862
dom=dom||this.editNode;
863
dojo.forEach(this.contentDomPreFilters,function(ef){
864
if(ef&&dojo.isFunction(ef)){
865
ef(dom);
866
}
867
},this);
868
},_postFilterContent:function(dom,_56){
869
var ec;
870
if(!dojo.isString(dom)){
871
dom=dom||this.editNode;
872
if(this.contentDomPostFilters.length){
873
if(_56){
874
dom=dojo.clone(dom);
875
}
876
dojo.forEach(this.contentDomPostFilters,function(ef){
877
dom=ef(dom);
878
});
879
}
880
ec=dijit._editor.getChildrenHtml(dom);
881
}else{
882
ec=dom;
883
}
884
if(!dojo.trim(ec.replace(/^\xA0\xA0*/,"").replace(/\xA0\xA0*$/,"")).length){
885
ec="";
886
}
887
dojo.forEach(this.contentPostFilters,function(ef){
888
ec=ef(ec);
889
});
890
return ec;
891
},_saveContent:function(e){
892
var _57=dojo.byId(dijit._scopeName+"._editor.RichText.savedContent");
893
if(_57.value){
894
_57.value+=this._SEPARATOR;
895
}
896
_57.value+=this.name+":"+this.getValue(true);
897
},escapeXml:function(str,_58){
898
str=str.replace(/&/gm,"&amp;").replace(/</gm,"&lt;").replace(/>/gm,"&gt;").replace(/"/gm,"&quot;");
899
if(!_58){
900
str=str.replace(/'/gm,"&#39;");
901
}
902
return str;
903
},getNodeHtml:function(_59){
904
dojo.deprecated("dijit.Editor::getNodeHtml is deprecated","use dijit._editor.getNodeHtml instead",2);
905
return dijit._editor.getNodeHtml(_59);
906
},getNodeChildrenHtml:function(dom){
907
dojo.deprecated("dijit.Editor::getNodeChildrenHtml is deprecated","use dijit._editor.getChildrenHtml instead",2);
908
return dijit._editor.getChildrenHtml(dom);
909
},close:function(_5a){
910
if(this.isClosed){
911
return false;
912
}
913
if(!arguments.length){
914
_5a=true;
915
}
916
this._content=this.getValue();
917
var _5b=(this.savedContent!=this._content);
918
if(this.interval){
919
clearInterval(this.interval);
920
}
921
if(this._webkitListener){
922
this.disconnect(this._webkitListener);
923
delete this._webkitListener;
924
}
925
if(dojo.isIE){
926
this.iframe.onfocus=null;
927
}
928
this.iframe._loadFunc=null;
929
if(this._iframeRegHandle){
930
dijit.unregisterIframe(this._iframeRegHandle);
931
delete this._iframeRegHandle;
932
}
933
if(this.textarea){
934
var s=this.textarea.style;
935
s.position="";
936
s.left=s.top="";
937
if(dojo.isIE){
938
s.overflow=this.__overflow;
939
this.__overflow=null;
940
}
941
this.textarea.value=_5a?this._content:this.savedContent;
942
dojo.destroy(this.domNode);
943
this.domNode=this.textarea;
944
}else{
945
this.domNode.innerHTML=_5a?this._content:this.savedContent;
946
}
947
delete this.iframe;
948
dojo.removeClass(this.domNode,this.baseClass);
949
this.isClosed=true;
950
this.isLoaded=false;
951
delete this.editNode;
952
delete this.focusNode;
953
if(this.window&&this.window._frameElement){
954
this.window._frameElement=null;
955
}
956
this.window=null;
957
this.document=null;
958
this.editingArea=null;
959
this.editorObject=null;
960
return _5b;
961
},destroy:function(){
962
if(!this.isClosed){
963
this.close(false);
964
}
965
this.inherited(arguments);
966
},_removeMozBogus:function(_5c){
967
return _5c.replace(/\stype="_moz"/gi,"").replace(/\s_moz_dirty=""/gi,"").replace(/_moz_resizing="(true|false)"/gi,"");
968
},_removeWebkitBogus:function(_5d){
969
_5d=_5d.replace(/\sclass="webkit-block-placeholder"/gi,"");
970
_5d=_5d.replace(/\sclass="apple-style-span"/gi,"");
971
return _5d;
972
},_normalizeFontStyle:function(_5e){
973
return _5e.replace(/<(\/)?strong([ \>])/gi,"<$1b$2").replace(/<(\/)?em([ \>])/gi,"<$1i$2");
974
},_preFixUrlAttributes:function(_5f){
975
return _5f.replace(/(?:(<a(?=\s).*?\shref=)("|')(.*?)\2)|(?:(<a\s.*?href=)([^"'][^ >]+))/gi,"$1$4$2$3$5$2 _djrealurl=$2$3$5$2").replace(/(?:(<img(?=\s).*?\ssrc=)("|')(.*?)\2)|(?:(<img\s.*?src=)([^"'][^ >]+))/gi,"$1$4$2$3$5$2 _djrealurl=$2$3$5$2");
976
},_inserthorizontalruleImpl:function(_60){
977
if(dojo.isIE){
978
return this._inserthtmlImpl("<hr>");
979
}
980
return this.document.execCommand("inserthorizontalrule",false,_60);
981
},_unlinkImpl:function(_61){
982
if((this.queryCommandEnabled("unlink"))&&(dojo.isMoz||dojo.isWebKit)){
983
var a=this._sCall("getAncestorElement",["a"]);
984
this._sCall("selectElement",[a]);
985
return this.document.execCommand("unlink",false,null);
986
}
987
return this.document.execCommand("unlink",false,_61);
988
},_hilitecolorImpl:function(_62){
989
var _63;
990
if(dojo.isMoz){
991
this.document.execCommand("styleWithCSS",false,true);
992
_63=this.document.execCommand("hilitecolor",false,_62);
993
this.document.execCommand("styleWithCSS",false,false);
994
}else{
995
_63=this.document.execCommand("hilitecolor",false,_62);
996
}
997
return _63;
998
},_backcolorImpl:function(_64){
999
if(dojo.isIE){
1000
_64=_64?_64:null;
1001
}
1002
return this.document.execCommand("backcolor",false,_64);
1003
},_forecolorImpl:function(_65){
1004
if(dojo.isIE){
1005
_65=_65?_65:null;
1006
}
1007
return this.document.execCommand("forecolor",false,_65);
1008
},_inserthtmlImpl:function(_66){
1009
_66=this._preFilterContent(_66);
1010
var rv=true;
1011
if(dojo.isIE){
1012
var _67=this.document.selection.createRange();
1013
if(this.document.selection.type.toUpperCase()=="CONTROL"){
1014
var n=_67.item(0);
1015
while(_67.length){
1016
_67.remove(_67.item(0));
1017
}
1018
n.outerHTML=_66;
1019
}else{
1020
_67.pasteHTML(_66);
1021
}
1022
_67.select();
1023
}else{
1024
if(dojo.isMoz&&!_66.length){
1025
this._sCall("remove");
1026
}else{
1027
rv=this.document.execCommand("inserthtml",false,_66);
1028
}
1029
}
1030
return rv;
1031
},getHeaderHeight:function(){
1032
return this._getNodeChildrenHeight(this.header);
1033
},getFooterHeight:function(){
1034
return this._getNodeChildrenHeight(this.footer);
1035
},_getNodeChildrenHeight:function(_68){
1036
var h=0;
1037
if(_68&&_68.childNodes){
1038
var i;
1039
for(i=0;i<_68.childNodes.length;i++){
1040
var _69=dojo.position(_68.childNodes[i]);
1041
h+=_69.h;
1042
}
1043
}
1044
return h;
1045
}});
1046
}