Skip to content

Commit 0112a39

Browse files
committed
make ace theme a config option
1 parent 26f5c8c commit 0112a39

File tree

5 files changed

+34
-29
lines changed

5 files changed

+34
-29
lines changed

handlers/web/PreviewHandler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func PrevievFileHandler(handlerData HandlerData, w http.ResponseWriter, r *http.
7575
Encrypted: (file.Encryption.Valid && libdm.EncryptionIValid(file.Encryption.Int32)),
7676
MimeType: file.FileType,
7777
Scheme: scheme,
78+
AceTheme: handlerData.Config.Webserver.AceTheme,
7879
}
7980

8081
//Serve preview

html/templates/Content.html

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,6 @@
3636
<button class="fab_dl" onclick="dl()"><i class="material-icons">download</i></button>
3737

3838
<script>
39-
$.get("{{.Scheme}}://{{.Host}}/preview/raw/{{.PublicFilename}}", {}, function (data) {
40-
editor.setValue(data, -1);
41-
setTimeout(function(){
42-
var heightUpdateFunction = function () {
43-
// http://stackoverflow.com/questions/11584061/
44-
var newHeight =
45-
editor.getSession().getScreenLength()
46-
* editor.renderer.lineHeight
47-
+ editor.renderer.scrollBar.getWidth()+1;
48-
49-
$('#editor').height(newHeight.toString() + "px");
50-
$('#editor-section').height(newHeight.toString() + "px");
51-
52-
// This call is required for the editor to fix all of
53-
// its inner structure for adapting to a change in size
54-
editor.resize();
55-
};
56-
57-
// Set initial size to match initial content
58-
heightUpdateFunction();
59-
60-
// Whenever a change happens inside the ACE editor, update
61-
// the size again
62-
editor.getSession().on('change', heightUpdateFunction);
63-
}, 10);
64-
});
65-
6639
function dl() {
6740
window.location.href = "{{.Scheme}}://{{.Host}}/preview/raw/{{.PublicFilename}}";
6841
}

html/templates/Preview.html

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,45 @@
122122

123123
<!-- Text preview -->
124124
<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>
126125
<script src="/static/preview/ace/ext-modelist.js" type="text/javascript" charset="utf-8"></script>
127126
<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>
128128

129129
<script>
130130
var editor = ace.edit("editor");
131-
editor.setTheme("ace/theme/nord_dark");
131+
editor.setTheme("ace/theme/{{.AceTheme}}");
132132

133133
var modelist = ace.require("ace/ext/modelist");
134134
var mode = modelist.getModeForPath( "{{.Filename}}").mode;
135135
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+
136164
</script>
137165
{{ end }}
138166

models/Config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type webserverConf struct {
3434
SchemeOverwrite string
3535
HTTP configHTTPstruct
3636
HTTPS configTLSStruct
37+
AceTheme string
3738
}
3839

3940
type configServer struct {
@@ -174,6 +175,7 @@ func InitConfig(confFile string, createMode bool) (*Config, bool) {
174175
Enabled: false,
175176
ListenAddress: ":443",
176177
},
178+
AceTheme: "nord_dark",
177179
},
178180
}
179181
}

models/Preview.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type PreviewTemplate struct {
3636
Encrypted bool
3737
MimeType string
3838
Scheme string
39+
AceTheme string
3940
}
4041

4142
// PreviewTypeFromMime get Type to preview from mime

0 commit comments

Comments
 (0)