source: branches/testa/js/main.js @ 107

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

dispaly message for debug

File size: 3.6 KB
RevLine 
[23]1let Globalx = {};
[25]2let GlobalxInitValue = {
3    editor: null,
4    key_indicate_file: false,
5    key: '/'
6};
[23]7
[27]8function init_globalx_storagex() {
9    Globalx.storagex = new Storagex();
10}
[23]11
[27]12function init_globalx() {
13    Globalx.num = 0;
14    Globalx.index = 0;
15    Globalx.parts = ["data", "output", "setting"]
16    Globalx.bookmark_displayname_max_length = 18
[23]17
[25]18    tab_init()
19    topmenu_init()
[27]20    Globalx.remotex = new Remotex('php/content.php')
21}
[23]22
[27]23function menu_action(part, item_name , up_flag = false) {
24    //console.log("menu_action 1")
25    Globalx[part].sidemenu.menu_action(item_name , up_flag)
26    //console.log("menu_action 2")
27}
[23]28
[27]29function main() {
30    init_globalx_storagex()
[25]31
[27]32    let need_to_save = Globalx.storagex.restore_globalx_from_info()
33    init_globalx()
34
35    Globalx.parts.map( ( part ) => {
36        set_globalx_editor(part)
37        Globalx[ part ].bookmarkmenu = new BookmarkMenu( Globalx.num, part )
38        Globalx[ part ].sidemenu = new SideMenu( Globalx.num, part )
39        Globalx[ part ].sidemenu.setup(`#${part}-side`)
40        Globalx[ part ].bookmarkmenu.set_click_handler()
41        Globalx[ part ].bookmarkmenu.rebuild_bookmark_menu(part)
42
43        $( Globalx[ part ].download_sel ).on('click', {num: Globalx.num, part: part}, handleDownload)
44        $( Globalx[ part ].textarea_sel ).val("");
45    } )
46/*
47    Globalx.parts.map( (part) => {
48        Globalx[ part ].sidemenu.setup(`#${part}-side`)
49        Globalx[ part ].bookmarkmenu.rebuild_bookmark_menu(part)
50
51        $( Globalx[part].download_sel ).on('click', {num: Globalx.num, part: part}, handleDownload)
52        $( Globalx[part].textarea_sel ).val("");
53    }
54  */ 
55    if( need_to_save ){
56        // LocalStorageにまだ保存していない場合、ここで保存しておく
57        //console.log("call save_as_info_from_globalx()")
58        Globalx.storagex.save_as_info_from_globalx( (data) => { console.log( "data=" + data ) } )
59    }
60
61    let part = "data"
62    $( '#bookmark_displayname' ).prop( 'maxlength' , Globalx.bookmark_displayname_max_length)
[25]63    $('#bookmarkDlg').dialog({
64        autoOpen: false,
65        modal: true,
66        buttons: {
67            "OK": function() {
68                part = Globalx.parts[ Globalx.index ]
69                path = $( '#bookmark_path' ).val()
70                displayname = $( '#bookmark_displayname' ).val()
71                register_bookmark_( part , path, displayname )
72                $(this).dialog("close")},
73            "Cancel": function() {
74                bookmark_cb.prop('checked', false)
75                $(this).dialog("close")
76            }
77        }
78    })
[23]79}
80
[25]81
[23]82function set_globalx_editor(part) {
83      Globalx[part] = {
84          editor_id: `${part}-editor`,
85          editor: null,
86          textarea_sel: `textarea[name=${part}-editor-t`,
87/**/
88          menu_id: `${part}-menu2`,
89          bookmark_id: `${part}-bookmark`,
90          bookmark_op_id: `${part}-bookmark_op`,
91          item_name: "",
92/**/
93          bookmarks: [],
94          key_indicate_file: false,
95          key: '/',
96          key_sel: `#${part}-filelist_key`,
[27]97          download_sel: `#${part}-down-download`
[23]98      }
[27]99      editor_config(part);
100
[23]101      Globalx[part].menu_sel = `#${Globalx[part].menu_id}`
102      Globalx[part].bookmark_sel = `#${Globalx[part].bookmark_id}`
103      Globalx[part].bookmark_op_sel = `#${Globalx[part].bookmark_op_id}`
[27]104      Globalx[part].bookmark_mgr = new BookmarkMgr( Globalx.bookmark_displayname_max_length )
[23]105}
106
[27]107function editor_config(part) {
[23]108      let editor = ace.edit( Globalx[part].editor_id )
109      editor.setTheme("ace/theme/monokai");
110      editor.setFontSize(14);
111      editor.getSession().setMode("ace/mode/markdown");
112      editor.getSession().setUseWrapMode(true);
113      editor.getSession().setTabSize(2);
114      Globalx[part].editor = editor;
115      let textarea = $( Globalx[part].textarea_sel );
116      Globalx[part].textarea = textarea;
117      editor.getSession().on("change", function () {
118          Globalx[part].textarea.val(editor.getSession().getValue());
119      });
120}
Note: See TracBrowser for help on using the repository browser.