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

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

hide unused menu by css

File size: 4.0 KB
RevLine 
[23]1let Globalx = {};
[36]2const GlobalxItems = ["output_url"]
3const GlobalxInitValue = {
[25]4    editor: null,
5    key_indicate_file: false,
6    key: '/'
7};
[36]8const GlobalxInitValueItems = ["editor", "key_indicate_file", "key"]
[23]9
[27]10function init_globalx_storagex() {
11    Globalx.storagex = new Storagex();
12}
[23]13
[27]14function init_globalx() {
[36]15    Globalx.num = 0
16    Globalx.index = 0
[27]17    Globalx.parts = ["data", "output", "setting"]
18    Globalx.bookmark_displayname_max_length = 18
[36]19    Globalx.output_url = null
[23]20
[25]21    tab_init()
22    topmenu_init()
[27]23    Globalx.remotex = new Remotex('php/content.php')
[36]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
[27]30}
[23]31
[36]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    } )
[27]57}
[23]58
[36]59
[27]60function main() {
61    init_globalx_storagex()
[25]62
[27]63    let need_to_save = Globalx.storagex.restore_globalx_from_info()
64    init_globalx()
[36]65    setup()
[27]66
[36]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
[27]72    Globalx.parts.map( ( part ) => {
73        set_globalx_editor(part)
[36]74
[27]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("");
[36]80        Globalx.bookmarkmenu.rebuild_bookmark_menu(part)
81        Globalx.bookmarkmenu.set_click_handler(part)
[27]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    }
[36]89/*
90    Object.keys(Globalx).forEach((key) => {
91        console.log(key)
92    }) */
[23]93}
94
[25]95
[23]96function set_globalx_editor(part) {
97      Globalx[part] = {
98          editor_id: `${part}-editor`,
[36]99          editor: null, /* variable */
[23]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/**/
[36]107          bookmarks: [],
108          key_indicate_file: false, /* variable */
109          key: '/',
[23]110          key_sel: `#${part}-filelist_key`,
[36]111          download_sel: `#${part}-down-download`,
112          download_url_sel: `#${part}-down-url`,
113          download_partial_url_sel: `#${part}-partial-down-url`
[23]114      }
[27]115      editor_config(part);
116
[23]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
[27]122function editor_config(part) {
[23]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;
[36]130
131      let textarea = $( Globalx[part].textarea_sel )
132      editor.getSession().on("change", (textarea) => {
133          textarea.val(editor.getSession().getValue());
[23]134      });
135}
Note: See TracBrowser for help on using the repository browser.