PageRenderTime 38ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/backend/Apricot/assets/js/custom/scriptbreaker-multiple-accordion-1.js

https://gitlab.com/kaouech/theme
JavaScript | 89 lines | 61 code | 11 blank | 17 comment | 14 complexity | 5ea6e0e6aac0c3c315e8719ae839a60a MD5 | raw file
  1. /*
  2. * jQuery UI Multilevel accordionze v.1
  3. *
  4. * Copyright (c) 2011 Pieter Pareit
  5. *
  6. * http://www.scriptbreaker.com
  7. *
  8. */
  9. //plugin definition
  10. (function($){
  11. $.fn.extend({
  12. //pass the options variable to the function
  13. accordionze: function(options) {
  14. var defaults = {
  15. accordionze: 'true',
  16. speed: 300,
  17. closedSign: '[+]',
  18. openedSign: '[-]'
  19. };
  20. // Extend our default options with those provided.
  21. var opts = $.extend(defaults, options);
  22. //Assign current element to variable, in this case is UL element
  23. var $this = $(this);
  24. //add a mark [+] to a multilevel menu
  25. $this.find("li").each(function() {
  26. if($(this).find("ul").size() != 0){
  27. //add the multilevel sign next to the link
  28. $(this).find("a:first").append("<h4>"+ opts.closedSign +"</h4>");
  29. //avoid jumping to the top of the page when the href is an #
  30. if($(this).find("a:first").attr('href') == "#"){
  31. $(this).find("a:first").click(function(){return false;});
  32. }
  33. }
  34. });
  35. //open active level
  36. $this.find("li.active").each(function() {
  37. $(this).parents("ul").slideDown(opts.speed);
  38. $(this).parents("ul").parent("li").find("h4:first").html(opts.openedSign);
  39. });
  40. $this.find("li a").click(function() {
  41. if($(this).parent().find("ul").size() != 0){
  42. if(opts.accordionze){
  43. //Do nothing when the list is open
  44. if(!$(this).parent().find("ul").is(':visible')){
  45. parents = $(this).parent().parents("ul");
  46. visible = $this.find("ul:visible");
  47. visible.each(function(visibleIndex){
  48. var close = true;
  49. parents.each(function(parentIndex){
  50. if(parents[parentIndex] == visible[visibleIndex]){
  51. close = false;
  52. return false;
  53. }
  54. });
  55. if(close){
  56. if($(this).parent().find("ul") != visible[visibleIndex]){
  57. $(visible[visibleIndex]).slideUp(opts.speed, function(){
  58. $(this).parent("li").find("h4:first").html(opts.closedSign);
  59. });
  60. }
  61. }
  62. });
  63. }
  64. }
  65. if($(this).parent().find("ul:first").is(":visible")){
  66. $(this).parent().find("ul:first").slideUp(opts.speed, function(){
  67. $(this).parent("li").find("h4:first").delay(opts.speed).html(opts.closedSign);
  68. });
  69. }else{
  70. $(this).parent().find("ul:first").slideDown(opts.speed, function(){
  71. $(this).parent("li").find("h4:first").delay(opts.speed).html(opts.openedSign);
  72. });
  73. }
  74. }
  75. });
  76. }
  77. });
  78. })(jQuery);