2013-08-25 01:06:37 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Directive that places focus on the element it is applied to when the expression it binds to evaluates to true.
|
|
|
|
|
*/
|
|
|
|
|
habitrpg.directive('taskFocus',
|
|
|
|
|
['$timeout',
|
|
|
|
|
function($timeout) {
|
|
|
|
|
return function(scope, elem, attrs) {
|
|
|
|
|
scope.$watch(attrs.taskFocus, function(newval) {
|
|
|
|
|
if ( newval ) {
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
elem[0].focus();
|
|
|
|
|
}, 0, false);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
|
2013-08-28 17:16:53 +00:00
|
|
|
habitrpg.directive('habitrpgAdsense', function() {
|
|
|
|
|
return {
|
|
|
|
|
restrict: 'A',
|
|
|
|
|
transclude: true,
|
|
|
|
|
replace: true,
|
|
|
|
|
template: '<div ng-transclude></div>',
|
|
|
|
|
link: function ($scope, element, attrs) {}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2013-08-25 01:06:37 +00:00
|
|
|
habitrpg.directive('whenScrolled', function() {
|
2013-10-30 02:07:39 +00:00
|
|
|
return function(scope, elm, attr) {
|
|
|
|
|
var raw = elm[0];
|
|
|
|
|
|
|
|
|
|
elm.bind('scroll', function() {
|
|
|
|
|
if (raw.scrollTop + raw.offsetHeight >= raw.scrollHeight) {
|
|
|
|
|
scope.$apply(attr.whenScrolled);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2013-08-25 01:06:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add sortable
|
|
|
|
|
*/
|
2013-08-28 18:12:50 +00:00
|
|
|
habitrpg.directive('habitrpgSortable', ['User', function(User) {
|
2013-08-28 18:04:54 +00:00
|
|
|
return function($scope, element, attrs, ngModel) {
|
2013-08-28 17:38:04 +00:00
|
|
|
$(element).sortable({
|
|
|
|
|
axis: "y",
|
2013-09-21 14:50:14 +00:00
|
|
|
distance: 5,
|
2013-08-28 17:38:04 +00:00
|
|
|
start: function (event, ui) {
|
|
|
|
|
ui.item.data('startIndex', ui.item.index());
|
|
|
|
|
},
|
|
|
|
|
stop: function (event, ui) {
|
2013-08-28 18:04:54 +00:00
|
|
|
var taskType = angular.element(ui.item[0]).scope().task.type + 's';
|
2013-08-28 17:38:04 +00:00
|
|
|
var startIndex = ui.item.data('startIndex');
|
|
|
|
|
var task = User.user[taskType][startIndex];
|
2013-12-13 00:32:54 +00:00
|
|
|
User.user.ops.sortTask({params:{id:task.id},query:{from:startIndex, to:ui.item.index()}});
|
2013-08-28 17:38:04 +00:00
|
|
|
}
|
|
|
|
|
});
|
2013-08-28 18:04:54 +00:00
|
|
|
}
|
2013-08-28 18:12:50 +00:00
|
|
|
}]);
|
2013-09-09 18:06:36 +00:00
|
|
|
|
2013-10-27 00:23:52 +00:00
|
|
|
|
|
|
|
|
habitrpg
|
|
|
|
|
.directive('habitrpgTasks', ['$rootScope', 'User', function($rootScope, User) {
|
|
|
|
|
return {
|
|
|
|
|
restrict: 'EA',
|
|
|
|
|
templateUrl: 'templates/habitrpg-tasks.html',
|
|
|
|
|
//transclude: true,
|
|
|
|
|
//scope: {
|
|
|
|
|
// main: '@', // true if it's the user's main list
|
|
|
|
|
// obj: '='
|
|
|
|
|
//},
|
2013-10-30 17:31:36 +00:00
|
|
|
controller: ['$scope', '$rootScope', function($scope, $rootScope){
|
2013-10-27 00:23:52 +00:00
|
|
|
$scope.editTask = function(task){
|
|
|
|
|
task._editing = !task._editing;
|
2014-01-09 04:19:38 +00:00
|
|
|
task._tags = User.user.preferences.tagsCollapsed;
|
|
|
|
|
task._advanced = User.user.preferences.advancedCollapsed;
|
2013-10-27 00:23:52 +00:00
|
|
|
if($rootScope.charts[task.id]) $rootScope.charts[task.id] = false;
|
|
|
|
|
};
|
2013-10-30 17:31:36 +00:00
|
|
|
}],
|
2013-10-27 00:23:52 +00:00
|
|
|
link: function(scope, element, attrs) {
|
2013-10-30 02:07:39 +00:00
|
|
|
// $scope.obj needs to come from controllers, so we can pass by ref
|
2013-10-27 00:23:52 +00:00
|
|
|
scope.main = attrs.main;
|
2013-10-30 02:07:39 +00:00
|
|
|
$rootScope.lists = [
|
2013-10-27 00:23:52 +00:00
|
|
|
{
|
2013-11-14 13:41:42 +00:00
|
|
|
header: env.t('Habits'),
|
2013-10-27 00:23:52 +00:00
|
|
|
type: 'habit',
|
2013-11-14 13:41:42 +00:00
|
|
|
placeHolder: env.t('newHabit')
|
2013-10-27 00:23:52 +00:00
|
|
|
}, {
|
2013-11-14 13:41:42 +00:00
|
|
|
header: env.t('Dailies'),
|
2013-10-27 00:23:52 +00:00
|
|
|
type: 'daily',
|
2013-11-14 13:41:42 +00:00
|
|
|
placeHolder: env.t('newDaily')
|
2013-10-27 00:23:52 +00:00
|
|
|
}, {
|
2013-11-14 13:41:42 +00:00
|
|
|
header: env.t('Todos'),
|
2013-10-27 00:23:52 +00:00
|
|
|
type: 'todo',
|
2013-11-14 13:41:42 +00:00
|
|
|
placeHolder: env.t('newTodo')
|
2013-10-27 00:23:52 +00:00
|
|
|
}, {
|
2013-11-14 13:41:42 +00:00
|
|
|
header: env.t('Rewards'),
|
2013-10-27 00:23:52 +00:00
|
|
|
type: 'reward',
|
2013-11-14 13:41:42 +00:00
|
|
|
placeHolder: env.t('newReward')
|
2013-10-27 00:23:52 +00:00
|
|
|
}
|
|
|
|
|
];
|
2013-10-30 02:07:39 +00:00
|
|
|
|
2013-10-27 00:23:52 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}]);
|
|
|
|
|
|
2013-11-17 19:52:39 +00:00
|
|
|
habitrpg.directive('fromNow', ['$interval', function($interval){
|
|
|
|
|
return function(scope, element, attr){
|
|
|
|
|
var updateText = function(){ element.text(moment(scope.message.timestamp).fromNow()) };
|
|
|
|
|
updateText();
|
|
|
|
|
// Update the counter every 60secs if was sent less than one hour ago otherwise every hour
|
|
|
|
|
// OPTIMIZATION, every time the interval is run, update the interval time
|
|
|
|
|
var intervalTime = moment().diff(scope.message.timestamp, 'minute') < 60 ? 60000 : 3600000;
|
|
|
|
|
var interval = $interval(function(){ updateText() }, intervalTime, false);
|
|
|
|
|
scope.$on('$destroy', function() {
|
|
|
|
|
$interval.cancel(interval);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}]);
|
2013-12-25 06:30:48 +00:00
|
|
|
|
|
|
|
|
habitrpg.directive('questRewards', ['$rootScope', function($rootScope){
|
|
|
|
|
return {
|
|
|
|
|
restrict: 'AE',
|
|
|
|
|
templateUrl: 'partials/options.social.party.quest-rewards.html',
|
|
|
|
|
link: function(scope, element, attrs){
|
|
|
|
|
scope.header = attrs.header || 'Rewards';
|
|
|
|
|
scope.quest = $rootScope.Content.quests[attrs.key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}])
|