B2G/gaia/apps/sms/js/thread_ui.js
// Returns false when no contact has been rendered
Returns false when no contact has been rendered
Returns false when no contact has been rendered
function thui_renderContact(params) {
    if (params.contact.tel === null) {
      return false;
    }
    var contact = params.contact;
    var input = params.input.trim();
    var ul = params.target;
    var isContact = params.isContact;
    var isSuggestion = params.isSuggestion;
    var tels = contact.tel;
    var telsLength = tels.length;
    var renderPhoto = params.renderPhoto;
    var escaped = Utils.escapeRegex(Utils.escapeHTML(input));
    var escsubs = escaped.split(/\s+/);
    var regexps = {
      name: escsubs.map(function(k) {
        return new RegExp('^' + k, 'gi');
      }),
      number: [new RegExp(escaped, 'ig')]
    };
    if (!telsLength) {
      return false;
    }
    var include = renderPhoto ? { photoURL: true } : null;
    var details = isContact ?
      Utils.getContactDetails(tels[0].value, contact, include) : {
        name: '',
        photoURL: ''
      };
    for (var i = 0; i < telsLength; i++) {
      var current = tels[i];
      if (!isSuggestion && !Utils.compareDialables(current.value, input)) {
        continue;
      }
       If rendering for contact search result suggestions, don't
       render contact tel records for values that are already
       selected as recipients. This comparison should be safe,
       as the value in this.recipients.numbers comes from the same
       source that current.value comes from.
      if (isSuggestion && this.recipients.numbers.indexOf(current.value) > -1) {
        continue;
      }
      var li = document.createElement('li');
      var data = Utils.getDisplayObject(details.title, current);
      ['name', 'number'].forEach(function(key) {
        var escapedData = Utils.escapeHTML(data[key]);
        if (isSuggestion) {
           When rendering a suggestion, we highlight the matched substring.
           The approach is to escape the html and the search string, and
           then replace on all "words" (whitespace bounded strings) with
           the substring run through the highlight template.
          var splitData = escapedData.split(/\s+/);
          var loopReplaceFn = (function(match) {
            matchFound = true;
             The match is safe, because splitData[i] is derived from
             escapedData
            return this.tmpl.highlight.interpolate({
              str: match
            }, {
              safe: ['str']
            });
          }).bind(this);
           For each "word"
          for (var i = 0; i < splitData.length; i++) {
            var matchFound = false;
             Loop over search term regexes
            for (var k = 0; !matchFound && k < regexps[key].length; k++) {
              splitData[i] = splitData[i].replace(
                regexps[key][k], loopReplaceFn);
            }
          }
          data[key + 'HTML'] = splitData.join(' ');
        } else {
           If we have no html template injection, simply escape the data
          data[key + 'HTML'] = escapedData;
        }
      }, this);
       Render contact photo only if specifically stated on the call
      data.photoHTML = renderPhoto ?
        this.tmpl.contactPhoto.interpolate({
          photoURL: details.photoURL || ''
        }) : '';
       Interpolate HTML template with data and inject.
       Known "safe" HTML values will not be re-sanitized.
      if (isContact) {
        li.innerHTML = this.tmpl.contact.interpolate(data, {
          safe: ['nameHTML', 'numberHTML', 'srcAttr', 'photoHTML']
        });
      } else {
        li.innerHTML = this.tmpl.number.interpolate(data);
      }
      ul.appendChild(li);
       Revoke contact photo after image onload.
      var photo = li.querySelector('img');
      if (photo) {
        photo.onload = photo.onerror = function revokePhotoURL() {
          this.onload = this.onerror = null;
          URL.revokeObjectURL(this.src);
        };
      }
    }
    return true;
  }
function thui_renderContact ( params ) { if ( params . contact . tel === null ) { return false ; } var contact = params . contact ; var input = params . input . trim ( ) ; var ul = params . target ; var isContact = params . isContact ; var isSuggestion = params . isSuggestion ; var tels = contact . tel ; var telsLength = tels . length ; var renderPhoto = params . renderPhoto ; var escaped = Utils . escapeRegex ( Utils . escapeHTML ( input ) ) ; var escsubs = escaped . split ( / \s+ / ) ; var regexps = { name : escsubs . map ( function ( k ) { return new RegExp ( '^' + k , 'gi' ) ; } ) , number : [ new RegExp ( escaped , 'ig' ) ] } ; if ( ! telsLength ) { return false ; } var include = renderPhoto ? { photoURL : true } : null ; var details = isContact ? Utils . getContactDetails ( tels [ 0 ] . value , contact , include ) : { name : '' , photoURL : '' } ; for ( var i = 0 ; i < telsLength ; i ++ ) { var current = tels [ i ] ; if ( ! isSuggestion && ! Utils . compareDialables ( current . value , input ) ) { continue ; } if ( isSuggestion && this . recipients . numbers . indexOf ( current . value ) > - 1 ) { continue ; } var li = document . createElement ( 'li' ) ; var data = Utils . getDisplayObject ( details . title , current ) ; [ 'name' , 'number' ] . forEach ( function ( key ) { var escapedData = Utils . escapeHTML ( data [ key ] ) ; if ( isSuggestion ) { var splitData = escapedData . split ( / \s+ / ) ; var loopReplaceFn = ( function ( match ) { matchFound = true ; return this . tmpl . highlight . interpolate ( { str : match } , { safe : [ 'str' ] } ) ; } ) . bind ( this ) ; for ( var i = 0 ; i < splitData . length ; i ++ ) { var matchFound = false ; for ( var k = 0 ; ! matchFound && k < regexps [ key ] . length ; k ++ ) { splitData [ i ] = splitData [ i ] . replace ( regexps [ key ] [ k ] , loopReplaceFn ) ; } } data [ key + 'HTML' ] = splitData . join ( ' ' ) ; } else { data [ key + 'HTML' ] = escapedData ; } } , this ) ; data . photoHTML = renderPhoto ? this . tmpl . contactPhoto . interpolate ( { photoURL : details . photoURL || '' } ) : '' ; if ( isContact ) { li . innerHTML = this . tmpl . contact . interpolate ( data , { safe : [ 'nameHTML' , 'numberHTML' , 'srcAttr' , 'photoHTML' ] } ) ; } else { li . innerHTML = this . tmpl . number . interpolate ( data ) ; } ul . appendChild ( li ) ; var photo = li . querySelector ( 'img' ) ; if ( photo ) { photo . onload = photo . onerror = function revokePhotoURL ( ) { this . onload = this . onerror = null ; URL . revokeObjectURL ( this . src ) ; } ; } } return true ; }
Returns false when no contact has been rendered
Returns false when no contact has been rendered
/**
     *
     * params {
     *   contact:
     *     A contact object.
     *
     *   input:
     *     Any input value associated with the contact,
     *     possibly from a search or similar operation.
     *
     *   target:
     *     UL node to append the rendered contact LI.
     *
     *   isContact:
     *     |true| if rendering a contact from stored contacts
     *     |false| if rendering an unknown contact
     *
     *   isSuggestion:
     *     |true| if the value params.input should be
     *     highlighted in the rendered HTML & all tel
     *     entries should be rendered.
     *
     *   renderPhoto:
     *     |true| if we want to retrieve the contact photo
     * }
     *
     */ // Contact records that don't have phone numbers // cannot be sent SMS or MMS messages // TODO: Add email checking support for MMS // We search on the escaped HTML via a regular expression // Build a list of regexes used for highlighting suggestions // String matches occur on the beginning of a "word" to // maintain parity with the contact search algorithm which // only considers left aligned exact matches on words // Only render a contact's tel value entry for the _specified_ // input value when not rendering a suggestion. If the tel // record value _doesn't_ match, then continue. // // If rendering for contact search result suggestions, don't // render contact tel records for values that are already // selected as recipients. This comparison should be safe, // as the value in this.recipients.numbers comes from the same // source that current.value comes from. // When rendering a suggestion, we highlight the matched substring. // The approach is to escape the html and the search string, and // then replace on all "words" (whitespace bounded strings) with // the substring run through the highlight template. // The match is safe, because splitData[i] is derived from // escapedData // For each "word" // Loop over search term regexes // If we have no html template injection, simply escape the data // Render contact photo only if specifically stated on the call // Interpolate HTML template with data and inject. // Known "safe" HTML values will not be re-sanitized. // Revoke contact photo after image onload.