? pathauto-live-844944.patch
Index: pathauto.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.js,v
retrieving revision 1.5.2.1
diff -u -p -r1.5.2.1 pathauto.js
--- pathauto.js	10 Feb 2010 21:47:40 -0000	1.5.2.1
+++ pathauto.js	20 Jul 2010 10:20:26 -0000
@@ -1,20 +1,36 @@
 // $Id: pathauto.js,v 1.5.2.1 2010/02/10 21:47:40 greggles Exp $
 if (Drupal.jsEnabled) {
   $(document).ready(function() {
+    var path;
     if ($("#edit-pathauto-perform-alias").size() && $("#edit-pathauto-perform-alias").attr("checked")) {
       // Disable input and hide its description.
-      $("#edit-path").attr("disabled","disabled");
+      $("#edit-path").hide(0);
       $("#edit-path-wrapper > div.description").hide(0);
+      var protocol = $(location).attr('protocol');
+      var hostname = $(location).attr('hostname');
+      $('#edit-path-wrapper').prepend('<div id="path-preview">'+protocol+'//'+hostname+'/</div>');
+      
+      $('#edit-title').keyup(function() {
+        var nodeTitle = $('#edit-title').val();
+        var nodeType = $('input[name=form_id]').val();
+        $.get('/pathauto/get_url_callback', {node_title: nodeTitle, node_type: nodeType}, function(data) {
+          path = data;
+          $('#path-preview #path').remove();
+          $('#path-preview').append('<span id="path">'+path+'</span>');
+        });
+      });
     }
     $("#edit-pathauto-perform-alias").bind("click", function() {
       if ($("#edit-pathauto-perform-alias").attr("checked")) {
         // Auto-alias checked; disable input.
-        $("#edit-path").attr("disabled","disabled");
+        $("#edit-path").val('');
+        $("#edit-path").slideUp('fast');
         $("#edit-path-wrapper > div[class=description]").slideUp('fast');
       }
       else {
         // Auto-alias unchecked; enable input.
-        $("#edit-path").removeAttr("disabled");
+        $("#edit-path").val(path);
+        $("#edit-path").slideDown('fast');
         $("#edit-path")[0].focus();
         $("#edit-path-wrapper > div[class=description]").slideDown('fast');
       }
Index: pathauto.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.module,v
retrieving revision 1.126.2.25
diff -u -p -r1.126.2.25 pathauto.module
--- pathauto.module	28 Jun 2010 19:05:24 -0000	1.126.2.25
+++ pathauto.module	20 Jul 2010 10:20:26 -0000
@@ -84,11 +84,81 @@ function pathauto_menu() {
     'weight' => 30,
     'file' => 'pathauto.admin.inc',
   );
+  $items['pathauto/get_url_callback'] = array(
+    'title' => 'Get url callback',
+    'page callback' => '_pathauto_get_url_callback',
+    'access arguments' => array('administer pathauto'),
+    'type' => MENU_CALLBACK,
+  );
 
   return $items;
 }
 
 /**
+ * AJAX callback to return URL for given node title.
+ */
+function _pathauto_get_url_callback(){
+  global $user;
+  $node_title = $_GET['node_title'];
+  $node_type = $_GET['node_type'];
+  $node_type = str_replace("_node_form", "", $node_type);
+  $node = array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'title' => $node_title, 'type' => $node_type, 'language' => '');
+  $node = (object)$node;
+  
+  _pathauto_include();
+  $placeholders = pathauto_get_placeholders('node', $node);
+  //drupal_set_message('<pre>'.print_r($placeholders,true).'</pre>');
+  $module = 'node';
+  $type = $node->type;
+  $language = $node->language;
+  // Retrieve and apply the pattern for this content type
+    if (!empty($type)) {
+      $pattern = trim(variable_get("pathauto_{$module}_{$type}_{$language}_pattern", ''));
+      if (empty($pattern)) {
+        $pattern = trim(variable_get("pathauto_{$module}_{$type}_pattern", ''));
+      }
+    }
+    if (empty($pattern)) {
+      $pattern = trim(variable_get("pathauto_{$module}_pattern", ''));
+    }
+    
+    // Replace the placeholders with the values provided by the module.
+    $alias = str_replace($placeholders['tokens'], $placeholders['values'], $pattern);
+
+    // Two or more slashes should be collapsed into one
+    $alias = preg_replace('/\/+/', '/', $alias);
+
+    // Trim any leading or trailing slashes
+    $alias = preg_replace('/^\/|\/+$/', '', $alias);
+
+    // Clean the alias.
+    $alias = pathauto_clean_alias($alias);
+
+    // Enforce the maximum length.
+    $maxlength = min(variable_get('pathauto_max_length', 100), _pathauto_get_schema_alias_maxlength());
+    $alias = drupal_substr($alias, 0, $maxlength);
+
+    // If the alias already exists, generate a new, hopefully unique, variant
+    $separator = variable_get('pathauto_separator', '-');
+    if (_pathauto_alias_exists($alias, $src, $language)) {
+      $original_alias = $alias;
+      for ($i = 0; _pathauto_alias_exists(drupal_substr($alias, 0, $maxlength - strlen($i)) . $separator . $i, $src, $language); $i++) {
+      }
+      // Make room for the sequence number
+      $alias = drupal_substr($alias, 0, $maxlength - drupal_strlen($i));
+      $alias = $alias . $separator . $i;
+      // If verbose is on, alert the user why this happened
+      if ($verbose) {
+        drupal_set_message(t('The automatically generated alias %original_alias conflicted with an existing alias. Alias changed to %alias.',
+          array('%original_alias' => $original_alias, '%alias' => $alias)));
+      }
+    }
+    
+  
+  print $alias;
+}
+
+/**
  * Include all Pathauto include files.
  */
 function _pathauto_include() {
