element_modifiers.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * searx is free software: you can redistribute it and/or modify
  3. * it under the terms of the GNU Affero General Public License as published by
  4. * the Free Software Foundation, either version 3 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * searx is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU Affero General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU Affero General Public License
  13. * along with searx. If not, see < http://www.gnu.org/licenses/ >.
  14. *
  15. * (C) 2014 by Thomas Pointhuber, <thomas.pointhuber@gmx.at>
  16. */
  17. $(document).ready(function(){
  18. /**
  19. * focus element if class="autofocus" and id="q"
  20. */
  21. $('#q.autofocus').focus();
  22. /**
  23. * Empty search bar when click on reset button
  24. */
  25. $("#clear_search").click(function () {
  26. document.getElementById("q").value = "";
  27. });
  28. /**
  29. * select full content on click if class="select-all-on-click"
  30. */
  31. $(".select-all-on-click").click(function () {
  32. $(this).select();
  33. });
  34. /**
  35. * change text during btn-collapse click if possible
  36. */
  37. $('.btn-collapse').click(function() {
  38. var btnTextCollapsed = $(this).data('btn-text-collapsed');
  39. var btnTextNotCollapsed = $(this).data('btn-text-not-collapsed');
  40. if(btnTextCollapsed !== '' && btnTextNotCollapsed !== '') {
  41. if($(this).hasClass('collapsed')) {
  42. new_html = $(this).html().replace(btnTextCollapsed, btnTextNotCollapsed);
  43. } else {
  44. new_html = $(this).html().replace(btnTextNotCollapsed, btnTextCollapsed);
  45. }
  46. $(this).html(new_html);
  47. }
  48. });
  49. /**
  50. * change text during btn-toggle click if possible
  51. */
  52. $('.btn-toggle .btn').click(function() {
  53. var btnClass = 'btn-' + $(this).data('btn-class');
  54. var btnLabelDefault = $(this).data('btn-label-default');
  55. var btnLabelToggled = $(this).data('btn-label-toggled');
  56. if(btnLabelToggled !== '') {
  57. if($(this).hasClass('btn-default')) {
  58. new_html = $(this).html().replace(btnLabelDefault, btnLabelToggled);
  59. } else {
  60. new_html = $(this).html().replace(btnLabelToggled, btnLabelDefault);
  61. }
  62. $(this).html(new_html);
  63. }
  64. $(this).toggleClass(btnClass);
  65. $(this).toggleClass('btn-default');
  66. });
  67. /**
  68. * change text during btn-toggle click if possible
  69. */
  70. $('.media-loader').click(function() {
  71. var target = $(this).data('target');
  72. var iframe_load = $(target + ' > iframe');
  73. var srctest = iframe_load.attr('src');
  74. if(srctest === undefined || srctest === false){
  75. iframe_load.attr('src', iframe_load.data('src'));
  76. }
  77. });
  78. /**
  79. * Select or deselect every categories on double clic
  80. */
  81. $(".btn-sm").dblclick(function() {
  82. var btnClass = 'btn-' + $(this).data('btn-class'); // primary
  83. if($(this).hasClass('btn-default')) {
  84. $(".btn-sm > input").attr('checked', 'checked');
  85. $(".btn-sm > input").prop("checked", true);
  86. $(".btn-sm").addClass(btnClass);
  87. $(".btn-sm").addClass('active');
  88. $(".btn-sm").removeClass('btn-default');
  89. } else {
  90. $(".btn-sm > input").attr('checked', '');
  91. $(".btn-sm > input").removeAttr('checked');
  92. $(".btn-sm > input").checked = false;
  93. $(".btn-sm").removeClass(btnClass);
  94. $(".btn-sm").removeClass('active');
  95. $(".btn-sm").addClass('btn-default');
  96. }
  97. });
  98. $(".nav-tabs").click(function(a) {
  99. var tabs = $(a.target).parents("ul");
  100. tabs.children().attr("aria-selected", "false");
  101. $(a.target).parent().attr("aria-selected", "true");
  102. });
  103. });