Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / editor / plugins / Breadcrumb.js

History | View | Annotate | Download (8.05 KB)

1 9 andrej.cim
/*
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["dojox.editor.plugins.Breadcrumb"]){
9
dojo._hasResource["dojox.editor.plugins.Breadcrumb"]=true;
10
dojo.provide("dojox.editor.plugins.Breadcrumb");
11
dojo.require("dijit._editor._Plugin");
12
dojo.require("dijit._editor.range");
13
dojo.require("dojo.i18n");
14
dojo.require("dojo.string");
15
dojo.require("dijit.Toolbar");
16
dojo.require("dijit.form.Button");
17
dojo.require("dijit._editor.selection");
18
dojo.require("dijit.Menu");
19
dojo.require("dijit.MenuItem");
20
dojo.require("dijit.MenuSeparator");
21
dojo.experimental("dojox.editor.plugins.Breadcrumb");
22
dojo.requireLocalization("dojox.editor.plugins","Breadcrumb",null,"ROOT,cs,de,es,fr,hu,it,ja,ko,pl,pt,ro,ru,zh,zh-tw");
23
dojo.declare("dojox.editor.plugins._BreadcrumbMenuTitle",[dijit._Widget,dijit._Templated,dijit._Contained],{templateString:"<tr><td dojoAttachPoint=\"title\" colspan=\"4\" class=\"dijitToolbar\" style=\"font-weight: bold; padding: 3px;\"></td></tr>",menuTitle:"",postCreate:function(){
24
dojo.setSelectable(this.domNode,false);
25
var _1=this.id+"_text";
26
dijit.setWaiState(this.domNode,"labelledby",_1);
27
},_setMenuTitleAttr:function(_2){
28
this.title.innerHTML=_2;
29
},_getMenuTitleAttr:function(_3){
30
return this.title.innerHTML;
31
}});
32
dojo.declare("dojox.editor.plugins.Breadcrumb",dijit._editor._Plugin,{_menu:null,breadcrumbBar:null,setEditor:function(_4){
33
this.editor=_4;
34
this._buttons=[];
35
this.breadcrumbBar=new dijit.Toolbar();
36
var _5=dojo.i18n.getLocalization("dojox.editor.plugins","Breadcrumb");
37
this._titleTemplate=_5.nodeActions;
38
dojo.place(this.breadcrumbBar.domNode,_4.footer);
39
this.editor.onLoadDeferred.addCallback(dojo.hitch(this,function(){
40
this._menu=new dijit.Menu({});
41
dojo.addClass(this.breadcrumbBar.domNode,"dojoxEditorBreadcrumbArrow");
42
var _6=this;
43
var _7=new dijit.form.ComboButton({showLabel:true,label:"body",_selNode:_4.editNode,dropDown:this._menu,onClick:dojo.hitch(this,function(){
44
this._menuTarget=_4.editNode;
45
this._selectContents();
46
})});
47
this._menuTitle=new dojox.editor.plugins._BreadcrumbMenuTitle({menuTitle:_5.nodeActions});
48
this._selCMenu=new dijit.MenuItem({label:_5.selectContents,onClick:dojo.hitch(this,this._selectContents)});
49
this._delCMenu=new dijit.MenuItem({label:_5.deleteContents,onClick:dojo.hitch(this,this._deleteContents)});
50
this._selEMenu=new dijit.MenuItem({label:_5.selectElement,onClick:dojo.hitch(this,this._selectElement)});
51
this._delEMenu=new dijit.MenuItem({label:_5.deleteElement,onClick:dojo.hitch(this,this._deleteElement)});
52
this._moveSMenu=new dijit.MenuItem({label:_5.moveStart,onClick:dojo.hitch(this,this._moveCToStart)});
53
this._moveEMenu=new dijit.MenuItem({label:_5.moveEnd,onClick:dojo.hitch(this,this._moveCToEnd)});
54
this._menu.addChild(this._menuTitle);
55
this._menu.addChild(this._selCMenu);
56
this._menu.addChild(this._delCMenu);
57
this._menu.addChild(new dijit.MenuSeparator({}));
58
this._menu.addChild(this._selEMenu);
59
this._menu.addChild(this._delEMenu);
60
this._menu.addChild(new dijit.MenuSeparator({}));
61
this._menu.addChild(this._moveSMenu);
62
this._menu.addChild(this._moveEMenu);
63
_7._ddConnect=dojo.connect(_7,"openDropDown",dojo.hitch(this,function(){
64
this._menuTarget=_7._selNode;
65
this._menuTitle.set("menuTitle",dojo.string.substitute(this._titleTemplate,{"nodeName":"&lt;body&gt;"}));
66
this._selEMenu.set("disabled",true);
67
this._delEMenu.set("disabled",true);
68
this._selCMenu.set("disabled",false);
69
this._delCMenu.set("disabled",false);
70
this._moveSMenu.set("disabled",false);
71
this._moveEMenu.set("disabled",false);
72
}));
73
this.breadcrumbBar.addChild(_7);
74
this.connect(this.editor,"onNormalizedDisplayChanged","updateState");
75
}));
76
this.breadcrumbBar.startup();
77
if(dojo.isIE){
78
setTimeout(dojo.hitch(this,function(){
79
this.breadcrumbBar.domNode.className=this.breadcrumbBar.domNode.className;
80
}),100);
81
}
82
},_selectContents:function(){
83
this.editor.focus();
84
if(this._menuTarget){
85
var _8=this._menuTarget.tagName.toLowerCase();
86
switch(_8){
87
case "br":
88
case "hr":
89
case "img":
90
case "input":
91
case "base":
92
case "meta":
93
case "area":
94
case "basefont":
95
break;
96
default:
97
try{
98
dojo.withGlobal(this.editor.window,"collapse",dijit._editor.selection,[null]);
99
dojo.withGlobal(this.editor.window,"selectElementChildren",dijit._editor.selection,[this._menuTarget]);
100
this.editor.onDisplayChanged();
101
}
102
catch(e){
103
}
104
}
105
}
106
},_deleteContents:function(){
107
if(this._menuTarget){
108
this.editor.beginEditing();
109
this._selectContents();
110
dojo.withGlobal(this.editor.window,"remove",dijit._editor.selection,[this._menuTarget]);
111
this.editor.endEditing();
112
this._updateBreadcrumb();
113
this.editor.onDisplayChanged();
114
}
115
},_selectElement:function(){
116
this.editor.focus();
117
if(this._menuTarget){
118
dojo.withGlobal(this.editor.window,"collapse",dijit._editor.selection,[null]);
119
dojo.withGlobal(this.editor.window,"selectElement",dijit._editor.selection,[this._menuTarget]);
120
this.editor.onDisplayChanged();
121
}
122
},_deleteElement:function(){
123
if(this._menuTarget){
124
this.editor.beginEditing();
125
this._selectElement();
126
dojo.withGlobal(this.editor.window,"remove",dijit._editor.selection,[this._menuTarget]);
127
this.editor.endEditing();
128
this._updateBreadcrumb();
129
this.editor.onDisplayChanged();
130
}
131
},_moveCToStart:function(){
132
this.editor.focus();
133
if(this._menuTarget){
134
this._selectContents();
135
dojo.withGlobal(this.editor.window,"collapse",dijit._editor.selection,[true]);
136
}
137
},_moveCToEnd:function(){
138
this.editor.focus();
139
if(this._menuTarget){
140
this._selectContents();
141
dojo.withGlobal(this.editor.window,"collapse",dijit._editor.selection,[false]);
142
}
143
},_updateBreadcrumb:function(){
144
var ed=this.editor;
145
if(ed.window){
146
var _9=dijit.range.getSelection(ed.window);
147
if(_9&&_9.rangeCount>0){
148
var _a=_9.getRangeAt(0);
149
var _b=dojo.withGlobal(ed.window,"getSelectedElement",dijit._editor.selection)||_a.startContainer;
150
var _c=[];
151
if(_b&&_b.ownerDocument===ed.document){
152
while(_b&&_b!==ed.editNode&&_b!=ed.document.body&&_b!=ed.document){
153
if(_b.nodeType===1){
154
_c.push({type:_b.tagName.toLowerCase(),node:_b});
155
}
156
_b=_b.parentNode;
157
}
158
_c=_c.reverse();
159
while(this._buttons.length){
160
var db=this._buttons.pop();
161
dojo.disconnect(db._ddConnect);
162
this.breadcrumbBar.removeChild(db);
163
}
164
this._buttons=[];
165
var i;
166
var _d=this;
167
for(i=0;i<_c.length;i++){
168
var bc=_c[i];
169
var b=new dijit.form.ComboButton({showLabel:true,label:bc.type,_selNode:bc.node,dropDown:this._menu,onClick:function(){
170
_d._menuTarget=this._selNode;
171
_d._selectContents();
172
}});
173
b._ddConnect=dojo.connect(b,"openDropDown",dojo.hitch(b,function(){
174
_d._menuTarget=this._selNode;
175
var _e=_d._menuTarget.tagName.toLowerCase();
176
var _f=dojo.string.substitute(_d._titleTemplate,{"nodeName":"&lt;"+_e+"&gt;"});
177
_d._menuTitle.set("menuTitle",_f);
178
switch(_e){
179
case "br":
180
case "hr":
181
case "img":
182
case "input":
183
case "base":
184
case "meta":
185
case "area":
186
case "basefont":
187
_d._selCMenu.set("disabled",true);
188
_d._delCMenu.set("disabled",true);
189
_d._moveSMenu.set("disabled",true);
190
_d._moveEMenu.set("disabled",true);
191
_d._selEMenu.set("disabled",false);
192
_d._delEMenu.set("disabled",false);
193
break;
194
default:
195
_d._selCMenu.set("disabled",false);
196
_d._delCMenu.set("disabled",false);
197
_d._selEMenu.set("disabled",false);
198
_d._delEMenu.set("disabled",false);
199
_d._moveSMenu.set("disabled",false);
200
_d._moveEMenu.set("disabled",false);
201
}
202
}));
203
this._buttons.push(b);
204
this.breadcrumbBar.addChild(b);
205
}
206
if(dojo.isIE){
207
this.breadcrumbBar.domNode.className=this.breadcrumbBar.domNode.className;
208
}
209
}
210
}
211
}
212
},updateState:function(){
213
if(dojo.style(this.editor.iframe,"display")==="none"){
214
dojo.style(this.breadcrumbBar.domNode,"display","none");
215
}else{
216
if(dojo.style(this.breadcrumbBar.domNode,"display")==="none"){
217
dojo.style(this.breadcrumbBar.domNode,"display","block");
218
}
219
this._updateBreadcrumb();
220
var _10=dojo.marginBox(this.editor.domNode);
221
this.editor.resize({h:_10.h});
222
}
223
},destroy:function(){
224
if(this.breadcrumbBar){
225
this.breadcrumbBar.destroy();
226
this.breadcrumbBar=null;
227
}
228
this._buttons=null;
229
delete this.editor.breadcrumbBar;
230
this.inherited(arguments);
231
}});
232
dojo.subscribe(dijit._scopeName+".Editor.getPlugin",null,function(o){
233
if(o.plugin){
234
return;
235
}
236
var _11=o.args.name.toLowerCase();
237
if(_11==="breadcrumb"){
238
o.plugin=new dojox.editor.plugins.Breadcrumb({});
239
}
240
});
241
}