From: Kevin Ball Date: Tue, 15 Nov 2016 01:13:39 +0000 (-0800) Subject: Update toggle to bubble up if no target is defined X-Git-Tag: v6.3-rc1~6^2~7^2~5^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05d52cb8bc6ec005dbed21b68d4e1b1bf8cccc00;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Update toggle to bubble up if no target is defined --- diff --git a/js/foundation.util.triggers.js b/js/foundation.util.triggers.js index b9cbfda4f..50b3f360d 100644 --- a/js/foundation.util.triggers.js +++ b/js/foundation.util.triggers.js @@ -36,7 +36,12 @@ $(document).on('click.zf.trigger', '[data-close]', function() { // Elements with [data-toggle] will toggle a plugin that supports it when clicked. $(document).on('click.zf.trigger', '[data-toggle]', function() { - triggers($(this), 'toggle'); + let id = $(this).data('toggle'); + if (id) { + triggers($(this), 'toggle'); + } else { + $(this).trigger('toggle.zf.trigger'); + } }); // Elements with [data-closable] will respond to close.zf.trigger events. @@ -165,7 +170,7 @@ function mutateListener(debounce) { function eventsListener() { if(!MutationObserver){ return false; } let nodes = document.querySelectorAll('[data-resize], [data-scroll], [data-mutate]'); - + //element callback var listeningElementsMutation = function (mutationRecordsList) { var $target = $(mutationRecordsList[0].target); @@ -174,14 +179,14 @@ function eventsListener() { switch (mutationRecordsList[0].type) { case "attributes": - if ($target.attr("data-events") === "scroll" && mutationRecordsList[0].attributeName === "data-events") { - $target.triggerHandler('scrollme.zf.trigger', [$target, window.pageYOffset]); + if ($target.attr("data-events") === "scroll" && mutationRecordsList[0].attributeName === "data-events") { + $target.triggerHandler('scrollme.zf.trigger', [$target, window.pageYOffset]); } - if ($target.attr("data-events") === "resize" && mutationRecordsList[0].attributeName === "data-events") { + if ($target.attr("data-events") === "resize" && mutationRecordsList[0].attributeName === "data-events") { $target.triggerHandler('resizeme.zf.trigger', [$target]); } if (mutationRecordsList[0].attributeName === "style") { - $target.closest("[data-mutate]").attr("data-events","mutate"); + $target.closest("[data-mutate]").attr("data-events","mutate"); $target.closest("[data-mutate]").triggerHandler('mutateme.zf.trigger', [$target.closest("[data-mutate]")]); } break; @@ -190,7 +195,7 @@ function eventsListener() { $target.closest("[data-mutate]").attr("data-events","mutate"); $target.closest("[data-mutate]").triggerHandler('mutateme.zf.trigger', [$target.closest("[data-mutate]")]); break; - + default: return false; //nothing diff --git a/test/visual/triggers/containing-toggle.html b/test/visual/triggers/containing-toggle.html new file mode 100644 index 000000000..ad76ee801 --- /dev/null +++ b/test/visual/triggers/containing-toggle.html @@ -0,0 +1,40 @@ + + + + + + + Foundation for Sites Testing + + + +
+

Triggers: Contained

+ +

This callout has a trigger inside of it with an id. Triggering it should toggle the type

+ +
+

You can toggle this

+ +
+ +

This callout has a trigger inside of it WITHOUT an id. Triggering it should also toggle the type

+ +
+

You can toggle this

+ +
+
+ + + + + + +