Skip to content

Commit f7bbfc4

Browse files
committed
Add shortcut: press backspace to focus the search box and rewrite keywords, and focus the search box when the page is ready
1 parent 219bece commit f7bbfc4

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

app/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
<script src="bower_components/angular-zeroclipboard/src/angular-zeroclipboard.js"></script>
1010
<script src="scripts/app.js"></script>
1111
</head>
12-
<body ng-app="abstackVarLib" ng-controller="mainCtrl">
12+
<body ng-app="abstackVarLib" ng-controller="mainCtrl" backspace-focus="search">
1313
<header>
1414
Abstack Tech Variables Library
15-
<input type="text" class="search-box" placeholder="Type some keywords..." ng-model="keywords">
15+
<input type="text" id="search" class="search-box" placeholder="Type some keywords..." ng-model="keywords" ready-focus>
1616
</header>
1717
<ul class="word-list ng-hide" ng-show="wordsList">
1818
<li ng-repeat="word in wordsList | keywords: keywords">
@@ -21,7 +21,7 @@ <h3>
2121
<a target="_blank" ng-href="{{ word.url?word.url: 'http://www.dict.cn/' + word.word }}" ng-bind="word.word"></a>
2222
</h3>
2323
<span class="tag-box">
24-
<em ng-repeat="tag in word.tags track by $index" ng-bind="tag" ng-click="setKeywords(tag)"></em>
24+
<a href="javascript:;" ng-repeat="tag in word.tags track by $index" ng-bind="tag" ng-click="setKeywords(tag)"></a>
2525
</span>
2626
</li>
2727
</ul>

app/scripts/app.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,32 @@ angular.module('abstackVarLib', ['zeroclipboard'])
1010
swfPath: '../bower_components/zeroclipboard/dist/ZeroClipboard.swf'
1111
});
1212
}])
13+
.directive('readyFocus', ['$document', function($document){
14+
return {
15+
restrict: 'A',
16+
link: function($scope, iElm, iAttrs, controller) {
17+
$document.ready(function(){
18+
iElm[0].focus();
19+
});
20+
}
21+
};
22+
}])
23+
.directive('backspaceFocus', function(){
24+
return {
25+
restrict: 'A',
26+
link: function($scope, iElm, iAttrs, controller) {
27+
var targetObj = document.getElementById(iAttrs['backspaceFocus']);
28+
29+
iElm[0].onkeydown = function(ev){
30+
var event = ev || event,
31+
keyCode = event.keyCode;
32+
if(keyCode == 8 && targetObj){
33+
targetObj.focus();
34+
}
35+
};
36+
}
37+
};
38+
})
1339
.filter('keywords', function(){
1440
return function(input, type){
1541
if(!type)

app/styles/main.less

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ only screen and (min-device-pixel-ratio: 2){
128128
font-size: 14px;
129129
margin-right: -2px;
130130
}
131-
em{
131+
a{
132132
@bgcolor: #eee;
133133
position: relative;
134134
display: inline-block;
@@ -137,6 +137,7 @@ only screen and (min-device-pixel-ratio: 2){
137137
padding: 3px 6px;
138138
font-size: 13px;
139139
font-style: normal;
140+
text-decoration: none;
140141
color: #333;
141142
background-color: @bgcolor;
142143
border-top-right-radius: 3px;

0 commit comments

Comments
 (0)