Skip to content

Commit

Permalink
refactor in boot.events and asides
Browse files Browse the repository at this point in the history
  • Loading branch information
pinaypunto committed Jan 21, 2013
1 parent cc45eab commit c6faae3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
4 changes: 1 addition & 3 deletions src/boot/Lungo.Boot.Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ Lungo.Boot.Events = (function(lng, undefined) {
*
*/
var init = function() {
lng.dom(SELECTORS.HREF_ASIDE).each(function() {
lng.View.Aside.suscribeEvents(this);
});
lng.dom(SELECTORS.HREF_TARGET_FROM_ASIDE).tap(_hideAsideIfNecesary);
lng.dom(SELECTORS.HREF_TARGET).tap(_loadTarget);
// lng.dom(SELECTORS.INPUT_CHECKBOX).tap(_changeCheckboxValue);
lng.View.Aside.suscribeEvents(lng.dom(SELECTORS.HREF_ASIDE));
};

var _loadTarget = function(event) {
Expand Down
59 changes: 30 additions & 29 deletions src/view/Lungo.View.Aside.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Lungo.View.Aside = (function(lng, undefined) {
var ELEMENT = lng.Constants.ELEMENT;
var CLASS = lng.Constants.CLASS;
var ATTRIBUTE = lng.Constants.ATTRIBUTE;
var MIN_XDIFF = parseInt(document.body.getBoundingClientRect().width / 3, 10);

/**
* Toggle an aside element
Expand Down Expand Up @@ -76,36 +75,38 @@ Lungo.View.Aside = (function(lng, undefined) {
}
};

var suscribeEvents = function(href) {

var STARTED = false;
var a = lng.dom(href);
var section = a.closest("section");
var aside = lng.dom(a.attr("href"));

section.swiping(function(gesture) {
if(!section.hasClass("aside")) {
var xdiff = gesture.currentTouch.x - gesture.iniTouch.x;
var ydiff = Math.abs(gesture.currentTouch.y - gesture.iniTouch.y);
STARTED = STARTED ? true : xdiff > 3*ydiff && xdiff < 50;
if(STARTED) {
xdiff = xdiff > 256 ? 256 : xdiff < 0 ? 0 : xdiff;
aside.addClass(CLASS.SHOW);
section.vendor('transform', 'translateX(' + xdiff + 'px)');
section.vendor('transition-duration', '0s');
} else {
section.attr('style', '');
var suscribeEvents = function(hrefs) {
var MIN_XDIFF = parseInt(document.body.getBoundingClientRect().width / 3, 10);
hrefs.each(function() {
var STARTED = false;
var a = lng.dom(this);
var section = a.closest("section");
var aside = lng.dom(a.attr("href"));

section.swiping(function(gesture) {
if(!section.hasClass("aside")) {
var xdiff = gesture.currentTouch.x - gesture.iniTouch.x;
var ydiff = Math.abs(gesture.currentTouch.y - gesture.iniTouch.y);
STARTED = STARTED ? true : xdiff > 3*ydiff && xdiff < 50;
if(STARTED) {
xdiff = xdiff > 256 ? 256 : xdiff < 0 ? 0 : xdiff;
aside.addClass(CLASS.SHOW);
section.vendor('transform', 'translateX(' + xdiff + 'px)');
section.vendor('transition-duration', '0s');
} else {
section.attr('style', '');
}
}
}
});
});

section.swipe(function(gesture) {
var diff = gesture.currentTouch.x - gesture.iniTouch.x;
var ydiff = Math.abs(gesture.currentTouch.y - gesture.iniTouch.y);
section.attr('style', '');
if(diff > MIN_XDIFF && STARTED) show(aside);
else hide(aside);
STARTED = false;
section.swipe(function(gesture) {
var diff = gesture.currentTouch.x - gesture.iniTouch.x;
var ydiff = Math.abs(gesture.currentTouch.y - gesture.iniTouch.y);
section.attr('style', '');
if(diff > MIN_XDIFF && STARTED) show(aside);
else hide(aside);
STARTED = false;
});
});
};

Expand Down

0 comments on commit c6faae3

Please sign in to comment.