cms/app-client/app/services/utils.js
author ymh <ymh.work@gmail.com>
Thu, 23 Feb 2017 10:37:22 +0100
changeset 522 c6cad1055714
parent 467 762fc0eb4946
permissions -rw-r--r--
force router refresh and close notice or transcript when clicking on navigation links. Fix #0025933


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;
  }
});