~jstys-z/helioviewer.org/timeline

« back to all changes in this revision

Viewing changes to timeline/Highstock-1.3.10/exporting-server/java/highcharts-export/highcharts-export-web/src/main/webapp/resources/lib/codemirror/util/match-highlighter.js

  • Committer: Jeff Stys
  • Date: 2014-04-21 12:46:26 UTC
  • Revision ID: jstys@sesda3.com-20140421124626-2332pb2dyjc33jxi
Proof-of-concept version of Data Coverage Timeline using Highchart/Highstock javascript library.  Changes to getDataCoverage API in order to feed the necessary data to the Timeline

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Define match-highlighter commands. Depends on searchcursor.js
 
2
// Use by attaching the following function call to the onCursorActivity event:
 
3
        //myCodeMirror.matchHighlight(minChars);
 
4
// And including a special span.CodeMirror-matchhighlight css class (also optionally a separate one for .CodeMirror-focused -- see demo matchhighlighter.html)
 
5
 
 
6
(function() {
 
7
  var DEFAULT_MIN_CHARS = 2;
 
8
  
 
9
  function MatchHighlightState() {
 
10
        this.marked = [];
 
11
  }
 
12
  function getMatchHighlightState(cm) {
 
13
        return cm._matchHighlightState || (cm._matchHighlightState = new MatchHighlightState());
 
14
  }
 
15
  
 
16
  function clearMarks(cm) {
 
17
        var state = getMatchHighlightState(cm);
 
18
        for (var i = 0; i < state.marked.length; ++i)
 
19
                state.marked[i].clear();
 
20
        state.marked = [];
 
21
  }
 
22
  
 
23
  function markDocument(cm, className, minChars) {
 
24
    clearMarks(cm);
 
25
        minChars = (typeof minChars !== 'undefined' ? minChars : DEFAULT_MIN_CHARS);
 
26
        if (cm.somethingSelected() && cm.getSelection().replace(/^\s+|\s+$/g, "").length >= minChars) {
 
27
                var state = getMatchHighlightState(cm);
 
28
                var query = cm.getSelection();
 
29
                cm.operation(function() {
 
30
                        if (cm.lineCount() < 2000) { // This is too expensive on big documents.
 
31
                          for (var cursor = cm.getSearchCursor(query); cursor.findNext();) {
 
32
                                //Only apply matchhighlight to the matches other than the one actually selected
 
33
                                if (!(cursor.from().line === cm.getCursor(true).line && cursor.from().ch === cm.getCursor(true).ch))
 
34
                                        state.marked.push(cm.markText(cursor.from(), cursor.to(), className));
 
35
                          }
 
36
                        }
 
37
                  });
 
38
        }
 
39
  }
 
40
 
 
41
  CodeMirror.defineExtension("matchHighlight", function(className, minChars) {
 
42
    markDocument(this, className, minChars);
 
43
  });
 
44
})();