-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
_like.html.erb
216 lines (203 loc) · 12.1 KB
/
_like.html.erb
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<div class="like-buttons d-print-none btn-toolbar" style="margin-bottom :4px;">
<% if logged_in_as(['admin', 'moderator']) || (current_user && (current_user.uid == node.uid || node.has_tag("with:#{current_user.username}"))) %>
<% if node.type == 'note' %>
<a aria-label="Edit post" <% if current_user && current_user.uid != node.uid %>data-confirm='Please be aware that you are editing a post by another contributor, a privilege you have only because you are an admin or co-author.' <% end %> class='btn btn-outline-secondary btn-circle btn-sm' href='/notes/edit/<%= node.id %>?t=<%= Time.now.to_i %><% if params[:controller] == "questions" %>&redirect=question&template=question<% end %>'>
<i class='ml-1 ff fa fa-pencil'></i>
</a>
<% end %>
<% end %>
<% if node.type == 'page' %>
<% if node.has_tag('locked') && (current_user ? (current_user.role != "moderator" && current_user.role != "admin") : true) %>
<a href="/wiki/locked" class='btn btn-outline-secondary btn-circle btn-sm'>
<i class="ml-1 ff fa fa-lock"></i>
</a>
<% elsif current_user && current_user.first_time_poster %>
<a class='btn btn-outline-secondary btn-circle btn-sm' rel="tooltip" title="Please post a question or other content before editing the wiki. Click to learn why." data-placement="top" href="https://publiclab.org/notes/tester/04-23-2016/new-moderation-system-for-first-time-posters">
<i class="ml-1 ff fa fa-lock"></i>
</a>
<% else %>
<a class="btn-circle btn btn-outline-secondary" id="edit-btn" href='<%= node.edit_path %>?t=<%= Time.now.to_i %>'>
<i class='ml-1 ff fa fa-pencil'></i>
</a>
<% end %>
<% end %>
<span data-toggle="tooltip" data-placement="top" rel="tooltip" title="Liked by <%= node.likers.length %> people" class="btn btn-outline-secondary btn-circle btn-like" node-id="<%= node.id %>" id="like-button-<%= node.id %>">
<% if !current_user %>
<a id="open-login-like" data-hashparams="like" data-toggle="modal" data-target="#loginModal">
<span id="like-star-<%= node.id %>" class="ff fa fa-star"></span>
</a>
<% else %>
<span id="like-star-<%= node.id %>" class="ff fa fa-star<% if !node.liked_by(current_user.uid) %>-o<% end %>"></span>
<% end %>
</span>
<% if @node %>
<% subpage_count = Tag.find_pages("parent:#{@node.slug}", 100).count %>
<% if subpage_count > 0 %>
<span class="btn btn-outline-secondary btn-circle" data-toggle="tooltip" data-placement="top" rel="tooltip" title="<%= subpage_count %> sub-pages">
<a href="/wiki/tag/parent:<%= @node.slug %>">
<i class="ff fa fa-book"></i>
</a>
</span>
<% end %>
<% end %>
<span data-toggle="tooltip" data-placement="bottom" title="Tools" id="menu-btn" class="btn btn-outline-secondary btn-circle btn-sm" rel="popover" data-placement="left" data-html="true" style="overflow: auto; max-height: 500px" data-content="
<p><b>Users who liked this</b></p>
<% node.likers.each do |user| %>
<i class='fa fa-star-o'></i> <a href='/profile/<%= user.username %>/'><%= user.username %></a><br />
<% end %>
<% if node.likers.length == 0 %><i>None</i><% end %>
<% if node.type == 'note' && current_user && node.uid != current_user.uid%>
<hr style='margin-bottom:3px;' />
<p><b>Award a Barnstar:</b></p>
<form class='form' action='/barnstar/give'>
<select name='star' class='form-control'>
<option value='basic'>The basic barnstar</option>
<option value='photo-documentation'>The photo documentation barnstar</option>
<option value='video-documentation'>The video documentation barnstar</option>
<option value='watchdog'>The watchdog barnstar</option>
<option value='empiricism'>The empiricism barnstar</option>
<option value='excessive-enthusiasm'>The enthusiasm barnstar</option>
</select><br />
<input type='hidden' name='nid' value='<%= node.id %>'/>
<input type='submit' class='btn btn-primary' value='Give'/> <a _target='blank' href='/wiki/barnstars'>Learn more</a>
</form>
<br>
<% end %>
<p><a class='btn btn-sm btn-outline-secondary' rel='tooltip' title='Try the beta inline Rich Wiki editor.' data-placement='top' href='<%= node.path %>?raw=true'>
<i style='color:#0c8;' class='fa fa-pencil'></i>
</a></p>
<% if logged_in_as(['admin', 'moderator']) || (current_user && current_user.uid == node.uid) %>
<hr />
<div class='btn-group'>
<a rel='tooltip' title='Flag as spam' class='btn btn-sm btn-outline-secondary btn-flag-spam-<%= node.id %>' href='mailto:[email protected]?subject=Reporting+spam+on+Public+Lab&body=Hi,+I+found+this+item+that+looks+like+spam+or+needs+to+be+moderated:+<%= node.title.gsub(/ /,'+') %>+https://publiclab.org/n/<%= node.id %>+by+https://publiclab.org/profile/<%= node.author.username %>+Thanks!'>
<i class='fa fa-flag'></i>
</a>
<li data-toggle='tooltip' data-placement='top' title='Follow by tag or author' id='menu-follow-btn' class='btn btn-outline-secondary btn-sm requireLogin nestedPopover' data-html='true' rel='popover' data-placement='left' data-content=" <%= "No tags" if tagnames.nil? || tagnames.length == 0 %> <% if tagnames %><% tagnames.each do |tagname| %><p style='margin-bottom:3px; overflow: hidden; text-overflow: ellipsis;'><a href='/subscribe/tag/<%= tagname %>' class='btn btn-outline-secondary btn-sm'><%= tagname %></a></p><% end %><% end %><hr /><i class='fa fa-user'></i><% if current_user && !current_user.following?(node.author) && node.author != current_user %> <a class='btn btn-sm' href='/relationships?followed_id=<%= node.author.id %>' data-method='post' > <%= node.author.name %></a><% else %> <%= node.author.name %><% end %>">
<i class='fa fa-user-plus' aria-hidden='true'></i>
</li>
<a href='/notes/delete/<%= node.id %>' class='btn btn-outline-secondary btn-sm' id='menu-delete-btn' data-confirm='All revisions will be lost, and you cannot undo this action. If this is a spam page, be sure that it did not overwrite valid content before deleting the entire page and the history.'>
<i class='fa fa-trash'></i><span class='d-none d-lg-inline'></span>
</a>
<a href='/notes/raw/<%= node.id %>' class='btn btn-outline-secondary btn-sm'>
<i class='fa fa-code'></i><span class='d-none d-lg-inline'> Raw</span>
</a>
<% if logged_in_as(['admin', 'moderator']) %>
<% if node.type == 'note' %>
<a class='btn btn-outline-secondary btn-sm' href='/moderate/spam/<%= node.id %>'><i class='fa fa-ban-circle'></i> Spam</a>
<% elsif node.type == 'page' %>
<a class='btn btn-outline-secondary btn-sm' href='/moderate/revision/spam/<%= @revision.vid %>'><i class='fa fa-ban-circle'></i> Spam revision</a>
<% end %>
<% end %>
</div>
<% end %>
<br />
<hr style='clear:both;' />
<div>
<span>
<% if node.type == 'note' %>
<%= number_with_delimiter(node.views) %> <%= translation('notes.show.views') %>
<% if node.comments %>
| <a href='#comments'><%= node.comments.length %> <%= translation('notes.show.comments') %></a>
<% end %>
| <%= raw translation('wiki.show.last_edited', url1: "/profile/" + node.latest.author.name, author: node.latest.author.name, time: time_ago_in_words(node.latest.created_at)) %>
<% end %>
<% if node.type == 'page' %>
<%= number_with_delimiter(node.views) %> <%= translation('wiki.show.views') %>
<% if node.comments %>
| <a href='#comments'><%= node.comments.length %> Comments</a>
<% end %>
| <%= raw translation('wiki.show.last_edited', url1: "/profile/" + @revision.author.name, author: @revision.author.name, time: time_ago_in_words(@revision.created_at)) %>
<% end %>
</span>
</div>
<br />
<hr style='clear:both;' />
<div>
<p><a id='print-command-no-links'><i class='fa fa-print'></i> Print without page links</a></p>
<p><a id='print-command-3-col'><i class='fa fa-print'></i> Print in 3-column layout</a></p>
</div>
">
<span style="margin: 5px !important;" class="ff fa fa-ellipsis-h"></span>
</span>
<style type="text/css">
/* Styling the links to remove underline on hover and setting pointer as cursor */
#print-command-3-col , #print-command-no-links {
text-decoration : none;
cursor : pointer;
}
.bs-popover-bottom {
overflow: visible;
max-width: 1000px;
}
.like-buttons {
margin-top:5px;
}
like-buttons a .fa, .popover .btn-group a .fa {
color: inherit;
}
@media (max-width: 992px) {
.like-buttons {
justify-content: center !important;
margin-top: 30px;
}
}
</style>
<script>
$('[rel="tooltip"]').on('click', function () {
$(this).tooltip('hide')
})
function print_three_column() {
$('body').css('column-count', 3)
.css('column-gap', '50px');
$('.popover').popover('hide');
window.print();
$('body').css('column-count', 1)
.css('column-gap', 0);
}
function print_linkless() {
window.print();
}
// Event listner on CLICK on links
$(document).on("click", "#print-command-3-col",print_three_column);
$(document).on("click", "#print-command-no-links",print_linkless);
jQuery(document).ready(function() {
// 304 cached response yields no data to insert, which is not useful
jQuery.ajaxSetup({
cache: false
});
// opens modal to login before you can like;
$("#open-login-like").click(function() {
$("input[name='hash_params']").val($(this).attr("data-hashparams"));
});
// triggers liking and unliking
<% if current_user %>
$('#like-button-<%= node.id %>').on('click', debounce(<% if node.liked_by(current_user.uid) %>clickliked<% else %>clicknotliked<% end %>, 200, true));
// leaving below uncommented for now - possibility useful for implement comment like functionality?
// if(window.location.href.includes("#like")) {
// $('#like-button-<%= node.id %>').click();
// }
<% end %>
});
$('body').on('click', '.nestedPopover', function() {
$(this).popover({
container: 'body',
trigger: 'focus click'
});
$(this).popover('show');
$(this).removeClass("nestedPopover");
});
$('body').on('click', function (e) { // If there's a click event in the body
$('[rel=popover]').each(function () { // For each popover
/*
* The popover will only `hide` if all the conditions below are satisfied :
* 1. The target triggering the `click` event is not `this`
* 2. `this` doesn't have a child triggering the `click` event
* 3. Any element with `.popover` class doesn't have a child triggering the `click` event
*/
if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
$(this).popover('hide');
}
});
});
</script>
</div>