2013-12-11 20:00:16 +08:00
|
|
|
/*
|
|
|
|
Copyright 2013 appPlant UG
|
|
|
|
|
|
|
|
Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
or more contributor license agreements. See the NOTICE file
|
|
|
|
distributed with this work for additional information
|
|
|
|
regarding copyright ownership. The ASF licenses this file
|
|
|
|
to you under the Apache License, Version 2.0 (the
|
|
|
|
"License"); you may not use this file except in compliance
|
|
|
|
with the License. You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing,
|
|
|
|
software distributed under the License is distributed on an
|
|
|
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
KIND, either express or implied. See the License for the
|
|
|
|
specific language governing permissions and limitations
|
|
|
|
under the License.
|
|
|
|
*/
|
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 () {
|
2013-08-22 00:04:51 +08:00
|
|
|
var args = typeof arguments[0] == 'boolean' ? arguments : arguments[0];
|
|
|
|
|
|
|
|
callback.apply(scope || window, args);
|
2013-08-13 17:01:15 +08:00
|
|
|
};
|
|
|
|
|
2013-12-11 22:49:00 +08:00
|
|
|
if (device.platform == 'Android' && device.version >= '4.4') {
|
|
|
|
cordova.exec(callbackFn, null, 'KitKatPrinter', 'isServiceAvailable', []);
|
|
|
|
} else {
|
|
|
|
cordova.exec(callbackFn, null, 'Printer', 'isServiceAvailable', []);
|
|
|
|
};
|
2013-08-10 15:50:42 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Übergibt den HTML-Content an den Drucker-Dienst.
|
|
|
|
*
|
2013-12-11 20:21:23 +08:00
|
|
|
* @param {String} content HTML string or DOM node (if latter, innerHTML is used to get the contents)
|
|
|
|
* @param {Object?} options platform specific options
|
2013-08-10 15:50:42 +08:00
|
|
|
*/
|
2013-12-11 20:21:23 +08:00
|
|
|
print: function (content, options) {
|
2013-08-24 05:54:04 +08:00
|
|
|
var page = content.innerHTML || content,
|
2013-12-11 20:21:23 +08:00
|
|
|
options = options || {};
|
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-12-11 22:49:00 +08:00
|
|
|
if (device.platform == 'Android' && device.version >= '4.4') {
|
|
|
|
cordova.exec(null, null, 'KitKatPrinter', 'print', [page, options]);
|
|
|
|
} else {
|
|
|
|
cordova.exec(null, null, 'Printer', 'print', [page, options]);
|
|
|
|
};
|
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;
|