- (function ($) {
- var
- defaults = {
- className: 'autosizejs',
- append: "",
- callback: false
- },
- hidden = 'hidden',
- borderBox = 'border-box',
- lineHeight = 'lineHeight',
-
-
- copy = '<textarea tabindex="-1" style="position:absolute; top:-9999px; left:-9999px; right:auto; bottom:auto; border:0; -moz-box-sizing:content-box; -webkit-box-sizing:content-box; box-sizing:content-box; word-wrap:break-word; height:0 !important; min-height:0 !important; overflow:hidden;"/>',
-
- copyStyle = [
- 'fontFamily',
- 'fontSize',
- 'fontWeight',
- 'fontStyle',
- 'letterSpacing',
- 'textTransform',
- 'wordSpacing',
- 'textIndent'
- ],
- oninput = 'oninput',
- onpropertychange = 'onpropertychange',
-
-
- mirrored,
-
- // Зеркало элемент, который используется для вычисления размера элемента должна быть зеркальной.
- mirror = $(copy).data('autosize', true)[0];
-
- mirror.style.lineHeight = '99px';
- if ($(mirror).css(lineHeight) === '99px') {
- copyStyle.push(lineHeight);
- }
- mirror.style.lineHeight = '';
-
- $.fn.autosize = function (options) {
- options = $.extend({}, defaults, options || {});
-
- if (mirror.parentNode !== document.body) {
- $(document.body).append(mirror);
- }
-
- return this.each(function () {
- var
- ta = this,
- $ta = $(ta),
- minHeight = $ta.height(),
- maxHeight = parseInt($ta.css('maxHeight'), 10),
- active,
- resize,
- boxOffset = 0,
- value = ta.value,
- callback = $.isFunction(options.callback);
-
- if ($ta.data('autosize')) {
- // выйти, если авторазмер уже применяется, или, если текстовое поле является зеркальным элементом.
- return;
- }
-
- if ($ta.css('box-sizing') === borderBox || $ta.css('-moz-box-sizing') === borderBox || $ta.css('-webkit-box-sizing') === borderBox){
- boxOffset = $ta.outerHeight() - $ta.height();
- }
-
- resize = $ta.css('resize') === 'none' ? 'none' : 'horizontal';
-
- $ta.css({
- overflow: hidden,
- overflowY: hidden,
- wordWrap: 'break-word',
- resize: resize
- }).data('autosize', true);
-
-
- maxHeight = maxHeight && maxHeight > 0 ? maxHeight : 9e4;
-
- function initMirror() {
- mirrored = ta;
- mirror.className = options.className;
-
- // Зеркало дубликат текстовой находится вне экрана, что
- // Автоматически обновляется, чтобы содержать тот же текст,
- // Оригинальные текстовое поле. Зеркало всегда имеет высоту 0.
- // Это дает кросс-браузерный поддерживаемый способ получения фактических
- // Высота текста, через scrollTop собственности.
-
- $.each(copyStyle, function(i, val){
- mirror.style[val] = $ta.css(val);
- });
- }
-
- // Использование основном голые JS в эту функцию, потому что она собирается
- // Стрелять очень часто во время набора текста, и нуждается в очень эффективна.
- function adjust() {
- var height, overflow, original;
-
- if (mirrored !== ta) {
- initMirror();
- }
-
- // Флаг активности сохраняет IE от отключения всего над собой. в противном случае
- // Действия в настроечном функция вызовет IE позвонить отрегулировать снова.
- if (!active) {
- active = true;
- mirror.value = ta.value + options.append;
- mirror.style.overflowY = ta.style.overflowY;
- original = parseInt(ta.style.height,10);
-
-
- mirror.style.width = $ta.width() + 'px';
-
-
- mirror.scrollTop = 0;
- mirror.scrollTop = 9e4;
- height = mirror.scrollTop;
-
- if (height > maxHeight) {
- height = maxHeight;
- overflow = 'scroll';
- } else if (height < minHeight) {
- height = minHeight;
- }
- height += boxOffset;
- ta.style.overflowY = overflow || hidden;
-
- if (original !== height) {
- ta.style.height = height + 'px';
- if (callback) {
- options.callback.call(ta);
- }
- }
- setTimeout(function () {
- active = false;
- }, 1);
- }
- }
-
- if (onpropertychange in ta) {
- if (oninput in ta) {
- ta[oninput] = ta.onkeyup = adjust;
- } else {
- ta[onpropertychange] = adjust;
- }
- } else {
- ta[oninput] = adjust;
- ta.value = '';
- ta.value = value;
- }
-
- $(window).resize(adjust);
-
- $ta.bind('autosize', adjust);
-
- adjust();
- });
- };
- }(window.jQuery || window.Zepto));
-
-
- /*
- Генерация пороля
- */
-
-
- function getPass( object, object2 ){
- var i, interval, words = "";
-
- words += "qwertyuiopasdfghjklzxcvbnm";
- words += "QWERTYUIOPASDFGHJKLZXCVBNM";
- words += "1234567890";
-
- var obj = document.getElementById(object);
- var obj2 = document.getElementById(object2);
-
- var objj = document.createElement("input");
- var objj2 = document.createElement("input");
-
- objj.size=obj.size;
- objj.className=obj.className;
- objj.id=obj.id;
- objj.name=obj.name;
- objj.type="text";
-
- objj2.size=obj2.size;
- objj2.className=obj2.className;
- objj2.id=obj2.id;
- objj2.name=obj2.name;
- objj2.type="text";
-
- obj.parentNode.replaceChild(objj,obj);
- obj2.parentNode.replaceChild(objj2,obj2);
-
- var new_word_timeout = 100; // время между появлением новых букв.
- var word_timeout = 10; // время между сменой букв
- var word_count = 10; // количество букв
-
- new function(){
- this.getNextWord = function(){
- objj.value += " ";
- objj2.value += " ";
- }
- this.getWord = function(){
- objj.value = objj.value.substring( 0, objj.value.length - 1 ) + words.charAt( getRand( 0, words.length -1 ) );
- objj2.value = objj.value;
- }
- this.stop = function(){
- clearInterval( interval );
- }
- for( i = 0; i < word_count; i ++ ){
- setTimeout( this.getNextWord, i * new_word_timeout );
- }
- interval = setInterval( this.getWord, word_timeout );
- setTimeout( this.stop, new_word_timeout * word_count );
- }
- }
-
- function getRand( min, max ){
- return Math.round( Math.random( ) * ( max - min ) ) + min;
- }