Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var semver = require('semver'),
'src/typeahead/input.js',
'src/typeahead/dataset.js',
'src/typeahead/menu.js',
'src/typeahead/status.js',
'src/typeahead/default_menu.js',
'src/typeahead/typeahead.js',
'src/typeahead/plugin.js'
Expand Down Expand Up @@ -153,12 +154,25 @@ module.exports = function(grunt) {
}
},

sed: {
replace: {
version: {
pattern: '%VERSION%',
replacement: '<%= version %>',
recursive: true,
path: '<%= buildDir %>'
options: {
patterns: [
{
match: '%VERSION%',
replacement: '<%= version %>',
}
],
usePrefix: false
},
files: [
{
expand: true,
flatten: true,
src: '<%= buildDir %>/**/*.js',
dest: '<%= buildDir %>'
}
]
}
},

Expand Down Expand Up @@ -308,14 +322,14 @@ module.exports = function(grunt) {
'uglify:typeaheadMin',
'uglify:bundle',
'uglify:bundleMin',
'sed:version'
'replace:version'
]);

// load tasks
// ----------

grunt.loadNpmTasks('grunt-umd');
grunt.loadNpmTasks('grunt-sed');
grunt.loadNpmTasks('grunt-replace');
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-step');
grunt.loadNpmTasks('grunt-concurrent');
Expand Down
6 changes: 3 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"version": "1.0.1",
"main": "dist/typeahead.bundle.js",
"dependencies": {
"jquery": ">=1.7"
"jquery": ">=1.11"
},
"devDependencies": {
"jquery": "~1.7",
"jquery": "~1.11",
"jasmine-ajax": "~1.3.1",
"jasmine-jquery": "~1.7.0"
},
"resolutions": {
"jquery": "1.7.2"
"jquery": "1.11.3"
}
}
9 changes: 8 additions & 1 deletion dist/bloodhound.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
define([ "jquery" ], function(a0) {
return root["Bloodhound"] = factory(a0);
});
} else if (typeof exports === "object") {
} else if (typeof module === "object" && module.exports) {
module.exports = factory(require("jquery"));
} else {
root["Bloodhound"] = factory(root["jQuery"]);
Expand Down Expand Up @@ -148,6 +148,13 @@
stringify: function(val) {
return _.isString(val) ? val : JSON.stringify(val);
},
guid: function() {
function _p8(s) {
var p = (Math.random().toString(16) + "000000000").substr(2, 8);
return s ? "-" + p.substr(0, 4) + "-" + p.substr(4, 4) : p;
}
return "tt-" + _p8() + _p8(true) + _p8(true) + _p8();
},
noop: function() {}
};
}();
Expand Down
2 changes: 1 addition & 1 deletion dist/bloodhound.min.js

Large diffs are not rendered by default.

94 changes: 81 additions & 13 deletions dist/typeahead.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
define([ "jquery" ], function(a0) {
return root["Bloodhound"] = factory(a0);
});
} else if (typeof exports === "object") {
} else if (typeof module === "object" && module.exports) {
module.exports = factory(require("jquery"));
} else {
root["Bloodhound"] = factory(root["jQuery"]);
Expand Down Expand Up @@ -148,6 +148,13 @@
stringify: function(val) {
return _.isString(val) ? val : JSON.stringify(val);
},
guid: function() {
function _p8(s) {
var p = (Math.random().toString(16) + "000000000").substr(2, 8);
return s ? "-" + p.substr(0, 4) + "-" + p.substr(4, 4) : p;
}
return "tt-" + _p8() + _p8(true) + _p8(true) + _p8();
},
noop: function() {}
};
}();
Expand Down Expand Up @@ -949,7 +956,7 @@
define([ "jquery" ], function(a0) {
return factory(a0);
});
} else if (typeof exports === "object") {
} else if (typeof module === "object" && module.exports) {
module.exports = factory(require("jquery"));
} else {
factory(root["jQuery"]);
Expand Down Expand Up @@ -1088,6 +1095,13 @@
stringify: function(val) {
return _.isString(val) ? val : JSON.stringify(val);
},
guid: function() {
function _p8(s) {
var p = (Math.random().toString(16) + "000000000").substr(2, 8);
return s ? "-" + p.substr(0, 4) + "-" + p.substr(4, 4) : p;
}
return "tt-" + _p8() + _p8(true) + _p8(true) + _p8();
},
noop: function() {}
};
}();
Expand Down Expand Up @@ -1129,7 +1143,7 @@
function buildHtml(c) {
return {
wrapper: '<span class="' + c.wrapper + '"></span>',
menu: '<div class="' + c.menu + '"></div>'
menu: '<div role="listbox" class="' + c.menu + '"></div>'
};
}
function buildSelectors(classes) {
Expand Down Expand Up @@ -1422,13 +1436,22 @@
www.mixin(this);
this.$hint = $(o.hint);
this.$input = $(o.input);
this.$input.attr({
"aria-activedescendant": "",
"aria-owns": this.$input.attr("id") + "_listbox",
role: "combobox",
"aria-readonly": "true",
"aria-autocomplete": "list"
});
$(www.menu).attr("id", this.$input.attr("id") + "_listbox");
this.query = this.$input.val();
this.queryWhenFocused = this.hasFocus() ? this.query : null;
this.$overflowHelper = buildOverflowHelper(this.$input);
this._checkLanguageDirection();
if (this.$hint.length === 0) {
this.setHint = this.getHint = this.clearHint = this.clearHintIfInvalid = _.noop;
}
this.onSync("cursorchange", this._updateDescendent);
}
Input.normalizeQuery = function(str) {
return _.toStr(str).replace(/^\s*/g, "").replace(/\s{2,}/g, " ");
Expand Down Expand Up @@ -1498,6 +1521,9 @@
this.trigger("whitespaceChanged", this.query);
}
},
_updateDescendent: function updateDescendent(event, id) {
this.$input.attr("aria-activedescendant", id);
},
bind: function() {
var that = this, onBlur, onFocus, onKeydown, onInput;
onBlur = _.bind(this._onBlur, this);
Expand Down Expand Up @@ -1648,7 +1674,7 @@
this.source = o.source.__ttAdapter ? o.source.__ttAdapter() : o.source;
this.async = _.isUndefined(o.async) ? this.source.length > 2 : !!o.async;
this._resetLastSuggestion();
this.$el = $(o.node).addClass(this.classes.dataset).addClass(this.classes.dataset + "-" + this.name);
this.$el = $(o.node).attr("role", "presentation").addClass(this.classes.dataset).addClass(this.classes.dataset + "-" + this.name);
}
Dataset.extractData = function extractData(el) {
var $el = $(el);
Expand Down Expand Up @@ -1820,7 +1846,7 @@
suggestion: templates.suggestion || suggestionTemplate
};
function suggestionTemplate(context) {
return $("<div>").text(displayFn(context));
return $('<div role="option">').attr("id", _.guid()).text(displayFn(context));
}
}
function isValidName(str) {
Expand Down Expand Up @@ -1861,10 +1887,11 @@
this.trigger.apply(this, arguments);
},
_allDatasetsEmpty: function allDatasetsEmpty() {
return _.every(this.datasets, isDatasetEmpty);
function isDatasetEmpty(dataset) {
return dataset.isEmpty();
}
return _.every(this.datasets, _.bind(function isDatasetEmpty(dataset) {
var isEmpty = dataset.isEmpty();
this.$node.attr("aria-expanded", !isEmpty);
return isEmpty;
}, this));
},
_getSelectables: function getSelectables() {
return this.$node.find(this.selectors.selectable);
Expand Down Expand Up @@ -1908,6 +1935,7 @@
this.$node.addClass(this.classes.open);
},
close: function close() {
this.$node.attr("aria-expanded", false);
this.$node.removeClass(this.classes.open);
this._removeCursor();
},
Expand Down Expand Up @@ -1972,6 +2000,42 @@
});
return Menu;
}();
var Status = function() {
"use strict";
function Status(options) {
this.el = '<span role="status" aria-live="polite" class="visuallyhidden"></span>';
this.$el = $(this.el);
options.$input.after(this.$el);
_.each(options.menu.datasets, _.bind(function(dataset) {
if (dataset.onSync) {
dataset.onSync("rendered", _.bind(this.update, this));
dataset.onSync("cleared", _.bind(this.cleared, this));
}
}, this));
}
_.mixin(Status.prototype, {
update: function update(event, suggestions) {
var length = suggestions.length;
var words;
if (length === 1) {
words = {
result: "result",
is: "is"
};
} else {
words = {
result: "results",
is: "are"
};
}
this.$el.text(length + " " + words.result + " " + words.is + " available, use up and down arrow keys to navigate.");
},
cleared: function() {
this.$el.text("");
}
});
return Status;
}();
var DefaultMenu = function() {
"use strict";
var s = Menu.prototype;
Expand Down Expand Up @@ -2257,12 +2321,14 @@
return false;
},
moveCursor: function moveCursor(delta) {
var query, $candidate, data, suggestion, datasetName, cancelMove;
var query, $candidate, data, suggestion, datasetName, cancelMove, id;
query = this.input.getQuery();
$candidate = this.menu.selectableRelativeToCursor(delta);
data = this.menu.getSelectableData($candidate);
suggestion = data ? data.obj : null;
datasetName = data ? data.dataset : null;
id = $candidate ? $candidate.attr("id") : null;
this.input.trigger("cursorchange", id);
cancelMove = this._minLengthMet() && this.menu.update(query);
if (!cancelMove && !this.eventBus.before("cursorchange", suggestion, datasetName)) {
this.menu.setCursor($candidate);
Expand Down Expand Up @@ -2310,7 +2376,7 @@
www = WWW(o.classNames);
return this.each(attach);
function attach() {
var $input, $wrapper, $hint, $menu, defaultHint, defaultMenu, eventBus, input, menu, typeahead, MenuConstructor;
var $input, $wrapper, $hint, $menu, defaultHint, defaultMenu, eventBus, input, menu, status, typeahead, MenuConstructor;
_.each(datasets, function(d) {
d.highlight = !!o.highlight;
});
Expand Down Expand Up @@ -2341,6 +2407,10 @@
node: $menu,
datasets: datasets
}, www);
status = new Status({
$input: $input,
menu: menu
});
typeahead = new Typeahead({
input: input,
menu: menu,
Expand Down Expand Up @@ -2470,7 +2540,6 @@
}
function buildHintFromInput($input, www) {
return $input.clone().addClass(www.classes.hint).removeData().css(www.css.hint).css(getBackgroundStyles($input)).prop("readonly", true).removeAttr("id name placeholder required").attr({
autocomplete: "off",
spellcheck: "false",
tabindex: -1
});
Expand All @@ -2483,7 +2552,6 @@
style: $input.attr("style")
});
$input.addClass(www.classes.input).attr({
autocomplete: "off",
spellcheck: false
});
try {
Expand Down
4 changes: 2 additions & 2 deletions dist/typeahead.bundle.min.js

Large diffs are not rendered by default.

Loading