]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/_editor/plugins/Print.js.uncompressed.js
933633d248f8bab2611e78393b36ccb148c183cb
1 define("dijit/_editor/plugins/Print", [
2 "dojo/_base/declare", // declare
3 "dojo/i18n", // i18n.getLocalization
4 "dojo/_base/lang", // lang.hitch
5 "dojo/sniff", // has("chrome") has("opera")
6 "../../focus", // focus.focus()
9 "dojo/i18n!../nls/commands"
10 ], function(declare
, i18n
, lang
, has
, focus
, _Plugin
, Button
){
13 // dijit/_editor/plugins/Print
16 var Print
= declare("dijit._editor.plugins.Print",_Plugin
,{
18 // This plugin provides Print capability to the editor. When
19 // clicked, the document in the editor frame will be printed.
21 _initButton: function(){
23 // Over-ride for creation of the Print button.
24 var strings
= i18n
.getLocalization("dijit._editor", "commands"),
26 this.button
= new Button({
27 label
: strings
["print"],
28 ownerDocument
: editor
.ownerDocument
,
32 iconClass
: this.iconClassPrefix
+ " " + this.iconClassPrefix
+ "Print",
34 onClick
: lang
.hitch(this, "_print")
38 setEditor: function(/*dijit/Editor*/ editor){
40 // Tell the plugin which Editor it is associated with.
42 // The editor object to attach the print capability to.
46 // Set up a check that we have a print function
47 // and disable button if we do not.
48 this.editor.onLoadDeferred.then(
49 lang.hitch(this, function(){
50 if(!this.editor.iframe.contentWindow["print"]){
51 this.button.set("disabled", true);
57 updateState: function(){
59 // Over-ride for button state control for disabled to work.
60 var disabled = this.get("disabled");
61 if(!this.editor.iframe.contentWindow["print"]){
64 this.button.set("disabled", disabled);
69 // Function to trigger printing of the editor document
72 var edFrame = this.editor.iframe;
73 if(edFrame.contentWindow["print"]){
74 // IE requires the frame to be focused for
75 // print to work, but since this is okay for all
77 if(!has("opera") && !has("chrome")){
79 edFrame.contentWindow.print();
81 // Neither Opera nor Chrome 3 et you print single frames.
82 // So, open a new 'window', print it, and close it.
83 // Also, can't use size 0x0, have to use 1x1
84 var edDoc = this.editor.document;
85 var content = this.editor.get("value");
86 content = "<html><head><meta http-equiv='Content-Type' " +
87 "content='text/html; charset='UTF-8'></head><body>" +
88 content + "</body></html>";
89 var win = window.open("javascript: ''",
91 "status=0,menubar=0,location=0,toolbar=0," +
92 "width=1,height=1,resizable=0,scrollbars=0");
94 win.document.write(content);
97 var styleNodes = edDoc.getElementsByTagName("style");
99 // Clone over any editor view styles, since we can't print the iframe
102 for(i = 0; i < styleNodes.length; i++){
103 var style = styleNodes[i].innerHTML;
104 var sNode = win.document.createElement("style");
105 sNode.appendChild(win.document.createTextNode(style));
106 win.document.getElementsByTagName("head")[0].appendChild(sNode);
116 // Register this plugin.
117 _Plugin.registry["print"] = function(){
118 return new Print({command: "print"});