Add JQuery plugin Chained
This commit is contained in:
73
public/scripts/3rdparty/jquery.chained.js
vendored
Normal file
73
public/scripts/3rdparty/jquery.chained.js
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Chained - jQuery non AJAX(J) chained selects plugin
|
||||
*
|
||||
* Copyright (c) 2010-2011 Mika Tuupola
|
||||
*
|
||||
* Licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
|
||||
$.fn.chained = function(parent_selector, options) {
|
||||
|
||||
return this.each(function() {
|
||||
|
||||
/* Save this to self because this changes when scope changes. */
|
||||
var self = this;
|
||||
var backup = $(self).clone();
|
||||
|
||||
/* Handles maximum two parents now. */
|
||||
$(parent_selector).each(function() {
|
||||
|
||||
$(this).bind("change", function() {
|
||||
$(self).html(backup.html());
|
||||
|
||||
/* If multiple parents build classname like foo\bar. */
|
||||
var selected = "";
|
||||
$(parent_selector).each(function() {
|
||||
selected += "\\" + $(":selected", this).val();
|
||||
});
|
||||
selected = selected.substr(1);
|
||||
|
||||
/* Also check for first parent without subclassing. */
|
||||
/* TODO: This should be dynamic and check for each parent */
|
||||
/* without subclassing. */
|
||||
var first = $(parent_selector).first();
|
||||
var selected_first = $(":selected", first).val();
|
||||
|
||||
$("option", self).each(function() {
|
||||
/* Remove unneeded items but save the default value. */
|
||||
if (!$(this).hasClass(selected) &&
|
||||
!$(this).hasClass(selected_first) && $(this).val() !== "") {
|
||||
$(this).remove();
|
||||
}
|
||||
});
|
||||
|
||||
/* If we have only the default value disable select. */
|
||||
if (1 == $("option", self).size() && $(self).val() === "") {
|
||||
$(self).attr("disabled", "disabled");
|
||||
} else {
|
||||
$(self).removeAttr("disabled");
|
||||
}
|
||||
$(self).trigger("change");
|
||||
});
|
||||
|
||||
/* Force IE to see something selected on first page load, */
|
||||
/* unless something is already selected */
|
||||
if ( !$("option:selected", this).length ) {
|
||||
$("option", this).first().attr("selected", "selected");
|
||||
}
|
||||
|
||||
/* Force updating the children. */
|
||||
$(this).trigger("change");
|
||||
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/* Alias for those who like to use more English like syntax. */
|
||||
$.fn.chainedTo = $.fn.chained;
|
||||
|
||||
})(jQuery);
|
||||
@@ -15,6 +15,7 @@
|
||||
<link type="text/css" href="{$base_uri}styles/3rdparty/jquery.asmselect.css" rel="Stylesheet" />
|
||||
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
|
||||
<script type="text/javascript" src="{$base_uri}scripts/3rdparty/jquery.chained.js"></script>
|
||||
<script type="text/javascript" src="{$base_uri}scripts/main.js"></script>
|
||||
<link rel="stylesheet/less" href="{$base_uri}less/bootstrap.less" media="all" />
|
||||
<script type="text/javascript" src="{$base_uri}scripts/3rdparty/less-1.1.5.min.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user