forked from mistic100/Photo-Sphere-Viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavbarCaption.js
More file actions
108 lines (93 loc) · 2.47 KB
/
Copy pathNavbarCaption.js
File metadata and controls
108 lines (93 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { CaptionButton } from '../buttons/CaptionButton';
import { AbstractComponent } from './AbstractComponent';
/**
* @summary Navbar caption class
* @extends PSV.components.AbstractComponent
* @memberof PSV.components
*/
export class NavbarCaption extends AbstractComponent {
static id = 'caption';
/**
* @param {PSV.components.Navbar} navbar
* @param {string} caption
*/
constructor(navbar, caption) {
super(navbar, 'psv-caption');
/**
* @member {PSV.buttons.CaptionButton}
* @readonly
* @private
*/
this.button = new CaptionButton(this);
this.button.hide();
/**
* @override
* @property {string} id
* @property {boolean} collapsable
* @property {number} width
* @property {string} caption
* @property {boolean} contentVisible - if the content is visible in the navbar
* @property {number} contentWidth - with of the caption content
*/
this.prop = {
...this.prop,
id : this.constructor.id,
collapsable : false,
width : this.button.prop.width,
caption : '',
contentVisible: true,
contentWidth : 0,
};
/**
* @member {HTMLElement}
* @readonly
* @private
*/
this.content = document.createElement('div');
this.content.className = 'psv-caption-content';
this.container.appendChild(this.content);
this.setCaption(caption);
}
/**
* @override
*/
destroy() {
delete this.button;
delete this.content;
super.destroy();
}
/**
* @summary Sets the bar caption
* @param {string} html
*/
setCaption(html) {
this.prop.caption = html || '';
this.content.innerHTML = this.prop.caption;
if (html) {
this.show(false);
this.content.style.display = '';
this.prop.contentWidth = this.content.offsetWidth;
this.refreshUi();
}
else {
this.hide();
}
}
/**
* @summary Toggles content and icon depending on available space
* @private
*/
refreshUi() {
const availableWidth = this.container.offsetWidth;
if (availableWidth >= this.prop.contentWidth && !this.prop.contentVisible) {
this.content.style.display = '';
this.prop.contentVisible = true;
this.button.hide(false);
}
else if (availableWidth < this.prop.contentWidth && this.prop.contentVisible) {
this.content.style.display = 'none';
this.prop.contentVisible = false;
this.button.show(false);
}
}
}