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

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

full, partial

File size: 5.4 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
47function set_output_url_listx(text){
48    if( text.match( /{.*}/ ) !== null ){
49        const obj = JSON.parse( text )
50        //console.log("update_all_info_on_host text=" + text )
51        Globalx.output_url_listx = {}
52        obj["htmlfname"].forEach( (item) => {
53            let words = item.full.split('.')
54            let base = words[0]
55            Globalx.output_url_listx[ base ] = {}
56            Globalx.output_url_listx[ base ].full = `${obj["output_url"]}/${item.full}`
57            Globalx.output_url_listx[ base ].partial = `${obj["output_url"]}/${item.partial}`
58            console.log(`${words[0].full}=${ Globalx.output_url_listx[ base ].full }`)
59            console.log(`${words[0].partial}=${ Globalx.output_url_listx[ base ].partial }`)
60        } )
61        Globalx.storagex.save_as_info_from_globalx()
62    }
63}
64
65async function update_all_info_on_host_async( ) {
66    await Globalx.remotex.update_output_url_listx( Globalx.num , (text) => {
67        set_output_url_listx(text)
68    } )
69
70    Globalx.parts.map( ( part ) => {
71        Globalx[ part ].sidemenu.update(`#${part}-side`)
72    } )
73
74}
75
76async function get_output_url( num ){
77    get_output_url_async( num, (str) => {
78        if( str.match( /{.*}/ ) !== null ){
79            const obj = JSON.parse( str )
80//console.log("get_output_url obj=" + obj.output_url)
81            Globalx.output_url = obj.output_url
82            Globalx.storagex.save_as_info_from_globalx()
83        }
84    } )
85
86}
87async function get_output_url_async( num, func ){
88    let output_url = Globalx.storagex.get_output_url()
89
90    if( output_url === undefined || output_url === null ){
91        await Globalx.remotex.get_output_url( num, func )
92    }
93    else{
94        Globalx.output_url = output_url
95        Globalx.storagex.save_as_info_from_globalx()
96    }
97}
98
99async function get_output_url_listx_async( num ) {
100    await Globalx.remotex.get_output_url_listx( num , (text) => {
101        set_output_url_listx(text)
102    } )
103}
104
105async function setup(){
106    await get_output_url_listx_async( Globalx.num )
107//    await get_output_url( Globalx.num )
108}
109
110
111function main() {
112    init_globalx_storagex()
113
114    let need_to_save = Globalx.storagex.restore_globalx_from_info()
115    init_globalx()
116    setup()
117
118    Globalx.bookmarkmenu = new BookmarkMenu( Globalx.bookmark_displayname_max_length , Globalx.bookmark_mgr )
119    Globalx.bookmarkmenu.dlg()
120
121    Globalx.parts.map( ( part ) => {
122        set_globalx_editor(part)
123
124        Globalx[ part ].menu = null
125        Globalx[ part ].sidemenu = new SideMenu( Globalx.num, part )
126        Globalx[ part ].sidemenu.setup(`#${part}-side`)
127
128        $( Globalx[ part ].download_sel ).on('click', {num: Globalx.num, part: part}, handleDownload)
129        $( Globalx[ part ].textarea_sel ).val("");
130        Globalx.bookmarkmenu.rebuild_bookmark_menu(part)
131        Globalx.bookmarkmenu.set_click_handler(part)
132    } )
133
134    if( need_to_save ){
135        // LocalStorageにまだ保存していない場合、ここで保存しておく
136        Globalx.storagex.save_as_info_from_globalx( (data) => { console.log( "data=" + data ) } )
137    }
138}
139
140
141function set_globalx_editor(part) {
142      Globalx[part] = {
143          editor_id: `${part}-editor`,
144          editor: null, /* variable */
145          textarea_sel: `textarea[name=${part}-editor-t`,
146/**/
147          menu_id: `${part}-menu2`,
148          bookmark_id: `${part}-bookmark`,
149          bookmark_op_id: `${part}-bookmark_op`,
150          item_name: "",
151/**/
152          bookmarks: [],
153          key_indicate_file: false, /* variable */
154          key: '/',
155          key_sel: `#${part}-filelist_key`,
156          download_sel: `#${part}-down-download`,
157          download_url_sel: `#${part}-down-url`,
158          download_partial_url_sel: `#${part}-partial-down-url`
159      }
160      editor_config(part);
161
162      Globalx[part].menu_sel = `#${Globalx[part].menu_id}`
163      Globalx[part].bookmark_sel = `#${Globalx[part].bookmark_id}`
164      Globalx[part].bookmark_op_sel = `#${Globalx[part].bookmark_op_id}`
165}
166
167function editor_config(part) {
168      let editor = ace.edit( Globalx[part].editor_id )
169      editor.setTheme("ace/theme/monokai");
170      editor.setFontSize(14);
171      editor.getSession().setMode("ace/mode/markdown");
172      editor.getSession().setUseWrapMode(true);
173      editor.getSession().setTabSize(2);
174      Globalx[part].editor = editor;
175
176      let textarea = $( Globalx[part].textarea_sel )
177      editor.getSession().on("change", () => {
178/*          textarea.val(editor.getSession().getValue()) */
179          $( Globalx[part].textarea_sel ).val(editor.getSession().getValue())
180      });
181}
182
183function upload_to_host( part ){
184    Globalx.remotex.upload_to_host( part )
185}
Note: See TracBrowser for help on using the repository browser.