-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathbook.view.ts
69 lines (53 loc) · 1.45 KB
/
book.view.ts
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
namespace $.$$ {
/** @deprecated Use $mol_book2 **/
export class $mol_book extends $.$mol_book {
@ $mol_mem
pages_extended() : $mol_view[] {
return [ this.Placeholder() , ... this.pages() ]
}
@ $mol_mem
break_point() {
const pages = this.pages_extended()
const limit = this.width()
let width = 0
for( var break_point = pages.length ; break_point > 0 ; -- break_point ) {
const page = pages[ break_point - 1 ]
if( !page ) continue
const page_width = page.minimal_width()
if( width + page_width > limit ) break
width += page_width
}
if( width === 0 ) -- break_point
return break_point
}
page( index : number ) {
return this.pages_extended()[ index ]
}
page_visible( index : number ) {
return index >= this.break_point()
}
@ $mol_mem
pages_wrapped() {
const pages = this.pages_extended()
const extended = [] as typeof pages
for( let i = 1 ; i < pages.length ; ++i ) {
if( pages[ i ] ) extended.push( this.Page( i ) )
}
if( pages[ 0 ] ) extended.push( this.Page( 0 ) )
return extended
}
title() {
return this.pages().map( page => page.title() ).reverse().join( ' | ' )
}
event_front_up( event? : Event ) {
if( !event ) return
if( event.defaultPrevented ) return
this.page(1).focused( true )
}
event_front_down( event? : Event ) {
if( !event ) return
if( event.defaultPrevented ) return
this.page(1).focused( false )
}
}
}