Skip to content

Commit

Permalink
Advanced Accordion: scroll top issue fixded
Browse files Browse the repository at this point in the history
  • Loading branch information
jakaria-istauk committed Dec 13, 2023
1 parent f6b1b07 commit 99ec975
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 19 deletions.
2 changes: 1 addition & 1 deletion assets/front-end/js/view/advanced-accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
/*! no static exports found */
/***/ (function(module, exports) {

eval("ea.hooks.addAction(\"init\", \"ea\", function () {\n elementorFrontend.hooks.addAction(\"frontend/element_ready/eael-adv-accordion.default\", function ($scope, $) {\n var hashTag = window.location.hash.substr(1);\n hashTag = hashTag === 'safari' ? 'eael-safari' : hashTag;\n var hashTagExists = false;\n var $advanceAccordion = $scope.find(\".eael-adv-accordion\"),\n $accordionHeader = $scope.find(\".eael-accordion-header\"),\n $accordionType = $advanceAccordion.data(\"accordion-type\"),\n $accordionSpeed = $advanceAccordion.data(\"toogle-speed\"),\n $customIdOffset = $advanceAccordion.data(\"custom-id-offset\"),\n $scrollOnClick = $advanceAccordion.data(\"scroll-on-click\"),\n $srollSpeed = $advanceAccordion.data(\"scroll-speed\");\n window.addEventListener('hashchange', function () {\n hashTag = window.location.hash.substr(1);\n if (hashTag !== 'undefined' && hashTag) {\n jQuery('#' + hashTag).trigger('click');\n }\n });\n // Open default actived tab\n if (hashTag || $scrollOnClick === 'yes') {\n $accordionHeader.each(function () {\n if ($scrollOnClick === 'yes') {\n $(this).attr('data-scroll', $(this).offset().top);\n }\n if (hashTag) {\n if ($(this).attr(\"id\") == hashTag) {\n hashTagExists = true;\n $(this).addClass(\"show active\");\n $(this).next().slideDown($accordionSpeed);\n }\n }\n });\n }\n if (hashTagExists === false) {\n $accordionHeader.each(function () {\n if ($(this).hasClass(\"active-default\")) {\n $(this).addClass(\"show active\");\n $(this).next().slideDown($accordionSpeed);\n }\n });\n }\n\n // Remove multiple click event for nested accordion\n $accordionHeader.unbind(\"click\");\n $accordionHeader.click(function (e) {\n e.preventDefault();\n var $this = $(this);\n\n //\n setTimeout(function () {\n $('html, body').animate({\n scrollTop: $this.offset().top - $customIdOffset\n }, 500);\n }, 500);\n if ($accordionType === \"accordion\") {\n if ($this.hasClass(\"show\")) {\n $this.removeClass(\"show active\");\n $this.next().slideUp($accordionSpeed);\n } else {\n $this.parent().parent().find(\".eael-accordion-header\").removeClass(\"show active\");\n $this.parent().parent().find(\".eael-accordion-content\").slideUp($accordionSpeed);\n $this.toggleClass(\"show active\");\n $this.next().slideToggle($accordionSpeed);\n }\n } else {\n // For acccordion type 'toggle'\n if ($this.hasClass(\"show\")) {\n $this.removeClass(\"show active\");\n $this.next().slideUp($accordionSpeed);\n } else {\n $this.addClass(\"show active\");\n $this.next().slideDown($accordionSpeed);\n }\n }\n if ($scrollOnClick === 'yes' && $this.hasClass(\"active\")) {\n var $customIdOffsetVal = $customIdOffset ? parseFloat($customIdOffset) : 0;\n $('html, body').animate({\n scrollTop: $(this).data('scroll') - $customIdOffsetVal\n }, $srollSpeed);\n }\n ea.hooks.doAction(\"widgets.reinit\", $this.parent());\n ea.hooks.doAction(\"ea-advanced-accordion-triggered\", $this.next());\n });\n $scope.on('keydown', '.eael-accordion-header', function (e) {\n if (e.which === 13 || e.which === 32) {\n $(this).trigger('click');\n }\n });\n\n // If hashTag is not null then scroll to that hashTag smoothly\n if (typeof hashTag !== 'undefined' && hashTag && !ea.elementStatusCheck('eaelAdvancedAccordionScroll')) {\n var $customIdOffsetVal = $customIdOffset ? parseFloat($customIdOffset) : 0;\n $('html, body').animate({\n scrollTop: $(\"#\" + hashTag).offset().top - $customIdOffsetVal\n }, $srollSpeed);\n }\n });\n});\n\n//# sourceURL=webpack:///./src/js/view/advanced-accordion.js?");
eval("ea.hooks.addAction(\"init\", \"ea\", function () {\n elementorFrontend.hooks.addAction(\"frontend/element_ready/eael-adv-accordion.default\", function ($scope, $) {\n var hashTag = window.location.hash.substr(1);\n hashTag = hashTag === 'safari' ? 'eael-safari' : hashTag;\n var hashTagExists = false;\n var $advanceAccordion = $scope.find(\".eael-adv-accordion\"),\n $accordionHeader = $scope.find(\".eael-accordion-header\"),\n $accordionType = $advanceAccordion.data(\"accordion-type\"),\n $accordionSpeed = $advanceAccordion.data(\"toogle-speed\"),\n $customIdOffset = $advanceAccordion.data(\"custom-id-offset\"),\n $scrollOnClick = $advanceAccordion.data(\"scroll-on-click\"),\n $srollSpeed = $advanceAccordion.data(\"scroll-speed\");\n window.addEventListener('hashchange', function () {\n hashTag = window.location.hash.substr(1);\n if (hashTag !== 'undefined' && hashTag) {\n jQuery('#' + hashTag).trigger('click');\n }\n });\n // Open default actived tab\n if (hashTag || $scrollOnClick === 'yes') {\n $accordionHeader.each(function () {\n if ($scrollOnClick === 'yes') {\n $(this).attr('data-scroll', $(this).offset().top);\n }\n if (hashTag) {\n if ($(this).attr(\"id\") == hashTag) {\n hashTagExists = true;\n $(this).addClass(\"show active\");\n $(this).next().slideDown($accordionSpeed);\n }\n }\n });\n }\n if (hashTagExists === false) {\n $accordionHeader.each(function () {\n if ($(this).hasClass(\"active-default\")) {\n $(this).addClass(\"show active\");\n $(this).next().slideDown($accordionSpeed);\n }\n });\n }\n\n // Remove multiple click event for nested accordion\n $accordionHeader.unbind(\"click\");\n $accordionHeader.click(function (e) {\n e.preventDefault();\n var $this = $(this);\n if ($accordionType === \"accordion\") {\n if ($this.hasClass(\"show\")) {\n $this.removeClass(\"show active\");\n $this.next().slideUp($accordionSpeed);\n } else {\n $this.parent().parent().find(\".eael-accordion-header\").removeClass(\"show active\");\n $this.parent().parent().find(\".eael-accordion-content\").slideUp($accordionSpeed);\n $this.toggleClass(\"show active\");\n $this.next().slideToggle($accordionSpeed);\n }\n } else {\n // For acccordion type 'toggle'\n if ($this.hasClass(\"show\")) {\n $this.removeClass(\"show active\");\n $this.next().slideUp($accordionSpeed);\n } else {\n $this.addClass(\"show active\");\n $this.next().slideDown($accordionSpeed);\n }\n }\n if ($scrollOnClick === 'yes' && $this.hasClass(\"active\")) {\n var $customIdOffsetVal = $customIdOffset ? parseFloat($customIdOffset) : 0;\n $('html, body').animate({\n scrollTop: $(this).data('scroll') - $customIdOffsetVal\n }, $srollSpeed);\n }\n ea.hooks.doAction(\"widgets.reinit\", $this.parent());\n ea.hooks.doAction(\"ea-advanced-accordion-triggered\", $this.next());\n });\n $scope.on('keydown', '.eael-accordion-header', function (e) {\n if (e.which === 13 || e.which === 32) {\n $(this).trigger('click');\n }\n });\n\n // If hashTag is not null then scroll to that hashTag smoothly\n if (typeof hashTag !== 'undefined' && hashTag && !ea.elementStatusCheck('eaelAdvancedAccordionScroll')) {\n var $customIdOffsetVal = $customIdOffset ? parseFloat($customIdOffset) : 0;\n $('html, body').animate({\n scrollTop: $(\"#\" + hashTag).offset().top - $customIdOffsetVal\n }, $srollSpeed);\n }\n });\n});\n\n//# sourceURL=webpack:///./src/js/view/advanced-accordion.js?");

/***/ })

Expand Down
2 changes: 1 addition & 1 deletion assets/front-end/js/view/advanced-accordion.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 2 additions & 17 deletions src/js/view/advanced-accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,13 @@ ea.hooks.addAction("init", "ea", () => {

var $this = $(this);

//
setTimeout(() => {
$('html, body').animate({
scrollTop: $this.offset().top - $customIdOffset
}, 500);
}, 500);

if ($accordionType === "accordion") {
if ($this.hasClass("show")) {
$this.removeClass("show active");
$this.next().slideUp($accordionSpeed);
} else {
$this
.parent()
.parent()
.find(".eael-accordion-header")
.removeClass("show active");
$this
.parent()
.parent()
.find(".eael-accordion-content")
.slideUp($accordionSpeed);
$this.parent().parent().find(".eael-accordion-header").removeClass("show active");
$this.parent().parent().find(".eael-accordion-content").slideUp($accordionSpeed);
$this.toggleClass("show active");
$this.next().slideToggle($accordionSpeed);
}
Expand Down

0 comments on commit 99ec975

Please sign in to comment.