app/jquery/jquery-growfield.js
author Lennard de Rijk <ljvderijk@gmail.com>
Sun, 28 Jun 2009 17:44:44 +0200
changeset 2439 7fac0da44bbf
parent 2421 0979e7af115f
permissions -rw-r--r--
Put ResultsLogic in its own Logic module named survey_record.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2420
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
     1
/*
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
     2
 * The MIT License
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
     3
 *
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
     4
 * Copyright (c) 2009 Johann Kuindji
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
     5
 *
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
     6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
     7
 * of this software and associated documentation files (the "Software"), to deal
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
     8
 * in the Software without restriction, including without limitation the rights
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
     9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    10
 * copies of the Software, and to permit persons to whom the Software is
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    11
 * furnished to do so, subject to the following conditions:
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    12
 *
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    13
 * The above copyright notice and this permission notice shall be included in
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    14
 * all copies or substantial portions of the Software.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    15
 *
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    22
 * THE SOFTWARE.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    23
 *
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    24
 * @author Johann Kuindji, Dmitriy Likhten
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    25
 * http://code.google.com/p/jquery-growfield/
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    26
 */
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    27
(function($) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    28
if ($.support === undefined) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    29
    $.support = { boxModel: $.boxModel };
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    30
}
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    31
var windowLoaded = false;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    32
$(window).one('load', function(){ windowLoaded=true; });
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    33
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    34
// we need to adapt jquery animations for textareas.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    35
// by default, it changes display to 'block' if we're trying to
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    36
// change width or height. We have to prevent this.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    37
// THIS WILL NOT ALTER JQUERY ORIGINAL BEHAVIORS, IT WILL HOWEVER ADD
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    38
// SOME SO THAT GROWFIELD ANIMATIONS WORK CORRECTLY.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    39
$.fx.prototype.originalUpdate = $.fx.prototype.update;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    40
$.fx.prototype.update = false;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    41
$.fx.prototype.update = function () {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    42
    if (!this.options.inline) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    43
        return this.originalUpdate.call(this);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    44
    }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    45
    if ( this.options.step ) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    46
        this.options.step.call( this.elem, this.now, this );
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    47
    }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    48
    (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    49
};
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    50
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    51
$.growfield = function(dom,options){
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    52
    // Extend ptt(prototype) with our own private variables/
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    53
    // shared's functions are re-referenced and not cloned so
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    54
    // memory is kept at a minimum.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    55
    var that = $.extend({
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    56
        dom: dom,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    57
        o: $(dom),
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    58
        enabled: false,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    59
        dummy: false,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    60
        busy: false,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    61
        initial: false,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    62
        sizseRelated: false,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    63
        prevH: false,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    64
        firstH: false,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    65
        restoreH: false,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    66
        opt: $.extend({},$.fn.growfield.defaults,options)
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    67
    },$.growfield.ptt);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    68
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    69
    return that;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    70
};
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    71
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    72
//-----------------------------------------------------
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    73
// This is the base class for all $.growfield objects
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    74
// (their prototype)
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    75
//-----------------------------------------------------
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    76
$.growfield.ptt = (function(){
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    77
    //-----------------------------------------------------
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    78
    //EVENT HANDLERS for dealing with the growfield object
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    79
    //-----------------------------------------------------
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    80
    var manualKeyUp = function(e) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    81
        var obj = e.data;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    82
        if (e.ctrlKey && (e.keyCode == 38 || e.keyCode == 40)){
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    83
            obj.update(
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    84
                obj.o.outerHeight() + (obj.opt.step*( e.keyCode==38? -1: 1)),
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    85
                obj.opt.animate
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    86
            );
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    87
        }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    88
    };
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    89
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    90
    var keyUp = function(e) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    91
        var obj = e.data;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    92
        if (!obj.busy){
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    93
            if ($.inArray(e.keyCode, [37,38,39,40]) === -1) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    94
                obj.update(obj.getDummyHeight(), obj.opt.animate);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    95
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    96
        }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    97
        return true;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    98
    };
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
    99
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   100
    var focus = function(e) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   101
        var obj = e.data;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   102
        if (!obj.busy) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   103
            if (obj.opt.restore) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   104
                obj.update(obj.dummy ? obj.getDummyHeight() : obj.restoreH, obj.opt.animate, 'growback');
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   105
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   106
        }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   107
    };
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   108
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   109
    var blur = function(e) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   110
        var obj = e.data;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   111
        if (!obj.busy) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   112
            if (obj.opt.restore) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   113
                obj.update(0, obj.opt.animate, 'restore');
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   114
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   115
        }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   116
    };
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   117
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   118
    var prepareSizeRelated = function(e) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   119
        var obj = e.data;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   120
        var o = obj.o;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   121
        var opt = obj.opt;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   122
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   123
        if (!opt.min) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   124
            opt.min = parseInt(o.css('min-height'), 10) || obj.firstH || parseInt(o.height(), 10) || 20;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   125
            if (opt.min <= 0) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   126
                opt.min = 20; // opera fix
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   127
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   128
            if (!obj.firstH) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   129
                obj.firstH = opt.min;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   130
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   131
        }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   132
        if (!opt.max) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   133
            opt.max = parseInt(o.css('max-height'), 10) || false;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   134
            if (opt.max <= 0) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   135
                opt.max = false; // opera fix
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   136
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   137
        }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   138
        if (!opt.step) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   139
            opt.step = parseInt(o.css('line-height'), 10) || parseInt(o.css('font-size'), 10) || 20;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   140
        }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   141
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   142
        var sr = {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   143
            pt: parseInt(o.css('paddingTop'), 10)||0,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   144
            pb: parseInt(o.css('paddingBottom'), 10)||0,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   145
            bt: parseInt(o.css('borderTopWidth'), 10)||0,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   146
            bb: parseInt(o.css('borderBottomWidth'), 10)||0,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   147
            lh: parseInt(o.css('lineHeight'), 10) || false,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   148
            fs: parseInt(o.css('fontSize'), 10) || false
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   149
        };
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   150
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   151
        obj.sizeRelated = sr;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   152
    };
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   153
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   154
    /**
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   155
     * Create a dummy if one does not yet exist.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   156
     */
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   157
    var createDummy = function(e) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   158
        var obj = e.data;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   159
        if(!obj.dummy){
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   160
            var val = obj.o.val();
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   161
            // we need dummy to calculate scrollHeight
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   162
            // (there are some tricks that can't be applied to the textarea itself, otherwise user will see it)
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   163
            // Also, dummy must be a textarea too, and must be placed at the same position in DOM
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   164
            // in order to keep all the inherited styles
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   165
            var dummy = obj.o.clone();
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   166
            dummy.addClass('growfieldDummy');
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   167
            dummy.attr('tabindex', -9999);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   168
            dummy.css({
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   169
                position: 'absolute',
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   170
                left: -9999,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   171
                top: 0,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   172
                height: '20px',
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   173
                resize: 'none'});
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   174
            // The dummy must be inserted after otherwise google chrome will
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   175
            // focus on the dummy instead of on the actual text area, focus will always
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   176
            // be lost.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   177
            dummy.insertAfter(obj.o);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   178
            dummy.show();
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   179
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   180
            // if there is no initial value, we have to add some text, otherwise textarea will jitter
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   181
            // at the first keydown
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   182
            if (!val) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   183
                dummy.val('dummy text');
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   184
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   185
            obj.dummy = dummy;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   186
            // lets set the initial height
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   187
            obj.update((!$.trim(val) || obj.opt.restore) ? 0 : obj.getDummyHeight(), false);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   188
        }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   189
    };
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   190
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   191
    /**
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   192
     * Remove the dummy if one exists
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   193
     */
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   194
    var removeDummy = function(e) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   195
        obj = e.data;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   196
        if(obj.dummy){
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   197
            obj.dummy.remove();
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   198
            delete obj.dummy;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   199
        }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   200
    };
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   201
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   202
    //-----------------------------------------------------
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   203
    // END EVENT HANDLERS
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   204
    //-----------------------------------------------------
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   205
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   206
    // This will bind to $(document).ready if the height is loaded
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   207
    // or a window.load event already occurred.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   208
    // OR it will just bind to the window.load event.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   209
    var executeWhenReady = function(data,fn){
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   210
        if (data.o.height() !== 0 || windowLoaded) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   211
            $(document).ready(function(){
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   212
                fn({data:data});
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   213
            });
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   214
        }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   215
        else {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   216
            $(window).one('load', data, fn);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   217
        }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   218
    };
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   219
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   220
    //-----------------------------------------------------
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   221
    // Public methods.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   222
    //-----------------------------------------------------
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   223
    var that = {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   224
        // Toggle the functionality.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   225
        // enable or true will enable growfield
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   226
        // disable or false will disable growfield
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   227
        toggle: function(mode) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   228
            if ((mode=='disable' || mode===false)&&this.enabled) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   229
                this.unbind();
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   230
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   231
            else if ((mode=='enable' || mode===true)&&!this.enabled) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   232
                this.bind();
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   233
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   234
            return this;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   235
        },
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   236
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   237
        // Bind all growfield events to the object.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   238
        bind: function(){
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   239
            executeWhenReady(this,prepareSizeRelated);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   240
            var opt = this.opt;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   241
            var o = this.o;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   242
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   243
            // auto mode, textarea grows as you type
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   244
            if (opt.auto) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   245
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   246
                o.bind('keyup.growfield', this, keyUp);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   247
                this.initial = {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   248
                    overflow: this.o.css('overflow'),
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   249
                    cssResize: this.o.css('resize')
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   250
                };
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   251
                // We want to ensure that safari and google chrome do not allow
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   252
                // the user to drag-to-resize the field. This should only be enabled
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   253
                // if auto mode is disabled.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   254
                if ($.browser.safari) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   255
                    o.css('resize', 'none');
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   256
                }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   257
                o.css('overflow','hidden');
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   258
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   259
                o.bind('focus.growfield', this, createDummy);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   260
                // all styles must be loaded before prepare elements
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   261
                // we need to ensure the dummy exists at least for a short
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   262
                // time so that we can calculate the initial state...
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   263
                executeWhenReady(this, createDummy);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   264
                executeWhenReady(this, removeDummy);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   265
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   266
            // manual mode, textarea grows as you type ctrl + up|down
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   267
            else {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   268
                o.bind('keydown.growfield', this, manualKeyUp);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   269
                o.css('overflow-y', 'auto');
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   270
                executeWhenReady(this,function(e){
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   271
                    e.data.update(e.data.o.height());
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   272
                });
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   273
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   274
            o.bind('focus.growfield', this, focus);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   275
            o.bind('blur.growfield', this, blur);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   276
            o.bind('blur.growfield', this, removeDummy);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   277
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   278
            // Custom events provided in options
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   279
            if (opt.onHeightChange) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   280
                o.bind('onHeightChange.growfield', opt.onHeightChange);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   281
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   282
            if (opt.onRestore) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   283
                o.bind('onRestore.growfield', opt.onRestore);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   284
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   285
            if (opt.onGrowBack) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   286
                o.bind('onGrowBack.growfield', opt.onGrowBack);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   287
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   288
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   289
            this.enabled = true;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   290
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   291
            return this;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   292
        },
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   293
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   294
        // Unbind all growfield events from the object (including custom events)
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   295
        unbind: function() {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   296
            removeDummy({data:this});
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   297
            this.o.unbind('.growfield');
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   298
            this.o.css('overflow', this.initial.overflow);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   299
            if ($.browser.safari) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   300
                this.o.css('resize', this.initial.cssResize);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   301
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   302
            this.enabled = false;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   303
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   304
            return this;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   305
        },
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   306
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   307
        // Trigger custom events according to updateMode
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   308
        triggerEvents: function(updateMode) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   309
            var o = this.o;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   310
            o.trigger('onHeightChange.growfield');
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   311
            if (updateMode == 'restore') {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   312
                o.trigger('onRestore.growfield');
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   313
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   314
            if (updateMode == 'growback') {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   315
                o.trigger('onGrowBack.growfield');
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   316
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   317
        },
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   318
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   319
        update: function(h, animate, updateMode) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   320
            var sr = this.sizeRelated;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   321
            var val = this.o.val();
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   322
            var opt = this.opt;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   323
            var dom = this.dom;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   324
            var o = this.o;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   325
            var th = this;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   326
            var prev = this.prevH;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   327
            var noHidden = !opt.auto;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   328
            var noFocus = opt.auto;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   329
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   330
            h = this.convertHeight(Math.round(h), 'inner');
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   331
            // get the right height according to min and max value
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   332
            h = opt.min > h ? opt.min :
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   333
                  opt.max && h > opt.max ? opt.max :
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   334
                  opt.auto && !val ? opt.min : h;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   335
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   336
            if (opt.max && opt.auto) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   337
                if (prev != opt.max && h == opt.max) { // now we reached maximum height
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   338
                    o.css('overflow-y', 'scroll');
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   339
                    if (!opt.animate) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   340
                        o.focus(); // browsers do loose cursor after changing overflow :(
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   341
                    }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   342
                    noHidden = true;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   343
                    noFocus = false;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   344
                }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   345
                if (prev == opt.max && h < opt.max) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   346
                    o.css('overflow-y', 'hidden');
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   347
                    if (!opt.animate) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   348
                        o.focus();
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   349
                    }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   350
                    noFocus = false;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   351
                }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   352
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   353
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   354
            if (h == prev) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   355
                return true;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   356
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   357
            // in case of restore in manual mode we have to store
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   358
            // previous height (we can't get it from dummy)
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   359
            if (!opt.auto && updateMode == 'restore') {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   360
                this.restoreH = this.convertHeight(this.prevH, 'outer');
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   361
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   362
            this.prevH = h;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   363
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   364
            if (animate) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   365
                th.busy = true;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   366
                o.animate({height: h}, {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   367
                    duration: opt.animate,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   368
                    easing: ($.easing ? opt.easing : null),
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   369
                    overflow: null,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   370
                    inline: true, // this option isn't jquery's. I added it by myself, see above
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   371
                    complete: function(){
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   372
                        // safari/chrome fix
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   373
                        // somehow textarea turns to overflow:scroll after animation
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   374
                        // i counldn't find it in jquery fx :(, so it looks like some bug
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   375
                        if (!noHidden) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   376
                            o.css('overflow', 'hidden');
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   377
                        }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   378
                        // but if we still need to change overflow (due to opt.max option)
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   379
                        // we have to invoke focus() event, otherwise browser will loose cursor
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   380
                        if (!noFocus && updateMode != 'restore') {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   381
                            o.focus();
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   382
                        }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   383
                        if (updateMode == 'growback') {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   384
                            dom.scrollTop = dom.scrollHeight;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   385
                        }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   386
                        th.busy = false;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   387
                        th.triggerEvents(updateMode);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   388
                    },
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   389
                    queue: false
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   390
                });
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   391
            } else {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   392
                dom.style.height = h+'px';
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   393
                this.triggerEvents(updateMode);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   394
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   395
        },
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   396
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   397
        getDummyHeight: function() {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   398
            var val = this.o.val();
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   399
            var h = 0;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   400
            var sr = this.sizeRelated;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   401
            var add = "\n111\n111";
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   402
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   403
            // Safari has some defect with double new line symbol at the end
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   404
            // It inserts additional new line even if you have only one
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   405
            // But that't not the point :)
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   406
            // Another question is how much pixels to keep at the bottom of textarea.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   407
            // We'll kill many rabbits at the same time by adding two new lines at the end
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   408
            // (but if we have font-size and line-height defined, we'll add two line-heights)
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   409
            if ($.browser.safari) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   410
                val = val.substring(0, val.length-1); // safari has an additional new line ;(
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   411
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   412
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   413
            if (!sr.lh || !sr.fs) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   414
                val += add;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   415
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   416
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   417
            this.dummy.val(val);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   418
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   419
            // IE requires to change height value in order to recalculate scrollHeight.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   420
            // otherwise it stops recalculating scrollHeight after some magical number of pixels
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   421
            if ($.browser.msie) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   422
                this.dummy[0].style.height = this.dummy[0].scrollHeight+'px';
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   423
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   424
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   425
            h = this.dummy[0].scrollHeight;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   426
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   427
            // if line-height is greater than font-size we'll add line-height + font-size
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   428
            // otherwise font-size * 2
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   429
            // there is no special logic in this behavior, it's been developed from visual testing
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   430
            if (sr.lh && sr.fs) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   431
                h += sr.lh > sr.fs ? sr.lh+sr.fs :  sr.fs * 2;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   432
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   433
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   434
            // now we have to minimize dummy back, or we'll get wrong scrollHeight next time
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   435
            //if ($.browser.msie) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   436
            //    this.dummy[0].style.height = '20px'; // random number
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   437
            //}
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   438
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   439
            return h;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   440
        },
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   441
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   442
        convertHeight: function(h, to) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   443
            var sr = this.sizeRelated, mod = (to=='inner' ? -1 : 1), bm = $.support.boxModel;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   444
            // what we get here in 'h' is scrollHeight value.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   445
            // so we need to subtract paddings not because of boxModel,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   446
            // but only if browser includes them to the scroll height (which is not defined by box model)
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   447
            return h
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   448
                + (bm ? sr.bt : 0) * mod
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   449
                + (bm ? sr.bb : 0) * mod
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   450
                + (bm ? sr.pt : 0) * mod
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   451
                + (bm ? sr.pb : 0) * mod;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   452
        }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   453
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   454
    };
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   455
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   456
    return that;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   457
})();
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   458
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   459
/**
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   460
 * The growfield function. This will make a textarea a growing text area.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   461
 *
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   462
 * @param {Object} options - See API for details on possible paramaters.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   463
 */
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   464
$.fn.growfield = function(options) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   465
    // enable/disable is same thing as true/false
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   466
    switch(options){
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   467
        case 'enable':
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   468
            options = true;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   469
            break;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   470
        case 'disable':
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   471
            options = false;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   472
            break;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   473
    }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   474
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   475
    // we need to know what was passed as the options
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   476
    var tp = typeof options;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   477
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   478
    // These variables are used to reduce string comparisons
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   479
    // happening over and over.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   480
    var conditions = {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   481
        bool: tp == 'boolean',
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   482
        string: tp == 'string',
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   483
        object: tp == 'object',
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   484
        restart: options == 'restart',
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   485
        destroy: options == 'destroy'
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   486
    };
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   487
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   488
    // If the type of the options is a string
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   489
    // and is not one of the pre-defined ones, then
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   490
    // options is a preset.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   491
    if(conditions.string && !conditions.destroy && !conditions.restart){
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   492
        options = $.fn.growfield.presets[options];
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   493
        // change to new conditions
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   494
        conditions.string = false;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   495
        conditions.object = true;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   496
    }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   497
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   498
    // completely remove growfield from the dom elements
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   499
    if (conditions.destroy) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   500
        this.each(function() {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   501
            var self = $(this);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   502
            var gf = self.data('growfield');
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   503
            if (gf !== undefined) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   504
                gf.unbind();
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   505
                self.removeData('growfield');
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   506
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   507
        });
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   508
    }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   509
    // Apply growfield
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   510
    else {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   511
        var textareaRegex = /textarea/i;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   512
        this.each(function() {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   513
            // only deal with textareas which are not dummy fields.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   514
            if (textareaRegex.test(this.tagName) && !$(this).hasClass('growfieldDummy')) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   515
                var o = $(this);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   516
                var gf = o.data('growfield');
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   517
                // Create the new options
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   518
                if (gf === undefined) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   519
                    gf = $.growfield(this,options);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   520
                    o.data('growfield', gf);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   521
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   522
                    // Bind only if the options is not a boolean
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   523
                    // or is not "false". Because options = a false boolean
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   524
                    // indicates intial bind should not happen.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   525
                    if(!conditions.bool || options){
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   526
                        gf.bind();
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   527
                    }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   528
                }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   529
                // Otherwise apply actions based on the options provided
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   530
                else {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   531
                    // If new options provided, set them
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   532
                    if(conditions.object && options) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   533
                        $.extend(gf.opt,options);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   534
                    }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   535
                    // If toggling enable/disable then do it
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   536
                    else if (conditions.bool) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   537
                        gf.toggle(options);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   538
                    }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   539
                    // If restarting, restart
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   540
                    else if (conditions.restart) {
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   541
                        gf.unbind();
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   542
                        gf.bind();
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   543
                    }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   544
                }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   545
            }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   546
        });
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   547
    }
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   548
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   549
    return this;
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   550
};
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   551
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   552
/**
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   553
 * These are the default options to use, unless specified when invoking growfield.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   554
 */
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   555
$.fn.growfield.defaults ={
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   556
    // Should the growfield automatically expand?
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   557
    auto: true,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   558
    // The animation speed for expanding (false = off)
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   559
    animate: 100,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   560
    // The easiny function to use, if the jquery.easing plugin is not present during
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   561
    // execution, this will always be treated as null regardless of the set value
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   562
    easing: null,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   563
    // The minimum height (defaults to CSS min-height, or the current height of the element)
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   564
    min: false,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   565
    // The maximum height (defaults to CSS max-height, or unlimited)
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   566
    max: false,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   567
    // Should the element restore to it's original size after focus is lost?
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   568
    restore: false,
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   569
    // How many pixels to expand when the user is about to have to scroll. Defaults to 1 line.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   570
    step: false
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   571
};
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   572
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   573
/**
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   574
 * These are presets. The presets are indexed by name containing different preset
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   575
 * option objects. When growfield is invoked with the preset's name, that options object
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   576
 * is loaded without having to be specified each time.
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   577
 */
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   578
$.fn.growfield.presets = {};
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   579
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   580
})(jQuery);
645f4de26f99 Patch that adds the JS and CSS files for surveys.
Daniel Diniz <ajaksu@gmail.com>
parents:
diff changeset
   581