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

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

set_anchor_url

File size: 5.1 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    Globalx.build = {
13        'contest2011.md': {
14            path: '/attempt/contest2011/data/contest2011.md',
15            target: 'cont',
16            subtarget: '2011',
17            category: 'attempt',
18            output_html: 'contest2011.html',
19            alias_html: 'contest.html',
20        }
21    }
22
23}
24
25
26function init_globalx() {
27    Globalx.num = 0
28    Globalx.index = 0
29    Globalx.parts = ["data" , "output", "conf"]
30    Globalx.bookmark_displayname_max_length = 18
31    Globalx.output_url = null
32    Globalx.output_url_listx = null
33    Globalx.remote_filename = 'php/content3.php'
34    Globalx.build = new Build()
35
36    tab_init()
37    topmenu_init()
38    Globalx.remotex = new Remotex( Globalx.remote_filename )
39    if( Globalx.bookmark_mgr === null || Globalx.bookmark_mgr === undefined ){
40        Globalx.bookmark_mgr = new BookmarkMgr(Globalx.bookmark_displayname_max_length, Globalx.parts)
41    }
42    Globalx.bookmarkmenu = null
43
44    Globalx.build.setup('data')
45}
46
47async function update_all_info_on_host_async( ) {
48    await Globalx.remotex.get_output_url_listx( Globalx.num , (text) => {
49        if( text.match( /{.*}/ ) !== null ){
50            const obj = JSON.parse( text )
51//console.log("update_all_info_on_host text=" + text )
52            Globalx.output_url_listx = obj
53            Globalx.storagex.save_as_info_from_globalx()
54        }
55    } )
56
57    Globalx.parts.map( ( part ) => {
58        Globalx[ part ].sidemenu.update(`#${part}-side`)
59    } )
60
61}
62
63async function get_output_url( num ){
64    get_output_url_async( num, (str) => {
65        if( str.match( /{.*}/ ) !== null ){
66            const obj = JSON.parse( str )
67//console.log("get_output_url obj=" + obj.output_url)
68            Globalx.output_url = obj.output_url
69            Globalx.storagex.save_as_info_from_globalx()
70        }
71    } )
72
73}
74async function get_output_url_async( num, func ){
75    let output_url = Globalx.storagex.get_output_url()
76
77    if( output_url === undefined || output_url === null ){
78        await Globalx.remotex.get_output_url( num, func )
79    }
80    else{
81        Globalx.output_url = output_url
82        Globalx.storagex.save_as_info_from_globalx()
83    }
84}
85
86async function get_output_url_listx_async( num ) {
87    await Globalx.remotex.get_output_url_listx( num , (text) => {
88        if( text.match( /{.*}/ ) !== null ){
89            const obj = JSON.parse( text )
90//console.log("update_all_info_on_host text=" + text )
91            Globalx.output_url_listx = obj
92            Globalx.storagex.save_as_info_from_globalx()
93        }
94    } )
95}
96async function setup(){
97    await get_output_url_listx_async( Globalx.num )
98    await get_output_url( Globalx.num )
99}
100
101
102function main() {
103    init_globalx_storagex()
104
105    let need_to_save = Globalx.storagex.restore_globalx_from_info()
106    init_globalx()
107    setup()
108
109    Globalx.bookmarkmenu = new BookmarkMenu( Globalx.bookmark_displayname_max_length , Globalx.bookmark_mgr )
110    Globalx.bookmarkmenu.dlg()
111
112    Globalx.parts.map( ( part ) => {
113        set_globalx_editor(part)
114
115        Globalx[ part ].menu = null
116        Globalx[ part ].sidemenu = new SideMenu( Globalx.num, part )
117        Globalx[ part ].sidemenu.setup(`#${part}-side`)
118
119        $( Globalx[ part ].download_sel ).on('click', {num: Globalx.num, part: part}, handleDownload)
120        $( Globalx[ part ].textarea_sel ).val("");
121        Globalx.bookmarkmenu.rebuild_bookmark_menu(part)
122        Globalx.bookmarkmenu.set_click_handler(part)
123    } )
124
125    if( need_to_save ){
126        // LocalStorageにまだ保存していない場合、ここで保存しておく
127        Globalx.storagex.save_as_info_from_globalx( (data) => { console.log( "data=" + data ) } )
128    }
129}
130
131
132function set_globalx_editor(part) {
133      Globalx[part] = {
134          editor_id: `${part}-editor`,
135          editor: null, /* variable */
136          textarea_sel: `textarea[name=${part}-editor-t`,
137/**/
138          menu_id: `${part}-menu2`,
139          bookmark_id: `${part}-bookmark`,
140          bookmark_op_id: `${part}-bookmark_op`,
141          item_name: "",
142/**/
143          bookmarks: [],
144          key_indicate_file: false, /* variable */
145          key: '/',
146          key_sel: `#${part}-filelist_key`,
147          download_sel: `#${part}-down-download`,
148          download_url_sel: `#${part}-down-url`,
149          download_partial_url_sel: `#${part}-partial-down-url`
150      }
151      editor_config(part);
152
153      Globalx[part].menu_sel = `#${Globalx[part].menu_id}`
154      Globalx[part].bookmark_sel = `#${Globalx[part].bookmark_id}`
155      Globalx[part].bookmark_op_sel = `#${Globalx[part].bookmark_op_id}`
156}
157
158function editor_config(part) {
159      let editor = ace.edit( Globalx[part].editor_id )
160      editor.setTheme("ace/theme/monokai");
161      editor.setFontSize(14);
162      editor.getSession().setMode("ace/mode/markdown");
163      editor.getSession().setUseWrapMode(true);
164      editor.getSession().setTabSize(2);
165      Globalx[part].editor = editor;
166
167      let textarea = $( Globalx[part].textarea_sel )
168      editor.getSession().on("change", () => {
169/*          textarea.val(editor.getSession().getValue()) */
170          $( Globalx[part].textarea_sel ).val(editor.getSession().getValue())
171      });
172}
173
174function upload_to_host( part ){
175    Globalx.remotex.upload_to_host( part )
176}
Note: See TracBrowser for help on using the repository browser.