use Rails 4 turbolinks

This commit is contained in:
Lee Lawlor
2014-07-23 13:45:15 -04:00
parent 7a132477d0
commit 937d2eea47
25 changed files with 49 additions and 55 deletions

View File

@ -2,6 +2,7 @@
// This file is automatically included by javascript_include_tag :defaults
//= require jquery_ujs
//= require turbolinks
//= require ./jquery.cookie.js
//= require ./updateChart.js
//= require ./timeago.min.js

View File

@ -1,5 +1,5 @@
// when the dom is ready
$(document).ready(function() {
$(document).on('page:load ready', function() {
// if the cheerlights row exists
if ($('#cheerlights_row').length > 0) {

View File

@ -1,5 +1,5 @@
// when the document is ready
$(document).ready(function() {
$(document).on('page:load ready', function() {
// allow flash notices to be dismissed
if ($(".flash").length > 0) {

View File

@ -1,4 +1,4 @@
$(document).ready(function() {
$(document).on('page:load ready', function() {
// when a response is clicked
$('.response').click(function() {

View File

@ -21,21 +21,21 @@
*/
(function($){
// Change the values of this global object if your method parameter is different.
$.restSetup = { methodParam: '_method' };
// collects the csrf-param and csrf-token from meta tags
$(document).ready(function(){
$(document).on('page:load ready', function(){
$.extend($.restSetup, {
csrfParam: $('meta[name=csrf-param]').attr('content'),
csrfToken: $('meta[name=csrf-token]').attr('content')
});
});
// jQuery doesn't provide a better way of intercepting the ajax settings object
var _ajax = $.ajax, options;
function collect_options (url, data, success, error) {
options = { dataType: 'json' };
if (arguments.length === 1 && typeof arguments[0] !== "string") {
@ -62,7 +62,7 @@
});
}
}
function fill_url (url, data) {
var key, u, val;
for (key in data) {
@ -75,25 +75,25 @@
}
return url;
}
// public functions
function ajax (settings) {
settings.type = settings.type || "GET";
if (typeof settings.data !== "string")
if (settings.data != null) {
settings.data = $.param(settings.data);
}
settings.data = settings.data || "";
if ($.restSetup.csrf && !$.isEmptyObject($.restSetup.csrf))
if (!/^(get)$/i.test(settings.type))
if (!/(authenticity_token=)/i.test(settings.data)) {
settings.data += (settings.data ? "&" : "") + $.restSetup.csrfParam + '=' + $restSetup.csrfToken;
}
if (!/^(get|post)$/i.test(settings.type)) {
settings.data += (settings.data ? "&" : "") + $.restSetup.methodParam + '=' + settings.type.toLowerCase();
settings.type = "POST";
@ -101,31 +101,31 @@
return _ajax.call(this, settings);
}
function read () {
collect_options.apply(this, arguments);
$.extend(options, { type: 'GET' })
return $.ajax(options);
}
function create () {
collect_options.apply(this, arguments);
$.extend(options, { type: 'POST' });
return $.ajax(options);
}
function update () {
collect_options.apply(this, arguments);
$.extend(options, { type: 'PUT' });
return $.ajax(options);
}
function destroy () {
collect_options.apply(this, arguments);
$.extend(options, { type: 'DELETE' });
return $.ajax(options);
}
$.extend({
ajax: ajax,
read: read,
@ -133,5 +133,6 @@
update: update,
destroy: destroy
});
})(jQuery);
})(jQuery);

View File

@ -1,5 +1,5 @@
// execute on window load (and not document.ready), so that the sidebar is positioned correctly
$(window).load(function() {
$(window).on('page:load load', function() {
// if affix function exists
if ($.fn.affix) {

View File

@ -71,14 +71,6 @@ class WindowsController < ApplicationController
def index
channel = Channel.find(params[:channel_id])
#channel.update_status_portlet false if (channel.windows.select { |w| w.window_type == 'status' && w.private_flag == false } )
#channel.update_status_portlet true if (channel.windows.select { |w| w.window_type == 'status' && w.private_flag == true } )
#channel.update_video_portlet false if (channel.windows.select { |w| w.window_type == 'video' && w.private_flag == false } )
#channel.update_video_portlet true if (channel.windows.select { |w| w.window_type == 'video' && w.private_flag == true } )
#channel.update_location_portlet false if (channel.windows.select { |w| w.window_type == 'location' && w.private_flag == false } )
#channel.update_location_portlet true if (channel.windows.select { |w| w.window_type == 'location' && w.private_flag == true } )
#channel.update_chart_portlets if (channel.windows.select { |w| w.window_type == 'chart' } )
windows = channel.public_windows(true).order(:position) unless params[:channel_id].nil?
if channel.recent_statuses.nil? || channel.recent_statuses.size <= 0
@ -141,15 +133,6 @@ class WindowsController < ApplicationController
def private_windows
channel = Channel.find(params[:channel_id])
#channel.update_status_portlet false if (channel.windows.select { |w| w.window_type == 'status' && w.private_flag == false } )
#channel.update_status_portlet true if (channel.windows.select { |w| w.window_type == 'status' && w.private_flag == true } )
#channel.update_video_portlet false if (channel.windows.select { |w| w.window_type == 'video' && w.private_flag == false } )
#channel.update_video_portlet true if (channel.windows.select { |w| w.window_type == 'video' && w.private_flag == true } )
#channel.update_location_portlet false if (channel.windows.select { |w| w.window_type == 'location' && w.private_flag == false } )
#channel.update_location_portlet true if (channel.windows.select { |w| w.window_type == 'location' && w.private_flag == true } )
#channel.update_chart_portlets if (channel.windows.select { |w| w.window_type == 'chart' } )
windows = channel.private_windows(true).order(:position) unless params[:channel_id].nil?
if channel.recent_statuses.nil? || channel.recent_statuses.size <= 0

View File

@ -3,7 +3,7 @@
<h4 class="breadcrumb"><%= t(:channels_my) %></h4>
<div class="col-pad">
<div class="col-pad" data-no-turbolink>
<% if @channels.length > 0 %>
@ -73,7 +73,7 @@
</div>
<script>
$(document).ready(function() {
$(document).on('page:load ready', function() {
$('.tablesorter').tablesorter();
});
</script>

View File

@ -36,7 +36,7 @@
<script>
// when the document is ready
$(document).ready(function() {
$(document).on('page:load ready', function() {
// when search tag is clicked
$('#search_tag').on('click', function() {

View File

@ -11,7 +11,7 @@
</style>
<script type="text/javascript">
$(document).ready(function() {
$(document).on('page:load ready', function() {
var html = '';
var field1, field2, field3, field4, field5, field6, field7, field8;
@ -56,7 +56,7 @@
setInterval(function() {
// get the data with a webservice call
$.getJSON('<%= "#{@domain}channels/#{params[:channel_id]}/feed/last.json?callback=?&offset=0&location=true&status=true" %>', function(data) {
$.getJSON('<%= "#{@domain}channels/#{params[:channel_id]}/feed/last.json?callback=?&offset=0&location=true&status=true" %>', function(data) {
// if data exists and entry id doesn't already exist
if (data.location && $('#entry_' + data.entry_id).length == 0) {
html = '<div id="entry_' + data.entry_id + '"><b><img src="<%= "#{@domain}images/icon_location_24.png" %>" width="24" height="24" border="0" align="absbottom" /> ' + data.location + '</b></div>';
@ -91,3 +91,4 @@
<div id="feed-container"></div>
</body>
</html>

View File

@ -174,7 +174,7 @@
var options = '<%= options.gsub(/'/, "%27") if options %>';
$(document).ready(function() {
$(document).on('page:load ready', function() {
// set initial saved values
$.each((options.split('&amp;')), setupChartForm(<%= index %> ));
// draw initial chart with saved options

View File

@ -56,7 +56,7 @@
<script type="text/javascript">
$(document).ready(function() {
$(document).on('page:load ready', function() {
// if chrome/safari error occurs, reload page
if ($('#title0').val() == '60' && $('#color0').val() == '10') {
window.location.reload();

View File

@ -20,7 +20,7 @@
return Date.UTC(d.substring(0,4), d.substring(5,7)-1, d.substring(8,10), d.substring(11,13), d.substring(14,16), d.substring(17,19)) - (myOffset * 60000);
}
$(document).ready(function() {
$(document).on('page:load ready', function() {
// blank array for holding chart data
var chartData = [];
// variable for the local date in milliseconds

View File

@ -6,12 +6,12 @@
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootswatch/3.1.1/cerulean/bootstrap.min.css" />
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" media="screen" rel="stylesheet" />
<%= stylesheet_link_tag 'application' %>
<%= stylesheet_link_tag 'application', "data-turbolinks-track" => true %>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type='text/javascript' src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<%= javascript_include_tag 'application' %>
<%= javascript_include_tag 'application', "data-turbolinks-track" => true %>
<%= csrf_meta_tag %>
<% if Rails.env == 'production' %>

View File

@ -15,7 +15,7 @@
return Date.UTC(d.substring(0,4), d.substring(5,7)-1, d.substring(8,10), d.substring(11,13), d.substring(14,16), d.substring(17,19)) - (myOffset * 60000);
}
$(document).ready(function() {
$(document).on('page:load ready', function() {
// blank array for holding chart data
var chartData = [];
// variable for the date string

View File

@ -1,6 +1,6 @@
<div class="col-sm-8 col-xs-8">
<ol class="breadcrumb">
<ol class="breadcrumb" data-no-turbolink>
<li><%= link_to t(:plugins), plugins_path %></li>
<li><%= link_to plugin_path(@plugin.id) do %> <%= t(:plugin) %> <%= @plugin.id %><% end %></li>
<li class="active"><%= t(:edit) %></li>