Skip to content
region_manager.js 3.85 KiB
Newer Older
James Sansbury's avatar
James Sansbury committed

/**
 * Show/hide form elements for editing a block title.
 */
Drupal.behaviors.blockTitle = function() {
  // Show hide the textfield depending on the radio states.
James Sansbury's avatar
James Sansbury committed
  $('input.region-manager-manage-form-title-status').change(function() {
    if (this.checked) {
      var textfield = $('input.form-text', $(this).parents('td.block'));
      switch (this.value) {
        // Default Title
James Sansbury's avatar
James Sansbury committed
        case '0':
          textfield.val('').hide('fast');
          break;

        // Disable Title
James Sansbury's avatar
James Sansbury committed
        case '1':
          textfield.val('<none>').hide();
          break;

        // Custom Title
James Sansbury's avatar
James Sansbury committed
        case '2':
          if (textfield.val() == '<none>') {
            textfield.val('');
          }
          textfield.show('fast');
          break;
      }
    }
  });

  // Instantiate a change so we can hide the title field if need be.
James Sansbury's avatar
James Sansbury committed
  $('input.region-manager-manage-form-title-status').change();
James Sansbury's avatar
James Sansbury committed

/**
 * Perform actions from operation links
James Sansbury's avatar
James Sansbury committed
 */
Drupal.behaviors.regionManagerOperations = function() {
  $('td.operations a').click(function() {
    var op = $(this).attr('class');
    var rowClass = $(this).parents('ul').attr('class');
    var row = $('tr.' + rowClass);
    var configWrapper = $('div.region-manager-block-config-wrapper', row);
    var tableDragObj = Drupal.tableDrag['region-manager-blocks-active_path'];
    var tables = $('#region-manager-manage-form table');
James Sansbury's avatar
James Sansbury committed

    switch(op) {
      case 'add':
        row.appendTo('table#region-manager-blocks-active_path').each(function() { tableDragObj.makeDraggable(this) });
        $('select.block-state-select', row).val('active_path');
        break;
        
      case 'configure':
        if (configWrapper.is(':hidden')) {
          configWrapper.show('fast');
        }
        else {
          configWrapper.hide('fast');
        }
        break;
James Sansbury's avatar
James Sansbury committed

      case 'remove':
        row.insertAfter('table#region-manager-blocks-active tr.rm-state-message');
        $('select.block-state-select', row).val('active');
        $('a.tabledrag-handle', row).remove();
        configWrapper.hide();
        break;
James Sansbury's avatar
James Sansbury committed

      case 'disable':
        row.insertAfter('table#region-manager-blocks-disabled tr.rm-state-message');
        $('select.block-state-select', row).val('disabled');
        $('a.tabledrag-handle', row).remove();
        configWrapper.hide();
        break;
James Sansbury's avatar
James Sansbury committed
    }
    if (op != 'configure') {
      tables.each(function() { checkEmptyRegions(this, row); });
    }
    $('tr', tables).filter(':odd').filter('.odd')
      .removeClass('odd').addClass('even')
    .end().end()
    .filter(':even').filter('.even')
      .removeClass('even').addClass('odd');
James Sansbury's avatar
James Sansbury committed

    return false;
James Sansbury's avatar
James Sansbury committed
  });

  var checkEmptyRegions = function(table, rowObject) {
    $('tr.rm-state-message', table).each(function() {
James Sansbury's avatar
James Sansbury committed
      // If the dragged row is in this region, but above the message row, swap it down one space.
      if ($(this).prev('tr').get(0) == rowObject.element) {
        // Prevent a recursion problem when using the keyboard to move rows up.
        if ((rowObject.method != 'keyboard' || rowObject.direction == 'down')) {
          rowObject.swap('after', this);
        }
      }
      // This region has become empty
      if ($(this).next('tr').is(':not(.draggable)') || $(this).next('tr').size() == 0) {
        $(this).removeClass('rm-state-populated').addClass('rm-state-empty');
James Sansbury's avatar
James Sansbury committed
      }
      // This region has become populated.
      else if ($(this).is('.rm-state-empty')) {
        $(this).removeClass('rm-state-empty').addClass('rm-state-populated');
James Sansbury's avatar
James Sansbury committed
      }
    });
  };
}

/**
 * Perform actions from operation links
 */
Drupal.behaviors.regionManagerCreate = function() {
  $('a.region-manager-create-menu-link').click(function() {
    var typesList = $('div.region-manager-create-menu div.item-list-wrapper');
    if (typesList.is(':hidden')) {
      typesList.show('fast');
    }
    else {
      typesList.hide('fast');
    }

    return false;
  });
}