Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cssgallery.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. $(document).ready(function () {
  2. // If the custom stylesheet field is empty, select the current style from the previews
  3. if (!$('input#styleurl').val()){
  4. var radiobutton = $('input[name="stylesheet_gallery"][value="' + $('select#stylesheet').val() + '"]');
  5. radiobutton.click();
  6. $('.preview_wrapper').removeClass('selected');
  7. radiobutton.parent().parent().addClass('selected');
  8. }
  9. // If the input is clicked, redirect it to the overlay click event
  10. $('input[name="stylesheet_gallery"]').click(function() {
  11. $('.preview_wrapper').removeClass('selected');
  12. var parent = $(this).parent();
  13. parent.addClass('selected');
  14. var radiobutton = parent.find('input');
  15. radiobutton.prop('checked', true);
  16. $('select#stylesheet').val(radiobutton.attr('value'));
  17. $('select#stylesheet').change();
  18. $('input#styleurl').val('');
  19. })
  20. // Passthrough image click to radio button
  21. $('.preview_image').click(function(e) {
  22. e.currentTarget.children[1].children[0].children[0].click()
  23. })
  24. // If the drop-down is changed, select the appropriate item in gallery, clear the custom CSS field
  25. $('select#stylesheet').change(function() {
  26. var radiobutton = $('input[name="stylesheet_gallery"][value="' + $(this).val() + '"]');
  27. radiobutton.prop('checked', true);
  28. $('.preview_wrapper').removeClass('selected');
  29. radiobutton.parent().parent().addClass('selected');
  30. $('input#styleurl').val('');
  31. })
  32. // If the custom CSS field is changed, clear radio buttons
  33. $('input#styleurl').keydown(function() {
  34. $('input[name="stylesheet_gallery"]').each(function() {
  35. $(this).prop('checked', false);
  36. })
  37. $('.preview_wrapper').removeClass('selected');
  38. })
  39. // If the input is empty, select appropriate gallery item again by the drop-down
  40. $('input#styleurl').keyup(function() {
  41. if (!$(this).val()){
  42. $('select#stylesheet').change();
  43. }
  44. })
  45. // Allow the CSS gallery to be expanded/contracted
  46. $('#toggle_css_gallery').click(function (e) {
  47. e.preventDefault();
  48. $('#css_gallery').slideToggle(function () {
  49. $('#toggle_css_gallery').text($(this).is(':visible') ? 'Hide gallery' : 'Show gallery');
  50. });
  51. });
  52. document.querySelectorAll('[name=style_additions\\[\\]]').forEach(function(el) {
  53. el.addEventListener('change', function(e) {
  54. if (e.target.checked) {
  55. document.body.classList.add('style_'+e.target.value)
  56. } else {
  57. document.body.classList.remove('style_'+e.target.value)
  58. }
  59. })
  60. })
  61. var userstyle = $('link[rel=stylesheet][title]')[0]
  62. $('select#stylesheet').on('change', function(e) {
  63. var changetext = e.target.options[e.target.selectedIndex].text.toLowerCase()
  64. userstyle.href = userstyle.href.replace(/\/[^\/]+?\/style.css/, '/'+changetext+'/style.css')
  65. $('.style_addition').each(function(i, el){
  66. if (el.id == 'style_addition_'+changetext) {
  67. if (el.children.length) {
  68. el.classList.remove('hidden')
  69. $('#style_additions_tr')[0].classList.remove('hidden')
  70. } else {
  71. $('#style_additions_tr')[0].classList.add('hidden')
  72. }
  73. } else {
  74. el.classList.add('hidden')
  75. }
  76. })
  77. })
  78. });