Skip to content

Commit

Permalink
Merge 7c7ff92 into efb205e
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravshe committed Mar 10, 2017
2 parents efb205e + 7c7ff92 commit ac9935d
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 54 deletions.
4 changes: 2 additions & 2 deletions bower.json
Expand Up @@ -11,11 +11,11 @@
],
"license": "Apache2",
"dependencies": {
"angular": "1.0 - 1.1",
"angular": "^1.2.0",
"jquery": "*"
},
"devDependencies": {
"angular-mocks": "1.0 - 1.1",
"angular-mocks": "^1.2.0",
"bootstrap": "^3.1"
}
}
12 changes: 6 additions & 6 deletions demo/index.html
Expand Up @@ -144,11 +144,11 @@
cache: true,
params: { search: text }
})
.success(function (results) {
.then(function (results) {
$scope.loading = false;
$scope.results = results;
})
.error(function (err) {
},
function (err) {
$scope.loading = false;
throw new Error (err);
});
Expand Down Expand Up @@ -180,11 +180,11 @@
cache: true,
params: { search: text }
})
.success(function (results) {
.then(function (results) {
$scope.loading = false;
$scope.results = results;
})
.error(function (err) {
},
function (err) {
$scope.loading = false;
throw new Error (err);
});
Expand Down
56 changes: 27 additions & 29 deletions dist/search.js
Expand Up @@ -3,22 +3,24 @@ angular.module('turn/search/template', ['search.html']);
angular.module("search.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("search.html",
"<form class=\"search\">\n" +
" <span class=\"turn-search\" ng-click=\"update()\"></span>\n" +
" <span class=\"turn-clear\" ng-show=\"param\" ng-click=\"clear()\"></span>\n" +
" <input\n" +
" type=\"search\"\n" +
" ng-model=\"param\"\n" +
" class=\"{{ class }}\"\n" +
" ng-class=\"{ 'input-error': searchValidation }\"\n" +
" ng-disabled=\"disabled\"\n" +
" placeholder=\"{{ placeholder }}\"\n" +
" >\n" +
" <span\n" +
" class=\"press-enter\"\n" +
" ng-click=\"update()\"\n" +
" ng-show=\"!typeAhead && dirty && !loading\"\n" +
" >Press <kbd>enter</kbd> to search</span>\n" +
" <span ng-show=\"searchValidation\" class=\"error-label\">You have to enter at least {{minSearchLength}} characters</span>\n" +
" <span class=\"turn-search\" ng-click=\"update()\"></span>\n" +
" <span class=\"turn-clear\" ng-show=\"param\" ng-click=\"clear()\"></span>\n" +
" <input\n" +
" type=\"search\"\n" +
" ng-model=\"param\"\n" +
" ng-keyup=\"change($event)\"\n" +
" ng-paste=\"change($event)\"\n" +
" class=\"{{ class }}\"\n" +
" ng-class=\"{ 'input-error': searchValidation }\"\n" +
" ng-disabled=\"disabled\"\n" +
" placeholder=\"{{ placeholder }}\"\n" +
" >\n" +
" <span\n" +
" class=\"press-enter\"\n" +
" ng-click=\"update()\"\n" +
" ng-show=\"!typeAhead && dirty && !loading\"\n" +
" >Press <kbd>enter</kbd> to search</span>\n" +
" <span ng-show=\"searchValidation\" class=\"error-label\">You have to enter at least {{minSearchLength}} characters</span>\n" +
"</form>");
}]);

Expand Down Expand Up @@ -68,25 +70,21 @@ angular.module('turn/search', ['turn/search/template']).constant('SEARCH_KEYS',
}
},
update: function () {
if(scope.minSearchLength && scope.param !== '' && scope.param.length < scope.minSearchLength){
scope.searchValidation = true;
} else {
scope.searchValidation = false;
scope.search({
$param: scope.param
});
}
scope.dirty = false;
scope.$apply();
if(scope.minSearchLength && scope.param !== '' && scope.param.length < scope.minSearchLength){
scope.searchValidation = true;
} else {
scope.searchValidation = false;
scope.search({
$param: scope.param
});
}
scope.dirty = false;
},
clear: function () {
scope.param = '';
scope.update();
}
});
// TODO: investigate why this doesn't work when
// declared in the DOM
element.find('input').on('keyup paste', scope.change);
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -29,13 +29,13 @@
"grunt-contrib-clean": "^0.5.0",
"grunt-contrib-coffee": "^0.10.1",
"grunt-contrib-concat": "^0.4.0",
"grunt-contrib-jasmine": "^0.5.2",
"grunt-contrib-jasmine": "^1.1.0",
"grunt-contrib-sass": "^0.8.1",
"grunt-contrib-watch": "^0.6.1",
"grunt-coveralls": "^1.0.0",
"grunt-html2js": "^0.2.4",
"grunt-ngmin": "0.0.3",
"grunt-template-jasmine-istanbul": "^0.2.6",
"grunt-template-jasmine-istanbul": "^0.3.0",
"lodash": "^2.4.1"
}
}
2 changes: 2 additions & 0 deletions src/search.html
Expand Up @@ -4,6 +4,8 @@
<input
type="search"
ng-model="param"
ng-keyup="change($event)"
ng-paste="change($event)"
class="{{ class }}"
ng-class="{ 'input-error': searchValidation }"
ng-disabled="disabled"
Expand Down
8 changes: 0 additions & 8 deletions src/search.js
Expand Up @@ -82,7 +82,6 @@ angular
});
}
scope.dirty = false;
scope.$apply();
},

/**
Expand All @@ -92,14 +91,7 @@ angular
scope.param = '';
scope.update();
}

});

// TODO: investigate why this doesn't work when
// declared in the DOM
element.find('input').on('keyup paste', scope.change);

}
};

});
20 changes: 15 additions & 5 deletions test/test.coffee
Expand Up @@ -33,7 +33,7 @@ describe 'search', ->

(@$compile @element) @scope
do @scope.$apply
@scope = do @element.scope
@scope = do @element.isolateScope


#########################################
Expand Down Expand Up @@ -100,6 +100,16 @@ describe 'search', ->
do expect @scope.update
.toHaveBeenCalled

it 'should call #update if the user pressed ENTER, on browsers not supporting keyCode', ->

spyOn @scope, 'update'

@scope.change
which: 13

do expect @scope.update
.toHaveBeenCalled

it 'should call #update if typeAhead is true', ->

spyOn @scope, 'update'
Expand Down Expand Up @@ -209,21 +219,21 @@ describe 'search', ->

@scope.minSearchLength = 2

do scope.update
do @scope.update

expect @scope.searchValidation
/toBe true
.toBe true

it 'should set scope.searchValidation to false', ->

@scope.param = '11'

@scope.minSearchLength = 2

do scope.update
do @scope.update

expect @scope.searchValidation
/toBe false
.toBe false


describe '#clear', ->
Expand Down
11 changes: 9 additions & 2 deletions test/test.js

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

0 comments on commit ac9935d

Please sign in to comment.