Skip to content
search_api.admin.js 2.05 KiB
Newer Older
Thomas Seidl's avatar
Thomas Seidl committed

// Copied from filter.admin.js
(function ($) {

Drupal.behaviors.searchApiStatus = {
  attach: function (context, settings) {
    $('.search-api-status-wrapper input.form-checkbox', context).once('search-api-status', function () {
      var $checkbox = $(this);
      // Retrieve the tabledrag row belonging to this processor.
      var $row = $('#' + $checkbox.attr('id').replace(/-status$/, '-weight'), context).closest('tr');
      // Retrieve the vertical tab belonging to this processor.
      var $tab = $('#' + $checkbox.attr('id').replace(/-status$/, '-settings'), context).data('verticalTab');

      // Bind click handler to this checkbox to conditionally show and hide the
      // filter's tableDrag row and vertical tab pane.
      $checkbox.bind('click.searchApiUpdate', function () {
        if ($checkbox.is(':checked')) {
          $row.show();
          if ($tab) {
            $tab.tabShow().updateSummary();
          }
        }
        else {
          $row.hide();
          if ($tab) {
            $tab.tabHide().updateSummary();
          }
        }
        // Restripe table after toggling visibility of table row.
        Drupal.tableDrag['search-api-' + $checkbox.attr('id').replace(/^edit-([^-]+)-.*$/, '$1') + '-order-table'].restripeTable();
      });

      // Attach summary for configurable items (only for screen-readers).
      if ($tab) {
        $tab.fieldset.drupalSetSummary(function (tabContext) {
          return $checkbox.is(':checked') ? Drupal.t('Enabled') : Drupal.t('Disabled');
        });
      }

      // Trigger our bound click handler to update elements to initial state.
      $checkbox.triggerHandler('click.searchApiUpdate');
    });
  }
};

Thomas Seidl's avatar
Thomas Seidl committed
Drupal.behaviors.searchApiEditMenu = {
  attach: function (context, settings) {
    $('.search-api-edit-menu-toggle', context).click(function (e) {
      $menu = $(this).parent().find('.search-api-edit-menu');
      if ($menu.is('.collapsed')) {
    	$menu.removeClass('collapsed');
      }
      else {
    	$menu.addClass('collapsed');
      }
      return false;
    });
  }
};

Thomas Seidl's avatar
Thomas Seidl committed
})(jQuery);