Merge pull request #5 from jfederico/master

Encapsulated javascript for landingController
This commit is contained in:
Jesus Federico 2016-10-18 14:15:27 -04:00 committed by GitHub
commit 14ad57d4d1
4 changed files with 28 additions and 24 deletions

View File

@ -1,3 +0,0 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View File

@ -0,0 +1,27 @@
(function() {
var initIndex = function() {
$('#join_form_button').click (function (event) {
$.ajax({
url : $(this).data ('url') + "?name=" + $('#join_form_name').val(),
dataType : "json",
async : true,
type : 'GET',
success : function(data) {
$(location).attr("href", data.response.join_url);
},
error : function(xhr, status, error) {
},
complete : function(xhr, status) {
}
});
});
};
$(document).on("turbolinks:load", function() {
if ($("body[data-controller=landing]").get(0)) {
if ($("body[data-action=index]").get(0)) {
initIndex();
}
}
});
}).call(this);

View File

@ -45,26 +45,6 @@
</div>
<script>
$(document).ready(function($) {
$('#join_form_button').click (function (event) {
$.ajax({
url : $(this).data ('url') + "?name=" + $('#join_form_name').val(),
dataType : "json",
async : true,
type : 'GET',
success : function(data) {
$(location).attr("href", data.response.join_url);
},
error : function(xhr, status, error) {
},
complete : function(xhr, status) {
}
});
});
});
</script>
<% if current_user.nil? %>
<ul>
<li><%= link_to 'Twitter', '/auth/twitter' %></li>

View File

@ -8,7 +8,7 @@
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<body data-controller="<%= params[:controller] %>" data-action="<%= params[:action] %>">
<!-- Messages -->
<div id='messages' class='hidden'>
</div>