PageRenderTime 35ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/pqb/filemanager-laravel/public/filemanager/scripts/jquery.filetree/jqueryFileTree.js

https://gitlab.com/hatemdigify/digifyblog
JavaScript | 118 lines | 69 code | 10 blank | 39 comment | 43 complexity | 5f1b59a48951fcd0935cc6913167105b MD5 | raw file
  1. // jQuery File Tree Plugin
  2. //
  3. // Version 1.01
  4. //
  5. // Cory S.N. LaViska
  6. // A Beautiful Site (http://abeautifulsite.net/)
  7. // 24 March 2008
  8. //
  9. // Visit http://abeautifulsite.net/notebook.php?article=58 for more information
  10. //
  11. // Usage: $('.fileTreeDemo').fileTree( options, callback )
  12. //
  13. // Options: root - root folder to display; default = /
  14. // script - location of the serverside AJAX file to use; default = jqueryFileTree.php
  15. // folderEvent - event to trigger expand/collapse; default = click
  16. // expandSpeed - default = 500 (ms); use -1 for no animation
  17. // collapseSpeed - default = 500 (ms); use -1 for no animation
  18. // expandEasing - easing function to use on expand (optional)
  19. // collapseEasing - easing function to use on collapse (optional)
  20. // multiFolder - whether or not to limit the browser to one subfolder at a time
  21. // loadMessage - Message to display while initial tree loads (can be HTML)
  22. //
  23. // History:
  24. // 1.03 (patched by simo for Filemanager) - add an expandedFolder option to open desired folder when init
  25. // 1.02 (patched by Filemanager) - add a datafunc option to get data through a function instead of a script
  26. // 1.01 - updated to work with foreign characters in directory/file names (12 April 2008)
  27. // 1.00 - released (24 March 2008)
  28. //
  29. // TERMS OF USE
  30. //
  31. // jQuery File Tree is licensed under a Creative Commons License and is copyrighted (C)2008 by Cory S.N. LaViska.
  32. // For details, visit http://creativecommons.org/licenses/by/3.0/us/
  33. //
  34. if(jQuery) (function($){
  35. $.extend($.fn, {
  36. fileTree: function(o, h) {
  37. // Defaults
  38. if( !o ) var o = {};
  39. if( o.root == undefined ) o.root = '/';
  40. if( o.datafunc == undefined ) o.datafunc = null;
  41. if( o.script == undefined ) o.script = 'jqueryFileTree.php';
  42. if( o.folderEvent == undefined ) o.folderEvent = 'click';
  43. if( o.expandSpeed == undefined ) o.expandSpeed= 500;
  44. if( o.collapseSpeed == undefined ) o.collapseSpeed= 500;
  45. if( o.expandEasing == undefined ) o.expandEasing = null;
  46. if( o.collapseEasing == undefined ) o.collapseEasing = null;
  47. if( o.multiFolder == undefined ) o.multiFolder = true;
  48. if( o.loadMessage == undefined ) o.loadMessage = 'Loading...';
  49. if( o.folderCallback == undefined ) o.folderCallback = null;
  50. if( o.after == undefined ) o.after = null;
  51. if(o.expandedFolder == undefined) o.expandedFolder = '';
  52. $(this).each( function() {
  53. function showTree(c, t) {
  54. function showData(data) {
  55. $(c).find('.start').html('');
  56. $(c).removeClass('wait').append(data);
  57. if( o.root == t ) $(c).find('UL:hidden').show();
  58. else $(c).find('UL:hidden').slideDown({ duration: o.expandSpeed, easing: o.expandEasing });
  59. bindTree(c);
  60. if (o.expandedFolder != null) {
  61. $(c).find(".directory.collapsed").each(function (i,f) {
  62. if ((o.expandedFolder).match($(f).children().attr('data-path'))) {
  63. showTree($(f), $(f).children().attr('data-path').match(/.*\//));
  64. $(f).removeClass('collapsed').addClass('expanded');
  65. };
  66. });
  67. }
  68. o.after(data);
  69. }
  70. $(c).addClass('wait');
  71. $(".jqueryFileTree.start").remove();
  72. if (o.datafunc) o.datafunc(t, showData);
  73. else $.post(o.script, { dir: t }, showData);
  74. }
  75. function bindTree(t) {
  76. $(t).find('LI A').bind(o.folderEvent, function() {
  77. if( $(this).parent().hasClass('directory') ) {
  78. if( $(this).parent().hasClass('collapsed') ) {
  79. // Expand
  80. if( !o.multiFolder ) {
  81. $(this).parent().parent().find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing });
  82. $(this).parent().parent().find('LI.directory').removeClass('expanded').addClass('collapsed');
  83. }
  84. $(this).parent().find('UL').remove(); // cleanup
  85. showTree( $(this).parent(), $(this).attr('data-path').match( /.*\// ) );
  86. $(this).parent().removeClass('collapsed').addClass('expanded');
  87. } else {
  88. // Collapse
  89. $(this).parent().find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing });
  90. $(this).parent().removeClass('expanded').addClass('collapsed');
  91. }
  92. o.folderCallback($(this).attr('data-path'));
  93. } else {
  94. h($(this).attr('data-path'));
  95. }
  96. return false;
  97. });
  98. // Prevent A from triggering the # on non-click events
  99. if( o.folderEvent.toLowerCase != 'click' ) $(t).find('LI A').bind('click', function() { return false; });
  100. }
  101. // Loading message
  102. $(this).html('<ul class="jqueryFileTree start"><li class="wait">' + o.loadMessage + '<li></ul>');
  103. // Get the initial file list
  104. showTree( $(this), o.root );
  105. });
  106. }
  107. });
  108. })(jQuery);