From 17d2deb7cf09e7576faba3f1af65ee5e1b5828fa Mon Sep 17 00:00:00 2001 From: Kristoffer Svanmark Date: Tue, 11 Oct 2016 14:00:20 +0200 Subject: [PATCH] Do not show expand/collapse button if theres nothing to expand/collapse --- dist/js/acf-ux-collapse.dev.js | 8 ++++++-- dist/js/acf-ux-collapse.min.js | 2 +- source/js/FieldTypes/Repeater.js | 8 ++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/dist/js/acf-ux-collapse.dev.js b/dist/js/acf-ux-collapse.dev.js index 7f932fb..93b84d5 100644 --- a/dist/js/acf-ux-collapse.dev.js +++ b/dist/js/acf-ux-collapse.dev.js @@ -40,20 +40,24 @@ AcfUxCollapse.FieldTypes.Repeater = (function ($) { Repeater.prototype.init = function (field) { var $field = $(field); + varĀ $cloneRow = $field.find('> .acf-input > .acf-repeater > table > tbody > .acf-row.acf-clone'); + $cloneRow.removeClass('acf-clone'); + $field.find('> .acf-input > .acf-repeater > table > tbody > .acf-row').each(function (index, element) { $(element).removeClass('-collapsed'); - if (!$(element).hasClass('acf-clone') && $(element).height() <= 150) { + if ($(element).height() <= 150) { return; } $(element).addClass('acf-collapser-initialized'); $(element).find('.acf-fields').wrapInner('
'); + $(element).find('.acf-row-handle.order').append('
'); this.toggle(element); }.bind(this)); - $field.find('.acf-collapser-initialized > .acf-row-handle.order').append('
'); + $cloneRow.addClass('acf-clone'); }; /** diff --git a/dist/js/acf-ux-collapse.min.js b/dist/js/acf-ux-collapse.min.js index a47a4d4..b842f84 100644 --- a/dist/js/acf-ux-collapse.min.js +++ b/dist/js/acf-ux-collapse.min.js @@ -1 +1 @@ -var AcfUxCollapse={};AcfUxCollapse=AcfUxCollapse||{},AcfUxCollapse.FieldTypes=AcfUxCollapse.FieldTypes||{},AcfUxCollapse.FieldTypes.Repeater=function(a){function e(){a('div.inside.acf-fields.-top > .acf-field-repeater[data-type="repeater"]').each(function(a,e){this.init(e)}.bind(this)),a(document).on("click",'.acf-field-repeater[data-type="repeater"] .acf-collapser-initialized .acf-row-handle.order',function(e){this.toggle(a(e.target).closest("td").parent(".acf-row"))}.bind(this)),a(document).on("click",".acf-collapser-collapser-area",function(e){var l=a(e.target).closest(".acf-collapser-collapser-area"),c=l.parents(".acf-row");c.hasClass("acf-collapser-collapsed")&&this.toggle(c)}.bind(this))}return e.prototype.init=function(e){var l=a(e);l.find("> .acf-input > .acf-repeater > table > tbody > .acf-row").each(function(e,l){a(l).removeClass("-collapsed"),!a(l).hasClass("acf-clone")&&a(l).height()<=150||(a(l).addClass("acf-collapser-initialized"),a(l).find(".acf-fields").wrapInner('
'),this.toggle(l))}.bind(this)),l.find(".acf-collapser-initialized > .acf-row-handle.order").append('
')},e.prototype.toggle=function(e){var l=a(e);l.toggleClass("acf-collapser-collapsed"),l.hasClass("acf-collapser-collapsed")?l.find(".acf-collapser-icon").attr("data-text","Expand"):l.find(".acf-collapser-icon").attr("data-text","Collapse")},new e}(jQuery); \ No newline at end of file +var AcfUxCollapse={};AcfUxCollapse=AcfUxCollapse||{},AcfUxCollapse.FieldTypes=AcfUxCollapse.FieldTypes||{},AcfUxCollapse.FieldTypes.Repeater=function(a){function e(){a('div.inside.acf-fields.-top > .acf-field-repeater[data-type="repeater"]').each(function(a,e){this.init(e)}.bind(this)),a(document).on("click",'.acf-field-repeater[data-type="repeater"] .acf-collapser-initialized .acf-row-handle.order',function(e){this.toggle(a(e.target).closest("td").parent(".acf-row"))}.bind(this)),a(document).on("click",".acf-collapser-collapser-area",function(e){var l=a(e.target).closest(".acf-collapser-collapser-area"),c=l.parents(".acf-row");c.hasClass("acf-collapser-collapsed")&&this.toggle(c)}.bind(this))}return e.prototype.init=function(e){var l=a(e),c=l.find("> .acf-input > .acf-repeater > table > tbody > .acf-row.acf-clone");c.removeClass("acf-clone"),l.find("> .acf-input > .acf-repeater > table > tbody > .acf-row").each(function(e,l){a(l).removeClass("-collapsed"),a(l).height()<=150||(a(l).addClass("acf-collapser-initialized"),a(l).find(".acf-fields").wrapInner('
'),a(l).find(".acf-row-handle.order").append('
'),this.toggle(l))}.bind(this)),c.addClass("acf-clone")},e.prototype.toggle=function(e){var l=a(e);l.toggleClass("acf-collapser-collapsed"),l.hasClass("acf-collapser-collapsed")?l.find(".acf-collapser-icon").attr("data-text","Expand"):l.find(".acf-collapser-icon").attr("data-text","Collapse")},new e}(jQuery); \ No newline at end of file diff --git a/source/js/FieldTypes/Repeater.js b/source/js/FieldTypes/Repeater.js index 6ba38d7..76ae1e0 100644 --- a/source/js/FieldTypes/Repeater.js +++ b/source/js/FieldTypes/Repeater.js @@ -38,20 +38,24 @@ AcfUxCollapse.FieldTypes.Repeater = (function ($) { Repeater.prototype.init = function (field) { var $field = $(field); + varĀ $cloneRow = $field.find('> .acf-input > .acf-repeater > table > tbody > .acf-row.acf-clone'); + $cloneRow.removeClass('acf-clone'); + $field.find('> .acf-input > .acf-repeater > table > tbody > .acf-row').each(function (index, element) { $(element).removeClass('-collapsed'); - if (!$(element).hasClass('acf-clone') && $(element).height() <= 150) { + if ($(element).height() <= 150) { return; } $(element).addClass('acf-collapser-initialized'); $(element).find('.acf-fields').wrapInner('
'); + $(element).find('.acf-row-handle.order').append('
'); this.toggle(element); }.bind(this)); - $field.find('.acf-collapser-initialized > .acf-row-handle.order').append('
'); + $cloneRow.addClass('acf-clone'); }; /**