From 4bc63fdbbbd6d5ca874d405aaa266a037c675ee2 Mon Sep 17 00:00:00 2001 From: hamid_mayeli_geeksltd Date: Fri, 5 Apr 2019 11:51:25 +0100 Subject: [PATCH] Small fix --- types/jquery-typeahead/index.d.ts | 6 +- types/jquery-typeahead/tslint.json | 80 +------- types/jquery-typeahead/typeahead-tests.ts | 222 +++++++++++----------- 3 files changed, 113 insertions(+), 195 deletions(-) diff --git a/types/jquery-typeahead/index.d.ts b/types/jquery-typeahead/index.d.ts index db69bfc98b..26ec18e304 100644 --- a/types/jquery-typeahead/index.d.ts +++ b/types/jquery-typeahead/index.d.ts @@ -127,7 +127,7 @@ declare namespace RunningCoder.Typeahead { * Set `"asc"` or `"desc"` to have the group name sorted ascending or descending * Set an `Array` to specify the group order to appear in the search result */ - groupOrder?: "asc" | "desc" | string[] | ((node?: JQuery, query?: string, result?: any, resultCount?: number, resultCountPerGroup?: number) => any), + groupOrder?: "asc" | "desc" | string[] | ((node?: JQuery, query?: string, result?: any, resultCount?: number, resultCountPerGroup?: number) => any[]), /** Set a maximum results per group if `group: true` configuration is enabled */ maxItemPerGroup?: number, @@ -378,7 +378,7 @@ declare namespace RunningCoder.Typeahead { limit?: number, /** Template when the limit is reached */ - limitTemplate?: string | ((query?: string) => any), + limitTemplate?: string | ((query?: string) => string), /** Unique item identifier to remove an item from the result list when selected (use any of the item key), by default a JSON of the item will be used */ matchOn?: string | any[], @@ -387,7 +387,7 @@ declare namespace RunningCoder.Typeahead { cancelOnBackspace?: boolean, /** Href link on the multiselect item */ - href?: string | ((item?: any) => any), + href?: string | ((item?: any) => string), /** Default items when Typeahead is loade */ data?: any[] | (() => any[] | any), diff --git a/types/jquery-typeahead/tslint.json b/types/jquery-typeahead/tslint.json index a41bf5d19a..e60c15844f 100644 --- a/types/jquery-typeahead/tslint.json +++ b/types/jquery-typeahead/tslint.json @@ -1,79 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } -} + "extends": "dtslint/dt.json" +} \ No newline at end of file diff --git a/types/jquery-typeahead/typeahead-tests.ts b/types/jquery-typeahead/typeahead-tests.ts index 8399aaa56b..c3f68b0876 100644 --- a/types/jquery-typeahead/typeahead-tests.ts +++ b/types/jquery-typeahead/typeahead-tests.ts @@ -1,118 +1,112 @@ -class Tests { - method1(input: JQuery) { - input.typeahead({ - order: "desc", - source: { - data: [ - "Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda", - "Argentina", "Armenia", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", - "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", - "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei", "Bulgaria", "Burkina Faso", "Burma", - "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Central African Republic", "Chad", - "Chile", "China", "Colombia", "Comoros", "Congo, Democratic Republic", "Congo, Republic of the", - "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", - "Dominica", "Dominican Republic", "East Timor", "Ecuador", "Egypt", "El Salvador", - "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Fiji", "Finland", "France", "Gabon", - "Gambia", "Georgia", "Germany", "Ghana", "Greece", "Greenland", "Grenada", "Guatemala", "Guinea", - "Guinea-Bissau", "Guyana", "Haiti", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", - "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", - "Kazakhstan", "Kenya", "Kiribati", "Korea, North", "Korea, South", "Kuwait", "Kyrgyzstan", "Laos", - "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", - "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", - "Mauritania", "Mauritius", "Mexico", "Micronesia", "Moldova", "Mongolia", "Morocco", "Monaco", - "Mozambique", "Namibia", "Nauru", "Nepal", "Netherlands", "New Zealand", "Nicaragua", "Niger", - "Nigeria", "Norway", "Oman", "Pakistan", "Panama", "Papua New Guinea", "Paraguay", "Peru", - "Philippines", "Poland", "Portugal", "Qatar", "Romania", "Russia", "Rwanda", "Samoa", "San Marino", - "Sao Tome", "Saudi Arabia", "Senegal", "Serbia and Montenegro", "Seychelles", "Sierra Leone", - "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "Spain", - "Sri Lanka", "Sudan", "Suriname", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", - "Tajikistan", "Tanzania", "Thailand", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", - "Turkmenistan", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", - "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Yemen", "Zambia", "Zimbabwe" - ] - }, - callback: { - onInit: function (node) { - console.log('Typeahead Initiated'); - } - } - }); +let t1 = $('input').typeahead({ + order: "desc", + source: { + data: [ + "Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda", + "Argentina", "Armenia", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", + "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", + "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei", "Bulgaria", "Burkina Faso", "Burma", + "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Central African Republic", "Chad", + "Chile", "China", "Colombia", "Comoros", "Congo, Democratic Republic", "Congo, Republic of the", + "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", + "Dominica", "Dominican Republic", "East Timor", "Ecuador", "Egypt", "El Salvador", + "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Fiji", "Finland", "France", "Gabon", + "Gambia", "Georgia", "Germany", "Ghana", "Greece", "Greenland", "Grenada", "Guatemala", "Guinea", + "Guinea-Bissau", "Guyana", "Haiti", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", + "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", + "Kazakhstan", "Kenya", "Kiribati", "Korea, North", "Korea, South", "Kuwait", "Kyrgyzstan", "Laos", + "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", + "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", + "Mauritania", "Mauritius", "Mexico", "Micronesia", "Moldova", "Mongolia", "Morocco", "Monaco", + "Mozambique", "Namibia", "Nauru", "Nepal", "Netherlands", "New Zealand", "Nicaragua", "Niger", + "Nigeria", "Norway", "Oman", "Pakistan", "Panama", "Papua New Guinea", "Paraguay", "Peru", + "Philippines", "Poland", "Portugal", "Qatar", "Romania", "Russia", "Rwanda", "Samoa", "San Marino", + "Sao Tome", "Saudi Arabia", "Senegal", "Serbia and Montenegro", "Seychelles", "Sierra Leone", + "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "Spain", + "Sri Lanka", "Sudan", "Suriname", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", + "Tajikistan", "Tanzania", "Thailand", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", + "Turkmenistan", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", + "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Yemen", "Zambia", "Zimbabwe" + ] + }, + callback: { + onInit: function (node) { + console.log('Typeahead Initiated'); + } } +}); - method2() { - $.typeahead({ - input: '.js-typeahead-country_v2', - minLength: 1, - maxItem: 20, - order: "asc", - href: "https://en.wikipedia.org/?title={{display}}", - template: "{{display}} {{group}}", - source: { - country: { - ajax: { - url: "/jquerytypeahead/country_v2.json", - path: "data.country" - } - }, - capital: { - ajax: { - type: "POST", - url: "/jquerytypeahead/country_v2.json", - path: "data.capital", - data: { myKey: "myValue" } - } - } - }, - callback: { - onNavigateAfter: function (node, lis, a, item, query, event) { - if (~[38, 40].indexOf(event.keyCode)) { - var resultList = node.closest("form").find("ul.typeahead__list"), - activeLi = lis.filter("li.active"), - offsetTop = activeLi[0] && activeLi[0].offsetTop - (resultList.height() / 2) || 0; - - resultList.scrollTop(offsetTop); - } - - }, - onClickAfter: function (node, a, item, event) { - - event.preventDefault(); - - var r = confirm("You will be redirected to:\n" + item.href + "\n\nContinue?"); - if (r == true) { - window.open(item.href); - } - - $('#result-container').text(''); - - }, - onResult: function (node, query, result, resultCount) { - if (query === "") return; - - var text = ""; - if (result.length > 0 && result.length < resultCount) { - text = "Showing " + result.length + " of " + resultCount + ' elements matching "' + query + '"'; - } else if (result.length > 0) { - text = 'Showing ' + result.length + ' elements matching "' + query + '"'; - } else { - text = 'No results matching "' + query + '"'; - } - $('#result-container').html(text); - - }, - onMouseEnter: function (node, a, item, event) { - - if (item.group === "country") { - $(a).append('') - } - - }, - onMouseLeave: function (node, a, item, event) { - - $(a).find('.flag-chart').remove(); - - } +let t2 = $.typeahead({ + input: '.js-typeahead-country_v2', + minLength: 1, + maxItem: 20, + order: "asc", + href: "https://en.wikipedia.org/?title={{display}}", + template: "{{display}} {{group}}", + source: { + country: { + ajax: { + url: "/jquerytypeahead/country_v2.json", + path: "data.country" } - }); + }, + capital: { + ajax: { + type: "POST", + url: "/jquerytypeahead/country_v2.json", + path: "data.capital", + data: { myKey: "myValue" } + } + } + }, + callback: { + onNavigateAfter: function (node, lis, a, item, query, event) { + if (~[38, 40].indexOf(event.keyCode)) { + var resultList = node.closest("form").find("ul.typeahead__list"), + activeLi = lis.filter("li.active"), + offsetTop = activeLi[0] && activeLi[0].offsetTop - (resultList.height() / 2) || 0; + + resultList.scrollTop(offsetTop); + } + + }, + onClickAfter: function (node, a, item, event) { + + event.preventDefault(); + + var r = confirm("You will be redirected to:\n" + item.href + "\n\nContinue?"); + if (r == true) { + window.open(item.href); + } + + $('#result-container').text(''); + + }, + onResult: function (node, query, result, resultCount) { + if (query === "") return; + + var text = ""; + if (result.length > 0 && result.length < resultCount) { + text = "Showing " + result.length + " of " + resultCount + ' elements matching "' + query + '"'; + } else if (result.length > 0) { + text = 'Showing ' + result.length + ' elements matching "' + query + '"'; + } else { + text = 'No results matching "' + query + '"'; + } + $('#result-container').html(text); + + }, + onMouseEnter: function (node, a, item, event) { + + if (item.group === "country") { + $(a).append('') + } + + }, + onMouseLeave: function (node, a, item, event) { + + $(a).find('.flag-chart').remove(); + + } } -} +});