Skip to content

Commit

Permalink
Implement wiki directive for #634 too, see issue for details
Browse files Browse the repository at this point in the history
  • Loading branch information
gashcrumb committed Oct 10, 2013
1 parent b0b2c3b commit 56191bd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hawtio-web/src/main/webapp/app/wiki/html/viewPage.html
Expand Up @@ -99,7 +99,7 @@
</div>
</div>

<div ng-hide="!html">
<div ng-hide="!html" wiki-href-adjuster>
<div ng-bind-html-unsafe="html"></div>
</div>

Expand Down
3 changes: 3 additions & 0 deletions hawtio-web/src/main/webapp/app/wiki/js/helpers.ts
Expand Up @@ -7,6 +7,9 @@ module Wiki {

export var customViewLinks = ["/wiki/formTable", "/wiki/camel/diagram", "/wiki/camel/canvas", "/wiki/camel/properties", "/wiki/dozer/mappings"];


export var excludeAdjustmentPrefixes = ["http://", "https://", "#"];

/**
* Which extensions do we wish to hide in the wiki file listing
*/
Expand Down
49 changes: 49 additions & 0 deletions hawtio-web/src/main/webapp/app/wiki/js/wikiPlugin.ts
Expand Up @@ -45,6 +45,55 @@ module Wiki {
directive('wikiFileList', () => {
return new Wiki.FileList();
}).
directive('wikiHrefAdjuster', ($location) => {
return {
restrict: 'A',
link: ($scope, $element, $attr) => {

$element.bind('DOMNodeInserted', (event) => {
var ays = $element.find('a');

angular.forEach(ays, (a) => {
if (a.hasAttribute('no-adjust')) {
return;
}

a = $(a);

var href = a.attr('href').trim();

// Deal with relative URLs first...
if (href.startsWith('../')) {
var path = $location.path();
var parts = href.split('/');
var pathParts = path.split('/');
var parents = parts.filter((part) => { return part === ".."; });
parts = parts.last(parts.length - parents.length);
pathParts = pathParts.first(pathParts.length - parents.length);

a.attr('href', '#' + pathParts.join('/') + '/' + parts.join('/') + $location.hash());
Core.$apply($scope);
return;
}

// Turn an absolute link into a wiki link...
if (href.startsWith('/')) {
a.attr('href', Wiki.branchLink($scope.branch, href, $location));
return;
}

if (!Wiki.excludeAdjustmentPrefixes.any((exclude) => {
return href.startsWith(exclude);
})) {
a.attr('href', '#' + $location.path() + "/" + href + $location.hash());
Core.$apply($scope);
return;
}
});
})
}
}
}).
run(($location:ng.ILocationService, workspace:Workspace, viewRegistry, jolokia, localStorage, layoutFull) => {

/*
Expand Down

0 comments on commit 56191bd

Please sign in to comment.