Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new option to fix issues with offset dimensions #15

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
65bbfa9
Move source file in its source folder
ExoAndy Jan 30, 2017
cb41475
Add NPM package configuration file
ExoAndy Jan 30, 2017
87f2600
Add gitignore file
ExoAndy Jan 30, 2017
11f4bd0
Add grunt and the uglify plugin to the package configuration file
ExoAndy Jan 30, 2017
13235ac
Add jit-grunt dependancy to the package configuration file
ExoAndy Jan 30, 2017
baca355
Add Grunt configuration file
ExoAndy Jan 30, 2017
e21873a
Change documentation header to retain it during the minification process
ExoAndy Jan 30, 2017
2c04ea5
Add minified version
ExoAndy Jan 30, 2017
e65cf91
Add new option to be able to ignore inner dimensions check
ExoAndy Jan 30, 2017
32d6cd9
Update minified version with the latest build
ExoAndy Jan 30, 2017
a1af9a2
Change ignoreInnerDimensionValidator to ignoreInnerDimensionValidation
ExoAndy Jan 30, 2017
2b50783
Add description for the new option ignoreInnerDimensionValidation
ExoAndy Jan 30, 2017
e5047ef
Change option description
ExoAndy Jan 30, 2017
5923154
Update minified version with the latest build
ExoAndy Jan 30, 2017
abfc7d7
Add deployment documentation
ExoAndy Jan 30, 2017
f3d86d5
Update deployment description
ExoAndy Jan 30, 2017
4096037
Fix wrong option anme
ExoAndy Feb 1, 2017
ccb258a
Add source code documentation for the new option
ExoAndy Feb 1, 2017
49cbc04
Fix wrong description about the new option in the README file
ExoAndy Feb 1, 2017
5a91bc4
Update minified version of the library to the latest build
ExoAndy Feb 1, 2017
e13da46
Add test case file for the offset dimensions offset issue
ExoAndy Feb 6, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@

# Created by https://www.gitignore.io/api/macos,windows,linux,node

### macOS ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk


### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*


### Node ###
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity


# End of https://www.gitignore.io/api/macos,windows,linux,node
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ Although SpatialNavigation is a standalone (pure-javascript-based) library, it c

+ [Demonstrations](https://luke-chang.github.io/js-spatial-navigation/demo/)

Deployment
----------

After changing the source file you can create a new build by entering following line:

```shell
grunt
```

This will create a new minified version of the library and saves it into the ``dist`` folder.
In case you haven't Grunt available yet, just enter

```shell
npm install
```

and Grunt as well as all the needed plugins will be installed in your repository folder. Afterwards you
can perform the instruction from above to create a new minified version of the library.

Documentation
-------------

Expand Down Expand Up @@ -194,7 +213,8 @@ Following is an example with default values.
leaveFor: null,
restrict: 'self-first',
tabIndexIgnoreList: 'a, input, select, textarea, button, iframe, [contentEditable=true]',
navigableFilter: null
navigableFilter: null,
ignoreOffsetDimensionValidation: false
}
```

Expand Down Expand Up @@ -293,6 +313,15 @@ A callback function that accepts a DOM element as the first argument.

SpatialNavigation calls this function every time when it tries to traverse every single candidate. You can ignore arbitrary elements by returning `false`.

#### `ignoreOffsetDimensionValidation`

+ Type: `'boolean'`
+ Default: `false`

When the library checks whether an element is navigable or not, it validates the offset width and height values to be greater than zero
and only then the element is navigable. There're also cases where the offset width and height are zero but the element is still visible and therefore needs to be focusable.
In such cases it's possible to disable the validation at all for a particular section or globally.

### Custom Attributes

SpatialNavigation supports HTML `data-*` attributes as follows:
Expand Down
9 changes: 9 additions & 0 deletions dist/spatial_navigation.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const fs = require('fs');

module.exports = function(grunt)
{
require('jit-grunt')(grunt, {
ngtemplates: 'grunt-angular-templates'
});

grunt.initConfig({
/**
* uglify.
*/
uglify: {
options: {
beautify: false,
preserveComments: 'some',
compress: {
drop_console: true
}
},
release: {
files: {
'dist/spatial_navigation.min.js': ['src/spatial_navigation.js']
}
}
}
});

grunt.registerTask('default', [
'uglify'
]);
};
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "js-spatial-navigation",
"version": "1.0.0",
"description": "A javascript-based implementation of Spatial Navigation.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/exozet/js-spatial-navigation.git"
},
"keywords": [
"spatial",
"navigation",
"javascript"
],
"author": "Luke Chang",
"license": "MPL-2.0",
"bugs": {
"url": "https://github.com/exozet/js-spatial-navigation/issues"
},
"homepage": "https://github.com/exozet/js-spatial-navigation#readme",
"devDependencies": {
"grunt": "^1.0.1",
"grunt-contrib-uglify": "^2.0.0",
"jit-grunt": "^0.10.0"
}
}
25 changes: 21 additions & 4 deletions spatial_navigation.js → src/spatial_navigation.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
/**
* A javascript-based implementation of Spatial Navigation.
*
* Copyright (c) 2017 Luke Chang.
* https://github.com/luke-chang/js-spatial-navigation
*
* Licensed under the MPL 2.0.
* @license Licensed under the MPL 2.0.
*/
;(function($) {
'use strict';
Expand Down Expand Up @@ -32,7 +32,20 @@
restrict: 'self-first', // 'self-first', 'self-only', 'none'
tabIndexIgnoreList:
'a, input, select, textarea, button, iframe, [contentEditable=true]',
navigableFilter: null
navigableFilter: null,

/**
* Disables offset dimension validation.
*
* Usually before an element get focused it'll be checked
* whether it's navigable or not. To do so it checks, among other things, whether
* the offsetWidth or the offsetHeight is greater than null because then it means
* that element is visible. Some elements haven't any offsetWidth or offsetHeight
* defined even though they're visible to the viewer. To make those elements
* navigable this option can be set to true and the validation will be ignored.
* That option is available for a particular section or globally.
*/
ignoreOffsetDimensionValidation: false
};

/*********************/
Expand Down Expand Up @@ -518,7 +531,11 @@
!_sections[sectionId] || _sections[sectionId].disabled) {
return false;
}
if ((elem.offsetWidth <= 0 && elem.offsetHeight <= 0) ||

var ignoreOffsetDimensionValidation = (typeof _sections[sectionId].ignoreOffsetDimensionValidation === 'boolean' && _sections[sectionId].ignoreOffsetDimensionValidation === true) ||
(typeof GlobalConfig.ignoreOffsetDimensionValidation === 'boolean' && GlobalConfig.ignoreOffsetDimensionValidation === true);

if ((!ignoreOffsetDimensionValidation && elem.offsetWidth <= 0 && elem.offsetHeight <= 0) ||
elem.hasAttribute('disabled')) {
return false;
}
Expand Down
Loading