Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2.0.0 beta.4 #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 16 additions & 18 deletions jquery.chained.js
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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();
}
});
Expand Down
5 changes: 3 additions & 2 deletions jquery.chained.min.js

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

14 changes: 11 additions & 3 deletions jquery.chained.remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"use strict";

$.fn.remoteChained = function(options) {

var settings = $.extend({}, $.fn.remoteChained.defaults, options);

/* Loading text always clears the select. */
Expand All @@ -38,7 +37,16 @@
var data = {};
$(settings.parents).each(function() {
var id = $(this).attr(settings.attribute);
var value = ($(this).is("select") ? $(":selected", this) : $(this)).val();
var value = []

if($(this).is("select")) {
$(":selected", this).each(function() {
value.push($(this).val());
});
} else {
value.push($(this).val());
}

data[id] = value;

/* Optionally also depend on values from these inputs. */
Expand Down Expand Up @@ -164,4 +172,4 @@
clear : false
};

})(window.jQuery || window.Zepto, window, document);
})(window.jQuery || window.Zepto, window, document);
5 changes: 3 additions & 2 deletions jquery.chained.remote.min.js

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