Skip to content

Commit 3bba708

Browse files
committed
Merge pull request #278 from dpalou/MOBILE-1308
MOBILE-1308 ui: Auto-focus some input elements
2 parents 887f3cb + 3919578 commit 3bba708

File tree

7 files changed

+61
-4
lines changed

7 files changed

+61
-4
lines changed

config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<preference name="BackupWebStorage" value="none"/>
1919
<preference name="SplashScreen" value="screen"/>
2020
<preference name="SplashScreenDelay" value="3000"/>
21+
<preference name="KeyboardDisplayRequiresUserAction" value="false" />
2122
<feature name="StatusBar">
2223
<param name="ios-package" value="CDVStatusBar" onload="true"/>
2324
</feature>

www/core/components/courses/templates/search.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<form class="list">
44
<label class="item item-input">
55
<i class="icon ion-search placeholder-icon"></i>
6-
<input type="text" placeholder="{{ 'mm.courses.search' | translate}}" ng-model="searchText">
6+
<input type="text" placeholder="{{ 'mm.courses.search' | translate}}" ng-model="searchText" mm-auto-focus>
77
</label>
88
<button class="button button-block" ng-click="search(searchText)" ng-disabled="searchText.length < 3">
99
{{ 'mm.courses.search' | translate }}

www/core/components/login/templates/credentials.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<form>
66
<label class="item item-input item-stacked-label">
77
<span class="input-label">{{ 'mm.login.username' | translate }}</span>
8-
<input type="text" placeholder="{{ 'mm.login.username' | translate }}" ng-model="credentials.username" autocapitalize="off" autocorrect="off">
8+
<input type="text" placeholder="{{ 'mm.login.username' | translate }}" ng-model="credentials.username" autocapitalize="off" autocorrect="off" mm-auto-focus>
99
</label>
1010
<label class="item item-input item-stacked-label">
1111
<span class="input-label">{{ 'mm.login.password' | translate }}</span>

www/core/components/login/templates/reconnect.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h2>{{ 'mm.login.username' | translate }}</h2>
1313
<form>
1414
<label class="item item-input item-stacked-label">
1515
<span class="input-label">{{ 'mm.login.password' | translate }}</span>
16-
<input type="password" placeholder="{{ 'mm.login.password' | translate }}" ng-model="credentials.password">
16+
<input type="password" placeholder="{{ 'mm.login.password' | translate }}" ng-model="credentials.password" mm-auto-focus>
1717
</label>
1818
<div class="item">
1919
<button class="button button-block" ng-click="login()">{{ 'mm.login.loginbutton' | translate }}</button>

www/core/components/login/templates/site.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<form>
99
<label class="item item-input item-stacked-label">
1010
<span class="input-label">{{ 'mm.login.siteaddress' | translate }}</span>
11-
<input type="url" placeholder="moodle.org" ng-model="siteurl" mm-no-input-validation ng-change="validate(siteurl)" >
11+
<input type="url" placeholder="moodle.org" ng-model="siteurl" mm-no-input-validation ng-change="validate(siteurl)" mm-auto-focus >
1212
</label>
1313
<div class="item">
1414
<button class="button button-block" ng-click="connect(siteurl)" ng-disabled="isInvalidUrl">{{ 'mm.login.connect' | translate }}</button>

www/core/directives/autofocus.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// (C) Copyright 2015 Martin Dougiamas
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
angular.module('mm.core')
16+
17+
/**
18+
* Directive to auto focus an element when a view is loaded.
19+
*
20+
* @module mm.core
21+
* @ngdoc directive
22+
* @name mmAutoFocus
23+
*/
24+
.directive('mmAutoFocus', function($mmApp) {
25+
return {
26+
restrict: 'A',
27+
link: function(scope, el) {
28+
// Wait for transition to finish before auto-focus.
29+
var unregister = scope.$watch(function() {
30+
return ionic.transition.isActive;
31+
}, function(isActive) {
32+
if (!isActive) {
33+
el[0].focus();
34+
unregister(); // Stop watching.
35+
if (ionic.Platform.isAndroid()) {
36+
// On some Android versions the keyboard doesn't open automatically.
37+
$mmApp.openKeyboard();
38+
}
39+
}
40+
});
41+
}
42+
};
43+
});

www/core/lib/app.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,19 @@ angular.module('mm.core')
238238
return promise.$$state.status === 1;
239239
};
240240

241+
/**
242+
* Open the keyboard if plugin is available.
243+
*
244+
* @return {Boolean} True if plugin is available, false otherwise.
245+
*/
246+
self.openKeyboard = function() {
247+
if (typeof cordova != 'undefined' && cordova.plugins && cordova.plugins.Keyboard && cordova.plugins.Keyboard.show) {
248+
cordova.plugins.Keyboard.show();
249+
return true;
250+
}
251+
return false;
252+
};
253+
241254
/**
242255
* Resolves when the app is ready.
243256
*

0 commit comments

Comments
 (0)