| [23] | 1 | let Globalx = {}; |
|---|
| [36] | 2 | const GlobalxItems = ["output_url"] |
|---|
| 3 | const GlobalxInitValue = { |
|---|
| [25] | 4 | editor: null, |
|---|
| 5 | key_indicate_file: false, |
|---|
| 6 | key: '/' |
|---|
| 7 | }; |
|---|
| [36] | 8 | const GlobalxInitValueItems = ["editor", "key_indicate_file", "key"] |
|---|
| [23] | 9 | |
|---|
| [27] | 10 | function init_globalx_storagex() { |
|---|
| 11 | Globalx.storagex = new Storagex(); |
|---|
| [41] | 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 | |
|---|
| [27] | 23 | } |
|---|
| [23] | 24 | |
|---|
| [41] | 25 | |
|---|
| [27] | 26 | function init_globalx() { |
|---|
| [36] | 27 | Globalx.num = 0 |
|---|
| 28 | Globalx.index = 0 |
|---|
| [59] | 29 | Globalx.parts = ["data" , "output", "conf"] |
|---|
| [27] | 30 | Globalx.bookmark_displayname_max_length = 18 |
|---|
| [36] | 31 | Globalx.output_url = null |
|---|
| [66] | 32 | Globalx.output_url_listx = null |
|---|
| [41] | 33 | Globalx.remote_filename = 'php/content3.php' |
|---|
| 34 | Globalx.build = new Build() |
|---|
| [23] | 35 | |
|---|
| [25] | 36 | tab_init() |
|---|
| 37 | topmenu_init() |
|---|
| [41] | 38 | Globalx.remotex = new Remotex( Globalx.remote_filename ) |
|---|
| [36] | 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 |
|---|
| [41] | 43 | |
|---|
| [66] | 44 | Globalx.build.setup('data') |
|---|
| [27] | 45 | } |
|---|
| [23] | 46 | |
|---|
| [67] | 47 | function 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 | |
|---|
| [66] | 65 | async function update_all_info_on_host_async( ) { |
|---|
| [67] | 66 | await Globalx.remotex.update_output_url_listx( Globalx.num , (text) => { |
|---|
| 67 | set_output_url_listx(text) |
|---|
| [66] | 68 | } ) |
|---|
| 69 | |
|---|
| [41] | 70 | Globalx.parts.map( ( part ) => { |
|---|
| 71 | Globalx[ part ].sidemenu.update(`#${part}-side`) |
|---|
| 72 | } ) |
|---|
| [66] | 73 | |
|---|
| [41] | 74 | } |
|---|
| 75 | |
|---|
| [66] | 76 | async 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 | } |
|---|
| [41] | 87 | async function get_output_url_async( num, func ){ |
|---|
| [66] | 88 | let output_url = Globalx.storagex.get_output_url() |
|---|
| [36] | 89 | |
|---|
| [66] | 90 | if( output_url === undefined || output_url === null ){ |
|---|
| [41] | 91 | await Globalx.remotex.get_output_url( num, func ) |
|---|
| [36] | 92 | } |
|---|
| 93 | else{ |
|---|
| [66] | 94 | Globalx.output_url = output_url |
|---|
| [36] | 95 | Globalx.storagex.save_as_info_from_globalx() |
|---|
| 96 | } |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| [66] | 99 | async function get_output_url_listx_async( num ) { |
|---|
| 100 | await Globalx.remotex.get_output_url_listx( num , (text) => { |
|---|
| [67] | 101 | set_output_url_listx(text) |
|---|
| [36] | 102 | } ) |
|---|
| [27] | 103 | } |
|---|
| [67] | 104 | |
|---|
| [66] | 105 | async function setup(){ |
|---|
| 106 | await get_output_url_listx_async( Globalx.num ) |
|---|
| [67] | 107 | // await get_output_url( Globalx.num ) |
|---|
| [66] | 108 | } |
|---|
| [23] | 109 | |
|---|
| [36] | 110 | |
|---|
| [27] | 111 | function main() { |
|---|
| 112 | init_globalx_storagex() |
|---|
| [25] | 113 | |
|---|
| [27] | 114 | let need_to_save = Globalx.storagex.restore_globalx_from_info() |
|---|
| 115 | init_globalx() |
|---|
| [36] | 116 | setup() |
|---|
| [27] | 117 | |
|---|
| [36] | 118 | Globalx.bookmarkmenu = new BookmarkMenu( Globalx.bookmark_displayname_max_length , Globalx.bookmark_mgr ) |
|---|
| 119 | Globalx.bookmarkmenu.dlg() |
|---|
| 120 | |
|---|
| [27] | 121 | Globalx.parts.map( ( part ) => { |
|---|
| 122 | set_globalx_editor(part) |
|---|
| [36] | 123 | |
|---|
| [41] | 124 | Globalx[ part ].menu = null |
|---|
| [27] | 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(""); |
|---|
| [36] | 130 | Globalx.bookmarkmenu.rebuild_bookmark_menu(part) |
|---|
| 131 | Globalx.bookmarkmenu.set_click_handler(part) |
|---|
| [27] | 132 | } ) |
|---|
| 133 | |
|---|
| 134 | if( need_to_save ){ |
|---|
| 135 | // LocalStorageにまだ保存していない場合、ここで保存しておく |
|---|
| 136 | Globalx.storagex.save_as_info_from_globalx( (data) => { console.log( "data=" + data ) } ) |
|---|
| 137 | } |
|---|
| [23] | 138 | } |
|---|
| 139 | |
|---|
| [25] | 140 | |
|---|
| [23] | 141 | function set_globalx_editor(part) { |
|---|
| 142 | Globalx[part] = { |
|---|
| 143 | editor_id: `${part}-editor`, |
|---|
| [36] | 144 | editor: null, /* variable */ |
|---|
| [23] | 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 | /**/ |
|---|
| [36] | 152 | bookmarks: [], |
|---|
| 153 | key_indicate_file: false, /* variable */ |
|---|
| 154 | key: '/', |
|---|
| [23] | 155 | key_sel: `#${part}-filelist_key`, |
|---|
| [36] | 156 | download_sel: `#${part}-down-download`, |
|---|
| 157 | download_url_sel: `#${part}-down-url`, |
|---|
| 158 | download_partial_url_sel: `#${part}-partial-down-url` |
|---|
| [23] | 159 | } |
|---|
| [27] | 160 | editor_config(part); |
|---|
| 161 | |
|---|
| [23] | 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 | |
|---|
| [27] | 167 | function editor_config(part) { |
|---|
| [23] | 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; |
|---|
| [36] | 175 | |
|---|
| 176 | let textarea = $( Globalx[part].textarea_sel ) |
|---|
| [41] | 177 | editor.getSession().on("change", () => { |
|---|
| 178 | /* textarea.val(editor.getSession().getValue()) */ |
|---|
| 179 | $( Globalx[part].textarea_sel ).val(editor.getSession().getValue()) |
|---|
| [23] | 180 | }); |
|---|
| 181 | } |
|---|
| [41] | 182 | |
|---|
| 183 | function upload_to_host( part ){ |
|---|
| 184 | Globalx.remotex.upload_to_host( part ) |
|---|
| 185 | } |
|---|