Skip to content

Commit

Permalink
Meta: add rudimentary linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Mottie committed Feb 21, 2018
1 parent 5f441a2 commit 7e23c23
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 66 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties
root = true

[*]
indent_style = tab
trim_trailing_whitespace = true
end_of_line = lf
charset = utf-8
insert_final_newline = true
max_line_length = 100
29 changes: 29 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"env": {
"browser": true,
"jquery": true
},
"rules": {
"curly": 1,
"dot-location": [2, "property"],
"eqeqeq": 1,
"linebreak-style": [2, "unix"],
"no-else-return": 1,
"no-eval": 2,
"no-octal": 2,
"no-with": 2,
"radix": 2,
"brace-style": 0,
"camelcase": 0,
"indent": 0,
"no-array-constructor": 2,
"quotes": [2, "single", {
"allowTemplateLiterals": true,
"avoidEscape": true
}],
"spaced-comment": 0,
"arrow-spacing": 2,
"no-var": 0,
"no-unused-vars": 1
}
}
12 changes: 6 additions & 6 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ module.exports = function(grunt) {
'█████▀ ▀████▀ ██ ██ ▀████▀ ██ ██ ██ ██ ▀████▀ █████▀ ██ ██ █████▀\n*/\n',

hintOpts = {
"jquery": true,
"browser": true,
"sub": true, // used by layouts
"-W100": true // ignore "This character may get silently deleted by one or more browsers."
'jquery': true,
'browser': true,
'sub': true, // used by layouts
'-W100': true // ignore "This character may get silently deleted by one or more browsers."
};

// Project configuration.
Expand Down Expand Up @@ -232,7 +232,7 @@ module.exports = function(grunt) {
]);

function escapeRegExp(str) {
return str.replace(/[$()*+\-.\/?[\\\]^{|}]/g, "\\$&");
return str.replace(/[$()*+\-.\/?[\\\]^{|}]/g, '\\$&');
}

// update keyboard.jquery.json file version numbers to match the package.json version
Expand All @@ -259,7 +259,7 @@ module.exports = function(grunt) {
project = grunt.file.read('js/jquery.keyboard.js');
if (
new RegExp(escapeRegExp('/*! jQuery UI Virtual Keyboard v' + pkg.version)).test(project) &&
new RegExp(escapeRegExp("base.version = '" + pkg.version)).test(project)
new RegExp(escapeRegExp('base.version = \'' + pkg.version)).test(project)
) {
console.info('versions all match!');
} else {
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.keyboard.extension-altkeyspopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
base.options.ignoreEsc = true;
$( document )
.unbind( base.altkeypopup_namespace )
.bind( 'keydown' + base.altkeypopup_namespace, function( event ) {
.bind( 'keydown' + base.altkeypopup_namespace, function() {
// keep home & end from scrolling the page
return false;
})
Expand Down Expand Up @@ -353,7 +353,7 @@
});

// adjust position as needed using popupPosition callback function
if ( typeof base.altkeypopup_options.popupPosition === "function" ) {
if ( typeof base.altkeypopup_options.popupPosition === 'function' ) {
base.altkeypopup_options.popupPosition(base, data);
}

Expand Down
2 changes: 1 addition & 1 deletion js/jquery.keyboard.extension-extender.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
};

// add {extender} keyaction
$keyboard.keyaction.extender = function( base, el ) {
$keyboard.keyaction.extender = function( base ) {
base.extender_toggle();
return false;
};
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.keyboard.extension-mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ $.fn.addMobile = function(options){
// Using this instead of the jQuery Mobile buttonMarkup because it is expecting <a>'s instead of <button>
// theme:'a', shadow:'true', inline:'true', corners:'false'
return css + ' ' + (btn && btn.cssClass ? btn.cssClass + '-' + (t.theme || '') : '') +
(t.shadow == 'true' ? ' ui-shadow' : '') +
(t.corners == 'true' ? ' ui-corner-all' : '');
(t.shadow == 'true' ? ' ui-shadow' : '') + // eslint-disable-line eqeqeq
(t.corners == 'true' ? ' ui-corner-all' : ''); // eslint-disable-line eqeqeq
};

base.mobile_init();
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.keyboard.extension-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ $.fn.addNavigation = function(options){

// save navigation settings - disabled when the toggled
base.saveNav = [ base.options.tabNavigation, base.options.enterNavigation ];
base.allNavKeys = $.map(k, function(v,i){ return v; });
base.allNavKeys = $.map(k, function(v){ return v; });

// Setup
base.navigation_init = function(){
Expand All @@ -108,7 +108,7 @@ $.fn.addNavigation = function(options){
};

base.checkKeys = function(key, disable){
if (typeof(key) === "undefined") {
if (typeof(key) === 'undefined') {
return;
}
var k = base.navigation_keys;
Expand Down
100 changes: 48 additions & 52 deletions js/jquery.keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,8 @@ http://www.opensource.org/licenses/mit-license.php
!base.$el.hasClass(kbcss.locked))) {
base.$el.addClass(kbcss.noKeyboard);
return;
} else {
base.$el.removeClass(kbcss.noKeyboard);
}
base.$el.removeClass(kbcss.noKeyboard);

// Unbind focus to prevent recursion - openOn may be empty if keyboard is opened externally
if (o.openOn) {
Expand Down Expand Up @@ -572,7 +571,7 @@ http://www.opensource.org/licenses/mit-license.php
base.bindKeys();

// reposition keyboard on window resize
if (o.reposition && $.ui && $.ui.position && o.appendTo == 'body') {
if (o.reposition && $.ui && $.ui.position && o.appendTo === 'body') {
$(window).bind('resize' + base.namespace, function () {
base.reposition();
});
Expand Down Expand Up @@ -1102,7 +1101,7 @@ http://www.opensource.org/licenses/mit-license.php
last.virtual = true;
last.$key = $key;
last.key = $key.attr('data-value');
last.keyPress = "";
last.keyPress = '';
// Start caret in IE when not focused (happens with each virtual keyboard button click
base.setFocus();
if (/^meta/.test(action)) {
Expand Down Expand Up @@ -1418,10 +1417,10 @@ http://www.opensource.org/licenses/mit-license.php
if (base.metaActive) {
// remove "-shift" and "-alt" from meta name if it exists
if (base.shiftActive) {
name = (name || "").replace("-shift", "");
name = (name || '').replace('-shift', '');
}
if (base.altActive) {
name = (name || "").replace("-alt", "");
name = (name || '').replace('-alt', '');
}
// the name attribute contains the meta set name 'meta99'
key = (/^meta/i.test(name)) ? name : '';
Expand Down Expand Up @@ -1466,7 +1465,7 @@ http://www.opensource.org/licenses/mit-license.php
.find('.' + kbcss.keySet)
.hide()
.end()
.find('.' + (kbcss.keyAction + prefix + key).replace("--", "-"))
.find('.' + (kbcss.keyAction + prefix + key).replace('--', '-'))
.addClass(active);

// show keyset using inline-block ( extender layout will then line up )
Expand Down Expand Up @@ -1776,7 +1775,6 @@ http://www.opensource.org/licenses/mit-license.php
return;
}
var kbcss = $.keyboard.css,
name = e.target.nodeName,
$contenteditable = $(e.target).closest('[contenteditable]'),
$target = $contenteditable.length ? $contenteditable : $(e.target);
base.escClose(e, $target);
Expand All @@ -1800,7 +1798,7 @@ http://www.opensource.org/licenses/mit-license.php
base.escCloseCallback = {
// keep keyboard open if alwaysOpen or stayOpen is true - fixes mutliple
// always open keyboards or single stay open keyboard
keepOpen: function($target) {
keepOpen: function() {
return !base.isOpen;
}
};
Expand Down Expand Up @@ -1878,9 +1876,8 @@ http://www.opensource.org/licenses/mit-license.php
);
}
return newName.join('');
} else {
return name;
}
return name;
};

base.processKeys = function (name) {
Expand Down Expand Up @@ -3056,7 +3053,7 @@ http://www.opensource.org/licenses/mit-license.php
// value ( like this "keyboard.$preview.val('');" ), if desired. The validate function is called after
// each input, the 'isClosing' value will be false; when the accept button is clicked,
// 'isClosing' is true
validate: function (keyboard, value, isClosing) {
validate: function (/* keyboard, value, isClosing */) {
return true;
}

Expand Down Expand Up @@ -3285,7 +3282,7 @@ http://www.opensource.org/licenses/mit-license.php
max = 0,
nodes = $.makeArray(container.childNodes);
function updateText(val) {
txt += val ? options && options.replaceCR || "\n" : "";
txt += val ? options && options.replaceCR || '\n' : '';
return val > 0;
}
function checkDone(adj) {
Expand Down Expand Up @@ -3338,13 +3335,13 @@ http://www.opensource.org/licenses/mit-license.php
range.setStart(result.node, result.offset);
// Only find end if > start and is defined... this allows passing
// setEditableCaret(el, 'end') or setEditableCaret(el, 10, 'end');
if (typeof end !== "undefined" && end !== start) {
if (typeof end !== 'undefined' && end !== start) {
result = findNode(end);
}
if (result.node) {
e = result.position; // Adjust if end > content length
range.setEnd(result.node, result.offset);
text = s === e ? "" : result.text.substring(s, e);
text = s === e ? '' : result.text.substring(s, e);
}
sel.removeAllRanges();
sel.addRange(range);
Expand Down Expand Up @@ -3447,46 +3444,45 @@ http://www.opensource.org/licenses/mit-license.php
}
el.scrollTop = sTop;
return this;
} else {
if (/(email|number)/i.test(el.type)) {
// fix suggested by raduanastase (https://github.com/Mottie/Keyboard/issues/105#issuecomment-40456535)
start = end = $el.val().length;
} else if (ss) {
start = el.selectionStart;
end = el.selectionEnd;
} else if (selection) {
if (el.nodeName === 'TEXTAREA') {
val = $el.val();
range = selection.createRange();
stored_range = range.duplicate();
stored_range.moveToElementText(el);
stored_range.setEndPoint('EndToEnd', range);
// thanks to the awesome comments in the rangy plugin
start = stored_range.text.replace(/\r/g, '\n').length;
end = start + range.text.replace(/\r/g, '\n').length;
} else {
val = $el.val().replace(/\r/g, '\n');
range = selection.createRange().duplicate();
range.moveEnd('character', val.length);
start = (range.text === '' ? val.length : val.lastIndexOf(range.text));
range = selection.createRange().duplicate();
range.moveStart('character', -val.length);
end = range.text.length;
}
}
if (/(email|number)/i.test(el.type)) {
// fix suggested by raduanastase (https://github.com/Mottie/Keyboard/issues/105#issuecomment-40456535)
start = end = $el.val().length;
} else if (ss) {
start = el.selectionStart;
end = el.selectionEnd;
} else if (selection) {
if (el.nodeName === 'TEXTAREA') {
val = $el.val();
range = selection.createRange();
stored_range = range.duplicate();
stored_range.moveToElementText(el);
stored_range.setEndPoint('EndToEnd', range);
// thanks to the awesome comments in the rangy plugin
start = stored_range.text.replace(/\r/g, '\n').length;
end = start + range.text.replace(/\r/g, '\n').length;
} else {
// caret positioning not supported
start = end = (el.value || '').length;
val = $el.val().replace(/\r/g, '\n');
range = selection.createRange().duplicate();
range.moveEnd('character', val.length);
start = (range.text === '' ? val.length : val.lastIndexOf(range.text));
range = selection.createRange().duplicate();
range.moveStart('character', -val.length);
end = range.text.length;
}
txt = (el.value || '');
return {
start: start,
end: end,
text: txt.substring(start, end),
replace: function (str) {
return txt.substring(0, start) + str + txt.substring(end, txt.length);
}
};
} else {
// caret positioning not supported
start = end = (el.value || '').length;
}
txt = (el.value || '');
return {
start: start,
end: end,
text: txt.substring(start, end),
replace: function (str) {
return txt.substring(0, start) + str + txt.substring(end, txt.length);
}
};
};

return $keyboard;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"url": "git://github.com/Mottie/keyboard.git"
},
"scripts": {
"authors": "bash tools/authors.sh"
"authors": "bash tools/authors.sh",
"lint": "eslint *.js || true"
},
"npmName": "virtual-keyboard",
"npmFileMap": [
Expand Down

0 comments on commit 7e23c23

Please sign in to comment.