LaravelTest
47 строк · 1.5 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"))7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod)9else // Plain browser env10mod(CodeMirror)11})(function(CodeMirror) {12"use strict"13
14CodeMirror.defineOption("autoRefresh", false, function(cm, val) {15if (cm.state.autoRefresh) {16stopListening(cm, cm.state.autoRefresh)17cm.state.autoRefresh = null18}19if (val && cm.display.wrapper.offsetHeight == 0)20startListening(cm, cm.state.autoRefresh = {delay: val.delay || 250})21})22
23function startListening(cm, state) {24function check() {25if (cm.display.wrapper.offsetHeight) {26stopListening(cm, state)27if (cm.display.lastWrapHeight != cm.display.wrapper.clientHeight)28cm.refresh()29} else {30state.timeout = setTimeout(check, state.delay)31}32}33state.timeout = setTimeout(check, state.delay)34state.hurry = function() {35clearTimeout(state.timeout)36state.timeout = setTimeout(check, 50)37}38CodeMirror.on(window, "mouseup", state.hurry)39CodeMirror.on(window, "keyup", state.hurry)40}41
42function stopListening(_cm, state) {43clearTimeout(state.timeout)44CodeMirror.off(window, "mouseup", state.hurry)45CodeMirror.off(window, "keyup", state.hurry)46}47});48