B2G/gaia/apps/sms/js/thread_ui.js
/**
 * generateHeightRule
 *
 * Generates a new style element, appends to head
 * and inserts a generated rule for applying a class
 * to the recipients list to set its height for
 * multiline mode.
 *
 * @return {Boolean} true if rule was created, false if not.
 */
generateHeightRule
Generates a new style element, appends to head
and inserts a generated rule for applying a class
to the recipients list to set its height for
multiline mode.

@return {Boolean} true if rule was created, false if not.
generateHeightRule Generates a new style element appends to head and inserts a generated rule for applying a class to the recipients list to set its height for multiline mode . @return { Boolean } true if rule was created false if not .
function generateHeightRule() {
  var available, css, computed, occupied, index,
      sheet, sheets, style, tmpl;
  occupied = generateHeightRule.occupied;
  if (occupied == null) {
    computed = {
      list: window.getComputedStyle(
        ThreadUI.recipientsList, null
      ),
      carrier: window.getComputedStyle(
        document.getElementById('contact-carrier'), null
      )
    };
    occupied = generateHeightRule.occupied = [
      2,
      ThreadUI.INPUT_MARGIN,
      ThreadUI.subheader.scrollHeight,
      ThreadUI.sendButton.scrollHeight,
      parseInt(computed.list.getPropertyValue('margin-bottom'), 10),
      parseInt(computed.carrier.getPropertyValue('height'), 10)
    ].reduce(function(a, b) { return a + b; });
  }
  available = ThreadUI.container.clientHeight - occupied;
  if (available === generateHeightRule.available) {
    return false;
  }
  if (!generateHeightRule.sheet) {
    style = document.createElement('style');
    document.head.appendChild(style);
    sheets = document.styleSheets;
  }
  sheet = generateHeightRule.sheet || sheets[sheets.length - 1];
  index = generateHeightRule.index || sheet.cssRules.length;
  tmpl = generateHeightRule.tmpl || Utils.Template('height-rule-tmpl');
  css = tmpl.interpolate({
    height: String(available)
  }, { safe: ['height'] });
  if (generateHeightRule.index) {
    sheet.deleteRule(index);
  }
  sheet.insertRule(css, index);
  generateHeightRule.available = available;
  generateHeightRule.index = index;
  generateHeightRule.sheet = sheet;
  generateHeightRule.tmpl = tmpl;
  return true;
}
function generateHeightRule ( ) { var available , css , computed , occupied , index , sheet , sheets , style , tmpl ; occupied = generateHeightRule . occupied ; if ( occupied == null ) { computed = { list : window . getComputedStyle ( ThreadUI . recipientsList , null ) , carrier : window . getComputedStyle ( document . getElementById ( 'contact-carrier' ) , null ) } ; occupied = generateHeightRule . occupied = [ 2 , ThreadUI . INPUT_MARGIN , ThreadUI . subheader . scrollHeight , ThreadUI . sendButton . scrollHeight , parseInt ( computed . list . getPropertyValue ( 'margin-bottom' ) , 10 ) , parseInt ( computed . carrier . getPropertyValue ( 'height' ) , 10 ) ] . reduce ( function ( a , b ) { return a + b ; } ) ; } available = ThreadUI . container . clientHeight - occupied ; if ( available === generateHeightRule . available ) { return false ; } if ( ! generateHeightRule . sheet ) { style = document . createElement ( 'style' ) ; document . head . appendChild ( style ) ; sheets = document . styleSheets ; } sheet = generateHeightRule . sheet || sheets [ sheets . length - 1 ] ; index = generateHeightRule . index || sheet . cssRules . length ; tmpl = generateHeightRule . tmpl || Utils . Template ( 'height-rule-tmpl' ) ; css = tmpl . interpolate ( { height : String ( available ) } , { safe : [ 'height' ] } ) ; if ( generateHeightRule . index ) { sheet . deleteRule ( index ) ; } sheet . insertRule ( css , index ) ; generateHeightRule . available = available ; generateHeightRule . index = index ; generateHeightRule . sheet = sheet ; generateHeightRule . tmpl = tmpl ; return true ; }
generateHeightRule
 Generates a new style element, appends to head
 and inserts a generated rule for applying a class
 to the recipients list to set its height for
 multiline mode.
generateHeightRule Generates a new style element appends to head and inserts a generated rule for applying a class to the recipients list to set its height for multiline mode .
// This magic number ensures no part of the input // area "shifts" downward. Without this, the placeholder // text in the input appears to move ever so slightly.