Skip to content

Commit

Permalink
Merge #32: JSCS added
Browse files Browse the repository at this point in the history
  • Loading branch information
pukhalski committed Jun 16, 2015
1 parent 8563ede commit af3f60c
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 95 deletions.
134 changes: 134 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"excludeFiles": ["node_modules/**", "dist/**"],
"disallowDanglingUnderscores": true,
"disallowEmptyBlocks": true,
"disallowFunctionDeclarations": true,
"disallowImplicitTypeConversion": ["numeric", "boolean", "binary", "string"],
"disallowKeywordsOnNewLine": ["else"],
"disallowMixedSpacesAndTabs": true,
"disallowMultipleLineBreaks": true,
"disallowMultipleSpaces": true,
"disallowNamedUnassignedFunctions": true,
"disallowNewlineBeforeBlockStatements": true,
"disallowOperatorBeforeLineBreak": ["+", "."],
"disallowQuotedKeysInObjects": "allButReserved",
"disallowSpaceAfterObjectKeys": true,
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
"disallowSpacesInCallExpression": true,
"disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInsideBrackets": true,
"disallowSpacesInsideParentheses": true,
"disallowTrailingComma": true,
"disallowTrailingWhitespace": true,

"requireAnonymousFunctions": true,
"requireBlocksOnNewline": true,
"requireCamelCaseOrUpperCaseIdentifiers": true,
"requireCapitalizedComments": true,
"requireCapitalizedConstructors": true,
"requireCommaBeforeLineBreak": true,
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch",
"case",
"default"
],
"requireDollarBeforejQueryAssignment": true,
"requireDotNotation": "except_snake_case",
"requireLineBreakAfterVariableAssignment": true,
"requireLineFeedAtFileEnd": true,
"requireMultipleVarDecl": "onevar",
"requirePaddingNewLineAfterVariableDeclaration": true,
"requirePaddingNewLinesAfterBlocks": {
"allExcept": ["inCallExpressions", "inArrayExpressions", "inProperties"]
},
"requirePaddingNewLinesAfterUseStrict": true,
"requirePaddingNewLinesBeforeExport": true,
"requirePaddingNewlinesBeforeKeywords": [
"do",
"for",
"if",
"switch",
"try",
"while",
"with",
"return"
],
"requirePaddingNewLinesBeforeLineComments": { "allExcept": "firstAfterCurly" },
"requirePaddingNewLinesInObjects": true,
"requireParenthesesAroundIIFE": true,
"requireSemicolons": true,
"requireSpaceAfterBinaryOperators": [
"=",
",",
"+",
"-",
"/",
"*",
"==",
"===",
"!=",
"!=="
],
"requireSpaceAfterKeywords": [
"do",
"for",
"if",
"else",
"switch",
"case",
"try",
"catch",
"void",
"while",
"with",
"return",
"typeof"
],
"requireSpaceAfterLineComment": true,
"requireSpaceBeforeBinaryOperators": [
"=",
"+",
"-",
"/",
"*",
"==",
"===",
"!=",
"!=="
],
"requireSpaceBeforeBlockStatements": 1,
"requireSpaceBeforeKeywords": [
"do",
"else",
"while",
"catch",
"catch"
],
"requireSpaceBeforeObjectValues": true,
"requireSpaceBetweenArguments": true,
"requireSpacesInConditionalExpression": true,
"requireSpacesInForStatement": true,
"requireSpacesInFunctionDeclaration": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInFunction": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInsideObjectBrackets": "all",
"safeContextKeyword": ["that"],
"validateParameterSeparator": ", ",
"validateQuoteMarks": "'",
"requirePaddingNewLinesAfterBlocks": true
}
96 changes: 49 additions & 47 deletions dist/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,42 @@

var utils = {};

utils.attachEvent = function( element, eventName, callback ) {
if ( 'addEventListener' in window ) {
return element.addEventListener( eventName, callback, false );
utils.attachEvent = function(element, eventName, callback) {
if ('addEventListener' in window) {
return element.addEventListener(eventName, callback, false);
}
};

utils.fireFakeEvent = function( e, eventName ) {
if ( document.createEvent ) {
return e.target.dispatchEvent( utils.createEvent( eventName ) );
utils.fireFakeEvent = function(e, eventName) {
if (document.createEvent) {
return e.target.dispatchEvent(utils.createEvent(eventName));
}
};

utils.createEvent = function( name ) {
if ( document.createEvent ) {
var evnt = window.document.createEvent( 'HTMLEvents' );
evnt.initEvent( name, true, true );
utils.createEvent = function(name) {
if (document.createEvent) {
var evnt = window.document.createEvent('HTMLEvents');

evnt.initEvent(name, true, true);
evnt.eventName = name;

return evnt;
}
};

utils.getRealEvent = function( e ) {
if ( e.originalEvent && e.originalEvent.touches && e.originalEvent.touches.length ) {
return e.originalEvent.touches[ 0 ];
} else if ( e.touches && e.touches.length ) {
return e.touches[ 0 ];
utils.getRealEvent = function(e) {
if (e.originalEvent && e.originalEvent.touches && e.originalEvent.touches.length) {
return e.originalEvent.touches[0];
} else if (e.touches && e.touches.length) {
return e.touches[0];
}

return e;
};

var eventMatrix = [{
// Touchable devices
test: ( 'propertyIsEnumerable' in window || 'hasOwnProperty' in document ) && ( window.propertyIsEnumerable( 'ontouchstart' ) || document.hasOwnProperty( 'ontouchstart') ),
test: ('propertyIsEnumerable' in window || 'hasOwnProperty' in document) && (window.propertyIsEnumerable('ontouchstart') || document.hasOwnProperty('ontouchstart')),
events: {
start: 'touchstart',
move: 'touchmove',
Expand Down Expand Up @@ -69,45 +70,45 @@
var attachDeviceEvent, init, handlers, deviceEvents,
coords = {};

attachDeviceEvent = function( eventName ) {
return utils.attachEvent( document.documentElement, deviceEvents[ eventName ], handlers[ eventName ] );
attachDeviceEvent = function(eventName) {
return utils.attachEvent(document.documentElement, deviceEvents[eventName], handlers[eventName]);
};

handlers = {
start: function( e ) {
e = utils.getRealEvent( e );
start: function(e) {
e = utils.getRealEvent(e);

coords.start = [ e.pageX, e.pageY ];
coords.offset = [ 0, 0 ];
coords.start = [e.pageX, e.pageY];
coords.offset = [0, 0];
},

move: function( e ) {
if ( !coords[ 'start' ] && !coords[ 'move' ] ) {
move: function(e) {
if (!coords.start && !coords.move) {
return false;
}

e = utils.getRealEvent( e );
e = utils.getRealEvent(e);

coords.move = [ e.pageX, e.pageY ];
coords.move = [e.pageX, e.pageY];
coords.offset = [
Math.abs( coords.move[ 0 ] - coords.start[ 0 ] ),
Math.abs( coords.move[ 1 ] - coords.start[ 1 ] )
Math.abs(coords.move[0] - coords.start[0]),
Math.abs(coords.move[1] - coords.start[1])
];
},

end: function( e ) {
e = utils.getRealEvent( e );
end: function(e) {
e = utils.getRealEvent(e);

if ( coords.offset[ 0 ] < Tap.options.fingerMaxOffset && coords.offset[ 1 ] < Tap.options.fingerMaxOffset && !utils.fireFakeEvent( e, Tap.options.eventName ) ) {
if (coords.offset[0] < Tap.options.fingerMaxOffset && coords.offset[1] < Tap.options.fingerMaxOffset && !utils.fireFakeEvent(e, Tap.options.eventName)) {
// Windows Phone 8.0 trigger `click` after `pointerup` firing
// #16 https://github.com/pukhalski/tap/issues/16
if ( window.navigator.msPointerEnabled || window.navigator.pointerEnabled ) {
var preventDefault = function( clickEvent ) {
if (window.navigator.msPointerEnabled || window.navigator.pointerEnabled) {
var preventDefault = function(clickEvent) {
clickEvent.preventDefault();
e.target.removeEventListener( 'click', preventDefault );
e.target.removeEventListener('click', preventDefault);
};

e.target.addEventListener( 'click', preventDefault, false );
e.target.addEventListener('click', preventDefault, false);
}

e.preventDefault();
Expand All @@ -116,8 +117,8 @@
coords = {};
},

click: function( e ) {
if ( !utils.fireFakeEvent( e, Tap.options.eventName ) ) {
click: function(e) {
if (!utils.fireFakeEvent(e, Tap.options.eventName)) {
return e.preventDefault();
}
},
Expand All @@ -134,27 +135,28 @@
init = function() {
var i = 0;

for ( ; i < eventMatrix.length; i++ ) {
if ( eventMatrix[ i ].test ) {
deviceEvents = eventMatrix[ i ].events;
for (; i < eventMatrix.length; i++) {
if (eventMatrix[i].test) {
deviceEvents = eventMatrix[i].events;

attachDeviceEvent( 'start' );
attachDeviceEvent( 'move' );
attachDeviceEvent( 'end' );
utils.attachEvent( document.documentElement, 'click', handlers[ 'emulatedTap' ] );
attachDeviceEvent('start');
attachDeviceEvent('move');
attachDeviceEvent('end');
utils.attachEvent(document.documentElement, 'click', handlers['emulatedTap']);

return false;
}
}

return utils.attachEvent( document.documentElement, 'click', handlers[ 'click' ] );
return utils.attachEvent(document.documentElement, 'click', handlers.click);
};

utils.attachEvent( window, 'load', init );
utils.attachEvent(window, 'load', init);

if (typeof define === 'function' && define.amd) {
define(function () {
define(function() {
init();

return Tap;
});
} else {
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
"devDependencies": {
"grunt": "latest",
"grunt-contrib-concat": "^0.4.0",
"grunt-contrib-uglify": "^0.4.0"
"grunt-contrib-uglify": "^0.4.0",
"jscs": "^1.13.1"
},
"description": "`Tap` is a Javascript library for easy unified handling of user interactions such as mouse, touch and pointer events.",
"main": "dist/tap.js",
"dependencies": {},
"scripts": {
"test": "./node_modules/.bin/jscs src/*"
},
"repository": {
"type": "git",
"url": "https://github.com/pukhalski/tap.git"
Expand Down
2 changes: 1 addition & 1 deletion src/events.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var eventMatrix = [{
// Touchable devices
test: ( 'propertyIsEnumerable' in window || 'hasOwnProperty' in document ) && ( window.propertyIsEnumerable( 'ontouchstart' ) || document.hasOwnProperty( 'ontouchstart') ),
test: ('propertyIsEnumerable' in window || 'hasOwnProperty' in document) && (window.propertyIsEnumerable('ontouchstart') || document.hasOwnProperty('ontouchstart')),
events: {
start: 'touchstart',
move: 'touchmove',
Expand Down
Loading

0 comments on commit af3f60c

Please sign in to comment.