The version of vichan running on lainchan.org
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.

60 line
1.6KB

  1. /*
  2. * options/user-css.js - allow user enter custom css entries
  3. *
  4. * Copyright (c) 2014 Marcin Łabanowski <marcin@6irc.net>
  5. *
  6. * Usage:
  7. * $config['additional_javascript'][] = 'js/jquery.min.js';
  8. * $config['additional_javascript'][] = 'js/options.js';
  9. * $config['additional_javascript'][] = 'js/options/user-css.js';
  10. */
  11. +function(){
  12. var tab = Options.add_tab("user-css", "css3", _("User CSS"));
  13. var textarea = $("<textarea></textarea>").css({
  14. "font-size": 12,
  15. position: "absolute",
  16. top: 35, bottom: 35,
  17. width: "calc(100% - 20px)", margin: 0, padding: "4px", border: "1px solid black",
  18. left: 5, right: 5
  19. }).appendTo(tab.content);
  20. var submit = $("<input type='button' value='"+_("Update custom CSS")+"'>").css({
  21. position: "absolute",
  22. height: 25, bottom: 5,
  23. width: "calc(100% - 10px)",
  24. left: 5, right: 5
  25. }).click(function() {
  26. localStorage.user_css = textarea.val();
  27. apply_css();
  28. }).appendTo(tab.content);
  29. var apply_css = function() {
  30. $('.user-css').remove();
  31. $('link[rel="stylesheet"]')
  32. .last()
  33. .after($("<style></style>")
  34. .addClass("user-css")
  35. .text(localStorage.user_css)
  36. );
  37. };
  38. var update_textarea = function() {
  39. if (!localStorage.user_css) {
  40. textarea.text("/* "+_("Enter here your own CSS rules...")+" */\n" +
  41. "/* "+_("If you want to make a redistributable style, be sure to\nhave a Yotsuba B theme selected.")+" */\n" +
  42. "/* "+_("You can include CSS files from remote servers, for example:")+" */\n" +
  43. '@import "http://example.com/style.css";');
  44. }
  45. else {
  46. textarea.text(localStorage.user_css);
  47. apply_css();
  48. }
  49. };
  50. update_textarea();
  51. }();