Add scrollfix for iOS

This commit is contained in:
squidfunk 2016-12-29 14:19:26 +01:00
parent 9edf730873
commit 5ef3ec7aa3
11 changed files with 30 additions and 11 deletions

View File

@ -110,7 +110,7 @@
<script src="https://cdn.mathjax.org/{{ path }}"></script> <script src="https://cdn.mathjax.org/{{ path }}"></script>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<script src="{{ base_url }}/assets/javascripts/application-f33e110d6b.js"></script> <script src="{{ base_url }}/assets/javascripts/application-2442e71194.js"></script>
<script>var config={url:{base:"{{ base_url }}"}},app=new Application(config);app.initialize()</script> <script>var config={url:{base:"{{ base_url }}"}},app=new Application(config);app.initialize()</script>
{% for path in extra_javascript %} {% for path in extra_javascript %}
<script src="{{ path }}"></script> <script src="{{ path }}"></script>

View File

@ -12,7 +12,7 @@
<label class="md-nav__title" for="{{ path }}"> <label class="md-nav__title" for="{{ path }}">
{{ nav_item.title}} {{ nav_item.title}}
</label> </label>
<ul class="md-nav__list"> <ul class="md-nav__list" data-md-scrollfix>
{% for nav_item in nav_item.children %} {% for nav_item in nav_item.children %}
{% set temp = path %} {% set temp = path %}
{% set path = path + "-" + loop.index | string %} {% set path = path + "-" + loop.index | string %}

View File

@ -14,7 +14,7 @@
{% include "partials/source.html" %} {% include "partials/source.html" %}
</div> </div>
{% endif %} {% endif %}
<ul class="md-nav__list"> <ul class="md-nav__list" data-md-scrollfix>
{% for nav_item in nav %} {% for nav_item in nav %}
{% set path = "nav-" + loop.index | string %} {% set path = "nav-" + loop.index | string %}
{% include "partials/nav-item.html" %} {% include "partials/nav-item.html" %}

View File

@ -6,7 +6,7 @@
<label class="md-icon md-search__icon" for="search"></label> <label class="md-icon md-search__icon" for="search"></label>
</form> </form>
<div class="md-search__output"> <div class="md-search__output">
<div class="md-search__scrollwrap"> <div class="md-search__scrollwrap" data-md-scrollfix>
<div class="md-search-result" data-md-component="result"></div> <div class="md-search-result" data-md-component="result"></div>
</div> </div>
</div> </div>

View File

@ -5,7 +5,7 @@
{% endif %} {% endif %}
{% if toc and (toc | first) %} {% if toc and (toc | first) %}
<label class="md-nav__title" for="toc">Table of contents</label> <label class="md-nav__title" for="toc">Table of contents</label>
<ul class="md-nav__list"> <ul class="md-nav__list" data-md-scrollfix>
{% for toc_item in toc %} {% for toc_item in toc %}
{% include "partials/toc-item.html" %} {% include "partials/toc-item.html" %}
{% endfor %} {% endfor %}

View File

@ -72,6 +72,25 @@ export default class Application {
} }
wrap.appendChild(table) wrap.appendChild(table)
}) })
/* Force 1px scroll offset to trigger overflow scrolling */
if (Modernizr.ios) {
const scrollable = document.querySelectorAll("[data-md-scrollfix]")
Array.prototype.forEach.call(scrollable, item => {
item.addEventListener("touchstart", () => {
const top = item.scrollTop
/* We're at the top of the container */
if (top === 0) {
item.scrollTop = 1
/* We're at the bottom of the container */
} else if (top + item.offsetHeight === item.scrollHeight) {
item.scrollTop = top - 1
}
})
})
}
}).listen() }).listen()
/* Component: sidebar container */ /* Component: sidebar container */

View File

@ -41,7 +41,7 @@
<label class="md-nav__title" for="{{ path }}"> <label class="md-nav__title" for="{{ path }}">
{{ nav_item.title}} {{ nav_item.title}}
</label> </label>
<ul class="md-nav__list"> <ul class="md-nav__list" data-md-scrollfix>
<!-- Render nested item list --> <!-- Render nested item list -->
{% for nav_item in nav_item.children %} {% for nav_item in nav_item.children %}

View File

@ -38,7 +38,7 @@
{% include "partials/source.html" %} {% include "partials/source.html" %}
</div> </div>
{% endif %} {% endif %}
<ul class="md-nav__list"> <ul class="md-nav__list" data-md-scrollfix>
{% for nav_item in nav %} {% for nav_item in nav %}
{% set path = "nav-" + loop.index | string %} {% set path = "nav-" + loop.index | string %}
{% include "partials/nav-item.html" %} {% include "partials/nav-item.html" %}

View File

@ -31,7 +31,7 @@
<label class="md-icon md-search__icon" for="search"></label> <label class="md-icon md-search__icon" for="search"></label>
</form> </form>
<div class="md-search__output"> <div class="md-search__output">
<div class="md-search__scrollwrap"> <div class="md-search__scrollwrap" data-md-scrollfix>
<div class="md-search-result" data-md-component="result"></div> <div class="md-search-result" data-md-component="result"></div>
</div> </div>
</div> </div>

View File

@ -37,7 +37,7 @@
<!-- Render item list --> <!-- Render item list -->
{% if toc and (toc | first) %} {% if toc and (toc | first) %}
<label class="md-nav__title" for="toc">Table of contents</label> <label class="md-nav__title" for="toc">Table of contents</label>
<ul class="md-nav__list"> <ul class="md-nav__list" data-md-scrollfix>
{% for toc_item in toc %} {% for toc_item in toc %}
{% include "partials/toc-item.html" %} {% include "partials/toc-item.html" %}
{% endfor %} {% endfor %}