vendor: 3,917 bytes, lines 1-110
1/* 2 * Chained - jQuery / Zepto chained selects plugin 3 * 4 * Copyright (c) 2010-2017 Mika Tuupola 5 * 6 * Licensed under the MIT license: 7 * http://www.opensource.org/licenses/mit-license.php 8 * 9 * Project home: 10 * http://www.appelsiini.net/projects/chained 11 * 12 * Version: 2.0.0-beta.3 13 * 14 */ 15 16;(function($, window, document, undefined) { 17 "use strict"; 18 19 $.fn.chained = function(parentSelector) { 20 return this.each(function() { 21 22 /* Save this to child because this changes when scope changes. */ 23 var child = this; 24 var backup = $(child).clone(); 25 26 /* Handles maximum two parents now. */ 27 $(parentSelector).each(function() { 28 $(this).bind("change", function() { 29 updateChildren(); 30 }); 31 32 /* Force IE to see something selected on first page load, */ 33 /* unless something is already selected */ 34 if (!$("option:selected", this).length) { 35 $("option", this).first().attr("selected", "selected"); 36 } 37 38 /* Force updating the children. */ 39 updateChildren(); 40 }); 41 42 function updateChildren() { 43 var triggerChange = true; 44 var currentlySelectedValue = $("option:selected", child).val(); 45 46 $(child).html(backup.html()); 47 48 /* If multiple parents build value like foo+bar. */ 49 var selected = ""; 50 $(parentSelector).each(function() { 51 var selectedValue = $("option:selected", this).val(); 52 if (selectedValue) { 53 if (selected.length > 0) { 54 selected += "+"; 55 } 56 selected += selectedValue; 57 } 58 }); 59 60 /* Also check for first parent without subclassing. */ 61 /* TODO: This should be dynamic and check for each parent */ 62 /* without subclassing. */ 63 var first; 64 if ($.isArray(parentSelector)) { 65 first = $(parentSelector[0]).first(); 66 } else { 67 first = $(parentSelector).first(); 68 } 69 var selectedFirst = $("option:selected", first).val(); 70 71 $("option", child).each(function() { 72 /* Always leave the default value in place. */ 73 if ($(this).val() === "") { 74 return; 75 } 76 var matches = []; 77 var data = String($(this).data("chained")); 78 if (data) { 79 matches = data.split(" "); 80 } 81 if ((matches.indexOf(selected) > -1) || (matches.indexOf(selectedFirst) > -1)) { 82 if ($(this).val() === currentlySelectedValue) { 83 $(this).prop("selected", true); 84 triggerChange = false; 85 } 86 } else { 87 $(this).remove(); 88 } 89 }); 90 91 /* If we have only the default value disable select. */ 92 if (1 === $("option", child).length && $(child).val() === "") { 93 $(child).prop("disabled", true); 94 } else { 95 $(child).prop("disabled", false); 96 } 97 if (triggerChange) { 98 $(child).trigger("change"); 99 } 100 } 101 }); 102 }; 103 104 /* Alias for those who like to use more English like syntax. */ 105 $.fn.chainedTo = $.fn.chained; 106 107 /* Default settings for plugin. */ 108 $.fn.chained.defaults = {}; 109 110})(window.jQuery || window.Zepto, window, document);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.