Skip to content

Commit

Permalink
reimplemented clickable links
Browse files Browse the repository at this point in the history
  • Loading branch information
Henni committed Dec 9, 2016
1 parent 88c436b commit be1b84b
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
5 changes: 5 additions & 0 deletions css/notes.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
overflow-x: auto !important;
}

/* enable clickthrough for links */
.CodeMirror-cursor {
pointer-events: none;
}

#app-content .note-meta {
position: relative;
padding: 0 45px 30px 45px;
Expand Down
13 changes: 12 additions & 1 deletion js/app/directives/editor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*global SimpleMDE*/
app.directive('editor', ['$timeout', function ($timeout) {
app.directive('editor', ['$timeout',
'urlFinder',
function ($timeout, urlFinder) {
'use strict';
return {
restrict: 'A',
Expand All @@ -26,6 +28,15 @@ app.directive('editor', ['$timeout', function ($timeout) {
});
});
});

editorElement.on('click', '.cm-link, .cm-url', function(event) {
if(event.ctrlKey) {
var url = urlFinder(this);
if(angular.isDefined(url)) {
window.open(url, '_blank');
}
}
});
}
};
}]);
40 changes: 40 additions & 0 deletions js/app/services/urlFinder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (c) 2016, Hendrik Leppelsack
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING file.
*/

// finds the url which should be opened when a link is clicked
// example: '[hello](http://example.com)'
app.factory('urlFinder', [function() {
'use strict';

return function urlFinder(element) {
element = $(element);

// special case: click on ')'
if(element.is('.cm-url.cm-formatting')) {
if(element.prev().length !== 0) {
element = element.prev();
}
}

// skip '[hello]'
while(element.is('.cm-link')) {
element = element.next();
}

// skip '('
while(element.is('.cm-url.cm-formatting')) {
element = element.next();
}

// check if we actually have a cm-url
if(element.is('.cm-url:not(.cm-formatting)')) {
return element.text();
}

return undefined;
};
}]);
2 changes: 1 addition & 1 deletion js/public/app.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit be1b84b

Please sign in to comment.