Skip to content

Commit

Permalink
Merge 21737c6 into fda1ab2
Browse files Browse the repository at this point in the history
  • Loading branch information
FranklinWhale committed Aug 10, 2018
2 parents fda1ab2 + 21737c6 commit 3e5249c
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ dist/
*.css.map
assets/css/taggle.min.css
.sass-cache
.tscache/
10 changes: 9 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,23 @@ module.exports = function(grunt) {
]
}]
}
},

ts: {
testTypes: {
tsconfig: 'types/test/tsconfig.json'
}
}
});

grunt.loadNpmTasks('grunt-ts');

// register task
grunt.registerTask('build', ['test', 'css', 'modern', 'ie9', 'ie8']);
grunt.registerTask('build-modern', ['test', 'css', 'uglify:main']);
grunt.registerTask('build-ie9', ['test', 'css', 'ie9']);
grunt.registerTask('build-ie8', ['test', 'css', 'ie8']);
grunt.registerTask('test', ['eslint', 'karma']);
grunt.registerTask('test', ['eslint', 'karma', 'ts:testTypes']);
grunt.registerTask('css', ['sass', 'postcss']);
grunt.registerTask('dev', ['watch']);

Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"grunt-mocha": "^0.4.15",
"grunt-postcss": "^0.8.0",
"grunt-sass": "^1.2.0",
"grunt-ts": "^6.0.0-beta.21",
"karma": "^0.13.22",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^0.2.3",
Expand All @@ -38,18 +39,21 @@
"mocha": "^2.4.5",
"phantomjs-prebuilt": "^2.1.6",
"sinon": "^1.17.3",
"sinon-chai": "^2.6.0"
"sinon-chai": "^2.6.0",
"typescript": "^3.0.1"
},
"bugs": {
"url": "https://github.com/okcoker/taggle.js/issues"
},
"homepage": "https://github.com/okcoker/taggle.js",
"main": "src/taggle.js",
"types": "types/taggle.d.ts",
"directories": {
"test": "test"
},
"scripts": {
"test": "grunt test"
"test": "grunt test",
"test:types": "tsc --project types/test/tsconfig.json"
},
"keywords": [
"tags",
Expand Down
99 changes: 99 additions & 0 deletions types/taggle.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
declare namespace Taggle {
interface Options {
additionalTagClasses?: string;

allowDuplicates?: boolean;

saveOnBlur?: boolean;

clearOnBlur?: boolean;

/** @deprecated */
duplicateTagClass?: string;

containerFocusClass?: string;

focusInputOnContainerClick?: boolean;

hiddenInputName?: string;

tags?: string[];

delimeter?: string;
delimiter?: string;

/** @deprecated */
attachTagId?: boolean;

allowedTags?: string[];

disallowedTags?: string[];

trimTags?: boolean;

maxTags?: number | null;

tabIndex?: number;

placeholder?: string;

submitKeys?: number[];

preserveCase?: boolean;

inputFormatter?: (input: HTMLInputElement) => HTMLInputElement;

tagFormatter?: (li: HTMLLIElement) => HTMLLIElement;

onBeforeTagAdd?: (e: Event, tag: string) => boolean;

onTagAdd?: (e: Event, tag: string) => void;

onBeforeTagRemove?: (e: Event, tag: string) => boolean;

onTagRemove?: (e: Event, tag: string) => void;
}
}

declare class Taggle {
constructor(el: string | HTMLElement, options?: Taggle.Options);

getTags(): { elements: HTMLElement[], values: string[] };

/** @deprecated */
getTagElements(): HTMLElement[];

/** @deprecated */
getTagValues(): string[];

getInput(): HTMLInputElement;

getContainer(): HTMLElement;

add(text: string | string[], index?: number): this;

edit(text: string, index: number): this;

move(currentIndex: number, destinationIndex: number): this;

remove(text: string, all?: boolean): this;

removeAll(): this;

setOptions(options: Taggle.Options): this;

enable(): this;

disable(): this;

setData(data: any): this;

getData(): any;

attachEvents(): this;

removeEvents(): this;
}

export as namespace Taggle;
export = Taggle;
77 changes: 77 additions & 0 deletions types/test/main-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const x: Taggle.Options = {
// all options are optional
};
const y: Taggle.Options = {
maxTags: null // maxTags may be null
};

new Taggle(document.getElementById("eleId")!);

const taggle = new Taggle("eleId", {
additionalTagClasses: "additionalTagClasses",
allowDuplicates: true,
saveOnBlur: true,
clearOnBlur: true,
duplicateTagClass: "duplicateTagClass",
containerFocusClass: "containerFocusClass",
focusInputOnContainerClick: true,
hiddenInputName: "hiddenInputName",
tags: ["tag1", "tag2"],
delimeter: "|",
delimiter: "|",
attachTagId: true,
allowedTags: ["tag1", "tag2"],
disallowedTags: ["tag0"],
trimTags: true,
maxTags: 10,
tabIndex: 1,
placeholder: "placeholder",
submitKeys: [13],
preserveCase: true,
inputFormatter: i => i,
tagFormatter: i => {
i.setAttribute("data-test", "test");
return i;
},
onBeforeTagAdd: (e, t) => false,
onTagAdd: (e, t) => {},
onBeforeTagRemove: (e, t) => false,
onTagRemove: (e, t) => {}
});

for (let e of taggle.getTags().elements) {
console.log(e.localName);
}

for (let v of taggle.getTags().values) {
console.log(v.length);
}

for (let e of taggle.getTagElements()) {
console.log(e.localName);
}

for (let v of taggle.getTagValues()) {
console.log(v.length);
}

taggle.getInput().name;

taggle.getContainer().localName;

taggle.getData();

taggle
.add("str")
.add(["a", "b"])
.edit("x", 0)
.move(0, 1)
.remove("tag0")
.remove("tag0", true)
.removeAll()
.setOptions(x)
.enable()
.disable()
.setData({})
.attachEvents()
.removeEvents();
4 changes: 4 additions & 0 deletions types/test/module-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as A from "taggle";

const options: A.Options = {};
new A("eleId", options);
12 changes: 12 additions & 0 deletions types/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "es3",
"strict": true,
"noImplicitReturns": true,
"noEmit": true,
"baseUrl": ".",
"paths": {
"taggle": ["../taggle.d.ts"]
}
}
}
7 changes: 7 additions & 0 deletions types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"target": "es3",
"strict": true,
"noImplicitReturns": true
}
}

0 comments on commit 3e5249c

Please sign in to comment.