mirror of
				https://github.com/BookStackApp/BookStack.git
				synced 2025-10-31 03:50:27 +03:00 
			
		
		
		
	Extracted functions out of app file during changes to clean up. Altered animation function to use normal css prop names instead of JS CSS prop names.
		
			
				
	
	
		
			49 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import {slideDown, slideUp} from '../services/animations.ts';
 | |
| import {Component} from './component';
 | |
| 
 | |
| /**
 | |
|  * Collapsible
 | |
|  * Provides some simple logic to allow collapsible sections.
 | |
|  */
 | |
| export class Collapsible extends Component {
 | |
| 
 | |
|     setup() {
 | |
|         this.container = this.$el;
 | |
|         this.trigger = this.$refs.trigger;
 | |
|         this.content = this.$refs.content;
 | |
| 
 | |
|         if (this.trigger) {
 | |
|             this.trigger.addEventListener('click', this.toggle.bind(this));
 | |
|             this.openIfContainsError();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     open() {
 | |
|         this.container.classList.add('open');
 | |
|         this.trigger.setAttribute('aria-expanded', 'true');
 | |
|         slideDown(this.content, 300);
 | |
|     }
 | |
| 
 | |
|     close() {
 | |
|         this.container.classList.remove('open');
 | |
|         this.trigger.setAttribute('aria-expanded', 'false');
 | |
|         slideUp(this.content, 300);
 | |
|     }
 | |
| 
 | |
|     toggle() {
 | |
|         if (this.container.classList.contains('open')) {
 | |
|             this.close();
 | |
|         } else {
 | |
|             this.open();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     openIfContainsError() {
 | |
|         const error = this.content.querySelector('.text-neg.text-small');
 | |
|         if (error) {
 | |
|             this.open();
 | |
|         }
 | |
|     }
 | |
| 
 | |
| }
 |