| [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 |
|---|
| [41] | 29 | Globalx.parts = ["data" , "output", "setting"] |
|---|
| [27] | 30 | Globalx.bookmark_displayname_max_length = 18 |
|---|
| [36] | 31 | Globalx.output_url = null |
|---|
| [41] | 32 | Globalx.remote_filename = 'php/content3.php' |
|---|
| 33 | Globalx.build = new Build() |
|---|
| [23] | 34 | |
|---|
| [25] | 35 | tab_init() |
|---|
| 36 | topmenu_init() |
|---|
| [41] | 37 | Globalx.remotex = new Remotex( Globalx.remote_filename ) |
|---|
| [36] | 38 | if( Globalx.bookmark_mgr === null || Globalx.bookmark_mgr === undefined ){ |
|---|
| 39 | Globalx.bookmark_mgr = new BookmarkMgr(Globalx.bookmark_displayname_max_length, Globalx.parts) |
|---|
| 40 | } |
|---|
| 41 | Globalx.bookmarkmenu = null |
|---|
| [41] | 42 | |
|---|
| 43 | Globalx.build.setup() |
|---|
| [27] | 44 | } |
|---|
| [23] | 45 | |
|---|
| [41] | 46 | async function update_all_filelist( ) { |
|---|
| 47 | Globalx.parts.map( ( part ) => { |
|---|
| 48 | Globalx[ part ].sidemenu.update(`#${part}-side`) |
|---|
| 49 | } ) |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | async function get_output_url_async( num, func ){ |
|---|
| [36] | 53 | let realData = Globalx.storagex.get_output_url() |
|---|
| 54 | |
|---|
| 55 | if( realData === undefined || realData === null ){ |
|---|
| [41] | 56 | await Globalx.remotex.get_output_url( num, func ) |
|---|
| [36] | 57 | } |
|---|
| 58 | else{ |
|---|
| [41] | 59 | const obj = Globalx.storagex.get_output_url( num ) |
|---|
| [36] | 60 | Globalx.output_url = obj.output_url |
|---|
| 61 | Globalx.storagex.save_as_info_from_globalx() |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | async function setup(){ |
|---|
| [41] | 66 | get_output_url_async( Globalx.num, (text) => { |
|---|
| [36] | 67 | let str = text |
|---|
| 68 | let obj |
|---|
| 69 | if( str.match( /{.*}/ ) === null ){ |
|---|
| 70 | obj = {} |
|---|
| 71 | } |
|---|
| 72 | else { |
|---|
| 73 | obj = JSON.parse( str ) |
|---|
| 74 | } |
|---|
| 75 | Globalx.storagex.change_cache( obj, this.num , this.part ) |
|---|
| 76 | } ) |
|---|
| [27] | 77 | } |
|---|
| [23] | 78 | |
|---|
| [36] | 79 | |
|---|
| [27] | 80 | function main() { |
|---|
| 81 | init_globalx_storagex() |
|---|
| [25] | 82 | |
|---|
| [27] | 83 | let need_to_save = Globalx.storagex.restore_globalx_from_info() |
|---|
| 84 | init_globalx() |
|---|
| [36] | 85 | setup() |
|---|
| [27] | 86 | |
|---|
| [36] | 87 | Globalx.bookmarkmenu = new BookmarkMenu( Globalx.bookmark_displayname_max_length , Globalx.bookmark_mgr ) |
|---|
| 88 | Globalx.bookmarkmenu.dlg() |
|---|
| 89 | |
|---|
| [27] | 90 | Globalx.parts.map( ( part ) => { |
|---|
| 91 | set_globalx_editor(part) |
|---|
| [36] | 92 | |
|---|
| [41] | 93 | Globalx[ part ].menu = null |
|---|
| [27] | 94 | Globalx[ part ].sidemenu = new SideMenu( Globalx.num, part ) |
|---|
| 95 | Globalx[ part ].sidemenu.setup(`#${part}-side`) |
|---|
| 96 | |
|---|
| 97 | $( Globalx[ part ].download_sel ).on('click', {num: Globalx.num, part: part}, handleDownload) |
|---|
| 98 | $( Globalx[ part ].textarea_sel ).val(""); |
|---|
| [36] | 99 | Globalx.bookmarkmenu.rebuild_bookmark_menu(part) |
|---|
| 100 | Globalx.bookmarkmenu.set_click_handler(part) |
|---|
| [27] | 101 | } ) |
|---|
| 102 | |
|---|
| 103 | if( need_to_save ){ |
|---|
| 104 | // LocalStorageにまだ保存していない場合、ここで保存しておく |
|---|
| 105 | Globalx.storagex.save_as_info_from_globalx( (data) => { console.log( "data=" + data ) } ) |
|---|
| 106 | } |
|---|
| [23] | 107 | } |
|---|
| 108 | |
|---|
| [25] | 109 | |
|---|
| [23] | 110 | function set_globalx_editor(part) { |
|---|
| 111 | Globalx[part] = { |
|---|
| 112 | editor_id: `${part}-editor`, |
|---|
| [36] | 113 | editor: null, /* variable */ |
|---|
| [23] | 114 | textarea_sel: `textarea[name=${part}-editor-t`, |
|---|
| 115 | /**/ |
|---|
| 116 | menu_id: `${part}-menu2`, |
|---|
| 117 | bookmark_id: `${part}-bookmark`, |
|---|
| 118 | bookmark_op_id: `${part}-bookmark_op`, |
|---|
| 119 | item_name: "", |
|---|
| 120 | /**/ |
|---|
| [36] | 121 | bookmarks: [], |
|---|
| 122 | key_indicate_file: false, /* variable */ |
|---|
| 123 | key: '/', |
|---|
| [23] | 124 | key_sel: `#${part}-filelist_key`, |
|---|
| [36] | 125 | download_sel: `#${part}-down-download`, |
|---|
| 126 | download_url_sel: `#${part}-down-url`, |
|---|
| 127 | download_partial_url_sel: `#${part}-partial-down-url` |
|---|
| [23] | 128 | } |
|---|
| [27] | 129 | editor_config(part); |
|---|
| 130 | |
|---|
| [23] | 131 | Globalx[part].menu_sel = `#${Globalx[part].menu_id}` |
|---|
| 132 | Globalx[part].bookmark_sel = `#${Globalx[part].bookmark_id}` |
|---|
| 133 | Globalx[part].bookmark_op_sel = `#${Globalx[part].bookmark_op_id}` |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| [27] | 136 | function editor_config(part) { |
|---|
| [23] | 137 | let editor = ace.edit( Globalx[part].editor_id ) |
|---|
| 138 | editor.setTheme("ace/theme/monokai"); |
|---|
| 139 | editor.setFontSize(14); |
|---|
| 140 | editor.getSession().setMode("ace/mode/markdown"); |
|---|
| 141 | editor.getSession().setUseWrapMode(true); |
|---|
| 142 | editor.getSession().setTabSize(2); |
|---|
| 143 | Globalx[part].editor = editor; |
|---|
| [36] | 144 | |
|---|
| 145 | let textarea = $( Globalx[part].textarea_sel ) |
|---|
| [41] | 146 | editor.getSession().on("change", () => { |
|---|
| 147 | /* textarea.val(editor.getSession().getValue()) */ |
|---|
| 148 | $( Globalx[part].textarea_sel ).val(editor.getSession().getValue()) |
|---|
| [23] | 149 | }); |
|---|
| 150 | } |
|---|
| [41] | 151 | |
|---|
| 152 | function upload_to_host( part ){ |
|---|
| 153 | Globalx.remotex.upload_to_host( part ) |
|---|
| 154 | } |
|---|