
import Ember from 'ember';

export default Ember.Service.extend({

  // inspired by http://stackoverflow.com/a/39089679
  getWidthOfText(txt, fontsize){
    // Create dummy span
    var e = document.createElement('span');

    // set the base font defined in app.scss
    //e.className = 'base-font';
    e.style.fontFamily = 'sans-serif';
    // Set font-size
    e.style.fontSize = fontsize;
    // Set text
    e.innerHTML = txt;
    // Return width
    e.style.visibility = 'hidden';

    document.body.appendChild(e);
    let w = e.offsetWidth;
    document.body.removeChild(e);

    return w;
  }
});
