|
@ -1,14 +1,17 @@ |
|
|
<tiny-one-page> |
|
|
<tiny-one-page> |
|
|
<div class="tiny-one-page"> |
|
|
<div class="tiny-one-page"> |
|
|
<div class="tiny-one-page__inner"></div> |
|
|
|
|
|
<button class="tiny-one-page__button"> |
|
|
|
|
|
<i class="icon icon-menu"></i> |
|
|
|
|
|
|
|
|
<div style="{ getStyles() }" class={ getModalClasses() }> |
|
|
|
|
|
<div class="tiny-one-page__inner"></div> |
|
|
|
|
|
</div> |
|
|
|
|
|
<button class="tiny-one-page__button button button--tiny-one-page" onclick={ handleToggle }> |
|
|
|
|
|
<i class={ getIconClasses() } /> |
|
|
</button> |
|
|
</button> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
|
|
|
<script> |
|
|
<script> |
|
|
|
|
|
|
|
|
import SmoothScroll from 'smooth-scroll'; |
|
|
import SmoothScroll from 'smooth-scroll'; |
|
|
|
|
|
import { throttle, debounce } from 'throttle-debounce'; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* tiny-one-page.riot |
|
|
* tiny-one-page.riot |
|
@ -29,8 +32,19 @@ |
|
|
* |
|
|
* |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
export default |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
export default { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* |
|
|
|
|
|
*/ |
|
|
|
|
|
state: |
|
|
|
|
|
{ |
|
|
|
|
|
isOpen: false, |
|
|
|
|
|
animate: null, |
|
|
|
|
|
namespace: 'tiny-one-page' |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* getting innerHTML and remove |
|
|
* getting innerHTML and remove |
|
|
* |
|
|
* |
|
@ -38,8 +52,23 @@ |
|
|
*/ |
|
|
*/ |
|
|
onBeforeMount() |
|
|
onBeforeMount() |
|
|
{ |
|
|
{ |
|
|
this.content = this.root.innerHTML |
|
|
|
|
|
this.root.innerHTML = '' |
|
|
|
|
|
|
|
|
// getting helper and add component
|
|
|
|
|
|
this.state.animate = this.props.animate; |
|
|
|
|
|
this.state.animate.setComponent(this); |
|
|
|
|
|
|
|
|
|
|
|
this.content = this.root.innerHTML; |
|
|
|
|
|
this.root.innerHTML = ''; |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* getting innerHTML and remove |
|
|
|
|
|
* |
|
|
|
|
|
* |
|
|
|
|
|
*/ |
|
|
|
|
|
onBeforeUnmount() |
|
|
|
|
|
{ |
|
|
|
|
|
document.addEventListener('click', this.handleClick.bind(this)); |
|
|
|
|
|
this.$('.tiny-one-page__inner a').removeEventListener('click', this.handleClose.bind(this)); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -56,14 +85,20 @@ |
|
|
// adding scroll smooth, get all elements with hash
|
|
|
// adding scroll smooth, get all elements with hash
|
|
|
this.scroll = new SmoothScroll('.tiny-one-page__inner a[href*="#"]'); |
|
|
this.scroll = new SmoothScroll('.tiny-one-page__inner a[href*="#"]'); |
|
|
|
|
|
|
|
|
window.addEventListener('scroll', this.handleScroll.bind(this), false); |
|
|
|
|
|
|
|
|
window.addEventListener('scroll', throttle(300, this.handleScroll.bind(this)), false); |
|
|
|
|
|
|
|
|
// if hash is set,
|
|
|
|
|
|
|
|
|
// if hash is set
|
|
|
if (window.location.hash) { |
|
|
if (window.location.hash) { |
|
|
this.$(".tiny-one-page__inner a[href$='" + window.location.hash + "']").click(); |
|
|
this.$(".tiny-one-page__inner a[href$='" + window.location.hash + "']").click(); |
|
|
} else { |
|
|
} else { |
|
|
this.addClass(this.$$(".tiny-one-page__inner a")[0]); |
|
|
this.addClass(this.$$(".tiny-one-page__inner a")[0]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// adding for outer click and all a-tags click event to close
|
|
|
|
|
|
document.addEventListener('click', this.handleClick.bind(this)) |
|
|
|
|
|
this.$$('.tiny-one-page__inner a').forEach((a) => { |
|
|
|
|
|
a.addEventListener('click', this.handleClose.bind(this)); |
|
|
|
|
|
}); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -92,6 +127,86 @@ |
|
|
.remove('current'); |
|
|
.remove('current'); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* @return {string} |
|
|
|
|
|
*/ |
|
|
|
|
|
getStyles() |
|
|
|
|
|
{ |
|
|
|
|
|
return this.state.animate.getStyles(); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* |
|
|
|
|
|
*/ |
|
|
|
|
|
getIconClasses() |
|
|
|
|
|
{ |
|
|
|
|
|
return this.state.isOpen ? |
|
|
|
|
|
'icon icon-tiny-one-page-close' : |
|
|
|
|
|
'icon icon-tiny-one-page-open'; |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* |
|
|
|
|
|
*/ |
|
|
|
|
|
getModalClasses() |
|
|
|
|
|
{ |
|
|
|
|
|
return this.state.isOpen ? |
|
|
|
|
|
'tiny-one-page__modal tiny-one-page__modal--open' : |
|
|
|
|
|
'tiny-one-page__modal tiny-one-page__modal--closed'; |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* |
|
|
|
|
|
*/ |
|
|
|
|
|
handleClick(event) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!this.root.contains(event.target)) { |
|
|
|
|
|
this.handleClose(); |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* |
|
|
|
|
|
*/ |
|
|
|
|
|
handleOpen() |
|
|
|
|
|
{ |
|
|
|
|
|
this.state.animate.prepareOpen(); |
|
|
|
|
|
this.state.isOpen = true; |
|
|
|
|
|
|
|
|
|
|
|
this.update(); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* |
|
|
|
|
|
*/ |
|
|
|
|
|
handleClose() |
|
|
|
|
|
{ |
|
|
|
|
|
this.state.animate.prepareClose(); |
|
|
|
|
|
this.state.isOpen = false; |
|
|
|
|
|
|
|
|
|
|
|
this.update(); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* toggle modal |
|
|
|
|
|
* |
|
|
|
|
|
* |
|
|
|
|
|
*/ |
|
|
|
|
|
handleToggle() |
|
|
|
|
|
{ |
|
|
|
|
|
if (this.state.isOpen === true) { |
|
|
|
|
|
this.handleClose(); |
|
|
|
|
|
} else { |
|
|
|
|
|
this.handleOpen(); |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* handle scrolling and check visibility of elements from navigation |
|
|
* handle scrolling and check visibility of elements from navigation |
|
|
* |
|
|
* |
|
@ -129,8 +244,8 @@ |
|
|
|
|
|
|
|
|
// check if element is visible
|
|
|
// check if element is visible
|
|
|
if (!result && |
|
|
if (!result && |
|
|
(target.offsetTop - (window.innerHeight / 2)) <= (window.pageYOffset + offset) && |
|
|
|
|
|
(target.offsetTop + target.offsetHeight) - (window.innerHeight / 2) > window.pageYOffset) { |
|
|
|
|
|
|
|
|
(target.offsetTop - (window.innerHeight / 2)) <= (window.pageYOffset + offset) && |
|
|
|
|
|
(target.offsetTop + target.offsetHeight) - (window.innerHeight / 2) > window.pageYOffset) { |
|
|
result = target; |
|
|
result = target; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -142,6 +257,5 @@ |
|
|
this.addClass(this.$(".tiny-one-page__inner a[href$='" + result.id + "']")); |
|
|
this.addClass(this.$(".tiny-one-page__inner a[href$='" + result.id + "']")); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
</script> |
|
|
</script> |
|
|
</tiny-one-page> |
|
|
</tiny-one-page> |