function(item) {
  var that = this,
      r;

  var docFrag = document.createDocumentFragment();
  var option = this.options[item.idx];
  var data = this.data ? this.data[item.idx] : option;
  var content = this.customSelected ? this.config.renderSelection(data) : option.textContent;

  var tag = util.createElement("li", {
    class: "selectr-tag",
    html: content
  });
  var btn = util.createElement("button", {
    class: "selectr-tag-remove",
    type: "button"
  });

  tag.appendChild(btn);

  // Set property to check against later
  tag.idx = item.idx;
  tag.tag = option.value;

  this.tags.push(tag);

  if (this.config.sortSelected) {

    var tags = this.tags.slice();

    // Deal with values that contain numbers
    r = function(val, arr) {
      val.replace(/(\d+)|(\D+)/g, function(that, $1, $2) {
        arr.push([$1 || Infinity, $2 || ""]);
      });
    };

    tags.sort(function(a, b) {
      var x = [],
          y = [],
          ac, bc;
      if (that.config.sortSelected === true) {
        ac = a.tag;
        bc = b.tag;
      } else if (that.config.sortSelected === 'text') {
        ac = a.textContent;
        bc = b.textContent;
      }

      r(ac, x);
      r(bc, y);

      while (x.length && y.length) {
        var ax = x.shift();
        var by = y.shift();
        var nn = (ax[0] - by[0]) || ax[1].localeCompare(by[1]);
        if (nn) return nn;
      }

      return x.length - y.length;
    });

    util.each(tags, function(i, tg) {
      docFrag.appendChild(tg);
    });

    this.label.innerHTML = "";

  } else {
    docFrag.appendChild(tag);
  }

  if (this.config.taggable) {
    this.label.insertBefore(docFrag, this.input.parentNode);
  } else {
    this.label.appendChild(docFrag);
  }
}
function(item) {
  var that = this,
      r;

  var docFrag = document.createDocumentFragment();
  var option = this.options[item.idx];
  var data = this.data ? this.data[item.idx] : option;
  var content = this.customSelected ? this.config.renderSelection(data) : option.textContent;

  var tag = util.createElement("li", {
    class: "selectr-tag",
    html: content
  });
  var btn = util.createElement("button", {
    class: "selectr-tag-remove",
    type: "button"
  });

  tag.appendChild(btn);

  
  tag.idx = item.idx;
  tag.tag = option.value;

  this.tags.push(tag);

  if (this.config.sortSelected) {

    var tags = this.tags.slice();

    
    r = function(val, arr) {
      val.replace(/(\d+)|(\D+)/g, function(that, $1, $2) {
        arr.push([$1 || Infinity, $2 || ""]);
      });
    };

    tags.sort(function(a, b) {
      var x = [],
          y = [],
          ac, bc;
      if (that.config.sortSelected === true) {
        ac = a.tag;
        bc = b.tag;
      } else if (that.config.sortSelected === 'text') {
        ac = a.textContent;
        bc = b.textContent;
      }

      r(ac, x);
      r(bc, y);

      while (x.length && y.length) {
        var ax = x.shift();
        var by = y.shift();
        var nn = (ax[0] - by[0]) || ax[1].localeCompare(by[1]);
        if (nn) return nn;
      }

      return x.length - y.length;
    });

    util.each(tags, function(i, tg) {
      docFrag.appendChild(tg);
    });

    this.label.innerHTML = "";

  } else {
    docFrag.appendChild(tag);
  }

  if (this.config.taggable) {
    this.label.insertBefore(docFrag, this.input.parentNode);
  } else {
    this.label.appendChild(docFrag);
  }
}
function ( item ) { var that = this , r ; var docFrag = document . createDocumentFragment ( ) ; var option = this . options [ item . idx ] ; var data = this . data ? this . data [ item . idx ] : option ; var content = this . customSelected ? this . config . renderSelection ( data ) : option . textContent ; var tag = util . createElement ( "li" , { class : "selectr-tag" , html : content } ) ; var btn = util . createElement ( "button" , { class : "selectr-tag-remove" , type : "button" } ) ; tag . appendChild ( btn ) ; // Set property to check against later tag . idx = item . idx ; tag . tag = option . value ; this . tags . push ( tag ) ; if ( this . config . sortSelected ) { var tags = this . tags . slice ( ) ; // Deal with values that contain numbers r = function ( val , arr ) { val . replace ( / (\d+)|(\D+) / g , function ( that , $1 , $2 ) { arr . push ( [ $1 || Infinity , $2 || "" ] ) ; } ) ; } ; tags . sort ( function ( a , b ) { var x = [ ] , y = [ ] , ac , bc ; if ( that . config . sortSelected === true ) { ac = a . tag ; bc = b . tag ; } else if ( that . config . sortSelected === 'text' ) { ac = a . textContent ; bc = b . textContent ; } r ( ac , x ) ; r ( bc , y ) ; while ( x . length && y . length ) { var ax = x . shift ( ) ; var by = y . shift ( ) ; var nn = ( ax [ 0 ] - by [ 0 ] ) || ax [ 1 ] . localeCompare ( by [ 1 ] ) ; if ( nn ) return nn ; } return x . length - y . length ; } ) ; util . each ( tags , function ( i , tg ) { docFrag . appendChild ( tg ) ; } ) ; this . label . innerHTML = "" ; } else { docFrag . appendChild ( tag ) ; } if ( this . config . taggable ) { this . label . insertBefore ( docFrag , this . input . parentNode ) ; } else { this . label . appendChild ( docFrag ) ; } }
Add a tag
@param  {HTMLElement} item
Add a tag