Index: l10n_client.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/l10n_client/Attic/l10n_client.js,v
retrieving revision 1.10.4.10
diff -u -p -r1.10.4.10 l10n_client.js
--- l10n_client.js	8 Dec 2010 14:03:15 -0000	1.10.4.10
+++ l10n_client.js	16 Dec 2010 12:37:26 -0000
@@ -5,6 +5,8 @@
 // Store all l10n_client related data + methods in its own object
 $.extend(Drupal, {
   l10nClient: new (function() {
+    // Cache selector.
+    var $client = $('#l10n-client');
     // Set "selected" string to unselected, i.e. -1
     this.selected = -1;
     // Keybindings
@@ -14,17 +16,17 @@ $.extend(Drupal, {
       switch(pressed) {
         case 'toggle':
           // Grab user-hilighted text & send it into the search filter
-          userSelection = window.getSelection ? window.getSelection() : document.getSelection ? document.getSelection() : document.selection.createRange().text;
+          var userSelection = window.getSelection ? window.getSelection() : document.getSelection ? document.getSelection() : document.selection.createRange().text;
           userSelection = String(userSelection);
           if(userSelection.length > 0) {
             Drupal.l10nClient.filter(userSelection);
             Drupal.l10nClient.toggle(1);
-            $('#l10n-client .string-search').focus();
+            $client.find('.string-search').focus();
           } else {
-            if($('#l10n-client').is('.hidden')) {
+            if($client.is('.hidden')) {
               Drupal.l10nClient.toggle(1);
               if(!$.browser.safari) {
-                $('#l10n-client .string-search').focus();
+                $client.find('.string-search').focus();
               }
             } else {
               Drupal.l10nClient.toggle(0);
@@ -41,8 +43,8 @@ $.extend(Drupal, {
       switch(state) {
         case 1:
           $('#l10n-client-string-select, #l10n-client-string-editor, #l10n-client .labels .label').show();
-          $('#l10n-client').height('22em').removeClass('hidden');
-          $('#l10n-client .labels .toggle').text('X');
+          $client.height('22em').removeClass('hidden');
+          $client.find('.labels .toggle').text('X');
           if(!$.browser.msie) {
             $('body').css('border-bottom', '22em solid #fff');
           }
@@ -50,8 +52,8 @@ $.extend(Drupal, {
         break;
         case 0:
           $('#l10n-client-string-select, #l10n-client-string-editor, #l10n-client .labels .label').hide();
-          $('#l10n-client').height('2em').addClass('hidden');
-          $('#l10n-client .labels .toggle').text(Drupal.t('Translate Text'));
+          $client.height('2em').addClass('hidden');
+          $client.find('.labels .toggle').text(Drupal.t('Translate Text'));
           if(!$.browser.msie) {
             $('body').css('border-bottom', '0px');
           }
@@ -70,15 +72,14 @@ $.extend(Drupal, {
     // Filter the the string list by a search string
     this.filter = function(search) {
       if(search == false || search == '') {
-        $('#l10n-client #l10n-client-search-filter-clear').focus();
+        $('#l10n-client-search-filter-clear').focus();
         $('#l10n-client-string-select li').show();
-        $('#l10n-client .string-search').val('');
-        $('#l10n-client .string-search').focus();
+        $client.find('.string-search').val('').focus();
       } else {
         if(search.length > 0) {
           $('#l10n-client-string-select li').hide();
           $('#l10n-client-string-select li:contains('+search+')').show();
-          $('#l10n-client .string-search').val(search);
+          $client.find('.string-search').val(search);
         }
       }
     }
@@ -88,13 +89,17 @@ $.extend(Drupal, {
 // Attaches the localization editor behavior to all required fields.
 Drupal.behaviors.l10nClient = {}
 Drupal.behaviors.l10nClient.attach = function (context) {
+  // Cache selectors.
+  var $client = $('#l10n-client'),
+      $stringList = $('#l10n-client-string-select li'),
+      $form = $('#l10n-client-form');
   // Killswitch - attach only once.
-  if ($('#l10n-client').is('.l10n-client-processed')) {
+  if ($client.is('.l10n-client-processed')) {
     return;
   }
 
   // First time - init & attach all handlers.
-  $('#l10n-client').addClass('l10n-client-processed');
+  $client.addClass('l10n-client-processed');
 
   switch($.cookie('Drupal_l10n_client')) {
     case '1':
@@ -107,22 +112,22 @@ Drupal.behaviors.l10nClient.attach = fun
 
   // If the selection changes, copy string values to the source and target fields.
   // Add class to indicate selected string in list widget.
-  $('#l10n-client-string-select li').click(function() {
-    $('#l10n-client-string-select li').removeClass('active');
+  $stringList.click(function() {
+    $stringList.removeClass('active');
     $(this).addClass('active');
-    var index = $('#l10n-client-string-select li').index(this);
+    var index = $stringList.index(this);
 
     $('#l10n-client-string-editor .source-text').text(Drupal.l10nClient.getString(index, 'source'));
-    $('#l10n-client-form .translation-target').val(Drupal.l10nClient.getString(index, 'target'));
-    $('#l10n-client-form .source-textgroup').val(Drupal.l10nClient.getString(index, 'textgroup'));
+    $form.find('.translation-target').val(Drupal.l10nClient.getString(index, 'target'));
+    $form.find('.source-textgroup').val(Drupal.l10nClient.getString(index, 'textgroup'));
 
     Drupal.l10nClient.selected = index;
-    $('#l10n-client-form .form-submit').removeAttr("disabled");
+    $form.find('.form-submit').removeAttr("disabled");
   });
 
   // When l10n_client window is clicked, toggle based on current state.
-  $('#l10n-client .labels .toggle').click(function() {
-    if($('#l10n-client').is('.hidden')) {
+  $client.find('.labels .toggle').click(function() {
+    if($client.is('.hidden')) {
       Drupal.l10nClient.toggle(1);
     } else {
       Drupal.l10nClient.toggle(0);
@@ -130,14 +135,14 @@ Drupal.behaviors.l10nClient.attach = fun
   });
 
   // Copy source text to translation field on button click.
-  $('#l10n-client-form .edit-copy').click(function() {
-    $('#l10n-client-form .translation-target').val($('#l10n-client-string-editor .source-text').text());
+  $form.find('.edit-copy').click(function() {
+    $form.find('.translation-target').val($('#l10n-client-string-editor .source-text').text());
     return false;
   });
 
   // Clear translation field on button click.
-  $('#l10n-client-form .edit-clear').click(function() {
-    $('#l10n-client-form .translation-target').val('');
+  $form.find('.edit-clear').click(function() {
+    $form.find('.translation-target').val('');
     return false;
   });
 
@@ -148,35 +153,35 @@ Drupal.behaviors.l10nClient.attach = fun
   }
 
   // Custom listener for l10n_client livesearch
-  $('#l10n-client .string-search').keyup(function(key) {
-    Drupal.l10nClient.filter($('#l10n-client .string-search').val());
+  $client.find('.string-search').keyup(function(key) {
+    Drupal.l10nClient.filter($client.find('.string-search').val());
   });
 
   // Clear search
-  $('#l10n-client #l10n-client-search-filter-clear').click(function() {
+  $('#l10n-client-search-filter-clear').click(function() {
     Drupal.l10nClient.filter(false);
     return false;
   });
 
   // Send AJAX POST data on form submit.
-  $('#l10n-client-form').submit(function() {
-    $('#l10n-client-form .form-submit').attr("disabled", "true");
+  $form.submit(function() {
+    $form.find('.form-submit').attr("disabled", "true");
     $.ajax({
       type: "POST",
-      url: $('#l10n-client-form').attr('action'),
+      url: $form.attr('action'),
       // Send source and target strings.
       data: {
         source: $('#l10n-client-string-editor .source-text').text(),
-        target: $('#l10n-client-form .translation-target').val(),
-        textgroup: $('#l10n-client-form .source-textgroup').val(),
-        'form_token': $('#l10n-client-form input[name=form_token]').val()
+        target: $form.find('.translation-target').val(),
+        textgroup: $form.find('.source-textgroup').val(),
+        'form_token': $form.find('input[name=form_token]').val()
       },
       success: function (data) {
         // Store string in local js
-        Drupal.l10nClient.setString(Drupal.l10nClient.selected, $('#l10n-client-form .translation-target').val());
+        Drupal.l10nClient.setString(Drupal.l10nClient.selected, $form.find('.translation-target').val());
 
         // Figure out the display of the new translation in the selection list.
-        var newTranslation = $('#l10n-client-form .translation-target').val();
+        var newTranslation = $form.find('.translation-target').val();
         var newTranslationDisplay = newTranslation;
         var newTranslationStripped = newTranslation.replace(/<\/?[^<>]+>/gi, '')
                                                    .replace(/&quot;/g, '"')
@@ -196,11 +201,11 @@ Drupal.behaviors.l10nClient.attach = fun
         }
 
         // Mark string as translated.
-        $('#l10n-client-string-select li').eq(Drupal.l10nClient.selected).removeClass('untranslated').removeClass('active').addClass('translated').text(newTranslationDisplay);
+        $stringList.eq(Drupal.l10nClient.selected).removeClass('untranslated').removeClass('active').addClass('translated').text(newTranslationDisplay);
 
         // Empty input fields.
         $('#l10n-client-string-editor .source-text').html(data);
-        $('#l10n-client-form .translation-target').val('');
+        $form.find('.translation-target').val('');
 
       },
       error: function (xmlhttp) {
