visual.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. ////////////////////////////////////////////////////////////////
  2. /// Mode line and bars
  3. tab_bar_button_close = 1;
  4. tab_bar_show_icon = true;
  5. // Widget to display profile name in the mode-line.
  6. function profile_name_widget (window) {
  7. this.class_name = "profile-name-widget";
  8. text_widget.call(this, window);
  9. }
  10. profile_name_widget.prototype = {
  11. constructor: profile_name_widget,
  12. __proto__: text_widget.prototype,
  13. update: function () {
  14. this.view.text = current_profile;
  15. }
  16. };
  17. add_hook("mode_line_hook", mode_line_adder(profile_name_widget));
  18. remove_hook("mode_line_hook", mode_line_adder(clock_widget));
  19. function toggle_all_bars (window, state) {
  20. // Set to STATE or toggle if STATE is not a boolean
  21. // the visibility of tab_bar, minibuffer and mode_line.
  22. if ( !(state === true || state === false) )
  23. state = window.minibuffer.element.collapsed;
  24. window.minibuffer.element.collapsed = !state;
  25. tab_bar_mode(state);
  26. if (window.mode_line)
  27. window.mode_line.container.collapsed = !state;
  28. }
  29. interactive("toggle-all-bars",
  30. "Hide or show tab-bar, minibuffer and mode-line",
  31. function (I) { toggle_all_bars(I.window) });
  32. ////////////////////////////////////////////////////////////////
  33. /// Colors
  34. active_hint_background_color = "#7ACF19";
  35. active_img_hint_background_color = "#AEEE66";
  36. hint_background_color = "#F6F38A";
  37. img_hint_background_color = "#FCF9A5";
  38. ////////////////////////////////////////////////////////////////
  39. /// CSS themes
  40. // Used resources:
  41. // http://conkeror.org/Appearance
  42. // http://conkeror.org/Tips#Darken_the_current_page
  43. // https://github.com/scottjad/dotfiles/blob/master/.conkerorrc/color-theme.js
  44. // https://developer.mozilla.org/en-US/Add-ons/Code_snippets/File_I_O
  45. var global_themes = {};
  46. var css_dir = al_load_dir.clone();
  47. css_dir.append("css");
  48. Components.utils.import("resource://gre/modules/NetUtil.jsm");
  49. // Define 2 interactive commands for a theme NAME with stylesheets
  50. // defined in a css FILE:
  51. // - "apply-NAME-theme" applies the theme to the current document;
  52. // - "toggle-NAME-theme" loads/unloads the theme globally.
  53. function define_theme (name, file) {
  54. var styles;
  55. NetUtil.asyncFetch(file, function(inputStream, status) {
  56. if (!Components.isSuccessCode(status)) {
  57. dumpln("File not found: " + file);
  58. return;
  59. }
  60. styles = escape(NetUtil.readInputStreamToString(inputStream, inputStream.available()));
  61. });
  62. interactive("apply-" + name + "-theme",
  63. "Apply " + name + " color theme to the current document",
  64. function (I) {
  65. var document = I.buffer.document;
  66. var newSS = document.createElement("link");
  67. newSS.rel = "stylesheet";
  68. // Making URI to a local file in `href' doesn't work,
  69. // so we had to read the file and pass it as CSS data.
  70. newSS.href = "data:text/css," + styles;
  71. document.getElementsByTagName("head")[0].appendChild(newSS);
  72. });
  73. global_themes[name] = false;
  74. interactive("toggle-" + name + "-theme",
  75. "Toggle " + name + " color theme globally",
  76. function (I) {
  77. if (global_themes[name]) {
  78. unregister_user_stylesheet(file);
  79. global_themes[name] = false;
  80. } else {
  81. register_user_stylesheet(file);
  82. global_themes[name] = true;
  83. }
  84. });
  85. }
  86. // Define themes for all "*.css" files from dir.
  87. function define_themes (dir) {
  88. if (dir.isDirectory()) {
  89. var entries = dir.directoryEntries;
  90. while (entries.hasMoreElements()) {
  91. var entry = entries.getNext();
  92. entry.QueryInterface(Ci.nsIFile);
  93. var filename = entry.leafName;
  94. if (filename.substr(-4).toLowerCase() == ".css")
  95. define_theme(filename.substr(0, filename.length-4), entry);
  96. }
  97. } else {
  98. dumpln(dir.path + " is not a directory");
  99. }
  100. }
  101. define_themes(css_dir);