source: branches/testa/js/menux.js @ 28

Last change on this file since 28 was 25, checked in by anonymous, 6 years ago

use localstorage to store/restore settings

File size: 5.3 KB
RevLine 
[23]1function make_ul_for_menu( part, sel ) {
2    let content = `<ul id="${Globalx[part].menu_id}"></ul>`
3    let v = $(sel).append( content )
4}
5
6function set_globalx_item_name( part, item_name ) {
7    Globalx[part].item_name = item_name
8    let dl = $( '#download' )
9    dl.attr('download' , Globalx[part].item_name)
10    dl.removeAttr('href')
11}
12
13function menu_action( part, item_name , up_flag = false ) {
[25]14    if( Globalx[part].key != '/' ){
15       
16    }
17
[23]18    let realData = get_filelist( Globalx.num )
19    Globalx[part].key_indicate_file = false;
20    if( up_flag ){
21        set_globalx_item_name(part, "")
22        Globalx[part].editor.getSession().setValue( "" );
23        $( Globalx[part].textarea_sel ).val( "" );
24        if( Globalx[part].key != '/' ){
25            let array = Globalx[part].key.split("/")
26            array.pop()
27            if( array.length > 1 ){
28                Globalx[part].key_type = false;
29                set_globalx_item_name( part, array[array.length - 1] )
30
31                Globalx[part].key = array.join('/')
32                $( Globalx[part].menu_sel ).empty()
33            }
34            else {
35                Globalx[part].key = '/'
36                set_globalx_item_name( part, "" )
37            }
38        }
39    }
40    else{
41        if( Globalx[part].key == '/' ){
42            Globalx[part].key = Globalx[part].key + item_name
43        }
44        else{
45            Globalx[part].key = Globalx[part].key + '/' + item_name
46        }
47    }
48    set_globalx_item_name(part, item_name)
49
50    const bookmark_cb = $( Globalx[part].bookmark_op_sel )
51    if( Globalx[part].bookmarks.indexOf( Globalx[part].key ) >= 0 ){
52        bookmark_cb.prop('checked', true)
53    }
54    else{
55        bookmark_cb.prop('checked', false)
56    }
57
58    $( Globalx[part].key_sel ).val( Globalx[part].key )
59    $( Globalx[part].menu_sel ).empty()
60
61    make_menu_item_list(part, realData)
62
63    if( realData[Globalx[part].key].length == 0 ){
64        Globalx[part].key_indicate_file = true;
65        get_content( Globalx[part].key , function(content) {
66            Globalx[part].editor.getSession().setValue( content );
67            $( Globalx[part].textarea_sel ).val( content );
68        });
69    }
70}
71
72function make_menu_item_list( part, realData ) {
73    let content = null
74    let ary = realData[ Globalx[part].key ]
75
76    let name = '..(Up)'
77    content = `<li class="ui-menu-item"><div class="ui-menu-item-wrapper hasmenu" onclick="menu_action( '${part}', '${name}', true)">${name}</div></li>`;
78    $( Globalx[part].menu_sel ).append(content);
79
80    ary.map( function( item_name ){
81        content = `<li class="ui-menu-item"><div class="ui-menu-item-wrapper hasmenu" onclick="menu_action( '${part}', '${item_name}' , false)">${item_name}</div></li>`;
82        $( Globalx[part].menu_sel ).append(content);
83    })
84}
85
86async function get_filelist_async( num )
87{
88     let realData = get_filelist( Globalx.num )
89     if( realData === undefined ){
90        await get_filelist_from_remote()
91        realData = get_filelist( Globalx.num )
92    }
93
94    return realData
95}
96
97function menux( part ) {
98    get_filelist_async( Globalx.num ).then( (data) => {
99        make_menu_item_list( part, data )
100        $( Globalx[part].menu_sel ).menu({
101            classes: {
102                "ui-menu": "highlight"
103            }
104        })
105    })
106}
107
108function contextmenux0( menu_sel ) {
109    $( menu_sel ).contextmenu({
110        delegate: ".hasmenu",
111        menu: [
112            {title: "Copy", cmd: "copy", uiIcon: "ui-icon-copy"},
113            {title: "----"},
114            {title: "More", childern: [
115                {title: "Sub 1", cmd: "sub1"},
116                {title: "Sub 2", cmd: "sub1"}
117            ]}
118        ],
119        select: function(event, ui) {
120            alert("select " + ui.cmd + " on " + ui.target.text());
121        }
122    });
123}
124
125function bookmark_op(part) {
126    if( $( Globalx[part].bookmark_op_sel ).is(':checked') == true ){
127        add_bookmark(part)
128    }
129    else{
130        remove_bookmark(part)
131    }
132}
133
134function add_bookmark( part ) {
135    $( '#bookmark_displayname' ).val( Globalx[part].bookmark_mgr.get_restricted_display_name( Globalx[part].key ) )
136    $( '#bookmark_path' ).val( Globalx[part].key )
137    $('#bookmarkDlg').dialog("open")
138}
139
[25]140function register_bookmark_( part , path, displayname ) {
141    Globalx[part].bookmark_mgr.add( path , displayname )
142    rebuild_bookmark_menu( part )
143}
144
[23]145function remove_bookmark(part) {
146    Globalx[part].bookmark_mgr.remove( Globalx[part].key )
147    rebuild_bookmark_menu(part)
148}
149
150function rebuild_bookmark_menu(part) {
151    $( Globalx[part].bookmark_sel ).empty()
152
153    const mgr = Globalx[part].bookmark_mgr
154    const array = mgr.get_paths()
155
156    array.map( function( path ){
157        const display_name = mgr.display_name( path )
158        content = `<li><a href="#" onclick="bookmark_action( '${part}' , '${path}' )">${display_name}</a></li>`;
159        $( Globalx[part].bookmark_sel ).append(content);
160    })
161}
162
163function bookmark_action( part, key ) {
164    if( key === null || key === "" ){
165        alert("illeagal key=" + key )
166        return
167    }
[25]168    if(key === Globalx[part].key){
169        return
170    }
171
[23]172    let realData = get_filelist( Globalx.num )
173    Globalx[part].key = key
174    Globalx[part].key_indicate_file = false;
175
176    set_globalx_item_name( part, key )
177    $( Globalx[part].key_sel ).val( key )
178
179    if( realData[Globalx[part].key].length == 0 ){
180        Globalx[part].key_indicate_file = true;
181        get_content( Globalx[part].key , function(content) {
182            Globalx[part].editor.getSession().setValue( content );
183            $( Globalx[part].textarea_sel ).val( content );
184        });
185    }
[25]186    else{
187        Globalx[part].key_indicate_file = false
188        Globalx[part].editor.getSession().setValue( "" );
189        $( Globalx[part].textarea_sel ).val( "" );
190    }
[23]191    const bookmark_cb = $( Globalx[part].bookmark_op_sel )
192    bookmark_cb.prop('checked', true)
[25]193
194    $( Globalx[part].menu_sel ).empty()
195
196    make_menu_item_list(part, realData)
[23]197}
[25]198
Note: See TracBrowser for help on using the repository browser.