File tree Expand file tree Collapse file tree 2 files changed +11
-0
lines changed
Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -838,6 +838,13 @@ <h2 id="api">Programming API</h2>
838838 will cause the given value (usually a method) to be added to all
839839 CodeMirror instances created from then on.</ p >
840840
841+ < p id ="defineInitHook "> If your extention just needs to run some
842+ code whenever a CodeMirror instance is initialized,
843+ use < code > CodeMirror.defineInitHook</ code > . Give it a function as
844+ its only argument, and from then on, that function will be called
845+ (with the instance as argument) whenever a new CodeMirror instance
846+ is initialized.</ p >
847+
841848 < h2 id ="addons "> Add-ons</ h2 >
842849
843850 < p > The < code > lib/util</ code > directory in the distribution
Original file line number Diff line number Diff line change @@ -1986,6 +1986,7 @@ window.CodeMirror = (function() {
19861986 if ( extensions . propertyIsEnumerable ( ext ) &&
19871987 ! instance . propertyIsEnumerable ( ext ) )
19881988 instance [ ext ] = extensions [ ext ] ;
1989+ for ( var i = 0 ; i < initHooks . length ; ++ i ) initHooks [ i ] ( instance ) ;
19891990 return instance ;
19901991 } // (end of function CodeMirror)
19911992
@@ -2083,6 +2084,9 @@ window.CodeMirror = (function() {
20832084 extensions [ name ] = func ;
20842085 } ;
20852086
2087+ var initHooks = [ ] ;
2088+ CodeMirror . defineInitHook = function ( f ) { initHooks . push ( f ) ; } ;
2089+
20862090 var modeExtensions = CodeMirror . modeExtensions = { } ;
20872091 CodeMirror . extendMode = function ( mode , properties ) {
20882092 var exts = modeExtensions . hasOwnProperty ( mode ) ? modeExtensions [ mode ] : ( modeExtensions [ mode ] = { } ) ;
You can’t perform that action at this time.
0 commit comments