diff options
Diffstat (limited to 'static/admin/js/SelectBox.js')
-rw-r--r-- | static/admin/js/SelectBox.js | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/static/admin/js/SelectBox.js b/static/admin/js/SelectBox.js index 1a14959..95825d8 100644 --- a/static/admin/js/SelectBox.js +++ b/static/admin/js/SelectBox.js @@ -1,4 +1,4 @@ -(function($) { +(function() { 'use strict'; var SelectBox = { cache: {}, @@ -7,10 +7,8 @@ var node; SelectBox.cache[id] = []; var cache = SelectBox.cache[id]; - var boxOptions = box.options; - var boxOptionsLength = boxOptions.length; - for (var i = 0, j = boxOptionsLength; i < j; i++) { - node = boxOptions[i]; + for (var i = 0, j = box.options.length; i < j; i++) { + node = box.options[i]; cache.push({value: node.value, text: node.text, displayed: 1}); } }, @@ -18,8 +16,7 @@ // Repopulate HTML select box from cache var box = document.getElementById(id); var node; - $(box).empty(); // clear all options - var new_options = box.outerHTML.slice(0, -9); // grab just the opening tag + box.options.length = 0; // clear all options var cache = SelectBox.cache[id]; for (var i = 0, j = cache.length; i < j; i++) { node = cache[i]; @@ -27,11 +24,9 @@ var new_option = new Option(node.text, node.value, false, false); // Shows a tooltip when hovering over the option new_option.setAttribute("title", node.text); - new_options += new_option.outerHTML; + box.options[box.options.length] = new_option; } } - new_options += '</select>'; - box.outerHTML = new_options; }, filter: function(id, text) { // Redisplay the HTML select box, displaying only the choices containing ALL @@ -42,13 +37,11 @@ for (var i = 0, j = cache.length; i < j; i++) { node = cache[i]; node.displayed = 1; - var node_text = node.text.toLowerCase(); var numTokens = tokens.length; for (var k = 0; k < numTokens; k++) { token = tokens[k]; - if (node_text.indexOf(token) === -1) { + if (node.text.toLowerCase().indexOf(token) === -1) { node.displayed = 0; - break; // Once the first token isn't found we're done } } } @@ -64,7 +57,11 @@ break; } } - cache.splice(delete_index, 1); + var k = cache.length - 1; + for (i = delete_index; i < k; i++) { + cache[i] = cache[i + 1]; + } + cache.length--; }, add_to_cache: function(id, option) { SelectBox.cache[id].push({value: option.value, text: option.text, displayed: 1}); @@ -85,13 +82,11 @@ var from_box = document.getElementById(from); var option; var boxOptions = from_box.options; - var boxOptionsLength = boxOptions.length; - for (var i = 0, j = boxOptionsLength; i < j; i++) { + for (var i = 0, j = boxOptions.length; i < j; i++) { option = boxOptions[i]; - var option_value = option.value; - if (option.selected && SelectBox.cache_contains(from, option_value)) { - SelectBox.add_to_cache(to, {value: option_value, text: option.text, displayed: 1}); - SelectBox.delete_from_cache(from, option_value); + if (option.selected && SelectBox.cache_contains(from, option.value)) { + SelectBox.add_to_cache(to, {value: option.value, text: option.text, displayed: 1}); + SelectBox.delete_from_cache(from, option.value); } } SelectBox.redisplay(from); @@ -101,13 +96,11 @@ var from_box = document.getElementById(from); var option; var boxOptions = from_box.options; - var boxOptionsLength = boxOptions.length; - for (var i = 0, j = boxOptionsLength; i < j; i++) { + for (var i = 0, j = boxOptions.length; i < j; i++) { option = boxOptions[i]; - var option_value = option.value; - if (SelectBox.cache_contains(from, option_value)) { - SelectBox.add_to_cache(to, {value: option_value, text: option.text, displayed: 1}); - SelectBox.delete_from_cache(from, option_value); + if (SelectBox.cache_contains(from, option.value)) { + SelectBox.add_to_cache(to, {value: option.value, text: option.text, displayed: 1}); + SelectBox.delete_from_cache(from, option.value); } } SelectBox.redisplay(from); @@ -133,12 +126,10 @@ }, select_all: function(id) { var box = document.getElementById(id); - var boxOptions = box.options; - var boxOptionsLength = boxOptions.length; - for (var i = 0; i < boxOptionsLength; i++) { - boxOptions[i].selected = 'selected'; + for (var i = 0; i < box.options.length; i++) { + box.options[i].selected = 'selected'; } } }; window.SelectBox = SelectBox; -})(django.jQuery); +})(); |