Skip to content

Instantly share code, notes, and snippets.

@monapasan
Created June 7, 2015 23:24
Show Gist options
  • Save monapasan/a4480bcd2aeca1348157 to your computer and use it in GitHub Desktop.
Save monapasan/a4480bcd2aeca1348157 to your computer and use it in GitHub Desktop.
var Node = Famous.Node;
var DOMElement = Famous.DOMElement;
var Align = Famous.Align;
var Header = App.Header;
var Footer = App.Footer;
var Swapper = App.Swapper;
var GestureHandler = Famous.GestureHandler;
var ArticleSelectionBody = App.ArticleSelectionBody;
function SelectionView(data) {
Node.call(this);
this.currentArtikel = 0;
this.data = data;
this.articelAmount = data.length;
this.addUIEvent("click");
makeBackground.call(this);
makeHeader.call(this);
makeFooter.call(this);
this.artikels = makeArticles.call(this);
}
SelectionView.prototype = Object.create(Node.prototype);
SelectionView.prototype.constructor = SelectionView;
SelectionView.prototype.onReceive = function onReceive (event, payload) {
if (event === 'click') {
var to;
if(payload.node == this.footer)
to = this.currentArtikel + 1;
else if(payload.node == this.header)
to = this.currentArtikel - 1;
else
this.emit('goToAnotherView',{href: payload.node.getParent().data._id});
if(to >= this.articelAmount || to < 0){
return;
}
this.emit('changeArtikel', {
from: this.currentArtikel,
to: to
});
}
if(event === "changeArtikel"){
this.changeArtikel(payload.to);
}
this.receive(event, payload);
};
SelectionView.prototype.onParentMount = function onMount (parent, id) {
Node.prototype.onMount.call(this, parent, id);
this.emit('changeArtikel', {from: null, to: this.currentArtikel});
};
function makeBackground(){
this.backgroundColor = new DOMElement(this, {
classes: ['bg']/*,
properties:{
backgroundColor: '#'+ this.data.bgColor
} */
});
}
function makeArticles(articleNumber) {
var result = {};
this.data.forEach(function(dataItem, i){
var child = this.addChild()
.setDifferentialSize(null, -100)
.setPosition(0, 50);
result[i] = {
align: new Align(child),
artikel: child.addChild(new ArticleSelectionBody(this.data[i], i))
};
}.bind(this));
return result;
}
SelectionView.prototype.changeArtikel = function changeArtikel (to) {
var curve = {duration: 500, curve: 'easeIn'};
this.data.forEach(function (section, i) {
if (i === to)
this.artikels[i].align.set(0, 0, 0, {
duration: 500, curve: 'easeOut'
});
else
this.artikels[i].align.set(0, 1, 0, {
duration: 500, curve: 'easeIn'
});
}.bind(this));
if(to == this.articelAmount - 1){
this.header.setOpacity(1, curve);
this.footer.setOpacity(0, curve);
}
else if(to === 0){
this.footer.setOpacity(1, curve);
this.header.setOpacity(0, curve);
} else{
this.footer.setOpacity(1, curve);
this.header.setOpacity(1, curve);
}
this.currentArtikel = to;
};
function makeHeader() {
this.header = this.addChild()
.setSizeMode('default', 'absolute')
.setAbsoluteSize(null, 50)
.setMountPoint(0.5, 0)
.setAlign(0.5, 0);
this.headerEl = new DOMElement(this.header, {
classes: ['arrowUp', 'white']
});
this.header.addUIEvent('click');
}
function makeFooter(){
footer = this.addChild()
.setSizeMode('default', 'absolute')
.setAbsoluteSize(null, 50)
.setMountPoint(0, 1)
.setAlign(0, 1);
this.footerEl = new DOMElement(footer, {
classes: ['arrowDown', 'white']
});
footer.addUIEvent('click');
var myComponent = {
onReceive: function(event, payload) {
console.log('Received ' + event + ' event!');
}
};
footer.addComponent(myComponent);
this.footer = footer;
}
App.SelectionView = SelectionView;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment