10
10
table {
11
11
width : 100% ;
12
12
border-collapse : collapse;
13
+ margin-bottom : 20px ;
13
14
}
14
15
tr {
15
16
border : solid;
18
19
h1 {
19
20
text-align : center;
20
21
}
22
+ # rightSide {
23
+ display : none;
24
+ }
21
25
</ style >
22
26
</ head >
23
27
< body >
24
28
25
29
< h1 > My Library – List of books</ h1 >
26
30
27
- < table >
31
+ < table id =" booksTable " >
28
32
< thead >
29
33
< tr >
30
34
< th > ID</ th >
@@ -35,7 +39,7 @@ <h1>My Library – List of books</h1>
35
39
</ tr >
36
40
</ thead >
37
41
< tbody >
38
- < tr th:each ="book : *{books} ">
42
+ < tr th:each ="book : *{books} " th:id = ${book.id} th:onclick =" showDetail([[${book.id}]], [[${book.title}]], [[${book.pages}]], [[${book.year}]], [[${book.author.name}]]); " >
39
43
< td th:text ="*{book.id} "> </ td >
40
44
< td th:text ="*{book.title} "> </ td >
41
45
< td th:text ="*{book.pages} "> </ td >
@@ -44,5 +48,44 @@ <h1>My Library – List of books</h1>
44
48
</ tr >
45
49
</ tbody >
46
50
</ table >
51
+
52
+ < div id ="rightSide " >
53
+
54
+ < h2 id ="bookTitle "> Title</ h2 >
55
+ < h3 id ="bookAuthor "> Author</ h3 >
56
+ < p id ="bookDescription "> Description</ p >
57
+ </ div >
58
+
59
+ < script th:inline ="javascript ">
60
+
61
+ var isResized = false ;
62
+ var lastId ;
63
+ function showDetail ( id , title , page , year , author ) {
64
+
65
+ if ( isResized && lastId === id ) {
66
+ document . getElementById ( 'booksTable' ) . style . width = "100%" ;
67
+ document . getElementById ( 'rightSide' ) . style . display = "none" ;
68
+ } else {
69
+ document . getElementById ( 'booksTable' ) . style . width = "50%" ;
70
+ document . getElementById ( 'booksTable' ) . style . float = "left" ;
71
+
72
+ document . getElementById ( 'rightSide' ) . style . float = "left" ;
73
+ document . getElementById ( 'rightSide' ) . style . width = "40%" ;
74
+ document . getElementById ( 'rightSide' ) . style . display = "block" ;
75
+ document . getElementById ( 'rightSide' ) . style . margin = "1% 5% 1% 5%" ;
76
+
77
+ document . getElementById ( 'bookTitle' ) . innerHTML = title ;
78
+ document . getElementById ( 'bookAuthor' ) . innerHTML = author ;
79
+ document . getElementById ( 'bookDescription' ) . innerHTML = 'Year: ' + year + ', pages: ' + page ;
80
+ }
81
+
82
+
83
+
84
+ isResized = ! isResized ;
85
+ lastId = id ;
86
+ }
87
+
88
+
89
+ </ script >
47
90
</ body >
48
91
</ html >
0 commit comments