PageRenderTime 73ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/jojo_core/external/jsTree/!DEV/jstree.themes.js

http://jojocms.googlecode.com/
JavaScript | 186 lines | 127 code | 6 blank | 53 comment | 36 complexity | ee7bc795f770c65eacb5934eb68225e5 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, LGPL-2.0, CC-BY-SA-3.0, MIT
  1. /* File: jstree.themes.js
  2. Controls the looks of jstree, without this plugin you will get a functional tree, but it will look just like an ordinary UL list
  3. */
  4. (function ($) {
  5. var themes_loaded = [];
  6. /*
  7. Group: $.jstree.
  8. Variable: $.jstree.THEMES_DIR
  9. The location of all themes, this is used when setting a theme without supplying an URL (only by name).
  10. Default is _false_. If left as _false_ the path will be autodetected when the DOM is ready.
  11. The location of _jquery.jstree.js_ is used for the autodetection.
  12. Normally you won't need to modify this (provided you leave the _themes_ folder in the same folder as _jquery.jstree.js_ and do not rename the file).
  13. If you decide to move the folder or rename the file, but still want to load themes by name, simply set this to the new location of the _themes_ folder.
  14. > <script type="text/javascript" src="jquery.jstree.js"></script>
  15. > <script type="text/javascript">$.jstree.THEMES_DIR = "some/path/with-a-trailing-slash/";</script>
  16. */
  17. $.jstree.THEMES_DIR = false;
  18. $.jstree.plugin("themes", {
  19. __construct : function () {
  20. this.get_container()
  21. .bind("__construct.jstree", $.proxy(function () {
  22. var s = this.get_settings(true).themes;
  23. this.data.themes.dots = s.dots;
  24. this.data.themes.icons = s.icons;
  25. if(s.url === false && s.theme === false) {
  26. s.theme = this.data.core.rtl ? 'default-rtl' : 'default';
  27. }
  28. this.set_theme(s.theme, s.url);
  29. this[ this.data.themes.dots ? "show_dots" : "hide_dots" ]();
  30. this[ this.data.themes.icons ? "show_icons" : "hide_icons" ]();
  31. }, this));
  32. },
  33. /* Class: jstree */
  34. /*
  35. Group: THEMES options
  36. Variable: config.themes.theme
  37. *string* the name of the theme you want to use. Default is _default_.
  38. Variable: config.themes.url
  39. *mixed* the URL of the stylesheet of the theme you want to use. Default is _false_. If left as _false_ the location will be autodetected using <$.jstree.THEMES_DIR>.
  40. Variable: config.themes.dots
  41. *boolean* whether to show dots or not. Default is _true_. The chosen theme should support this option.
  42. Variable: config.themes.icons
  43. *boolean* whether to show icons or not. Default is _true_.
  44. */
  45. defaults : {
  46. theme : false,
  47. url : false,
  48. dots : true,
  49. icons : true
  50. },
  51. _fn : {
  52. /*
  53. Group: THEMES functions
  54. Function: set_theme
  55. Sets the tree theme. This function is automatically called at construction with the settings specified in <config.themes.theme> and <config.themes.theme.url>.
  56. Parameters:
  57. theme_name - the name of the theme to apply
  58. theme_url - the URL of the stylesheet - leave this blank for autodetect
  59. Example:
  60. >// Set the theme and autodetect the location
  61. >$("#div1").jstree("set_theme","classic");
  62. >// A custom theme. Please note that if you place your own theme in the _themes_ folder ot will be autodetected too.
  63. >$("#div2").jstree("set_theme","custom-theme","/some/path/theme.css");
  64. */
  65. set_theme : function (theme_name, theme_url) {
  66. if(!theme_name) { return false; }
  67. if(!theme_url) { theme_url = $.jstree.THEMES_DIR + theme_name + '/style.css'; }
  68. if($.inArray(theme_url, themes_loaded) === -1) {
  69. $.vakata.css.add_sheet({ "url" : theme_url });
  70. themes_loaded.push(theme_url);
  71. }
  72. if(this.data.themes.theme != theme_name) {
  73. this.get_container().removeClass('jstree-' + this.data.themes.theme);
  74. this.data.themes.theme = theme_name;
  75. }
  76. this.get_container().addClass('jstree-' + theme_name);
  77. this.__callback(theme_name);
  78. },
  79. get_theme : function () { return this.data.themes.theme; },
  80. show_dots : function () { this.data.themes.dots = true; this.get_container().children("ul").removeClass("jstree-no-dots"); },
  81. hide_dots : function () { this.data.themes.dots = false; this.get_container().children("ul").addClass("jstree-no-dots"); },
  82. toggle_dots : function () { if(this.data.themes.dots) { this.hide_dots(); } else { this.show_dots(); } },
  83. show_icons : function () { this.data.themes.icons = true; this.get_container().children("ul").removeClass("jstree-no-icons"); },
  84. hide_icons : function () { this.data.themes.icons = false; this.get_container().children("ul").addClass("jstree-no-icons"); },
  85. toggle_icons : function () { if(this.data.themes.icons) { this.hide_icons(); } else { this.show_icons(); } },
  86. clean_node : function(obj) {
  87. obj = this.__call_old();
  88. return obj.each(function () {
  89. var t = $(this),
  90. d = t.data("jstree");
  91. if(!t.find("> a > ins.jstree-themeicon").length) {
  92. t.children("a").prepend("<ins class='jstree-icon jstree-themeicon'>&#160;</ins>");
  93. }
  94. if(d && d.icon) {
  95. if(d.icon.indexOf("/") === -1) { t.find("> a > .jstree-themeicon").addClass(d.icon); }
  96. else { t.find("> a > .jstree-themeicon").css("background", "url('" + d.icon + "') center center no-repeat"); }
  97. }
  98. else if(d && d.icon === false) {
  99. t.find("> a > .jstree-themeicon").hide();
  100. }
  101. else {
  102. t.children("a").each(function () {
  103. var t = $(this),
  104. d = t.data("jstree");
  105. if(d && d.icon) {
  106. if(d.icon.indexOf("/") === -1) { t.children(".jstree-themeicon").addClass(d.icon); }
  107. else { t.children(".jstree-themeicon").css("background", "url('" + d.icon + "') center center no-repeat"); }
  108. }
  109. else if(d && d.icon === false) {
  110. t.children(".jstree-themeicon").hide();
  111. }
  112. });
  113. }
  114. });
  115. },
  116. get_state : function () {
  117. var state = this.__call_old();
  118. state.themes = { 'theme' : this.get_theme(), 'icons' : this.data.themes.icons, 'dots' : this.data.themes.dots };
  119. return state;
  120. },
  121. set_state : function (state, callback) {
  122. if(this.__call_old()) {
  123. if(state.themes) {
  124. if(state.themes.theme) {
  125. this.set_theme(state.themes.theme);
  126. }
  127. if(typeof state.themes.dots !== 'undefined') {
  128. this[ state.themes.dots ? "show_dots" : "hide_dots" ]();
  129. }
  130. if(typeof state.themes.icons !== 'undefined') {
  131. this[ state.themes.icons ? "show_icons" : "hide_icons" ]();
  132. }
  133. delete state.themes;
  134. this.set_state(state, callback);
  135. return false;
  136. }
  137. return true;
  138. }
  139. return false;
  140. }
  141. }
  142. });
  143. $(function () {
  144. // autodetect themes path
  145. if($.jstree.THEMES_DIR === false) {
  146. $("script").each(function () {
  147. if(this.src.toString().match(/jquery\.jstree[^\/]*?\.js(\?.*)?$/)) {
  148. $.jstree.THEMES_DIR = this.src.toString().replace(/jquery\.jstree[^\/]*?\.js(\?.*)?$/, "") + 'themes/';
  149. return false;
  150. }
  151. });
  152. }
  153. if($.jstree.THEMES_DIR === false) { $.jstree.THEMES_DIR = "themes/"; }
  154. // add themes specific CSS
  155. var css_string = '' +
  156. '.jstree a { text-decoration:none; } ' +
  157. '.jstree a > .jstree-themeicon { height:16px; width:16px; margin-right:3px; } ' +
  158. '.jstree-rtl a > .jstree-themeicon { margin-left:3px; margin-right:0; } ' +
  159. '.jstree .jstree-no-icons .jstree-themeicon { display:none; } ';
  160. // Correct IE 6 (does not support the > CSS selector)
  161. if($.jstree.IS_IE6) {
  162. css_string += '' +
  163. '.jstree li a .jstree-themeicon { height:16px; width:16px; margin-right:3px; } ' +
  164. '.jstree-rtl li a .jstree-themeicon { margin-right:0px; margin-left:3px; } ';
  165. }
  166. // the default stylesheet
  167. $.vakata.css.add_sheet({ str : css_string, title : "jstree" });
  168. });
  169. // include the themes plugin by default
  170. $.jstree.defaults.plugins.push("themes");
  171. })(jQuery);
  172. //*/