Skip to content

Commit

Permalink
Merge pull request #140 from refugeetech/feature/issue75
Browse files Browse the repository at this point in the history
Add share button. Closes issue#75
  • Loading branch information
brylie committed Feb 15, 2016
2 parents 2cccf95 + cbbfb61 commit 1514f0f
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 66 deletions.
37 changes: 29 additions & 8 deletions main/client/header/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,39 @@ <h1 class="visuallyhidden">Refugee Tech</h1>
</div>
<div class="navbar-collapse collapse" id="rft-collapse-navbar">
<ul class="text-uppercase navbar-left navbar-nav nav ">
<!--When changing to proper links for "What we do", "Knowledge hub" and "Blog", please change the path in <li> to the same as in the corresponding href-->
<li class="{{isActivePath class='active' path='/#about'}}"><a href="/#about">What we do</a></li>
<li class="{{isActivePath class='active' path='/#knowledge'}}"><a href="/#knowledge">Knowledge Hub</a></li>
<li class="{{isActivePath class='active' path='/projects'}}"><a href="/projects">Projects</a></li>
<li class="{{isActivePath class='active' path='/#blog'}}"><a href=/#blog>Blog</a></li>
<li><a href="#">What we do</a></li>
<li><a href="#">Knowledge Hub</a></li>
<li><a href="/projects">Projects</a></li>
<li><a href="#">Blog</a></li>
</ul>
<ul class="navbar-right navbar-nav nav">
<li><a href="#"><span class="glyphicon glyphicon-globe" aria-hidden="true"></span><span class="visible-lg-inline visible-xs-inline">English</span></a></li>
<li><a href="#"><span class="glyphicon glyphicon-share-alt" aria-hidden="true"></span><span class="visible-lg-inline visible-xs-inline">Share</span></a></li>
<li>
<a href="#">
<span class="glyphicon glyphicon-globe" aria-hidden="true"></span>
<span class="visible-lg-inline visible-xs-inline">English</span>
</a>
</li>
<li id="share-button-container">
<share-button></share-button>
</li>
<!--<li><a class="activate-searchbar" href="#"><span class="glyphicon glyphicon-search" aria-hidden="true"></span><span class="visible-lg-inline visible-xs-inline">Search</span></a></li>-->
</ul>
</div>
</div>
</nav>
<div class="navbar-collapse collapse" id="rft-collapse-navbar">
<ul class="text-uppercase navbar-left navbar-nav nav ">
<!--When changing to proper links for "What we do", "Knowledge hub" and "Blog", please change the path in <li> to the same as in the corresponding href-->
<li class="{{isActivePath class='active' path='/#about'}}"><a href="/#about">What we do</a></li>
<li class="{{isActivePath class='active' path='/#knowledge'}}"><a href="/#knowledge">Knowledge Hub</a></li>
<li class="{{isActivePath class='active' path='/projects'}}"><a href="/projects">Projects</a></li>
<li class="{{isActivePath class='active' path='/#blog'}}"><a href=/#blog>Blog</a></li>
</ul>
<ul class="navbar-right navbar-nav nav">
<li><a href="#"><span class="glyphicon glyphicon-globe" aria-hidden="true"></span><span class="visible-lg-inline visible-xs-inline">English</span></a></li>
<li><a href="#"><span class="glyphicon glyphicon-share-alt" aria-hidden="true"></span><span class="visible-lg-inline visible-xs-inline">Share</span></a></li>
<!--<li><a class="activate-searchbar" href="#"><span class="glyphicon glyphicon-search" aria-hidden="true"></span><span class="visible-lg-inline visible-xs-inline">Search</span></a></li>-->
</ul>
</div>
</div>
</nav>
</template>
93 changes: 51 additions & 42 deletions main/client/header/navbar.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,56 @@
if (Meteor.isClient) {

Meteor.startup(function() {
// Runs when the DOM is ready
Session.set('willShowAutoSuggestion',false);

const NAVBAR_HEIGHT = 75; // original navbar height in px

var $window = $(window),
$document = $(document),
$searchbar = $('#searchbar');

$window.on('scroll', function(e) {
// The scroll event is not supported yet by Meteor https://github.com/meteor/meteor/issues/3298,
// so we use a jquery instead.
// This block runs whenever the page is scrolled
toggleNavbarClass();
});

var toggleNavbarClass = function() {
// Toggles a css class when the page is scrolled past NAVBAR_HEIGHT.
// The behaviour is controlled from the .shrinked class in navbar.css
let $topNav = $('#top-nav');
if ($document.scrollTop() > NAVBAR_HEIGHT) {
$topNav.addClass('shrinked');
$searchbar.addClass('navbar-is-shrinked');
}
else {
$topNav.removeClass('shrinked');
$searchbar.removeClass('navbar-is-shrinked');
}
};
}); // end Meteor.startup

Template.mainNavbar.events({
'click .activate-searchbar': function(event) {
event.preventDefault();
if(!$('#searchbar').hasClass('active')) {
Template.mainNavbar.rendered = function () {
// Get reference to template instance
let instance = this;

const NAVBAR_HEIGHT = 75; // original navbar height in px

var $window = $(window),
$document = $(document),
$searchbar = $('#searchbar');


$window.on('scroll', function(e) {
// The scroll event is not supported yet by Meteor https://github.com/meteor/meteor/issues/3298,
// so we use a jquery instead.
// This block runs whenever the page is scrolled
toggleNavbarClass();
});

var toggleNavbarClass = function() {
// Toggles a css class when the page is scrolled past NAVBAR_HEIGHT.
// The behaviour is controlled from the .shrinked class in navbar.css
let $topNav = $('#top-nav');
if ($document.scrollTop() > NAVBAR_HEIGHT) {
$topNav.addClass('shrinked');
$searchbar.addClass('navbar-is-shrinked');
}
else {
$topNav.removeClass('shrinked');
$searchbar.removeClass('navbar-is-shrinked');
}
};

//adding share-button
let config = {
ui: {
flyout: "bottom center",
button_font: false,
icon_font:false
}
};

new ShareButton(config);
};

Template.mainNavbar.events({
'click .activate-searchbar': function(event) {
event.preventDefault();
if(!$('#searchbar').hasClass('active')) {
// Focus on the input of the searchbar only if it is already hidden
$('#searchbar input').focus();
//show autosuggestions only if input has focus
Session.set('willShowAutoSuggestion',true);
}
$('#searchbar').toggleClass('active'); // Toggle the searchbar
}
});
}
$('#searchbar').toggleClass('active'); // Toggle the searchbar
}
});
28 changes: 12 additions & 16 deletions main/client/header/searchbar.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
if(Meteor.isClient) {
Template.searchbar.events({
'keyup #searchbar [type=text]': function(event, template) {
// Mimic a search
$('#spinner').removeClass('hidden'); // Show the spinner icon

Template.searchbar.events({
'keyup #searchbar [type=text]': function(event, template) {
// Mimic a search
$('#spinner').removeClass('hidden'); // Show the spinner icon

window.setTimeout(function() { // Remove spinner icon after a while
$('#spinner').addClass('hidden')
}, 1500);
},
'blur input':function(event,template) {
$('#searchbar').removeClass('active'); //hide the searchbar when input blurs
}
});

}
window.setTimeout(function() { // Remove spinner icon after a while
$('#spinner').addClass('hidden')
}, 1500);
},
'blur input':function(event,template) {
$('#searchbar').removeClass('active'); //hide the searchbar when input blurs
}
});
14 changes: 14 additions & 0 deletions main/client/header/share-button.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
share-button {
background: #fff;
color: #1d2660;
}

#top-nav .navbar-nav.navbar-right #share-button-container {
margin-right: calc(20/16 * 1em);
padding: calc(28/16 * 1em - 0.2em) calc(4/16 * 1em) calc(26/16 * 1em - 5px);
}
#top-nav.shrinked .navbar-right #share-button-container {
padding: 1em calc(4/16 * 1em) calc(1em - 5px);
}


1 change: 1 addition & 0 deletions main/client/lib/carrot-share/share-button.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions main/client/lib/carrot-share/share-button.min.js

Large diffs are not rendered by default.

0 comments on commit 1514f0f

Please sign in to comment.