Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ validation-status.json
bower_components
node_modules

# yarn.lock
# yarn.lock
/package-lock.json
13 changes: 13 additions & 0 deletions .run/CLEAN.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="CLEAN" type="js.build_tools.gulp">
<node-interpreter>project</node-interpreter>
<node-options />
<gulpfile>$PROJECT_DIR$/gulpfile.js</gulpfile>
<tasks>
<task>clean</task>
</tasks>
<arguments />
<envs />
<method v="2" />
</configuration>
</component>
11 changes: 11 additions & 0 deletions .run/RELEASE.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="RELEASE" type="js.build_tools.gulp">
<node-interpreter>project</node-interpreter>
<node-options />
<gulpfile>$PROJECT_DIR$/gulpfile.js</gulpfile>
<tasks />
<arguments>release</arguments>
<envs />
<method v="2" />
</configuration>
</component>
2 changes: 1 addition & 1 deletion dist/latest/bootstrap-autocomplete.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/latest/bootstrap-autocomplete.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,4 @@ exports.default = help;
exports.monitor = monitor;
exports.release = release;
exports.test = test;
exports.clean = cleanDist;
25 changes: 14 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bootstrap-autocomplete",
"version": "2.3.7",
"version": "2.3.8",
"description": "Autocomplete for Bootstrap version 4.",
"keywords": [
"bootstrap",
Expand All @@ -21,22 +21,25 @@
"test": "gulp test"
},
"devDependencies": {
"@types/bootstrap": "^4.2.1",
"@types/bootstrap": "^4.6.6",
"@types/jquery": "^3.3.29",
"ansi-colors": "^4.1.1",
"browser-sync": "^2.26.3",
"del": "^6.0.0",
"fancy-log": "^1.3.3",
"gulp": "^4.0.0",
"browser-sync": "^3.0.2",
"del": "^4.1.1",
"fancy-log": "^2.0.0",
"gulp": "^4.0.2",
"gulp-plumber": "^1.2.1",
"gulp-rename": "^2.0.0",
"gulp-size": "^3.0.0",
"gulp-size": "^4.0.1",
"gulp-tslint": "^8.1.4",
"gulp-uglify": "^3.0.1",
"ts-loader": "^8.0.11",
"ts-loader": "^9.5.1",
"tslint": "^6.1.0",
"typescript": "^4.0.5",
"webpack-stream": "^6.1.0"
"typescript": "^5.5.4",
"webpack": "^5.94.0",
"webpack-stream": "^7.0.0"
},
"dependencies": {}
"dependencies": {
"npm-check": "^6.0.1"
}
}
136 changes: 68 additions & 68 deletions src/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,89 +1,89 @@
export class BaseResolver {
protected results: any[];
protected results: any[];

protected _settings: any;
protected _settings: any;

constructor(options: any) {
this._settings = $.extend(true, {}, this.getDefaults(), options);
}
constructor(options: any) {
this._settings = $.extend(true, {}, this.getDefaults(), options);
}

protected getDefaults(): {} {
return {};
}
protected getDefaults(): {} {
return {};
}

protected getResults(limit?: number, start?: number, end?: number): any[] {
protected getResults(limit?: number, start?: number, end?: number): any[] {

return this.results;
}
return this.results;
}

public search(q: string, cbk: (results: any[]) => void): void {
cbk(this.getResults());
}
public search(q: string, cbk: (results: any[]) => void): void {
cbk(this.getResults());
}

}

// tslint:disable-next-line: max-classes-per-file
export class AjaxResolver extends BaseResolver {
protected jqXHR: JQueryXHR;
protected requestTID: number;

constructor(options: any) {
super(options);

// console.log('resolver settings', this._settings);
}

protected getDefaults(): {} {
return {
url: '',
method: 'get',
queryKey: 'q',
extraData: {},
timeout: undefined,
requestThrottling: 500
};
}

public search(q: string, cbk: (results: any[]) => void): void {
if (this.jqXHR != null) {
this.jqXHR.abort();
}
protected jqXHR: JQueryXHR;
protected requestTID: number;

const data: {
[key: string]: any
} = {};
data[this._settings.queryKey] = q;
$.extend(data, this._settings.extraData);
constructor(options: any) {
super(options);

// request throttling
if (this.requestTID) {
window.clearTimeout(this.requestTID);
// console.log('resolver settings', this._settings);
}
this.requestTID = window.setTimeout(() => {
this.jqXHR = $.ajax(
this._settings.url,
{
method: this._settings.method,
data,
timeout: this._settings.timeout
}
);

this.jqXHR.done((result) => {
cbk(result);
});
protected getDefaults(): {} {
return {
url: '',
method: 'get',
queryKey: 'q',
extraData: {},
timeout: undefined,
requestThrottling: 500
};
}

this.jqXHR.fail((err) => {
// console.log(err);
// this._settings.fail && this._settings.fail(err);
this._settings?.fail(err);
});
public search(q: string, cbk: (results: any[]) => void): void {
if (this.jqXHR != null) {
this.jqXHR.abort();
}

this.jqXHR.always(() => {
this.jqXHR = null;
});
const data: {
[key: string]: any
} = {};
data[this._settings.queryKey] = q;
$.extend(data, this._settings.extraData);

}, this._settings.requestThrottling);
}
// request throttling
if (this.requestTID) {
window.clearTimeout(this.requestTID);
}
this.requestTID = window.setTimeout(() => {
this.jqXHR = $.ajax(
this._settings.url,
{
method: this._settings.method,
data,
timeout: this._settings.timeout
}
);

this.jqXHR.done((result) => {
cbk(result);
});

this.jqXHR.fail((err) => {
if (this._settings?.fail === undefined)
console.error(err);
this._settings?.fail?.(err);
});

this.jqXHR.always(() => {
this.jqXHR = null;
});

}, this._settings.requestThrottling);
}

}
4 changes: 3 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"tslint:recommended"
],
"jsRules": {},
"rules": {},
"rules": {
"no-console": false //Disable for typescript
},
"rulesDirectory": []
}
Loading