As items are getting created many of them have the same weight, and many of the weights are out of scale. Almost every item is over the weight of 0. I have items with a weight of 167 being created, even when there are only 20 or so items in that parent category.

Weights on menu items should look more like this:

  • -50
  • -49
    • -50
    • -49
    • -48
    • -47
      • -50
      • -49
  • -48
  • -47

Instead once I actually load the menu I'll findsomething like this:

  • -50
  • -49
    • 50
    • 50
    • 50
    • 50
      • -50
      • -50
  • 50
  • 50
CommentFileSizeAuthor
#4 updateWeight.js_.patch2.69 KBmcaden
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mcaden’s picture

Project: Taxonomy Menu » Taxonomy Manager
Version: 6.x-2.x-dev » 6.x-2.2

I originally had this on Taxonomy menu but the more I looked into it, it's not taxonomy menu's fault, it's taxonomy manager which we're using to reorder the term order.

The weighting system is incompatible with Drupal's current method of weighting, which constrains weights between 50 and -50.

mcaden’s picture

Hmm...I think this might do it.

In file: "updateWeight.js"
Replace Drupal.swapWeights with this one and add the two functions below it:

Drupal.swapWeights = function(upTerm, downTerm) {
  var upWeight = Drupal.getWeight(upTerm);
  var downWeight = Drupal.getWeight(downTerm);
  var downTid = Drupal.getTermId(downTerm);
  var upTid = Drupal.getTermId(upTerm);  
    
  if(upWeight > 50) {
    upWeight = 50;
  }
  if(downWeight > 50) {
    downWeight = 50;
  }
  if(upWeight < -50) {
    upWeight = -50;
  }
  if(downWeight < -50) {
    downWeight = -50;
  }
  //same weight, decrease upTerm
  if (upWeight == downWeight) {
    if(upWeight != -50) {
      weights[upTid] = --upWeight;
    }
    else {
      weights[downTid] = ++upWeight;
    }
  }  
  //different weights, swap
  else {
    weights[upTid] = downWeight;
    weights[downTid] = upWeight;
  }
  //update prev siblings if necessary
  try {
    if (Drupal.getWeight($(upTerm).prev()) >= upWeight) {
      $(upTerm).prevAll().each(Drupal.updateNextSiblingWeight(upWeight));
    }
  } catch(e) {
    //no prev
  }
  //update next siblings if necessary
  try {
    if (Drupal.getWeight($(downTerm).next()) <= downWeight) {
      $(downTerm).nextAll().each(Drupal.updatePrevSiblingWeight(downWeight));
    }
  } catch(e) {
    //no next
  }
}

Drupal.updateNextSiblingWeight = function (startWeight){
  var next = startWeight;
  function helper() {
    var id = Drupal.getTermId(this);
    weights[id] = --next;
  }
  
  return helper;
}

Drupal.updatePrevSiblingWeight = function (startWeight){
  var prev = startWeight;
  function helper() {
    var id = Drupal.getTermId(this);
    weights[id] = ++prev;
  }
  
  return helper;
}
mcaden’s picture

Title: Weight Normalization » Lack of Weight Normalization causes problems with taxonomy_menu
Status: Active » Needs review
mcaden’s picture

FileSize
2.69 KB

It appeared to work when I tested it, however there were a few things that would cause the above code to go extremely wrong. I've rewritten it and everything seems to function great.

The following patch is against 6.x-2.x-dev.

mcaden’s picture

Status: Needs review » Needs work
mcaden’s picture

Status: Needs work » Needs review
ivnish’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)