Skip to content

Commit

Permalink
Fully removed stack from program (issue #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
gigafiga21 committed Nov 24, 2017
1 parent 90fb6c1 commit 2851fb4
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 24 deletions.
8 changes: 0 additions & 8 deletions CSS/RISE.CSS
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@
TRANSITION:NONE !IMPORTANT;
}

.RISE__SHIELD
{
POSITION:ABSOLUTE;
WIDTH:100%;
HEIGHT:100%;
}

.RISE__CONTAINER
{
POSITION:RELATIVE;
DISPLAY:FLEX;
WIDTH:100%;
}

Expand Down
3 changes: 2 additions & 1 deletion EXAMPLE.HTML
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
{
tabId++;
var tab = interface.createTab(tabId);
tab.dataset.previous = tabId - 1;
renderTab(tab);
interface.showTab(tabId);
}
Expand All @@ -74,7 +75,7 @@

function hideTab(event)
{
interface.hideTab(event.target.parentNode.parentNode.dataset.id);
interface.showTab(event.target.parentNode.parentNode.dataset.previous);
}

function renderTab(tab)
Expand Down
79 changes: 64 additions & 15 deletions JS/RISE.JS
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ function Interface(parent, params)

var timer = undefined,
current = undefined,
stack = [],
order = [],
properties =
{
Expand Down Expand Up @@ -85,8 +84,8 @@ function Interface(parent, params)
/**
* Returns a tab name
*
* @param {Element} - DOM-Element in tab
* @return {Element} - name of the found tab
* @param {Element} element - DOM-Element in tab
* @return {Element} - name of the found tab
*/
this.getTabName = function(element)
{
Expand All @@ -106,6 +105,36 @@ function Interface(parent, params)
return undefined;
}

/**
* Return a direction of swiping
*
* @param {String} start - name of the tab where swipe starts
* @param {String} end - name of the tab where swipe ends
* @return {Number} - 1 if swipe is to right, 0 if start equals end, else -1
*/
function getSwipeDirection(start, end)
{
if (DOM.tabs[start] && DOM.tabs[end])
{
if (order.indexOf(start) < order.indexOf(end))
{
return 1;
}
else if (start == end)
{
return 0;
}
else
{
return -1;
}
}
else
{
console.warn("ERROR: no tab called " + start + " or " + end);
}
}

/**
* Shows tab on DOM
*
Expand All @@ -115,18 +144,45 @@ function Interface(parent, params)
{
if (DOM.tabs[name])
{
let previous = current,
to = {x: undefined, y: undefined},
from = {x: undefined, y: undefined},
direction = getSwipeDirection(current, name);

stack.push(name);
console.log(direction);
current = name;
DOM.tabs[name].removeCSS(CSS.hidden);
if (direction == 1)
{
to.x = - DOM.tabs[current].offsetLeft + "PX";
to.y = - DOM.tabs[current].offsetTop + "PX";
from.x = "0PX";
from.y = "0PX";
}
else if (direction == -1)
{
from.x = - DOM.tabs[previous].offsetLeft + "PX";
from.y = - DOM.tabs[previous].offsetTop + "PX";
to.x = "0PX";
to.y = "0PX";
}

DOM.container.style.left = from.x;
DOM.container.style.top = from.y;
var layoutTrigger = DOM.container.offsetHeight;
DOM.container.removeCSS(CSS.noAnimation);
DOM.container.style.left = - DOM.tabs[name].offsetLeft + "PX";
DOM.container.style.top = - DOM.tabs[name].offsetTop + "PX";
DOM.container.style.left = to.x;
DOM.container.style.top = to.y;

if (DOM.tabs[stack[stack.length - 2]])
if (DOM.tabs[current])
{
setTimeout((function()
{
DOM.tabs[stack[stack.length - 2]].setCSS(CSS.hidden);
if (DOM.tabs[previous])
{
DOM.tabs[previous].setCSS(CSS.hidden);
}

DOM.container.setCSS(CSS.noAnimation);
DOM.container.style.left = "0PX";
DOM.container.style.top = "0PX";
Expand Down Expand Up @@ -176,14 +232,7 @@ function Interface(parent, params)
}).bind(this), properties.duration * 1000);*/
}

let indexInStack = stack.indexOf(name);

order.splice(order.indexOf(name), 1);
while (indexInStack != -1)
{
stack.splice(indexInStack, 1);
indexInStack = stack.indexOf(name);
}

}
else
Expand Down

0 comments on commit 2851fb4

Please sign in to comment.