src/jquery-tokeninput/jquery-tokeninput.js
function insert_token(item) {
          var $this_token = $($(input).data("settings").tokenFormatter(item));
          var readonly = item.readonly === true ? true : false;

          if(readonly) $this_token.addClass($(input).data("settings").classes.tokenReadOnly);

          $this_token.addClass($(input).data("settings").classes.token).insertBefore(input_token);

          // The 'delete token' button
          if(!readonly) {
            $("<span>" + $(input).data("settings").deleteText + "</span>")
                .addClass($(input).data("settings").classes.tokenDelete)
                .appendTo($this_token)
                .click(function () {
                    if (!$(input).data("settings").disabled) {
                        delete_token($(this).parent());
                        hidden_input.change();
                        return false;
                    }
                });
          }

          // Store data on the token
          var token_data = item;
          $.data($this_token.get(0), "tokeninput", item);

          // Save this token for duplicate checking
          saved_tokens = saved_tokens.slice(0,selected_token_index).concat([token_data]).concat(saved_tokens.slice(selected_token_index));
          selected_token_index++;

          // Update the hidden input
          update_hidden_input(saved_tokens, hidden_input);

          token_count += 1;

          // Check the token limit
          if($(input).data("settings").tokenLimit !== null && token_count >= $(input).data("settings").tokenLimit) {
              input_box.hide();
              hide_dropdown();
          }

          return $this_token;
      }
function insert_token(item) {
          var $this_token = $($(input).data("settings").tokenFormatter(item));
          var readonly = item.readonly === true ? true : false;

          if(readonly) $this_token.addClass($(input).data("settings").classes.tokenReadOnly);

          $this_token.addClass($(input).data("settings").classes.token).insertBefore(input_token);

          // The 'delete token' button
          if(!readonly) {
            $("<span>" + $(input).data("settings").deleteText + "</span>")
                .addClass($(input).data("settings").classes.tokenDelete)
                .appendTo($this_token)
                .click(function () {
                    if (!$(input).data("settings").disabled) {
                        delete_token($(this).parent());
                        hidden_input.change();
                        return false;
                    }
                });
          }

          // Store data on the token
          var token_data = item;
          $.data($this_token.get(0), "tokeninput", item);

          // Save this token for duplicate checking
          saved_tokens = saved_tokens.slice(0,selected_token_index).concat([token_data]).concat(saved_tokens.slice(selected_token_index));
          selected_token_index++;

          // Update the hidden input
          update_hidden_input(saved_tokens, hidden_input);

          token_count += 1;

          // Check the token limit
          if($(input).data("settings").tokenLimit !== null && token_count >= $(input).data("settings").tokenLimit) {
              input_box.hide();
              hide_dropdown();
          }

          return $this_token;
      }
function insert_token ( item ) { var $this_token = $ ( $ ( input ) . data ( "settings" ) . tokenFormatter ( item ) ) ; var readonly = item . readonly === true ? true : false ; if ( readonly ) $this_token . addClass ( $ ( input ) . data ( "settings" ) . classes . tokenReadOnly ) ; $this_token . addClass ( $ ( input ) . data ( "settings" ) . classes . token ) . insertBefore ( input_token ) ; // The 'delete token' button if ( ! readonly ) { $ ( "<span>" + $ ( input ) . data ( "settings" ) . deleteText + "</span>" ) . addClass ( $ ( input ) . data ( "settings" ) . classes . tokenDelete ) . appendTo ( $this_token ) . click ( function ( ) { if ( ! $ ( input ) . data ( "settings" ) . disabled ) { delete_token ( $ ( this ) . parent ( ) ) ; hidden_input . change ( ) ; return false ; } } ) ; } // Store data on the token var token_data = item ; $ . data ( $this_token . get ( 0 ) , "tokeninput" , item ) ; // Save this token for duplicate checking saved_tokens = saved_tokens . slice ( 0 , selected_token_index ) . concat ( [ token_data ] ) . concat ( saved_tokens . slice ( selected_token_index ) ) ; selected_token_index ++ ; // Update the hidden input update_hidden_input ( saved_tokens , hidden_input ) ; token_count += 1 ; // Check the token limit if ( $ ( input ) . data ( "settings" ) . tokenLimit !== null && token_count >= $ ( input ) . data ( "settings" ) . tokenLimit ) { input_box . hide ( ) ; hide_dropdown ( ) ; } return $this_token ; }
Inner function to a token to the list
Inner function to a token to the list