├── screenshots └── highlight.png ├── bower.json ├── .jshintrc ├── .jscs.json ├── package.json ├── LICENSE ├── Gruntfile.js ├── README.md ├── README.ru.md ├── dist ├── jquery.lookingfor.min.js ├── jquery.lookingfor.min.map └── jquery.lookingfor.js ├── html ├── simple.html ├── highlight.html └── data │ └── countries.csv └── src └── jquery.lookingfor.js /screenshots/highlight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/albburtsev/jquery.lookingfor/HEAD/screenshots/highlight.png -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery.lookingfor", 3 | "version": "0.0.8", 4 | "main": ["jquery.lookingfor.js"], 5 | "ignore": [ 6 | "Gruntfile.js", 7 | "package.json", 8 | ".jscs.json", 9 | ".jshintrc", 10 | "screenshots", 11 | "html" 12 | ], 13 | "dependencies": { 14 | "jquery": ">=1.7" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "bitwise": true, 4 | "browser": true, 5 | "eqeqeq": true, 6 | "camelcase": true, 7 | "curly": true, 8 | "debug": true, 9 | "forin": true, 10 | "freeze": true, 11 | "immed": true, 12 | "latedef": true, 13 | "maxdepth": 3, 14 | "maxparams": 3, 15 | "newcap": true, 16 | "noarg": true, 17 | "noempty": true, 18 | "nonbsp": true, 19 | "quotmark": "single", 20 | "undef": true, 21 | "unused": true, 22 | "predef": [ 23 | "define", 24 | "jQuery" 25 | ] 26 | } -------------------------------------------------------------------------------- /.jscs.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "requireCurlyBraces": ["for", "while", "do", "if", "else"], 4 | "requireSpaceAfterKeywords": ["if", "for", "while", "do", "switch", "return"], 5 | "disallowSpacesInsideArrayBrackets": true, 6 | "requireSpacesInsideObjectBrackets": "all", 7 | "disallowQuotedKeysInObjects": true, 8 | "disallowSpaceAfterObjectKeys": true, 9 | "disallowLeftStickedOperators": ["?", "+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], 10 | "requireRightStickedOperators": ["!"], 11 | "disallowRightStickedOperators": ["?", "+", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], 12 | "requireLeftStickedOperators": [","], 13 | "disallowKeywords": ["with", "eval"], 14 | "validateJSDoc": { 15 | "checkParamNames": true, 16 | "checkRedundantParams": true, 17 | "requireParamTypes": true 18 | } 19 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery.lookingfor", 3 | "version": "0.0.8", 4 | "description": "Fast search as you type jQuery-plugin", 5 | "repository": { 6 | "type": "git", 7 | "url": "git://github.com/albburtsev/jquery.lookingfor.git" 8 | }, 9 | "keywords": [ 10 | "jquery", 11 | "plugin", 12 | "search", 13 | "highlight", 14 | "client search", 15 | "page search" 16 | ], 17 | "author": { 18 | "name": "Alexander Burtsev", 19 | "url": "https://github.com/albburtsev" 20 | }, 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/albburtsev/jquery.lookingfor/issues" 24 | }, 25 | "homepage": "https://github.com/albburtsev/jquery.lookingfor", 26 | "devDependencies": { 27 | "grunt": "^0.4.4", 28 | "grunt-contrib-copy": "^0.8.0", 29 | "grunt-contrib-jshint": "^0.10.0", 30 | "grunt-contrib-uglify": "^0.4.0", 31 | "grunt-contrib-watch": "^0.6.1", 32 | "grunt-jscs-checker": "^0.4.1", 33 | "matchdep": "^0.3.0" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Alexander Burtsev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function(grunt) { 2 | 'use strict'; 3 | 4 | require('matchdep') 5 | .filterDev('grunt-*') 6 | .forEach(grunt.loadNpmTasks); 7 | 8 | grunt.initConfig({ 9 | jsSource: 'src/*.js', 10 | jsDist: 'dist/', 11 | banner: 12 | '/**\n' + 13 | ' * jquery.lookingfor — fast search as you type\n' + 14 | ' * @author Alexander Burtsev, http://burtsev.me, 2014—<%= grunt.template.today("yyyy") %>\n' + 15 | ' * @license MIT\n' + 16 | ' */\n', 17 | 18 | jshint: { 19 | options: { 20 | jshintrc: '.jshintrc' 21 | }, 22 | app: ['<%= jsSource %>'] 23 | }, 24 | 25 | jscs: { 26 | options: { 27 | config: '.jscs.json' 28 | }, 29 | app: ['<%= jsSource %>'] 30 | }, 31 | 32 | copy: { 33 | options: { 34 | process: function (content, srcpath) { 35 | return grunt.config.get('banner') + content; 36 | } 37 | }, 38 | source: { 39 | files: [{ 40 | expand: true, 41 | cwd: 'src/', 42 | src: ['**'], 43 | dest: 'dist/' 44 | }] 45 | } 46 | }, 47 | 48 | uglify: { 49 | options: { 50 | banner: '<%= banner %>', 51 | sourceMap: true 52 | }, 53 | lookingfor: { 54 | files: { 55 | '<%= jsDist %>jquery.lookingfor.min.js': ['<%= jsSource %>'] 56 | } 57 | } 58 | }, 59 | 60 | watch: { 61 | lookingfor: { 62 | files: ['<%= jsSource %>'], 63 | tasks: ['jshint', 'jscs', 'uglify'] 64 | } 65 | } 66 | }); 67 | 68 | grunt.registerTask('default', ['jshint', 'jscs', 'copy', 'uglify', 'watch']); 69 | }; 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | jquery.lookingfor 2 | ================= 3 | 4 | ![Screenshot](https://rawgithub.com/albburtsev/jquery.lookingfor/master/screenshots/highlight.png) 5 | 6 | Fast search as you type jQuery plugin. 7 | 8 | It's very small (minified — 2.5kb, gzipped — 1.2kb), very fast and supports old browsers (IE6+). 9 | 10 | __jquery.lookingfor__ plugin searches text in list items (```
  • ```) and hides unmatched items. 11 | It works not only for `
  • `s, but for any HTML element on a page. 12 | Any input field (```input, textarea```) can be transformed to search filter with __jquery.lookingfor__. 13 | 14 | [Live demo](http://albburtsev.github.io/jquery.lookingfor/) 15 | 16 | ## Install 17 | 18 | Download latest [release](https://github.com/albburtsev/jquery.lookingfor/releases). 19 | Use [minified](https://github.com/albburtsev/jquery.lookingfor/blob/master/jquery.lookingfor.min.js) 20 | or [development](https://github.com/albburtsev/jquery.lookingfor/blob/master/jquery.lookingfor.js) version. 21 | 22 | Or use [bower](http://bower.io/) for install: 23 | 24 | ``` 25 | bower install jquery.lookingfor --save 26 | ``` 27 | 28 | ## Usage 29 | 30 | Include [jQuery](http://jquery.com) and __jquery.lookingfor__ on your page: 31 | 32 | ```html 33 | 34 | 35 | ``` 36 | 37 | Prepare list of items for following search and an input field (optional): 38 | 39 | ```html 40 | 41 | 47 | ``` 48 | 49 | Call ```lookingfor()``` method with necessary options: 50 | 51 | ```js 52 | jQuery(function($) { 53 | $('#numerals').lookingfor({ 54 | input: $('input[name="query"]'), 55 | items: 'li' 56 | }); 57 | }); 58 | ``` 59 | 60 | ### Options 61 | 62 | All options are optional. 63 | 64 | * __input__ — input field's selector; 65 | * __items__ — item's selector, default – ```'li'```; 66 | * __highlight__ — set ```true``` to highlight matched text, default — ```false```; 67 | * __highlightColor__ — ```#RRGGBB``` background color for matched text, default – ```#FFDE00```; 68 | * __onFound {Function(HTMLElement item, String query)}__ — callback, will be called when text is found. 69 | -------------------------------------------------------------------------------- /README.ru.md: -------------------------------------------------------------------------------- 1 | jquery.lookingfor 2 | ================= 3 | 4 | ![Screenshot](https://rawgithub.com/albburtsev/jquery.lookingfor/master/screenshots/highlight.png) 5 | 6 | Быстрый поиск набираемого текста. 7 | 8 | Плагин очень маленький (минифицированный — 2.5kb, сжатый — 1.2kb), очень быстрый и даже поддерживает старые браузеры (IE6+). 9 | 10 | Плагин __jquery.lookingfor__ ищет текст в элементах списков (```
  • ```) и скрывает те элементы, для которых не найдено совпадений. 11 | Он работает не только со списками, но и с любыми другими элементами на странице, содержащими текст. 12 | Любое текстовое поле (```input, textarea```) можно сделать поисковым фильтром с помощью __jquery.lookingfor__. 13 | 14 | [Демо](http://albburtsev.github.io/jquery.lookingfor/) 15 | 16 | ## Установка 17 | 18 | Скачайте последний [релиз](https://github.com/albburtsev/jquery.lookingfor/releases) 19 | и подключите на страницу [минифицированную](https://github.com/albburtsev/jquery.lookingfor/blob/master/jquery.lookingfor.min.js) 20 | или [полную](https://github.com/albburtsev/jquery.lookingfor/blob/master/jquery.lookingfor.js) версию плагина. 21 | 22 | Или установите с помощью [bower](http://bower.io/) 23 | 24 | ``` 25 | bower install jquery.lookingfor --save 26 | ``` 27 | 28 | ## Быстрый старт 29 | 30 | Подключите [jQuery](http://jquery.com) и __jquery.lookingfor__ на свою страницу: 31 | 32 | ```html 33 | 34 | 35 | ``` 36 | 37 | Приготовьте список элементов, содержащих текст, и поле ввода (при необходимости): 38 | 39 | ```html 40 | 41 | 47 | ``` 48 | 49 | Вызовите метод ```lookingfor()``` с необходимыми опциями для списка: 50 | 51 | ```js 52 | jQuery(function($) { 53 | $('#numerals').lookingfor({ 54 | input: $('input[name="query"]'), 55 | items: 'li' 56 | }); 57 | }); 58 | ``` 59 | 60 | ### Опции 61 | 62 | Все опции являются необязательными. 63 | 64 | * __input__ — селектор для поля ввода; 65 | * __items__ — селектор для элементов списка, по умолчанию – ```'li'```; 66 | * __highlight__ — переключите в ```true``` для подсветки найденного текста, по умолчанию — ```false```; 67 | * __highlightColor__ — ```#RRGGBB``` цвет фона для подсветки найденного текста, по умолчанию – ```#FFDE00```; 68 | * __onFound {Function(HTMLElement item, String query)}__ — колбек, вызывается при найденном совпадении. 69 | -------------------------------------------------------------------------------- /dist/jquery.lookingfor.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * jquery.lookingfor — fast search as you type 3 | * @author Alexander Burtsev, http://burtsev.me, 2014—2015 4 | * @license MIT 5 | */ 6 | 7 | !function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){"use strict";function b(b,c){a.extend(this,{_input:null,_items:null,_container:a(b),items:"li",value:"",cache:[],queryCharLimit:1,queryTimer:null,queryDelay:100,highlight:!1,highlightClass:"lfitem_match",highlightColor:"#ffde00",hiddenListClass:"lflist_hidden",hiddenItemAttr:"data-lfhidden",hiddenCount:0,onFound:null},c||{}),this._items=a(this.items,b),this._input=a(this.input),this._items.length&&(this._input.length&&this._input.on("keyup change",this._debounce(function(){var b=(this._input.val()||"").toLowerCase();b=a.trim(b),b!==this.value&&(this.value=b,b.length>=this.queryCharLimit?this.query():this.showAll())},this.queryDelay,this)),this.addStyles(),this.indexing())}a.fn.lookingfor=function(a){return this.each(function(){new b(this,a)})},b.prototype={addStyles:function(){var b,c=a("head"),d=a(" 37 | 38 | 39 |
    40 |

    Countries ()

    41 | 42 |
    43 |
    44 |
    45 | 46 |
    $('ul').lookingfor({ input: 'input' });
    47 | 
    48 | 49 | 50 |
    51 |
    52 |
    53 | 54 | 55 |
    56 | 57 | 58 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /html/highlight.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | jQuery.lookingfor demo page 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 35 | 41 | 42 | 43 |
    44 |

    Countries ()

    45 | 46 |
    47 |
    48 |
    49 | 50 |
    $('ul').lookingfor({
    51 | 	input: $('input'),
    52 | 	items: 'li',
    53 | 	highlight: true
    54 | });
    55 | 
    56 | 57 | 58 |
    59 |
    60 |
    61 | 62 | 63 |
    64 | 65 | 66 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /dist/jquery.lookingfor.min.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"jquery.lookingfor.min.js","sources":["../src/jquery.lookingfor.js"],"names":["factory","define","amd","jQuery","$","Lookingfor","container","opts","extend","this","_input","_items","_container","items","value","cache","queryCharLimit","queryTimer","queryDelay","highlight","highlightClass","highlightColor","hiddenListClass","hiddenItemAttr","hiddenCount","onFound","input","length","on","_debounce","val","toLowerCase","trim","query","showAll","addStyles","indexing","fn","lookingfor","each","prototype","sheet","_head","style","get","styles","append","document","styleSheets","selector","rules","i","insertRule","addRule","self","_item","push","node","html","innerHTML","text","hidden","item","re","RegExp","paint","proxy","_paint","indexOf","setAttribute","removeAttribute","matched","replace","addClass","removeClass","$0","delay","context","timer","args","arguments","clearTimeout","setTimeout","apply"],"mappings":";;;;;;CAAC,SAASA,GACc,kBAAXC,SAAyBA,OAAOC,IAC3CD,QAAQ,UAAWD,GAEnBA,EAAQG,SAER,SAASC,GACV,YAuBA,SAASC,GAAWC,EAAWC,GAC9BH,EAAEI,OAAOC,MACRC,OAAQ,KACRC,OAAQ,KACRC,WAAYR,EAAEE,GAEdO,MAAO,KACPC,MAAO,GACPC,SACAC,eAAgB,EAChBC,WAAY,KACZC,WAAY,IAEZC,WAAW,EACXC,eAAgB,eAChBC,eAAgB,UAEhBC,gBAAiB,gBACjBC,eAAgB,gBAChBC,YAAa,EAEbC,QAAS,MACPlB,OAEHE,KAAKE,OAASP,EAAEK,KAAKI,MAAOP,GAC5BG,KAAK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AC9B,GAAIC,GAAQ,KACXxB,EAAO7C,IAER,OAAO,YACN,GAAIsE,GAAOC,SACXC,cAAaH,GACbA,EAAQI,WAAW,WAClB7C,EAAG8C,MAAMN,GAAWvB,EAAMyB,IACxBH"} -------------------------------------------------------------------------------- /html/data/countries.csv: -------------------------------------------------------------------------------- 1 | United States,US 2 | Afghanistan,AF 3 | Albania,AL 4 | Algeria,DZ 5 | Andorra,AD 6 | Angola,AO 7 | Antigua and Barbuda,AG 8 | Argentina,AR 9 | Armenia,AM 10 | Australia,AU 11 | Austria,AT 12 | Azerbaijan,AZ 13 | Bahamas,BS 14 | Bahrain,BH 15 | Bangladesh,BD 16 | Barbados,BB 17 | Belarus,BY 18 | Belgium,BE 19 | Belize,BZ 20 | Benin,BJ 21 | Bhutan,BT 22 | Bolivia,BO 23 | Bosnia and Herzegovina,BA 24 | Botswana,BW 25 | Brazil,BR 26 | Brunei,BN 27 | Bulgaria,BG 28 | Burkina Faso,BF 29 | Burundi,BI 30 | Cambodia,KH 31 | Cameroon,CM 32 | Canada,CA 33 | Cape Verde,CV 34 | Central African Republic,CF 35 | Chad,TD 36 | Chile,CL 37 | People's Republic of China,CN 38 | Colombia,CO 39 | Comoros,KM 40 | Congo - Kinshasa,CD 41 | Congo - Brazzaville,CG 42 | Costa Rica,CR 43 | Cote d'Ivoire (The Ivory Coast),CI 44 | Croatia,HR 45 | Cuba,CU 46 | Cyprus,CY 47 | Czech Republic,CZ 48 | Denmark,DK 49 | Djibouti,DJ 50 | Dominica,DM 51 | Dominican Republic,DO 52 | Ecuador,EC 53 | Egypt,EG 54 | El Salvador,SV 55 | Equatorial Guinea,GQ 56 | Eritrea,ER 57 | Estonia,EE 58 | Ethiopia,ET 59 | Fiji,FJ 60 | Finland,FI 61 | France,FR 62 | Gabon,GA 63 | Gambia,GM 64 | Georgia,GE 65 | Germany,DE 66 | Ghana,GH 67 | Greece,GR 68 | Grenada,GD 69 | Guatemala,GT 70 | Guinea,GN 71 | Guinea-Bissau,GW 72 | Guyana,GY 73 | Haiti,HT 74 | Honduras,HN 75 | Hungary,HU 76 | Iceland,IS 77 | India,IN 78 | Indonesia,ID 79 | Iran,IR 80 | Iraq,IQ 81 | Ireland,IE 82 | Israel,IL 83 | Italy,IT 84 | Jamaica,JM 85 | Japan,JP 86 | Jordan,JO 87 | Kazakhstan,KZ 88 | Kenya,KE 89 | Kiribati,KI 90 | North Korea,KP 91 | South Korea,KR 92 | Kuwait,KW 93 | Kyrgyzstan,KG 94 | Laos,LA 95 | Latvia,LV 96 | Lebanon,LB 97 | Lesotho,LS 98 | Liberia,LR 99 | Libya,LY 100 | Liechtenstein,LI 101 | Lithuania,LT 102 | Luxembourg,LU 103 | Macedonia,MK 104 | Madagascar,MG 105 | Malawi,MW 106 | Malaysia,MY 107 | Maldives,MV 108 | Mali,ML 109 | Malta,MT 110 | Marshall Islands,MH 111 | Mauritania,MR 112 | Mauritius,MU 113 | Mexico,MX 114 | Micronesia,FM 115 | Moldova,MD 116 | Monaco,MC 117 | Mongolia,MN 118 | Montenegro,ME 119 | Morocco,MA 120 | Mozambique,MZ 121 | Myanmar (Burma),MM 122 | Namibia,NA 123 | Nauru,NR 124 | Nepal,NP 125 | Netherlands,NL 126 | New Zealand,NZ 127 | Nicaragua,NI 128 | Niger,NE 129 | Nigeria,NG 130 | Norway,NO 131 | Oman,OM 132 | Pakistan,PK 133 | Palau,PW 134 | Panama,PA 135 | Papua New Guinea,PG 136 | Paraguay,PY 137 | Peru,PE 138 | Philippines,PH 139 | Poland,PL 140 | Portugal,PT 141 | Qatar,QA 142 | Romania,RO 143 | Russia,RU 144 | Rwanda,RW 145 | Saint Kitts and Nevis,KN 146 | Saint Lucia,LC 147 | Saint Vincent and the Grenadines,VC 148 | Samoa,WS 149 | San Marino,SM 150 | Sao Tome and Principe,ST 151 | Saudi Arabia,SA 152 | Senegal,SN 153 | Serbia,RS 154 | Seychelles,SC 155 | Sierra Leone,SL 156 | Singapore,SG 157 | Slovakia,SK 158 | Slovenia,SI 159 | Solomon Islands,SB 160 | Somalia,SO 161 | South Africa,ZA 162 | Spain,ES 163 | Sri Lanka,LK 164 | Sudan,SD 165 | Suriname,SR 166 | Swaziland,SZ 167 | Sweden,SE 168 | Switzerland,CH 169 | Syria,SY 170 | Tajikistan,TJ 171 | Tanzania,TZ 172 | Thailand,TH 173 | Timor-Leste (East Timor),TL 174 | Togo,TG 175 | Tonga,TO 176 | Trinidad and Tobago,TT 177 | Tunisia,TN 178 | Turkey,TR 179 | Turkmenistan,TM 180 | Tuvalu,TV 181 | Uganda,UG 182 | Ukraine,UA 183 | United Arab Emirates,AE 184 | United Kingdom,GB 185 | Uruguay,UY 186 | Uzbekistan,UZ 187 | Vanuatu,VU 188 | Vatican City,VA 189 | Venezuela,VE 190 | Vietnam,VN 191 | Yemen,YE 192 | Zambia,ZM 193 | Zimbabwe,ZW 194 | Abkhazia,GE 195 | Taiwan,TW 196 | Nagorno-Karabakh,AZ 197 | Northern Cyprus,CY 198 | Pridnestrovie (Transnistria),MD 199 | Somaliland,SO 200 | South Ossetia,GE 201 | Ashmore and Cartier Islands,AU 202 | Christmas Island,CX 203 | Cocos (Keeling) Islands,CC 204 | Coral Sea Islands,AU 205 | Heard Island and McDonald Islands,HM 206 | Norfolk Island,NF 207 | New Caledonia,NC 208 | French Polynesia,PF 209 | Mayotte,YT 210 | Saint Barthelemy,GP 211 | Saint Martin,GP 212 | Saint Pierre and Miquelon,PM 213 | Wallis and Futuna,WF 214 | French Southern and Antarctic Lands,TF 215 | Clipperton Island,PF 216 | Bouvet Island,BV 217 | Cook Islands,CK 218 | Niue,NU 219 | Tokelau,TK 220 | Guernsey,GG 221 | Isle of Man,IM 222 | Jersey,JE 223 | Anguilla,AI 224 | Bermuda,BM 225 | British Indian Ocean Territory,IO 226 | British Sovereign Base Areas, 227 | British Virgin Islands,VG 228 | Cayman Islands,KY 229 | Falkland Islands (Islas Malvinas),FK 230 | Gibraltar,GI 231 | Montserrat,MS 232 | Pitcairn Islands,PN 233 | Saint Helena,SH 234 | South Georgia & South Sandwich Islands,GS 235 | Turks and Caicos Islands,TC 236 | Northern Mariana Islands,MP 237 | Puerto Rico,PR 238 | American Samoa,AS 239 | Baker Island,UM 240 | Guam,GU 241 | Howland Island,UM 242 | Jarvis Island,UM 243 | Johnston Atoll,UM 244 | Kingman Reef,UM 245 | Midway Islands,UM 246 | Navassa Island,UM 247 | Palmyra Atoll,UM 248 | U.S. Virgin Islands,VI 249 | Wake Island,UM 250 | Hong Kong,HK 251 | Macau,MO 252 | Faroe Islands,FO 253 | Greenland,GL 254 | French Guiana,GF 255 | Guadeloupe,GP 256 | Martinique,MQ 257 | Reunion,RE 258 | Aland,AX 259 | Aruba,AW 260 | Netherlands Antilles,AN 261 | Svalbard,SJ 262 | Ascension,AC 263 | Tristan da Cunha,TA 264 | Australian Antarctic Territory,AQ 265 | Ross Dependency,AQ 266 | Peter I Island,AQ 267 | Queen Maud Land,AQ 268 | British Antarctic Territory,AQ -------------------------------------------------------------------------------- /src/jquery.lookingfor.js: -------------------------------------------------------------------------------- 1 | (function(factory) { 2 | if ( typeof define === 'function' && define.amd ) { 3 | define(['jquery'], factory); 4 | } else { 5 | factory(jQuery); 6 | } 7 | }(function($) { 8 | 'use strict'; 9 | 10 | $.fn.lookingfor = function(opts) { 11 | return this.each(function() { 12 | new Lookingfor(this, opts); 13 | }); 14 | }; 15 | 16 | /** 17 | * @class 18 | * @param {HTMLElement} container 19 | * @param {Object} opts 20 | * @param {String} [opts.input] Selector for input field 21 | * @param {String} [opts.items='li'] Selector for nested items 22 | * @param {Number} [opts.queryCharLimit = 1] 23 | * @param {Number} [opts.queryDelay = 100] ms 24 | * @param {Boolean} [opts.highlight=false] Highlight matched text 25 | * @param {Boolean} [opts.highlightColor='#ffde00'] Background color for matched text 26 | * @param {Function(HTMLElement item, String query)} [opts.onFound] Callback, calls when text found in element 27 | * 28 | * @todo: nested items 29 | * @todo: show/hide animation 30 | */ 31 | function Lookingfor(container, opts) { 32 | $.extend(this, { 33 | _input: null, 34 | _items: null, 35 | _container: $(container), 36 | 37 | items: 'li', 38 | value: '', 39 | cache: [], 40 | queryCharLimit: 1, 41 | queryTimer: null, 42 | queryDelay: 100, // ms 43 | 44 | highlight: false, 45 | highlightClass: 'lfitem_match', 46 | highlightColor: '#ffde00', 47 | 48 | hiddenListClass: 'lflist_hidden', 49 | hiddenItemAttr: 'data-lfhidden', 50 | hiddenCount: 0, 51 | 52 | onFound: null 53 | }, opts || {}); 54 | 55 | this._items = $(this.items, container); 56 | this._input = $(this.input); 57 | 58 | if ( !this._items.length ) { 59 | return; 60 | } 61 | 62 | if ( this._input.length ) { 63 | this._input.on('keyup change', this._debounce(function() { 64 | var value = (this._input.val() || '').toLowerCase(); 65 | value = $.trim(value); 66 | 67 | if ( value === this.value ) { 68 | return; 69 | } 70 | 71 | this.value = value; 72 | if ( value.length >= this.queryCharLimit ) { 73 | this.query(); 74 | } else { 75 | this.showAll(); 76 | } 77 | }, this.queryDelay, this)); 78 | } 79 | 80 | this.addStyles(); 81 | this.indexing(); 82 | } 83 | 84 | Lookingfor.prototype = 85 | /** @lends Lookingfor */ 86 | { 87 | /** 88 | * Generates and adds styles for hiding and highlighting items 89 | */ 90 | addStyles: function() { 91 | var _head = $('head'), 92 | style = $('