Author: jablko
Date: Mon Aug 31 15:46:36 2009
New Revision: 3131

Log:
Add JavaScript behavior to progressively enhance <select multiple="multiple"> 
elements, highlighting the list of selected items -- force

Added:
   trunk/web/js/select.js   (contents, props changed)
Modified:
   trunk/apps/qubit/modules/informationobject/config/view.yml

Modified: trunk/apps/qubit/modules/informationobject/config/view.yml
==============================================================================
--- trunk/apps/qubit/modules/informationobject/config/view.yml  Mon Aug 31 
12:20:38 2009        (r3130)
+++ trunk/apps/qubit/modules/informationobject/config/view.yml  Mon Aug 31 
15:46:36 2009        (r3131)
@@ -1,14 +1,14 @@
 editDcSuccess:
-  javascripts: [/sfDrupalPlugin/vendor/drupal/misc/collapse, 
/sfDrupalPlugin/vendor/drupal/misc/textarea, multiDelete, multiInstanceInput, 
multiInstanceSelect]
+  javascripts: [/sfDrupalPlugin/vendor/drupal/misc/collapse, 
/sfDrupalPlugin/vendor/drupal/misc/textarea, multiDelete, multiInstanceInput, 
multiInstanceSelect, select]
 
 editIsadSuccess:
-  javascripts: [/sfDrupalPlugin/vendor/drupal/misc/collapse, 
/sfDrupalPlugin/vendor/drupal/misc/textarea, multiDelete, multiInstanceInput, 
multiInstanceSelect]
+  javascripts: [/sfDrupalPlugin/vendor/drupal/misc/collapse, 
/sfDrupalPlugin/vendor/drupal/misc/textarea, multiDelete, multiInstanceInput, 
multiInstanceSelect, select]
 
 editRadSuccess:
-  javascripts: [/sfDrupalPlugin/vendor/drupal/misc/collapse, 
/sfDrupalPlugin/vendor/drupal/misc/textarea, multiDelete, multiInstanceInput, 
multiInstanceSelect]
+  javascripts: [/sfDrupalPlugin/vendor/drupal/misc/collapse, 
/sfDrupalPlugin/vendor/drupal/misc/textarea, multiDelete, multiInstanceInput, 
multiInstanceSelect, select]
 
 editModsSuccess:
-  javascripts: [/sfDrupalPlugin/vendor/drupal/misc/collapse, 
/sfDrupalPlugin/vendor/drupal/misc/textarea, multiDelete, multiInstanceInput, 
multiInstanceSelect]
+  javascripts: [/sfDrupalPlugin/vendor/drupal/misc/collapse, 
/sfDrupalPlugin/vendor/drupal/misc/textarea, multiDelete, multiInstanceInput, 
multiInstanceSelect, select]
 
 listSuccess:
   javascripts: [actions]

Added: trunk/web/js/select.js
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/web/js/select.js      Mon Aug 31 15:46:36 2009        (r3131)
@@ -0,0 +1,72 @@
+// $Id$
+
+Drupal.behaviors.select = {
+  select: function (option, name, ul)
+    {
+      // Disable <option>
+      $(option).attr('disabled', 'disabled');
+
+      // Make <li> of hidden <input> with <option> value, and <span> with
+      // <option> HTML contents
+      $(<li><input name={name} type="hidden" 
value={$(option).val()}/><span>{XML($(option).html())}</span></li>.toXMLString())
+        .click(function ()
+          {
+            // On click, remove <li> and enable <option>
+            $(this).hide('fast', function ()
+              {
+                $(this).remove();
+              });
+
+            $(option).removeAttr('disabled');
+          })
+        .appendTo(ul);
+    },
+  attach: function (context)
+    {
+      $('select[multiple]', context).each(function ()
+        {
+          // Share <select> name with nested scopes
+          var name = $(this).attr('name');
+
+          // Make <ul> of selected <option>s
+          var ul = $(<ul/>.toXMLString()).insertBefore(this)[0];
+
+          $('option:selected', this).each(function ()
+            {
+              // Disable <option> and make <li>
+              Drupal.behaviors.select.select(this, name, ul);
+            });
+
+          // Add blank option for clearing <select>
+          var blank = $(<option/>.toXMLString())
+            .attr('selected', 'selected')
+            .prependTo(this)[0];
+
+          $(this)
+
+            // Change multiple <select> to single <select>
+            .removeAttr('multiple')
+
+            // Remove @name to avoid submitting single <select> along with
+            // selected options
+            .removeAttr('name')
+
+            .bind('blur click keydown', function (event)
+              {
+                if ($(this).val() && ('keydown' != event.type || 9 == 
event.keyCode))
+                {
+                  // Cancel default action so as not to loose focus
+                  if ('keydown' == event.type)
+                  {
+                    event.preventDefault();
+                  }
+
+                  // Disable <option> and make <li>
+                  Drupal.behaviors.select.select($('option:selected', 
this)[0], name, ul);
+
+                  // Clear <select>
+                  $(blank).attr('selected', 'selected');
+                }
+              });
+        });
+    } };

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to