jquery.treed.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. $.fn.extend({
  17. treed: function (o) {
  18. var openedClass = 'fa-angle-down';
  19. var closedClass = 'fa-angle-right';
  20. var tree = $(this);
  21. tree.addClass("tree");
  22. tree.find('li').has("ul").each(function () {
  23. var branch = $(this);
  24. branch.prepend("<i class='indicator fa fa-fw " + openedClass + "'></i>");
  25. branch.addClass('branch');
  26. branch.on('click', function (e) {
  27. if (this == e.target) {
  28. var icon = $(this).children('i:first');
  29. icon.toggleClass(openedClass + " " + closedClass);
  30. $(this).children().children().toggle();
  31. $(this).children().children().each(function () {
  32. var child = $(this);
  33. child.find('i:first').height(child.find('a').height() - 6);
  34. });
  35. }
  36. });
  37. });
  38. tree.find('li').not(":has(ul)").each(function () {
  39. var branch = $(this);
  40. branch.prepend("<i class='indicator fa fa-fw fa-empty'></i>");
  41. });
  42. tree.find('.branch .indicator').each(function () {
  43. $(this).on('click', function () {
  44. $(this).closest('li').click();
  45. });
  46. });
  47. tree.find('.branch>a').each(function () {
  48. $(this).on('click', function (e) {
  49. $(this).closest('li').click();
  50. });
  51. });
  52. }
  53. });