Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to latest 1.18.x version of jquery.autosize #608

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
source 'https://rubygems.org'
source 'https://rails-assets.org'

# Specify your gem's dependencies in best_in_place.gemspec
gemspec

gem 'activerecord'
gem "rails", github: "rails/rails"
gem 'rails-assets-jquery', '1.11.1'
gem 'rails-assets-jquery-ui', '1.10.4'
gem 'rdiscount'
gem 'rspec-rails'
gem 'nokogiri'
gem 'combustion'
gem 'sprockets-rails'
gem "sprockets", "~> 3"
gem 'sprockets-rails', "~> 3"
gem 'capybara'
gem 'poltergeist'
gem 'sqlite3'
Expand Down
6 changes: 5 additions & 1 deletion lib/best_in_place.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
require 'action_controller/railtie'

module BestInPlace
def self.deprecator
@deprecator ||= ActiveSupport::Deprecation.new("1.0", "BestInPlace")
end

def self.configure
@configuration ||= Configuration.new
yield @configuration if block_given?
Expand Down Expand Up @@ -30,4 +34,4 @@ def initialize
require 'best_in_place/helper'
require 'best_in_place/railtie'
require 'best_in_place/controller_extensions'
require 'best_in_place/display_methods'
require 'best_in_place/display_methods'
6 changes: 3 additions & 3 deletions lib/best_in_place/display_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ def lookup(klass, attr)
end

def add_model_method(klass, attr, display_as)
model_attributes(klass)[attr.to_s] = Renderer.new method: display_as.to_sym, type: :model
model_attributes(klass)[attr.to_s] = Renderer.new({ method: display_as.to_sym, type: :model })
end

def add_helper_method(klass, attr, helper_method, helper_options = nil)
model_attributes(klass)[attr.to_s] = Renderer.new method: helper_method.to_sym, type: :helper, attr: attr, helper_options: helper_options
model_attributes(klass)[attr.to_s] = Renderer.new({ method: helper_method.to_sym, type: :helper, attr: attr, helper_options: helper_options })
end

def add_helper_proc(klass, attr, helper_proc)
model_attributes(klass)[attr.to_s] = Renderer.new type: :proc, attr: attr, proc: helper_proc
model_attributes(klass)[attr.to_s] = Renderer.new({ type: :proc, attr: attr, proc: helper_proc })
end

def model_attributes(klass)
Expand Down
6 changes: 4 additions & 2 deletions lib/best_in_place/engine.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module BestInPlace
class Engine < Rails::Engine
initializer 'best_in_place' do
ActionView::Base.send(:include, BestInPlace::Helper)
ActionController::Base.send(:include, BestInPlace::ControllerExtensions)
ActiveSupport.on_load(:action_controller) do
ActionView::Base.send(:include, BestInPlace::Helper)
ActionController::Base.send(:include, BestInPlace::ControllerExtensions)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/best_in_place/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def best_in_place_deprecated_options(opts)
deprecations.each do |deprecation|
if deprecated_option = opts.delete(deprecation[:from])
opts[deprecation[:from]] = deprecated_option
ActiveSupport::Deprecation.warn("[Best_in_place] :#{deprecation[:from]} is deprecated in favor of :#{deprecation[:to]} ")
BestInPlace.deprecator.warn("[Best_in_place] :#{deprecation[:from]} is deprecated in favor of :#{deprecation[:to]} ")
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion lib/best_in_place/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
module BestInPlace
class Railtie < ::Rails::Railtie #:nodoc:
config.after_initialize do
BestInPlace::ViewHelpers = ActionView::Base.new
BestInPlace::ViewHelpers = ActionView::Base.respond_to?(:empty) ? ActionView::Base.empty : ActionView::Base.new
end

initializer "best_in_place.deprecator" do |app|
app.deprecators[:best_in_place] = BestInPlace.deprecator if app.respond_to?(:deprecators)
end
end
end
2 changes: 1 addition & 1 deletion spec/helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
end

it "should show deprecation warning" do
expect(ActiveSupport::Deprecation).to receive(:warn).with("[Best_in_place] :path is deprecated in favor of :url ")
expect(BestInPlace.deprecator).to receive(:warn).with("[Best_in_place] :path is deprecated in favor of :url ")

helper.best_in_place @user, :name, path: "http://example.com"
end
Expand Down
71 changes: 36 additions & 35 deletions vendor/assets/javascripts/jquery.autosize.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/*!
Autosize v1.18.9 - 2014-05-27
Automatically adjust textarea height based on user input.
(c) 2014 Jack Moore - http://www.jacklmoore.com/autosize
license: http://www.opensource.org/licenses/mit-license.php
Autosize 1.18.18
license: MIT
http://www.jacklmoore.com/autosize
*/
(function ($) {
'use strict';
var defaults = {
var
defaults = {
className: 'autosizejs',
id: 'autosizejs',
append: '\n',
Expand All @@ -15,9 +14,6 @@
placeholder: true
},

// border:0 is unnecessary, but avoids a bug in Firefox on OSX
copy = '<textarea tabindex="-1" style="position:absolute; top:-999px; left:0; right:auto; bottom:auto; border:0; padding: 0; -moz-box-sizing:content-box; -webkit-box-sizing:content-box; box-sizing:content-box; word-wrap:break-word; height:0 !important; min-height:0 !important; overflow:hidden; transition:none; -webkit-transition:none; -moz-transition:none;"/>',

// line-height is conditionally included because IE7/IE8/old Opera do not return the correct value.
typographyStyles = [
'fontFamily',
Expand All @@ -27,14 +23,18 @@
'letterSpacing',
'textTransform',
'wordSpacing',
'textIndent'
'textIndent',
'whiteSpace'
],

// to keep track which textarea is being mirrored when adjust() is called.
mirrored,

// the mirror element, which is used to calculate what size the mirrored element should be.
mirror = $(copy).data('autosize', true)[0];
mirror = $('<textarea tabindex="-1"/>').data('autosize', true)[0];

// border:0 is unnecessary, but avoids a bug in Firefox on OSX
mirror.style.cssText = "position:absolute; top:-999px; left:0; right:auto; bottom:auto; border:0; padding: 0; -moz-box-sizing:content-box; -webkit-box-sizing:content-box; box-sizing:content-box; word-wrap:break-word; height:0 !important; min-height:0 !important; overflow:hidden; transition:none; -webkit-transition:none; -moz-transition:none;";

// test that line-height can be accurately copied.
mirror.style.lineHeight = '99px';
Expand Down Expand Up @@ -84,7 +84,7 @@
}

// IE8 and lower return 'auto', which parses to NaN, if no min-height is set.
minHeight = Math.max(parseInt($ta.css('minHeight'), 10) - boxOffset || 0, $ta.height());
minHeight = Math.max(parseFloat($ta.css('minHeight')) - boxOffset || 0, $ta.height());

$ta.css({
overflow: 'hidden',
Expand All @@ -98,23 +98,18 @@
$ta.css('resize', 'horizontal');
}

// The mirror width must exactly match the textarea width, so using getBoundingClientRect because it doesn't round the sub-pixel value.
// window.getComputedStyle, getBoundingClientRect returning a width are unsupported, but also unneeded in IE8 and lower.
// getComputedStyle is preferred here because it preserves sub-pixel values, while jQuery's .width() rounds to an integer.
function setWidth() {
var width;
var style = window.getComputedStyle ? window.getComputedStyle(ta, null) : false;

if (style) {

width = ta.getBoundingClientRect().width;
var style = window.getComputedStyle ? window.getComputedStyle(ta, null) : null;

if (width === 0 || typeof width !== 'number') {
width = parseInt(style.width,10);
if (style) {
width = parseFloat(style.width);
if (style.boxSizing === 'border-box' || style.webkitBoxSizing === 'border-box' || style.mozBoxSizing === 'border-box') {
$.each(['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth'], function(i,val){
width -= parseFloat(style[val]);
});
}

$.each(['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth'], function(i,val){
width -= parseInt(style[val],10);
});
} else {
width = $ta.width();
}
Expand All @@ -128,7 +123,7 @@
mirrored = ta;
mirror.className = options.className;
mirror.id = options.id;
maxHeight = parseInt($ta.css('maxHeight'), 10);
maxHeight = parseFloat($ta.css('maxHeight'));

// mirror is a duplicate textarea located off-screen that
// is automatically updated to contain the same text as the
Expand All @@ -138,7 +133,7 @@
$.each(typographyStyles, function(i,val){
styles[val] = $ta.css(val);
});

$(mirror).css(styles).attr('wrap', $ta.attr('wrap'));

setWidth();
Expand All @@ -157,7 +152,7 @@
// Using mainly bare JS in this function because it is going
// to fire very often while typing, and needs to very efficient.
function adjust() {
var height, original;
var height, originalHeight;

if (mirrored !== ta) {
initMirror();
Expand All @@ -166,16 +161,17 @@
}

if (!ta.value && options.placeholder) {
// If the textarea is empty, copy the placeholder text into
// the mirror control and use that for sizing so that we
// If the textarea is empty, copy the placeholder text into
// the mirror control and use that for sizing so that we
// don't end up with placeholder getting trimmed.
mirror.value = ($ta.attr("placeholder") || '') + options.append;
mirror.value = ($ta.attr("placeholder") || '');
} else {
mirror.value = ta.value + options.append;
mirror.value = ta.value;
}

mirror.value += options.append || '';
mirror.style.overflowY = ta.style.overflowY;
original = parseInt(ta.style.height,10);
originalHeight = parseFloat(ta.style.height) || 0;

// Setting scrollTop to zero is needed in IE8 and lower for the next step to be accurately applied
mirror.scrollTop = 0;
Expand All @@ -197,11 +193,16 @@

height += boxOffset;

if (original !== height) {
if (Math.abs(originalHeight - height) > 1/100) {
ta.style.height = height + 'px';

// Trigger a repaint for IE8 for when ta is nested 2 or more levels inside an inline-block
mirror.className = mirror.className;

if (callback) {
options.callback.call(ta,ta);
}
$ta.trigger('autosize.resized');
}
}

Expand Down Expand Up @@ -269,4 +270,4 @@
adjust();
});
};
}(window.jQuery || window.$)); // jQuery or jQuery-like library, such as Zepto
}(jQuery || $)); // jQuery or jQuery-like library, such as Zepto