common.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * This file is part of the ForkBB <https://github.com/forkbb>.
  3. *
  4. * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
  5. * @license The MIT License (MIT)
  6. */
  7. if (typeof ForkBB === "undefined" || !ForkBB) {
  8. var ForkBB = {};
  9. }
  10. ForkBB.common = (function (doc, win) {
  11. 'use strict';
  12. var selectorBack = ".f-go-back",
  13. hlClass = "f-highlighted";
  14. function initGoBack()
  15. {
  16. var backs = doc.querySelectorAll(selectorBack);
  17. for (var i = 0; i < backs.length; i++) {
  18. backs[i].addEventListener("click", function (event) {
  19. win.history.back();
  20. event.preventDefault();
  21. return false;
  22. });
  23. }
  24. }
  25. function initAnchorHL()
  26. {
  27. var target,
  28. hash = (win.location.hash || "").replace(/^#/, "");
  29. if (hash && (target = doc.getElementById(hash))) {
  30. target.classList.add(hlClass);
  31. setTimeout(function() {
  32. target.classList.remove(hlClass);
  33. }, 1500);
  34. }
  35. }
  36. function initShowPAss()
  37. {
  38. var inps = doc.querySelectorAll("input[type='password']");
  39. for (var i = 0; i < inps.length; i++) {
  40. var span = doc.createElement("span");
  41. span.classList.add('f-pass-ctrl');
  42. span.addEventListener('click', (function(i, s){
  43. return function () {
  44. if (i.getAttribute('type') == 'password') {
  45. i.setAttribute('type', 'text');
  46. s.classList.add('f-pass-dspl');
  47. } else {
  48. i.setAttribute('type', 'password');
  49. s.classList.remove('f-pass-dspl');
  50. }
  51. i.focus();
  52. }
  53. })(inps[i], span));
  54. var parent = inps[i].parentNode;
  55. parent.appendChild(span);
  56. parent.classList.add('f-pass-prnt');
  57. }
  58. }
  59. function initForm()
  60. {
  61. var inps = doc.querySelectorAll("input[type='hidden'][name='nekot']");
  62. for (var i = 0; i < inps.length; i++) {
  63. inps[i].value = (inps[i].parentNode.querySelector("input[type='hidden'][name='token']").value.replace(/\D/g, '').replace(/(......).*/, '$1'));
  64. }
  65. }
  66. return {
  67. init : function () {
  68. initGoBack();
  69. initAnchorHL();
  70. initShowPAss();
  71. initForm();
  72. },
  73. };
  74. }(document, window));
  75. if (document.addEventListener) {
  76. document.addEventListener("DOMContentLoaded", ForkBB.common.init, false);
  77. }