2013-08-10 00:58:47 +08:00
|
|
|
/**
|
2013-08-10 17:22:49 +08:00
|
|
|
* printer.js
|
2013-08-10 15:50:42 +08:00
|
|
|
* Cordova Printer Plugin
|
|
|
|
*
|
|
|
|
* Created by Sebastian Katzer (github.com/katzer) on 10/08/2013.
|
|
|
|
* Copyright 2013 Sebastian Katzer. All rights reserved.
|
|
|
|
* GPL v2 licensed
|
2013-08-10 00:58:47 +08:00
|
|
|
*/
|
|
|
|
|
2013-08-10 15:50:42 +08:00
|
|
|
var Printer = function () {
|
2013-08-10 00:58:47 +08:00
|
|
|
|
2013-08-10 15:50:42 +08:00
|
|
|
};
|
2013-08-10 00:58:47 +08:00
|
|
|
|
2013-08-10 15:50:42 +08:00
|
|
|
Printer.prototype = {
|
|
|
|
/**
|
|
|
|
* Überprüft, ob der Drucker-Dienst verfügbar ist.
|
|
|
|
*
|
|
|
|
* @param {Function} callback
|
2013-08-13 17:01:15 +08:00
|
|
|
* @param {Object?} scope callback scope (default: window)
|
|
|
|
*
|
2013-08-10 15:50:42 +08:00
|
|
|
* @return {Boolean}
|
|
|
|
*/
|
2013-08-13 17:01:15 +08:00
|
|
|
isServiceAvailable: function (callback, scope) {
|
|
|
|
var callbackFn = function () {
|
|
|
|
callback.apply(scope || window, arguments);
|
|
|
|
};
|
|
|
|
|
|
|
|
cordova.exec(callbackFn, null, 'Printer', 'isServiceAvailable', []);
|
2013-08-10 15:50:42 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Übergibt den HTML-Content an den Drucker-Dienst.
|
|
|
|
*
|
2013-08-13 17:01:15 +08:00
|
|
|
* @param {String} content HTML string or DOM node (if latter, innerHTML is used to get the contents)
|
|
|
|
* @param {Function?} callback callback function called if print is completed. {success: bool, available: bool, error: reason}
|
|
|
|
* @param {Object?} scope callback scope (default: window)
|
2013-08-10 15:50:42 +08:00
|
|
|
*/
|
2013-08-13 17:01:15 +08:00
|
|
|
print: function (content, callback, scope) {
|
|
|
|
var page = content.innerHTML || content,
|
|
|
|
callbackFn;
|
2013-08-10 15:50:42 +08:00
|
|
|
|
2013-08-13 17:01:15 +08:00
|
|
|
if (typeof page != 'string') {
|
2013-08-10 15:50:42 +08:00
|
|
|
console.log('Print function requires an HTML string. Not an object');
|
|
|
|
return;
|
2013-08-10 00:58:47 +08:00
|
|
|
}
|
|
|
|
|
2013-08-13 17:01:15 +08:00
|
|
|
if (typeof callback == 'function'){
|
|
|
|
callbackFn = function () {
|
|
|
|
callback.apply(scope || window, arguments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cordova.exec(callbackFn, null, 'Printer', 'print', [page]);
|
2013-08-10 15:50:42 +08:00
|
|
|
}
|
2013-08-10 00:58:47 +08:00
|
|
|
};
|
|
|
|
|
2013-08-13 17:01:15 +08:00
|
|
|
var plugin = new Printer();
|
2013-08-10 00:58:47 +08:00
|
|
|
|
2013-08-13 17:01:15 +08:00
|
|
|
module.exports = plugin;
|