root / trunk / web / dojo / dojox / editor / plugins / PageBreak.js
History | View | Annotate | Download (3.2 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["dojox.editor.plugins.PageBreak"]){ |
9 |
dojo._hasResource["dojox.editor.plugins.PageBreak"]=true; |
10 |
dojo.provide("dojox.editor.plugins.PageBreak");
|
11 |
dojo.require("dijit._editor._Plugin");
|
12 |
dojo.require("dojo.i18n");
|
13 |
dojo.requireLocalization("dojox.editor.plugins","PageBreak",null,"ROOT,cs,de,es,fr,hu,it,ja,ko,pl,pt,ro,ru,zh,zh-tw"); |
14 |
dojo.declare("dojox.editor.plugins.PageBreak",dijit._editor._Plugin,{useDefaultCommand:false,iconClassPrefix:"dijitAdditionalEditorIcon",_unbreakableNodes:["li","ul","ol"],_pbContent:"<hr style='page-break-after: always;' class='dijitEditorPageBreak'>",_initButton:function(){ |
15 |
var ed=this.editor; |
16 |
var _1=dojo.i18n.getLocalization("dojox.editor.plugins","PageBreak"); |
17 |
this.button=new dijit.form.Button({label:_1["pageBreak"],showLabel:false,iconClass:this.iconClassPrefix+" "+this.iconClassPrefix+"PageBreak",tabIndex:"-1",onClick:dojo.hitch(this,"_insertPageBreak")}); |
18 |
ed.onLoadDeferred.addCallback(dojo.hitch(this,function(){ |
19 |
ed.addKeyHandler(dojo.keys.ENTER,true,true,dojo.hitch(this,this._insertPageBreak)); |
20 |
if(dojo.isWebKit||dojo.isOpera){
|
21 |
this.connect(this.editor,"onKeyDown",dojo.hitch(this,function(e){ |
22 |
if((e.keyCode===dojo.keys.ENTER)&&e.ctrlKey&&e.shiftKey){
|
23 |
this._insertPageBreak();
|
24 |
} |
25 |
})); |
26 |
} |
27 |
})); |
28 |
},setEditor:function(_2){ |
29 |
this.editor=_2;
|
30 |
this._initButton();
|
31 |
},_style:function(){ |
32 |
if(!this._styled){ |
33 |
this._styled=true; |
34 |
var _3=this.editor.document; |
35 |
var _4=".dijitEditorPageBreak {\n"+"\tborder-top-style: solid;\n"+"\tborder-top-width: 3px;\n"+"\tborder-top-color: #585858;\n"+"\tborder-bottom-style: solid;\n"+"\tborder-bottom-width: 1px;\n"+"\tborder-bottom-color: #585858;\n"+"\tborder-left-style: solid;\n"+"\tborder-left-width: 1px;\n"+"\tborder-left-color: #585858;\n"+"\tborder-right-style: solid;\n"+"\tborder-right-width: 1px;\n"+"\tborder-right-color: #585858;\n"+"\tcolor: #A4A4A4;\n"+"\tbackground-color: #A4A4A4;\n"+"\theight: 10px;\n"+"\tpage-break-after: always;\n"+"\tpadding: 0px 0px 0px 0px;\n"+"}\n\n"+"@media print {\n"+"\t.dijitEditorPageBreak { page-break-after: always; "+"background-color: rgba(0,0,0,0); color: rgba(0,0,0,0); "+"border: 0px none rgba(0,0,0,0); display: hidden; "+"width: 0px; height: 0px;}\n"+"}"; |
36 |
if(!dojo.isIE){
|
37 |
var _5=_3.createElement("style"); |
38 |
_5.appendChild(_3.createTextNode(_4)); |
39 |
_3.getElementsByTagName("head")[0].appendChild(_5); |
40 |
}else{
|
41 |
var ss=_3.createStyleSheet(""); |
42 |
ss.cssText=_4; |
43 |
} |
44 |
} |
45 |
},_insertPageBreak:function(){ |
46 |
try{
|
47 |
if(!this._styled){ |
48 |
this._style();
|
49 |
} |
50 |
if(this._allowBreak()){ |
51 |
this.editor.execCommand("inserthtml",this._pbContent); |
52 |
} |
53 |
} |
54 |
catch(e){
|
55 |
console.warn(e); |
56 |
} |
57 |
},_allowBreak:function(){ |
58 |
var ed=this.editor; |
59 |
var _6=ed.document;
|
60 |
var _7=ed._sCall("getSelectedElement",null)||ed._sCall("getParentElement",null); |
61 |
while(_7&&_7!==_6.body&&_7!==_6.html){
|
62 |
if(ed._sCall("isTag",[_7,this._unbreakableNodes])){ |
63 |
return false; |
64 |
} |
65 |
_7=_7.parentNode; |
66 |
} |
67 |
return true; |
68 |
}}); |
69 |
dojo.subscribe(dijit._scopeName+".Editor.getPlugin",null,function(o){ |
70 |
if(o.plugin){
|
71 |
return;
|
72 |
} |
73 |
var _8=o.args.name.toLowerCase();
|
74 |
if(_8==="pagebreak"){ |
75 |
o.plugin=new dojox.editor.plugins.PageBreak({});
|
76 |
} |
77 |
}); |
78 |
} |