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

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

init

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