# ------------------------------------------------------------------- # plugins / expanding-input.coffee ### * @class ExpandingInput ### ExpandingInput = ($container, options={}) -> @options = $.extend({}, ExpandingInput.DEFAULTS, options || {}) @$container = $container @$target = if @options.target and @$container.find(@options.target).length then @$container.find(@options.target) else null @$content = if @options.hidden_content and @$container.find(@options.hidden_content).length then @$container.find(@options.hidden_content) else null @$container.addClass('expanding-input') if @$target @$target.addClass('expanding-input-target') @$container.addClass('expanding-input-sm') if @$target.hasClass('input-sm') @$container.addClass('expanding-input-lg') if @$target.hasClass('input-lg') @$content.addClass('expanding-input-content') if @$content @$overlay = $('
').appendTo(@$container) if @$target and @$target.attr('placeholder') @options.placeholder = @$target.attr('placeholder') unless @options.placeholder @$target.attr('placeholder', '') @$overlay.append($('').html(@options.placeholder)) if @options.placeholder @$target.on('focus', $.proxy(@expand, @)) if @$target @$overlay.on('click.expanding_input', $.proxy(@expand, @)) ExpandingInput.prototype.expand = () -> return if @$container.hasClass('expanded') # Run before callback @options.onBeforeExpand.call(@) if @options.onBeforeExpand # Remove overlay @$overlay.remove() # Add class @$container.addClass('expanded') # Focus on input setTimeout(=> @$target.focus() , 1) if @$target @$target.attr('placeholder', $('