diff --git l10n_client.js l10n_client.js index 59314db..045735f 100644 --- l10n_client.js +++ l10n_client.js @@ -3,98 +3,99 @@ (function ($) { // Store all l10n_client related data + methods in its own object -$.extend(Drupal, { - l10nClient: new (function() { - // Set "selected" string to unselected, i.e. -1 - this.selected = -1; - // Keybindings - this.keys = {'toggle':'ctrl+shift+s', 'clear': 'esc'}; // Keybindings - // Keybinding functions - this.key = function(pressed) { - 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; - userSelection = String(userSelection); - if(userSelection.length > 0) { - Drupal.l10nClient.filter(userSelection); +Drupal.l10nClient = { + // Set "selected" string to unselected, i.e. -1 + selected: -1, + // Keybindings + keys: {'toggle':'ctrl+shift+s', 'clear': 'esc'}, // Keybindings + // Keybinding functions + key: function(pressed) { + switch(pressed) { + case 'toggle': + // Grab user-hilighted text & send it into the search filter + 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(); + } else { + if($('#l10n-client').is('.hidden')) { Drupal.l10nClient.toggle(1); - $('#l10n-client .string-search').focus(); - } else { - if($('#l10n-client').is('.hidden')) { - Drupal.l10nClient.toggle(1); - if(!$.browser.safari) { - $('#l10n-client .string-search').focus(); - } - } else { - Drupal.l10nClient.toggle(0); + if(!$.browser.safari) { + $('#l10n-client .string-search').focus(); } + } else { + Drupal.l10nClient.toggle(0); } - break; - case 'clear': - this.filter(false); - break; - } - } - // Toggle the l10nclient - this.toggle = function(state) { - 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'); - if(!$.browser.msie) { - $('body').css('border-bottom', '22em solid #fff'); - } - $.cookie('Drupal_l10n_client', '1', {expires: 7, path: '/'}); - 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')); - if(!$.browser.msie) { - $('body').css('border-bottom', '0px'); - } - $.cookie('Drupal_l10n_client', '0', {expires: 7, path: '/'}); - break; - } - } - // Get a string from the DOM tree - this.getString = function(index, type) { - return $('#l10n-client-data div:eq('+index+') .'+type).text(); - } - // Set a string in the DOM tree - this.setString = function(index, data) { - $('#l10n-client-data div:eq('+index+') .target').text(data); + } + break; + case 'clear': + this.filter(false); + break; } - // 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-string-select li').show(); - $('#l10n-client .string-search').val(''); - $('#l10n-client .string-search').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); + }, + // Toggle the l10nclient + toggle: function(state) { + 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'); + if(!$.browser.msie) { + $('body').css('border-bottom', '22em solid #fff'); } + $.cookie('Drupal_l10n_client', '1', {expires: 7, path: '/'}); + 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')); + if(!$.browser.msie) { + $('body').css('border-bottom', '0px'); + } + $.cookie('Drupal_l10n_client', '0', {expires: 7, path: '/'}); + break; + } + }, + // Get a string from the DOM tree + getString: function(index, type) { + return $('#l10n-client-data div:eq('+index+') .'+type).text(); + }, + // Set a string in the DOM tree + setString: function(index, data) { + $('#l10n-client-data div:eq('+index+') .target').text(data); + }, + // Filter the the string list by a search string + filter: function(search) { + if(search == false || search == '') { + $('#l10n-client #l10n-client-search-filter-clear').focus(); + $('#l10n-client-string-select li').show(); + $('#l10n-client .string-search').val(''); + $('#l10n-client .string-search').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); } } - }) -}); + } +} // Attaches the localization editor behavior to all required fields. Drupal.behaviors.l10nClient = {} Drupal.behaviors.l10nClient.attach = function (context) { + // Cache client object + var $client = $('#l10n-client'); + // 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': @@ -122,7 +123,7 @@ Drupal.behaviors.l10nClient.attach = function (context) { // When l10n_client window is clicked, toggle based on current state. $('#l10n-client .labels .toggle').click(function() { - if($('#l10n-client').is('.hidden')) { + if($client.is('.hidden')) { Drupal.l10nClient.toggle(1); } else { Drupal.l10nClient.toggle(0);