pax_global_header 0000666 0000000 0000000 00000000064 14023456335 0014517 g ustar 00root root 0000000 0000000 52 comment=7cfd4885d152900d49ec94fc7fd54925d9f3fd2b
awesomplete-1.1.5+dfsg/ 0000775 0000000 0000000 00000000000 14023456335 0014767 5 ustar 00root root 0000000 0000000 awesomplete-1.1.5+dfsg/.codeclimate.yml 0000664 0000000 0000000 00000000252 14023456335 0020040 0 ustar 00root root 0000000 0000000 engines:
eslint:
enabled: true
fixme:
enabled: true
ratings:
paths:
- "**.js"
exclude_paths:
- "**.min.js"
- karma*.conf.js
- prism/**/*
- test/**/*
- .*
awesomplete-1.1.5+dfsg/.eslintrc 0000664 0000000 0000000 00000010073 14023456335 0016614 0 ustar 00root root 0000000 0000000 ecmaFeatures: {}
rules:
no-alert: 0
no-array-constructor: 0
no-bitwise: 0
no-caller: 0
no-catch-shadow: 0
no-class-assign: 0
no-cond-assign: 2
no-console: 2
no-const-assign: 0
no-constant-condition: 2
no-continue: 0
no-control-regex: 2
no-debugger: 2
no-delete-var: 2
no-div-regex: 0
no-dupe-keys: 2
no-dupe-args: 2
no-duplicate-case: 2
no-else-return: 0
no-empty: 2
no-empty-character-class: 2
no-empty-label: 0
no-eq-null: 0
no-eval: 0
no-ex-assign: 2
no-extend-native: 0
no-extra-bind: 0
no-extra-boolean-cast: 2
no-extra-parens: 0
no-extra-semi: 2
no-fallthrough: 2
no-floating-decimal: 0
no-func-assign: 2
no-implicit-coercion: 0
no-implied-eval: 0
no-inline-comments: 0
no-inner-declarations:
- 2
- functions
no-invalid-regexp: 2
no-invalid-this: 0
no-irregular-whitespace: 2
no-iterator: 0
no-label-var: 0
no-labels: 0
no-lone-blocks: 0
no-lonely-if: 0
no-loop-func: 0
no-mixed-requires:
- 0
- false
no-mixed-spaces-and-tabs:
- 2
- smart-tabs
linebreak-style:
- 0
- unix
no-multi-spaces: 0
no-multi-str: 0
no-multiple-empty-lines:
- 0
- max: 2
no-native-reassign: 0
no-negated-in-lhs: 2
no-nested-ternary: 0
no-new: 0
no-new-func: 0
no-new-object: 0
no-new-require: 0
no-new-wrappers: 0
no-obj-calls: 2
no-octal: 2
no-octal-escape: 0
no-param-reassign: 0
no-path-concat: 0
no-plusplus: 0
no-process-env: 0
no-process-exit: 0
no-proto: 0
no-redeclare: 2
no-regex-spaces: 2
no-reserved-keys: 0
no-restricted-modules: 0
no-return-assign: 0
no-script-url: 0
no-self-compare: 0
no-sequences: 0
no-shadow: 0
no-shadow-restricted-names: 0
no-spaced-func: 0
no-sparse-arrays: 2
no-sync: 0
no-ternary: 0
no-trailing-spaces: 0
no-this-before-super: 0
no-throw-literal: 0
no-undef: 2
no-undef-init: 0
no-undefined: 0
no-unexpected-multiline: 0
no-underscore-dangle: 0
no-unneeded-ternary: 0
no-unreachable: 2
no-unused-expressions: 0
no-unused-vars:
- 2
- vars: all
args: after-used
no-use-before-define: 0
no-useless-call: 0
no-void: 0
no-var: 0
no-warning-comments:
- 0
- terms:
- todo
- fixme
- xxx
location: start
no-with: 0
array-bracket-spacing:
- 0
- never
arrow-parens: 0
arrow-spacing: 0
accessor-pairs: 0
block-scoped-var: 0
brace-style:
- 0
- 1tbs
callback-return: 0
camelcase: 0
comma-dangle:
- 2
- never
comma-spacing: 0
comma-style: 0
complexity:
- 2
- 11
computed-property-spacing:
- 0
- never
consistent-return: 0
consistent-this:
- 0
- that
constructor-super: 0
curly:
- 0
- all
default-case: 0
dot-location: 0
dot-notation:
- 0
- allowKeywords: true
eol-last: 0
eqeqeq: 0
func-names: 0
func-style:
- 0
- declaration
generator-star-spacing: 0
guard-for-in: 0
handle-callback-err: 0
indent: 0
init-declarations: 0
key-spacing:
- 0
- beforeColon: false
afterColon: true
lines-around-comment: 0
max-depth:
- 0
- 4
max-len:
- 0
- 80
- 4
max-nested-callbacks:
- 0
- 2
max-params:
- 0
- 3
max-statements:
- 0
- 10
new-cap: 0
new-parens: 0
newline-after-var: 0
object-curly-spacing:
- 0
- never
object-shorthand: 0
one-var: 0
operator-assignment:
- 0
- always
operator-linebreak: 0
padded-blocks: 0
prefer-const: 0
prefer-spread: 0
prefer-reflect: 0
quote-props: 0
quotes:
- 2
- double
- avoid-escape
radix: 0
require-yield: 0
semi: 0
semi-spacing:
- 0
- before: false
after: true
sort-vars: 0
space-after-keywords:
- 0
- always
space-before-blocks:
- 0
- always
space-before-function-paren:
- 0
- always
space-in-parens:
- 0
- never
space-infix-ops: 0
space-return-throw-case: 0
space-unary-ops:
- 0
- words: true
nonwords: false
spaced-comment: 0
strict: 0
use-isnan: 2
valid-jsdoc: 0
valid-typeof: 2
vars-on-top: 0
wrap-iife: 0
wrap-regex: 0
yoda:
- 0
- never
env:
browser: true
node: true
jquery: true
amd: true
commonjs: true
awesomplete-1.1.5+dfsg/.gitignore 0000664 0000000 0000000 00000000027 14023456335 0016756 0 ustar 00root root 0000000 0000000 node_modules/
coverage/ awesomplete-1.1.5+dfsg/.travis.yml 0000664 0000000 0000000 00000000657 14023456335 0017110 0 ustar 00root root 0000000 0000000 language: node_js
node_js:
- "0.10"
branches:
only:
- gh-pages
- /v\d+\.\d+/
install:
- npm install -g codeclimate-test-reporter
- npm install
before_script:
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
after_script:
- codeclimate-test-reporter < ./coverage/lcov.info
deploy:
provider: npm
email: $NPM_EMAIL
api_key: $NPM_TOKEN
on:
tags: true
awesomplete-1.1.5+dfsg/CHANGELOG.md 0000664 0000000 0000000 00000001637 14023456335 0016607 0 ustar 00root root 0000000 0000000 # 1.1.1 (2016-06-25)
## Fixes
* Improved docs
* Emit close reason with `awesomplete-close` events ([8c0ff62](https://github.com/LeaVerou/awesomplete/commit/8c0ff6225c96af2f5f3b7312d7ba7b69f71be575)). See [Events](http://leaverou.github.io/awesomplete/#events).
* Fire `awesomplete-close` event only if open ([2cef2c2](https://github.com/LeaVerou/awesomplete/commit/2cef2c28a6f74ee5c0b294d2c3c7d2bad72bd466))
# 1.1.0 (2016-03-16)
## Features
* Separate label/value for each suggestion on the list
* New `suggestions` property with suggestion items only (to be rendered in completer)
* New `data` method to convert/change suggestion item data and corresponding `Awesomplete.DATA`
* The `item` and `replace` methods have a corresponding `Awesomplete.ITEM` and `Awesomplete.REPLACE` defaults now
* Ajax and Combobox examples
* Nearly 100% test coverage with Travis CI and Code Climate
# 1.0.0 (2015-04-23)
## First release
awesomplete-1.1.5+dfsg/CONTRIBUTING.md 0000664 0000000 0000000 00000003075 14023456335 0017225 0 ustar 00root root 0000000 0000000 ##Contributing
**Prerequisites**
Install [Node.js](https://nodejs.org/) and [npm](https://www.npmjs.com/). On OSX with [Homebrew](http://brew.sh/) installed it is as easy as:
```
brew install node
```
Install dependencies:
```
npm install
```
**Running tests**
Run tests once and exit:
```
npm test
```
Continuous mode. Whenever any source or test file changes, tests will run automatically:
```
karma start
```
Chrome starts automatically and stops on ```Ctrl+C```. You can also open ```http://localhost:9876/``` in any other browser and it will run the tests as long as the tab is open.
**Adding a test**
[Jasmine](http://jasmine.github.io/) is the testing framework used by Awesomplete.
To write a test (or suite of tests) start by adding a `describe` function which receives a string describing what is being tested and a function containing what you expect the test to do. Inside the function use the `it` block to arrange and assert a functionality.
A test would look like this:
```javascript
describe("A fact", function(){
it("is always true",function(){
var fact = true;
expect(fact).toBe(true);
});
});
```
See existing tests in ```test``` directory as an example. More expectations and examples on how to use Jasmine can be found on the official [documentation](http://jasmine.github.io/2.2/introduction.html).
**Build**
Run the build with the following command:
```
gulp
```
The build will:
1. Minify `awesomplete.js` and generate `awesomplete.min.js`.
2. Merge `awesomplete.base.css` and `awesomplete.theme.css` and generate `awesomplete.css`. awesomplete-1.1.5+dfsg/LICENSE 0000664 0000000 0000000 00000002065 14023456335 0015777 0 ustar 00root root 0000000 0000000 The MIT License (MIT)
Copyright (c) 2015 Lea Verou
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
awesomplete-1.1.5+dfsg/README.md 0000664 0000000 0000000 00000006364 14023456335 0016257 0 ustar 00root root 0000000 0000000 # Awesomplete
[](https://www.npmjs.com/package/awesomplete)
[](https://travis-ci.org/LeaVerou/awesomplete)
[](https://codeclimate.com/github/LeaVerou/awesomplete)
[](https://codeclimate.com/github/LeaVerou/awesomplete/coverage)
https://leaverou.github.io/awesomplete/
Awesomplete is an ultra lightweight, customizable, simple autocomplete widget with zero dependencies, built with modern standards for modern browsers.
## Installation
There are a few ways to obtain the needed files.
Here are 2 of them:
1. CDN server
```sh
https://cdnjs.com/libraries/awesomplete
```
2. Another way to get up and running is by using `yarn` or `npm`:
```sh
yarn add awesomplete
```
```sh
npm install awesomplete --save
```
More information about the npm package can be found [here](https://www.npmjs.com/package/awesomplete).
## Basic Usage
Before you try anything, you need to include awesomplete.css and awesomplete.js in your page, via the usual tags:
```html
```
Then you can add an Awesomplete widget by adding the following input tag:
```html
```
Add `class="awesomplete"` for it to be automatically processed (you can still specify many options via HTML attributes)
Otherwise you can instantiate with a few lines of JS code, which allow for more customization.
There are many ways to link an input to a list of suggestions.
The simple example above could have also been made with the following markup, which provides a nice native fallback in case the script doesn’t load:
```html
Ada
Java
JavaScript
Brainfuck
LOLCODE
Node.js
Ruby on Rails
```
Or the following, if you don’t want to use a ``, or if you don’t want to use IDs (since any selector will work in data-list):
```html
Ada
Java
JavaScript
Brainfuck
LOLCODE
Node.js
Ruby on Rails
```
There are multiple customizations and properties able to be instantiated within the JS. Libraries and definitions of the properties are available in the Links below.
## License
Awesomplete is released under the MIT License. See [LICENSE][1] file for
details.
## Links
The official site for the library is at .
Documentation for the API and other topics is at
.
Created by Lea Verou and other fantastic contributors.
[1]: https://github.com/LeaVerou/awesomplete/blob/gh-pages/LICENSE
awesomplete-1.1.5+dfsg/awesomplete.base.css 0000664 0000000 0000000 00000000757 14023456335 0020750 0 ustar 00root root 0000000 0000000 .awesomplete [hidden] {
display: none;
}
.awesomplete .visually-hidden {
position: absolute;
clip: rect(0, 0, 0, 0);
}
.awesomplete {
display: inline-block;
position: relative;
}
.awesomplete > input {
display: block;
}
.awesomplete > ul {
position: absolute;
left: 0;
z-index: 1;
min-width: 100%;
box-sizing: border-box;
list-style: none;
padding: 0;
margin: 0;
background: #fff;
}
.awesomplete > ul:empty {
display: none;
}
awesomplete-1.1.5+dfsg/awesomplete.js 0000664 0000000 0000000 00000031423 14023456335 0017655 0 ustar 00root root 0000000 0000000 /**
* Simple, lightweight, usable local autocomplete library for modern browsers
* Because there weren’t enough autocomplete scripts in the world? Because I’m completely insane and have NIH syndrome? Probably both. :P
* @author Lea Verou http://leaverou.github.io/awesomplete
* MIT license
*/
(function () {
var _ = function (input, o) {
var me = this;
// Keep track of number of instances for unique IDs
_.count = (_.count || 0) + 1;
this.count = _.count;
// Setup
this.isOpened = false;
this.input = $(input);
this.input.setAttribute("autocomplete", "off");
this.input.setAttribute("aria-expanded", "false");
this.input.setAttribute("aria-owns", "awesomplete_list_" + this.count);
this.input.setAttribute("role", "combobox");
// store constructor options in case we need to distinguish
// between default and customized behavior later on
this.options = o = o || {};
configure(this, {
minChars: 2,
maxItems: 10,
autoFirst: false,
data: _.DATA,
filter: _.FILTER_CONTAINS,
sort: o.sort === false ? false : _.SORT_BYLENGTH,
container: _.CONTAINER,
item: _.ITEM,
replace: _.REPLACE,
tabSelect: false
}, o);
this.index = -1;
// Create necessary elements
this.container = this.container(input);
this.ul = $.create("ul", {
hidden: "hidden",
role: "listbox",
id: "awesomplete_list_" + this.count,
inside: this.container
});
this.status = $.create("span", {
className: "visually-hidden",
role: "status",
"aria-live": "assertive",
"aria-atomic": true,
inside: this.container,
textContent: this.minChars != 0 ? ("Type " + this.minChars + " or more characters for results.") : "Begin typing for results."
});
// Bind events
this._events = {
input: {
"input": this.evaluate.bind(this),
"blur": this.close.bind(this, { reason: "blur" }),
"keydown": function(evt) {
var c = evt.keyCode;
// If the dropdown `ul` is in view, then act on keydown for the following keys:
// Enter / Esc / Up / Down
if(me.opened) {
if (c === 13 && me.selected) { // Enter
evt.preventDefault();
me.select(undefined, undefined, evt);
}
else if (c === 9 && me.selected && me.tabSelect) {
me.select(undefined, undefined, evt);
}
else if (c === 27) { // Esc
me.close({ reason: "esc" });
}
else if (c === 38 || c === 40) { // Down/Up arrow
evt.preventDefault();
me[c === 38? "previous" : "next"]();
}
}
}
},
form: {
"submit": this.close.bind(this, { reason: "submit" })
},
ul: {
// Prevent the default mousedowm, which ensures the input is not blurred.
// The actual selection will happen on click. This also ensures dragging the
// cursor away from the list item will cancel the selection
"mousedown": function(evt) {
evt.preventDefault();
},
// The click event is fired even if the corresponding mousedown event has called preventDefault
"click": function(evt) {
var li = evt.target;
if (li !== this) {
while (li && !/li/i.test(li.nodeName)) {
li = li.parentNode;
}
if (li && evt.button === 0) { // Only select on left click
evt.preventDefault();
me.select(li, evt.target, evt);
}
}
}
}
};
$.bind(this.input, this._events.input);
$.bind(this.input.form, this._events.form);
$.bind(this.ul, this._events.ul);
if (this.input.hasAttribute("list")) {
this.list = "#" + this.input.getAttribute("list");
this.input.removeAttribute("list");
}
else {
this.list = this.input.getAttribute("data-list") || o.list || [];
}
_.all.push(this);
};
_.prototype = {
set list(list) {
if (Array.isArray(list)) {
this._list = list;
}
else if (typeof list === "string" && list.indexOf(",") > -1) {
this._list = list.split(/\s*,\s*/);
}
else { // Element or CSS selector
list = $(list);
if (list && list.children) {
var items = [];
slice.apply(list.children).forEach(function (el) {
if (!el.disabled) {
var text = el.textContent.trim();
var value = el.value || text;
var label = el.label || text;
if (value !== "") {
items.push({ label: label, value: value });
}
}
});
this._list = items;
}
}
if (document.activeElement === this.input) {
this.evaluate();
}
},
get selected() {
return this.index > -1;
},
get opened() {
return this.isOpened;
},
close: function (o) {
if (!this.opened) {
return;
}
this.input.setAttribute("aria-expanded", "false");
this.ul.setAttribute("hidden", "");
this.isOpened = false;
this.index = -1;
this.status.setAttribute("hidden", "");
$.fire(this.input, "awesomplete-close", o || {});
},
open: function () {
this.input.setAttribute("aria-expanded", "true");
this.ul.removeAttribute("hidden");
this.isOpened = true;
this.status.removeAttribute("hidden");
if (this.autoFirst && this.index === -1) {
this.goto(0);
}
$.fire(this.input, "awesomplete-open");
},
destroy: function() {
//remove events from the input and its form
$.unbind(this.input, this._events.input);
$.unbind(this.input.form, this._events.form);
// cleanup container if it was created by Awesomplete but leave it alone otherwise
if (!this.options.container) {
//move the input out of the awesomplete container and remove the container and its children
var parentNode = this.container.parentNode;
parentNode.insertBefore(this.input, this.container);
parentNode.removeChild(this.container);
}
//remove autocomplete and aria-autocomplete attributes
this.input.removeAttribute("autocomplete");
this.input.removeAttribute("aria-autocomplete");
//remove this awesomeplete instance from the global array of instances
var indexOfAwesomplete = _.all.indexOf(this);
if (indexOfAwesomplete !== -1) {
_.all.splice(indexOfAwesomplete, 1);
}
},
next: function () {
var count = this.ul.children.length;
this.goto(this.index < count - 1 ? this.index + 1 : (count ? 0 : -1) );
},
previous: function () {
var count = this.ul.children.length;
var pos = this.index - 1;
this.goto(this.selected && pos !== -1 ? pos : count - 1);
},
// Should not be used, highlights specific item without any checks!
goto: function (i) {
var lis = this.ul.children;
if (this.selected) {
lis[this.index].setAttribute("aria-selected", "false");
}
this.index = i;
if (i > -1 && lis.length > 0) {
lis[i].setAttribute("aria-selected", "true");
this.status.textContent = lis[i].textContent + ", list item " + (i + 1) + " of " + lis.length;
this.input.setAttribute("aria-activedescendant", this.ul.id + "_item_" + this.index);
// scroll to highlighted element in case parent's height is fixed
this.ul.scrollTop = lis[i].offsetTop - this.ul.clientHeight + lis[i].clientHeight;
$.fire(this.input, "awesomplete-highlight", {
text: this.suggestions[this.index]
});
}
},
select: function (selected, origin, originalEvent) {
if (selected) {
this.index = $.siblingIndex(selected);
} else {
selected = this.ul.children[this.index];
}
if (selected) {
var suggestion = this.suggestions[this.index];
var allowed = $.fire(this.input, "awesomplete-select", {
text: suggestion,
origin: origin || selected,
originalEvent: originalEvent
});
if (allowed) {
this.replace(suggestion);
this.close({ reason: "select" });
$.fire(this.input, "awesomplete-selectcomplete", {
text: suggestion,
originalEvent: originalEvent
});
}
}
},
evaluate: function() {
var me = this;
var value = this.input.value;
if (value.length >= this.minChars && this._list && this._list.length > 0) {
this.index = -1;
// Populate list with options that match
this.ul.innerHTML = "";
this.suggestions = this._list
.map(function(item) {
return new Suggestion(me.data(item, value));
})
.filter(function(item) {
return me.filter(item, value);
});
if (this.sort !== false) {
this.suggestions = this.suggestions.sort(this.sort);
}
this.suggestions = this.suggestions.slice(0, this.maxItems);
this.suggestions.forEach(function(text, index) {
me.ul.appendChild(me.item(text, value, index));
});
if (this.ul.children.length === 0) {
this.status.textContent = "No results found";
this.close({ reason: "nomatches" });
} else {
this.open();
this.status.textContent = this.ul.children.length + " results found";
}
}
else {
this.close({ reason: "nomatches" });
this.status.textContent = "No results found";
}
}
};
// Static methods/properties
_.all = [];
_.FILTER_CONTAINS = function (text, input) {
return RegExp($.regExpEscape(input.trim()), "i").test(text);
};
_.FILTER_STARTSWITH = function (text, input) {
return RegExp("^" + $.regExpEscape(input.trim()), "i").test(text);
};
_.SORT_BYLENGTH = function (a, b) {
if (a.length !== b.length) {
return a.length - b.length;
}
return a < b? -1 : 1;
};
_.CONTAINER = function (input) {
return $.create("div", {
className: "awesomplete",
around: input
});
}
_.ITEM = function (text, input, item_id) {
var html = input.trim() === "" ? text : text.replace(RegExp($.regExpEscape(input.trim()), "gi"), "$& ");
return $.create("li", {
innerHTML: html,
"role": "option",
"aria-selected": "false",
"id": "awesomplete_list_" + this.count + "_item_" + item_id
});
};
_.REPLACE = function (text) {
this.input.value = text.value;
};
_.DATA = function (item/*, input*/) { return item; };
// Private functions
function Suggestion(data) {
var o = Array.isArray(data)
? { label: data[0], value: data[1] }
: typeof data === "object" && "label" in data && "value" in data ? data : { label: data, value: data };
this.label = o.label || o.value;
this.value = o.value;
}
Object.defineProperty(Suggestion.prototype = Object.create(String.prototype), "length", {
get: function() { return this.label.length; }
});
Suggestion.prototype.toString = Suggestion.prototype.valueOf = function () {
return "" + this.label;
};
function configure(instance, properties, o) {
for (var i in properties) {
var initial = properties[i],
attrValue = instance.input.getAttribute("data-" + i.toLowerCase());
if (typeof initial === "number") {
instance[i] = parseInt(attrValue);
}
else if (initial === false) { // Boolean options must be false by default anyway
instance[i] = attrValue !== null;
}
else if (initial instanceof Function) {
instance[i] = null;
}
else {
instance[i] = attrValue;
}
if (!instance[i] && instance[i] !== 0) {
instance[i] = (i in o)? o[i] : initial;
}
}
}
// Helpers
var slice = Array.prototype.slice;
function $(expr, con) {
return typeof expr === "string"? (con || document).querySelector(expr) : expr || null;
}
function $$(expr, con) {
return slice.call((con || document).querySelectorAll(expr));
}
$.create = function(tag, o) {
var element = document.createElement(tag);
for (var i in o) {
var val = o[i];
if (i === "inside") {
$(val).appendChild(element);
}
else if (i === "around") {
var ref = $(val);
ref.parentNode.insertBefore(element, ref);
element.appendChild(ref);
if (ref.getAttribute("autofocus") != null) {
ref.focus();
}
}
else if (i in element) {
element[i] = val;
}
else {
element.setAttribute(i, val);
}
}
return element;
};
$.bind = function(element, o) {
if (element) {
for (var event in o) {
var callback = o[event];
event.split(/\s+/).forEach(function (event) {
element.addEventListener(event, callback);
});
}
}
};
$.unbind = function(element, o) {
if (element) {
for (var event in o) {
var callback = o[event];
event.split(/\s+/).forEach(function(event) {
element.removeEventListener(event, callback);
});
}
}
};
$.fire = function(target, type, properties) {
var evt = document.createEvent("HTMLEvents");
evt.initEvent(type, true, true );
for (var j in properties) {
evt[j] = properties[j];
}
return target.dispatchEvent(evt);
};
$.regExpEscape = function (s) {
return s.replace(/[-\\^$*+?.()|[\]{}]/g, "\\$&");
};
$.siblingIndex = function (el) {
/* eslint-disable no-cond-assign */
for (var i = 0; el = el.previousElementSibling; i++);
return i;
};
// Initialization
function init() {
$$("input.awesomplete").forEach(function (input) {
new _(input);
});
}
// Make sure to export Awesomplete on self when in a browser
if (typeof self !== "undefined") {
self.Awesomplete = _;
}
// Are we in a browser? Check for Document constructor
if (typeof Document !== "undefined") {
// DOM already loaded?
if (document.readyState !== "loading") {
init();
}
else {
// Wait for it
document.addEventListener("DOMContentLoaded", init);
}
}
_.$ = $;
_.$$ = $$;
// Expose Awesomplete as a CJS module
if (typeof module === "object" && module.exports) {
module.exports = _;
}
return _;
}());
awesomplete-1.1.5+dfsg/awesomplete.theme.css 0000664 0000000 0000000 00000002550 14023456335 0021131 0 ustar 00root root 0000000 0000000 .awesomplete > ul {
border-radius: .3em;
margin: .2em 0 0;
background: hsla(0,0%,100%,.9);
background: linear-gradient(to bottom right, white, hsla(0,0%,100%,.8));
border: 1px solid rgba(0,0,0,.3);
box-shadow: .05em .2em .6em rgba(0,0,0,.2);
text-shadow: none;
}
@supports (transform: scale(0)) {
.awesomplete > ul {
transition: .3s cubic-bezier(.4,.2,.5,1.4);
transform-origin: 1.43em -.43em;
}
.awesomplete > ul[hidden],
.awesomplete > ul:empty {
opacity: 0;
transform: scale(0);
display: block;
transition-timing-function: ease;
}
}
/* Pointer */
.awesomplete > ul:before {
content: "";
position: absolute;
top: -.43em;
left: 1em;
width: 0; height: 0;
padding: .4em;
background: white;
border: inherit;
border-right: 0;
border-bottom: 0;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
}
.awesomplete > ul > li {
position: relative;
padding: .2em .5em;
cursor: pointer;
}
.awesomplete > ul > li:hover {
background: hsl(200, 40%, 80%);
color: black;
}
.awesomplete > ul > li[aria-selected="true"] {
background: hsl(205, 40%, 40%);
color: white;
}
.awesomplete mark {
background: hsl(65, 100%, 50%);
}
.awesomplete li:hover mark {
background: hsl(68, 100%, 41%);
}
.awesomplete li[aria-selected="true"] mark {
background: hsl(86, 100%, 21%);
color: inherit;
} awesomplete-1.1.5+dfsg/bower.json 0000664 0000000 0000000 00000000537 14023456335 0017005 0 ustar 00root root 0000000 0000000 {
"name": "awesomplete",
"main": [
"./awesomplete.css",
"./awesomplete.js"
],
"homepage": "https://github.com/LeaVerou/awesomplete",
"authors": [
"Lea Verou <>"
],
"description": "Ultra lightweight, usable autocomplete with zero dependencies.",
"keywords": [
"autocomplete",
"lightweight"
],
"license": "MIT"
}
awesomplete-1.1.5+dfsg/gulpfile.js 0000664 0000000 0000000 00000001425 14023456335 0017136 0 ustar 00root root 0000000 0000000 var gulp = require('gulp');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var header = require('gulp-header');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');
var banner = "// Awesomplete - Lea Verou - MIT license\n";
gulp.task('minify', function() {
return gulp.src(['awesomplete.js'])
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(header(banner))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('.'));
});
gulp.task('concat', function() {
return gulp.src(['awesomplete.base.css', 'awesomplete.theme.css'])
.pipe(sourcemaps.init())
.pipe(concat('awesomplete.css'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('.'));
});
gulp.task('default', ['minify', 'concat']);
awesomplete-1.1.5+dfsg/karma.conf.js 0000664 0000000 0000000 00000003565 14023456335 0017355 0 ustar 00root root 0000000 0000000 module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine', 'jasmine-def', 'fixture'],
// list of files / patterns to load in the browser
files: [
'awesomplete.js',
'test/specHelper.js',
{
pattern: 'test/fixtures/**/*.html',
watched: true, included: true, served: true
},
'test/**/*Spec.js'
],
// list of files to exclude
exclude: [
'**/*.swp'
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'awesomplete.js': ['coverage'],
'**/*.html' : ['html2js']
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['dots', 'coverage'],
coverageReporter: {
type: 'lcov',
subdir: '.'
},
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: process.env.TRAVIS ? ['ChromeTravisCI'] : ['Chrome'],
// need this to run Chrome on Travis CI
customLaunchers: {
ChromeTravisCI: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
awesomplete-1.1.5+dfsg/package.json 0000664 0000000 0000000 00000001560 14023456335 0017257 0 ustar 00root root 0000000 0000000 {
"name": "awesomplete",
"version": "1.1.5",
"description": "http://leaverou.github.io/awesomplete/",
"main": "awesomplete.js",
"scripts": {
"test": "karma start --single-run"
},
"repository": "LeaVerou/awesomplete",
"author": "Lea Verou",
"license": "MIT",
"bugs": {
"url": "https://github.com/LeaVerou/awesomplete/issues"
},
"homepage": "https://leaverou.github.io/awesomplete/",
"devDependencies": {
"gulp": "^3.9.0",
"gulp-concat": "^2.6.0",
"gulp-header": "^1.7.1",
"gulp-rename": "^1.2.2",
"gulp-sourcemaps": "^1.6.0",
"gulp-uglify": "^2.0.0",
"jasmine-core": "^2.4.1",
"karma": "^0.13.19",
"karma-chrome-launcher": "^0.2.2",
"karma-coverage": "^0.5.3",
"karma-fixture": "^0.2.5",
"karma-html2js-preprocessor": "^0.1.0",
"karma-jasmine": "^0.3.6",
"karma-jasmine-def": "^0.1.0"
}
}
awesomplete-1.1.5+dfsg/test/ 0000775 0000000 0000000 00000000000 14023456335 0015746 5 ustar 00root root 0000000 0000000 awesomplete-1.1.5+dfsg/test/api/ 0000775 0000000 0000000 00000000000 14023456335 0016517 5 ustar 00root root 0000000 0000000 awesomplete-1.1.5+dfsg/test/api/closeSpec.js 0000664 0000000 0000000 00000001760 14023456335 0021001 0 ustar 00root root 0000000 0000000 describe("awesomplete.close", function () {
$.fixture("plain");
subject(function () { return new Awesomplete("#plain", { list: ["item1", "item2", "item3"] }) });
beforeEach(function () {
$.type(this.subject.input, "ite");
this.subject.open();
this.subject.next();
});
it("closes completer", function () {
this.subject.close();
expect(this.subject.ul.hasAttribute("hidden")).toBe(true);
});
it("makes no item selected", function () {
this.subject.close();
expect(this.subject.index).toBe(-1);
});
it("fires awesomplete-close event", function () {
var handler = $.spyOnEvent(this.subject.input, "awesomplete-close");
this.subject.close();
expect(handler).toHaveBeenCalledWith(
jasmine.any(document.createEvent("HTMLEvents").constructor)
);
});
it("returns early if already closed", function () {
var handler = $.spyOnEvent(this.subject.input, "awesomplete-close");
this.subject.close();
this.subject.close();
expect(handler.calls.count()).toBe(1);
});
});
awesomplete-1.1.5+dfsg/test/api/evaluateSpec.js 0000664 0000000 0000000 00000004262 14023456335 0021502 0 ustar 00root root 0000000 0000000 describe("awesomplete.evaluate", function () {
$.fixture("plain");
subject(function () {
return new Awesomplete("#plain", { list: ["item1", "item2", "item3"] });
});
describe("with too short input value", function () {
beforeEach(function () {
$.type(this.subject.input, "i");
});
it("closes completer", function () {
spyOn(this.subject, "close");
this.subject.evaluate();
expect(this.subject.close).toHaveBeenCalledWith({
reason: "nomatches"
});
});
});
describe("with no items found", function () {
beforeEach(function () {
$.type(this.subject.input, "nosuchitem");
});
it("closes completer", function () {
spyOn(this.subject, "close");
this.subject.evaluate();
expect(this.subject.close).toHaveBeenCalledWith({
reason: "nomatches"
});
});
});
describe("with some items found", function () {
beforeEach(function () {
$.type(this.subject.input, "ite");
});
it("opens completer", function () {
spyOn(this.subject, "open");
this.subject.evaluate();
expect(this.subject.open).toHaveBeenCalled();
});
it("fills completer with found items", function () {
this.subject.evaluate();
expect(this.subject.ul.children.length).toBe(3);
});
it("shows no more than maxItems", function () {
this.subject.maxItems = 2;
this.subject.evaluate();
expect(this.subject.ul.children.length).toBe(2);
});
it("makes no item selected", function () {
this.subject.evaluate();
expect(this.subject.index).toBe(-1);
});
});
describe("with minChars: 0", function () {
beforeEach(function () {
this.subject.minChars = 0;
});
it("opens completer", function () {
spyOn(this.subject, "open");
this.subject.evaluate();
expect(this.subject.open).toHaveBeenCalled();
});
it("fills completer with all items", function () {
this.subject.evaluate();
expect(this.subject.ul.children.length).toBe(3);
});
it("shows no more than maxItems", function () {
this.subject.maxItems = 2;
this.subject.evaluate();
expect(this.subject.ul.children.length).toBe(2);
});
it("makes no item selected", function () {
this.subject.evaluate();
expect(this.subject.index).toBe(-1);
});
});
});
awesomplete-1.1.5+dfsg/test/api/gotoSpec.js 0000664 0000000 0000000 00000003253 14023456335 0020643 0 ustar 00root root 0000000 0000000 describe("awesomplete.goto", function () {
$.fixture("plain");
subject(function () {
return new Awesomplete("#plain", { list: ["item1", "item2", "item3"] });
});
def("lastIndex", function () { return this.subject.ul.children.length - 1 });
beforeEach(function () {
$.type(this.subject.input, "ite");
});
it("clears previous aria-selected", function () {
this.subject.goto(0);
this.subject.goto(this.lastIndex);
expect(this.subject.ul.children[0].getAttribute("aria-selected")).toBe("false");
});
it("goes to first item", function () {
this.subject.goto(0);
expect(this.subject.index).toBe(0);
});
it("goes to last item", function () {
this.subject.goto(this.lastIndex);
expect(this.subject.index).toBe(this.lastIndex);
});
it("fires awesomplete-highlight event", function () {
var handler = $.spyOnEvent(this.subject.input, "awesomplete-highlight");
this.subject.goto(1);
expect(handler).toHaveBeenCalledWith(
jasmine.objectContaining({
text: jasmine.objectContaining({ label: "item2", value: "item2" })
})
);
});
describe("with item index > -1", function () {
beforeEach(function () {
this.subject.goto(0);
});
it("sets aria-selected", function () {
expect(this.subject.ul.children[0].getAttribute("aria-selected")).toBe("true");
});
it("updates status", function () {
expect(this.subject.status.textContent).toBe("item1, list item 1 of 3");
});
});
describe("with item index = -1", function () {
beforeEach(function () {
this.subject.goto(0);
this.subject.goto(-1);
});
it("does not update status", function () {
expect(this.subject.status.textContent).toBe("item1, list item 1 of 3");
});
});
});
awesomplete-1.1.5+dfsg/test/api/nextSpec.js 0000664 0000000 0000000 00000002635 14023456335 0020654 0 ustar 00root root 0000000 0000000 describe("awesomplete.next", function () {
$.fixture("plain");
subject(function () {
return new Awesomplete("#plain", { list: ["item1", "item2", "item3"] });
});
def("lastIndex", function () { return this.subject.ul.children.length - 1 });
describe("without any items found", function () {
beforeEach(function () {
$.type(this.subject.input, "nosuchitem");
this.subject.open();
});
it("does not select any item", function () {
this.subject.next();
expect(this.subject.index).toBe(-1);
});
});
describe("with some items found", function () {
beforeEach(function () {
$.type(this.subject.input, "ite");
this.subject.open();
});
describe("and no item was already selected", function () {
it("selects the first item ", function () {
this.subject.next();
expect(this.subject.index).toBe(0);
});
});
describe("and some item was already selected", function () {
it("selects the second item", function () {
this.subject.goto(0);
this.subject.next();
expect(this.subject.index).toBe(1);
});
it("selects the last item", function () {
this.subject.goto(this.lastIndex - 1);
this.subject.next();
expect(this.subject.index).toBe(this.lastIndex);
});
it("selects the first item after reaching the end", function () {
this.subject.goto(this.lastIndex);
this.subject.next();
expect(this.subject.index).toBe(0);
});
});
});
});
awesomplete-1.1.5+dfsg/test/api/openSpec.js 0000664 0000000 0000000 00000002767 14023456335 0020645 0 ustar 00root root 0000000 0000000 describe("awesomplete.open", function () {
$.fixture("plain");
subject(function () { return new Awesomplete("#plain", { list: ["item1", "item2", "item3"] }) });
// Exposes this bug https://github.com/LeaVerou/awesomplete/pull/16740
// FIXME better fix is probably required as discussed in PR above
xit("fills in the list on creation", function () {
$("#plain").value = "ite";
this.subject.open();
expect(this.subject.ul.children.length).toBe(3);
});
it("opens completer", function () {
this.subject.open();
expect(this.subject.ul.hasAttribute("hidden")).toBe(false);
});
describe("with autoFirst: true", function () {
beforeEach(function () {
this.subject.autoFirst = true;
spyOn(this.subject, "goto");
});
it("selects first item if wasn't seleted before", function () {
this.subject.open();
expect(this.subject.goto).toHaveBeenCalledWith(0);
});
it("does not select any item if was seleted before", function () {
this.subject.index = 0;
this.subject.open();
expect(this.subject.goto).not.toHaveBeenCalled();
});
});
describe("with autoFirst: false", function () {
it("does not select any item", function () {
this.subject.autoFirst = false;
spyOn(this.subject, "goto");
this.subject.open();
expect(this.subject.goto).not.toHaveBeenCalled();
});
});
it("fires awesomplete-open event", function () {
var handler = $.spyOnEvent(this.subject.input, "awesomplete-open");
this.subject.open();
expect(handler).toHaveBeenCalled();
});
});
awesomplete-1.1.5+dfsg/test/api/openedSpec.js 0000664 0000000 0000000 00000001122 14023456335 0021136 0 ustar 00root root 0000000 0000000 describe("awesomplete.opened", function () {
$.fixture("plain");
subject(function () { return new Awesomplete("#plain") });
describe("with newly created completer", function () {
it("is false", function () {
expect(this.subject.opened).toBe(false);
});
});
describe("with opened completer", function () {
it("is true", function () {
this.subject.open();
expect(this.subject.opened).toBe(true);
});
});
describe("with closed completer", function () {
it("is false", function () {
this.subject.close();
expect(this.subject.opened).toBe(false);
});
});
});
awesomplete-1.1.5+dfsg/test/api/previousSpec.js 0000664 0000000 0000000 00000002720 14023456335 0021545 0 ustar 00root root 0000000 0000000 describe("awesomplete.previous", function () {
$.fixture("plain");
subject(function () {
return new Awesomplete("#plain", { list: ["item1", "item2", "item3"] });
});
def("lastIndex", function () { return this.subject.ul.children.length - 1 });
describe("without any items found", function () {
beforeEach(function () {
$.type(this.subject.input, "nosuchitem");
this.subject.open();
});
it("does not select any item", function () {
this.subject.previous();
expect(this.subject.index).toBe(-1);
});
});
describe("with some items found", function () {
beforeEach(function () {
$.type(this.subject.input, "ite");
this.subject.open();
});
describe("and no item was already selected", function () {
it("selects the last item ", function () {
this.subject.previous();
expect(this.subject.index).toBe(this.lastIndex);
});
});
describe("and some item was already selected", function () {
it("selects the second item from the end", function () {
this.subject.goto(this.lastIndex);
this.subject.previous();
expect(this.subject.index).toBe(this.lastIndex - 1);
});
it("selects the first item", function () {
this.subject.goto(1);
this.subject.previous();
expect(this.subject.index).toBe(0);
});
it("selects the last item after reaching the start", function () {
this.subject.goto(0);
this.subject.previous();
expect(this.subject.index).toBe(this.lastIndex);
});
});
});
});
awesomplete-1.1.5+dfsg/test/api/removeSpec.js 0000664 0000000 0000000 00000002664 14023456335 0021175 0 ustar 00root root 0000000 0000000 describe("awesomplete.destroy", function () {
$.fixture("plain");
subject(function () { return new Awesomplete("#plain", { list: ["item1", "item2", "item3"] }) });
beforeEach(function () {
$.type(this.subject.input, "ite");
this.subject.open();
this.subject.next();
});
it("removes its elements from the DOM", function () {
var instance = this.subject;
var inputParentBefore = this.subject.input.parentNode;
instance.destroy();
expect(instance.input.parentNode).not.toBe(inputParentBefore);
expect(document.body.contains(instance.container)).toBeFalsy();
expect(document.body.contains(instance.ul)).toBeFalsy()
});
it("removes the autocomplete and aria-autocomplete attributes", function() {
var instance = this.subject;
instance.destroy();
expect(instance.input.getAttribute("autocomplete")).toBeNull();
expect(instance.input.getAttribute("aria-autocomplete")).toBeNull();
});
it("removes event listeners from form and input", function () {
var instance = this.subject;
var events = instance._events;
spyOn(events.input, "blur");
instance.destroy();
Awesomplete.$.fire(instance.input, "blur");
expect(events.input.blur).not.toHaveBeenCalledTimes(1);
});
it("removes itself from the global list of instances", function() {
var countBefore = Awesomplete.all.length;
this.subject.destroy();
var countAfter = Awesomplete.all.length;
expect(countAfter).toBeLessThan(countBefore);
});
});
awesomplete-1.1.5+dfsg/test/api/selectSpec.js 0000664 0000000 0000000 00000007226 14023456335 0021156 0 ustar 00root root 0000000 0000000 describe("awesomplete.select", function () {
$.fixture("plain");
subject(function () {
return new Awesomplete("#plain", { list: ["item1", "item2", "item3"] });
});
def("lastIndex", function () { return this.subject.ul.children.length - 1 });
def("lastLi", function () { return this.subject.ul.children[this.lastIndex] });
beforeEach(function () {
$.type(this.subject.input, "ite");
});
describe("with closed completer", itDoesNotSelectAnyItem);
describe("with opened completer", function () {
beforeEach(function () {
this.subject.open();
});
describe("and no current item", itDoesNotSelectAnyItem);
describe("and current item", function () {
beforeEach(function () {
this.subject.goto(0);
});
itSelects("item1");
});
describe("and item specified as argument", function () {
def("selectArgument", function () { return this.lastLi });
itSelects("item3");
});
});
// Shared behaviors
function itSelects(expectedTxt) {
it("fires awesomplete-select event", function () {
var handler = $.spyOnEvent(this.subject.input, "awesomplete-select");
this.subject.select(this.selectArgument);
expect(handler).toHaveBeenCalledWith(
jasmine.objectContaining({
text: jasmine.objectContaining({ label: expectedTxt, value: expectedTxt }),
origin: this.selectArgument || this.subject.ul.children[0]
})
);
});
describe("and awesomplete-select event was not prevented", function () {
beforeEach(function () {
$.on(this.subject.input, "awesomplete-select", $.noop);
});
it("changes the input value", function () {
this.subject.select(this.selectArgument);
expect(this.subject.input.value).toBe(expectedTxt);
});
it("closes completer", function () {
spyOn(this.subject, "close");
this.subject.select(this.selectArgument);
expect(this.subject.close).toHaveBeenCalledWith({
reason: "select"
});
});
it("fires awesomplete-selectcomplete event", function () {
var handler = $.spyOnEvent(this.subject.input, "awesomplete-selectcomplete");
this.subject.select(this.selectArgument);
expect(handler).toHaveBeenCalledWith(
jasmine.objectContaining({
text: jasmine.objectContaining({ label: expectedTxt, value: expectedTxt })
})
);
});
});
describe("and awesomplete-select event was prevented", function () {
beforeEach(function () {
$.on(this.subject.input, "awesomplete-select", function (evt) { evt.preventDefault() });
});
it("does not change the input value", function () {
this.subject.select(this.selectArgument);
expect(this.subject.input.value).toBe("ite");
});
it("does not close completer", function () {
spyOn(this.subject, "close");
this.subject.select(this.selectArgument);
expect(this.subject.close).not.toHaveBeenCalled();
});
it("does not fire awesomplete-selectcomplete event", function () {
var handler = $.spyOnEvent(this.subject.input, "awesomplete-selectcomplete");
this.subject.select(this.selectArgument);
expect(handler).not.toHaveBeenCalled();
});
});
}
function itDoesNotSelectAnyItem() {
it("does not change the input value", function () {
this.subject.select();
expect(this.subject.input.value).toBe("ite");
});
it("does not fire awesomplete-select event", function () {
var handler = $.spyOnEvent(this.subject.input, "awesomplete-select");
this.subject.select();
expect(handler).not.toHaveBeenCalled();
});
it("does not fire awesomplete-selectcomplete event", function () {
var handler = $.spyOnEvent(this.subject.input, "awesomplete-selectcomplete");
this.subject.select();
expect(handler).not.toHaveBeenCalled();
});
}
});
awesomplete-1.1.5+dfsg/test/api/selectedSpec.js 0000664 0000000 0000000 00000001660 14023456335 0021463 0 ustar 00root root 0000000 0000000 describe("awesomplete.selected", function () {
$.fixture("plain");
subject(function () {
return new Awesomplete("#plain", { list: ["item1", "item2", "item3"] });
});
describe("with newly created completer", function () {
it("is false", function () {
expect(this.subject.selected).toBe(false);
});
});
describe("with opened completer", function () {
beforeEach(function () {
this.subject.open();
$.type(this.subject.input, "ite");
});
describe("and no item selected", function () {
it("is false", function () {
expect(this.subject.selected).toBe(false);
});
});
describe("and some item selected", function () {
it("is true", function () {
this.subject.next();
expect(this.subject.selected).toBe(true);
});
});
});
describe("with closed completer", function () {
it("is false", function () {
this.subject.close();
expect(this.subject.selected).toBe(false);
});
});
});
awesomplete-1.1.5+dfsg/test/events/ 0000775 0000000 0000000 00000000000 14023456335 0017252 5 ustar 00root root 0000000 0000000 awesomplete-1.1.5+dfsg/test/events/blurSpec.js 0000664 0000000 0000000 00000000616 14023456335 0021372 0 ustar 00root root 0000000 0000000 describe("blur event", function () {
$.fixture("plain");
subject(function () { return new Awesomplete("#plain") });
it("closes completer", function () {
spyOn(Awesomplete.prototype, "close");
$.fire(this.subject.input, "blur");
expect(Awesomplete.prototype.close).toHaveBeenCalledWith(
{ reason: "blur" },
jasmine.any(document.createEvent("HTMLEvents").constructor)
);
});
});
awesomplete-1.1.5+dfsg/test/events/clickSpec.js 0000664 0000000 0000000 00000003312 14023456335 0021507 0 ustar 00root root 0000000 0000000 describe("click event", function () {
$.fixture("plain");
subject(function () {
return new Awesomplete("#plain", { list: ["item1", "item2", "item3"] });
});
def("li", function () { return this.subject.ul.children[1] });
beforeEach(function () {
$.type(this.subject.input, "ite");
spyOn(this.subject, "select");
});
describe("with ul target", function () {
def("target", function () { return this.subject.ul });
it("does not select item", function () {
$.fire(this.target, "click", { button: 0 });
expect(this.subject.select).not.toHaveBeenCalled();
});
});
describe("with li target", function () {
def("target", function () { return this.li });
describe("on left click", function () {
it("selects item", function () {
var event = $.fire(this.target, "click", { button: 0 });
expect(this.subject.select).toHaveBeenCalledWith(this.li, this.target, event);
});
});
describe("on right click", function () {
it("does not select item", function () {
$.fire(this.target, "click", { button: 2 });
expect(this.subject.select).not.toHaveBeenCalled();
});
});
});
describe("with child of li target", function () {
def("target", function () { return $("mark", this.li) });
describe("on left click", function () {
it("selects item", function () {
var event = $.fire(this.target, "click", { button: 0 });
expect(this.subject.select).toHaveBeenCalledWith(this.li, this.target, event);
expect(event.defaultPrevented).toBe(true);
});
});
describe("on right click", function () {
it("does not select item", function () {
$.fire(this.target, "click", { button: 2 });
expect(this.subject.select).not.toHaveBeenCalled();
});
});
});
});
awesomplete-1.1.5+dfsg/test/events/inputSpec.js 0000664 0000000 0000000 00000000470 14023456335 0021563 0 ustar 00root root 0000000 0000000 describe("input event", function () {
$.fixture("plain");
subject(function () { return new Awesomplete("#plain") });
it("rebuilds the list", function () {
spyOn(Awesomplete.prototype, "evaluate");
$.type(this.subject.input, "ite");
expect(Awesomplete.prototype.evaluate).toHaveBeenCalled();
});
});
awesomplete-1.1.5+dfsg/test/events/keydownSpec.js 0000664 0000000 0000000 00000004332 14023456335 0022105 0 ustar 00root root 0000000 0000000 describe("keydown event", function () {
$.fixture("plain");
subject(function () {
return new Awesomplete("#plain", { list: ["item1", "item2", "item3"] });
});
beforeEach(function () {
$.type(this.subject.input, "ite");
});
it("supports enter", function () {
this.subject.next();
spyOn(this.subject, "select");
$.keydown(this.subject.input, $.k.ENTER);
expect(this.subject.select).toHaveBeenCalled();
});
it("supports escape", function () {
spyOn(this.subject, "close");
$.keydown(this.subject.input, $.k.ESC);
expect(this.subject.close).toHaveBeenCalledWith({
reason: "esc"
});
});
it("supports down arrow", function () {
spyOn(this.subject, "next");
$.keydown(this.subject.input, $.k.DOWN);
expect(this.subject.next).toHaveBeenCalled();
});
it("supports up arrow", function () {
spyOn(this.subject, "previous");
$.keydown(this.subject.input, $.k.UP);
expect(this.subject.previous).toHaveBeenCalled();
});
it("ignores other keys", function() {
spyOn(this.subject, "select");
spyOn(this.subject, "close");
spyOn(this.subject, "next");
spyOn(this.subject, "previous");
$.keydown(this.subject.input, 111);
expect(this.subject.select).not.toHaveBeenCalled();
expect(this.subject.close).not.toHaveBeenCalled();
expect(this.subject.next).not.toHaveBeenCalled();
expect(this.subject.previous).not.toHaveBeenCalled();
});
it("does nothing if not opened", function () {
this.subject.close();
spyOn(this.subject, "next");
$.keydown(this.subject.input, $.k.DOWN);
expect(this.subject.next).not.toHaveBeenCalled();
});
it("does not select on tab", function () {
this.subject.next();
spyOn(this.subject, "select");
$.keydown(this.subject.input, $.k.TAB);
expect(this.subject.select).not.toHaveBeenCalled();
});
});
describe("tabSelect option true ", function () {
$.fixture("plain");
subject(function () {
return new Awesomplete("#plain", { list: ["item1", "item2", "item3"], tabSelect: true });
});
beforeEach(function () {
$.type(this.subject.input, "ite");
});
it("selects on tab", function () {
this.subject.next();
spyOn(this.subject, "select");
$.keydown(this.subject.input, $.k.TAB);
expect(this.subject.select).toHaveBeenCalled();
});
})
awesomplete-1.1.5+dfsg/test/events/mousedownSpec.js 0000664 0000000 0000000 00000004442 14023456335 0022447 0 ustar 00root root 0000000 0000000 describe("mousedown event", function () {
$.fixture("plain");
subject(function () {
return new Awesomplete("#plain", { list: ["item1", "item2", "item3"] });
});
def("li", function () { return this.subject.ul.children[1] });
beforeEach(function () {
$.type(this.subject.input, "ite");
spyOn(this.subject, "select");
});
describe("with ul target", function () {
def("target", function () { return this.subject.ul });
it("does not select item and keeps the input focussed", function () {
$.fire(this.target, "mousedown", { button: 0 });
expect(this.subject.select).not.toHaveBeenCalled();
expect(this.subject.input).toBe(document.activeElement);
});
});
describe("with li target", function () {
def("target", function () { return this.li });
describe("on left click", function () {
it("does not select item and keeps the input focussed", function () {
var event = $.fire(this.target, "mousedown", { button: 0 });
expect(this.subject.select).not.toHaveBeenCalled();
expect(event.defaultPrevented).toBe(true);
expect(this.subject.input).toBe(document.activeElement);
});
});
describe("on right click", function () {
it("does not select item and keeps the input focussed", function () {
var event = $.fire(this.target, "mousedown", { button: 2 });
expect(this.subject.select).not.toHaveBeenCalled();
expect(event.defaultPrevented).toBe(true);
expect(this.subject.input).toBe(document.activeElement);
});
});
});
describe("with child of li target", function () {
def("target", function () { return $("mark", this.li) });
describe("on left click", function () {
it("does not select item and keeps the input focussed", function () {
var event = $.fire(this.target, "mousedown", { button: 0 });
expect(this.subject.select).not.toHaveBeenCalled();
expect(event.defaultPrevented).toBe(true);
expect(this.subject.input).toBe(document.activeElement);
});
});
describe("on right click", function () {
it("does not select item and keeps the input focussed", function () {
var event = $.fire(this.target, "mousedown", { button: 2 });
expect(this.subject.select).not.toHaveBeenCalled();
expect(event.defaultPrevented).toBe(true);
expect(this.subject.input).toBe(document.activeElement);
});
});
});
});
awesomplete-1.1.5+dfsg/test/events/submitSpec.js 0000664 0000000 0000000 00000001107 14023456335 0021725 0 ustar 00root root 0000000 0000000 describe("form submit event", function () {
$.fixture("options");
subject(function () { return new Awesomplete("#inside-form") });
it("closes completer", function () {
spyOn(Awesomplete.prototype, "close");
// prevent full page reload in Firefox, which causes tests to stop running
$.on(this.subject.input.form, "submit", function (evt) { evt.preventDefault() });
$.fire(this.subject.input.form, "submit");
expect(Awesomplete.prototype.close).toHaveBeenCalledWith(
{ reason: "submit" },
jasmine.any(document.createEvent("HTMLEvents").constructor)
);
});
});
awesomplete-1.1.5+dfsg/test/fixtures/ 0000775 0000000 0000000 00000000000 14023456335 0017617 5 ustar 00root root 0000000 0000000 awesomplete-1.1.5+dfsg/test/fixtures/options.html 0000664 0000000 0000000 00000000767 14023456335 0022212 0 ustar 00root root 0000000 0000000
With
List
awesomplete-1.1.5+dfsg/test/fixtures/plain.html 0000664 0000000 0000000 00000000025 14023456335 0021605 0 ustar 00root root 0000000 0000000
awesomplete-1.1.5+dfsg/test/helpers/ 0000775 0000000 0000000 00000000000 14023456335 0017410 5 ustar 00root root 0000000 0000000 awesomplete-1.1.5+dfsg/test/helpers/bindSpec.js 0000664 0000000 0000000 00000003243 14023456335 0021477 0 ustar 00root root 0000000 0000000 describe("Awesomplete.$.bind", function () {
$.fixture("plain");
subject(function () {
return function () { Awesomplete.$.bind(this.element, this.events) };
});
describe("with invalid element", function () {
it("does nothing if element is undefined", function () {
this.element = undefined;
expect(this.subject).not.toThrow();
});
it("does nothing if element is null", function () {
this.element = null;
expect(this.subject).not.toThrow();
});
it("does nothing if element is false", function () {
this.element = false;
expect(this.subject).not.toThrow();
});
it("does nothing if element is 0", function () {
this.element = 0;
expect(this.subject).not.toThrow();
});
it("does nothing if element is empty string", function () {
this.element = "";
expect(this.subject).not.toThrow();
});
});
describe("with valid element", function () {
def("element", function () { return $("#plain") });
beforeEach(function () {
spyOn(this.element, "addEventListener");
});
it("adds event listeners for all events", function () {
this.events = { click: $.noop, input: $.noop };
this.subject();
expect(this.element.addEventListener).toHaveBeenCalledWith("click", this.events.click);
expect(this.element.addEventListener).toHaveBeenCalledWith("input", this.events.input);
});
it("adds single event listener for multiple events", function () {
this.events = { "click input": $.noop };
this.subject();
expect(this.element.addEventListener).toHaveBeenCalledWith("click", this.events["click input"]);
expect(this.element.addEventListener).toHaveBeenCalledWith("input", this.events["click input"]);
});
});
});
awesomplete-1.1.5+dfsg/test/helpers/createSpec.js 0000664 0000000 0000000 00000005576 14023456335 0022041 0 ustar 00root root 0000000 0000000 describe("Awesomplete.$.create", function () {
$.fixture("options");
subject(function () { return Awesomplete.$.create(this.tag, this.options || {}) });
def("tag", "div");
it("creates DOM element", function () {
expect(this.subject instanceof HTMLElement).toBe(true);
});
describe("with various tag names", function () {
it("creates element", function () {
this.tag = "ul";
expect(this.subject.tagName).toEqual("UL");
});
it("creates element", function () {
this.tag = "li";
expect(this.subject.tagName).toEqual("LI");
});
});
describe("without options", function () {
it("creates element without any attributes", function () {
expect(this.subject.attributes.length).toEqual(0);
});
});
describe("with simple options", function () {
it("assigns properties", function () {
this.options = { id: "id1", className: "class-name" };
expect(this.subject.id).toEqual("id1");
expect(this.subject.className).toEqual("class-name");
});
it("assigns attributes", function () {
this.options = { attr1: "val1", attr2: "val2" };
expect(this.subject.getAttribute("attr1")).toEqual("val1");
expect(this.subject.getAttribute("attr2")).toEqual("val2");
});
});
describe("with option for boolean attribute/property", function () {
it("assigns from true value", function () {
this.options = { hidden: true };
expect(this.subject.hasAttribute("hidden")).toBe(true);
});
it("assigns from truthy value", function () {
this.options = { hidden: "hidden" };
expect(this.subject.hasAttribute("hidden")).toBe(true);
});
it("assigns from false value", function () {
this.options = { hidden: false };
expect(this.subject.hasAttribute("hidden")).toBe(false);
});
it("assigns from falsy value", function () {
this.options = { hidden: "" };
expect(this.subject.hasAttribute("hidden")).toBe(false);
});
});
describe("with inside: option", function () {
it("appends to container by element", function () {
this.options = { inside: $("#data-list") };
expect(this.subject).toEqual(this.options.inside.lastChild);
});
it("appends to container by selector", function () {
this.options = { inside: "#data-list" };
expect(this.subject).toEqual($(this.options.inside).lastChild);
});
});
describe("with around: option", function () {
it("wraps specified element", function () {
this.options = { around: $("#no-options") };
var originalParent = this.options.around.parentNode;
expect(this.subject.parentNode).toEqual(originalParent);
expect(this.subject.firstChild).toEqual(this.options.around);
});
it("wraps element specified by selector", function () {
this.options = { around: "#no-options" };
var originalParent = $(this.options.around).parentNode;
expect(this.subject.parentNode).toEqual(originalParent);
expect(this.subject.firstChild).toEqual($(this.options.around));
});
});
});
awesomplete-1.1.5+dfsg/test/helpers/dollarSpec.js 0000664 0000000 0000000 00000003054 14023456335 0022040 0 ustar 00root root 0000000 0000000 describe("Awesomplete.$", function () {
$.fixture("options");
subject(function () { return Awesomplete.$(this.expression, this.context) });
describe("with default context", itFindsElement);
describe("with custom context", function () {
def("context", function () { return fixture.el });
itFindsElement();
});
describe("with truthy non string expression", function () {
it("returns the expression back", function () {
this.expression = $("#no-options");
expect(this.subject).toBe(this.expression);
});
});
describe("with falsy non string expression", function () {
it("returns null if expression is undefined", function () {
this.expression = undefined;
expect(this.subject).toBeNull();
});
it("returns null if expression is null", function () {
this.expression = null;
expect(this.subject).toBeNull();
});
it("returns null if expression is false", function () {
this.expression = false;
expect(this.subject).toBeNull();
});
});
// Shared behaviors
function itFindsElement() {
it("returns DOM element", function () {
this.expression = "#no-options";
expect(this.subject instanceof HTMLElement).toBe(true);
});
it("finds by id", function () {
this.expression = "#no-options";
expect(this.subject.id).toEqual("no-options");
});
it("finds by class name", function () {
this.expression = ".simple-input";
expect(this.subject.id).toEqual("no-options");
});
it("finds by tag name", function () {
this.expression = "datalist";
expect(this.subject.id).toEqual("list");
});
}
});
awesomplete-1.1.5+dfsg/test/helpers/doubleDollarSpec.js 0000664 0000000 0000000 00000002410 14023456335 0023166 0 ustar 00root root 0000000 0000000 describe("Awesomplete.$$", function () {
$.fixture("options");
subject(function () { return Awesomplete.$$(this.expression, this.context) });
describe("with default context", itFindsAllElements);
describe("with custom context", function () {
def("context", function () { return fixture.el });
itFindsAllElements();
});
// Shared behaviors
function itFindsAllElements() {
it("returns an array of DOM elements", function () {
this.expression = "#no-options";
expect(this.subject).toEqual(jasmine.any(Array));
expect(this.subject[0] instanceof HTMLElement).toBe(true);
});
it("finds all elements", function () {
this.expression = "input";
expect(this.subject.length).toEqual($$("input").length);
});
it("finds DOM element", function () {
this.expression = "#no-options";
expect(this.subject[0] instanceof HTMLElement).toBe(true);
});
it("finds by id", function () {
this.expression = "#no-options";
expect(this.subject[0].id).toEqual("no-options");
});
it("finds by class name", function () {
this.expression = ".simple-input";
expect(this.subject[0].id).toEqual("no-options");
});
it("finds by tag name", function () {
this.expression = "datalist";
expect(this.subject[0].id).toEqual("list");
});
}
});
awesomplete-1.1.5+dfsg/test/helpers/fireSpec.js 0000664 0000000 0000000 00000003644 14023456335 0021515 0 ustar 00root root 0000000 0000000 describe("Awesomplete.$.fire", function () {
$.fixture("plain");
subject(function () {
return Awesomplete.$.fire.bind(Awesomplete.$, this.element);
});
def("element", function () { return $("#plain") });
beforeEach(function () {
spyOn(this.element, "dispatchEvent");
});
it("fires event once", function () {
this.subject("click");
expect(this.element.dispatchEvent.calls.count()).toEqual(1);
});
describe("fires different event types", function () {
it("fires click event", function () {
this.subject("click");
expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining({ type: "click" }));
});
it("fires input event", function () {
this.subject("input");
expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining({ type: "input" }));
});
});
describe("sets event properties", function () {
it("makes cancelable event", function () {
this.subject("click");
expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining({ cancelable: true }));
});
it("can't make non cancelable event", function () {
this.subject("click", { cancelable: false });
expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining({ cancelable: true }));
});
it("makes event that bubbles", function () {
this.subject("click");
expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining({ bubbles: true }));
});
it("can't make event that does not bubble", function () {
this.subject("click", { bubbles: false });
expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining({ bubbles: true }));
});
it("sets properties on the event", function () {
var properties = { text: "hello", preventDefault: $.noop };
this.subject("click", properties);
expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining(properties));
});
});
});
awesomplete-1.1.5+dfsg/test/helpers/regExpEscapeSpec.js 0000664 0000000 0000000 00000002037 14023456335 0023136 0 ustar 00root root 0000000 0000000 describe("Awesomplete.$.regExpEscape", function () {
subject(function () { return Awesomplete.$.regExpEscape(this.str) });
describe("with regular expression special characters", function () {
it("escapes backslashes", function () {
this.str = "\\";
expect(this.subject).toBe("\\\\");
});
it("escapes brackets, braces and parentheses", function () {
this.str = "[]{}()";
expect(this.subject).toBe("\\[\\]\\{\\}\\(\\)");
});
it("escapes other special characters", function () {
this.str = "-^$*+?.|";
expect(this.subject).toBe("\\-\\^\\$\\*\\+\\?\\.\\|");
});
it("escapes the whole string", function () {
this.str = "**";
expect(this.subject).toBe("\\*\\*");
});
});
describe("with plain characters", function () {
it("does not escape letters", function () {
this.str = "abcdefjhijklmnopqrstuvwxyzABCDEFJHIJKLMNOPQRSTUVWXYZ";
expect(this.subject).toBe(this.str);
});
it("does not escape numbers", function () {
this.str = "0123456789";
expect(this.subject).toBe(this.str);
});
});
});
awesomplete-1.1.5+dfsg/test/helpers/unbindSpec.js 0000664 0000000 0000000 00000003274 14023456335 0022046 0 ustar 00root root 0000000 0000000 describe("Awesomplete.$.unbind", function () {
$.fixture("plain");
subject(function () {
return function () { Awesomplete.$.unbind(this.element, this.events) };
});
describe("with invalid element", function () {
it("does nothing if element is undefined", function () {
this.element = undefined;
expect(this.subject).not.toThrow();
});
it("does nothing if element is null", function () {
this.element = null;
expect(this.subject).not.toThrow();
});
it("does nothing if element is false", function () {
this.element = false;
expect(this.subject).not.toThrow();
});
it("does nothing if element is 0", function () {
this.element = 0;
expect(this.subject).not.toThrow();
});
it("does nothing if element is empty string", function () {
this.element = "";
expect(this.subject).not.toThrow();
});
});
describe("with valid element", function () {
def("element", function () { return $("#plain") });
beforeEach(function () {
spyOn(this.element, "removeEventListener");
});
it("removes event listeners for all events", function () {
this.events = { click: $.noop, input: $.noop };
this.subject();
expect(this.element.removeEventListener).toHaveBeenCalledWith("click", this.events.click);
expect(this.element.removeEventListener).toHaveBeenCalledWith("input", this.events.input);
});
it("removes single event listener for multiple events", function () {
this.events = { "click input": $.noop };
this.subject();
expect(this.element.removeEventListener).toHaveBeenCalledWith("click", this.events["click input"]);
expect(this.element.removeEventListener).toHaveBeenCalledWith("input", this.events["click input"]);
});
});
});
awesomplete-1.1.5+dfsg/test/init/ 0000775 0000000 0000000 00000000000 14023456335 0016711 5 ustar 00root root 0000000 0000000 awesomplete-1.1.5+dfsg/test/init/htmlSpec.js 0000664 0000000 0000000 00000003560 14023456335 0021032 0 ustar 00root root 0000000 0000000 describe("Html modifications", function () {
$.fixture("plain");
subject(function () { return new Awesomplete("#plain") });
it("binds to correct input", function () {
expect(this.subject.input instanceof HTMLElement).toBe(true);
expect(this.subject.input.id).toBe("plain");
});
it("turns native autocompleter off", function () {
expect(this.subject.input.getAttribute("autocomplete")).toBe("off");
});
describe("HTML tweaks", function () {
it("creates container", function () {
expect(this.subject.container instanceof HTMLElement).toBe(true);
expect(this.subject.container.className).toBe("awesomplete");
});
it("places input inside container", function () {
expect(this.subject.input.parentNode).toBe(this.subject.container);
});
it("creates list", function () {
expect(this.subject.ul instanceof HTMLElement).toBe(true);
expect(this.subject.ul.tagName).toBe("UL");
});
it("puts list inside container", function () {
expect(this.subject.ul.parentNode).toBe(this.subject.container);
});
it("hides list", function () {
expect(this.subject.ul.hasAttribute("hidden")).toBe(true);
});
});
describe("ARIA support", function () {
it("makes input accessible", function () {
expect(this.subject.input.getAttribute("role")).toBe("combobox");
expect(this.subject.input.getAttribute("aria-owns")).toMatch(/awesomplete_list_[0-9]+/);
});
it("creates status", function () {
expect(this.subject.status instanceof HTMLElement).toBe(true);
expect(this.subject.status.getAttribute("role")).toBe("status");
expect(this.subject.status.getAttribute("aria-live")).toBe("assertive");
});
it("puts status inside container", function () {
expect(this.subject.status.parentNode).toBe(this.subject.container);
});
it("hides status", function () {
expect(this.subject.status.className).toBe("visually-hidden");
});
});
});
awesomplete-1.1.5+dfsg/test/init/listSpec.js 0000664 0000000 0000000 00000006617 14023456335 0021047 0 ustar 00root root 0000000 0000000 describe("Awesomplete list", function () {
$.fixture("options");
subject(function () { return new Awesomplete(this.element, this.options) });
def("element", "#no-options");
it("is empty if not provided", function () {
expect(this.subject._list).toEqual([]);
});
describe("setter", function () {
it("assigns from array", function () {
this.subject.list = [ "From", "Array" ];
expect(this.subject._list).toEqual([ "From", "Array" ]);
});
it("assigns from comma separated list", function () {
this.subject.list = "From, Inline, List";
expect(this.subject._list).toEqual([ "From", "Inline", "List" ]);
});
it("assigns from element specified by selector", function () {
this.subject.list = "#data-list";
expect(this.subject._list).toEqual([
{ label: "With", value: "With" },
{ label: "Data", value: "Data" },
{ label: "List", value: "List" }
]);
});
it("assigns from element", function () {
this.subject.list = $("#data-list");
expect(this.subject._list).toEqual([
{ label: "With", value: "With" },
{ label: "Data", value: "Data" },
{ label: "List", value: "List" }
]);
});
it("does not assigns from not found list", function () {
this.subject.list = "#nosuchlist";
expect(this.subject._list).toEqual([]);
});
it("does not assigns from empty list", function () {
this.subject.list = "#empty-list";
expect(this.subject._list).toEqual([]);
});
describe("with active input", function() {
beforeEach(function() {
this.subject.input.focus();
});
it("evaluates completer", function() {
spyOn(this.subject, "evaluate");
this.subject.list = "#data-list";
expect(this.subject.evaluate).toHaveBeenCalled();
});
});
});
describe("constructor option", function () {
it("assigns from array", function () {
this.options = { list: [ "From", "Array" ] };
expect(this.subject._list).toEqual([ "From", "Array" ]);
});
it("assigns from comma separated list", function () {
this.options = { list: "From, Inline, List" };
expect(this.subject._list).toEqual([ "From", "Inline", "List" ]);
});
it("assigns from element specified by selector", function () {
this.options = { list: "#data-list" };
expect(this.subject._list).toEqual([
{ label: "With", value: "With" },
{ label: "Data", value: "Data" },
{ label: "List", value: "List" }
]);
});
it("assigns from list specified by element", function () {
this.options = { list: $("#data-list") };
expect(this.subject._list).toEqual([
{ label: "With", value: "With" },
{ label: "Data", value: "Data" },
{ label: "List", value: "List" }
]);
});
});
describe("data-list html attribute", function () {
it("assigns from comma separated list", function () {
this.element = "#with-data-list-inline";
expect(this.subject._list).toEqual(["With", "Data", "List", "Inline"]);
});
it("assigns from element referenced by selector", function () {
this.element = "#with-data-list";
expect(this.subject._list).toEqual([
{ label: "With", value: "With" },
{ label: "Data", value: "Data" },
{ label: "List", value: "List" }
]);
});
});
describe("list html attribute", function () {
it("assigns from element referenced by id", function () {
this.element = "#with-list";
expect(this.subject._list).toEqual([
{ label: "With", value: "With" },
{ label: "List", value: "List" }
]);
});
});
});
awesomplete-1.1.5+dfsg/test/init/optionsSpec.js 0000664 0000000 0000000 00000004304 14023456335 0021556 0 ustar 00root root 0000000 0000000 describe("Constructor options", function () {
$.fixture("options");
subject(function () { return new Awesomplete(this.element, this.options) });
describe("with default options", function () {
def("element", "#with-data-list");
it("requires minimum 2 chars to open completer", function () {
expect(this.subject.minChars).toBe(2);
});
it("shows 10 items in completer", function () {
expect(this.subject.maxItems).toBe(10);
});
it("does not select the first ocurrence automatically" , function () {
expect(this.subject.autoFirst).toBe(false);
});
it("modifies list item with DATA", function () {
expect(this.subject.data).toBe(Awesomplete.DATA);
});
it("filters with FILTER_CONTAINS", function () {
expect(this.subject.filter).toBe(Awesomplete.FILTER_CONTAINS);
});
it("orders with SORT_BYLENGTH", function () {
expect(this.subject.sort).toBe(Awesomplete.SORT_BYLENGTH);
});
it("creates item with ITEM", function () {
expect(this.subject.item).toEqual(Awesomplete.ITEM);
});
it("replaces input value with REPLACE", function () {
expect(this.subject.replace).toEqual(Awesomplete.REPLACE);
});
});
describe("with custom options in constructor", function () {
def("element", "#with-data-list");
def("options", function () {
return {
minChars: 3,
maxItems: 9,
autoFirst: true,
filter: $.noop,
sort: $.noop,
item: $.noop,
replace: $.noop
};
});
it("overrides simple default options", function () {
expect(this.subject.minChars).toBe(3);
expect(this.subject.maxItems).toBe(9);
expect(this.subject.autoFirst).toBe(true);
});
it("overrides default functions", function () {
expect(this.subject.filter).toBe(this.options.filter);
expect(this.subject.sort).toBe(this.options.sort);
expect(this.subject.item).toBe(this.options.item);
expect(this.subject.replace).toBe(this.options.replace);
});
});
describe("with custom options in data-* attributes", function () {
def("element", "#with-custom-options");
it("overrides simple default options", function () {
expect(this.subject.minChars).toBe(4);
expect(this.subject.maxItems).toBe(8);
expect(this.subject.autoFirst).toBe(true);
});
});
});
awesomplete-1.1.5+dfsg/test/specHelper.js 0000664 0000000 0000000 00000003030 14023456335 0020372 0 ustar 00root root 0000000 0000000 fixture.setBase("test/fixtures");
// finds DOM elements in tests
function $ (str, context) {
return (context || fixture.el).querySelector(str);
}
function $$ (str, context) {
return (context || fixture.el).querySelectorAll(str);
}
// bundled fixture load/cleanup
$.fixture = function (fixtureName) {
beforeEach(function () {
// Awesomplete probably needs to cleanup this by itself
try { Awesomplete.all = []; } catch(e) {};
fixture.load(fixtureName + ".html");
});
afterEach(function () {
fixture.cleanup();
});
};
// spy to check if event was fired or not
$.spyOnEvent = function (target, type) {
var handler = jasmine.createSpy(type);
$.on(target, type, handler);
return handler;
};
$.on = function (target, type, callback) {
target.addEventListener(type, callback);
};
$.fire = function (target, type, properties) {
var evt = document.createEvent("HTMLEvents");
evt.initEvent(type, true, true );
for (var j in properties) {
evt[j] = properties[j];
}
target.dispatchEvent(evt);
return evt;
};
// simulates text input (very simple, only "input" event is fired)
$.type = function (input, text) {
input.focus();
input.value = text;
return $.fire(input, "input");
};
// simulates keydown events
$.keydown = function (target, keyCode) {
return $.fire(target, "keydown", { keyCode: keyCode });
};
$.k = {
TAB: 9,
ENTER: 13,
ESC: 27,
DOWN: 40,
UP: 38
};
// $.noop returns a new empty function each time it's being called
Object.defineProperty($, "noop", {
get: function () {
return function noop () {}
}
});
awesomplete-1.1.5+dfsg/test/static/ 0000775 0000000 0000000 00000000000 14023456335 0017235 5 ustar 00root root 0000000 0000000 awesomplete-1.1.5+dfsg/test/static/allSpec.js 0000664 0000000 0000000 00000001102 14023456335 0021150 0 ustar 00root root 0000000 0000000 describe("Awesomplete.all", function () {
$.fixture("options");
subject(function () { return Awesomplete.all });
it("is empty initially", function () {
expect(this.subject.length).toBe(0);
});
it("keeps a list of created instances", function () {
var first = new Awesomplete("#with-data-list-inline");
expect(this.subject.length).toBe(1);
expect(this.subject).toContain(first);
var second = new Awesomplete("#with-data-list");
expect(this.subject.length).toBe(2);
expect(this.subject).toContain(first);
expect(this.subject).toContain(second);
});
});
awesomplete-1.1.5+dfsg/test/static/dataSpec.js 0000664 0000000 0000000 00000001050 14023456335 0021313 0 ustar 00root root 0000000 0000000 describe("Awesomplete.DATA", function () {
subject(function () { return Awesomplete.DATA(this.item) });
it("returns original String", function () {
this.item = "JavaScript";
expect(this.subject).toEqual("JavaScript");
});
it("returns original Object", function () {
this.item = { label: "JavaScript", value: "JS" };
expect(this.subject).toEqual({ label: "JavaScript", value: "JS" });
});
it("returns original Array", function () {
this.item = [ "JavaScript", "JS" ];
expect(this.subject).toEqual([ "JavaScript", "JS" ]);
});
});
awesomplete-1.1.5+dfsg/test/static/filterContainsSpec.js 0000664 0000000 0000000 00000003424 14023456335 0023375 0 ustar 00root root 0000000 0000000 describe("Awesomplete.FILTER_CONTAINS", function () {
subject(function () { return Awesomplete.FILTER_CONTAINS });
describe("search in a plain string", function () {
it("matches at the start", function () {
expect(this.subject("Hello world", "Hello")).toBe(true);
});
it("matches in the middle", function () {
expect(this.subject("Ticket to the moon", "to the")).toBe(true);
});
it("matches at the end", function () {
expect(this.subject("This is the end", "end")).toBe(true);
});
it("performs case insensitive match", function () {
expect(this.subject("Hey You", "HEY YOU")).toBe(true);
});
it("ignores whitespaces around the search value", function () {
expect(this.subject("Watch this", " Watch ")).toBe(true);
});
it("does not match if substring is not found", function () {
expect(this.subject("No", "way")).toBe(false);
});
});
describe("search in string with special RegExp chars", function () {
it("matches at the start", function () {
expect(this.subject("[^j(a)v?a-sc|ri\\p+t*]{.$}", "[^j(a)v?a-")).toBe(true);
});
it("matches in the middle", function () {
expect(this.subject("[^j(a)v?a-sc|ri\\p+t*]{.$}", "sc|ri\\p+t*")).toBe(true);
});
it("matches at the end", function () {
expect(this.subject("[^j(a)v?a-sc|ri\\p+t*]{.$}", "{.$}")).toBe(true);
});
it("performs case insensitive match", function () {
expect(this.subject("[^j(a)v?a-sc|ri\\p+t*]{.$}", "[^J(A)V?A-SC|RI\\P+T*]{.$}")).toBe(true);
});
it("ignores whitespaces around the search value", function () {
expect(this.subject("[^j(a)v?a-sc|ri\\p+t*]{.$}", " [^j(a)v?a- ")).toBe(true);
});
it("does not match if substring is not found", function () {
expect(this.subject("[^j(a)v?a-sc|ri\\p+t*]{.$}", "no way")).toBe(false);
});
});
});
awesomplete-1.1.5+dfsg/test/static/filterStartsWithSpec.js 0000664 0000000 0000000 00000003466 14023456335 0023741 0 ustar 00root root 0000000 0000000 describe("Awesomplete.FILTER_STARTSWITH", function () {
subject(function () { return Awesomplete.FILTER_STARTSWITH });
describe("search in plain string", function () {
it("matches at the start", function () {
expect(this.subject("Hello world", "Hello")).toBe(true);
});
it("does not match in the middle", function () {
expect(this.subject("Ticket to the moon", "to the")).toBe(false);
});
it("does not match at the end", function () {
expect(this.subject("This is the end", "end")).toBe(false);
});
it("performs case insensitive match", function () {
expect(this.subject("Hey You", "HEY YOU")).toBe(true);
});
it("ignores whitespaces around the search value", function () {
expect(this.subject("Watch this", " Watch ")).toBe(true);
});
it("does not match if substring is not found", function () {
expect(this.subject("No", "way")).toBe(false);
});
});
describe("search in string with special RegExp chars", function () {
it("matches at the start", function () {
expect(this.subject("[^j(a)v?a-sc|ri\\p+t*]{.$}", "[^j(a)v?a-")).toBe(true);
});
it("does not match in the middle", function () {
expect(this.subject("[^j(a)v?a-sc|ri\\p+t*]{.$}", "sc|ri\\p+t*")).toBe(false);
});
it("does not match at the end", function () {
expect(this.subject("[^j(a)v?a-sc|ri\\p+t*]{.$}", "{.$}")).toBe(false);
});
it("performs case insensitive match", function () {
expect(this.subject("[^j(a)v?a-sc|ri\\p+t*]{.$}", "[^J(A)V?A-SC|RI\\P+T*]{.$}")).toBe(true);
});
it("ignores whitespaces around the search value", function () {
expect(this.subject("[^j(a)v?a-sc|ri\\p+t*]{.$}", " [^j(a)v?a- ")).toBe(true);
});
it("does not match if substring is not found", function () {
expect(this.subject("[^j(a)v?a-sc|ri\\p+t*]{.$}", "no way")).toBe(false);
});
});
});
awesomplete-1.1.5+dfsg/test/static/itemSpec.js 0000664 0000000 0000000 00000002616 14023456335 0021351 0 ustar 00root root 0000000 0000000 describe("Awesomplete.ITEM", function () {
subject(function () { return Awesomplete.ITEM });
def("element", function () { return this.subject("JavaScript", this.input || "") });
it("creates DOM element", function () {
expect(this.element instanceof HTMLElement).toBe(true);
});
it("creates LI element", function () {
expect(this.element.tagName).toBe("LI");
});
it("sets aria-selected to false", function () {
expect(this.element.getAttribute("aria-selected")).toBe("false");
});
describe("with matched input", function () {
def("input", "jav");
it("marks the match", function () {
expect(this.element.innerHTML).toBe("Jav aScript");
});
});
describe("with multiple matches", function () {
def("input", "a");
it("marks all matches", function () {
expect(this.element.innerHTML).toBe("Ja va Script");
});
});
describe("with no match", function () {
def("input", "foo");
it("does not mark anything", function () {
expect(this.element.innerHTML).toBe("JavaScript");
});
});
describe("with empty input", function () {
def("input", "");
it("does not mark anything", function () {
expect(this.element.innerHTML).toBe("JavaScript");
});
});
describe("with space input", function () {
def("input", " ");
it("does not mark anything", function () {
expect(this.element.innerHTML).toBe("JavaScript");
});
});
});
awesomplete-1.1.5+dfsg/test/static/replaceSpec.js 0000664 0000000 0000000 00000000530 14023456335 0022017 0 ustar 00root root 0000000 0000000 describe("Awesomplete.REPLACE", function () {
subject(function () { return Awesomplete.REPLACE });
def("instance", function() { return { input: { value: "initial" } } });
it("replaces input value", function () {
this.subject.call(this.instance, { value: "JavaScript" });
expect(this.instance.input.value).toBe("JavaScript");
});
});
awesomplete-1.1.5+dfsg/test/static/sortByLengthSpec.js 0000664 0000000 0000000 00000003207 14023456335 0023034 0 ustar 00root root 0000000 0000000 describe("Awesomplete.SORT_BYLENGTH", function () {
subject(function () { return Awesomplete.SORT_BYLENGTH });
describe("with strings of different length", function () {
it("returns negative number if the first string is shorter", function () {
expect(this.subject("a", "aa")).toBe(-1);
expect(this.subject("a", "bb")).toBe(-1);
expect(this.subject("b", "aa")).toBe(-1);
expect(this.subject("a", "aaa")).toBe(-2);
expect(this.subject("a", "bbb")).toBe(-2);
expect(this.subject("b", "aaa")).toBe(-2);
});
it("returns positive number if the first string is longer", function () {
expect(this.subject("aa", "a")).toBe(1);
expect(this.subject("bb", "a")).toBe(1);
expect(this.subject("aa", "b")).toBe(1);
expect(this.subject("aaa", "a")).toBe(2);
expect(this.subject("bbb", "a")).toBe(2);
expect(this.subject("aaa", "b")).toBe(2);
});
});
describe("with strings of the same length", function () {
it("returns -1 if the first string < second string", function () {
expect(this.subject("a", "b")).toBe(-1);
expect(this.subject("aa", "bb")).toBe(-1);
expect(this.subject("aaa", "bbb")).toBe(-1);
});
it("returns 1 if the first string > second string", function () {
expect(this.subject("b", "a")).toBe(1);
expect(this.subject("bb", "aa")).toBe(1);
expect(this.subject("bbb", "aaa")).toBe(1);
});
// FIXME SORT_BYLENGTH should probably return 0 like classic string comparison
it("returns 1 if the first string == second string", function () {
expect(this.subject("a", "a")).toBe(1);
expect(this.subject("aa", "aa")).toBe(1);
expect(this.subject("aaa", "aaa")).toBe(1);
});
});
});