Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show more/less in grids #2184

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions app/views/grids/_notes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</tr>
<% if index == 9 %>
<tr class="show-all">
<td><a>Show <%= nodes.length - 10 %> more <b class="caret"></b></a></td>
<td><a>Show <%= (nodes.length - 10) == 0 ? "" : (nodes.length - 10) %> more <b class="caret"></b></a></td>
<td></td>
<td></td>
<td></td>
Expand All @@ -73,15 +73,37 @@
<% end %>

<script>
(function(){
$(".<%= className %>-<%= randomSeed %> .show-all a").click(function() {
$(".<%= className %>-<%= randomSeed %> .show-all a").click(function(event) {
$(".<%= className %>-<%= randomSeed %> tr.hide").toggleClass("hide");
});
$(".grid-embed-<%= randomSeed %>").click(function() {
prompt('Use this HTML code to embed this table on another site.', '<iframe style="border:none;" width="100%" height="900px" src="//publiclab.org/embed/grid/<% if type != "notes" %><%= type.gsub('questions', 'question').gsub('activities', 'activity') %>:<% end %><%= tagname %>"></iframe>')
});
setupGridSorters(".<%= className %>-<%= randomSeed %>");
})()
console.log(event);
if(event.currentTarget.offsetParent.offsetParent.classList[2] == "questions-grid"){
// console.log("question was clicked");
if(event.currentTarget.firstElementChild.classList[1] !== "caret-up"){
$(".questions-grid .show-all a").html("Show less <b class=\"caret caret-up\"></b>");
$(".grid-embed-<%= randomSeed %>").click(function() {
prompt('Use this HTML code to embed this table on another site.', '<iframe style="border:none;" width="100%" height="900px" src="//publiclab.org/embed/grid/<% if type != "notes" %><%= type.gsub('questions', 'question').gsub('activities', 'activity') %>:<% end %><%= tagname %>"></iframe>')
});
}else{
$(".questions-grid .show-all a").html('Show <%= (nodes.length - 10) == 0 ? "" : (nodes.length - 10) %> more <b class="caret"></b>');
for(var i = 12; i < $(".questions-grid tr").length; i++){
$(".questions-grid tr")[i].className = "hide";
}
}
}else if(event.currentTarget.offsetParent.offsetParent.classList[2] == "activity-grid"){
// console.log("activity was clicked");
if(event.currentTarget.firstElementChild.classList[1] !== "caret-up"){
$(".activity-grid .show-all a").html("Show less <b class=\"caret caret-up\"></b>");
$(".grid-embed-<%= randomSeed %>").click(function() {
prompt('Use this HTML code to embed this table on another site.', '<iframe style="border:none;" width="100%" height="900px" src="//publiclab.org/embed/grid/<% if type != "notes" %><%= type.gsub('questions', 'question').gsub('activities', 'activity') %>:<% end %><%= tagname %>"></iframe>')
});
}else{
$(".activity-grid .show-all a").html('Show <%= (nodes.length - 10) == 0 ? "" : (nodes.length - 10) %> more <b class="caret"></b>');
for(var i = 12; i < $(".activity-grid tr").length; i++){
$(".activity-grid tr")[i].className = "hide";
}
}
}
});
</script>
<style>
a.grid-embed {
Expand All @@ -91,4 +113,8 @@
a.grid-embed:hover {
color: #888;
}
.caret.caret-up{
border-top-width: 0;
border-bottom: 4px solid;
}
</style>