support for windows 10 UWP apps

This commit is contained in:
Pirvu Doru Lucian
2014-03-04 18:21:30 +02:00
committed by Sebastián Katzer
parent a4f5dd098f
commit 970060a28e
3 changed files with 54 additions and 1 deletions

View File

@@ -0,0 +1,44 @@
PrinterProxy = {
printDocumentSource: null,
isAvailable: function (successCallback, failCallback, args) {
successCallback(true, 0);
},
print: function (successCallback, failCallback, args) {
var documentFragment = document.createDocumentFragment();
var content = document.createElement("html");
window.printContent = args[0];
content.innerHTML = window.printContent;
documentFragment.appendChild(content);
PrinterProxy.getPrintDocumentSource(documentFragment).then(function(source) {
PrinterProxy.printDocumentSource = source;
Windows.Graphics.Printing.PrintManager.showPrintUIAsync();
});
},
getPrintDocumentSource: function(documentFragment) {
var promise;
if(MSApp.getHtmlPrintDocumentSourceAsync) {
promise = MSApp.getHtmlPrintDocumentSourceAsync(documentFragment);
} else {
promise = new WinJS.Promise(function(completeDispatch) {
completeDispatch(MSApp.getHtmlPrintDocumentSource(documentFragment));
});
}
return promise;
},
printTaskRequested: function (printEvent) {
printEvent.request.createPrintTask("Print", function (args) {
args.setSource(PrinterProxy.printDocumentSource);
});
}
};
var printManager = Windows.Graphics.Printing.PrintManager.getForCurrentView();
printManager.onprinttaskrequested = PrinterProxy.printTaskRequested;
require("cordova/exec/proxy").add("Printer", PrinterProxy);