提交 | 用户 | 时间
|
e7c126
|
1 |
/* |
H |
2 |
* Copyright 1999-2018 Alibaba Group Holding Ltd. |
|
3 |
* |
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
* you may not use this file except in compliance with the License. |
|
6 |
* You may obtain a copy of the License at |
|
7 |
* |
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
* |
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
* See the License for the specific language governing permissions and |
|
14 |
* limitations under the License. |
|
15 |
*/ |
|
16 |
|
|
17 |
(function(mod) { |
|
18 |
if (typeof exports == "object" && typeof module == "object") // CommonJS |
|
19 |
mod(require("../../lib/codemirror")); |
|
20 |
else if (typeof define == "function" && define.amd) // AMD |
|
21 |
define(["../../lib/codemirror"], mod); |
|
22 |
else // Plain browser env |
|
23 |
mod(CodeMirror); |
|
24 |
})(function(CodeMirror) { |
|
25 |
"use strict"; |
|
26 |
|
|
27 |
CodeMirror.defineOption("fullScreen", false, function(cm, val, old) { |
|
28 |
if (old == CodeMirror.Init) old = false; |
|
29 |
if (!old == !val) return; |
|
30 |
if (val) setFullscreen(cm); |
|
31 |
else setNormal(cm); |
|
32 |
}); |
|
33 |
|
|
34 |
function setFullscreen(cm) { |
|
35 |
var wrap = cm.getWrapperElement(); |
|
36 |
cm.state.fullScreenRestore = {scrollTop: window.pageYOffset, scrollLeft: window.pageXOffset, |
|
37 |
width: wrap.style.width, height: wrap.style.height}; |
|
38 |
wrap.style.width = ""; |
|
39 |
wrap.style.height = "auto"; |
|
40 |
wrap.className += " CodeMirror-fullscreen"; |
|
41 |
document.documentElement.style.overflow = "hidden"; |
|
42 |
cm.refresh(); |
|
43 |
} |
|
44 |
|
|
45 |
function setNormal(cm) { |
|
46 |
var wrap = cm.getWrapperElement(); |
|
47 |
wrap.className = wrap.className.replace(/\s*CodeMirror-fullscreen\b/, ""); |
|
48 |
document.documentElement.style.overflow = ""; |
|
49 |
var info = cm.state.fullScreenRestore; |
|
50 |
wrap.style.width = info.width; wrap.style.height = info.height; |
|
51 |
window.scrollTo(info.scrollLeft, info.scrollTop); |
|
52 |
cm.refresh(); |
|
53 |
} |
|
54 |
}); |