@ng-select/ng-option-highlight
Version:
## Build
137 lines (131 loc) • 4.73 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) :
typeof define === 'function' && define.amd ? define('@ng-select/ng-option-highlight', ['exports', '@angular/core'], factory) :
(global = global || self, factory((global['ng-select'] = global['ng-select'] || {}, global['ng-select']['ng-option-highlight'] = {}), global.ng.core));
}(this, function (exports, core) { 'use strict';
/**
* @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: core.Directive, args: [{
selector: '[ngOptionHighlight]'
},] }
];
/** @nocollapse */
NgOptionHighlightDirective.ctorParameters = function () { return [
{ type: core.ElementRef },
{ type: core.Renderer2 }
]; };
NgOptionHighlightDirective.propDecorators = {
term: [{ type: core.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: core.NgModule, args: [{
declarations: [NgOptionHighlightDirective],
exports: [NgOptionHighlightDirective]
},] }
];
return NgOptionHighlightModule;
}());
exports.NgOptionHighlightDirective = NgOptionHighlightDirective;
exports.NgOptionHighlightModule = NgOptionHighlightModule;
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=ng-select-ng-option-highlight.umd.js.map