mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Encapsulate directive functions in anonymous functions - avoid the global namespace
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
(function(){
|
||||
angular
|
||||
.module('habitrpg')
|
||||
.directive('focusMe', focusMe);
|
||||
|
||||
focusMe.$inject = [
|
||||
focusMe.$inject = [
|
||||
'$timeout',
|
||||
'$parse'
|
||||
];
|
||||
];
|
||||
|
||||
function focusMe($timeout, $parse) {
|
||||
function focusMe($timeout, $parse) {
|
||||
return {
|
||||
link: function(scope, element, attrs) {
|
||||
var model = $parse(attrs.focusMe);
|
||||
@@ -20,4 +21,5 @@ function focusMe($timeout, $parse) {
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
(function(){
|
||||
angular
|
||||
.module('habitrpg')
|
||||
.directive('fromNow', fromNow);
|
||||
|
||||
fromNow.$inject = [
|
||||
fromNow.$inject = [
|
||||
'$interval',
|
||||
'$timeout'
|
||||
];
|
||||
];
|
||||
|
||||
function fromNow($interval, $timeout) {
|
||||
function fromNow($interval, $timeout) {
|
||||
return function(scope, element, attr){
|
||||
var interval, timeout;
|
||||
|
||||
@@ -41,4 +42,5 @@ function fromNow($interval, $timeout) {
|
||||
if(timeout) $timeout.cancel(timeout);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
(function(){
|
||||
angular
|
||||
.module('habitrpg')
|
||||
.directive('habitrpgTasks', habitrpgTasks);
|
||||
|
||||
habitrpgTasks.$inject = [
|
||||
habitrpgTasks.$inject = [
|
||||
'$rootScope',
|
||||
'User'
|
||||
];
|
||||
];
|
||||
|
||||
function habitrpgTasks($rootScope, User) {
|
||||
function habitrpgTasks($rootScope, User) {
|
||||
return {
|
||||
restrict: 'EA',
|
||||
templateUrl: 'templates/habitrpg-tasks.html',
|
||||
@@ -58,4 +59,5 @@ function habitrpgTasks($rootScope, User) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
(function(){
|
||||
angular
|
||||
.module('habitrpg')
|
||||
.directive('hrpgSortChecklist', hrpgSortChecklist);
|
||||
|
||||
hrpgSortChecklist.$inject = [
|
||||
hrpgSortChecklist.$inject = [
|
||||
'User'
|
||||
];
|
||||
];
|
||||
|
||||
function hrpgSortChecklist(User) {
|
||||
function hrpgSortChecklist(User) {
|
||||
return function($scope, element, attrs, ngModel) {
|
||||
$(element).sortable({
|
||||
axis: "y",
|
||||
@@ -27,4 +28,5 @@ function hrpgSortChecklist(User) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
(function(){
|
||||
angular
|
||||
.module('habitrpg')
|
||||
.directive('hrpgSortTags', hrpgSortTags);
|
||||
|
||||
hrpgSortTags.$inject = [
|
||||
hrpgSortTags.$inject = [
|
||||
'User'
|
||||
];
|
||||
];
|
||||
|
||||
function hrpgSortTags(User) {
|
||||
function hrpgSortTags(User) {
|
||||
return function($scope, element, attrs, ngModel) {
|
||||
$(element).sortable({
|
||||
start: function (event, ui) {
|
||||
@@ -24,4 +25,5 @@ function hrpgSortTags(User) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
(function(){
|
||||
angular
|
||||
.module('habitrpg')
|
||||
.directive('hrpgSortTasks', hrpgSortTasks);
|
||||
|
||||
hrpgSortTasks.$inject = [
|
||||
hrpgSortTasks.$inject = [
|
||||
'User'
|
||||
];
|
||||
];
|
||||
|
||||
function hrpgSortTasks(User) {
|
||||
function hrpgSortTasks(User) {
|
||||
return function($scope, element, attrs, ngModel) {
|
||||
$(element).sortable({
|
||||
axis: "y",
|
||||
@@ -29,4 +30,5 @@ function hrpgSortTasks(User) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
(function(){
|
||||
angular
|
||||
.module('habitrpg')
|
||||
.directive('popoverHtmlPopup', popoverHtmlPopup)
|
||||
.run(loadPopupTemplate);
|
||||
|
||||
popoverHtmlPopup.$inject = [
|
||||
popoverHtmlPopup.$inject = [
|
||||
'$sce'
|
||||
];
|
||||
];
|
||||
|
||||
function popoverHtmlPopup($sce) {
|
||||
function popoverHtmlPopup($sce) {
|
||||
return {
|
||||
restrict: 'EA',
|
||||
replace: true,
|
||||
@@ -21,18 +22,18 @@ function popoverHtmlPopup($sce) {
|
||||
},
|
||||
templateUrl: 'template/popover/popover-html.html'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* TODO: Review whether it's appropriate to be seeding this into the
|
||||
* templateCache like this. Feel like this might be an antipattern?
|
||||
*/
|
||||
|
||||
loadPopupTemplate.$inject = [
|
||||
loadPopupTemplate.$inject = [
|
||||
'$templateCache'
|
||||
];
|
||||
];
|
||||
|
||||
function loadPopupTemplate($templateCache) {
|
||||
function loadPopupTemplate($templateCache) {
|
||||
$templateCache.put("template/popover/popover-html.html",
|
||||
"<div class=\"popover {{placement}}\" ng-class=\"{ in: isOpen(), fade: animation() }\">\n" +
|
||||
" <div class=\"arrow\"></div>\n" +
|
||||
@@ -42,4 +43,5 @@ function loadPopupTemplate($templateCache) {
|
||||
" <div class=\"popover-content\" ng-bind-html=\"unsafeContent\" style=\"word-wrap: break-word\"> </div>\n" +
|
||||
" </div>\n" +
|
||||
"</div>\n");
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
(function(){
|
||||
angular
|
||||
.module('habitrpg')
|
||||
.directive('popoverHtml', popoverHtml);
|
||||
|
||||
popoverHtml.$inject = [
|
||||
popoverHtml.$inject = [
|
||||
'$compile',
|
||||
'$timeout',
|
||||
'$parse',
|
||||
'$window',
|
||||
'$tooltip'
|
||||
];
|
||||
];
|
||||
|
||||
function popoverHtml($compile, $timeout, $parse, $window, $tooltip) {
|
||||
function popoverHtml($compile, $timeout, $parse, $window, $tooltip) {
|
||||
return $tooltip('popoverHtml', 'popover', 'click');
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
(function(){
|
||||
angular
|
||||
.module('habitrpg')
|
||||
.directive('taskFocus', taskFocus);
|
||||
|
||||
taskFocus.$inject = ['$timeout'];
|
||||
taskFocus.$inject = ['$timeout'];
|
||||
|
||||
/**
|
||||
/**
|
||||
* Directive that places focus on the element it is applied to when the
|
||||
* expression it binds to evaluates to true.
|
||||
*/
|
||||
|
||||
function taskFocus($timeout) {
|
||||
function taskFocus($timeout) {
|
||||
return function(scope, elem, attrs) {
|
||||
scope.$watch(attrs.taskFocus, function(newVal) {
|
||||
if (newVal) {
|
||||
@@ -21,4 +22,5 @@ function taskFocus($timeout) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
(function(){
|
||||
angular
|
||||
.module('habitrpg')
|
||||
.directive('whenScrolled', whenScrolled);
|
||||
|
||||
function whenScrolled() {
|
||||
function whenScrolled() {
|
||||
return function(scope, elm, attr) {
|
||||
var raw = elm[0];
|
||||
|
||||
@@ -14,4 +15,5 @@ function whenScrolled() {
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
||||
Reference in New Issue
Block a user