Skip to content

Commit

Permalink
Move scroll-buttons into a Vue component
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkykh committed Jul 2, 2018
1 parent eb7ccac commit 2457020
Show file tree
Hide file tree
Showing 14 changed files with 350 additions and 350 deletions.
41 changes: 0 additions & 41 deletions themes-default/slim/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4393,47 +4393,6 @@ CSS helper classes
cursor: default;
}

/* =======================================================================
Scroll to top
========================================================================== */
.scroll-wrapper {
position: fixed;
opacity: 0;
visibility: hidden;
overflow: hidden;
text-align: center;
font-size: 20px;
z-index: 999;
background-color: #777;
color: #eee;
width: 50px;
height: 48px;
line-height: 48px;
right: 30px;
bottom: 30px;
padding-top: 2px;
border-radius: 10px;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-ms-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}

.scroll-top-wrapper:hover {
background-color: #888;
}

.scroll-top-wrapper.show {
visibility: visible;
cursor: pointer;
opacity: 1;
}

.scroll-top-wrapper i.fa {
line-height: inherit;
}

/* CSS for Nav dropdown hover
.dropdown:hover .dropdown-menu {
display: block;
Expand Down
58 changes: 0 additions & 58 deletions themes-default/slim/static/js/common/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,66 +32,8 @@ MEDUSA.common.init = function() {
return offset;
}

/**
* Make an attempt to detect if there are currently scroll bars visible for divs with the horizontal-scroll class.
*
* If scroll bars are visible the fixed left and right buttons become visible on that page.
*/
const initHorizontalScroll = function() {
const scrollDiv = $('div.horizontal-scroll').get();
if (scrollDiv.length === 0) {
return;
}

const scrollbarVisible = scrollDiv.map(el => {
return (el.scrollWidth > el.clientWidth);
}).indexOf(true);

if (scrollbarVisible >= 0) {
$('.scroll-wrapper.left').addClass('show');
$('.scroll-wrapper.right').addClass('show');
} else {
$('.scroll-wrapper.left').removeClass('show');
$('.scroll-wrapper.right').removeClass('show');
}
};

initHorizontalScroll();

$(window).on('resize', () => {
$('.backstretch').css('top', backstretchOffset());
initHorizontalScroll();
});

// Scroll Functions
function scrollTo(dest) {
$('html, body').animate({ scrollTop: $(dest).offset().top }, 500, 'linear');
}

$('#scroll-left').on('click', e => {
e.preventDefault();
$('div.horizontal-scroll').animate({
scrollLeft: '-=153'
}, 1000, 'easeOutQuad');
});

$('#scroll-right').on('click', e => {
e.preventDefault();
$('div.horizontal-scroll').animate({
scrollLeft: '+=153'
}, 1000, 'easeOutQuad');
});

$(document).on('scroll', () => {
if ($(window).scrollTop() > 100) {
$('.scroll-wrapper.top').addClass('show');
} else {
$('.scroll-wrapper.top').removeClass('show');
}
});

$('.scroll-wrapper.top').on('click', () => {
scrollTo($('body'));
});

// Scroll to Anchor
Expand Down
19 changes: 2 additions & 17 deletions themes-default/slim/views/layouts/main.mako
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,7 @@
</div><!-- /content -->
<app-footer></app-footer>

<div class="scroll-wrapper top">
<span class="scroll-top-inner">
<i class="glyphicon glyphicon-circle-arrow-up"></i>
</span>
</div>

<div class="scroll-wrapper left">
<span class="scroll-left-inner">
<i id="scroll-left" class="glyphicon glyphicon-circle-arrow-left"></i>
</span>
</div>

<div class="scroll-wrapper right">
<span class="scroll-right-inner">
<i id="scroll-right" class="glyphicon glyphicon-circle-arrow-right"></i>
</span>
</div>
<scroll-buttons></scroll-buttons>
</div>
<script type="text/javascript" src="js/vender${('.min', '')[app.DEVELOPER]}.js?${sbPID}"></script>
<script type="text/javascript" src="js/lib/bootstrap-formhelpers.min.js?${sbPID}"></script>
Expand Down Expand Up @@ -144,6 +128,7 @@
<script src="js/store.js"></script>

<%include file="/vue-components/app-footer.mako"/>
<%include file="/vue-components/scroll-buttons.mako"/>
<%include file="/vue-components/app-link.mako"/>
<%include file="/vue-components/asset.mako"/>
<%include file="/vue-components/file-browser.mako"/>
Expand Down
114 changes: 114 additions & 0 deletions themes-default/slim/views/vue-components/scroll-buttons.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<script type="text/x-template" id="scroll-buttons-template">
<div id="scroll-buttons-wrapper">
<div class="scroll-wrapper top" :class="{ show: showToTop }" @click.prevent="scrollTop">
<span class="scroll-top-inner">
<i class="glyphicon glyphicon-circle-arrow-up"></i>
</span>
</div>

<div class="scroll-wrapper left" :class="{ show: showLeftRight }">
<span class="scroll-left-inner">
<i @click.prevent="scrollLeft" class="glyphicon glyphicon-circle-arrow-left"></i>
</span>
</div>

<div class="scroll-wrapper right" :class="{ show: showLeftRight }">
<span class="scroll-right-inner">
<i @click.prevent="scrollRight" class="glyphicon glyphicon-circle-arrow-right"></i>
</span>
</div>
</div>
</script>
<script>
Vue.component('scroll-buttons', {
template: '#scroll-buttons-template',
data() {
return {
showToTop: false,
showLeftRight: false
};
},
methods: {
scrollTop() {
const { scrollTo } = this;
scrollTo($('body'));
},
scrollLeft() {
$('div.horizontal-scroll').animate({
scrollLeft: '-=153'
}, 1000, 'easeOutQuad');
},
scrollRight() {
$('div.horizontal-scroll').animate({
scrollLeft: '+=153'
}, 1000, 'easeOutQuad');
},
/**
* Make an attempt to detect if there are currently scroll bars visible for divs with the horizontal-scroll class.
*
* If scroll bars are visible the fixed left and right buttons become visible on that page.
*/
initHorizontalScroll() {
const scrollDiv = $('div.horizontal-scroll').get();
if (scrollDiv.length === 0) {
return;
}
const scrollbarVisible = scrollDiv.map(el => {
return (el.scrollWidth > el.clientWidth);
}).indexOf(true);
if (scrollbarVisible >= 0) {
this.showLeftRight = true;
} else {
this.showLeftRight = false;
}
},
scrollTo(dest) {
$('html, body').animate({ scrollTop: $(dest).offset().top }, 500, 'linear');
}
},
mounted() {
const { initHorizontalScroll } = this;
initHorizontalScroll();
$(window).on('resize', () => {
initHorizontalScroll();
});
$(document).on('scroll', () => {
if ($(window).scrollTop() > 100) {
this.showToTop = true;
} else {
this.showToTop = false;
}
});
}
});
</script>
<style>
.scroll-wrapper {
position: fixed;
opacity: 0;
visibility: hidden;
overflow: hidden;
text-align: center;
font-size: 20px;
z-index: 999;
background-color: #777;
color: #eee;
width: 50px;
height: 48px;
line-height: 48px;
right: 30px;
bottom: 30px;
padding-top: 2px;
border-radius: 10px;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-ms-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
</style>
41 changes: 0 additions & 41 deletions themes/dark/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4393,47 +4393,6 @@ CSS helper classes
cursor: default;
}

/* =======================================================================
Scroll to top
========================================================================== */
.scroll-wrapper {
position: fixed;
opacity: 0;
visibility: hidden;
overflow: hidden;
text-align: center;
font-size: 20px;
z-index: 999;
background-color: #777;
color: #eee;
width: 50px;
height: 48px;
line-height: 48px;
right: 30px;
bottom: 30px;
padding-top: 2px;
border-radius: 10px;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-ms-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}

.scroll-top-wrapper:hover {
background-color: #888;
}

.scroll-top-wrapper.show {
visibility: visible;
cursor: pointer;
opacity: 1;
}

.scroll-top-wrapper i.fa {
line-height: inherit;
}

/* CSS for Nav dropdown hover
.dropdown:hover .dropdown-menu {
display: block;
Expand Down
58 changes: 0 additions & 58 deletions themes/dark/assets/js/common/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,66 +32,8 @@ MEDUSA.common.init = function() {
return offset;
}

/**
* Make an attempt to detect if there are currently scroll bars visible for divs with the horizontal-scroll class.
*
* If scroll bars are visible the fixed left and right buttons become visible on that page.
*/
const initHorizontalScroll = function() {
const scrollDiv = $('div.horizontal-scroll').get();
if (scrollDiv.length === 0) {
return;
}

const scrollbarVisible = scrollDiv.map(el => {
return (el.scrollWidth > el.clientWidth);
}).indexOf(true);

if (scrollbarVisible >= 0) {
$('.scroll-wrapper.left').addClass('show');
$('.scroll-wrapper.right').addClass('show');
} else {
$('.scroll-wrapper.left').removeClass('show');
$('.scroll-wrapper.right').removeClass('show');
}
};

initHorizontalScroll();

$(window).on('resize', () => {
$('.backstretch').css('top', backstretchOffset());
initHorizontalScroll();
});

// Scroll Functions
function scrollTo(dest) {
$('html, body').animate({ scrollTop: $(dest).offset().top }, 500, 'linear');
}

$('#scroll-left').on('click', e => {
e.preventDefault();
$('div.horizontal-scroll').animate({
scrollLeft: '-=153'
}, 1000, 'easeOutQuad');
});

$('#scroll-right').on('click', e => {
e.preventDefault();
$('div.horizontal-scroll').animate({
scrollLeft: '+=153'
}, 1000, 'easeOutQuad');
});

$(document).on('scroll', () => {
if ($(window).scrollTop() > 100) {
$('.scroll-wrapper.top').addClass('show');
} else {
$('.scroll-wrapper.top').removeClass('show');
}
});

$('.scroll-wrapper.top').on('click', () => {
scrollTo($('body'));
});

// Scroll to Anchor
Expand Down

0 comments on commit 2457020

Please sign in to comment.