Merge pull request #43 from alberanid/master

focus directive
This commit is contained in:
Davide Alberani 2015-04-18 15:53:00 +02:00
commit 49a12c1582
8 changed files with 46 additions and 33 deletions

View file

@ -32,7 +32,7 @@
<form class="form-inline">
<div class="form-group">
<label for="query-persons">{{'Search:' | translate}}</label>
<input type="text" id="query-persons" class="form-control" placeholder="{{'Name or email' | translate}}" ng-model="query">
<input eventman-focus type="text" id="query-persons" class="form-control" placeholder="{{'Name or email' | translate}}" ng-model="query">
</div>
<div class="form-group">
<label for="persons-order">{{'Sort by:' | translate}}</label>

View file

@ -12,7 +12,7 @@
<form class="form-inline">
<div class="form-group">
<label for="query-events">{{'Search:' | translate}}</label>
<input type="text" id="query-events" class="form-control" placeholder="{{'Event title' | translate}}" ng-model="query">
<input eventman-focus type="text" id="query-events" class="form-control" placeholder="{{'Event title' | translate}}" ng-model="query">
</div>
<div class="form-group">
<label for="events-order">Sort by:</label>

View file

@ -16,6 +16,7 @@
<script src="/js/app.js"></script>
<script src="/js/i18n.js"></script>
<script src="/js/filters.js"></script>
<script src="/js/directives.js"></script>
<script src="/js/services.js"></script>
<script src="/js/controllers.js"></script>
<link href="/static/css/normalize.css" rel="stylesheet">

29
angular_app/js/app.js vendored
View file

@ -35,35 +35,6 @@ eventManApp.run(['$rootScope', '$state', '$stateParams',
);
/* Filter that handles splitted words. */
eventManApp.filter('splittedFilter', ['$filter',
function($filter) {
return function(inputArray, searchText) {
var wordArray = searchText ? searchText.toLowerCase().split(/\s+/) : [];
for (var x=0; x < wordArray.length; x++) {
inputArray = $filter('filter')(inputArray, wordArray[x]);
}
return inputArray;
};
}]
);
/* Directive that can be used to make an input field react to the press of Enter. */
eventManApp.directive('ngEnter', function () {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
if(event.which === 13) {
scope.$apply(function (){
scope.$eval(attrs.ngEnter);
});
event.preventDefault();
}
});
};
});
/* Configure the states. */
eventManApp.config(['$stateProvider', '$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {

27
angular_app/js/directives.js vendored Normal file
View file

@ -0,0 +1,27 @@
'use strict';
/* Directives for DOM manipulation and interaction. */
/* Directive that can be used to make an input field react to the press of Enter. */
eventManApp.directive('eventmanPressEnter', function () {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
if(event.which === 13) {
scope.$apply(function (){
scope.$eval(attrs.ngEnter);
});
event.preventDefault();
}
});
};
});
eventManApp.directive('eventmanFocus', function () {
function link(scope, element, attrs) {
element[0].focus();
};
return {
link: link
};
});

View file

@ -50,3 +50,17 @@ eventManApp.filter('personRegistered', ['$filter',
}]
);
/* Filter that handles splitted words. */
eventManApp.filter('splittedFilter', ['$filter',
function($filter) {
return function(inputArray, searchText) {
var wordArray = searchText ? searchText.toLowerCase().split(/\s+/) : [];
for (var x=0; x < wordArray.length; x++) {
inputArray = $filter('filter')(inputArray, wordArray[x]);
}
return inputArray;
};
}]
);

View file

@ -12,7 +12,7 @@
<form class="form-inline">
<div class="form-group">
<label for="query-persons">{{'Search:' | translate}}</label>
<input type="text" id="query-persons" class="form-control" placeholder="{{'Name or email' | translate}}" ng-model="query">
<input eventman-focus type="text" id="query-persons" class="form-control" placeholder="{{'Name or email' | translate}}" ng-model="query">
</div>
<div class="form-group">
<label for="events-order">{{'Sort by:' | translate}}</label>

View file

@ -16,7 +16,7 @@
<form class="form-inline">
<div class="form-group">
<label for="query-persons">{{'Search:' | translate}}</label>
<input type="text" id="query-persons" class="form-control" placeholder="{{'Name or email' | translate}}" ng-model="query">
<input eventman-focus type="text" id="query-persons" class="form-control" placeholder="{{'Name or email' | translate}}" ng-model="query">
</div>
<div class="form-group">
<label for="persons-order">{{'Sort by:' | translate}}</label>