Permalink
Browse files

Merge https://github.com/facebook/javelin

  • Loading branch information...
hedgerwang committed Sep 10, 2012
2 parents 7519bc2 + 83aedd5 commit d2dd54245cc90fb5dc75e40c8266962a5f99de4f
Showing with 59 additions and 21 deletions.
  1. +1 −1 pkg/init.min.js
  2. +5 −1 pkg/javelin.dev.js
  3. +1 −1 pkg/javelin.min.js
  4. +50 −16 pkg/typeahead.dev.js
  5. +1 −1 pkg/typeahead.min.js
  6. +1 −1 src/lib/Resource.js
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -3928,7 +3928,11 @@ JX.install('URI', {
if (JX.Stratcom.invoke('go', null, {uri: uri}).getPrevented()) {
return;
}
- (uri && (window.location = uri)) || window.location.reload(true);
+ if (!uri) {
+ // window.location.reload clears cache in Firefox.
+ uri = window.location.pathname + (window.location.query || '');
+ }
+ window.location = uri;
}
}
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -122,6 +122,8 @@ JX.install('Typeahead', {
_placeholder : null,
_display : null,
_datasource : null,
+ _waitingListener : null,
+ _readyListener : null,
/**
* Activate your properly configured typeahead. It won't do anything until
@@ -154,19 +156,27 @@ JX.install('Typeahead', {
* draw from.
*/
setDatasource : function(datasource) {
- if (__DEV__) {
- if (this._datasource) {
- throw new Error(
- "JX.Typeahead.setDatasource(): " +
- "Typeahead already has a datasource.");
- }
+ if (this._datasource) {
+ this._datasource.unbindFromTypeahead();
+ this._waitingListener.remove();
+ this._readyListener.remove();
}
- datasource.listen('waiting', JX.bind(this, this.waitForResults));
- datasource.listen('resultsready', JX.bind(this, this.showResults));
+ this._waitingListener = datasource.listen(
+ 'waiting',
+ JX.bind(this, this.waitForResults)
+ );
+ this._readyListener = datasource.listen(
+ 'resultsready',
+ JX.bind(this, this.showResults)
+ );
datasource.bindToTypeahead(this);
this._datasource = datasource;
},
+ getDatasource : function() {
+ return this._datasource;
+ },
+
/**
* Override the <input /> selected in the constructor with some other input.
* This is primarily useful when building a control on top of the typeahead,
@@ -302,6 +312,7 @@ JX.install('Typeahead', {
*/
clear : function() {
this._control.value = '';
+ this._value = '';
this.hide();
},
@@ -630,10 +641,23 @@ JX.install('TypeaheadSource', {
_raw : null,
_lookup : null,
_excludeIDs : null,
+ _changeListener : null,
+ _startListener : null,
bindToTypeahead : function(typeahead) {
- typeahead.listen('change', JX.bind(this, this.didChange));
- typeahead.listen('start', JX.bind(this, this.didStart));
+ this._changeListener = typeahead.listen(
+ 'change',
+ JX.bind(this, this.didChange)
+ );
+ this._startListener = typeahead.listen(
+ 'start',
+ JX.bind(this, this.didStart)
+ );
+ },
+
+ unbindFromTypeahead : function() {
+ this._changeListener.remove();
+ this._startListener.remove();
},
didChange : function(value) {
@@ -664,10 +688,6 @@ JX.install('TypeaheadSource', {
addResult : function(obj) {
obj = (this.getTransformer() || this._defaultTransformer)(obj);
- if (obj && obj.id && this._excludeIDs[obj.id]) {
- return;
- }
-
if (obj.id in this._raw) {
// We're already aware of this result. This will happen if someone
// searches for "zeb" and then for "zebra" with a
@@ -699,6 +719,20 @@ JX.install('TypeaheadSource', {
return this;
},
+
+ /**
+ * Get the raw state of a result by its ID. A number of other events and
+ * mechanisms give a list of result IDs and limited additional data; if you
+ * need to act on the full result data you can look it up here.
+ *
+ * @param scalar Result ID.
+ * @return dict Corresponding raw result.
+ */
+ getResult : function(id) {
+ return this._raw[id];
+ },
+
+
matchResults : function(value) {
// This table keeps track of the number of tokens each potential match
@@ -758,7 +792,7 @@ JX.install('TypeaheadSource', {
var hits = [];
for (var k in match_count) {
- if (match_count[k] == t.length) {
+ if (match_count[k] == t.length && !this._excludeIDs[k]) {
hits.push(k);
}
}
@@ -1143,7 +1177,7 @@ JX.install('Tokenizer', {
if (this.shouldHideResultsOnChoose()) {
this._typeahead.hide();
}
- this._focus.value = '';
+ this._typeahead.clear();
this._redraw();
this.focus();
}
Oops, something went wrong.

0 comments on commit d2dd542

Please sign in to comment.