Print-View positioning on iPad

This commit is contained in:
Sebastián Katzer
2014-10-13 23:31:12 +02:00
parent 268f1b652d
commit 15aa295cf6
4 changed files with 87 additions and 4 deletions

View File

@@ -26,6 +26,20 @@ var exec = require('cordova/exec');
*/
exports.DEFAULT_DOC_NAME = 'unknown';
/**
* List of all available options with their default value.
*
* @return {Object}
*/
exports.getDefaults = function () {
return {
name: exports.DEFAULT_DOC_NAME,
duplex: true,
landscape: false,
bounds: [40, 30, 0, 0]
};
};
/**
* Checks if the printer service is avaible (iOS)
* or if connected to the Internet (Android).
@@ -69,12 +83,52 @@ exports.print = function (content, options, callback, scope) {
if (typeof params == 'string')
params = { name: params };
params = this.mergeWithDefaults(params);
if ([null, undefined, ''].indexOf(params.name) > -1)
params.name = this.DEFAULT_DOC_NAME;
exec(fn, null, 'Printer', 'print', [page, params]);
};
/**
* @private
*
* Merge settings with default values.
*
* @param {Object} options
* The custom options
*
* @retrun {Object}
* Default values merged
* with custom values
*/
exports.mergeWithDefaults = function (options) {
var defaults = this.getDefaults();
if (options.bounds && !options.bounds.length) {
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],
];
}
for (var key in defaults) {
if (!options.hasOwnProperty(key)) {
options[key] = defaults[key];
continue;
}
if (typeof options[key] != typeof defaults[key]) {
delete options[key];
}
}
return options;
};
/**
* @private
*
@@ -95,4 +149,4 @@ exports._createCallbackFn = function (callbackFn, scope) {
return function () {
callbackFn.apply(scope || this, arguments);
};
};
};