|
122 | 122 |
|
123 | 123 | <!-- Text preview --> |
124 | 124 | <script src="/static/preview/ace/ace.js" type="text/javascript" charset="utf-8"></script> |
125 | | -<script src="/static/preview/ace/theme-nord_dark.js" type="text/javascript" charset="utf-8"></script> |
126 | 125 | <script src="/static/preview/ace/ext-modelist.js" type="text/javascript" charset="utf-8"></script> |
127 | 126 | <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> |
| 127 | +<script src="/static/preview/ace/theme-{{.AceTheme}}.js" type="text/javascript" charset="utf-8"></script> |
128 | 128 |
|
129 | 129 | <script> |
130 | 130 | var editor = ace.edit("editor"); |
131 | | - editor.setTheme("ace/theme/nord_dark"); |
| 131 | + editor.setTheme("ace/theme/{{.AceTheme}}"); |
132 | 132 |
|
133 | 133 | var modelist = ace.require("ace/ext/modelist"); |
134 | 134 | var mode = modelist.getModeForPath( "{{.Filename}}").mode; |
135 | 135 | editor.session.setMode(mode); |
| 136 | + |
| 137 | + $.get("{{.Scheme}}://{{.Host}}/preview/raw/{{.PublicFilename}}", {}, function (data) { |
| 138 | + editor.setValue(data, -1); |
| 139 | + setTimeout(function(){ |
| 140 | + var heightUpdateFunction = function () { |
| 141 | + // http://stackoverflow.com/questions/11584061/ |
| 142 | + var newHeight = |
| 143 | + editor.getSession().getScreenLength() |
| 144 | + * editor.renderer.lineHeight |
| 145 | + + editor.renderer.scrollBar.getWidth()+1; |
| 146 | + |
| 147 | + $('#editor').height(newHeight.toString() + "px"); |
| 148 | + $('#editor-section').height(newHeight.toString() + "px"); |
| 149 | + |
| 150 | + // This call is required for the editor to fix all of |
| 151 | + // its inner structure for adapting to a change in size |
| 152 | + editor.resize(); |
| 153 | + }; |
| 154 | + |
| 155 | + // Set initial size to match initial content |
| 156 | + heightUpdateFunction(); |
| 157 | + |
| 158 | + // Whenever a change happens inside the ACE editor, update |
| 159 | + // the size again |
| 160 | + editor.getSession().on('change', heightUpdateFunction); |
| 161 | + }, 10); |
| 162 | + }); |
| 163 | + |
136 | 164 | </script> |
137 | 165 | {{ end }} |
138 | 166 |
|
|
0 commit comments