root / trunk / web / dojo / dijit / _editor / plugins / Print.js
History | View | Annotate | Download (2.21 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.plugins.Print"]){ |
9 |
dojo._hasResource["dijit._editor.plugins.Print"]=true; |
10 |
dojo.provide("dijit._editor.plugins.Print");
|
11 |
dojo.require("dijit._editor._Plugin");
|
12 |
dojo.require("dijit.form.Button");
|
13 |
dojo.require("dojo.i18n");
|
14 |
dojo.requireLocalization("dijit._editor","commands",null,"ROOT,ar,ca,cs,da,de,el,es,fi,fr,he,hu,it,ja,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw"); |
15 |
dojo.declare("dijit._editor.plugins.Print",dijit._editor._Plugin,{_initButton:function(){ |
16 |
var _1=dojo.i18n.getLocalization("dijit._editor","commands"),_2=this.editor; |
17 |
this.button=new dijit.form.Button({label:_1["print"],dir:_2.dir,lang:_2.lang,showLabel:false,iconClass:this.iconClassPrefix+" "+this.iconClassPrefix+"Print",tabIndex:"-1",onClick:dojo.hitch(this,"_print")}); |
18 |
},setEditor:function(_3){ |
19 |
this.editor=_3;
|
20 |
this._initButton();
|
21 |
this.editor.onLoadDeferred.addCallback(dojo.hitch(this,function(){ |
22 |
if(!this.editor.iframe.contentWindow["print"]){ |
23 |
this.button.set("disabled",true); |
24 |
} |
25 |
})); |
26 |
},_print:function(){ |
27 |
var _4=this.editor.iframe; |
28 |
if(_4.contentWindow["print"]){ |
29 |
if(!dojo.isOpera&&!dojo.isChrome){
|
30 |
dijit.focus(_4); |
31 |
_4.contentWindow.print(); |
32 |
}else{
|
33 |
var _5=this.editor.document; |
34 |
var _6=this.editor.get("value"); |
35 |
_6="<html><head><meta http-equiv='Content-Type' "+"content='text/html; charset='UTF-8'></head><body>"+_6+"</body></html>"; |
36 |
var _7=window.open("javascript: ''","","status=0,menubar=0,location=0,toolbar=0,"+"width=1,height=1,resizable=0,scrollbars=0"); |
37 |
_7.document.open(); |
38 |
_7.document.write(_6); |
39 |
_7.document.close(); |
40 |
var _8=[];
|
41 |
var _9=_5.getElementsByTagName("style"); |
42 |
if(_9){
|
43 |
var i;
|
44 |
for(i=0;i<_9.length;i++){ |
45 |
var _a=_9[i].innerHTML;
|
46 |
var _b=_7.document.createElement("style"); |
47 |
_b.appendChild(_7.document.createTextNode(_a)); |
48 |
_7.document.getElementsByTagName("head")[0].appendChild(_b); |
49 |
} |
50 |
} |
51 |
_7.print(); |
52 |
_7.close(); |
53 |
} |
54 |
} |
55 |
}}); |
56 |
dojo.subscribe(dijit._scopeName+".Editor.getPlugin",null,function(o){ |
57 |
if(o.plugin){
|
58 |
return;
|
59 |
} |
60 |
var _c=o.args.name.toLowerCase();
|
61 |
if(_c==="print"){ |
62 |
o.plugin=new dijit._editor.plugins.Print({command:"print"}); |
63 |
} |
64 |
}); |
65 |
} |