Cleaned book-show and page sidebar by hiding inactive chapter contents
Showing
4 changed files
with
51 additions
and
7 deletions
| ... | @@ -37,6 +37,32 @@ abstract class Entity extends Model | ... | @@ -37,6 +37,32 @@ abstract class Entity extends Model |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | /** | 39 | /** |
| 40 | + * Checks if an entity matches or contains another given entity. | ||
| 41 | + * @param Entity $entity | ||
| 42 | + * @return bool | ||
| 43 | + */ | ||
| 44 | + public function matchesOrContains(Entity $entity) | ||
| 45 | + { | ||
| 46 | + $matches = [get_class($this), $this->id] === [get_class($entity), $entity->id]; | ||
| 47 | + | ||
| 48 | + if ($matches) return true; | ||
| 49 | + | ||
| 50 | + if ($entity->isA('chapter') && $this->isA('book')) { | ||
| 51 | + return $entity->book_id === $this->id; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + if ($entity->isA('page') && $this->isA('book')) { | ||
| 55 | + return $entity->book_id === $this->id; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + if ($entity->isA('page') && $this->isA('chapter')) { | ||
| 59 | + return $entity->chapter_id === $this->id; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + return false; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + /** | ||
| 40 | * Gets the activity objects for this entity. | 66 | * Gets the activity objects for this entity. |
| 41 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany | 67 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
| 42 | */ | 68 | */ |
| ... | @@ -106,7 +132,7 @@ abstract class Entity extends Model | ... | @@ -106,7 +132,7 @@ abstract class Entity extends Model |
| 106 | $search = $search->with('book'); | 132 | $search = $search->with('book'); |
| 107 | } | 133 | } |
| 108 | 134 | ||
| 109 | - if(static::isA('page')) { | 135 | + if (static::isA('page')) { |
| 110 | $search = $search->with('chapter'); | 136 | $search = $search->with('chapter'); |
| 111 | } | 137 | } |
| 112 | 138 | ... | ... |
| ... | @@ -6,7 +6,7 @@ | ... | @@ -6,7 +6,7 @@ |
| 6 | color: $color-chapter; | 6 | color: $color-chapter; |
| 7 | } | 7 | } |
| 8 | .inset-list { | 8 | .inset-list { |
| 9 | - display: block; | 9 | + display: none; |
| 10 | overflow: hidden; | 10 | overflow: hidden; |
| 11 | // padding-left: $-m; | 11 | // padding-left: $-m; |
| 12 | margin-bottom: $-l; | 12 | margin-bottom: $-l; |
| ... | @@ -45,7 +45,7 @@ | ... | @@ -45,7 +45,7 @@ |
| 45 | margin: 0 0 $-l 0; | 45 | margin: 0 0 $-l 0; |
| 46 | transition: all ease-in-out 180ms; | 46 | transition: all ease-in-out 180ms; |
| 47 | user-select: none; | 47 | user-select: none; |
| 48 | - i { | 48 | + i.zmdi-caret-right { |
| 49 | transition: all ease-in-out 180ms; | 49 | transition: all ease-in-out 180ms; |
| 50 | transform: rotate(0deg); | 50 | transform: rotate(0deg); |
| 51 | transform-origin: 25% 50%; | 51 | transform-origin: 25% 50%; |
| ... | @@ -53,7 +53,7 @@ | ... | @@ -53,7 +53,7 @@ |
| 53 | &.open { | 53 | &.open { |
| 54 | margin-bottom: 0; | 54 | margin-bottom: 0; |
| 55 | } | 55 | } |
| 56 | - &.open i { | 56 | + &.open i.zmdi-caret-right { |
| 57 | transform: rotate(90deg); | 57 | transform: rotate(90deg); |
| 58 | } | 58 | } |
| 59 | } | 59 | } |
| ... | @@ -140,6 +140,9 @@ | ... | @@ -140,6 +140,9 @@ |
| 140 | background-color: rgba($color-chapter, 0.12); | 140 | background-color: rgba($color-chapter, 0.12); |
| 141 | } | 141 | } |
| 142 | } | 142 | } |
| 143 | + .chapter-toggle { | ||
| 144 | + padding-left: $-s; | ||
| 145 | + } | ||
| 143 | .list-item-chapter { | 146 | .list-item-chapter { |
| 144 | border-left: 5px solid $color-chapter; | 147 | border-left: 5px solid $color-chapter; |
| 145 | margin: 10px 10px; | 148 | margin: 10px 10px; |
| ... | @@ -157,6 +160,12 @@ | ... | @@ -157,6 +160,12 @@ |
| 157 | background-color: rgba($color-page, 0.1); | 160 | background-color: rgba($color-page, 0.1); |
| 158 | } | 161 | } |
| 159 | } | 162 | } |
| 163 | + .sub-menu { | ||
| 164 | + display: none; | ||
| 165 | + } | ||
| 166 | + .sub-menu.open { | ||
| 167 | + display: block; | ||
| 168 | + } | ||
| 160 | } | 169 | } |
| 161 | 170 | ||
| 162 | // Sortable Lists | 171 | // Sortable Lists | ... | ... |
| ... | @@ -11,7 +11,7 @@ | ... | @@ -11,7 +11,7 @@ |
| 11 | @endif | 11 | @endif |
| 12 | 12 | ||
| 13 | @if(count($chapter->pages) > 0 && !isset($hidePages)) | 13 | @if(count($chapter->pages) > 0 && !isset($hidePages)) |
| 14 | - <p class="text-muted chapter-toggle open"><i class="zmdi zmdi-caret-right"></i> {{ count($chapter->pages) }} Pages</p> | 14 | + <p class="text-muted chapter-toggle"><i class="zmdi zmdi-caret-right"></i> <i class="zmdi zmdi-file-text"></i> <span>{{ count($chapter->pages) }} Pages</span></p> |
| 15 | <div class="inset-list"> | 15 | <div class="inset-list"> |
| 16 | @foreach($chapter->pages as $page) | 16 | @foreach($chapter->pages as $page) |
| 17 | <h4><a href="{{$page->getUrl()}}"><i class="zmdi zmdi-file-text"></i>{{$page->name}}</a></h4> | 17 | <h4><a href="{{$page->getUrl()}}"><i class="zmdi zmdi-file-text"></i>{{$page->name}}</a></h4> | ... | ... |
| ... | @@ -3,14 +3,19 @@ | ... | @@ -3,14 +3,19 @@ |
| 3 | <h6 class="text-muted">Book Navigation</h6> | 3 | <h6 class="text-muted">Book Navigation</h6> |
| 4 | <ul class="sidebar-page-list menu"> | 4 | <ul class="sidebar-page-list menu"> |
| 5 | <li class="book-header"><a href="{{$book->getUrl()}}" class="book {{ $current->matches($book)? 'selected' : '' }}"><i class="zmdi zmdi-book"></i>{{$book->name}}</a></li> | 5 | <li class="book-header"><a href="{{$book->getUrl()}}" class="book {{ $current->matches($book)? 'selected' : '' }}"><i class="zmdi zmdi-book"></i>{{$book->name}}</a></li> |
| 6 | + | ||
| 7 | + | ||
| 6 | @foreach($sidebarTree as $bookChild) | 8 | @foreach($sidebarTree as $bookChild) |
| 7 | - <li class="list-item-{{ $bookChild->getName() }}"> | 9 | + <li class="list-item-{{ $bookChild->getName() }} {{ $bookChild->getName() }}"> |
| 8 | <a href="{{$bookChild->getUrl()}}" class="{{ $bookChild->getName() }} {{ $current->matches($bookChild)? 'selected' : '' }}"> | 10 | <a href="{{$bookChild->getUrl()}}" class="{{ $bookChild->getName() }} {{ $current->matches($bookChild)? 'selected' : '' }}"> |
| 9 | @if($bookChild->isA('chapter'))<i class="zmdi zmdi-collection-bookmark"></i>@else <i class="zmdi zmdi-file-text"></i>@endif{{ $bookChild->name }} | 11 | @if($bookChild->isA('chapter'))<i class="zmdi zmdi-collection-bookmark"></i>@else <i class="zmdi zmdi-file-text"></i>@endif{{ $bookChild->name }} |
| 10 | </a> | 12 | </a> |
| 11 | 13 | ||
| 12 | @if($bookChild->isA('chapter') && count($bookChild->pages) > 0) | 14 | @if($bookChild->isA('chapter') && count($bookChild->pages) > 0) |
| 13 | - <ul class="menu"> | 15 | + <p class="text-muted chapter-toggle @if($bookChild->matchesOrContains($current)) open @endif"> |
| 16 | + <i class="zmdi zmdi-caret-right"></i> <i class="zmdi zmdi-file-text"></i> <span>{{ count($bookChild->pages) }} Pages</span> | ||
| 17 | + </p> | ||
| 18 | + <ul class="menu sub-menu inset-list @if($bookChild->matchesOrContains($current)) open @endif"> | ||
| 14 | @foreach($bookChild->pages as $childPage) | 19 | @foreach($bookChild->pages as $childPage) |
| 15 | <li class="list-item-page"> | 20 | <li class="list-item-page"> |
| 16 | <a href="{{$childPage->getUrl()}}" class="page {{ $current->matches($childPage)? 'selected' : '' }}"> | 21 | <a href="{{$childPage->getUrl()}}" class="page {{ $current->matches($childPage)? 'selected' : '' }}"> |
| ... | @@ -20,7 +25,11 @@ | ... | @@ -20,7 +25,11 @@ |
| 20 | @endforeach | 25 | @endforeach |
| 21 | </ul> | 26 | </ul> |
| 22 | @endif | 27 | @endif |
| 28 | + | ||
| 29 | + | ||
| 23 | </li> | 30 | </li> |
| 24 | @endforeach | 31 | @endforeach |
| 32 | + | ||
| 33 | + | ||
| 25 | </ul> | 34 | </ul> |
| 26 | </div> | 35 | </div> | ... | ... |
-
Please register or sign in to post a comment