aszx87410 / frontend-intermediate-course

It's a free online course about some frontend tech including Ajax, CORS, gulp, webpack and so on.
266 stars 88 forks source link

[作業] 繳交hw7 #105

Closed lucreciaLin closed 7 years ago

lucreciaLin commented 7 years ago

slack 帳號

lucrelin

哪一個作業

走向國際:i18n 作業 Github 連結

https://github.com/lucreciaLin/frontend-intermediate-course/tree/master/answers/hw7

作業 Github Page 連結

https://lucreciaLin.github.io/frontend-intermediate-course/answers/hw7/index.html

其他補充說明

附加修改hw6的"頻道數目不是三的倍數的時候排版問題"...

aszx87410 commented 7 years ago

ok,都很不錯,特別喜歡你把切換語言按鈕那邊用 attribute 來做,很不錯的用法 只是這一段:https://github.com/lucreciaLin/frontend-intermediate-course/blob/master/answers/hw7/assets/js/index.js#L169-L188 的程式碼重複性很高,其實可以改成:

function changeLang(e) {
    var e = event.target;
    let getAttr = e.getAttribute("data-selectedLang");
    if (getAttr === "en" || getAttr === 'zh-tw') {
      document.getElementById("mainTitle").innerHTML = window.I18N[getAttr].TITLE;
      m_lang = getAttr;
      //the following 4 lines: recalculation
      m_offset = 0;
      m_dataOffset = 0;
      LIZONE.innerHTML="";
      init();
    }
  }
lucreciaLin commented 7 years ago

"切換語言按鈕那邊用 attribute 來做"是我以前有次在網路上看到別人的做法, 這次想到可以拿來用而已^^

謝謝你! 其實一直在想如何簡潔這部分的code, 但沒想到, 已將你的修改建議修改在作業8 真的好高招! 謝謝指導, 很受用 : )