summaryrefslogtreecommitdiff
path: root/static/website/js/fullscreen.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/website/js/fullscreen.js')
-rw-r--r--static/website/js/fullscreen.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/static/website/js/fullscreen.js b/static/website/js/fullscreen.js
new file mode 100644
index 0000000..a442f6a
--- /dev/null
+++ b/static/website/js/fullscreen.js
@@ -0,0 +1,31 @@
+(function() {
+ "use strict";
+
+ CodeMirror.defineOption("fullScreen", false, function(cm, val, old) {
+ if (old == CodeMirror.Init) old = false;
+ if (!old == !val) return;
+ if (val) setFullscreen(cm);
+ else setNormal(cm);
+ });
+
+ function setFullscreen(cm) {
+ var wrap = cm.getWrapperElement();
+ cm.state.fullScreenRestore = {scrollTop: window.pageYOffset, scrollLeft: window.pageXOffset,
+ width: wrap.style.width, height: wrap.style.height};
+ wrap.style.width = "";
+ wrap.style.height = "auto";
+ wrap.className += " CodeMirror-fullscreen";
+ document.documentElement.style.overflow = "hidden";
+ cm.refresh();
+ }
+
+ function setNormal(cm) {
+ var wrap = cm.getWrapperElement();
+ wrap.className = wrap.className.replace(/\s*CodeMirror-fullscreen\b/, "");
+ document.documentElement.style.overflow = "";
+ var info = cm.state.fullScreenRestore;
+ wrap.style.width = info.width; wrap.style.height = info.height;
+ window.scrollTo(info.scrollLeft, info.scrollTop);
+ cm.refresh();
+ }
+})();