1111
1212import Ember from 'ember' ;
1313import TooltipMixin from '../../mixins/tooltip' ;
14+ import NotifierMixin from '../../mixins/notifier' ;
1415
15- export default Ember . Component . extend ( TooltipMixin , {
16+ export default Ember . Component . extend ( TooltipMixin , NotifierMixin , {
1617 documentService : Ember . inject . service ( 'document' ) ,
1718 document : { } ,
1819 folder : { } ,
1920 showToc : true ,
2021 showViews : false ,
2122 showContributions : false ,
23+ showSections : false ,
24+ showScrollTool : false ,
25+ showingSections : false ,
2226
2327 didRender ( ) {
2428 if ( this . session . authenticated ) {
2529 this . addTooltip ( document . getElementById ( "owner-avatar" ) ) ;
30+ this . addTooltip ( document . getElementById ( "section-tool" ) ) ;
2631 }
2732 } ,
2833
29- willDestroyElements ( ) {
30- this . destroyElements ( ) ;
34+ didInsertElement ( ) {
35+ this . eventBus . subscribe ( 'resized' , this , 'positionTool' ) ;
36+ this . eventBus . subscribe ( 'scrolled' , this , 'positionTool' ) ;
37+ } ,
38+
39+ willDestroyElement ( ) {
40+ this . destroyTooltips ( ) ;
41+ } ,
42+
43+ positionTool ( ) {
44+ if ( this . get ( 'isDestroyed' ) || this . get ( 'isDestroying' ) ) {
45+ return ;
46+ }
47+
48+ let s = $ ( ".scroll-tool" ) ;
49+ let windowpos = $ ( window ) . scrollTop ( ) ;
50+
51+ if ( windowpos >= 300 ) {
52+ this . set ( 'showScrollTool' , true ) ;
53+ s . addClass ( "stuck-tool" ) ;
54+ s . css ( 'left' , parseInt ( $ ( ".zone-sidebar" ) . css ( 'width' ) ) - 18 + 'px' ) ;
55+ } else {
56+ this . set ( 'showScrollTool' , false ) ;
57+ s . removeClass ( "stuck-tool" ) ;
58+ }
3159 } ,
3260
3361 actions : {
@@ -45,27 +73,55 @@ export default Ember.Component.extend(TooltipMixin, {
4573 return this . attrs . gotoPage ( id ) ;
4674 } ,
4775
48- // close dialog
49- close ( ) {
50- return true ;
51- } ,
52-
5376 showToc ( ) {
5477 this . set ( 'showToc' , true ) ;
5578 this . set ( 'showViews' , false ) ;
5679 this . set ( 'showContributions' , false ) ;
80+ this . set ( 'showSections' , false ) ;
81+ this . set ( 'showingSections' , false ) ;
5782 } ,
5883
5984 showViews ( ) {
6085 this . set ( 'showToc' , false ) ;
6186 this . set ( 'showViews' , true ) ;
6287 this . set ( 'showContributions' , false ) ;
88+ this . set ( 'showSections' , false ) ;
89+ this . set ( 'showingSections' , false ) ;
6390 } ,
6491
6592 showContributions ( ) {
6693 this . set ( 'showToc' , false ) ;
6794 this . set ( 'showViews' , false ) ;
6895 this . set ( 'showContributions' , true ) ;
96+ this . set ( 'showSections' , false ) ;
97+ this . set ( 'showingSections' , false ) ;
98+ } ,
99+
100+ showSections ( ) {
101+ this . set ( 'showToc' , false ) ;
102+ this . set ( 'showViews' , false ) ;
103+ this . set ( 'showContributions' , false ) ;
104+ this . set ( 'showSections' , true ) ;
105+ this . set ( 'showingSections' , true ) ;
106+ } ,
107+
108+ onCancel ( ) {
109+ this . send ( 'showToc' ) ;
110+ this . set ( 'showingSections' , false ) ;
111+ } ,
112+
113+ onAddSection ( section ) {
114+ this . attrs . onAddSection ( section ) ;
115+
116+ this . set ( 'showingSections' , false ) ;
117+ } ,
118+
119+ scrollTop ( ) {
120+ this . set ( 'showScrollTool' , false ) ;
121+
122+ $ ( "html,body" ) . animate ( {
123+ scrollTop : 0
124+ } , 500 , "linear" ) ;
69125 }
70126 }
71127} ) ;
0 commit comments