From f818449e72bc62d8de45011bd781e6713913bc55 Mon Sep 17 00:00:00 2001 From: Gee Date: Thu, 21 Jul 2005 23:45:17 +0000 Subject: [PATCH] Functions for lists and dropdowns. This was SVN commit r2508. --- .../mods/official/gui/test/functions_list.js | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 binaries/data/mods/official/gui/test/functions_list.js diff --git a/binaries/data/mods/official/gui/test/functions_list.js b/binaries/data/mods/official/gui/test/functions_list.js new file mode 100644 index 0000000000..200e72fc00 --- /dev/null +++ b/binaries/data/mods/official/gui/test/functions_list.js @@ -0,0 +1,53 @@ +/* + *************************************** + functions_list.js + + Functions to manipulate objects with + a 'list' property. It is important to + do this and not manually to ensure that + the selection is updated properly. + + *************************************** +*/ + +function removeItem(objectName, pos) +{ + var list = getGUIObjectByName(objectName).list; + var selected = getGUIObjectByName(objectName).selected; + list.splice(pos, 1); + + getGUIObjectByName(objectName).list = list; + + // It is important that we're setting the new selection *after* + // the list is already updated. + + // Update the selected so the same element remains selected + if (selected == pos) + { + getGUIObjectByName(objectName).selected = -1; + } + else + if (selected > pos) + { + getGUIObjectByName(objectName).selected = selected - 1; + } +} + +function addItem(objectName, pos, value) +{ + var list = getGUIObjectByName(objectName).list; + var selected = getGUIObjectByName(objectName).selected; + list.splice(pos, 0, value); + + getGUIObjectByName(objectName).list = list; + + // It is important that we're setting the new selection *after* + // the list is already updated. + + // Update the selected so the same element remains selected + if (selected >= pos) + { + getGUIObjectByName(objectName).selected = selected + 1; + } + +} \ No newline at end of file