@ng-select/ng-option-highlight
Version:
## Build
128 lines (124 loc) • 3.68 kB
JavaScript
import { Directive, ElementRef, Renderer2, Input, NgModule } from '@angular/core';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NgOptionHighlightDirective = /** @class */ (function () {
function NgOptionHighlightDirective(elementRef, renderer) {
this.elementRef = elementRef;
this.renderer = renderer;
this.element = this.elementRef.nativeElement;
}
/**
* @return {?}
*/
NgOptionHighlightDirective.prototype.ngOnChanges = /**
* @return {?}
*/
function () {
if (this._canHighlight) {
this._highlightLabel();
}
};
/**
* @return {?}
*/
NgOptionHighlightDirective.prototype.ngAfterViewInit = /**
* @return {?}
*/
function () {
this.label = this.element.innerHTML;
if (this._canHighlight) {
this._highlightLabel();
}
};
/**
* @private
* @return {?}
*/
NgOptionHighlightDirective.prototype._highlightLabel = /**
* @private
* @return {?}
*/
function () {
/** @type {?} */
var label = this.label;
if (!this.term) {
this._setInnerHtml(label);
return;
}
/** @type {?} */
var alternationString = this.term.replace(' ', '|');
/** @type {?} */
var termRegex = new RegExp(alternationString, 'gi');
this._setInnerHtml(label.replace(termRegex, "<span class=\"highlighted\">$&</span>"));
};
Object.defineProperty(NgOptionHighlightDirective.prototype, "_canHighlight", {
get: /**
* @private
* @return {?}
*/
function () {
return this._isDefined(this.term) && this._isDefined(this.label);
},
enumerable: true,
configurable: true
});
/**
* @private
* @param {?} html
* @return {?}
*/
NgOptionHighlightDirective.prototype._setInnerHtml = /**
* @private
* @param {?} html
* @return {?}
*/
function (html) {
this.renderer.setProperty(this.elementRef.nativeElement, 'innerHTML', html);
};
/**
* @private
* @param {?} value
* @return {?}
*/
NgOptionHighlightDirective.prototype._isDefined = /**
* @private
* @param {?} value
* @return {?}
*/
function (value) {
return value !== undefined && value !== null;
};
NgOptionHighlightDirective.decorators = [
{ type: Directive, args: [{
selector: '[ngOptionHighlight]'
},] }
];
/** @nocollapse */
NgOptionHighlightDirective.ctorParameters = function () { return [
{ type: ElementRef },
{ type: Renderer2 }
]; };
NgOptionHighlightDirective.propDecorators = {
term: [{ type: Input, args: ['ngOptionHighlight',] }]
};
return NgOptionHighlightDirective;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NgOptionHighlightModule = /** @class */ (function () {
function NgOptionHighlightModule() {
}
NgOptionHighlightModule.decorators = [
{ type: NgModule, args: [{
declarations: [NgOptionHighlightDirective],
exports: [NgOptionHighlightDirective]
},] }
];
return NgOptionHighlightModule;
}());
export { NgOptionHighlightDirective, NgOptionHighlightModule };
//# sourceMappingURL=ng-select-ng-option-highlight.js.map