summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--awesomplete.js35
-rw-r--r--index.html5
-rw-r--r--package.json19
3 files changed, 50 insertions, 9 deletions
diff --git a/awesomplete.js b/awesomplete.js
index 442bfd1..4053101 100644
--- a/awesomplete.js
+++ b/awesomplete.js
@@ -7,7 +7,7 @@
(function () {
-var _ = self.Awesomplete = function (input, o) {
+var _ = function (input, o) {
var me = this;
// Setup
@@ -184,6 +184,8 @@ _.prototype = {
lis[i].setAttribute("aria-selected", "true");
this.status.textContent = lis[i].textContent;
}
+
+ $.fire(this.input, "awesomplete-highlight");
},
select: function (selected) {
@@ -356,16 +358,31 @@ function init() {
});
}
-// DOM already loaded?
-if (document.readyState !== "loading") {
- init();
-}
-else {
- // Wait for it
- document.addEventListener("DOMContentLoaded", init);
+// 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);
+ }
}
_.$ = $;
_.$$ = $$;
-})();
+// Make sure to export Awesomplete on self when in a browser
+if (typeof self !== 'undefined') {
+ self.Awesomplete = _;
+}
+
+// Expose Awesomplete as a CJS module
+if (typeof exports === 'object') {
+ module.exports = _;
+}
+
+return _;
+
+}());
diff --git a/index.html b/index.html
index 9059604..0710845 100644
--- a/index.html
+++ b/index.html
@@ -271,6 +271,11 @@ awesomplete.list = ["Ada", "Java", "JavaScript", "Brainfuck", "LOLCODE", "Node.j
<td>The popup just closed.</td>
<td>No</td>
</tr>
+ <tr>
+ <td><code>awesomplete-highlight</code></td>
+ <td>The highlighted item just changed (in response to pressing an arrow key or via an API call).</td>
+ <td>No</td>
+ </tr>
</tbody>
</table>
</section>
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..148cdec
--- /dev/null
+++ b/package.json
@@ -0,0 +1,19 @@
+{
+ "name": "awesomplete",
+ "version": "1.0.0",
+ "description": "http://leaverou.github.io/awesomplete/",
+ "main": "awesomplete.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/LeaVerou/awesomplete.git"
+ },
+ "author": "",
+ "license": "ISC",
+ "bugs": {
+ "url": "https://github.com/LeaVerou/awesomplete/issues"
+ },
+ "homepage": "https://github.com/LeaVerou/awesomplete"
+}