Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
Removes jQuery and CoffeeScript dependencies
Browse files Browse the repository at this point in the history
jQuery Rails is now at v3, so forcing a lower version means that some
users will run into dependency conflicts when installing CASino
(especially Rails 4 users)

Additionally, not only do some users not use (or want) jQuery or
CoffeeScript in their application, CASino isn't using that much
CoffeeScript to necessitate pulling in all of jQuery or requiring
CoffeeScript.

This updates the javascript in two ways:

* Replaces the auto-focusing of CASino elements with the `autofocus`
  HTML5 attribute

* Replaces the jQuery-specific javascript that automatically logs a
  user in when a TGT is already present with native DOM calls inlined
  directly in the login form so that it is always present, regardless
  of how the parent application has configured its layouts.

* Rewrites the CoffeeScript source into JavaScript
  • Loading branch information
Derek Lindahl committed Oct 26, 2013
1 parent 61c97fa commit d6cbe59
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 26 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/casino/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Place all the behaviors and hooks related to the matching controller here.
5 changes: 0 additions & 5 deletions app/assets/javascripts/casino/application.js.coffee

This file was deleted.

2 changes: 0 additions & 2 deletions app/assets/javascripts/casino/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require_tree .
23 changes: 23 additions & 0 deletions app/assets/javascripts/casino/sessions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(function(win, doc) {
var url = '/login',
cookie_regex = /(^|;)\s*tgt=/;

function checkCookieExists() {
var serviceEl = doc.getElementById('service'),
svcValue = serviceEl ? serviceEl.getAttribute('value') : null;

if(svcValue) {
if(cookie_regex.test(doc.cookie)) {
win.location = url + '?service=' + encodeURIComponent(svcValue);
}
} else {
setTimeout(checkCookieExists, 1000);
}
}

// Auto-login when logged-in in other browser window (9887c4e)
if(doc.getElementById('login-form')) {
checkCookieExists();
}

})(this, document);
15 changes: 0 additions & 15 deletions app/assets/javascripts/casino/sessions.js.coffee

This file was deleted.

6 changes: 5 additions & 1 deletion app/views/casino/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<%= hidden_field_tag :lt, @login_ticket.ticket %>
<%= hidden_field_tag :service, params[:service] unless params[:service].nil? %>
<%= label_tag :username, t('login.label_username') %>
<%= text_field_tag :username, params[:username] %>
<%= text_field_tag :username, params[:username], autofocus:true %>
<%= label_tag :password, t('login.label_password') %>
<%= password_field_tag :password %>
<%= label_tag :rememberMe do %>
Expand All @@ -28,3 +28,7 @@
</div>
<%= render 'footer' %>
</div>

<%= javascript_tag do %>
<%= Rails.application.assets.find_asset('casino/sessions').to_s.html_safe %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/casino/sessions/validate_otp.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<%= hidden_field_tag :tgt, @ticket_granting_ticket || params[:tgt] %>
<%= hidden_field_tag :service, params[:service] %>
<%= label_tag :code, t('validate_otp.code') %>
<%= text_field_tag :otp, nil, maxlength: 6 %>
<%= text_field_tag :otp, nil, maxlength: 6, autofocus:true %>
<%= button_tag t('validate_otp.submit'), :class => 'button' %>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/casino/two_factor_authenticators/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<%= form_tag(two_factor_authenticators_path, method: :post, id: 'two_factor_authenticators-form') do %>
<%= hidden_field_tag :id, @two_factor_authenticator.id %>
<%= label_tag :code, t('two_factor_authenticators.code') %>
<%= text_field_tag :otp, nil, maxlength: 6 %>
<%= text_field_tag :otp, nil, maxlength: 6, autofocus:true %>
<%= link_to t('two_factor_authenticators.cancel'), sessions_path, :class => 'secondary button' %>
<%= button_tag t('two_factor_authenticators.submit'), :class => 'button' %>
<% end %>
Expand Down
1 change: 0 additions & 1 deletion casino.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Gem::Specification.new do |s|
s.add_development_dependency 'coveralls', '~> 0.7'

s.add_runtime_dependency 'rails', '~> 3.2.9'
s.add_runtime_dependency 'jquery-rails', '~> 2.1'
s.add_runtime_dependency 'http_accept_language', '~> 2.0.0.pre'
s.add_runtime_dependency 'addressable', '~> 2.3'
s.add_runtime_dependency 'terminal-table', '~> 1.4'
Expand Down

0 comments on commit d6cbe59

Please sign in to comment.