]>
Commit | Line | Data |
---|---|---|
06a3d686 BB |
1 | /*global CodeMirror:false, $:false*/ |
2 | ||
3 | (function(){ | |
4 | "use strict"; | |
5 | ||
6 | function makeid(num){ | |
7 | num = num || 5; | |
8 | var text = ""; | |
9 | var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | |
10 | ||
11 | for( var i=0; i < num; i++ ) | |
12 | text += possible.charAt(Math.floor(Math.random() * possible.length)); | |
13 | ||
14 | return text; | |
15 | } | |
16 | ||
17 | CodeMirror.prototype.markPopoverText = function(lineObj, regex, className, gutter, message){ | |
18 | var re = new RegExp('(' + regex + ')', 'g'); | |
19 | var cursor = this.getSearchCursor(re, lineObj); | |
20 | ||
21 | var match, internalClass = 'plato-mark-' + makeid(10); | |
22 | while (match = cursor.findNext()) { | |
23 | if (cursor.to().line !== lineObj.line) break; | |
24 | this.markText( | |
25 | { line : lineObj.line, ch : cursor.from().ch }, | |
26 | { line : lineObj.line, ch : cursor.to().ch }, | |
27 | { | |
28 | className : 'plato-mark ' + internalClass + ' ' + (className || ''), | |
29 | startStyle : 'plato-mark-start', | |
30 | endStyle : 'plato-mark-end' | |
31 | } | |
32 | ); | |
33 | } | |
34 | ||
35 | if (gutter) { | |
36 | this.setGutterMarker(lineObj.line, gutter.gutterId, gutter.el); | |
37 | } | |
38 | ||
39 | // return a function to bind hover events, to be run after | |
40 | // the codemirror operations are executed | |
41 | return function(){ | |
42 | var markStart = $('.plato-mark-start.' + internalClass); | |
43 | var markSpans = $('.' + internalClass); | |
44 | ||
45 | if (message.type === 'popover') { | |
46 | ||
47 | var triggered = false; | |
48 | markSpans.add(gutter.el) | |
49 | .on('mouseenter touchstart',function(e){ | |
50 | e.preventDefault(); | |
51 | triggered = true; | |
52 | markSpans.addClass('active'); | |
53 | markStart.popover('show'); | |
54 | }) | |
55 | .on('mouseleave touchend',function(e){ | |
56 | e.preventDefault(); | |
57 | markSpans.removeClass('active'); | |
58 | triggered = false; | |
59 | setTimeout(function(){ | |
60 | if (!triggered) markStart.popover('hide'); | |
61 | },200); | |
62 | }); | |
63 | ||
64 | markStart.popover({ | |
65 | trigger : 'manual', | |
66 | content : message.content, | |
67 | html : true, | |
68 | title : message.title, | |
69 | placement : 'top' | |
70 | }); | |
71 | } else if (message.type === 'block') { | |
72 | this.addLineWidget(lineObj.line, $(message.content)[0]); | |
73 | } | |
74 | }; | |
75 | }; | |
76 | ||
77 | })(); |