ionic-keyboard-assist
Version:
    • 8.2 kB
JavaScript
import { Injectable, defineInjectable } from '@angular/core';
/**
* @fileoverview added by tsickle
* Generated from: lib/keyboard-options.model.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Keyboard options class
*/
var /**
* Keyboard options class
*/
KeyboardOptions = /** @class */ (function () {
function KeyboardOptions(options) {
this.scrollPadding = options && options.scrollPadding ? options.scrollPadding : true;
this.scrollAssist = options && options.scrollAssist ? options.scrollAssist : true;
}
return KeyboardOptions;
}());
/**
* @fileoverview added by tsickle
* Generated from: lib/ionic-keyboard-assist.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var IonicKeyboardAssist = /** @class */ (function () {
function IonicKeyboardAssist() {
var _this = this;
/**
* Stores modified pages element
*/
this.pages = [];
/**
* On keyboard did show actions
* @param event: keyboard event
*/
this.onKeyboardDidShow = (/**
* @param {?} event
* @return {?}
*/
function (event) {
/** @type {?} */
var modal = _this.getActiveModalElement();
/** @type {?} */
var activeElement;
if (modal) {
activeElement = modal;
}
else {
activeElement = _this.getActivePageElement();
}
_this.pages.push(activeElement);
if (_this.options.scrollPadding) {
_this.setPadding(activeElement, event.keyboardHeight);
}
if (_this.options.scrollAssist) {
_this.scrollAssist();
}
});
/**
* On keyboard will hide actions
*/
this.onKeyboardWillHide = (/**
* @return {?}
*/
function () {
_this.pages.forEach((/**
* @param {?} elem
* @return {?}
*/
function (elem) {
_this.setPadding(elem);
}));
setTimeout((/**
* @return {?}
*/
function () { return _this.pages = []; }), 50);
});
this.setOptions();
}
/**
* Start the keyboard wizard
* @param options: KeyboardOptionsModel
*/
/**
* Start the keyboard wizard
* @param {?=} options
* @return {?}
*/
IonicKeyboardAssist.prototype.init = /**
* Start the keyboard wizard
* @param {?=} options
* @return {?}
*/
function (options) {
if (options) {
this.setOptions(options);
}
this.addEventListeners();
};
/**
* Set keyboard options
* @param options: KeyboardOptionsModel
*/
/**
* Set keyboard options
* @param {?=} options
* @return {?}
*/
IonicKeyboardAssist.prototype.setOptions = /**
* Set keyboard options
* @param {?=} options
* @return {?}
*/
function (options) {
this.options = new KeyboardOptions(options);
};
/**
* Add Event Listeners
*/
/**
* Add Event Listeners
* @private
* @return {?}
*/
IonicKeyboardAssist.prototype.addEventListeners = /**
* Add Event Listeners
* @private
* @return {?}
*/
function () {
window.addEventListener('keyboardDidShow', this.onKeyboardDidShow);
window.addEventListener('keyboardWillHide', this.onKeyboardWillHide);
};
/**
* Remove Event Listeners
*/
/**
* Remove Event Listeners
* @private
* @return {?}
*/
IonicKeyboardAssist.prototype.removeEventListeners = /**
* Remove Event Listeners
* @private
* @return {?}
*/
function () {
window.removeEventListener('keyboardDidShow', this.onKeyboardDidShow);
window.removeEventListener('keyboardWillHide', this.onKeyboardWillHide);
};
/**
* Get current page element
*/
/**
* Get current page element
* @private
* @return {?}
*/
IonicKeyboardAssist.prototype.getActivePageElement = /**
* Get current page element
* @private
* @return {?}
*/
function () {
/** @type {?} */
var elem = document.getElementsByTagName('ion-router-outlet');
if (elem && elem.length > 0) {
/** @type {?} */
var page = elem[elem.length - 1];
return page && page.lastElementChild ? page.lastElementChild : null;
}
return null;
};
/**
* Get current modal element
*/
/**
* Get current modal element
* @private
* @return {?}
*/
IonicKeyboardAssist.prototype.getActiveModalElement = /**
* Get current modal element
* @private
* @return {?}
*/
function () {
/** @type {?} */
var elem = document.getElementsByTagName('ion-app');
if (elem && elem.length > 0) {
/** @type {?} */
var page = elem[elem.length - 1];
return page && page.lastElementChild && page.lastElementChild.tagName === 'ION-MODAL' ? page.lastElementChild : null;
}
return null;
};
/**
* Add padding on the element
*/
/**
* Add padding on the element
* @private
* @param {?} elem
* @param {?=} value
* @return {?}
*/
IonicKeyboardAssist.prototype.setPadding = /**
* Add padding on the element
* @private
* @param {?} elem
* @param {?=} value
* @return {?}
*/
function (elem, value) {
if (value === void 0) { value = 0; }
if (elem) {
elem.setAttribute('style', "padding-bottom: " + value + "px !important");
}
};
/**
* Scroll view to active element
*/
/**
* Scroll view to active element
* @private
* @return {?}
*/
IonicKeyboardAssist.prototype.scrollAssist = /**
* Scroll view to active element
* @private
* @return {?}
*/
function () {
if (document.activeElement && document.activeElement.tagName === 'INPUT') {
setTimeout((/**
* @return {?}
*/
function () { return document.activeElement.scrollIntoView({ block: 'center', behavior: 'smooth' }); }), 100);
}
};
/**
* Remove listeners on destroy
*/
/**
* Remove listeners on destroy
* @return {?}
*/
IonicKeyboardAssist.prototype.ngOnDestroy = /**
* Remove listeners on destroy
* @return {?}
*/
function () {
this.removeEventListeners();
};
IonicKeyboardAssist.decorators = [
{ type: Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
IonicKeyboardAssist.ctorParameters = function () { return []; };
/** @nocollapse */ IonicKeyboardAssist.ngInjectableDef = defineInjectable({ factory: function IonicKeyboardAssist_Factory() { return new IonicKeyboardAssist(); }, token: IonicKeyboardAssist, providedIn: "root" });
return IonicKeyboardAssist;
}());
/**
* @fileoverview added by tsickle
* Generated from: public-api.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* Generated from: ionic-keyboard-assist.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
export { IonicKeyboardAssist };
//# sourceMappingURL=ionic-keyboard-assist.js.map