source: branches/testa-single-bookmark/js/main.js @ 37

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

hide unused menu by css

File size: 4.0 KB
Line 
1let Globalx = {};
2const GlobalxItems = ["output_url"]
3const GlobalxInitValue = {
4    editor: null,
5    key_indicate_file: false,
6    key: '/'
7};
8const GlobalxInitValueItems = ["editor", "key_indicate_file", "key"]
9
10function init_globalx_storagex() {
11    Globalx.storagex = new Storagex();
12}
13
14function init_globalx() {
15    Globalx.num = 0
16    Globalx.index = 0
17    Globalx.parts = ["data", "output", "setting"]
18    Globalx.bookmark_displayname_max_length = 18
19    Globalx.output_url = null
20
21    tab_init()
22    topmenu_init()
23    Globalx.remotex = new Remotex('php/content.php')
24    console.log( "init_globalx 1 : Globalx.bookmark_mgr="  + Globalx.bookmark_mgr )
25    if( Globalx.bookmark_mgr === null || Globalx.bookmark_mgr === undefined ){
26        Globalx.bookmark_mgr = new BookmarkMgr(Globalx.bookmark_displayname_max_length, Globalx.parts)
27    }
28    console.log( "init_globalx 2 : Globalx.bookmark_mgr="  + Globalx.bookmark_mgr )
29    Globalx.bookmarkmenu = null
30}
31
32async function get_output_url_async( func ){
33    let realData = Globalx.storagex.get_output_url()
34
35    if( realData === undefined || realData === null ){
36        await Globalx.remotex.get_output_url( func )
37    }
38    else{
39        const obj = Globalx.storagex.get_output_url( num , part )
40        Globalx.output_url = obj.output_url
41        Globalx.storagex.save_as_info_from_globalx()
42    }
43}
44
45async function setup(){
46    get_output_url_async( (text) => {
47        let str = text
48        let obj
49        if( str.match( /{.*}/ ) === null ){
50            obj = {}
51        }
52        else {
53            obj = JSON.parse( str )
54        }
55        Globalx.storagex.change_cache( obj, this.num , this.part )
56    } )
57}
58
59
60function main() {
61    init_globalx_storagex()
62
63    let need_to_save = Globalx.storagex.restore_globalx_from_info()
64    init_globalx()
65    setup()
66
67    console.log("##### Globalx.bookmarkmenu=" + Globalx.bookmarkmenu)
68    console.log("##### Globalx.bookmark_mgr=" + Globalx.bookmark_mgr)
69    Globalx.bookmarkmenu = new BookmarkMenu( Globalx.bookmark_displayname_max_length , Globalx.bookmark_mgr )
70    Globalx.bookmarkmenu.dlg()
71
72    Globalx.parts.map( ( part ) => {
73        set_globalx_editor(part)
74
75        Globalx[ part ].sidemenu = new SideMenu( Globalx.num, part )
76        Globalx[ part ].sidemenu.setup(`#${part}-side`)
77
78        $( Globalx[ part ].download_sel ).on('click', {num: Globalx.num, part: part}, handleDownload)
79        $( Globalx[ part ].textarea_sel ).val("");
80        Globalx.bookmarkmenu.rebuild_bookmark_menu(part)
81        Globalx.bookmarkmenu.set_click_handler(part)
82    } )
83
84    if( need_to_save ){
85        // LocalStorageにまだ保存していない場合、ここで保存しておく
86        //console.log("call save_as_info_from_globalx()")
87        Globalx.storagex.save_as_info_from_globalx( (data) => { console.log( "data=" + data ) } )
88    }
89/*
90    Object.keys(Globalx).forEach((key) => {
91        console.log(key)
92    }) */
93}
94
95
96function set_globalx_editor(part) {
97      Globalx[part] = {
98          editor_id: `${part}-editor`,
99          editor: null, /* variable */
100          textarea_sel: `textarea[name=${part}-editor-t`,
101/**/
102          menu_id: `${part}-menu2`,
103          bookmark_id: `${part}-bookmark`,
104          bookmark_op_id: `${part}-bookmark_op`,
105          item_name: "",
106/**/
107          bookmarks: [],
108          key_indicate_file: false, /* variable */
109          key: '/',
110          key_sel: `#${part}-filelist_key`,
111          download_sel: `#${part}-down-download`,
112          download_url_sel: `#${part}-down-url`,
113          download_partial_url_sel: `#${part}-partial-down-url`
114      }
115      editor_config(part);
116
117      Globalx[part].menu_sel = `#${Globalx[part].menu_id}`
118      Globalx[part].bookmark_sel = `#${Globalx[part].bookmark_id}`
119      Globalx[part].bookmark_op_sel = `#${Globalx[part].bookmark_op_id}`
120}
121
122function editor_config(part) {
123      let editor = ace.edit( Globalx[part].editor_id )
124      editor.setTheme("ace/theme/monokai");
125      editor.setFontSize(14);
126      editor.getSession().setMode("ace/mode/markdown");
127      editor.getSession().setUseWrapMode(true);
128      editor.getSession().setTabSize(2);
129      Globalx[part].editor = editor;
130
131      let textarea = $( Globalx[part].textarea_sel )
132      editor.getSession().on("change", (textarea) => {
133          textarea.val(editor.getSession().getValue());
134      });
135}
Note: See TracBrowser for help on using the repository browser.