| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/i18n", |
| 4 |
"dojo/_base/lang", |
| 5 |
"dojo/sniff", |
| 6 |
"../../focus", |
| 7 |
"../_Plugin", |
| 8 |
"../../form/Button", |
| 9 |
"dojo/i18n!../nls/commands" |
| 10 |
], function(declare, i18n, lang, has, focus, _Plugin, Button){ |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
var Print = declare("dijit._editor.plugins.Print", _Plugin, { |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
_initButton: function(){ |
| 21 |
|
| 22 |
|
| 23 |
var strings = i18n.getLocalization("dijit._editor", "commands"), |
| 24 |
editor = this.editor; |
| 25 |
this.button = new Button({ |
| 26 |
label: strings["print"], |
| 27 |
ownerDocument: editor.ownerDocument, |
| 28 |
dir: editor.dir, |
| 29 |
lang: editor.lang, |
| 30 |
showLabel: false, |
| 31 |
iconClass: this.iconClassPrefix + " " + this.iconClassPrefix + "Print", |
| 32 |
tabIndex: "-1", |
| 33 |
onClick: lang.hitch(this, "_print") |
| 34 |
}); |
| 35 |
}, |
| 36 |
|
| 37 |
setEditor: function( editor){ |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
this.editor = editor; |
| 43 |
this._initButton(); |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
this.editor.onLoadDeferred.then( |
| 48 |
lang.hitch(this, function(){ |
| 49 |
if(!this.editor.iframe.contentWindow["print"]){ |
| 50 |
this.button.set("disabled", true); |
| 51 |
} |
| 52 |
}) |
| 53 |
); |
| 54 |
}, |
| 55 |
|
| 56 |
updateState: function(){ |
| 57 |
|
| 58 |
|
| 59 |
var disabled = this.get("disabled"); |
| 60 |
if(!this.editor.iframe.contentWindow["print"]){ |
| 61 |
disabled = true; |
| 62 |
} |
| 63 |
this.button.set("disabled", disabled); |
| 64 |
}, |
| 65 |
|
| 66 |
_print: function(){ |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
var edFrame = this.editor.iframe; |
| 72 |
if(edFrame.contentWindow["print"]){ |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
if(!has("opera") && !has("chrome")){ |
| 77 |
focus.focus(edFrame); |
| 78 |
edFrame.contentWindow.print(); |
| 79 |
}else{ |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
var edDoc = this.editor.document; |
| 84 |
var content = this.editor.get("value"); |
| 85 |
content = "<html><head><meta http-equiv='Content-Type' " + |
| 86 |
"content='text/html; charset='UTF-8'></head><body>" + |
| 87 |
content + "</body></html>"; |
| 88 |
var win = window.open("javascript: ''", |
| 89 |
"", |
| 90 |
"status=0,menubar=0,location=0,toolbar=0," + |
| 91 |
"width=1,height=1,resizable=0,scrollbars=0"); |
| 92 |
win.document.open(); |
| 93 |
win.document.write(content); |
| 94 |
win.document.close(); |
| 95 |
|
| 96 |
var styleNodes = edDoc.getElementsByTagName("style"); |
| 97 |
if(styleNodes){ |
| 98 |
|
| 99 |
|
| 100 |
var i; |
| 101 |
for(i = 0; i < styleNodes.length; i++){ |
| 102 |
var style = styleNodes[i].innerHTML; |
| 103 |
var sNode = win.document.createElement("style"); |
| 104 |
sNode.appendChild(win.document.createTextNode(style)); |
| 105 |
win.document.getElementsByTagName("head")[0].appendChild(sNode); |
| 106 |
} |
| 107 |
} |
| 108 |
win.print(); |
| 109 |
win.close(); |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
}); |
| 114 |
|
| 115 |
|
| 116 |
_Plugin.registry["print"] = function(){ |
| 117 |
return new Print({command: "print"}); |
| 118 |
}; |
| 119 |
|
| 120 |
return Print; |
| 121 |
}); |