-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
127 lines (116 loc) · 4.02 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>RWS Sample</title>
<link href="./bootstrap-3.0.3/css/bootstrap.min.css" rel="stylesheet"/>
<style>
.container {
padding-top: 70px;
}
</style>
</head>
<body>
<div ng-app="rwsSampleApp">
<div class="navbar navbar-fixed-top navbar-inverse" role="navigation">
<div class="controller">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Rakuten API Sample Application</a>
</div>
</div>
</div>
<div class="container" ng-controller="itemsCntl">
<form class="form-inline" role="form" ng-submit="submit(keyword)">
<div class="form-group">
<input type="text" id="search" name="search" ng-model="keyword" placeholder="キーワード" required/>
</div>
<button type="submit" class="btn btn-default">検索</button>
</form>
<div ng-if="koboItems.hits == 0">Not found</div>
<ul class="pager" ng-if="koboItems.hits > 0">
<li ng-class="{disabled: koboItems.page <= 1}"><a ng-click="previousPage()">前へ</a></li>
<li>
{{ koboItems.count }} 件見つかりました
{{ koboItems.pageCount }} ページ中 {{ koboItems.page }}ページ目
</li>
<li ng-class="{disabled: koboItems.page >= koboItems.pageCount}"><a ng-click="nextPage()">次へ</a></li>
</ul>
<div ng-repeat="row in itemRow" class="row">
<div class="col-md-4" ng-repeat="itemInfo in row" ng-init="item = itemInfo.Item">
<div>
<a href="{{ item.affiliateUrl }}" target="_blank">
<img ng-src="{{ item.largeImageUrl }}"/>
</a>
</div>
<div>
<a href="{{ item.affiliateUrl }}" target="_blank">{{ item.title }}</a>
{{ item.itemPrice }}円
</div>
</div>
</div>
</div>
</div>
<script src="./jquery-1.10.2.min.js"></script>
<script src="./bootstrap-3.0.3/js/bootstrap.min.js"></script>
<script src="./angular-1.2.9/angular.min.js"></script>
<script src="./angular-1.2.9/angular-resource.min.js"></script>
<script src="./angular-rakutenwebservice.js"></script>
<script>
var app = angular.module('rwsSampleApp', ['RakutenService']);
app.config(['RakutenServiceConfig', function (rwsConfig) {
// it's sample developers ID :)
// UPDATE these parameters.
rwsConfig.applicationId = "1025899060325418115";
rwsConfig.affiliateId = "0dd78f8a.26c4c8c0.0dd78f8b.0ee811d2";
}]);
app.controller('itemsCntl', ['$scope', 'KoboBooks',
function ($scope, KoboBooks) {
var row = function (items) {
var result = [];
var size = 3;
var rowData;
for (var i = 0; i < items.length; i++) {
if (0 === (i % size)) {
rowData = [];
}
rowData.push(items[i]);
if (rowData.length === 3 || items.length - 1 === i) {
result.push(rowData);
}
}
return result;
};
$scope.submit = function (keyword) {
KoboBooks.get({keyword: keyword}, function (koboItems) {
$scope.koboItems = koboItems;
$scope.itemRow = row(koboItems.Items);
});
$scope.currentKeyword = keyword;
};
var changePage = function (page) {
$scope.koboItems = KoboBooks.get({
keyword: $scope.currentKeyword,
page: page
}, function(koboItems) {
$scope.itemRow = row(koboItems.Items);
});
}
$scope.nextPage = function () {
if ($scope.koboItems.page >= $scope.koboItems.pageCount) return;
changePage($scope.koboItems.page + 1);
};
$scope.previousPage = function () {
if ($scope.koboItems.page <= 1) return;
changePage($scope.koboItems.page - 1);
};
}
]);
</script>
</body>
</html>