[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/jquery_update/replace/ -> teaser.js (source)

   1  // $Id: teaser.js,v 1.1.2.1 2009/03/21 19:43:51 mfer Exp $
   2  
   3  /**
   4   * Auto-attach for teaser behavior.
   5   *
   6   * Note: depends on resizable textareas.
   7   */
   8  Drupal.behaviors.teaser = function(context) {
   9    $('textarea.teaser:not(.teaser-processed)', context).each(function() {
  10      var teaser = $(this).addClass('teaser-processed');
  11  
  12      // Move teaser textarea before body, and remove its form-item wrapper.
  13      var body = $('#'+ Drupal.settings.teaser[this.id]);
  14      var checkbox = $('#'+ Drupal.settings.teaserCheckbox[this.id]).parent();
  15      var checked = $(checkbox).children('input').attr('checked') ? true : false;
  16      var parent = teaser[0].parentNode;
  17      $(body).before(teaser);
  18      $(parent).remove();
  19  
  20      function trim(text) {
  21        return text.replace(/^\s+/g, '').replace(/\s+$/g, '');
  22      }
  23  
  24      // Join the teaser back to the body.
  25      function join_teaser() {
  26        if (teaser.val()) {
  27          body.val(trim(teaser.val()) +'\r\n\r\n'+ trim(body.val()));
  28        }
  29        // Empty, hide and disable teaser.
  30        teaser[0].value = '';
  31        $(teaser).attr('disabled', 'disabled');
  32        $(teaser).parent().slideUp('fast');
  33        // Change label.
  34        $(this).val(Drupal.t('Split summary at cursor'));
  35        // Hide separate teaser checkbox.
  36        $(checkbox).hide();
  37        // Force a hidden checkbox to be checked (to ensure that the body is
  38        // correctly processed on form submit when teaser/body are in joined
  39        // state), and remember the current checked status.
  40        checked = $(checkbox).children('input').attr('checked') ? true : false;
  41        $(checkbox).children('input').attr('checked', true);
  42      }
  43  
  44      // Split the teaser from the body.
  45      function split_teaser() {
  46        body[0].focus();
  47        var selection = Drupal.getSelection(body[0]);
  48        var split = selection.start;
  49        var text = body.val();
  50  
  51        // Note: using val() fails sometimes. jQuery bug?
  52        teaser[0].value = trim(text.slice(0, split));
  53        body[0].value = trim(text.slice(split));
  54        // Reveal and enable teaser
  55        $(teaser).attr('disabled', '');
  56        $(teaser).parent().slideDown('fast');
  57        // Change label
  58        $(this).val(Drupal.t('Join summary'));
  59        // Show separate teaser checkbox, restore checked value.
  60        $(checkbox).show().children('input').attr('checked', checked);
  61      }
  62  
  63      // Add split/join button.
  64      var button = $('<div class="teaser-button-wrapper"><input type="button" class="teaser-button" /></div>');
  65      var include = $('#'+ this.id.substring(0, this.id.length - 2) +'include');
  66      $(include).parent().parent().before(button);
  67  
  68      // Extract the teaser from the body, if set. Otherwise, stay in joined mode.
  69      var text = body.val().split('<!--break-->', 2);
  70      if (text.length == 2) {
  71        teaser[0].value = trim(text[0]);
  72        body[0].value = trim(text[1]);
  73        $(teaser).attr('disabled', '');
  74        $('input', button).val(Drupal.t('Join summary')).toggle(join_teaser, split_teaser);
  75      }
  76      else {
  77        $('input', button).val(Drupal.t('Split summary at cursor')).toggle(split_teaser, join_teaser);
  78        $(checkbox).hide().children('input').attr('checked', true);
  79      }
  80  
  81      // Make sure that textarea.js has done its magic to ensure proper visibility state.
  82      if (Drupal.behaviors.textarea && teaser.is(('.form-textarea:not(.textarea-processed)'))) {
  83        Drupal.behaviors.textarea(teaser.parentNode);
  84      }
  85      // Set initial visibility
  86      if (teaser[0].disabled) {
  87        teaser.parent().hide();
  88      }
  89  
  90    });
  91  };


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7