Socket
Socket
Sign inDemoInstall

angular-2-dropdown-multiselect

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-2-dropdown-multiselect - npm Package Compare versions

Comparing version 0.3.3 to 0.3.4

.editorconfig

23

package.json
{
"name": "angular-2-dropdown-multiselect",
"version": "0.3.3",
"version": "0.3.4",
"description": "Customizable dropdown multiselect in Angular 2 with bootstrap css.",

@@ -21,14 +21,15 @@ "main": "src/multiselect-dropdown.ts",

"homepage": "http://softsimon.github.io/angular-2-dropdown-multiselect",
"dependencies": {
"@angular/common": "^2.4.0",
"@angular/compiler": "^2.4.0",
"@angular/core": "^2.4.0",
"@angular/forms": "^2.4.0",
"rxjs": "^5.0.2",
"zone.js": "^0.7.2"
},
"devDependencies": {
"@angular/common": "^2.0.0",
"@angular/core": "^2.0.0",
"@angular/forms": "^2.0.0",
"rxjs": "5.0.0-rc.4"
},
"peerDependencies": {
"@angular/common": "^2.0.0",
"@angular/core": "^2.0.0",
"@angular/forms": "^2.0.0",
"rxjs": "5.0.0-rc.4"
"codelyzer": "^2.0.0-beta.4",
"tslint": "^4.0.0",
"typescript": "^2.1.0"
}
}

@@ -15,3 +15,3 @@ # Angular 2 Dropdown Multiselect for Bootstrap CSS

* [Download the latest release](https://github.com/softsimon/angular-2-dropdown-multiselect/archive/v0.2.0.zip).
* [Download the latest release](https://github.com/softsimon/angular-2-dropdown-multiselect/releases).
* Clone the repo: `git clone https://github.com/softsimon/angular-2-dropdown-multiselect.git`.

@@ -18,0 +18,0 @@ * Install with [Bower](http://bower.io): `bower install angular-2-dropdown-multiselect --save`.

@@ -42,3 +42,7 @@ /*

MultiSelectSearchFilter.prototype.transform = function (options, args) {
return options.filter(function (option) { return option.name.toLowerCase().indexOf((args || '').toLowerCase()) > -1; });
return options.filter(function (option) {
return option.name
.toLowerCase()
.indexOf((args || '').toLowerCase()) > -1;
});
};

@@ -60,6 +64,2 @@ MultiSelectSearchFilter = __decorate([

this.dropdownClosed = new core_1.EventEmitter();
this.onModelChange = function (_) {
};
this.onModelTouched = function () {
};
this.numSelected = 0;

@@ -89,4 +89,11 @@ this.isVisible = false;

};
this.onModelChange = function (_) { };
this.onModelTouched = function () { };
this.differ = differs.find([]).create(null);
}
MultiselectDropdown.prototype.ngOnInit = function () {
this.settings = Object.assign(this.defaultSettings, this.settings);
this.texts = Object.assign(this.defaultTexts, this.texts);
this.title = this.texts.defaultTitle;
};
MultiselectDropdown.prototype.onClick = function (target) {

@@ -104,7 +111,2 @@ var parentFound = false;

};
MultiselectDropdown.prototype.ngOnInit = function () {
this.settings = Object.assign(this.defaultSettings, this.settings);
this.texts = Object.assign(this.defaultTexts, this.texts);
this.title = this.texts.defaultTitle;
};
MultiselectDropdown.prototype.writeValue = function (value) {

@@ -178,3 +180,5 @@ if (value !== undefined) {

this.title = this.options
.filter(function (option) { return _this.model && _this.model.indexOf(option.id) > -1; })
.filter(function (option) {
return _this.model && _this.model.indexOf(option.id) > -1;
})
.map(function (option) { return option.name; })

@@ -184,3 +188,5 @@ .join(', ');

else {
this.title = this.numSelected + ' ' + (this.numSelected === 1 ? this.texts.checked : this.texts.checkedPlural);
this.title = this.numSelected
+ ' '
+ (this.numSelected === 1 ? this.texts.checked : this.texts.checkedPlural);
}

@@ -218,6 +224,4 @@ };

core_1.HostListener('document: click', ['$event.target']),
__metadata('design:type', Function),
__metadata('design:paramtypes', [HTMLElement]),
__metadata('design:returntype', void 0)
], MultiselectDropdown.prototype, "onClick", null);
__metadata('design:type', Array)
], MultiselectDropdown.prototype, "model", void 0);
MultiselectDropdown = __decorate([

@@ -227,9 +231,8 @@ core_1.Component({

providers: [MULTISELECT_VALUE_ACCESSOR],
styles: ["\n\t\ta { outline: none !important; }\n\t"],
template: "\n <div class=\"btn-group\">\n <button type=\"button\" class=\"dropdown-toggle\" [ngClass]=\"settings.buttonClasses\" \n (click)=\"toggleDropdown()\">{{ title }}&nbsp;<span class=\"caret\"></span></button>\n <ul *ngIf=\"isVisible\" class=\"dropdown-menu\" [class.pull-right]=\"settings.pullRight\" \n [style.max-height]=\"settings.maxHeight\" style=\"display: block; height: auto; overflow-y: auto;\">\n <li class=\"dropdown-item\" style=\"margin: 0px 5px 5px 5px;\" *ngIf=\"settings.enableSearch\">\n <div class=\"input-group input-group-sm\">\n <span class=\"input-group-addon\" id=\"sizing-addon3\"><i class=\"fa fa-search\"></i></span>\n <input type=\"text\" class=\"form-control\" placeholder=\"{{ texts.searchPlaceholder }}\" \n aria-describedby=\"sizing-addon3\" [(ngModel)]=\"searchFilterText\">\n <span class=\"input-group-btn\" *ngIf=\"searchFilterText.length > 0\">\n <button class=\"btn btn-default\" type=\"button\" (click)=\"clearSearch()\"><i class=\"fa fa-times\"></i></button>\n </span>\n </div>\n </li>\n <li class=\"dropdown-divider divider\" *ngIf=\"settings.enableSearch\"></li>\n <li class=\"dropdown-item\" *ngIf=\"settings.showCheckAll\">\n <a href=\"javascript:;\" role=\"menuitem\" tabindex=\"-1\" (click)=\"checkAll()\">\n <span style=\"width: 16px;\" class=\"glyphicon glyphicon-ok\"></span>\n {{ texts.checkAll }}\n </a>\n </li>\n <li class=\"dropdown-item\" *ngIf=\"settings.showUncheckAll\">\n <a href=\"javascript:;\" role=\"menuitem\" tabindex=\"-1\" (click)=\"uncheckAll()\">\n <span style=\"width: 16px;\" class=\"glyphicon glyphicon-remove\"></span>\n {{ texts.uncheckAll }}\n </a>\n </li>\n <li *ngIf=\"settings.showCheckAll || settings.showUncheckAll\" class=\"dropdown-divider divider\"></li>\n <li class=\"dropdown-item\" *ngFor=\"let option of options | searchFilter:searchFilterText\">\n <a href=\"javascript:;\" role=\"menuitem\" tabindex=\"-1\" (click)=\"setSelected($event, option)\">\n <input *ngIf=\"settings.checkedStyle == 'checkboxes'\" type=\"checkbox\" [checked]=\"isSelected(option)\" />\n <span *ngIf=\"settings.checkedStyle == 'glyphicon'\" style=\"width: 16px;\" \n class=\"glyphicon\" [class.glyphicon-ok]=\"isSelected(option)\"></span>\n {{ option.name }}\n </a>\n </li>\n </ul>\n </div>\n "
styles: ["\n\t a { outline: none !important; }\n "],
templateUrl: './multiselect-dropdown.html'
}),
__metadata('design:paramtypes', [(typeof (_a = typeof core_1.ElementRef !== 'undefined' && core_1.ElementRef) === 'function' && _a) || Object, (typeof (_b = typeof core_1.IterableDiffers !== 'undefined' && core_1.IterableDiffers) === 'function' && _b) || Object])
__metadata('design:paramtypes', [core_1.ElementRef, core_1.IterableDiffers])
], MultiselectDropdown);
return MultiselectDropdown;
var _a, _b;
}());

@@ -236,0 +239,0 @@ exports_1("MultiselectDropdown", MultiselectDropdown);

@@ -9,271 +9,237 @@ /*

import {
NgModule,
Component,
Pipe,
OnInit,
DoCheck,
HostListener,
Input,
ElementRef,
Output,
EventEmitter,
forwardRef,
IterableDiffers
NgModule,
Component,
Pipe,
OnInit,
DoCheck,
HostListener,
Input,
ElementRef,
Output,
EventEmitter,
forwardRef,
IterableDiffers
} from '@angular/core';
import {CommonModule} from '@angular/common';
import {FormsModule, NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/forms';
import { CommonModule } from '@angular/common';
import { FormsModule, NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';
const MULTISELECT_VALUE_ACCESSOR: any = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => MultiselectDropdown),
multi: true
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => MultiselectDropdown),
multi: true
};
export interface IMultiSelectOption {
id: any;
name: string;
id: any;
name: string;
}
export interface IMultiSelectSettings {
pullRight?: boolean;
enableSearch?: boolean;
checkedStyle?: 'checkboxes' | 'glyphicon';
buttonClasses?: string;
selectionLimit?: number;
closeOnSelect?: boolean;
autoUnselect?: boolean;
showCheckAll?: boolean;
showUncheckAll?: boolean;
dynamicTitleMaxItems?: number;
maxHeight?: string;
pullRight?: boolean;
enableSearch?: boolean;
checkedStyle?: 'checkboxes' | 'glyphicon';
buttonClasses?: string;
selectionLimit?: number;
closeOnSelect?: boolean;
autoUnselect?: boolean;
showCheckAll?: boolean;
showUncheckAll?: boolean;
dynamicTitleMaxItems?: number;
maxHeight?: string;
}
export interface IMultiSelectTexts {
checkAll?: string;
uncheckAll?: string;
checked?: string;
checkedPlural?: string;
searchPlaceholder?: string;
defaultTitle?: string;
checkAll?: string;
uncheckAll?: string;
checked?: string;
checkedPlural?: string;
searchPlaceholder?: string;
defaultTitle?: string;
}
@Pipe({
name: 'searchFilter'
name: 'searchFilter'
})
export class MultiSelectSearchFilter {
transform(options: Array<IMultiSelectOption>, args: string): Array<IMultiSelectOption> {
return options.filter((option: IMultiSelectOption) => option.name.toLowerCase().indexOf((args || '').toLowerCase()) > -1);
}
transform(options: Array<IMultiSelectOption>, args: string): Array<IMultiSelectOption> {
return options.filter((option: IMultiSelectOption) =>
option.name
.toLowerCase()
.indexOf((args || '').toLowerCase()) > -1);
}
}
@Component({
selector: 'ss-multiselect-dropdown',
providers: [MULTISELECT_VALUE_ACCESSOR],
styles: [`
a { outline: none !important; }
`],
template: `
<div class="btn-group">
<button type="button" class="dropdown-toggle" [ngClass]="settings.buttonClasses"
(click)="toggleDropdown()">{{ title }}&nbsp;<span class="caret"></span></button>
<ul *ngIf="isVisible" class="dropdown-menu" [class.pull-right]="settings.pullRight"
[style.max-height]="settings.maxHeight" style="display: block; height: auto; overflow-y: auto;">
<li class="dropdown-item" style="margin: 0px 5px 5px 5px;" *ngIf="settings.enableSearch">
<div class="input-group input-group-sm">
<span class="input-group-addon" id="sizing-addon3"><i class="fa fa-search"></i></span>
<input type="text" class="form-control" placeholder="{{ texts.searchPlaceholder }}"
aria-describedby="sizing-addon3" [(ngModel)]="searchFilterText">
<span class="input-group-btn" *ngIf="searchFilterText.length > 0">
<button class="btn btn-default" type="button" (click)="clearSearch()"><i class="fa fa-times"></i></button>
</span>
</div>
</li>
<li class="dropdown-divider divider" *ngIf="settings.enableSearch"></li>
<li class="dropdown-item" *ngIf="settings.showCheckAll">
<a href="javascript:;" role="menuitem" tabindex="-1" (click)="checkAll()">
<span style="width: 16px;" class="glyphicon glyphicon-ok"></span>
{{ texts.checkAll }}
</a>
</li>
<li class="dropdown-item" *ngIf="settings.showUncheckAll">
<a href="javascript:;" role="menuitem" tabindex="-1" (click)="uncheckAll()">
<span style="width: 16px;" class="glyphicon glyphicon-remove"></span>
{{ texts.uncheckAll }}
</a>
</li>
<li *ngIf="settings.showCheckAll || settings.showUncheckAll" class="dropdown-divider divider"></li>
<li class="dropdown-item" *ngFor="let option of options | searchFilter:searchFilterText">
<a href="javascript:;" role="menuitem" tabindex="-1" (click)="setSelected($event, option)">
<input *ngIf="settings.checkedStyle == 'checkboxes'" type="checkbox" [checked]="isSelected(option)" />
<span *ngIf="settings.checkedStyle == 'glyphicon'" style="width: 16px;"
class="glyphicon" [class.glyphicon-ok]="isSelected(option)"></span>
{{ option.name }}
</a>
</li>
</ul>
</div>
`
selector: 'ss-multiselect-dropdown',
providers: [MULTISELECT_VALUE_ACCESSOR],
styles: [`
a { outline: none !important; }
`],
templateUrl: './multiselect-dropdown.html'
})
export class MultiselectDropdown implements OnInit, DoCheck, ControlValueAccessor {
@Input() options: Array<IMultiSelectOption>;
@Input() settings: IMultiSelectSettings;
@Input() texts: IMultiSelectTexts;
@Output() selectionLimitReached = new EventEmitter();
@Output() dropdownClosed = new EventEmitter();
@Input() options: Array<IMultiSelectOption>;
@Input() settings: IMultiSelectSettings;
@Input() texts: IMultiSelectTexts;
@Output() selectionLimitReached = new EventEmitter();
@Output() dropdownClosed = new EventEmitter();
@HostListener('document: click', ['$event.target'])
onClick(target: HTMLElement) {
let parentFound = false;
while (target != null && !parentFound) {
if (target === this.element.nativeElement) {
parentFound = true;
}
target = target.parentElement;
}
if (!parentFound) {
this.isVisible = false;
}
}
@HostListener('document: click', ['$event.target'])
onModelChange: Function = (_: any) => {
};
onModelTouched: Function = () => {
};
model: number[];
title: string;
differ: any;
numSelected: number = 0;
isVisible: boolean = false;
searchFilterText: string = '';
defaultSettings: IMultiSelectSettings = {
pullRight: false,
enableSearch: false,
checkedStyle: 'checkboxes',
buttonClasses: 'btn btn-default',
selectionLimit: 0,
closeOnSelect: false,
autoUnselect: false,
showCheckAll: false,
showUncheckAll: false,
dynamicTitleMaxItems: 3,
maxHeight: '300px',
};
defaultTexts: IMultiSelectTexts = {
checkAll: 'Check all',
uncheckAll: 'Uncheck all',
checked: 'checked',
checkedPlural: 'checked',
searchPlaceholder: 'Search...',
defaultTitle: 'Select',
};
model: number[];
title: string;
differ: any;
numSelected: number = 0;
isVisible: boolean = false;
searchFilterText: string = '';
defaultSettings: IMultiSelectSettings = {
pullRight: false,
enableSearch: false,
checkedStyle: 'checkboxes',
buttonClasses: 'btn btn-default',
selectionLimit: 0,
closeOnSelect: false,
autoUnselect: false,
showCheckAll: false,
showUncheckAll: false,
dynamicTitleMaxItems: 3,
maxHeight: '300px',
};
defaultTexts: IMultiSelectTexts = {
checkAll: 'Check all',
uncheckAll: 'Uncheck all',
checked: 'checked',
checkedPlural: 'checked',
searchPlaceholder: 'Search...',
defaultTitle: 'Select',
};
constructor(private element: ElementRef,
private differs: IterableDiffers) {
this.differ = differs.find([]).create(null);
}
constructor(private element: ElementRef,
private differs: IterableDiffers) {
this.differ = differs.find([]).create(null);
}
ngOnInit() {
this.settings = Object.assign(this.defaultSettings, this.settings);
this.texts = Object.assign(this.defaultTexts, this.texts);
this.title = this.texts.defaultTitle;
}
ngOnInit() {
this.settings = Object.assign(this.defaultSettings, this.settings);
this.texts = Object.assign(this.defaultTexts, this.texts);
this.title = this.texts.defaultTitle;
}
writeValue(value: any): void {
if (value !== undefined) {
this.model = value;
}
onClick(target: HTMLElement) {
let parentFound = false;
while (target != null && !parentFound) {
if (target === this.element.nativeElement) {
parentFound = true;
}
target = target.parentElement;
}
registerOnChange(fn: Function): void {
this.onModelChange = fn;
if (!parentFound) {
this.isVisible = false;
}
}
onModelChange: Function = (_: any) => { };
onModelTouched: Function = () => { };
registerOnTouched(fn: Function): void {
this.onModelTouched = fn;
}
ngDoCheck() {
let changes = this.differ.diff(this.model);
if (changes) {
this.updateNumSelected();
this.updateTitle();
}
writeValue(value: any): void {
if (value !== undefined) {
this.model = value;
}
}
clearSearch() {
this.searchFilterText = '';
}
registerOnChange(fn: Function): void {
this.onModelChange = fn;
}
toggleDropdown() {
this.isVisible = !this.isVisible;
if (!this.isVisible) {
this.dropdownClosed.emit();
}
}
registerOnTouched(fn: Function): void {
this.onModelTouched = fn;
}
isSelected(option: IMultiSelectOption): boolean {
return this.model && this.model.indexOf(option.id) > -1;
ngDoCheck() {
let changes = this.differ.diff(this.model);
if (changes) {
this.updateNumSelected();
this.updateTitle();
}
}
setSelected(event: Event, option: IMultiSelectOption) {
if (!this.model) {
this.model = [];
}
var index = this.model.indexOf(option.id);
if (index > -1) {
this.model.splice(index, 1);
} else {
if (this.settings.selectionLimit === 0 || this.model.length < this.settings.selectionLimit) {
this.model.push(option.id);
} else {
if (this.settings.autoUnselect) {
this.model.push(option.id);
this.model.shift();
} else {
this.selectionLimitReached.emit(this.model.length);
return;
}
}
}
if (this.settings.closeOnSelect) {
this.toggleDropdown();
}
this.onModelChange(this.model);
clearSearch() {
this.searchFilterText = '';
}
toggleDropdown() {
this.isVisible = !this.isVisible;
if (!this.isVisible) {
this.dropdownClosed.emit();
}
}
updateNumSelected() {
this.numSelected = this.model && this.model.length || 0;
isSelected(option: IMultiSelectOption): boolean {
return this.model && this.model.indexOf(option.id) > -1;
}
setSelected(event: Event, option: IMultiSelectOption) {
if (!this.model) {
this.model = [];
}
updateTitle() {
if (this.numSelected === 0) {
this.title = this.texts.defaultTitle;
} else if (this.settings.dynamicTitleMaxItems >= this.numSelected) {
this.title = this.options
.filter((option: IMultiSelectOption) => this.model && this.model.indexOf(option.id) > -1)
.map((option: IMultiSelectOption) => option.name)
.join(', ');
let index = this.model.indexOf(option.id);
if (index > -1) {
this.model.splice(index, 1);
} else {
if (this.settings.selectionLimit === 0 || this.model.length < this.settings.selectionLimit) {
this.model.push(option.id);
} else {
if (this.settings.autoUnselect) {
this.model.push(option.id);
this.model.shift();
} else {
this.title = this.numSelected + ' ' + (this.numSelected === 1 ? this.texts.checked : this.texts.checkedPlural);
this.selectionLimitReached.emit(this.model.length);
return;
}
}
}
if (this.settings.closeOnSelect) {
this.toggleDropdown();
}
this.onModelChange(this.model);
}
checkAll() {
this.model = this.options.map(option => option.id);
this.onModelChange(this.model);
updateNumSelected() {
this.numSelected = this.model && this.model.length || 0;
}
updateTitle() {
if (this.numSelected === 0) {
this.title = this.texts.defaultTitle;
} else if (this.settings.dynamicTitleMaxItems >= this.numSelected) {
this.title = this.options
.filter((option: IMultiSelectOption) =>
this.model && this.model.indexOf(option.id) > -1
)
.map((option: IMultiSelectOption) => option.name)
.join(', ');
} else {
this.title = this.numSelected
+ ' '
+ (this.numSelected === 1 ? this.texts.checked : this.texts.checkedPlural);
}
}
uncheckAll() {
this.model = [];
this.onModelChange(this.model);
}
checkAll() {
this.model = this.options.map(option => option.id);
this.onModelChange(this.model);
}
uncheckAll() {
this.model = [];
this.onModelChange(this.model);
}
}
@NgModule({
imports: [CommonModule, FormsModule],
exports: [MultiselectDropdown],
declarations: [MultiselectDropdown, MultiSelectSearchFilter],
imports: [CommonModule, FormsModule],
exports: [MultiselectDropdown],
declarations: [MultiselectDropdown, MultiSelectSearchFilter],
})
export class MultiselectDropdownModule {
}
export class MultiselectDropdownModule {}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc