]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
wrap the hotkeys component to allow templating :art:
authorRigel Kent <sendmemail@rigelk.eu>
Tue, 11 Sep 2018 13:07:31 +0000 (15:07 +0200)
committerRigel Kent <sendmemail@rigelk.eu>
Tue, 11 Sep 2018 19:33:22 +0000 (21:33 +0200)
client/src/app/app.component.html
client/src/app/app.module.ts
client/src/app/core/hotkeys/hotkeys.component.html [new file with mode: 0644]
client/src/app/core/hotkeys/hotkeys.component.scss [new file with mode: 0644]
client/src/app/core/hotkeys/hotkeys.component.ts [new file with mode: 0644]
client/src/app/core/hotkeys/hotkeys.module.ts [new file with mode: 0644]
client/src/app/core/hotkeys/index.ts [new file with mode: 0644]
client/src/app/core/index.ts
client/src/app/core/theme/theme.service.ts

index 23ed04c2dad67b707ac25c9d5b11ebd761f82065..87de874bb9b8ba13ec1aa9195e664141dec95073 100644 (file)
@@ -1,6 +1,6 @@
 <div *ngIf="customCSS" [innerHTML]="customCSS"></div>
 
-<hotkeys-cheatsheet></hotkeys-cheatsheet>
+<my-hotkeys-cheatsheet></my-hotkeys-cheatsheet>
 
 <div [ngClass]="{ 'user-logged-in': isUserLoggedIn(), 'user-not-logged-in': !isUserLoggedIn() }">
   <div class="header">
index ba16c072e2805b1df2b70ec5d4cd836e35d8dbd3..e5a1883213d8337614f52628547282b2d2a384c6 100644 (file)
@@ -5,7 +5,8 @@ import { ResetPasswordModule } from '@app/reset-password'
 
 import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core'
 import { ClipboardModule } from 'ngx-clipboard'
-import { HotkeyModule, IHotkeyOptions } from 'angular2-hotkeys'
+import { HotkeyModule } from '@app/core/hotkeys'
+import { IHotkeyOptions } from 'angular2-hotkeys'
 import 'focus-visible'
 
 import { AppRoutingModule } from './app-routing.module'
diff --git a/client/src/app/core/hotkeys/hotkeys.component.html b/client/src/app/core/hotkeys/hotkeys.component.html
new file mode 100644 (file)
index 0000000..61f03be
--- /dev/null
@@ -0,0 +1,18 @@
+<div class="cfp-hotkeys-container fade" [ngClass]="{'in': helpVisible}">
+  <div class="cfp-hotkeys">
+    <h4 class="cfp-hotkeys-title">{{ title }}</h4>
+    <div class="cfp-hotkeys-table">
+      <table>
+        <tbody>
+          <tr *ngFor="let hotkey of hotkeys">
+            <td class="cfp-hotkeys-keys">
+              <span *ngFor="let key of hotkey.formatted" class="cfp-hotkeys-key">{{ key }}</span>
+            </td>
+            <td class="cfp-hotkeys-text">{{ hotkey.description }}</td>
+          </tr>
+        </tbody>
+      </table>
+    </div>
+    <div class="cfp-hotkeys-close" (click)="toggleCheatSheet()">&#215;</div>
+  </div>
+</div>
\ No newline at end of file
diff --git a/client/src/app/core/hotkeys/hotkeys.component.scss b/client/src/app/core/hotkeys/hotkeys.component.scss
new file mode 100644 (file)
index 0000000..9af10b7
--- /dev/null
@@ -0,0 +1,105 @@
+.cfp-hotkeys-container {
+  display: table !important;
+  position: fixed;
+  overflow: auto;
+  width: 100%;
+  height: 100%;
+  top: 0;
+  left: 0;
+  color: #333;
+  font-size: 1em;
+  background-color: rgba(255,255,255,0.9);
+}
+
+.cfp-hotkeys-container.fade {
+  z-index: -1024;
+  visibility: hidden;
+  opacity: 0;
+  -webkit-transition: opacity 0.15s linear;
+  -moz-transition: opacity 0.15s linear;
+  -o-transition: opacity 0.15s linear;
+  transition: opacity 0.15s linear;
+}
+
+.cfp-hotkeys-container.fade.in {
+  z-index: 10002;
+  visibility: visible;
+  opacity: 1;
+}
+
+.cfp-hotkeys-title {
+  font-weight: bold;
+  text-align: center;
+  font-size: 1.2em;
+}
+
+.cfp-hotkeys {
+  width: 100%;
+  height: 100%;
+  display: table-cell;
+  vertical-align: middle;
+}
+
+.cfp-hotkeys table {
+  margin: auto;
+  color: #333;
+}
+
+.cfp-content {
+  display: table-cell;
+  vertical-align: middle;
+}
+
+.cfp-hotkeys-keys {
+  padding: 5px;
+  text-align: right;
+}
+
+.cfp-hotkeys-key {
+  display: inline-block;
+  color: #fff;
+  background-color: #333;
+  border: 1px solid #333;
+  border-radius: 5px;
+  text-align: center;
+  margin-right: 5px;
+  box-shadow: inset 0 1px 0 #666, 0 1px 0 #bbb;
+  padding: 5px 9px;
+  font-size: 1em;
+}
+
+.cfp-hotkeys-text {
+  padding-left: 10px;
+  font-size: 1em;
+}
+
+.cfp-hotkeys-close {
+  position: fixed;
+  top: 20px;
+  right: 20px;
+  font-size: 2em;
+  font-weight: bold;
+  padding: 5px 10px;
+  border: 1px solid #ddd;
+  border-radius: 5px;
+  min-height: 45px;
+  min-width: 45px;
+  text-align: center;
+}
+
+.cfp-hotkeys-close:hover {
+  background-color: #fff;
+  cursor: pointer;
+}
+
+@media all and (max-width: 500px) {
+  .cfp-hotkeys {
+    font-size: 0.8em;
+  }
+}
+
+@media all and (min-width: 750px) {
+  .cfp-hotkeys {
+    font-size: 1.2em;
+  }
+}
\ No newline at end of file
diff --git a/client/src/app/core/hotkeys/hotkeys.component.ts b/client/src/app/core/hotkeys/hotkeys.component.ts
new file mode 100644 (file)
index 0000000..f6f2999
--- /dev/null
@@ -0,0 +1,46 @@
+import { Component, OnInit, OnDestroy, Input } from '@angular/core'
+import { Subscription } from 'rxjs'
+import { I18n } from '@ngx-translate/i18n-polyfill'
+import { HotkeysService, Hotkey } from 'angular2-hotkeys'
+
+@Component({
+  selector : 'my-hotkeys-cheatsheet',
+  templateUrl : './hotkeys.component.html',
+  styleUrls: [ './hotkeys.component.scss' ]
+})
+export class CheatSheetComponent implements OnInit, OnDestroy {
+  helpVisible = false
+  @Input() title = this.i18n('Keyboard Shortcuts:')
+  subscription: Subscription
+
+  hotkeys: Hotkey[]
+
+  constructor (
+    private hotkeysService: HotkeysService,
+    private i18n: I18n
+  ) {}
+
+  public ngOnInit (): void {
+    this.subscription = this.hotkeysService.cheatSheetToggle.subscribe((isOpen) => {
+      if (isOpen !== false) {
+        this.hotkeys = this.hotkeysService.hotkeys.filter(hotkey => hotkey.description)
+      }
+
+      if (isOpen === false) {
+        this.helpVisible = false
+      } else {
+        this.toggleCheatSheet()
+      }
+    })
+  }
+
+  public ngOnDestroy (): void {
+    if (this.subscription) {
+      this.subscription.unsubscribe()
+    }
+  }
+
+  public toggleCheatSheet (): void {
+    this.helpVisible = !this.helpVisible
+  }
+}
diff --git a/client/src/app/core/hotkeys/hotkeys.module.ts b/client/src/app/core/hotkeys/hotkeys.module.ts
new file mode 100644 (file)
index 0000000..7d42058
--- /dev/null
@@ -0,0 +1,23 @@
+import { NgModule, ModuleWithProviders } from '@angular/core'
+import { CommonModule } from '@angular/common'
+import { HotkeysDirective, IHotkeyOptions, HotkeyOptions, HotkeysService } from 'angular2-hotkeys'
+import { CheatSheetComponent } from './hotkeys.component'
+
+export * from './hotkeys.component'
+
+@NgModule({
+  imports : [CommonModule],
+  exports : [HotkeysDirective, CheatSheetComponent],
+  declarations : [HotkeysDirective, CheatSheetComponent]
+})
+export class HotkeyModule {
+  static forRoot (options: IHotkeyOptions = {}): ModuleWithProviders {
+    return {
+      ngModule : HotkeyModule,
+      providers : [
+        HotkeysService,
+        { provide : HotkeyOptions, useValue : options }
+      ]
+    }
+  }
+}
diff --git a/client/src/app/core/hotkeys/index.ts b/client/src/app/core/hotkeys/index.ts
new file mode 100644 (file)
index 0000000..4f27967
--- /dev/null
@@ -0,0 +1 @@
+export * from './hotkeys.module'
index 521afc29cf8a6062feed4809ebc4109ded94d471..524589d74268e5afe1bc5223c5ca2f84fd6fef48 100644 (file)
@@ -1,6 +1,7 @@
 export * from './auth'
-export * from './server'
 export * from './confirm'
 export * from './routing'
+export * from './server'
 export * from './theme'
+
 export * from './core.module'
index 17d33b4e50aea9ed31302629575d2e64a9e11950..a6eef089843017bb889e5ef4b55f579597df0d78 100644 (file)
@@ -16,7 +16,6 @@ export class ThemeService {
     this.previousTheme['inputPlaceholderColor'] = '#fff'
 
     this.darkTheme = (peertubeLocalStorage.getItem('theme') === 'dark')
-    console.log(this.darkTheme)
     if (this.darkTheme) this.toggleDarkTheme(false)
   }