From e9f77b4e2e421717fe001ead6887cd7768e9f8ae Mon Sep 17 00:00:00 2001 From: jfederico Date: Tue, 18 Oct 2016 14:14:37 -0400 Subject: [PATCH] Encapsulated javascript for landingController --- app/assets/javascripts/landing.coffee | 3 --- app/assets/javascripts/landing.js | 27 ++++++++++++++++++++++++++ app/views/landing/index.html.erb | 20 ------------------- app/views/layouts/application.html.erb | 2 +- 4 files changed, 28 insertions(+), 24 deletions(-) delete mode 100644 app/assets/javascripts/landing.coffee create mode 100644 app/assets/javascripts/landing.js diff --git a/app/assets/javascripts/landing.coffee b/app/assets/javascripts/landing.coffee deleted file mode 100644 index 24f83d18..00000000 --- a/app/assets/javascripts/landing.coffee +++ /dev/null @@ -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/ diff --git a/app/assets/javascripts/landing.js b/app/assets/javascripts/landing.js new file mode 100644 index 00000000..6f5c5ec1 --- /dev/null +++ b/app/assets/javascripts/landing.js @@ -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); \ No newline at end of file diff --git a/app/views/landing/index.html.erb b/app/views/landing/index.html.erb index 7cd1612e..13bee6ad 100644 --- a/app/views/landing/index.html.erb +++ b/app/views/landing/index.html.erb @@ -45,26 +45,6 @@ - - <% if current_user.nil? %>