stylesheets are basically now being served from sprockets
9
Gemfile
|
|
@ -107,6 +107,15 @@ gem 'sass'
|
|||
gem 'will_paginate'
|
||||
gem 'client_side_validations'
|
||||
|
||||
# assets
|
||||
|
||||
group :assets do
|
||||
gem 'sass-rails'
|
||||
gem 'uglifier'
|
||||
end
|
||||
|
||||
gem 'jquery-rails'
|
||||
|
||||
# web
|
||||
|
||||
gem 'faraday'
|
||||
|
|
|
|||
20
Gemfile.lock
|
|
@ -145,6 +145,8 @@ GEM
|
|||
erubis (2.7.0)
|
||||
eventmachine (1.0.0.beta.4)
|
||||
excon (0.12.0)
|
||||
execjs (1.3.0)
|
||||
multi_json (~> 1.0)
|
||||
factory_girl (2.6.4)
|
||||
activesupport (>= 2.3.9)
|
||||
factory_girl_rails (1.7.0)
|
||||
|
|
@ -219,7 +221,14 @@ GEM
|
|||
rspec (>= 1.3.1)
|
||||
selenium-webdriver (>= 0.1.3)
|
||||
jasmine-core (1.1.0)
|
||||
<<<<<<< HEAD
|
||||
json (1.6.6)
|
||||
=======
|
||||
jquery-rails (1.0.19)
|
||||
railties (~> 3.0)
|
||||
thor (~> 0.14)
|
||||
json (1.6.5)
|
||||
>>>>>>> stylesheets are basically now being served from sprockets
|
||||
jsonpath (0.5.0)
|
||||
multi_json
|
||||
jwt (0.1.4)
|
||||
|
|
@ -390,6 +399,11 @@ GEM
|
|||
s3 (0.3.11)
|
||||
proxies (~> 0.2.0)
|
||||
sass (3.1.15)
|
||||
sass-rails (3.1.6)
|
||||
actionpack (~> 3.1.0)
|
||||
railties (~> 3.1.0)
|
||||
sass (>= 3.1.10)
|
||||
tilt (~> 1.3.2)
|
||||
selenium-webdriver (2.16.0)
|
||||
childprocess (>= 0.2.5)
|
||||
ffi (~> 1.0.9)
|
||||
|
|
@ -425,6 +439,9 @@ GEM
|
|||
typhoeus (0.3.3)
|
||||
mime-types
|
||||
tzinfo (0.3.32)
|
||||
uglifier (1.2.3)
|
||||
execjs (>= 0.3.0)
|
||||
multi_json (>= 1.0.2)
|
||||
unicorn (4.2.0)
|
||||
kgio (~> 2.6)
|
||||
rack
|
||||
|
|
@ -486,6 +503,7 @@ DEPENDENCIES
|
|||
i18n-inflector-rails (~> 1.0)
|
||||
jammit-s3
|
||||
jasmine (~> 1.1.2)
|
||||
jquery-rails
|
||||
json
|
||||
jwt
|
||||
linecache (= 0.46)
|
||||
|
|
@ -528,6 +546,7 @@ DEPENDENCIES
|
|||
ruby-debug19
|
||||
ruby-oembed (~> 0.8.7)
|
||||
sass
|
||||
sass-rails
|
||||
selenium-webdriver (~> 2.16.0)
|
||||
settingslogic!
|
||||
sqlite3
|
||||
|
|
@ -535,6 +554,7 @@ DEPENDENCIES
|
|||
timecop
|
||||
twitter (= 2.0.2)
|
||||
typhoeus
|
||||
uglifier
|
||||
unicorn (~> 4.2.0)
|
||||
webmock
|
||||
whenever
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// licensed under the Affero General Public License version 3 or later. See
|
||||
// the COPYRIGHT file.
|
||||
//= require_self
|
||||
//= require ui
|
||||
|
||||
@import 'mixins'
|
||||
@import '_mixins.css.scss'
|
||||
|
||||
/* ====== media ====== */
|
||||
.media
|
||||
|
|
@ -684,7 +684,7 @@ form p.checkbox_select
|
|||
*:-moz-placeholder
|
||||
@include placeholder_styles
|
||||
|
||||
#file-upload
|
||||
#file-upload
|
||||
input
|
||||
:height 100%
|
||||
:width 100%
|
||||
|
|
@ -777,7 +777,7 @@ form p.checkbox_select
|
|||
:position absolute !important
|
||||
:right 6px
|
||||
:cursor pointer
|
||||
|
||||
|
||||
|
||||
input[type='file']
|
||||
:cursor pointer
|
||||
3
app/assets/stylesheets/blueprint.css
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
/*
|
||||
//= require vendor/blueprint/screen
|
||||
*/
|
||||
4
app/assets/stylesheets/bootstrap.css
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
/*
|
||||
*= require vendor/bootstrap
|
||||
*= require vendor/bootstrap-responsive
|
||||
*/
|
||||
14
app/assets/stylesheets/default.css
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
*= require media-box
|
||||
*= require loader
|
||||
*= require lightbox
|
||||
*= require autocomplete
|
||||
*= require mentions
|
||||
*= require tags
|
||||
*= require hovercard
|
||||
|
||||
*= require vendor/interim-bootstrap
|
||||
*= require vendor/facebox
|
||||
*= require vendor/fileuploader
|
||||
*= require vendor/autoSuggest
|
||||
*/
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
@import "mixins";
|
||||
@import "_mixins.css.scss";
|
||||
|
||||
#hovercard {
|
||||
@include border-radius(2px);
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// licensed under the Affero General Public License version 3 or later. See
|
||||
// the COPYRIGHT file.
|
||||
|
||||
@import 'mixins';
|
||||
@import '_mixins.css.scss';
|
||||
|
||||
#lightbox{
|
||||
z-index: 1003;
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
//= require_self
|
||||
|
||||
// Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||
// licensed under the Affero General Public License version 3 or later. See
|
||||
// the COPYRIGHT file.
|
||||
|
||||
@import "mixins";
|
||||
@import "_mixins.css.scss";
|
||||
|
||||
#login {
|
||||
width: 400px;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
@import 'mixins';
|
||||
@import '_mixins.css.scss';
|
||||
|
||||
.mentions-input-box {
|
||||
background: #fff;
|
||||
|
|
@ -1,4 +1,8 @@
|
|||
@import "mixins";
|
||||
//= require_self
|
||||
//= require vendor/bootstrap
|
||||
//= require vendor/bootstrap-responsive
|
||||
|
||||
@import "_mixins.css.scss";
|
||||
|
||||
$blue: #3f8fba;
|
||||
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
/* variables */
|
||||
//= require_self
|
||||
|
||||
/* variables */
|
||||
$light-grey: #999;
|
||||
$pane-width: 420px;
|
||||
|
||||
|
|
@ -808,4 +809,4 @@ text-rendering: optimizelegibility;
|
|||
|
||||
.headline p{
|
||||
@include media-text();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
//= require_self
|
||||
|
||||
body
|
||||
:direction rtl
|
||||
:text-align right
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// licensed under the Affero General Public License version 3 or later. See
|
||||
// the COPYRIGHT file.
|
||||
|
||||
@import 'mixins'
|
||||
@import '_mixins.css.scss'
|
||||
|
||||
$button-border-color: #aaa
|
||||
|
||||
|
Before Width: | Height: | Size: 43 B After Width: | Height: | Size: 43 B |
|
Before Width: | Height: | Size: 655 B After Width: | Height: | Size: 655 B |
|
Before Width: | Height: | Size: 455 B After Width: | Height: | Size: 455 B |
|
Before Width: | Height: | Size: 537 B After Width: | Height: | Size: 537 B |
|
Before Width: | Height: | Size: 777 B After Width: | Height: | Size: 777 B |
|
Before Width: | Height: | Size: 641 B After Width: | Height: | Size: 641 B |
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 691 B After Width: | Height: | Size: 691 B |
|
Before Width: | Height: | Size: 741 B After Width: | Height: | Size: 741 B |
|
Before Width: | Height: | Size: 591 B After Width: | Height: | Size: 591 B |
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 663 B After Width: | Height: | Size: 663 B |
|
Before Width: | Height: | Size: 132 B After Width: | Height: | Size: 132 B |
|
Before Width: | Height: | Size: 503 B After Width: | Height: | Size: 503 B |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
|
|
@ -35,11 +35,4 @@ module ApplicationHelper
|
|||
def diaspora_id_host
|
||||
User.diaspora_id_host
|
||||
end
|
||||
|
||||
def jquery_include_tag
|
||||
"<script src='//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' type='text/javascript'></script>".html_safe +
|
||||
content_tag(:script) do
|
||||
"!window.jQuery && document.write(unescape(\"#{escape_javascript(include_javascripts(:jquery))}\")); jQuery.ajaxSetup({'cache': false});".html_safe
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -61,9 +61,9 @@ module LayoutHelper
|
|||
|
||||
def include_base_css_framework(use_bootstrap=false)
|
||||
if use_bootstrap || @aspect == :getting_started || @page == :logged_out
|
||||
include_stylesheets :bootstrap
|
||||
stylesheet_link_tag 'bootstrap'
|
||||
else
|
||||
include_stylesheets :blueprint, :media => 'screen'
|
||||
stylesheet_link_tag 'blueprint', :media => 'screen'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -19,8 +19,7 @@
|
|||
= page_title yield(:page_title)
|
||||
|
||||
= include_base_css_framework
|
||||
= include_stylesheets :login, :media => 'screen'
|
||||
= include_stylesheets :application, :default, :media => 'all'
|
||||
= stylesheet_link_tag 'login', 'application', 'default'
|
||||
|
||||
- if rtl?
|
||||
= include_stylesheets :rtl, :media => 'all'
|
||||
|
|
@ -30,7 +29,8 @@
|
|||
= include_javascripts :ie
|
||||
<![endif]-->
|
||||
|
||||
= jquery_include_tag
|
||||
= javascript_include_tag 'jquery', 'jquery_ujs'
|
||||
|
||||
- unless @landing_page
|
||||
= include_javascripts :main, :templates
|
||||
= load_javascript_locales
|
||||
|
|
|
|||
|
|
@ -63,5 +63,8 @@ module Diaspora
|
|||
config.filter_parameters += [:text]
|
||||
config.filter_parameters += [:bio]
|
||||
|
||||
# Enable the asset pipeline
|
||||
config.assets.enabled = true
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,14 +2,12 @@ package_assets: on
|
|||
embed_assets: datauri
|
||||
compress_assets: on
|
||||
gzip_assets: off
|
||||
package_path: jammit
|
||||
|
||||
template_function: Handlebars.compile
|
||||
template_extension: 'handlebars'
|
||||
|
||||
javascripts:
|
||||
jquery:
|
||||
- public/javascripts/vendor/jquery-1.7.1.min.js
|
||||
|
||||
templates:
|
||||
- public/javascripts/app/templates/*.handlebars
|
||||
- public/javascripts/app/templates/**/*.handlebars
|
||||
|
|
@ -111,43 +109,3 @@ javascripts:
|
|||
- public/javascripts/vendor/jquery.autoSuggest.custom.js
|
||||
ie:
|
||||
- public/javascripts/ie.js
|
||||
|
||||
stylesheets:
|
||||
bootstrap:
|
||||
- public/stylesheets/bootstrap-responsive.css
|
||||
- public/stylesheets/bootstrap.css
|
||||
|
||||
blueprint:
|
||||
- public/stylesheets/blueprint/screen.css
|
||||
|
||||
login:
|
||||
- public/stylesheets/login.css
|
||||
|
||||
default:
|
||||
- public/stylesheets/media-box.css
|
||||
- public/stylesheets/loader.css
|
||||
- public/stylesheets/lightbox.css
|
||||
- public/stylesheets/autocomplete.css
|
||||
- public/stylesheets/mentions.css
|
||||
- public/stylesheets/tags.css
|
||||
- public/stylesheets/hovercard.css
|
||||
- public/stylesheets/vendor/facebox.css
|
||||
- public/stylesheets/vendor/fileuploader.css
|
||||
- public/stylesheets/vendor/autoSuggest.css
|
||||
- public/stylesheets/interim-bootstrap.css
|
||||
|
||||
application:
|
||||
- public/stylesheets/application.css
|
||||
- public/stylesheets/ui.css
|
||||
|
||||
new_templates:
|
||||
- public/stylesheets/new-templates.css
|
||||
|
||||
rtl:
|
||||
- public/stylesheets/rtl.css
|
||||
|
||||
mobile:
|
||||
- public/stylesheets/bootstrap2.css
|
||||
- public/stylesheets/bootstrap-responsive.css
|
||||
- public/stylesheets/mobile.css
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,12 @@ Diaspora::Application.configure do
|
|||
config.consider_all_requests_local = true
|
||||
config.action_controller.perform_caching = false
|
||||
|
||||
|
||||
# Do not compress assets
|
||||
config.assets.compress = false
|
||||
|
||||
# Expands the lines which load the assets
|
||||
config.assets.debug = true
|
||||
|
||||
# Don't care if the mailer can't send
|
||||
config.action_mailer.raise_delivery_errors = false
|
||||
config.active_support.deprecation = [:stderr, :log]
|
||||
|
|
|
|||
|
|
@ -46,10 +46,17 @@ Diaspora::Application.configure do
|
|||
# Disable delivery errors, bad email addresses will be ignored
|
||||
# config.action_mailer.raise_delivery_errors = false
|
||||
|
||||
# Compress JavaScript and CSS
|
||||
config.assets.compress = true
|
||||
|
||||
# Don't fallback to assets pipeline
|
||||
config.assets.compile = false
|
||||
|
||||
# Generate digests for assets URLs
|
||||
config.assets.digest = true
|
||||
|
||||
config.threadsafe!
|
||||
end
|
||||
|
||||
# Sacrifice readability for a 10% performance boost
|
||||
Haml::Template::options[:ugly] = true
|
||||
GC.enable_stats if GC.respond_to?(:enable_stats)
|
||||
GC::Profiler.enable if defined?(GC::Profiler) && GC::Profiler.respond_to?(:enable)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,13 @@ Diaspora::Application.configure do
|
|||
config.action_mailer.delivery_method = :test
|
||||
config.active_support.deprecation = :stderr
|
||||
|
||||
# Configure static asset server for tests with Cache-Control for performance
|
||||
config.serve_static_assets = true
|
||||
config.static_cache_control = "public, max-age=3600"
|
||||
|
||||
# Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets
|
||||
config.assets.allow_debugging = true
|
||||
|
||||
# fixes url helper issue in rspec
|
||||
#config.threadsafe!
|
||||
|
||||
|
|
|
|||
18
public/javascripts/clear-form.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* Clear form plugin - called using $("elem").clearForm(); */
|
||||
$.fn.clearForm = function() {
|
||||
return this.each(function() {
|
||||
if ($(this).is('form')) {
|
||||
return $(':input', this).clearForm();
|
||||
}
|
||||
if ($(this).hasClass('clear_on_submit') || $(this).is(':text') || $(this).is(':password') || $(this).is('textarea')) {
|
||||
$(this).val('');
|
||||
} else if ($(this).is(':checkbox') || $(this).is(':radio')) {
|
||||
$(this).attr('checked', false);
|
||||
} else if ($(this).is('select')) {
|
||||
this.selectedIndex = -1;
|
||||
} else if ($(this).attr('name') == 'photos[]') {
|
||||
$(this).val('');
|
||||
}
|
||||
$(this).blur();
|
||||
});
|
||||
};
|
||||
|
|
@ -1,373 +0,0 @@
|
|||
(function($, undefined) {
|
||||
|
||||
/**
|
||||
* Unobtrusive scripting adapter for jQuery
|
||||
*
|
||||
* Requires jQuery 1.6.0 or later.
|
||||
* https://github.com/rails/jquery-ujs
|
||||
|
||||
* Uploading file using rails.js
|
||||
* =============================
|
||||
*
|
||||
* By default, browsers do not allow files to be uploaded via AJAX. As a result, if there are any non-blank file fields
|
||||
* in the remote form, this adapter aborts the AJAX submission and allows the form to submit through standard means.
|
||||
*
|
||||
* The `ajax:aborted:file` event allows you to bind your own handler to process the form submission however you wish.
|
||||
*
|
||||
* Ex:
|
||||
* $('form').live('ajax:aborted:file', function(event, elements){
|
||||
* // Implement own remote file-transfer handler here for non-blank file inputs passed in `elements`.
|
||||
* // Returning false in this handler tells rails.js to disallow standard form submission
|
||||
* return false;
|
||||
* });
|
||||
*
|
||||
* The `ajax:aborted:file` event is fired when a file-type input is detected with a non-blank value.
|
||||
*
|
||||
* Third-party tools can use this hook to detect when an AJAX file upload is attempted, and then use
|
||||
* techniques like the iframe method to upload the file instead.
|
||||
*
|
||||
* Required fields in rails.js
|
||||
* ===========================
|
||||
*
|
||||
* If any blank required inputs (required="required") are detected in the remote form, the whole form submission
|
||||
* is canceled. Note that this is unlike file inputs, which still allow standard (non-AJAX) form submission.
|
||||
*
|
||||
* The `ajax:aborted:required` event allows you to bind your own handler to inform the user of blank required inputs.
|
||||
*
|
||||
* !! Note that Opera does not fire the form's submit event if there are blank required inputs, so this event may never
|
||||
* get fired in Opera. This event is what causes other browsers to exhibit the same submit-aborting behavior.
|
||||
*
|
||||
* Ex:
|
||||
* $('form').live('ajax:aborted:required', function(event, elements){
|
||||
* // Returning false in this handler tells rails.js to submit the form anyway.
|
||||
* // The blank required inputs are passed to this function in `elements`.
|
||||
* return ! confirm("Would you like to submit the form with missing info?");
|
||||
* });
|
||||
*/
|
||||
|
||||
// Shorthand to make it a little easier to call public rails functions from within rails.js
|
||||
var rails;
|
||||
|
||||
$.rails = rails = {
|
||||
// Link elements bound by jquery-ujs
|
||||
linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]',
|
||||
|
||||
// Select elements bound by jquery-ujs
|
||||
inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
|
||||
|
||||
// Form elements bound by jquery-ujs
|
||||
formSubmitSelector: 'form',
|
||||
|
||||
// Form input elements bound by jquery-ujs
|
||||
formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not(button[type])',
|
||||
|
||||
// Form input elements disabled during form submission
|
||||
disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]',
|
||||
|
||||
// Form input elements re-enabled after form submission
|
||||
enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled',
|
||||
|
||||
// Form required input elements
|
||||
requiredInputSelector: 'input[name][required]:not([disabled]),textarea[name][required]:not([disabled])',
|
||||
|
||||
// Form file input elements
|
||||
fileInputSelector: 'input:file',
|
||||
|
||||
// Link onClick disable selector with possible reenable after remote submission
|
||||
linkDisableSelector: 'a[data-disable-with]',
|
||||
|
||||
// Make sure that every Ajax request sends the CSRF token
|
||||
CSRFProtection: function(xhr) {
|
||||
var token = $('meta[name="csrf-token"]').attr('content');
|
||||
if (token) xhr.setRequestHeader('X-CSRF-Token', token);
|
||||
},
|
||||
|
||||
// Triggers an event on an element and returns false if the event result is false
|
||||
fire: function(obj, name, data) {
|
||||
var event = $.Event(name);
|
||||
obj.trigger(event, data);
|
||||
return event.result !== false;
|
||||
},
|
||||
|
||||
// Default confirm dialog, may be overridden with custom confirm dialog in $.rails.confirm
|
||||
confirm: function(message) {
|
||||
return confirm(message);
|
||||
},
|
||||
|
||||
// Default ajax function, may be overridden with custom function in $.rails.ajax
|
||||
ajax: function(options) {
|
||||
return $.ajax(options);
|
||||
},
|
||||
|
||||
// Submits "remote" forms and links with ajax
|
||||
handleRemote: function(element) {
|
||||
var method, url, data,
|
||||
crossDomain = element.data('cross-domain') || null,
|
||||
dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType),
|
||||
options;
|
||||
|
||||
if (rails.fire(element, 'ajax:before')) {
|
||||
|
||||
if (element.is('form')) {
|
||||
method = element.attr('method');
|
||||
url = element.attr('action');
|
||||
data = element.serializeArray();
|
||||
// memoized value from clicked submit button
|
||||
var button = element.data('ujs:submit-button');
|
||||
if (button) {
|
||||
data.push(button);
|
||||
element.data('ujs:submit-button', null);
|
||||
}
|
||||
} else if (element.is(rails.inputChangeSelector)) {
|
||||
method = element.data('method');
|
||||
url = element.data('url');
|
||||
data = element.serialize();
|
||||
if (element.data('params')) data = data + "&" + element.data('params');
|
||||
} else {
|
||||
method = element.data('method');
|
||||
url = element.attr('href');
|
||||
data = element.data('params') || null;
|
||||
}
|
||||
|
||||
options = {
|
||||
type: method || 'GET', data: data, dataType: dataType, crossDomain: crossDomain,
|
||||
// stopping the "ajax:beforeSend" event will cancel the ajax request
|
||||
beforeSend: function(xhr, settings) {
|
||||
if (settings.dataType === undefined) {
|
||||
xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
|
||||
}
|
||||
return rails.fire(element, 'ajax:beforeSend', [xhr, settings]);
|
||||
},
|
||||
success: function(data, status, xhr) {
|
||||
element.trigger('ajax:success', [data, status, xhr]);
|
||||
},
|
||||
complete: function(xhr, status) {
|
||||
element.trigger('ajax:complete', [xhr, status]);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
element.trigger('ajax:error', [xhr, status, error]);
|
||||
}
|
||||
};
|
||||
// Only pass url to `ajax` options if not blank
|
||||
if (url) { options.url = url; }
|
||||
|
||||
return rails.ajax(options);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
// Handles "data-method" on links such as:
|
||||
// <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
|
||||
handleMethod: function(link) {
|
||||
var href = link.attr('href'),
|
||||
method = link.data('method'),
|
||||
target = link.attr('target'),
|
||||
csrf_token = $('meta[name=csrf-token]').attr('content'),
|
||||
csrf_param = $('meta[name=csrf-param]').attr('content'),
|
||||
form = $('<form method="post" action="' + href + '"></form>'),
|
||||
metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
|
||||
|
||||
if (csrf_param !== undefined && csrf_token !== undefined) {
|
||||
metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
|
||||
}
|
||||
|
||||
if (target) { form.attr('target', target); }
|
||||
|
||||
form.hide().append(metadata_input).appendTo('body');
|
||||
form.submit();
|
||||
},
|
||||
|
||||
/* Disables form elements:
|
||||
- Caches element value in 'ujs:enable-with' data store
|
||||
- Replaces element text with value of 'data-disable-with' attribute
|
||||
- Sets disabled property to true
|
||||
*/
|
||||
disableFormElements: function(form) {
|
||||
form.find(rails.disableSelector).each(function() {
|
||||
var element = $(this), method = element.is('button') ? 'html' : 'val';
|
||||
element.data('ujs:enable-with', element[method]());
|
||||
element[method](element.data('disable-with'));
|
||||
element.prop('disabled', true);
|
||||
});
|
||||
},
|
||||
|
||||
/* Re-enables disabled form elements:
|
||||
- Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`)
|
||||
- Sets disabled property to false
|
||||
*/
|
||||
enableFormElements: function(form) {
|
||||
form.find(rails.enableSelector).each(function() {
|
||||
var element = $(this), method = element.is('button') ? 'html' : 'val';
|
||||
if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with'));
|
||||
element.prop('disabled', false);
|
||||
});
|
||||
},
|
||||
|
||||
/* For 'data-confirm' attribute:
|
||||
- Fires `confirm` event
|
||||
- Shows the confirmation dialog
|
||||
- Fires the `confirm:complete` event
|
||||
|
||||
Returns `true` if no function stops the chain and user chose yes; `false` otherwise.
|
||||
Attaching a handler to the element's `confirm` event that returns a `falsy` value cancels the confirmation dialog.
|
||||
Attaching a handler to the element's `confirm:complete` event that returns a `falsy` value makes this function
|
||||
return false. The `confirm:complete` event is fired whether or not the user answered true or false to the dialog.
|
||||
*/
|
||||
allowAction: function(element) {
|
||||
var message = element.data('confirm'),
|
||||
answer = false, callback;
|
||||
if (!message) { return true; }
|
||||
|
||||
if (rails.fire(element, 'confirm')) {
|
||||
answer = rails.confirm(message);
|
||||
callback = rails.fire(element, 'confirm:complete', [answer]);
|
||||
}
|
||||
return answer && callback;
|
||||
},
|
||||
|
||||
// Helper function which checks for blank inputs in a form that match the specified CSS selector
|
||||
blankInputs: function(form, specifiedSelector, nonBlank) {
|
||||
var inputs = $(), input,
|
||||
selector = specifiedSelector || 'input,textarea';
|
||||
form.find(selector).each(function() {
|
||||
input = $(this);
|
||||
// Collect non-blank inputs if nonBlank option is true, otherwise, collect blank inputs
|
||||
if (nonBlank ? input.val() : !input.val()) {
|
||||
inputs = inputs.add(input);
|
||||
}
|
||||
});
|
||||
return inputs.length ? inputs : false;
|
||||
},
|
||||
|
||||
// Helper function which checks for non-blank inputs in a form that match the specified CSS selector
|
||||
nonBlankInputs: function(form, specifiedSelector) {
|
||||
return rails.blankInputs(form, specifiedSelector, true); // true specifies nonBlank
|
||||
},
|
||||
|
||||
// Helper function, needed to provide consistent behavior in IE
|
||||
stopEverything: function(e) {
|
||||
$(e.target).trigger('ujs:everythingStopped');
|
||||
e.stopImmediatePropagation();
|
||||
return false;
|
||||
},
|
||||
|
||||
// find all the submit events directly bound to the form and
|
||||
// manually invoke them. If anyone returns false then stop the loop
|
||||
callFormSubmitBindings: function(form, event) {
|
||||
var events = form.data('events'), continuePropagation = true;
|
||||
if (events !== undefined && events['submit'] !== undefined) {
|
||||
$.each(events['submit'], function(i, obj){
|
||||
if (typeof obj.handler === 'function') return continuePropagation = obj.handler(event);
|
||||
});
|
||||
}
|
||||
return continuePropagation;
|
||||
},
|
||||
|
||||
// replace element's html with the 'data-disable-with' after storing original html
|
||||
// and prevent clicking on it
|
||||
disableElement: function(element) {
|
||||
element.data('ujs:enable-with', element.html()); // store enabled state
|
||||
element.html(element.data('disable-with')); // set to disabled state
|
||||
element.bind('click.railsDisable', function(e) { // prevent further clicking
|
||||
return rails.stopEverything(e)
|
||||
});
|
||||
},
|
||||
|
||||
// restore element to its original state which was disabled by 'disableElement' above
|
||||
enableElement: function(element) {
|
||||
if (element.data('ujs:enable-with') !== undefined) {
|
||||
element.html(element.data('ujs:enable-with')); // set to old enabled state
|
||||
// this should be element.removeData('ujs:enable-with')
|
||||
// but, there is currently a bug in jquery which makes hyphenated data attributes not get removed
|
||||
element.data('ujs:enable-with', false); // clean up cache
|
||||
}
|
||||
element.unbind('click.railsDisable'); // enable element
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }});
|
||||
|
||||
$(document).delegate(rails.linkDisableSelector, 'ajax:complete', function() {
|
||||
rails.enableElement($(this));
|
||||
});
|
||||
|
||||
$(document).delegate(rails.linkClickSelector, 'click.rails', function(e) {
|
||||
var link = $(this), method = link.data('method'), data = link.data('params');
|
||||
if (!rails.allowAction(link)) return rails.stopEverything(e);
|
||||
|
||||
if (link.is(rails.linkDisableSelector)) rails.disableElement(link);
|
||||
|
||||
if (link.data('remote') !== undefined) {
|
||||
if ( (e.metaKey || e.ctrlKey) && (!method || method === 'GET') && !data ) { return true; }
|
||||
|
||||
if (rails.handleRemote(link) === false) { rails.enableElement(link); }
|
||||
return false;
|
||||
|
||||
} else if (link.data('method')) {
|
||||
rails.handleMethod(link);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
$(document).delegate(rails.inputChangeSelector, 'change.rails', function(e) {
|
||||
var link = $(this);
|
||||
if (!rails.allowAction(link)) return rails.stopEverything(e);
|
||||
|
||||
rails.handleRemote(link);
|
||||
return false;
|
||||
});
|
||||
|
||||
$(document).delegate(rails.formSubmitSelector, 'submit.rails', function(e) {
|
||||
var form = $(this),
|
||||
remote = form.data('remote') !== undefined,
|
||||
blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector),
|
||||
nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
|
||||
|
||||
if (!rails.allowAction(form)) return rails.stopEverything(e);
|
||||
|
||||
// skip other logic when required values are missing or file upload is present
|
||||
if (blankRequiredInputs && form.attr("novalidate") == undefined && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
|
||||
return rails.stopEverything(e);
|
||||
}
|
||||
|
||||
if (remote) {
|
||||
if (nonBlankFileInputs) {
|
||||
return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
|
||||
}
|
||||
|
||||
// If browser does not support submit bubbling, then this live-binding will be called before direct
|
||||
// bindings. Therefore, we should directly call any direct bindings before remotely submitting form.
|
||||
if (!$.support.submitBubbles && $().jquery < '1.7' && rails.callFormSubmitBindings(form, e) === false) return rails.stopEverything(e);
|
||||
|
||||
rails.handleRemote(form);
|
||||
return false;
|
||||
|
||||
} else {
|
||||
// slight timeout so that the submit button gets properly serialized
|
||||
setTimeout(function(){ rails.disableFormElements(form); }, 13);
|
||||
}
|
||||
});
|
||||
|
||||
$(document).delegate(rails.formInputClickSelector, 'click.rails', function(event) {
|
||||
var button = $(this);
|
||||
|
||||
if (!rails.allowAction(button)) return rails.stopEverything(event);
|
||||
|
||||
// register the pressed submit button
|
||||
var name = button.attr('name'),
|
||||
data = name ? {name:name, value:button.val()} : null;
|
||||
|
||||
button.closest('form').data('ujs:submit-button', data);
|
||||
});
|
||||
|
||||
$(document).delegate(rails.formSubmitSelector, 'ajax:beforeSend.rails', function(event) {
|
||||
if (this == event.target) rails.disableFormElements($(this));
|
||||
});
|
||||
|
||||
$(document).delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) {
|
||||
if (this == event.target) rails.enableFormElements($(this));
|
||||
});
|
||||
|
||||
})( jQuery );
|
||||