Monday, February 24, 2014

With 'dojo/dom-class' one may "remove" a class decorating an element without any sanity checking to ensure the class actually decorates the element.

If the class is not there, the call to remove will throw no errors. This minimizes if/then logic obviously. In the example below domClass is a variable mapped to 'dojo/dom-class' at the AMD signature and countLineList is a data-dojo-attach-point designation in a dojox view.

var fourColumns = "cascading-effect-for-four-columns";
var fiveColumns = "cascading-effect-for-five-columns";
var fourColumnsOrFive = fourColumns;
if (this.mdoElt.ahType != i18n.typeUnplanned) {
   if (app.appSettings.AHS_ShowSystemQtyInCount) {
      fourColumnsOrFive = fiveColumns;
   }
}
domClass.remove(this.countLineList, fourColumns);
domClass.remove(this.countLineList, fiveColumns);
domClass.add(this.countLineList, fourColumnsOrFive);

No comments:

Post a Comment