| [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 | |
|---|
| [66] | 47 | async 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 | |
|---|
| [41] | 57 | Globalx.parts.map( ( part ) => { |
|---|
| 58 | Globalx[ part ].sidemenu.update(`#${part}-side`) |
|---|
| 59 | } ) |
|---|
| [66] | 60 | |
|---|
| [41] | 61 | } |
|---|
| 62 | |
|---|
| [66] | 63 | async 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 | } |
|---|
| [41] | 74 | async function get_output_url_async( num, func ){ |
|---|
| [66] | 75 | let output_url = Globalx.storagex.get_output_url() |
|---|
| [36] | 76 | |
|---|
| [66] | 77 | if( output_url === undefined || output_url === null ){ |
|---|
| [41] | 78 | await Globalx.remotex.get_output_url( num, func ) |
|---|
| [36] | 79 | } |
|---|
| 80 | else{ |
|---|
| [66] | 81 | Globalx.output_url = output_url |
|---|
| [36] | 82 | Globalx.storagex.save_as_info_from_globalx() |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| [66] | 86 | async 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() |
|---|
| [36] | 93 | } |
|---|
| 94 | } ) |
|---|
| [27] | 95 | } |
|---|
| [66] | 96 | async function setup(){ |
|---|
| 97 | await get_output_url_listx_async( Globalx.num ) |
|---|
| 98 | await get_output_url( Globalx.num ) |
|---|
| 99 | } |
|---|
| [23] | 100 | |
|---|
| [36] | 101 | |
|---|
| [27] | 102 | function main() { |
|---|
| 103 | init_globalx_storagex() |
|---|
| [25] | 104 | |
|---|
| [27] | 105 | let need_to_save = Globalx.storagex.restore_globalx_from_info() |
|---|
| 106 | init_globalx() |
|---|
| [36] | 107 | setup() |
|---|
| [27] | 108 | |
|---|
| [36] | 109 | Globalx.bookmarkmenu = new BookmarkMenu( Globalx.bookmark_displayname_max_length , Globalx.bookmark_mgr ) |
|---|
| 110 | Globalx.bookmarkmenu.dlg() |
|---|
| 111 | |
|---|
| [27] | 112 | Globalx.parts.map( ( part ) => { |
|---|
| 113 | set_globalx_editor(part) |
|---|
| [36] | 114 | |
|---|
| [41] | 115 | Globalx[ part ].menu = null |
|---|
| [27] | 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(""); |
|---|
| [36] | 121 | Globalx.bookmarkmenu.rebuild_bookmark_menu(part) |
|---|
| 122 | Globalx.bookmarkmenu.set_click_handler(part) |
|---|
| [27] | 123 | } ) |
|---|
| 124 | |
|---|
| 125 | if( need_to_save ){ |
|---|
| 126 | // LocalStorageにまだ保存していない場合、ここで保存しておく |
|---|
| 127 | Globalx.storagex.save_as_info_from_globalx( (data) => { console.log( "data=" + data ) } ) |
|---|
| 128 | } |
|---|
| [23] | 129 | } |
|---|
| 130 | |
|---|
| [25] | 131 | |
|---|
| [23] | 132 | function set_globalx_editor(part) { |
|---|
| 133 | Globalx[part] = { |
|---|
| 134 | editor_id: `${part}-editor`, |
|---|
| [36] | 135 | editor: null, /* variable */ |
|---|
| [23] | 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 | /**/ |
|---|
| [36] | 143 | bookmarks: [], |
|---|
| 144 | key_indicate_file: false, /* variable */ |
|---|
| 145 | key: '/', |
|---|
| [23] | 146 | key_sel: `#${part}-filelist_key`, |
|---|
| [36] | 147 | download_sel: `#${part}-down-download`, |
|---|
| 148 | download_url_sel: `#${part}-down-url`, |
|---|
| 149 | download_partial_url_sel: `#${part}-partial-down-url` |
|---|
| [23] | 150 | } |
|---|
| [27] | 151 | editor_config(part); |
|---|
| 152 | |
|---|
| [23] | 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 | |
|---|
| [27] | 158 | function editor_config(part) { |
|---|
| [23] | 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; |
|---|
| [36] | 166 | |
|---|
| 167 | let textarea = $( Globalx[part].textarea_sel ) |
|---|
| [41] | 168 | editor.getSession().on("change", () => { |
|---|
| 169 | /* textarea.val(editor.getSession().getValue()) */ |
|---|
| 170 | $( Globalx[part].textarea_sel ).val(editor.getSession().getValue()) |
|---|
| [23] | 171 | }); |
|---|
| 172 | } |
|---|
| [41] | 173 | |
|---|
| 174 | function upload_to_host( part ){ |
|---|
| 175 | Globalx.remotex.upload_to_host( part ) |
|---|
| 176 | } |
|---|