Skip to content

Commit 1acfdbd

Browse files
committed
reimplemented clickable links
1 parent 665db57 commit 1acfdbd

File tree

5 files changed

+59
-3
lines changed

5 files changed

+59
-3
lines changed

css/notes.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@
7777
overflow-x: auto !important;
7878
}
7979

80+
/* enable clickthrough for links */
81+
.CodeMirror-cursor {
82+
pointer-events: none;
83+
}
84+
8085
#app-content .note-meta {
8186
position: relative;
8287
padding: 0 45px 30px 45px;

js/app/directives/editor.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/*global SimpleMDE*/
2-
app.directive('editor', ['$timeout', function ($timeout) {
2+
app.directive('editor', ['$timeout',
3+
'urlFinder',
4+
function ($timeout, urlFinder) {
35
'use strict';
46
return {
57
restrict: 'A',
@@ -26,6 +28,15 @@ app.directive('editor', ['$timeout', function ($timeout) {
2628
});
2729
});
2830
});
31+
32+
editorElement.on('click', '.cm-link, .cm-url', function(event) {
33+
if(event.ctrlKey) {
34+
var url = urlFinder(this);
35+
if(angular.isDefined(url)) {
36+
window.open(url, '_blank');
37+
}
38+
}
39+
});
2940
}
3041
};
3142
}]);

js/app/services/urlFinder.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright (c) 2016, Hendrik Leppelsack
3+
* This file is licensed under the Affero General Public License version 3 or
4+
* later.
5+
* See the COPYING file.
6+
*/
7+
8+
// finds the url which should be opened when a link is clicked
9+
// example: '[hello](http://example.com)'
10+
app.factory('urlFinder', [function() {
11+
'use strict';
12+
13+
return function urlFinder(element) {
14+
element = $(element);
15+
16+
// special case: click on ')'
17+
if(element.is('.cm-url.cm-formatting')) {
18+
if(element.prev().length !== 0) {
19+
element = element.prev();
20+
}
21+
}
22+
23+
// skip '[hello]'
24+
while(element.is('.cm-link')) {
25+
element = element.next();
26+
}
27+
28+
// skip '('
29+
while(element.is('.cm-url.cm-formatting')) {
30+
element = element.next();
31+
}
32+
33+
// check if we actually have a cm-url
34+
if(element.is('.cm-url:not(.cm-formatting)')) {
35+
return element.text();
36+
}
37+
38+
return undefined;
39+
};
40+
}]);

js/public/app.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)