summaryrefslogtreecommitdiff
path: root/src/www/js
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2013-04-04 14:04:31 +0000
committerhallgren <hallgren@chalmers.se>2013-04-04 14:04:31 +0000
commit3c244ff27f015df6cfa918c9ba3e192f4d5b62ff (patch)
tree6dcc6016bd180b863cd5136d0f9ea1646b566799 /src/www/js
parenta22a419bc7ea0dc45f9965e6ffebf42417212d52 (diff)
minibar/syntax editor integration improvements
Work in progress on preserving the start category and selected target languages when switching between the minibar and the syntax editor.
Diffstat (limited to 'src/www/js')
-rw-r--r--src/www/js/support.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/www/js/support.js b/src/www/js/support.js
index e8b7e7878..27207ac2e 100644
--- a/src/www/js/support.js
+++ b/src/www/js/support.js
@@ -259,6 +259,25 @@ function toggleHidden(el) {
el.classList.add("hidden")
}
+// Update the selected options in a menu that allow multiple selections
+function updateMultiMenu(menu,selection) {
+ var set=toSet(selection)
+ var os=menu.options
+ for(var i=0;i<os.length;i++)
+ os[i].selected=set[os[i].value] || false
+}
+
+/* --- Document data extraction --------------------------------------------- */
+
+// List the selected options in a menu that allows multiple selections
+function multiMenuSelections(menu) {
+ var selection=[]
+ var os=menu.options;
+ for(var i=0;i<os.length;i++)
+ if(os[i].selected) selection.push(os[i].value)
+ return selection
+}
+
/* --- Debug ---------------------------------------------------------------- */
function debug(s) {
@@ -369,3 +388,10 @@ function shuffle(a) {
for(i=0;i<a.length;i++) swap(a,i,Math.floor(Math.random()*a.length))
return a;
}
+
+// Convert an array of strings to a set (for quick & easy membership tests)
+function toSet(a) {
+ var set={}
+ for(var i=0;i<a.length;i++) set[a[i]]=true
+ return set
+}