All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.butterfaces-js.butterfaces-expandable.jquery.js Maven / Gradle / Ivy

/**
 * jQuery-Plugin "Expanded TextAreas" for expandable text areas. It is used for the JSF-Component "b:textarea".
 * Works with at least jQuery 1.3.2.
 *
 * How to use:
 * jQuery("#someTextAreaSelector").butterExpandable();
 */
(function ($) {
    // extend jQuery --------------------------------------------------------------------
    $.fn.butterExpandable = function () {
        var EXPAND_HEIGHT = 250; //in px
        var EXPAND_WIDTH = 500; //in px
        var ANIMATION_DURATION = 200; //in ms
        var EASING = "swing";

        return this.each(function () {
            var $originalElement = $(this).find("textarea");
            $originalElement.addClass("butter-component-expandable-original");

            //do nothing, if original is not visible
            if (!$originalElement.is(":visible")) {
                // console.log("element is not visible, do nothing");
                return;
            }

            // console.log("element is visible, initialize it");

            var $ghostElement = null;
            var blockBlurEventOnOriginal = true;
            var blockFocusEventOnOriginal = false;
            var initialHeight;
            var initialWidth;
            var initialOffset;
            var positionTriggerInterval;

            var expandElement = function (event) {
                if (blockFocusEventOnOriginal) {
                    event.preventDefault();
                    return;
                }

                // console.log("expanding element");

                blockBlurEventOnOriginal = true;

                initialHeight = $originalElement.outerHeight();
                initialWidth = $originalElement.outerWidth();
                initialOffset = $originalElement.offset();

                //create a ghost element that be animated on gets the focus
                $ghostElement = $("