diff --git a/_includes/js/my-account-button.js b/_includes/js/my-account-button.js new file mode 100644 index 0000000..bc243fe --- /dev/null +++ b/_includes/js/my-account-button.js @@ -0,0 +1,56 @@ +(function () { + + if (typeof window.fetch === "undefined" || + typeof window.$ === "undefined" || + typeof window.localStorage === "undefined" + ) { + return; + } + + var ENDPOINT = isStagingEnvironment() + ? "https://apps.staging.tiny.cloud/tiny/user/me/" + : "https://apps.tiny.cloud/tiny/user/me/"; + + var LS_KEY_VALUE = "tiny:docs:isAuthKey"; + var LS_KEY_EXPIRE = "tiny:docs:isAuthKeyExpiry"; + var EXPIRE_TIMEOUT = 15 * 60 * 1000; + + var $getTinyBtn = $(".header-get-tiny-button, .header-get-tiny-button-mobile"); + var $myAccountBtn = $(".header-my-account-button, .header-my-account-button-mobile"); + + function getIsAuthData() { + + var isAuthFromStorage = localStorage.getItem(LS_KEY_VALUE) === "true"; + var isAuthExpireFromStorage = parseInt(localStorage.getItem(LS_KEY_EXPIRE), 10); + + if (isAuthFromStorage && isAuthExpireFromStorage > Date.now()) { + return renderMyAccountButton(); + } + + fetch(ENDPOINT, { + credentials: "include", + method: "GET", + mode: "cors" + }).then(function (response) { + return response.json() + }).then(function (response) { + localStorage.setItem(LS_KEY_VALUE, response.isAuthenticated); + localStorage.setItem(LS_KEY_EXPIRE, Date.now() + EXPIRE_TIMEOUT); + if (response.isAuthenticated) { + renderMyAccountButton(); + } + }); + } + + function isStagingEnvironment() { + return window.location.hostname.indexOf("staging") || + window.location.hostname.indexOf("localhost"); + } + + function renderMyAccountButton() { + $getTinyBtn.hide(); + $myAccountBtn.css({ display: "block"}); + } + + $(document).ready(getIsAuthData); +})(); \ No newline at end of file diff --git a/_includes/notification.html b/_includes/notification.html deleted file mode 100644 index 31ff477..0000000 --- a/_includes/notification.html +++ /dev/null @@ -1,67 +0,0 @@ -
-
- TinyMCE 5 is now live!  - - Read the announcement - -
- -
- - TinyMCE 5: Power meets beauty - -
-
- - diff --git a/_includes/template/bodycontents.html b/_includes/template/bodycontents.html index 40c1354..a2a75da 100644 --- a/_includes/template/bodycontents.html +++ b/_includes/template/bodycontents.html @@ -1,71 +1,133 @@ -
- {% include notification.html %} - {% include_remote {{ site.origin }}/_docs/menu.html css="body > *" %} +{% include template/notification.html %} +{% include template/menu.html css="body > *" %} -
-
-
- - -
- -
-

{{ page.title }}

-

{{ page.description }}

- {% if page.url contains '/api/' %} - - {% else %} - Contribute to this page - {% endif %} - {% if page.controls %} - {% assign controls = page.controls | split:',' %} -
- {% for control in controls %}+ {{ control }} {% endfor %} +
+
+

{{ page.title }}

+

{{ page.description }}

+ {% if page.url contains '/api/' %} + + {% else %} + Contribute to this page + {% endif %} + {% if page.controls %} + {% assign controls = page.controls | split:',' %} +
+ {% for control in controls %}+ {{ control }} {% endfor %} +
+ {% endif %}
- {% endif %} -
-
- {{ content }} - {% include feedback.html %} -

- Can't find what you're looking for? - - Let us know. - -

- {% include license.html %} -
+
+ {{ content }} + {% include feedback.html %} +

+ Can't find what you're looking for? + + Let us know. + +

+ {% include license.html %} +
+ +
+ +
{% include_remote {{ site.origin }}/_docs/footer.html css="body > *" %} + +