Some reformatting

This commit is contained in:
Sebastián Katzer 2019-02-12 09:47:19 +01:00
parent 951348aee5
commit 10645a709b

View File

@ -56,7 +56,10 @@ exports._defaults = {
// ui: { // ui: {
// hideNumberOfCopies: false, // hideNumberOfCopies: false,
// hidePaperFormat: false, // hidePaperFormat: false,
// bounds: [40, 30, 0, 0] // top: 30,
// left: 40,
// height: 0,
// width: 0
// }, // },
// paper: { // paper: {
@ -107,9 +110,10 @@ exports._defaults = {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.canPrintItem = function (uri, callback, scope) { exports.canPrintItem = function (uri, callback, scope)
{
if (typeof uri == 'function') { if (typeof uri == 'function')
{
scope = callback; scope = callback;
callback = uri; callback = uri;
uri = null; uri = null;
@ -128,7 +132,8 @@ exports.canPrintItem = function (uri, callback, scope) {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.getPrintableTypes = function (callback, scope) { exports.getPrintableTypes = function (callback, scope)
{
var fn = this._createCallbackFn(callback, scope); var fn = this._createCallbackFn(callback, scope);
exec(fn, null, 'Printer', 'types', []); exec(fn, null, 'Printer', 'types', []);
@ -143,9 +148,10 @@ exports.getPrintableTypes = function (callback, scope) {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.pick = function (options, callback, scope) { exports.pick = function (options, callback, scope)
{
if (typeof options == 'function') { if (typeof options == 'function')
{
scope = callback; scope = callback;
callback = options; callback = options;
options = {}; options = {};
@ -154,9 +160,12 @@ exports.pick = function (options, callback, scope) {
var fn = this._createCallbackFn(callback, scope), var fn = this._createCallbackFn(callback, scope),
params = this._mergeWithDefaults(options || {}); params = this._mergeWithDefaults(options || {});
if (isIOS) { if (isIOS)
{
exec(fn, null, 'Printer', 'pick', [params]); exec(fn, null, 'Printer', 'pick', [params]);
} else if (fn) { }
else if (fn)
{
fn(null); fn(null);
} }
}; };
@ -169,16 +178,18 @@ exports.pick = function (options, callback, scope) {
* @param [ Function ] callback The callback function. * @param [ Function ] callback The callback function.
* @param [ Object ] scope The scope for the function. * @param [ Object ] scope The scope for the function.
*/ */
exports.print = function (content, options, callback, scope) { exports.print = function (content, options, callback, scope)
{
if (typeof content == 'function') { if (typeof content == 'function')
{
scope = options; scope = options;
callback = content; callback = content;
options = {}; options = {};
content = null; content = null;
} }
if (typeof options == 'function') { if (typeof options == 'function')
{
scope = callback; scope = callback;
callback = options; callback = options;
options = typeof content != 'string' ? content : {}; options = typeof content != 'string' ? content : {};
@ -196,14 +207,18 @@ exports.print = function (content, options, callback, scope) {
* *
* @return [ Object ] * @return [ Object ]
*/ */
exports.getDefaults = function () { exports.getDefaults = function ()
{
var map = Object.assign({}, this._defaults); var map = Object.assign({}, this._defaults);
for (var key in map) { for (var key in map)
if (Array.isArray(map[key])) { {
if (Array.isArray(map[key]))
{
map[key] = Array.from(map[key]); map[key] = Array.from(map[key]);
} else }
if (Object.prototype.isPrototypeOf(map[key])) { else if (Object.prototype.isPrototypeOf(map[key]))
{
map[key] = Object.assign({}, map[key]); map[key] = Object.assign({}, map[key]);
} }
} }
@ -218,7 +233,8 @@ exports.getDefaults = function () {
* *
* @return [ Void ] * @return [ Void ]
*/ */
exports.setDefaults = function (newDefaults) { exports.setDefaults = function (newDefaults)
{
Object.assign(this._defaults, newDefaults); Object.assign(this._defaults, newDefaults);
}; };
@ -229,35 +245,33 @@ exports.setDefaults = function (newDefaults) {
* *
* @retrun [ Object ] * @retrun [ Object ]
*/ */
exports._mergeWithDefaults = function (options) { exports._mergeWithDefaults = function (options)
{
var defaults = this.getDefaults(); var defaults = this.getDefaults();
if (options.bounds && !Array.isArray(options.bounds)) { if (options.duplex && typeof options.duplex == 'boolean')
options.bounds = [ {
options.bounds.left || defaults.bounds[0],
options.bounds.top || defaults.bounds[1],
options.bounds.width || defaults.bounds[2],
options.bounds.height || defaults.bounds[3],
];
}
if (options.duplex && typeof options.duplex == 'boolean') {
options.duplex = options.duplex ? 'long' : 'none'; options.duplex = options.duplex ? 'long' : 'none';
} }
Object.assign(defaults, options); Object.assign(defaults, options);
for (var key in defaults) { for (var key in defaults)
if (defaults[key] !== null) { {
if (defaults[key] !== null)
{
options[key] = defaults[key]; options[key] = defaults[key];
} else { }
else
{
delete options[key]; delete options[key];
} }
} }
options.meta = { options.meta =
{
plugin: 'cordova-plugin-printer', plugin: 'cordova-plugin-printer',
version: '0.8.0-alpha' version: '0.8.0-beta'
}; };
return options; return options;
@ -274,8 +288,8 @@ exports._mergeWithDefaults = function (options) {
* *
* @return [ Function ] The new callback function * @return [ Function ] The new callback function
*/ */
exports._createCallbackFn = function (callback, scope) { exports._createCallbackFn = function (callback, scope)
{
if (typeof callback !== 'function') if (typeof callback !== 'function')
return; return;