From 61e6fdd004653a893f31329e68854e1fcd84f96c Mon Sep 17 00:00:00 2001 From: Shannon McPherson Date: Mon, 13 May 2019 14:02:39 -0700 Subject: [PATCH 1/4] apply https://github.com/benwbrum/jquery_chained/commit/d48884a330b252ede117f2beefea6a501177f90d#diff-d6dc038af4fe6b30c023109623978450 on 1.0.1 --- jquery.chained.js | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/jquery.chained.js b/jquery.chained.js index 2364e96..dfc3447 100644 --- a/jquery.chained.js +++ b/jquery.chained.js @@ -47,22 +47,15 @@ $(child).html(backup.html()); /* If multiple parents build classname like foo\bar. */ - var selected = ""; + var selected = []; $(parent_selector).each(function() { - var selectedClass = $("option:selected", this).val(); - if (selectedClass) { - if (selected.length > 0) { - if (window.Zepto) { - /* Zepto class regexp dies with classes like foo\bar. */ - selected += "\\\\"; - } else { - selected += "\\"; - } - } - selected += selectedClass; - } + $(":selected", this).each(function() { + selected.push($(this).val()); + }); }); + + /* Also check for first parent without subclassing. */ /* TODO: This should be dynamic and check for each parent */ /* without subclassing. */ @@ -75,11 +68,16 @@ var selected_first = $("option:selected", first).val(); $("option", child).each(function() { - /* Remove unneeded items but save the default value. */ - if ($(this).hasClass(selected) && $(this).val() === currently_selected_value) { - $(this).prop("selected", true); - trigger_change = false; - } else if (!$(this).hasClass(selected) && !$(this).hasClass(selected_first) && $(this).val() !== "") { + var hasSelectedClass = false; + var classList = ($(this).attr('class') == undefined || "" ) ? [] : $(this).attr('class').split(/\s+/); + $.each( classList, function(index, item){ + if (jQuery.inArray(item, selected) >= 0) { + hasSelectedClass = true; + return; + } + }); + if (!hasSelectedClass && + !$(this).hasClass(selected_first) && $(this).val() !== "") { $(this).remove(); } }); From 2e192f247fcc41d29a6c49bb6c39b382bdb82ebb Mon Sep 17 00:00:00 2001 From: Shannon McPherson Date: Wed, 21 Oct 2020 11:03:24 -0700 Subject: [PATCH 2/4] adds support for >1 value being passed to remote select --- jquery.chained.remote.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/jquery.chained.remote.js b/jquery.chained.remote.js index 46d2ff2..99a3044 100644 --- a/jquery.chained.remote.js +++ b/jquery.chained.remote.js @@ -17,7 +17,6 @@ "use strict"; $.fn.remoteChained = function(options) { - var settings = $.extend({}, $.fn.remoteChained.defaults, options); /* Loading text always clears the select. */ @@ -38,7 +37,13 @@ var data = {}; $(settings.parents).each(function() { var id = $(this).attr(settings.attribute); - var value = ($(this).is("select") ? $(":selected", this) : $(this)).val(); + var value = [] + + + $(":selected", this).each(function() { + value.push($(this).val()); + }); + data[id] = value; /* Optionally also depend on values from these inputs. */ @@ -164,4 +169,4 @@ clear : false }; -})(window.jQuery || window.Zepto, window, document); \ No newline at end of file +})(window.jQuery || window.Zepto, window, document); From 79ba398450a61c63824a0b15963bfd701ecc8c44 Mon Sep 17 00:00:00 2001 From: William Burns Date: Fri, 5 Jan 2024 17:37:03 -0500 Subject: [PATCH 3/4] Restore support for chaining to non-select fields --- jquery.chained.remote.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/jquery.chained.remote.js b/jquery.chained.remote.js index 99a3044..ed922e0 100644 --- a/jquery.chained.remote.js +++ b/jquery.chained.remote.js @@ -39,10 +39,13 @@ var id = $(this).attr(settings.attribute); var value = [] - - $(":selected", this).each(function() { + if($(this).is("select")) { + $(":selected", this).each(function() { + value.push($(this).val()); + }); + } else { value.push($(this).val()); - }); + } data[id] = value; From e57b00f07edcfbe4c27b5c2110c8e5f507ae85de Mon Sep 17 00:00:00 2001 From: William Burns Date: Fri, 5 Jan 2024 17:59:45 -0500 Subject: [PATCH 4/4] Minify JS by running 'grunt --force' --- jquery.chained.min.js | 5 +++-- jquery.chained.remote.min.js | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/jquery.chained.min.js b/jquery.chained.min.js index a70ce03..4710558 100644 --- a/jquery.chained.min.js +++ b/jquery.chained.min.js @@ -1,2 +1,3 @@ -/*! Chained 1.0.0 - MIT license - Copyright 2010-2017 Mika Tuupola */ -!function(a,b,c,d){"use strict";a.fn.chained=function(c){return this.each(function(){function d(){var d=!0,g=a("option:selected",e).val();a(e).html(f.html());var h="";a(c).each(function(){var c=a("option:selected",this).val();c&&(h.length>0&&(h+=b.Zepto?"\\\\":"\\"),h+=c)});var i;i=a.isArray(c)?a(c[0]).first():a(c).first();var j=a("option:selected",i).val();a("option",e).each(function(){a(this).hasClass(h)&&a(this).val()===g?(a(this).prop("selected",!0),d=!1):a(this).hasClass(h)||a(this).hasClass(j)||""===a(this).val()||a(this).remove()}),1===a("option",e).length&&""===a(e).val()?a(e).prop("disabled",!0):a(e).prop("disabled",!1),d&&a(e).trigger("change")}var e=this,f=a(e).clone();a(c).each(function(){a(this).bind("change",function(){d()}),a("option:selected",this).length||a("option",this).first().attr("selected","selected"),d()})})},a.fn.chainedTo=a.fn.chained,a.fn.chained.defaults={}}(window.jQuery||window.Zepto,window,document); \ No newline at end of file +/*! Chained 1.0.1 - MIT license - Copyright 2010-2017 Mika Tuupola */ + +!function(a,b,c,d){"use strict";a.fn.chained=function(b){return this.each(function(){function c(){a("option:selected",e).val();a(e).html(f.html());var c=[];a(b).each(function(){a(":selected",this).each(function(){c.push(a(this).val())})});var g;g=a.isArray(b)?a(b[0]).first():a(b).first();var h=a("option:selected",g).val();a("option",e).each(function(){var b=!1,e=a(this).attr("class")==d?[]:a(this).attr("class").split(/\s+/);a.each(e,function(a,d){if(jQuery.inArray(d,c)>=0)return void(b=!0)}),b||a(this).hasClass(h)||""===a(this).val()||a(this).remove()}),1===a("option",e).length&&""===a(e).val()?a(e).prop("disabled",!0):a(e).prop("disabled",!1),a(e).trigger("change")}var e=this,f=a(e).clone();a(b).each(function(){a(this).bind("change",function(){c()}),a("option:selected",this).length||a("option",this).first().attr("selected","selected"),c()})})},a.fn.chainedTo=a.fn.chained,a.fn.chained.defaults={}}(window.jQuery||window.Zepto,window,document); \ No newline at end of file diff --git a/jquery.chained.remote.min.js b/jquery.chained.remote.min.js index e89ce59..e8c2877 100644 --- a/jquery.chained.remote.min.js +++ b/jquery.chained.remote.min.js @@ -1,2 +1,3 @@ -/*! Chained 1.0.0 - MIT license - Copyright 2010-2017 Mika Tuupola */ -!function(a,b,c,d){"use strict";a.fn.remoteChained=function(b){var c=a.extend({},a.fn.remoteChained.defaults,b);return c.loading&&(c.clear=!0),this.each(function(){function b(b){var c=a(":selected",d).val();a("option",d).remove();var e=[];if(a.isArray(b))e=a.isArray(b[0])?b:a.map(b,function(b){return a.map(b,function(a,b){return[[b,a]]})});else for(var f in b)b.hasOwnProperty(f)&&e.push([f,b[f]]);for(var g=0;g!==e.length;g++){var h=e[g][0],i=e[g][1];if("selected"!==h){var j=a("