├── projects └── ngx-fullscreen │ ├── src │ ├── index.ts │ ├── lib │ │ ├── ngx-fullscreen.module.ts │ │ └── ngx-fullscreen.directive.ts │ └── test.ts │ ├── ng-package.json │ ├── package.json │ ├── tsconfig.lib.prod.json │ ├── tsconfig.spec.json │ ├── tsconfig.lib.json │ ├── .browserslistrc │ ├── karma.conf.js │ └── README.md ├── .vscode ├── extensions.json ├── launch.json └── tasks.json ├── .editorconfig ├── .gitignore ├── LICENSE ├── tsconfig.json ├── angular.json ├── package.json └── README.md /projects/ngx-fullscreen/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './lib/ngx-fullscreen.directive'; 2 | export * from './lib/ngx-fullscreen.module'; 3 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846 3 | "recommendations": ["angular.ng-template"] 4 | } 5 | -------------------------------------------------------------------------------- /projects/ngx-fullscreen/ng-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "../../node_modules/ng-packagr/ng-package.schema.json", 3 | "dest": "../../dist/ngx-fullscreen", 4 | "lib": { 5 | "entryFile": "src/index.ts" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /projects/ngx-fullscreen/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@ultimate/ngx-fullscreen", 3 | "version": "0.0.5", 4 | "peerDependencies": { 5 | "@angular/common": "^13.2.0", 6 | "@angular/core": "^13.2.0" 7 | }, 8 | "dependencies": { 9 | "tslib": "^2.3.0" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /projects/ngx-fullscreen/src/lib/ngx-fullscreen.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { NgxFullscreenDirective } from './ngx-fullscreen.directive'; 3 | 4 | @NgModule({ 5 | declarations: [NgxFullscreenDirective], 6 | exports: [NgxFullscreenDirective], 7 | }) 8 | export class NgxFullscreenModule {} 9 | -------------------------------------------------------------------------------- /projects/ngx-fullscreen/tsconfig.lib.prod.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.lib.json", 4 | "compilerOptions": { 5 | "declarationMap": false 6 | }, 7 | "angularCompilerOptions": { 8 | "compilationMode": "partial" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.ts] 12 | quote_type = single 13 | 14 | [*.md] 15 | max_line_length = off 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /projects/ngx-fullscreen/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "../../tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "../../out-tsc/spec", 6 | "types": [ 7 | "jasmine" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts" 12 | ], 13 | "include": [ 14 | "**/*.spec.ts", 15 | "**/*.d.ts" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /projects/ngx-fullscreen/tsconfig.lib.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "../../tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "../../out-tsc/lib", 6 | "declaration": true, 7 | "declarationMap": true, 8 | "inlineSources": true, 9 | "types": [] 10 | }, 11 | "exclude": [ 12 | "src/test.ts", 13 | "**/*.spec.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 3 | "version": "0.2.0", 4 | "configurations": [ 5 | { 6 | "name": "ng serve", 7 | "type": "pwa-chrome", 8 | "request": "launch", 9 | "preLaunchTask": "npm: start", 10 | "url": "http://localhost:4200/" 11 | }, 12 | { 13 | "name": "ng test", 14 | "type": "chrome", 15 | "request": "launch", 16 | "preLaunchTask": "npm: test", 17 | "url": "http://localhost:9876/debug.html" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /projects/ngx-fullscreen/.browserslistrc: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # For the full list of supported browsers by the Angular framework, please see: 6 | # https://angular.io/guide/browser-support 7 | 8 | # You can see what browsers were selected by your queries by running: 9 | # npx browserslist 10 | 11 | last 1 Chrome version 12 | last 1 Firefox version 13 | last 2 Edge major versions 14 | last 2 Safari major versions 15 | last 2 iOS major versions 16 | Firefox ESR 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # Compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | /bazel-out 8 | 9 | # Node 10 | /node_modules 11 | npm-debug.log 12 | yarn-error.log 13 | 14 | # IDEs and editors 15 | .idea/ 16 | .project 17 | .classpath 18 | .c9/ 19 | *.launch 20 | .settings/ 21 | *.sublime-workspace 22 | 23 | # Visual Studio Code 24 | .vscode/* 25 | !.vscode/settings.json 26 | !.vscode/tasks.json 27 | !.vscode/launch.json 28 | !.vscode/extensions.json 29 | .history/* 30 | 31 | # Miscellaneous 32 | /.angular/cache 33 | .sass-cache/ 34 | /connect.lock 35 | /coverage 36 | /libpeerconnection.log 37 | testem.log 38 | /typings 39 | 40 | # System files 41 | .DS_Store 42 | Thumbs.db 43 | -------------------------------------------------------------------------------- /projects/ngx-fullscreen/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js'; 4 | import 'zone.js/testing'; 5 | import { getTestBed } from '@angular/core/testing'; 6 | import { 7 | BrowserDynamicTestingModule, 8 | platformBrowserDynamicTesting 9 | } from '@angular/platform-browser-dynamic/testing'; 10 | 11 | declare const require: { 12 | context(path: string, deep?: boolean, filter?: RegExp): { 13 | (id: string): T; 14 | keys(): string[]; 15 | }; 16 | }; 17 | 18 | // First, initialize the Angular testing environment. 19 | getTestBed().initTestEnvironment( 20 | BrowserDynamicTestingModule, 21 | platformBrowserDynamicTesting(), 22 | ); 23 | 24 | // Then we find all the tests. 25 | const context = require.context('./', true, /\.spec\.ts$/); 26 | // And load the modules. 27 | context.keys().map(context); 28 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558 3 | "version": "2.0.0", 4 | "tasks": [ 5 | { 6 | "type": "npm", 7 | "script": "start", 8 | "isBackground": true, 9 | "problemMatcher": { 10 | "owner": "typescript", 11 | "pattern": "$tsc", 12 | "background": { 13 | "activeOnStart": true, 14 | "beginsPattern": { 15 | "regexp": "(.*?)" 16 | }, 17 | "endsPattern": { 18 | "regexp": "bundle generation complete" 19 | } 20 | } 21 | } 22 | }, 23 | { 24 | "type": "npm", 25 | "script": "test", 26 | "isBackground": true, 27 | "problemMatcher": { 28 | "owner": "typescript", 29 | "pattern": "$tsc", 30 | "background": { 31 | "activeOnStart": true, 32 | "beginsPattern": { 33 | "regexp": "(.*?)" 34 | }, 35 | "endsPattern": { 36 | "regexp": "bundle generation complete" 37 | } 38 | } 39 | } 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Ultimate Courses 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "compileOnSave": false, 4 | "compilerOptions": { 5 | "baseUrl": "./", 6 | "outDir": "./dist/out-tsc", 7 | "forceConsistentCasingInFileNames": true, 8 | "strict": true, 9 | "noImplicitOverride": true, 10 | "noPropertyAccessFromIndexSignature": true, 11 | "noImplicitReturns": true, 12 | "noFallthroughCasesInSwitch": true, 13 | "sourceMap": true, 14 | "paths": { 15 | "ngx-fullscreen": [ 16 | "dist/ngx-fullscreen/ngx-fullscreen", 17 | "dist/ngx-fullscreen" 18 | ] 19 | }, 20 | "declaration": false, 21 | "downlevelIteration": true, 22 | "experimentalDecorators": true, 23 | "moduleResolution": "node", 24 | "importHelpers": true, 25 | "target": "es2017", 26 | "module": "es2020", 27 | "lib": [ 28 | "es2020", 29 | "dom" 30 | ] 31 | }, 32 | "angularCompilerOptions": { 33 | "enableI18nLegacyMessageIdFormat": false, 34 | "strictInjectionParameters": true, 35 | "strictInputAccessModifiers": true, 36 | "strictTemplates": true 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "cli": { 4 | "analytics": false 5 | }, 6 | "version": 1, 7 | "newProjectRoot": "projects", 8 | "projects": { 9 | "ngx-fullscreen": { 10 | "projectType": "library", 11 | "root": "projects/ngx-fullscreen", 12 | "sourceRoot": "projects/ngx-fullscreen/src", 13 | "prefix": "lib", 14 | "architect": { 15 | "build": { 16 | "builder": "@angular-devkit/build-angular:ng-packagr", 17 | "options": { 18 | "project": "projects/ngx-fullscreen/ng-package.json" 19 | }, 20 | "configurations": { 21 | "production": { 22 | "tsConfig": "projects/ngx-fullscreen/tsconfig.lib.prod.json" 23 | }, 24 | "development": { 25 | "tsConfig": "projects/ngx-fullscreen/tsconfig.lib.json" 26 | } 27 | }, 28 | "defaultConfiguration": "production" 29 | }, 30 | "test": { 31 | "builder": "@angular-devkit/build-angular:karma", 32 | "options": { 33 | "main": "projects/ngx-fullscreen/src/test.ts", 34 | "tsConfig": "projects/ngx-fullscreen/tsconfig.spec.json", 35 | "karmaConfig": "projects/ngx-fullscreen/karma.conf.js" 36 | } 37 | } 38 | } 39 | } 40 | }, 41 | "defaultProject": "ngx-fullscreen" 42 | } 43 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ngx-fullscreen", 3 | "description": "Angular Directive that implements the Fullscreen API", 4 | "version": "0.0.0", 5 | "scripts": { 6 | "ng": "ng", 7 | "start": "ng serve", 8 | "build": "ng build", 9 | "watch": "ng build --watch --configuration development", 10 | "test": "ng test" 11 | }, 12 | "repository": { 13 | "url": "https://github.com/ultimatecourses/ngx-fullscreen.git", 14 | "type": "git" 15 | }, 16 | "keywords": [ 17 | "angular", 18 | "directives", 19 | "fullscreen" 20 | ], 21 | "license": "MIT", 22 | "dependencies": { 23 | "@angular/animations": "~13.2.0", 24 | "@angular/common": "~13.2.0", 25 | "@angular/compiler": "~13.2.0", 26 | "@angular/core": "~13.2.0", 27 | "@angular/forms": "~13.2.0", 28 | "@angular/platform-browser": "~13.2.0", 29 | "@angular/platform-browser-dynamic": "~13.2.0", 30 | "@angular/router": "~13.2.0", 31 | "rxjs": "~7.5.0", 32 | "tslib": "^2.3.0", 33 | "zone.js": "~0.11.4" 34 | }, 35 | "devDependencies": { 36 | "@angular-devkit/build-angular": "~13.2.5", 37 | "@angular/cli": "~13.2.5", 38 | "@angular/compiler-cli": "~13.2.0", 39 | "@types/jasmine": "~3.10.0", 40 | "@types/node": "^12.11.1", 41 | "jasmine-core": "~4.0.0", 42 | "karma": "~6.3.0", 43 | "karma-chrome-launcher": "~3.1.0", 44 | "karma-coverage": "~2.1.0", 45 | "karma-jasmine": "~4.0.0", 46 | "karma-jasmine-html-reporter": "~1.7.0", 47 | "ng-packagr": "^13.0.0", 48 | "typescript": "~4.5.2" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /projects/ngx-fullscreen/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | jasmine: { 17 | // you can add configuration options for Jasmine here 18 | // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html 19 | // for example, you can disable the random execution with `random: false` 20 | // or set a specific seed with `seed: 4321` 21 | }, 22 | clearContext: false // leave Jasmine Spec Runner output visible in browser 23 | }, 24 | jasmineHtmlReporter: { 25 | suppressAll: true // removes the duplicated traces 26 | }, 27 | coverageReporter: { 28 | dir: require('path').join(__dirname, '../../coverage/ngx-fullscreen'), 29 | subdir: '.', 30 | reporters: [ 31 | { type: 'html' }, 32 | { type: 'text-summary' } 33 | ] 34 | }, 35 | reporters: ['progress', 'kjhtml'], 36 | port: 9876, 37 | colors: true, 38 | logLevel: config.LOG_INFO, 39 | autoWatch: true, 40 | browsers: ['Chrome'], 41 | singleRun: false, 42 | restartOnFileChange: true 43 | }); 44 | }; 45 | -------------------------------------------------------------------------------- /projects/ngx-fullscreen/src/lib/ngx-fullscreen.directive.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Directive, 3 | Inject, 4 | Input, 5 | Output, 6 | EventEmitter, 7 | HostBinding, 8 | HostListener, 9 | } from '@angular/core'; 10 | import { DOCUMENT } from '@angular/common'; 11 | 12 | /** 13 | * The shape of the Event passed to the parent component 14 | * upon each fullscreen enter/exit transition 15 | */ 16 | export interface NgxFullscreenTransition { 17 | isFullscreen: boolean; 18 | element: Element | null; 19 | } 20 | 21 | @Directive({ 22 | selector: '[ngxFullscreen]', 23 | exportAs: 'ngxFullscreen', 24 | }) 25 | export class NgxFullscreenDirective { 26 | /** 27 | * The Element to go fullscreen 28 | */ 29 | private element!: Element; 30 | 31 | /** 32 | * Returns whether an Element is currently fullscreen 33 | * Also add a HostBinding to the Element 34 | */ 35 | @HostBinding('class.is-fullscreen') 36 | get isFullscreen(): boolean { 37 | return this.doc.fullscreenElement !== null; 38 | } 39 | 40 | /** 41 | * Register the event listener for `fullscreenchange` 42 | * and emit the fullscreen state and element up 43 | */ 44 | @HostListener('document:fullscreenchange') 45 | private onTransition() { 46 | const isFullscreen = this.isFullscreen; 47 | const element = this.doc.fullscreenElement; 48 | this.transition.emit({ isFullscreen, element }); 49 | } 50 | 51 | /** 52 | * Accepts an Element or string type 53 | * 54 | * Element: 55 | * 56 | * 57 | * String (as it is implicitly passed by just declaring 58 | * an empty attribute): 59 | *
60 | */ 61 | @Input() 62 | set ngxFullscreen(element: Element | string) { 63 | if (element instanceof Element) { 64 | this.element = element; 65 | } else if (element === '') { 66 | this.element = this.doc.documentElement; 67 | } else { 68 | throw new Error( 69 | `Only type Element or string allowed, got "${typeof element}".` 70 | ); 71 | } 72 | } 73 | 74 | /** 75 | * Each transition is captured and emitted as NgxFullscreenTransition 76 | * You can import this type inside your component 77 | */ 78 | @Output() 79 | transition = new EventEmitter(); 80 | 81 | /** 82 | * Pass each error up to the parent as a string 83 | * Instead of using the `fullscreenerror` event we're 84 | * using a try/catch and emitting on error 85 | */ 86 | @Output() 87 | errors = new EventEmitter(); 88 | 89 | /** 90 | * Pass the Document object so we can default to this if needed 91 | * Either way, we'll use this for our `fullscreenchange` event 92 | */ 93 | constructor(@Inject(DOCUMENT) private doc: Document) {} 94 | 95 | /** 96 | * Accept an optional Element to enter fullscreen mode 97 | * Either use this element or the registered `this.element` 98 | */ 99 | async enter(element?: Element) { 100 | if (!this.isFullscreen) { 101 | try { 102 | await (element || this.element).requestFullscreen(); 103 | } catch (e: any) { 104 | this.errors.emit(`${e.message} (${e.name})`); 105 | } 106 | } 107 | } 108 | 109 | /** 110 | * Exit via the document.exitFullscreen() method, it doesn't 111 | * matter what Element we have chosen to be fullscreen, the 112 | * way to exit is the same 113 | */ 114 | async exit() { 115 | if (this.isFullscreen) { 116 | try { 117 | await this.doc.exitFullscreen(); 118 | } catch (e: any) { 119 | this.errors.emit(`${e.message} (${e.name})`); 120 | } 121 | } 122 | } 123 | 124 | /** 125 | * Simple toggle method to switch between fullscreen mode" 126 | */ 127 | toggle(element?: Element) { 128 | if (this.isFullscreen) { 129 | this.exit(); 130 | } else { 131 | this.enter(element); 132 | } 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 📺 @ultimate/ngx-fullscreen 3 |

4 |

5 | 6 | Angular Directive that implements the Fullscreen API. 7 |

8 | 9 | --- 10 | 11 | 12 | 13 | 14 | 15 | --- 16 | 17 | ## Installation 18 | 19 | Install via `npm i @ultimate/ngx-fullscreen` and register the `NgxFullscreenModule` into an `@NgModule`. 20 | 21 | ## Live Demo 22 | 23 | Check the [StackBlitz demo](https://ultimate-ngx-fullscreen.stackblitz.io) and the [example code](https://stackblitz.com/edit/ultimate-ngx-fullscreen?file=src%2Fapp%2Fapp.component.ts). 24 | 25 | ## Template API 26 | 27 | `NgxFullscreenDirective` can be used in both template and component (when queried with `@ViewChild`). 28 | 29 | ### ✨ Document or Elements 30 | 31 | *Entire Document:* To fullscreen the `document` just add `ngxFullscreen` into a component template. Internally this uses the `document.documentElement` to enter fullscreen: 32 | 33 | ```html 34 | 35 |
36 | ``` 37 | 38 | *Elements:* Create a Template Ref, e.g. `#video` for the element you wish to fullscreen and pass it into `[ngxFullscreen]`: 39 | 40 | ```html 41 | 42 | 47 | ``` 48 | 49 | ### ✨ Enter Fullscreen Mode 50 | 51 | Export the `ngxFullscreen` directive to a Template Ref, e.g. `#fullscreen` and call `enter()`: 52 | 53 | ```html 54 | 60 | 61 | 64 | ``` 65 | 66 | The `enter()` method also accepts an optional `Element` to pass a dynamic element. 67 | 68 | ### ✨ Exit Fullscreen Mode 69 | 70 | Use the `exit()` method to exit fullscreen mode: 71 | 72 | ```html 73 | 79 | 80 | 83 | ``` 84 | 85 | ### ✨ Toggle Fullscreen Mode 86 | 87 | Use the `toggle()` method to toggle fullscreen mode: 88 | 89 | ```html 90 | 96 | 97 | 100 | ``` 101 | 102 | The `toggle()` method also accepts an optional `Element` to pass a dynamic element. 103 | 104 | ### ✨ Transition Event 105 | 106 | Fires entering and exiting fullscreen mode, using the `fullscreenchange` event behind-the-scenes: 107 | 108 | ```html 109 | 116 | ``` 117 | 118 | The `$event` is of type `NgxFullscreenTransition`, contains the fullscreen status and element that is/was fullscreened. 119 | 120 | ### ✨ isFullscreen property 121 | 122 | Check if fullscreen mode is active via `fullscreen.isFullscreen`. Returns `true` or `false`. 123 | 124 | ```html 125 | 131 | 132 | Fullscreen Mode: {{ fullscreen.isFullscreen ? 'Active' : 'Inactive' }} 133 | ``` 134 | 135 | ### ✨ Active Class 136 | 137 | The fullscreen element will receive an active class `is-fullscreen` via a `@HostBinding`. 138 | 139 | ## @ViewChild and Component API 140 | 141 | The `NgxFullscreenDirective` is exposed when queried with `@ViewChild`, any public methods and properties are also accessible. 142 | 143 | ### ✨ Query with @ViewChild 144 | 145 | Use a `@ViewChild` query and call any property as you would inside the template. 146 | 147 | ```ts 148 | import { 149 | NgxFullscreenDirective, 150 | NgxFullscreenTransition 151 | } from '@ultimate/ngx-fullscreen'; 152 | 153 | @Component({...}) 154 | export class AppComponent implements AfterViewInit { 155 | @ViewChild('fullscreen') fullscreen!: NgxFullscreenDirective; 156 | 157 | onClick() { 158 | this.fullscreen.toggle(); 159 | } 160 | 161 | enterFullscreen() { 162 | this.fullscreen.enter(); 163 | } 164 | 165 | exitFullscreen() { 166 | this.fullscreen.exit(); 167 | } 168 | 169 | ngAfterViewInit() { 170 | this.fullscreen.transition 171 | .subscribe((change: NgxFullscreenTransition) => { 172 | console.log(change); // { isFullscreen: boolean, element: Element } 173 | }); 174 | } 175 | } 176 | ``` 177 | 178 | ### ✨ Errors 179 | 180 | [Fullscreen errors](https://developer.mozilla.org/en-US/docs/Web/API/Document/fullscreenerror_event) are caught when entering and exiting and are passed from the directive via an `errors` event: 181 | 182 | ```ts 183 | @Component({...}) 184 | export class AppComponent implements AfterViewInit { 185 | @ViewChild('fullscreen') fullscreen!: NgxFullscreenDirective; 186 | 187 | ngAfterViewInit() { 188 | this.fullscreen.errors.subscribe((err: string) => { 189 | // e.g. "Failed to execute 'requestFullscreen' on 'Element'" 190 | console.log(err); 191 | }); 192 | } 193 | } 194 | ``` 195 | 196 | ### ⚠ Browser Permissions 197 | 198 | Due to the [Permissions API](https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API), you cannot invoke Fullscreen mode unless it is from a user action, such as a click event. 199 | 200 | This means you cannot load a page and behind the scenes invoke a successful Fullscreen request. This is a common source of errors so keep that in mind. 201 | 202 | -------------------------------------------------------------------------------- /projects/ngx-fullscreen/README.md: -------------------------------------------------------------------------------- 1 |

2 | 📺 @ultimate/ngx-fullscreen 3 |

4 |

5 | 6 | Angular Directive that implements the Fullscreen API. 7 |

8 | 9 | --- 10 | 11 | 12 | 13 | 14 | 15 | --- 16 | 17 | ## Installation 18 | 19 | Install via `npm i @ultimate/ngx-fullscreen` and register the `NgxFullscreenModule` into an `@NgModule`. 20 | 21 | ## Live Demo 22 | 23 | Check the [StackBlitz demo](https://ultimate-ngx-fullscreen.stackblitz.io) and the [example code](https://stackblitz.com/edit/ultimate-ngx-fullscreen?file=src%2Fapp%2Fapp.component.ts). 24 | 25 | ## Template API 26 | 27 | `NgxFullscreenDirective` can be used in both template and component (when queried with `@ViewChild`). 28 | 29 | ### ✨ Document or Elements 30 | 31 | *Entire Document:* To fullscreen the `document` just add `ngxFullscreen` into a component template. Internally this uses the `document.documentElement` to enter fullscreen: 32 | 33 | ```html 34 | 35 |
36 | ``` 37 | 38 | *Elements:* Create a Template Ref, e.g. `#video` for the element you wish to fullscreen and pass it into `[ngxFullscreen]`: 39 | 40 | ```html 41 | 42 | 47 | ``` 48 | 49 | ### ✨ Enter Fullscreen Mode 50 | 51 | Export the `ngxFullscreen` directive to a Template Ref, e.g. `#fullscreen` and call `enter()`: 52 | 53 | ```html 54 | 60 | 61 | 64 | ``` 65 | 66 | The `enter()` method also accepts an optional `Element` to pass a dynamic element. 67 | 68 | ### ✨ Exit Fullscreen Mode 69 | 70 | Use the `exit()` method to exit fullscreen mode: 71 | 72 | ```html 73 | 79 | 80 | 83 | ``` 84 | 85 | ### ✨ Toggle Fullscreen Mode 86 | 87 | Use the `toggle()` method to toggle fullscreen mode: 88 | 89 | ```html 90 | 96 | 97 | 100 | ``` 101 | 102 | The `toggle()` method also accepts an optional `Element` to pass a dynamic element. 103 | 104 | ### ✨ Transition Event 105 | 106 | Fires entering and exiting fullscreen mode, using the `fullscreenchange` event behind-the-scenes: 107 | 108 | ```html 109 | 116 | ``` 117 | 118 | The `$event` is of type `NgxFullscreenTransition`, contains the fullscreen status and element that is/was fullscreened. 119 | 120 | ### ✨ isFullscreen property 121 | 122 | Check if fullscreen mode is active via `fullscreen.isFullscreen`. Returns `true` or `false`. 123 | 124 | ```html 125 | 131 | 132 | Fullscreen Mode: {{ fullscreen.isFullscreen ? 'Active' : 'Inactive' }} 133 | ``` 134 | 135 | ### ✨ Active Class 136 | 137 | The fullscreen element will receive an active class `is-fullscreen` via a `@HostBinding`. 138 | 139 | ## @ViewChild and Component API 140 | 141 | The `NgxFullscreenDirective` is exposed when queried with `@ViewChild`, any public methods and properties are also accessible. 142 | 143 | ### ✨ Query with @ViewChild 144 | 145 | Use a `@ViewChild` query and call any property as you would inside the template. 146 | 147 | ```ts 148 | import { 149 | NgxFullscreenDirective, 150 | NgxFullscreenTransition 151 | } from '@ultimate/ngx-fullscreen'; 152 | 153 | @Component({...}) 154 | export class AppComponent implements AfterViewInit { 155 | @ViewChild('fullscreen') fullscreen!: NgxFullscreenDirective; 156 | 157 | onClick() { 158 | this.fullscreen.toggle(); 159 | } 160 | 161 | enterFullscreen() { 162 | this.fullscreen.enter(); 163 | } 164 | 165 | exitFullscreen() { 166 | this.fullscreen.exit(); 167 | } 168 | 169 | ngAfterViewInit() { 170 | this.fullscreen.transition 171 | .subscribe((change: NgxFullscreenTransition) => { 172 | console.log(change); // { isFullscreen: boolean, element: Element } 173 | }); 174 | } 175 | } 176 | ``` 177 | 178 | ### ✨ Errors 179 | 180 | [Fullscreen errors](https://developer.mozilla.org/en-US/docs/Web/API/Document/fullscreenerror_event) are caught when entering and exiting and are passed from the directive via an `errors` event: 181 | 182 | ```ts 183 | @Component({...}) 184 | export class AppComponent implements AfterViewInit { 185 | @ViewChild('fullscreen') fullscreen!: NgxFullscreenDirective; 186 | 187 | ngAfterViewInit() { 188 | this.fullscreen.errors.subscribe((err: string) => { 189 | // e.g. "Failed to execute 'requestFullscreen' on 'Element'" 190 | console.log(err); 191 | }); 192 | } 193 | } 194 | ``` 195 | 196 | ### ⚠ Browser Permissions 197 | 198 | Due to the [Permissions API](https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API), you cannot invoke Fullscreen mode unless it is from a user action, such as a click event. 199 | 200 | This means you cannot load a page and behind the scenes invoke a successful Fullscreen request. This is a common source of errors so keep that in mind. 201 | 202 | --------------------------------------------------------------------------------