Update js

This commit is contained in:
Sebastián Katzer 2014-09-07 22:52:47 +02:00
parent 43625bd313
commit 33b4c14557

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2013 appPlant UG Copyright 2013-2014 appPlant UG
Licensed to the Apache Software Foundation (ASF) under one Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file or more contributor license agreements. See the NOTICE file
@ -19,48 +19,80 @@
under the License. under the License.
*/ */
var Printer = function () { var exec = require('cordova/exec');
};
Printer.prototype = {
/** /**
* Überprüft, ob der Drucker-Dienst verfügbar ist. * The default document/job name.
*/
exports.DEFAULT_DOC_NAME = 'unknown';
/**
* Checks if the printer service is avaible (iOS)
* or if connected to the Internet (Android).
* *
* @param {Function} callback * @param {Function} callback
* @param {Object?} scope callback scope (default: window) * A callback function
* @param {Object?} scope
* The scope of the callback (default: window)
* *
* @return {Boolean} * @return {Boolean}
*/ */
isServiceAvailable: function (callback, scope) { exports.isAvailable = function (callback, scope) {
var callbackFn = function () { var fn = this._createCallbackFn(callback);
var args = typeof arguments[0] == 'boolean' ? arguments : arguments[0];
callback.apply(scope || window, args); exec(fn, null, 'Printer', 'isAvailable', []);
}; };
cordova.exec(callbackFn, null, 'Printer', 'isServiceAvailable', []);
},
/** /**
* Übergibt den HTML-Content an den Drucker-Dienst. * Sends the content to the Google Cloud Print service.
* *
* @param {String} content HTML string or DOM node (if latter, innerHTML is used to get the contents) * @param {String} content
* @param {Object?} options platform specific options * HTML string or DOM node
* if latter, innerHTML is used to get the content
* @param {Object} options
* Options for the print job
* @param {Function?} callback
* A callback function
* @param {Object?} scope
* The scope of the callback (default: window)
*/ */
print: function (content, options) { exports.print = function (content, options, callback, scope) {
var page = content.innerHTML || content, var page = content.innerHTML || content,
options = options || {}; params = options || {},
fn = this._createCallbackFn(callback);
if (typeof page != 'string') { if (typeof page != 'string') {
console.log('Print function requires an HTML string. Not an object'); console.log('Print function requires an HTML string. Not an object');
return; return;
} }
cordova.exec(null, null, 'Printer', 'print', [page, options]); if (typeof params == 'string')
} params = { name: params };
if ([null, undefined, ''].indexOf(params.name) > -1)
params.name = this.DEFAULT_DOC_NAME;
exec(fn, null, 'Printer', 'print', [page, params]);
}; };
var plugin = new Printer(); /**
* @private
*
* Creates a callback, which will be executed within a specific scope.
*
* @param {Function} callbackFn
* The callback function
* @param {Object} scope
* The scope for the function
*
* @return {Function}
* The new callback function
*/
exports._createCallbackFn = function (callbackFn, scope) {
if (typeof callbackFn != 'function')
return;
module.exports = plugin; return function () {
callbackFn.apply(scope || this, arguments);
};
};