Advertisement
Guest User

common.js

a guest
Jan 18th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $("#menu-toggle").click(function(e) {
  2.   e.preventDefault();
  3.   $("#wrapper").toggleClass("toggled");
  4. });
  5. setTimeout(function() {
  6. $('#msgbox').fadeOut('fast');
  7. }, 4000);
  8. $('#menu-toggle').click(function(){
  9.     $(this).text(function(i,old){
  10.         return old=='<' ?  '>' : '<';
  11.     });
  12. });
  13. $(document).ready(function() {
  14.       $('#switch1').click(function() {
  15.           $("#creditContainer").toggle();
  16.       });
  17. })
  18. function autocomplete(inp, arr) {
  19. /*the autocomplete function takes two arguments,
  20. the text field element and an array of possible autocompleted values:*/
  21. var currentFocus;
  22. /*execute a function when someone writes in the text field:*/
  23. inp.addEventListener("input", function(e) {
  24.   var a, b, i, val = this.value;
  25.   /*close any already open lists of autocompleted values*/
  26.   closeAllLists();
  27.   if (!val) { return false;}
  28.   currentFocus = -1;
  29.   /*create a DIV element that will contain the items (values):*/
  30.   a = document.createElement("DIV");
  31.   a.setAttribute("id", this.id + "autocomplete-list");
  32.   a.setAttribute("class", "autocomplete-items");
  33.   /*append the DIV element as a child of the autocomplete container:*/
  34.   this.parentNode.appendChild(a);
  35.   /*for each item in the array...*/
  36.   for (i = 0; i < arr.length; i++) {
  37.     /*check if the item starts with the same letters as the text field value:*/
  38.     if (arr[i].substr(0, val.length).toUpperCase() == val.toUpperCase()) {
  39.       /*create a DIV element for each matching element:*/
  40.       b = document.createElement("DIV");
  41.       /*make the matching letters bold:*/
  42.       b.innerHTML = "<strong>" + arr[i].substr(0, val.length) + "</strong>";
  43.       b.innerHTML += arr[i].substr(val.length);
  44.       /*insert a input field that will hold the current array item's value:*/
  45.       b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
  46.       /*execute a function when someone clicks on the item value (DIV element):*/
  47.       b.addEventListener("click", function(e) {
  48.           /*insert the value for the autocomplete text field:*/
  49.           inp.value = this.getElementsByTagName("input")[0].value;
  50.           /*close the list of autocompleted values,
  51.           (or any other open lists of autocompleted values:*/
  52.           closeAllLists();
  53.       });
  54.       a.appendChild(b);
  55.     }
  56.   }
  57. });
  58. /*execute a function presses a key on the keyboard:*/
  59. inp.addEventListener("keydown", function(e) {
  60.   var x = document.getElementById(this.id + "autocomplete-list");
  61.   if (x) x = x.getElementsByTagName("div");
  62.   if (e.keyCode == 40) {
  63.     /*If the arrow DOWN key is pressed,
  64.     increase the currentFocus variable:*/
  65.     currentFocus++;
  66.     /*and and make the current item more visible:*/
  67.     addActive(x);
  68.   } else if (e.keyCode == 38) { //up
  69.     /*If the arrow UP key is pressed,
  70.     decrease the currentFocus variable:*/
  71.     currentFocus--;
  72.     /*and and make the current item more visible:*/
  73.     addActive(x);
  74.   } else if (e.keyCode == 13) {
  75.     /*If the ENTER key is pressed, prevent the form from being submitted,*/
  76.     e.preventDefault();
  77.     if (currentFocus > -1) {
  78.       /*and simulate a click on the "active" item:*/
  79.       if (x) x[currentFocus].click();
  80.     }
  81.   }
  82. });
  83. function addActive(x) {
  84. /*a function to classify an item as "active":*/
  85. if (!x) return false;
  86. /*start by removing the "active" class on all items:*/
  87. removeActive(x);
  88. if (currentFocus >= x.length) currentFocus = 0;
  89. if (currentFocus < 0) currentFocus = (x.length - 1);
  90. /*add class "autocomplete-active":*/
  91. x[currentFocus].classList.add("autocomplete-active");
  92. }
  93. function removeActive(x) {
  94. /*a function to remove the "active" class from all autocomplete items:*/
  95. for (var i = 0; i < x.length; i++) {
  96.   x[i].classList.remove("autocomplete-active");
  97. }
  98. }
  99. function closeAllLists(elmnt) {
  100. /*close all autocomplete lists in the document,
  101. except the one passed as an argument:*/
  102. var x = document.getElementsByClassName("autocomplete-items");
  103. for (var i = 0; i < x.length; i++) {
  104.   if (elmnt != x[i] && elmnt != inp) {
  105.     x[i].parentNode.removeChild(x[i]);
  106.   }
  107. }
  108. }
  109. /*execute a function when someone clicks in the document:*/
  110. document.addEventListener("click", function (e) {
  111.   closeAllLists(e.target);
  112. });
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement