diff --git media.admin.inc media.admin.inc
index 2c74b99..5b1343e 100644
--- media.admin.inc
+++ media.admin.inc
@@ -31,7 +31,7 @@ function media_admin($form, $form_state) {
   }
 
   require_once dirname(__FILE__) . '/media.browser.inc';
-  media_include_browser_js();
+  media_attach_browser_js($form);
   
   $types = media_display_types();
 
diff --git media.browser.inc media.browser.inc
index 543b9dc..e9633de 100644
--- media.browser.inc
+++ media.browser.inc
@@ -293,41 +293,50 @@ function _media_recursive_check_plain(&$value, $key) {
 }
 
 /**
- * Prepares the page to be able to launch the media browser.
+ * Attaches media browser javascript to an element.
  *
- * @TODO: This is a WTF at present.  Basically, the browser is launched from wysiwyg
- * and from fields, so having a common function makes sense.  But not like this.
- *
- * Defines default variables.
+ * @param $element
+ *  The element array to attach to.
  */
-function media_include_browser_js() {
-  static $included;
-  if ($included) {
-    return;
+function media_attach_browser_js(&$element) {
+  $javascript = media_browser_js();
+  foreach ($javascript as $key => $definitions) {
+    foreach ($definitions as $definition) {
+      $element['#attached'][$key][] = $definition;
+    }
   }
-  $included = TRUE;
-  drupal_add_library('media', 'media_browser');
+}
 
+/**
+ * Helper function to define browser javascript.
+ */
+function media_browser_js() {
   $settings = array(
     'browserUrl' => url('media/browser',
       array('query' => array('render' => 'media-popup'))),
     'styleSelectorUrl' => url('media/-media_id-/format-form',
       array('query' => array('render' => 'media-popup'))),
-
-    // Adding src to blacklist; fid and view_mode we capture outside attribs so adding
-    // them too to the blacklist.
-    'blacklist' => array('src','fid','view_mode','format'), // Only applies to WYSIWG - should be removed;
   );
 
-  drupal_add_js(array('media' => $settings), 'setting');
+  $js = array(
+    'library' => array(
+      array('media', 'media_browser'),
+    ),
+    'js' => array(
+      array(
+       'data' => array('media' => $settings),
+       'type' => 'setting',
+      ),
+    ), 
+  );
+  return $js;
 }
 
-
 /**
  * Menu callback for testing the media browser
  */
 function media_browser_testbed($form) {
-  media_include_browser_js();
+  media_attach_browser_js($form);
 
   $form['test_element'] = array(
     '#type' => 'media',
diff --git media.module media.module
index 9c804b9..8e6b6cc 100644
--- media.module
+++ media.module
@@ -1085,7 +1085,7 @@ function media_element_process(&$element, &$form_state, $form) {
   // All settings would likely apply to all media in a multi-value, but what about passing the existing fid?
 
   module_load_include('inc', 'media', 'media.browser');
-  media_include_browser_js();
+  media_attach_browser_js($element);
 
   return $element;
   // @todo: make this work for file and image fields
diff --git wysiwyg_plugins/media.inc wysiwyg_plugins/media.inc
index 6b619d9..ff86cb4 100644
--- wysiwyg_plugins/media.inc
+++ wysiwyg_plugins/media.inc
@@ -11,7 +11,8 @@
  */
 function media_media_plugin() {
   // Include the required browser JS.
-  module_load_include('inc', 'media', 'media.browser');
+  // @todo: wyswiyg should allow libraries and multiple js files
+  // to be defined by this hook.
   media_include_browser_js();
 
   // Plugin definition
@@ -36,3 +37,28 @@ function media_media_plugin() {
 
    return $plugins;
 }
+
+/**
+ * Prepares the page to be able to launch the media browser.
+ *
+ * Defines default variables.
+ */
+function media_include_browser_js() {
+  static $included;
+  if ($included) {
+    return;
+  }
+  $included = TRUE;
+  module_load_include('inc', 'media', 'media.browser');
+  $javascript = media_browser_js();
+  foreach ($javascript as $key => $definitions) {
+    foreach ($definitions as $definition) {
+      $function = 'drupal_add_' . $key;
+      // Since the arguments to pass are variable, use call_user_func_array().
+      call_user_func_array($function, $definition);
+    }
+  }
+  // Add wysiwyg-specific settings.
+  $settings = array('blacklist' => array('src','fid','view_mode','format'));
+  drupal_add_js(array('media' => $settings), 'setting');
+}
