You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fullscreen.js 1.5KB

2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: https://codemirror.net/LICENSE
  3. (function(mod) {
  4. if (typeof exports == "object" && typeof module == "object") // CommonJS
  5. mod(require("../../lib/codemirror"));
  6. else if (typeof define == "function" && define.amd) // AMD
  7. define(["../../lib/codemirror"], mod);
  8. else // Plain browser env
  9. mod(CodeMirror);
  10. })(function(CodeMirror) {
  11. "use strict";
  12. CodeMirror.defineOption("fullScreen", false, function(cm, val, old) {
  13. if (old == CodeMirror.Init) old = false;
  14. if (!old == !val) return;
  15. if (val) setFullscreen(cm);
  16. else setNormal(cm);
  17. });
  18. function setFullscreen(cm) {
  19. var wrap = cm.getWrapperElement();
  20. cm.state.fullScreenRestore = {scrollTop: window.pageYOffset, scrollLeft: window.pageXOffset,
  21. width: wrap.style.width, height: wrap.style.height};
  22. wrap.style.width = "";
  23. wrap.style.height = "auto";
  24. wrap.className += " CodeMirror-fullscreen";
  25. document.documentElement.style.overflow = "hidden";
  26. cm.refresh();
  27. }
  28. function setNormal(cm) {
  29. var wrap = cm.getWrapperElement();
  30. wrap.className = wrap.className.replace(/\s*CodeMirror-fullscreen\b/, "");
  31. document.documentElement.style.overflow = "";
  32. var info = cm.state.fullScreenRestore;
  33. wrap.style.width = info.width; wrap.style.height = info.height;
  34. window.scrollTo(info.scrollLeft, info.scrollTop);
  35. cm.refresh();
  36. }
  37. });