Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gallery #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file added public/img/left-arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/right-arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions public/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
var sliderApp=angular.module('sliderApp',['ngAnimate']);

sliderApp.controller('SliderController', function($scope, $http) {
console.log("controller fired");
$scope.images = [];
$http.get('/api/images/list').success(function(data) {
data.forEach(function(image){
$scope.images.push({src:image.upload_name, title: image.timestamp});
console.log($scope.images);
})

})
});

sliderApp.directive('slider', function ($timeout) {
return {
restrict: 'AE',
replace: true,
scope:{
images: '='
},
link: function (scope, elem, attrs) {

scope.currentIndex=0;

scope.next=function(){
scope.currentIndex<scope.images.length-1?scope.currentIndex++:scope.currentIndex=0;
};

scope.prev=function(){
scope.currentIndex>0?scope.currentIndex--:scope.currentIndex=scope.images.length-1;
};

scope.$watch('currentIndex+images',function(){
scope.images.forEach(function(image){
// console.log(image);
image.visible=false;
});
console.log(scope.currentIndex, scope.images);
scope.images[scope.currentIndex].visible=true;
});

/* Start: For Automatic slideshow*/

var timer;

var sliderFunc=function(){
timer=$timeout(function(){
scope.next();
timer=$timeout(sliderFunc,10000);
},10000);
};

sliderFunc();

scope.$on('$destroy',function(){
$timeout.cancel(timer);
});

/* End : For Automatic slideshow*/

},
templateUrl:'templates/slider.html'
}
});
11 changes: 11 additions & 0 deletions public/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ paper-ripple{
color: #fff;
}

.slider{
position: relative;
left: 10%;
}
.slide{
position:absolute;
top:0;
left:0;
box-shadow: 0px 0px 15px #999;
}

.paper-header{
background-color: #2980b9;
height: 60px;
Expand Down
8 changes: 8 additions & 0 deletions public/templates/slider.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="slider">
<div class="slide" ng-repeat="image in images" ng-show="image.visible">
<img ng-src="img/{{image.src}}"/>
</div>
<div class="arrows">
<a href="#" ng-click="prev()"><img src="img/left-arrow.png"/></a> <a href="#" ng-click="next()"><img src="img/right-arrow.png"/></a>
</div>
</div>
4 changes: 4 additions & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});

router.get('/gallery', function(req, res, next) {
res.render('gallery');
});

router.get('/files', function(req, res){
res.render('file', { title : 'File Upload'});
});
Expand Down
4 changes: 4 additions & 0 deletions views/gallery.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extends layout

block content
slider(images='images')
11 changes: 8 additions & 3 deletions views/layout.jade
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
doctype html
html
html(ng-app="sliderApp")
head
title= title

script(src='/webcomponentsjs/webcomponents-lite.min.js')
meta(name='viewport', content='width=device-width', initial_scale='1')

link(href='https://fonts.googleapis.com/css?family=Roboto', rel='stylesheet', type='text/css')
link(href='https://fonts.googleapis.com/css?family=Roboto', rel='stylesheet', type='text/css')
link(rel='import', href='/polymer/polymer.html')
link(rel='import', href='/paper-button/paper-button.html')
link(rel='import', href='/paper-card/paper-card.html')
Expand All @@ -16,5 +16,10 @@ html
link(rel='import', href='/elements/ripple-card-element.html')
link(rel='stylesheet', href='/stylesheets/style.css')

body(fullbleed unresolved layout vertical)
link(href='http://fonts.googleapis.com/css?family=Open+Sans', rel='stylesheet', type='text/css')
script(src='http://code.angularjs.org/1.2.9/angular.min.js', type='text/javascript')
script(src='http://code.angularjs.org/1.2.9/angular-animate.min.js')
script(src='/js/app.js')

body(fullbleed unresolved layout vertical ng-controller='SliderController')
block content
10 changes: 10 additions & 0 deletions views/slider.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.slider
.slide(ng-repeat='image in images', ng-show='image.visible')
img(ng-src='img/{{image.src}}')
| &#x9;
.arrows
a(href='#', ng-click='prev()')
img(src='img/left-arrow.png')
|
a(href='#', ng-click='next()')
img(src='img/right-arrow.png')