diff --git a/insert.js b/insert.js
index f2b5e79..2a07cc2 100644
--- a/insert.js
+++ b/insert.js
@@ -1,3 +1,7 @@
+/**
+ * @file
+ * JavaScript to activate "Insert" buttons on file and image fields.
+ */
 
 (function ($) {
 
@@ -37,10 +41,17 @@ Drupal.behaviors.insert.attach = function(context) {
     var style = $('.insert-style', wrapper).val();
     var content = $('input.insert-template[name$="[' + style + ']"]', wrapper).val();
     var filename = $('input.insert-filename', wrapper).val();
+    var options = {
+      widgetType: widgetType,
+      filename: filename,
+      style: style,
+      fields: {}
+    };
 
     // Update replacements.
     for (var fieldName in settings.fields) {
       var fieldValue = $(settings.fields[fieldName], wrapper).val();
+      options['fields'][fieldName] = fieldValue;
       if (fieldValue) {
         var fieldRegExp = new RegExp('__' + fieldName + '(_or_filename)?__', 'g');
         content = content.replace(fieldRegExp, fieldValue);
@@ -55,9 +66,6 @@ Drupal.behaviors.insert.attach = function(context) {
     var fieldRegExp = new RegExp('__filename__', 'g');
     content = content.replace(fieldRegExp, filename);
 
-    // Cleanup unused replacements.
-    content = content.replace(/__([a-z0-9_]+)__/g, '');
-
     // Check for a maximum dimension and scale down the width if necessary.
     // This is intended for use with Image Resize Filter.
     var widthMatches = content.match(/width[ ]*=[ ]*"(\d*)"/i);
@@ -73,6 +81,14 @@ Drupal.behaviors.insert.attach = function(context) {
       }
     }
 
+    // Allow other modules to perform replacements.
+    options['content'] = content;
+    $.event.trigger('insertIntoActiveEditor', [options]);
+    content = options['content'];
+
+    // Cleanup unused replacements.
+    content = content.replace(/__([a-z0-9_]+)__/g, '');
+
     // Insert the text.
     Drupal.insert.insertIntoActiveEditor(content);
   }
diff --git a/insert.module b/insert.module
index 5b4a578..81be3b5 100644
--- a/insert.module
+++ b/insert.module
@@ -293,6 +293,7 @@ function insert_field_widget_settings_form($field, $instance) {
     '#title' => t('Enable insert button'),
     '#default_value' => $settings['insert'],
     '#description' => t('Enable the insert button and options for this widget.'),
+    '#weight' => -10,
   );
 
   $form['insert']['insert_styles'] = array(
@@ -303,6 +304,7 @@ function insert_field_widget_settings_form($field, $instance) {
     '#description' => t('Select which styles should be available when sending items to text areas. If no styles are selected, the option to use a style is not displayed. If all styles are selected, new styles will be enabled by default.'),
     '#element_validate' => array('insert_field_widget_settings_styles_validate'),
     '#theme' => 'insert_field_widget_settings_styles',
+    '#weight' => 0,
   );
 
   $form['insert']['insert_default'] = array(
@@ -311,6 +313,7 @@ function insert_field_widget_settings_form($field, $instance) {
     '#options' => insert_styles_list(),
     '#default_value' => $settings['insert_default'],
     '#description' => t('Select the default style which will be selected by default or used if no specific styles above are enabled.'),
+    '#weight' => 1,
   );
 
   $form['insert']['insert_class'] = array(
@@ -318,6 +321,7 @@ function insert_field_widget_settings_form($field, $instance) {
     '#type' => 'textfield',
     '#default_value' => $settings['insert_class'],
     '#description' => t('Add any classes that should be added to the item on output.'),
+    '#weight' => 5,
   );
 
   $form['insert']['insert_width'] = array(
@@ -327,6 +331,7 @@ function insert_field_widget_settings_form($field, $instance) {
     '#field_suffix' => ' '. t('pixels'),
     '#default_value' => $settings['insert_width'],
     '#description' => t('When inserting images, the height and width of images may be scaled down to fit within the specified width. Note that this does not resize the image, it only affects the HTML output. To resize images it is recommended to install the <a href="http://drupal.org/project/image_resize_filter">Image Resize Filter</a> module.'),
+    '#weight' => 10,
   );
 
   return $form;
