Files
habitica/website/client-old/js/directives/directives.js
Travis bf5ad2db1f Fixing Exponential Quest Reward Scrolls (#7800)
* adding quest owner specific rewards. closes #2715

* Updating model to prevent this from being a breaking change.

* Removing duplicate translatable string and readding accidentally deleted portion

* capitalizing according to pr.

* fixing according to comments on pr

* removing final mistakes

* fixing whitespace

* re-adding the onlyOwner field that got deleted when the index.js file was moved and fixed console errors.

* moving cleaning of empty obejct for quest owner updates into quest owner updates method

* Fixing so tests pass by updating variable name and removing unnecessary parameter definition.

* adding a new test and refactoring client side code to use controller method.
2016-12-28 01:38:52 -06:00

80 lines
2.0 KiB
JavaScript

'use strict';
/**
* Markdown
*/
(function(){
var md = function () {
var mdown = window.habiticaMarkdown;
var toHtml = function (markdown) {
if (markdown == undefined)
return '';
markdown = mdown.render(markdown);
return markdown;
};
return {
toHtml:toHtml
};
}();
habitrpg.directive('markdown', ['$timeout', function($timeout) {
return {
restrict: 'E',
link: function(scope, element, attrs) {
var removeWatch = !!scope.$eval(attrs.removeWatch);
var useTimeout = !!scope.$eval(attrs.useTimeout);
var timeoutTime = scope.$eval(attrs.timeoutTime) || 0;
var doRemoveWatch = scope.$watch(attrs.text, function(value, oldValue) {
var replaceMarkdown = function(){
var markdown = value;
var linktarget = attrs.target || '_self';
var userName = scope.User.user.profile.name;
var userHighlight = "@"+userName;
var html = md.toHtml(markdown);
html = html.replace(userHighlight, "<u>@"+userName+"</u>");
element.html(html);
if (removeWatch) {
doRemoveWatch();
}
};
if(useTimeout) {
$timeout(replaceMarkdown, timeoutTime);
} else {
replaceMarkdown();
}
});
}
};
}]);
habitrpg.filter('markdown', function() {
return function(input){
var html = md.toHtml(input);
return html;
};
});
})()
habitrpg.directive('questRewards', ['$rootScope', function($rootScope){
return {
restrict: 'AE',
templateUrl: 'partials/options.social.party.quest-rewards.html',
link: function(scope, element, attrs){
scope.headerParticipant = attrs.headerParticipant || env.t('rewardsAllParticipants');
scope.headerQuestOwner = attrs.headerQuestOwner || env.t('rewardsQuestOwner');
scope.quest = $rootScope.Content.quests[attrs.key];
}
}
}]);