forum.js
2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import './common/services/subscription';
import './common/controllers/subscription';
import './common/directives/frMarkdown';
import './poll/frPoll';
import './poll/frPollEditorModal';
import './common/jquery.litebox';
import './comment/frCommenter';
angular.module('footyroom')
.controller('forumCommentController', ['$scope', '$compile', '$element', function ($scope, $compile, $element) {
var editorEl;
var isEditing;
var commentId = $element.attr('commentID');
$scope.edit = function () {
if (!isEditing) {
isEditing = true;
editorEl = $compile(
'<forum-commenter class="edit-mode" comment-id=' + commentId + ' on-cancel="cancelEdit"></forum-commenter>'
)($scope);
$element.after(editorEl).hide();
}
};
$scope.cancelEdit = function () {
editorEl.remove();
$element.show();
isEditing = false;
};
}])
.controller('NewPostController', ['$scope', '$http', '$window', function ($scope, $http, $window) {
var isPosting;
var wizardEl = angular.element('#newpost-wizard');
$scope.step = 1;
$scope.showCategories = function () {
wizardEl.litebox();
};
$scope.selectCategory = function (id, title) {
$scope.categoryId = id;
$scope.categoryTitle = title;
$scope.step = 2;
};
$scope.title = window.localStorage.getItem('postTitle');
$scope.$watch('title', function (newValue, oldValue) {
window.localStorage.setItem('postTitle', $scope.title || '');
});
$scope.publish = function () {
if (isPosting) {
return;
}
isPosting = true;
wizardEl.find('.post-title').litelay();
wizardEl.find('markdown-editor').litelay({ spinner: true });
var data = {
category: $scope.categoryId,
title: $scope.title,
content: $scope.content,
honeypot: $scope.nameEmailUrl,
};
$http.post('/forum/discussions', $.param(data), { headers: {'Content-Type': 'application/x-www-form-urlencoded'} })
.then(function (response) {
window.localStorage.removeItem('postTitle');
window.localStorage.removeItem('markdownContent');
$window.location = response.data.url;
})
.catch(function (response) {
$scope.errors = response.data.errors || "Something went wrong, but we don't know what. Try again later or report this to us.";
isPosting = false;
wizardEl.find('.post-title').litelay();
wizardEl.find('markdown-editor').litelay();
});
};
}]);
//! !!!!!!
var Forum;
$(function () {
var filter = $.QueryString.filter;
if (filter) {
$('#posts .filter [data-tab="' + filter + '"]').addClass('active');
} else {
$('#posts .filter [data-tab="allposts"]').addClass('active');
}
});