Make links inside event-panel work with ctrl+click

Function introduce to be used in links inside event-panel to make ctrl + click work.
This commit is contained in:
Ana 2016-08-11 12:43:10 +02:00 committed by Ana María Martínez Gómez
parent 56f09474eb
commit cf5d4e4dbe
2 changed files with 26 additions and 12 deletions

View file

@ -116,3 +116,28 @@ $(document).ready( function() {
}
});
});
function eventClicked(e, element){
var url = $(element).data('url');
if(e.ctrlKey)
window.open(url,'_blank');
else
window.location = url;
}
/* Links inside event-panel (to make ctrl + click work for these links):
= link_to text, '#', onClick: 'insideLinkClicked();', 'data-url' => url
*/
function insideLinkClicked(event){
// stops the click from propagating
if (!event) // for IE
var event = window.event;
event.cancelBubble = true;
if (event.stopPropagation) event.stopPropagation();
var url = $(event.target).data('url');
if(event.ctrlKey)
window.open(url,'_blank');
else
window.location = url;
}

View file

@ -1,4 +1,4 @@
.panel.panel-default.event-panel{ id: "link-#{event.id}" }
.panel.panel-default.event-panel{ onClick: 'eventClicked(event, this);', "data-url" => "#{url_for(conference_program_proposal_path(@conference.short_title, event.id))}" }
.panel-body
- if speaker = event.speakers.first
= image_tag speaker.gravatar_url, :class => "img-circle pull-right all-speaker-pic", |
@ -30,14 +30,3 @@
%span.fa.fa-road
%span.label{ style: "background-color: #{event.track.color}; color: #{ contrast_color(event.track.color) }" }
= event.track.name
:javascript
$("#link-#{event.id}").click(function(e) {
var url = "#{url_for(conference_program_proposal_path(@conference.short_title, event.id))}";
if(e.ctrlKey)
window.open(url,'_blank');
else
window.location = url;
});