diff --git a/.editorconfig b/.editorconfig index 3af8e36..f103b3e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,5 +11,3 @@ insert_final_newline = true [package.json] indent_size = 2 -[bower.json] -indent_size = 2 diff --git a/.gitignore b/.gitignore index 2fd83a6..485dee6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ .idea -node_modules -dist diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 51be4e7..0000000 --- a/.jshintrc +++ /dev/null @@ -1,87 +0,0 @@ -{ - // JSHint Default Configuration File (as on JSHint website) - // See http://jshint.com/docs/ for more details - - "maxerr" : 50, // {int} Maximum error before stopping - - // Enforcing - "bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.) - "camelcase" : false, // true: Identifiers must be in camelCase - "curly" : true, // true: Require {} for every new block or scope - "eqeqeq" : true, // true: Require triple equals (===) for comparison - "forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty() - "freeze" : true, // true: prohibits overwriting prototypes of native objects such as Array, Date etc. - "immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());` - "indent" : 4, // {int} Number of spaces to use for indentation - "latedef" : false, // true: Require variables/functions to be defined before being used - "newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()` - "noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee` - "noempty" : true, // true: Prohibit use of empty blocks - "nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters. - "nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment) - "plusplus" : false, // true: Prohibit use of `++` & `--` - "quotmark" : false, // Quotation mark consistency: - // false : do nothing (default) - // true : ensure whatever is used is consistent - // "single" : require single quotes - // "double" : require double quotes - "undef" : true, // true: Require all non-global variables to be declared (prevents global leaks) - "unused" : true, // true: Require all defined variables be used - "strict" : true, // true: Requires all functions run in ES5 Strict Mode - "maxparams" : false, // {int} Max number of formal params allowed per function - "maxdepth" : false, // {int} Max depth of nested blocks (within functions) - "maxstatements" : false, // {int} Max number statements per function - "maxcomplexity" : false, // {int} Max cyclomatic complexity per function - "maxlen" : false, // {int} Max number of characters per line - - // Relaxing - "asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons) - "boss" : false, // true: Tolerate assignments where comparisons would be expected - "debug" : false, // true: Allow debugger statements e.g. browser breakpoints. - "eqnull" : false, // true: Tolerate use of `== null` - "es5" : false, // true: Allow ES5 syntax (ex: getters and setters) - "esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`) - "moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features) - // (ex: `for each`, multiple try/catch, function expression…) - "evil" : false, // true: Tolerate use of `eval` and `new Function()` - "expr" : false, // true: Tolerate `ExpressionStatement` as Programs - "funcscope" : false, // true: Tolerate defining variables inside control statements - "globalstrict" : false, // true: Allow global "use strict" (also enables 'strict') - "iterator" : false, // true: Tolerate using the `__iterator__` property - "lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block - "laxbreak" : false, // true: Tolerate possibly unsafe line breakings - "laxcomma" : false, // true: Tolerate comma-first style coding - "loopfunc" : false, // true: Tolerate functions being defined in loops - "multistr" : false, // true: Tolerate multi-line strings - "noyield" : false, // true: Tolerate generator functions with no yield statement in them. - "notypeof" : false, // true: Tolerate invalid typeof operator values - "proto" : false, // true: Tolerate using the `__proto__` property - "scripturl" : false, // true: Tolerate script-targeted URLs - "shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;` - "sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation - "supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;` - "validthis" : false, // true: Tolerate using this in a non-constructor function - - // Environments - "browser" : true, // Web Browser (window, document, etc) - "browserify" : false, // Browserify (node.js code in the browser) - "couch" : false, // CouchDB - "devel" : true, // Development/debugging (alert, confirm, etc) - "dojo" : false, // Dojo Toolkit - "jasmine" : false, // Jasmine - "jquery" : false, // jQuery - "mocha" : true, // Mocha - "mootools" : false, // MooTools - "node" : false, // Node.js - "nonstandard" : false, // Widely adopted globals (escape, unescape, etc) - "prototypejs" : false, // Prototype and Scriptaculous - "qunit" : false, // QUnit - "rhino" : false, // Rhino - "shelljs" : false, // ShellJS - "worker" : false, // Web Workers - "wsh" : false, // Windows Scripting Host - "yui" : false, // Yahoo User Interface - - // Custom Globals - "globals" : {} // additional predefined global variables -} diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index 6bf3552..0000000 --- a/Gruntfile.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = function (grunt) { - require('load-grunt-config')(grunt); -}; diff --git a/LICENSE b/LICENSE index 25d7b94..c6c7def 100644 --- a/LICENSE +++ b/LICENSE @@ -1,11 +1,13 @@ -DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE -Version 2, December 2004 + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 -Copyright (C) 2004 Sam Hocevar + Copyright (C) 2004 Sam Hocevar -Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. -DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE -TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION -0. You just DO WHAT THE FUCK YOU WANT TO. + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/README.md b/README.md index 55dc31e..a04dfb4 100644 --- a/README.md +++ b/README.md @@ -2,27 +2,29 @@ ___ # autohide-cursor -Tiny no-dependency library that will automatically hide the cursor after a given time of mouse inactivity. -## Installation -Simply use bower to grab the latest version: +Tiny no-dependency library that will automatically hide the cursor after a given time of mouse inactivity. No build +tools, no bundlers, nothing. - bower install autohide-cursor +## Installation -## Usage -Add a script tag to your HTML that loads autohide-cursor.min.js. You can configure the delay with a -data-attributes on the script tag itself. This is optional, though. Please do *not* use the async attribute :). +This is a ECMAScript Module. You can either install it via npm or simply take it from unpkg. - +todo: put in some URLs here :) -By default, autohide-cursor will hide the cursor whenever the user did not move the mouse for **1000 milliseconds**. -As soon as the user moves the mouse again, the cursor is visible again. +## Usage -## Build -Build the minified version (with source map) into the dist directory: +If you're fine with the 1 seconds default delay, simply do: - grunt +```html + +``` -Developer mode with livereload (press CTRL+C in the console to cancel): +If you want to control the delay yourself, you can import `autohideCursor` function directly and pass your custom value: - grunt dev +```html + +``` diff --git a/autohide-cursor.js b/autohide-cursor.js new file mode 100644 index 0000000..e37ba21 --- /dev/null +++ b/autohide-cursor.js @@ -0,0 +1,23 @@ +export function autohideCursor(delay = 1e3) { + + function showCursor() { + document.documentElement.removeAttribute('style'); + } + + function hideCursor() { + document.documentElement.style.cursor = 'none'; + } + + let timeout; + + document.documentElement.addEventListener('mousemove', function () { + showCursor(); + if (timeout) { + clearTimeout(timeout); + } + timeout = setTimeout(hideCursor, delay); + }, false); + + setTimeout(hideCursor, delay); + +} diff --git a/bower.json b/bower.json deleted file mode 100644 index 5bb04ae..0000000 --- a/bower.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "autohide-cursor", - "description": "Tiny no-dependency library that will automatically hide the cursor after a given time of mouse inactivity.", - "version": "0.0.2", - "main": "src/autohide-cursor.js", - "license": "WTFPL", - "ignore": [ - "**/.*", - "node_modules" - ], - "keywords": [ - "browser", - "cursor", - "hide" - ], - "authors": [{ - "name": "Roland Hummel", - "email": "git@defaude.info" - }], - "homepage": "https://github.com/defaude/autohide-cursor", - "repository": { - "type": "git", - "url": "git@github.com:defaude/autohide-cursor.git" - } -} diff --git a/example-custom.html b/example-custom.html new file mode 100644 index 0000000..8070501 --- /dev/null +++ b/example-custom.html @@ -0,0 +1,33 @@ + + + + + autohide-cursor + + + + +
+

autohide-cursor

+ I love it! +
+ + diff --git a/src/example.html b/example-simple.html similarity index 87% rename from src/example.html rename to example-simple.html index 985a003..d4a08f6 100644 --- a/src/example.html +++ b/example-simple.html @@ -1,5 +1,5 @@ - + autohide-cursor @@ -8,6 +8,7 @@ background-color: #223; font-family: sans-serif; } + #box { background-color: #eef; margin: 3em auto; @@ -16,7 +17,7 @@ max-width: 75%; } - +
diff --git a/grunt/aliases.yaml b/grunt/aliases.yaml deleted file mode 100644 index fc82acd..0000000 --- a/grunt/aliases.yaml +++ /dev/null @@ -1,16 +0,0 @@ -default: -- build - -dev: -- build -- serve - -build: -- clean -- jshint -- copy -- uglify - -serve: -- connect -- watch diff --git a/grunt/clean.yaml b/grunt/clean.yaml deleted file mode 100644 index 85e1cd7..0000000 --- a/grunt/clean.yaml +++ /dev/null @@ -1,2 +0,0 @@ -code: -- dist diff --git a/grunt/connect.yaml b/grunt/connect.yaml deleted file mode 100644 index fa2b432..0000000 --- a/grunt/connect.yaml +++ /dev/null @@ -1,5 +0,0 @@ -code: - options: - base: src - livereload: true - open: 'http://localhost:8000/example.html' diff --git a/grunt/copy.yaml b/grunt/copy.yaml deleted file mode 100644 index 45013f7..0000000 --- a/grunt/copy.yaml +++ /dev/null @@ -1,3 +0,0 @@ -code: - src: 'src/autohide-cursor.js' - dest: 'dist/autohide-cursor.js' diff --git a/grunt/jshint.yaml b/grunt/jshint.yaml deleted file mode 100644 index cb70f52..0000000 --- a/grunt/jshint.yaml +++ /dev/null @@ -1,6 +0,0 @@ -options: - force: true - jshintrc: true - -code: - src: 'src/autohide-cursor.js' diff --git a/grunt/uglify.yaml b/grunt/uglify.yaml deleted file mode 100644 index 44069b1..0000000 --- a/grunt/uglify.yaml +++ /dev/null @@ -1,5 +0,0 @@ -code: - options: - sourceMap: true - files: - 'dist/autohide-cursor.min.js': 'dist/autohide-cursor.js' diff --git a/grunt/watch.yaml b/grunt/watch.yaml deleted file mode 100644 index c86ea13..0000000 --- a/grunt/watch.yaml +++ /dev/null @@ -1,6 +0,0 @@ -code: - options: - livereload: true - files: 'src/**/*' - tasks: - - build diff --git a/index.js b/index.js new file mode 100644 index 0000000..a4d7412 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +import {autohideCursor} from "./autohide-cursor.js"; + +autohideCursor(); diff --git a/package.json b/package.json index ca1eb62..6424406 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { - "name": "autohide-cursor", - "version": "0.0.2", + "name": "@defaude/autohide-cursor", + "version": "1.0.0", "description": "Tiny no-dependency library that will automatically hide the cursor after a given time of mouse inactivity.", + "main": "autohide-cursor.js", "repository": { "type": "git", - "url": "https://github.com/defaude/autohide-cursor.git" + "url": "git+https://github.com/defaude/autohide-cursor.git" }, "author": { "name": "Roland Hummel", @@ -15,15 +16,5 @@ "bugs": { "url": "https://github.com/defaude/autohide-cursor/issues" }, - "homepage": "https://github.com/defaude/autohide-cursor", - "devDependencies": { - "grunt": "^0.4.5", - "grunt-contrib-clean": "^0.6.0", - "grunt-contrib-connect": "^0.9.0", - "grunt-contrib-copy": "^0.7.0", - "grunt-contrib-jshint": "^0.10.0", - "grunt-contrib-uglify": "^0.7.0", - "grunt-contrib-watch": "^0.6.1", - "load-grunt-config": "^0.16.0" - } + "homepage": "https://github.com/defaude/autohide-cursor#readme" } diff --git a/src/autohide-cursor.js b/src/autohide-cursor.js deleted file mode 100644 index 83fc6df..0000000 --- a/src/autohide-cursor.js +++ /dev/null @@ -1,44 +0,0 @@ -(function () { - - "use strict"; - - var delay = 1000; - var timeout; - - prepareConfig(); - bindMouseEvents(); - setTimeout(hideCursor, delay); - - function prepareConfig () { - var scripts = getTags('script'); - var myScript = scripts[scripts.length - 1]; - var delayAttribute = 'data-autohide-delay'; - - if (myScript.hasAttribute(delayAttribute)) { - delay = myScript.getAttribute(delayAttribute) || delay; - } - } - - function bindMouseEvents () { - document.documentElement.addEventListener('mousemove', function () { - showCursor(); - if (timeout) { - clearTimeout(timeout); - } - timeout = setTimeout(hideCursor, delay); - }, false); - } - - function showCursor () { - document.documentElement.removeAttribute('style'); - } - - function hideCursor () { - document.documentElement.style.cursor = 'none'; - } - - function getTags (name) { - return document.getElementsByTagName(name); - } - -}());