Skip to content

Commit 96ae643

Browse files
committed
initial work to support geodash
Document Fixes: * twitter#1498 * twitter#1555 Grunt Fixes: * twitter#1465 Improvements: * show all suggestions when query is empty string * `dataType` option for `prefetch` and `remote` to support `xml` based sources, such as WMS GetCapabilities. Used with `transform` function to convert to typeahead compatible json. Changes: * Runs `trie` search on results from remote and prefetch, instead of just displaying all results. * passes url to transform function, so it can be used in search index if needed.
1 parent 588440f commit 96ae643

File tree

14 files changed

+195
-113
lines changed

14 files changed

+195
-113
lines changed

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ module.exports = function(grunt) {
145145
},
146146
typeahead: {
147147
src: '<%= tempDir %>/typeahead.jquery.js',
148-
amdModuleId: 'typeahead.js',
148+
amdModuleId: 'typeahead',
149149
deps: {
150150
default: ['$'],
151151
amd: ['jquery'],

README.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
[![build status](https://secure.travis-ci.org/twitter/typeahead.js.svg?branch=master)](http://travis-ci.org/twitter/typeahead.js)
1+
[![build status](https://secure.travis-ci.org/twitter/typeahead.js.svg?branch=master)](https://travis-ci.org/twitter/typeahead.js)
22
[![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/)
33

44

55
[typeahead.js][gh-page]
66
=======================
77

8-
Inspired by [twitter.com]'s autocomplete search functionality, typeahead.js is
9-
a flexible JavaScript library that provides a strong foundation for building
8+
Inspired by [twitter.com]'s autocomplete search functionality, typeahead.js is
9+
a flexible JavaScript library that provides a strong foundation for building
1010
robust typeaheads.
1111

12-
The typeahead.js library consists of 2 components: the suggestion engine,
13-
[Bloodhound], and the UI view, [Typeahead].
14-
The suggestion engine is responsible for computing suggestions for a given
15-
query. The UI view is responsible for rendering suggestions and handling DOM
16-
interactions. Both components can be used separately, but when used together,
12+
The typeahead.js library consists of 2 components: the suggestion engine,
13+
[Bloodhound], and the UI view, [Typeahead].
14+
The suggestion engine is responsible for computing suggestions for a given
15+
query. The UI view is responsible for rendering suggestions and handling DOM
16+
interactions. Both components can be used separately, but when used together,
1717
they can provide a rich typeahead experience.
1818

1919
<!-- section links -->
2020

21-
[gh-page]: http://twitter.github.io/typeahead.js/
21+
[gh-page]: https://twitter.github.io/typeahead.js/
2222
[twitter.com]: https://twitter.com
2323
[Bloodhound]: https://github.com/twitter/typeahead.js/blob/master/doc/bloodhound.md
2424
[Typeahead]: https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md
@@ -39,20 +39,20 @@ Other methods:
3939
* *[typeahead.bundle.js]* (*bloodhound.js* + *typeahead.jquery.js*)
4040
* *[typeahead.bundle.min.js]*
4141

42-
**Note:** both *bloodhound.js* and *typeahead.jquery.js* have a dependency on
42+
**Note:** both *bloodhound.js* and *typeahead.jquery.js* have a dependency on
4343
[jQuery] 1.9+.
4444

4545
<!-- section links -->
4646

47-
[Bower]: http://bower.io/
48-
[zipball]: http://twitter.github.com/typeahead.js/releases/latest/typeahead.js.zip
49-
[bloodhound.js]: http://twitter.github.com/typeahead.js/releases/latest/bloodhound.js
50-
[typeahead.jquery.js]: http://twitter.github.com/typeahead.js/releases/latest/typeahead.jquery.js
51-
[typeahead.bundle.js]: http://twitter.github.com/typeahead.js/releases/latest/typeahead.bundle.js
52-
[typeahead.bundle.min.js]: http://twitter.github.com/typeahead.js/releases/latest/typeahead.bundle.min.js
53-
[jQuery]: http://jquery.com/
47+
[Bower]: https://bower.io/
48+
[zipball]: https://twitter.github.com/typeahead.js/releases/latest/typeahead.js.zip
49+
[bloodhound.js]: https://twitter.github.com/typeahead.js/releases/latest/bloodhound.js
50+
[typeahead.jquery.js]: https://twitter.github.com/typeahead.js/releases/latest/typeahead.jquery.js
51+
[typeahead.bundle.js]: https://twitter.github.com/typeahead.js/releases/latest/typeahead.bundle.js
52+
[typeahead.bundle.min.js]: https://twitter.github.com/typeahead.js/releases/latest/typeahead.bundle.min.js
53+
[jQuery]: https://jquery.com/
5454

55-
Documentation
55+
Documentation
5656
-------------
5757

5858
* [Typeahead Docs]
@@ -68,7 +68,7 @@ For some working examples of typeahead.js, visit the [examples page].
6868

6969
<!-- section links -->
7070

71-
[examples page]: http://twitter.github.io/typeahead.js/examples
71+
[examples page]: https://twitter.github.io/typeahead.js/examples
7272

7373
Browser Support
7474
---------------
@@ -86,14 +86,14 @@ Customer Support
8686

8787
For general questions about typeahead.js, tweet at [@typeahead].
8888

89-
For technical questions, you should post a question on [Stack Overflow] and tag
89+
For technical questions, you should post a question on [Stack Overflow] and tag
9090
it with [typeahead.js][so tag].
9191

9292
<!-- section links -->
9393

94-
[Stack Overflow]: http://stackoverflow.com/
94+
[Stack Overflow]: https://stackoverflow.com/
9595
[@typeahead]: https://twitter.com/typeahead
96-
[so tag]: http://stackoverflow.com/questions/tagged/typeahead.js
96+
[so tag]: https://stackoverflow.com/questions/tagged/typeahead.js
9797

9898
Issues
9999
------
@@ -105,7 +105,7 @@ https://github.com/twitter/typeahead.js/issues
105105
Versioning
106106
----------
107107

108-
For transparency and insight into our release cycle, releases will be numbered
108+
For transparency and insight into our release cycle, releases will be numbered
109109
with the following format:
110110

111111
`<major>.<minor>.<patch>`
@@ -126,27 +126,27 @@ the test suite with PhantomJS, run `$ npm test`.
126126

127127
<!-- section links -->
128128

129-
[Jasmine]: http://jasmine.github.io/
130-
[Karma]: http://karma-runner.github.io/
129+
[Jasmine]: https://jasmine.github.io/
130+
[Karma]: https://karma-runner.github.io/
131131

132132
Developers
133133
----------
134134

135-
If you plan on contributing to typeahead.js, be sure to read the
135+
If you plan on contributing to typeahead.js, be sure to read the
136136
[contributing guidelines]. A good starting place for new contributors are issues
137-
labeled with [entry-level]. Entry-level issues tend to require minor changes
137+
labeled with [entry-level]. Entry-level issues tend to require minor changes
138138
and provide developers a chance to get more familiar with typeahead.js before
139139
taking on more challenging work.
140140

141-
In order to build and test typeahead.js, you'll need to install its dev
142-
dependencies (`$ npm install`) and have [grunt-cli]
143-
installed (`$ npm install -g grunt-cli`). Below is an overview of the available
141+
In order to build and test typeahead.js, you'll need to install its dev
142+
dependencies (`$ npm install`) and have [grunt-cli]
143+
installed (`$ npm install -g grunt-cli`). Below is an overview of the available
144144
Grunt tasks that'll be useful in development.
145145

146146
* `grunt build` – Builds *typeahead.js* from source.
147147
* `grunt lint` – Runs source and test files through JSHint.
148148
* `grunt watch` – Rebuilds *typeahead.js* whenever a source file is modified.
149-
* `grunt server` – Serves files from the root of typeahead.js on localhost:8888.
149+
* `grunt server` – Serves files from the root of typeahead.js on localhost:8888.
150150
Useful for using *test/playground.html* for debugging/testing.
151151
* `grunt dev` – Runs `grunt watch` and `grunt server` in parallel.
152152

@@ -159,25 +159,25 @@ Grunt tasks that'll be useful in development.
159159
Maintainers
160160
-----------
161161

162-
* **Jake Harding**
163-
* [@JakeHarding](https://twitter.com/JakeHarding)
162+
* **Jake Harding**
163+
* [@JakeHarding](https://twitter.com/JakeHarding)
164164
* [GitHub](https://github.com/jharding)
165165

166166
* **You?**
167167

168168
Authors
169169
-------
170170

171-
* **Jake Harding**
172-
* [@JakeHarding](https://twitter.com/JakeHarding)
171+
* **Jake Harding**
172+
* [@JakeHarding](https://twitter.com/JakeHarding)
173173
* [GitHub](https://github.com/jharding)
174174

175175
* **Veljko Skarich**
176-
* [@vskarich](https://twitter.com/vskarich)
176+
* [@vskarich](https://twitter.com/vskarich)
177177
* [GitHub](https://github.com/vskarich)
178178

179179
* **Tim Trueman**
180-
* [@timtrueman](https://twitter.com/timtrueman)
180+
* [@timtrueman](https://twitter.com/timtrueman)
181181
* [GitHub](https://github.com/timtrueman)
182182

183183
License

dist/bloodhound.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* typeahead.js 0.11.1
33
* https://github.com/twitter/typeahead.js
4-
* Copyright 2013-2015 Twitter, Inc. and other contributors; Licensed MIT
4+
* Copyright 2013-2016 Twitter, Inc. and other contributors; Licensed MIT
55
*/
66

77
(function(root, factory) {
@@ -552,6 +552,7 @@
552552
};
553553
function Prefetch(o) {
554554
this.url = o.url;
555+
this.dataType = o.dataType;
555556
this.ttl = o.ttl;
556557
this.cache = o.cache;
557558
this.prepare = o.prepare;
@@ -565,13 +566,14 @@
565566
return {
566567
url: this.url,
567568
type: "GET",
568-
dataType: "json"
569+
dataType: this.dataType || "json"
569570
};
570571
},
571572
store: function store(data) {
572573
if (!this.cache) {
573574
return;
574575
}
576+
this.storage.clear();
575577
this.storage.set(keys.data, data, this.ttl);
576578
this.storage.set(keys.protocol, location.protocol, this.ttl);
577579
this.storage.set(keys.thumbprint, this.thumbprint, this.ttl);
@@ -598,7 +600,7 @@
598600
cb(true);
599601
}
600602
function onResponse(resp) {
601-
cb(null, that.transform(resp));
603+
cb(null, that.transform(resp, that.url));
602604
}
603605
},
604606
clear: function clear() {
@@ -612,6 +614,7 @@
612614
"use strict";
613615
function Remote(o) {
614616
this.url = o.url;
617+
this.dataType = o.dataType;
615618
this.prepare = o.prepare;
616619
this.transform = o.transform;
617620
this.transport = new Transport({
@@ -625,7 +628,7 @@
625628
return {
626629
url: this.url,
627630
type: "GET",
628-
dataType: "json"
631+
dataType: this.dataType || "json"
629632
};
630633
},
631634
get: function get(query, cb) {
@@ -637,7 +640,7 @@
637640
settings = this.prepare(query, this._settings());
638641
return this.transport.get(settings, onResponse);
639642
function onResponse(err, resp) {
640-
err ? cb([]) : cb(that.transform(resp));
643+
err ? cb([]) : cb(that.transform(resp, that.url));
641644
}
642645
},
643646
cancelLastRequest: function cancelLastRequest() {
@@ -848,6 +851,7 @@
848851
if (err) {
849852
return deferred.reject();
850853
}
854+
that.clear();
851855
that.add(data);
852856
that.prefetch.store(that.index.serialize());
853857
deferred.resolve();
@@ -875,7 +879,10 @@
875879
},
876880
search: function search(query, sync, async) {
877881
var that = this, local;
878-
local = this.sorter(this.index.search(query));
882+
var q2 = query;
883+
local = query == "" ? $.map(this.sorter(this.index.datums), function(d, i) {
884+
return d;
885+
}) : this.sorter(this.index.search(query));
879886
sync(this.remote ? local.slice() : local);
880887
if (this.remote && local.length < this.sufficient) {
881888
this.remote.get(query, processRemote);
@@ -890,6 +897,16 @@
890897
return that.identify(r) === that.identify(l);
891898
}) && nonDuplicates.push(r);
892899
});
900+
that.clear();
901+
if (q2 == "") {
902+
nonDuplicates = $.map(that.sorter(that.index.datums), function(d, i) {
903+
return d;
904+
});
905+
that.add(nonDuplicates);
906+
} else {
907+
that.add(nonDuplicates);
908+
nonDuplicates = that.sorter(that.index.search(q2));
909+
}
893910
async && async(nonDuplicates);
894911
}
895912
},

0 commit comments

Comments
 (0)