Advertisement
Guest User

converting to nodes

a guest
May 27th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     var addNewPrediction = function ( prediction, parent ) {
  2.     /* ( str, Node ) -> new Node
  3.  
  4.     Add the prediction list item node to parent and return it
  5.     */
  6.         var listItem        = document.createElement( 'li' );
  7.         listItem.className  = 'prediction-item';
  8.  
  9.         var optionCont      = document.createElement( 'span' );
  10.         listItem.appendChild( optionCont );
  11.         optionCont.className = 'prediction-text';
  12.  
  13.         var prediction      = document.createTextNode( prediction );
  14.         optionCont.appendChild( prediction );
  15.  
  16.         return listItem;
  17.     };  // End addNewPrediction()
  18.  
  19.  
  20.     function strInArray(str, testArray) {
  21.  
  22.         for (var wordi = 0; wordi < testArray.length; wordi++) {
  23.  
  24.             var word = testArray[ wordi ];
  25.  
  26.             if ( word.match( str ) ) { // && outputText.length < 5) { // Why restrict length?
  27.  
  28.                 // Replace matching letters with bold letters (not sure how to do
  29.                 // this elegantly, i.e. without just adding to the string)
  30.                 var bold = document.create
  31.  
  32.                 var prediction = word.replace( str, '<strong>' + str + '</strong>' );
  33.                 outputText.push('<li class="prediction-item"><span class="prediction-text">' + prediction + '</span></li>');
  34.  
  35.             }
  36.  
  37.         }
  38.     }  // end for testArray
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement