Completed
Push — master ( 6f3751...ba7898 )
by Dimas
13:22
created

edit.js ➔ previewRender   A

Complexity

Conditions 3

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 14
dl 0
loc 20
rs 9.7
c 0
b 0
f 0
1
$("#body").on("click keydown", function (e) {
2
  // auto height (fit content)
3
  //this.style.height = "";
4
  this.style.height = this.scrollHeight + "px";
5
});
6
$("#body").autoHeight();
7
$("#body").on("focusout", previewRender);
8
$("#preview-tab").on("click", previewRender);
9
10
/**
11
 *
12
 * @param {JQuery.Event} e
13
 */
14
function previewRender(e) {
15
  e.preventDefault();
16
  var bodyx = $("#body");
17
  bodyx.trigger("click");
18
  /**
19
   * @type {HTMLIFrameElement}
20
   */
21
  var ifr = document.getElementById("FileFrame");
22
  var doc = ifr.contentWindow.document;
23
  doc.open();
24
  doc.write(bodyx.val());
25
  doc.close();
26
27
  setTimeout(() => {
28
    // auto resize iframe by content height
29
    ifr.style.height =
30
      document.getElementById("FileFrame").contentWindow.document
31
        .documentElement.scrollHeight + "px";
32
  }, 1000);
33
}
34