Просмотр файла template/designs/shcms/js/shcms.js

Размер файла: 5.8Kb
  1. (function ($) {
  2. var
  3. defaults = {
  4. className: 'autosizejs',
  5. append: "",
  6. callback: false
  7. },
  8. hidden = 'hidden',
  9. borderBox = 'border-box',
  10. lineHeight = 'lineHeight',
  11.  
  12.  
  13. 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;"/>',
  14. copyStyle = [
  15. 'fontFamily',
  16. 'fontSize',
  17. 'fontWeight',
  18. 'fontStyle',
  19. 'letterSpacing',
  20. 'textTransform',
  21. 'wordSpacing',
  22. 'textIndent'
  23. ],
  24. oninput = 'oninput',
  25. onpropertychange = 'onpropertychange',
  26.  
  27. mirrored,
  28.  
  29. // Зеркало элемент, который используется для вычисления размера элемента должна быть зеркальной.
  30. mirror = $(copy).data('autosize', true)[0];
  31.  
  32. mirror.style.lineHeight = '99px';
  33. if ($(mirror).css(lineHeight) === '99px') {
  34. copyStyle.push(lineHeight);
  35. }
  36. mirror.style.lineHeight = '';
  37.  
  38. $.fn.autosize = function (options) {
  39. options = $.extend({}, defaults, options || {});
  40.  
  41. if (mirror.parentNode !== document.body) {
  42. $(document.body).append(mirror);
  43. }
  44.  
  45. return this.each(function () {
  46. var
  47. ta = this,
  48. $ta = $(ta),
  49. minHeight = $ta.height(),
  50. maxHeight = parseInt($ta.css('maxHeight'), 10),
  51. active,
  52. resize,
  53. boxOffset = 0,
  54. value = ta.value,
  55. callback = $.isFunction(options.callback);
  56.  
  57. if ($ta.data('autosize')) {
  58. // выйти, если авторазмер уже применяется, или, если текстовое поле является зеркальным элементом.
  59. return;
  60. }
  61.  
  62. if ($ta.css('box-sizing') === borderBox || $ta.css('-moz-box-sizing') === borderBox || $ta.css('-webkit-box-sizing') === borderBox){
  63. boxOffset = $ta.outerHeight() - $ta.height();
  64. }
  65.  
  66. resize = $ta.css('resize') === 'none' ? 'none' : 'horizontal';
  67.  
  68. $ta.css({
  69. overflow: hidden,
  70. overflowY: hidden,
  71. wordWrap: 'break-word',
  72. resize: resize
  73. }).data('autosize', true);
  74.  
  75.  
  76. maxHeight = maxHeight && maxHeight > 0 ? maxHeight : 9e4;
  77.  
  78. function initMirror() {
  79. mirrored = ta;
  80. mirror.className = options.className;
  81.  
  82. // Зеркало дубликат текстовой находится вне экрана, что
  83. // Автоматически обновляется, чтобы содержать тот же текст,
  84. // Оригинальные текстовое поле. Зеркало всегда имеет высоту 0.
  85. // Это дает кросс-браузерный поддерживаемый способ получения фактических
  86. // Высота текста, через scrollTop собственности.
  87.  
  88. $.each(copyStyle, function(i, val){
  89. mirror.style[val] = $ta.css(val);
  90. });
  91. }
  92.  
  93. // Использование основном голые JS в эту функцию, потому что она собирается
  94. // Стрелять очень часто во время набора текста, и нуждается в очень эффективна.
  95. function adjust() {
  96. var height, overflow, original;
  97.  
  98. if (mirrored !== ta) {
  99. initMirror();
  100. }
  101.  
  102. // Флаг активности сохраняет IE от отключения всего над собой. в противном случае
  103. // Действия в настроечном функция вызовет IE позвонить отрегулировать снова.
  104. if (!active) {
  105. active = true;
  106. mirror.value = ta.value + options.append;
  107. mirror.style.overflowY = ta.style.overflowY;
  108. original = parseInt(ta.style.height,10);
  109.  
  110.  
  111. mirror.style.width = $ta.width() + 'px';
  112.  
  113.  
  114. mirror.scrollTop = 0;
  115. mirror.scrollTop = 9e4;
  116. height = mirror.scrollTop;
  117.  
  118. if (height > maxHeight) {
  119. height = maxHeight;
  120. overflow = 'scroll';
  121. } else if (height < minHeight) {
  122. height = minHeight;
  123. }
  124. height += boxOffset;
  125. ta.style.overflowY = overflow || hidden;
  126.  
  127. if (original !== height) {
  128. ta.style.height = height + 'px';
  129. if (callback) {
  130. options.callback.call(ta);
  131. }
  132. }
  133. setTimeout(function () {
  134. active = false;
  135. }, 1);
  136. }
  137. }
  138.  
  139. if (onpropertychange in ta) {
  140. if (oninput in ta) {
  141. ta[oninput] = ta.onkeyup = adjust;
  142. } else {
  143. ta[onpropertychange] = adjust;
  144. }
  145. } else {
  146. ta[oninput] = adjust;
  147. ta.value = '';
  148. ta.value = value;
  149. }
  150.  
  151. $(window).resize(adjust);
  152.  
  153. $ta.bind('autosize', adjust);
  154.  
  155. adjust();
  156. });
  157. };
  158. }(window.jQuery || window.Zepto));
  159.  
  160.  
  161. /*
  162. Генерация пороля
  163. */
  164.  
  165.  
  166. function getPass( object, object2 ){
  167. var i, interval, words = "";
  168.  
  169. words += "qwertyuiopasdfghjklzxcvbnm";
  170. words += "QWERTYUIOPASDFGHJKLZXCVBNM";
  171. words += "1234567890";
  172.  
  173. var obj = document.getElementById(object);
  174. var obj2 = document.getElementById(object2);
  175.  
  176. var objj = document.createElement("input");
  177. var objj2 = document.createElement("input");
  178.  
  179. objj.size=obj.size;
  180. objj.className=obj.className;
  181. objj.id=obj.id;
  182. objj.name=obj.name;
  183. objj.type="text";
  184.  
  185. objj2.size=obj2.size;
  186. objj2.className=obj2.className;
  187. objj2.id=obj2.id;
  188. objj2.name=obj2.name;
  189. objj2.type="text";
  190.  
  191. obj.parentNode.replaceChild(objj,obj);
  192. obj2.parentNode.replaceChild(objj2,obj2);
  193.  
  194. var new_word_timeout = 100; // время между появлением новых букв.
  195. var word_timeout = 10; // время между сменой букв
  196. var word_count = 10; // количество букв
  197.  
  198. new function(){
  199. this.getNextWord = function(){
  200. objj.value += " ";
  201. objj2.value += " ";
  202. }
  203. this.getWord = function(){
  204. objj.value = objj.value.substring( 0, objj.value.length - 1 ) + words.charAt( getRand( 0, words.length -1 ) );
  205. objj2.value = objj.value;
  206. }
  207. this.stop = function(){
  208. clearInterval( interval );
  209. }
  210. for( i = 0; i < word_count; i ++ ){
  211. setTimeout( this.getNextWord, i * new_word_timeout );
  212. }
  213. interval = setInterval( this.getWord, word_timeout );
  214. setTimeout( this.stop, new_word_timeout * word_count );
  215. }
  216. }
  217.  
  218. function getRand( min, max ){
  219. return Math.round( Math.random( ) * ( max - min ) ) + min;
  220. }