Skip to content
This repository has been archived by the owner on Nov 22, 2017. It is now read-only.

Commit

Permalink
Add linting, fix clicking on auto complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashid Khan committed Nov 6, 2015
1 parent 424061e commit db550ee
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 13 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
@@ -0,0 +1,14 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
insert_final_newline = false
68 changes: 68 additions & 0 deletions .eslintrc
@@ -0,0 +1,68 @@
---
parser: babel-eslint

env:
es6: true
amd: true
node: true
browser: true


rules:
block-scoped-var: 2
camelcase: [ 2, { properties: never } ]
comma-dangle: 0
comma-style: [ 2, last ]
consistent-return: 0
curly: [ 2, multi-line ]
dot-location: [ 2, property ]
dot-notation: [ 2, { allowKeywords: true } ]
eqeqeq: [ 2, allow-null ]
guard-for-in: 2
indent: [ 2, 2, { SwitchCase: 1 } ]
key-spacing: [ 0, { align: value } ]
max-len: [ 2, 140, 2, { ignoreComments: true, ignoreUrls: true } ]
new-cap: [ 2, { capIsNewExceptions: [ Private ] } ]
no-bitwise: 0
no-caller: 2
no-cond-assign: 0
no-debugger: 2
no-empty: 2
no-eval: 2
no-extend-native: 2
no-extra-parens: 0
no-irregular-whitespace: 2
no-iterator: 2
no-loop-func: 2
no-multi-spaces: 0
no-multi-str: 2
no-nested-ternary: 2
no-new: 0
no-path-concat: 0
no-proto: 2
no-return-assign: 0
no-script-url: 2
no-sequences: 2
no-shadow: 0
no-trailing-spaces: 2
no-undef: 2
no-underscore-dangle: 0
no-unused-expressions: 0
no-unused-vars: 0
no-use-before-define: [ 2, nofunc ]
no-with: 2
one-var: [ 2, never ]
quotes: [ 2, single ]
semi-spacing: [ 2, { before: false, after: true } ]
semi: [ 2, always ]
space-after-keywords: [ 2, always ]
space-before-blocks: [ 2, always ]
space-before-function-paren: [ 2, { anonymous: always, named: never } ]
space-in-parens: [ 2, never ]
space-infix-ops: [ 2, { int32Hint: false } ]
space-return-throw-case: [ 2 ]
space-unary-ops: [ 2 ]
strict: [ 2, never ]
valid-typeof: 2
wrap-iife: [ 2, outside ]
yoda: 0
9 changes: 6 additions & 3 deletions package.json
Expand Up @@ -11,18 +11,21 @@
"pegjs": "^0.9.0" "pegjs": "^0.9.0"
}, },
"devDependencies": { "devDependencies": {
"babel-eslint": "^4.1.4",
"bluebird": "^3.0.5", "bluebird": "^3.0.5",
"chai": "^3.2.0",
"eslint": "^1.9.0",
"eslint-plugin-mocha": "^1.0.0",
"gulp": "^3.9.0", "gulp": "^3.9.0",
"gulp-eslint": "^1.0.0", "gulp-eslint": "^1.0.0",
"gulp-gzip": "^1.2.0", "gulp-gzip": "^1.2.0",
"gulp-tar": "^1.5.0", "gulp-tar": "^1.5.0",
"gulp-util": "^3.0.7", "gulp-util": "^3.0.7",
"lodash": "^3.10.1", "lodash": "^3.10.1",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"mocha": "^2.3.0",
"rimraf": "^2.4.3", "rimraf": "^2.4.3",
"rsync": "^0.4.0", "rsync": "^0.4.0"
"chai": "^3.2.0",
"mocha": "^2.3.0"
}, },
"scripts": { "scripts": {
"test": "mocha --compilers js:babel/register series_functions/__test__/*.js" "test": "mocha --compilers js:babel/register series_functions/__test__/*.js"
Expand Down
24 changes: 16 additions & 8 deletions public/directives/expression_directive.js
Expand Up @@ -47,7 +47,11 @@ app.directive('timelionExpression', function ($compile, $http, $timeout, $rootSc
}); });
$elem.on('keydown', keyDownHandler); $elem.on('keydown', keyDownHandler);
$elem.on('keyup', keyUpHandler); $elem.on('keyup', keyUpHandler);
$elem.on('blur', resetSuggestions); $elem.on('blur', function () {
$timeout(function () {
$scope.suggestions.show = false;
}, 100);
});


$elem.after($compile(template)($scope)); $elem.after($compile(template)($scope));
$http.get('/timelion/functions').then(function (resp) { $http.get('/timelion/functions').then(function (resp) {
Expand Down Expand Up @@ -75,6 +79,7 @@ app.directive('timelionExpression', function ($compile, $http, $timeout, $rootSc
if (functionReference.byName) { if (functionReference.byName) {
if (functionReference.byName[possible.function]) { if (functionReference.byName[possible.function]) {
$scope.suggestions.list = [functionReference.byName[possible.function]]; $scope.suggestions.list = [functionReference.byName[possible.function]];
$scope.suggestions.show = true;
} else { } else {
resetSuggestions(); resetSuggestions();
} }
Expand All @@ -97,6 +102,7 @@ app.directive('timelionExpression', function ($compile, $http, $timeout, $rootSc
} }
})); }));
} }
$scope.suggestions.show = true;
} }
$scope.suggestions.location = e.location; $scope.suggestions.location = e.location;
} catch (e) { } catch (e) {
Expand All @@ -112,13 +118,14 @@ app.directive('timelionExpression', function ($compile, $http, $timeout, $rootSc
else if ($scope.suggestions.selected < 0) $scope.suggestions.selected = 0; else if ($scope.suggestions.selected < 0) $scope.suggestions.selected = 0;
} }


function completeExpression() { $scope.completeExpression = function (selected) {
console.log('completing', selected, $scope.suggestions.list);
if (!$scope.suggestions.list.length) return; if (!$scope.suggestions.list.length) return;
var expression = $attrs.timelionExpression; var expression = $attrs.timelionExpression;
var startOf = expression.slice(0, $scope.suggestions.location.min); var startOf = expression.slice(0, $scope.suggestions.location.min);
var endOf = expression.slice($scope.suggestions.location.max, expression.length); var endOf = expression.slice($scope.suggestions.location.max, expression.length);


var completeFunction = $scope.suggestions.list[$scope.suggestions.selected].name + '()'; var completeFunction = $scope.suggestions.list[selected].name + '()';


var newVal = startOf + completeFunction + endOf; var newVal = startOf + completeFunction + endOf;


Expand All @@ -128,7 +135,7 @@ app.directive('timelionExpression', function ($compile, $http, $timeout, $rootSc
ngModelCtrl.$setViewValue(newVal); ngModelCtrl.$setViewValue(newVal);


resetSuggestions(); resetSuggestions();
} };




function keyDownHandler(e) { function keyDownHandler(e) {
Expand All @@ -141,17 +148,17 @@ app.directive('timelionExpression', function ($compile, $http, $timeout, $rootSc
$scope.suggestions.selected++; $scope.suggestions.selected++;
break; break;
case keys.TAB: case keys.TAB:
completeExpression(); $scope.completeExpression($scope.suggestions.selected);
break; break;
case keys.ENTER: case keys.ENTER:
if ($scope.suggestions.list.length) { if ($scope.suggestions.list.length) {
completeExpression(); $scope.completeExpression($scope.suggestions.selected);
} else { } else {
$scope.search(); $scope.search();
} }
break; break;
case keys.ESC: case keys.ESC:
resetSuggestions(); $scope.suggestions.show = false;
break; break;
} }
scrollTo($scope.suggestions); scrollTo($scope.suggestions);
Expand All @@ -170,7 +177,8 @@ app.directive('timelionExpression', function ($compile, $http, $timeout, $rootSc
$scope.suggestions = { $scope.suggestions = {
selected: 0, selected: 0,
list: [], list: [],
position: {} position: {},
show: false
}; };
return $scope.suggestions; return $scope.suggestions;
} }
Expand Down
4 changes: 2 additions & 2 deletions public/directives/partials/suggestion.html
@@ -1,6 +1,6 @@
<div class="suggestions" ng-if="suggestions.list"> <div class="suggestions" ng-show="suggestions.show">
<div class="suggestion" <div class="suggestion"
ng-click="suggestions.selected = $index" ng-click="completeExpression($index)"
ng-class="{active: $index === suggestions.selected}" ng-class="{active: $index === suggestions.selected}"
ng-repeat="suggestion in suggestions.list track by $index | orderBy:'name'"> ng-repeat="suggestion in suggestions.list track by $index | orderBy:'name'">
<h4><strong>{{suggestion.name}}()</strong> <small>{{suggestion.help}} {{suggestion.chainable}}</small></h4> <h4><strong>{{suggestion.name}}()</strong> <small>{{suggestion.help}} {{suggestion.chainable}}</small></h4>
Expand Down
4 changes: 4 additions & 0 deletions public/main.less
Expand Up @@ -152,6 +152,10 @@ input.timelion-interval {
border-bottom: 1px solid @gray-lighter; border-bottom: 1px solid @gray-lighter;
padding: 5px 20px; padding: 5px 20px;


&:hover {
background-color: @gray-lighter;
}

&.active { &.active {
background-color: @gray-lighter; background-color: @gray-lighter;
} }
Expand Down

0 comments on commit db550ee

Please sign in to comment.