Skip to content
This repository was archived by the owner on Jul 8, 2020. It is now read-only.
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
1 change: 1 addition & 0 deletions src/_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// @include ./core/const.js
// @include ./core/object.js
// @include ./core/config.js
// @include ./core/backstack.js
// @include ./core/logger.js
// @include ./core/controller.js
// @include ./core/application.js
Expand Down
140 changes: 140 additions & 0 deletions src/core/backstack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Copyright (c) 2013 M-Way Solutions GmbH
// http://github.com/mwaylabs/The-M-Project/blob/absinthe/MIT-LICENSE.txt

/**
*
* Use the BackStack to manage the navigation stack
* @module M.BackStack
*
* @type {*}
* @extends M.Object
*/
M.BackStack = M.Object.design({

/**
* The stack contains an object with the
* name of the route and the corresponding data
* @type {Array}
*/
stack: [],

/**
* The counter counts your steps
* trough the application forwards and backwards
* @type {Integer}
*/
counter: 0,

/**
* Is set to YES when first time starting
* at root route or deleting stack
* @type {Integer}
*/
initial: YES,

/**
* Recognizes if moving forward in history stack or
* backwards and push or pop item to the stack.
*/
manage: function(){

var next = Backbone.history.fragment ? Backbone.history.fragment : '/';

var previous = '';
if(this.stack[this.counter-1]){
previous = this.stack[this.counter-1].path;
}

if(this.initial){
this.initial = NO;
this.stack.push({
path: next,
data: {}
});
this.counter = 0;

}else {
if(previous !== next){
this.stack.push({
path: next,
data: {}
});
this.counter++;

}else{
this.stack.pop();
this.counter--;
}
}

var route = '';

_.each(this.stack, function(item){
route = route.concat(' '+ item.path);
});
route = ('--------------- \n' + 'route: ' + route);

console.log(route);

console.log(this.stack[this.counter]);

},

/**
* Deletes complete stack and initializes it with acutal route
*/
deleteStack: function(){
this.stack = [];
this.initial = YES;
this.counter = 0;
this.manage();
return;
},

/**
* Stack is set one step back
*/
goBack: function(){
this.stack.pop();
this.counter--;
return;
},

/**
* Searches for route in stack and jumps to that position.
* Removes all following items in stack
* @param route
*/
goBackTo: function(route){
if(route && typeof route === 'string'){
var searchIndex = 0;
_.each(this.stack, function(item, index){
if(item.path === route){
searchIndex = index;
this.stack = this.stack.splice(searchIndex);
return;
}
}, this);
}
},

/**
* Getter for data of actual route
* @returns {Object}
*/
getData: function(){
return this.stack[this.counter].data;
},

/**
* Setter for data of actual route
* @param data
*/
setData: function(data){
if(data){
this.stack[this.counter].data = data;
}
return;
}

});
5 changes: 5 additions & 0 deletions src/core/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ _.extend(M.Controller.prototype, Backbone.Events, {
},

apply: function( router, args ) {
this.manageStack();
var appInstance = global[M.APPLICATION_NAME];

if( appInstance.isInitialLoad ) {
Expand All @@ -70,5 +71,9 @@ _.extend(M.Controller.prototype, Backbone.Events, {
} else {
this.show.apply(this, args);
}
},

manageStack: function(){
M.BackStack.manage();
}
});
18 changes: 9 additions & 9 deletions src/templates.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/templates/default/text.ejs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<div><% if(label) { %><div class="label"><%= label %></div><% } %><div><% if(icon) { %><div class="input-icon-addon"><i class="fa <%= icon %> fa-fw"></i><% } %><%= value %></div>
<div><% if(label) { %> <div class="label"><%= label %></div> <% } %> <% if(icon) { %> <div class="input-icon-addon"><i class="fa <%= icon %> fa-fw"></i></div> <% } %> <p class="inner-text"><%= value %></p></div>


8 changes: 5 additions & 3 deletions src/ui/layouts/tab-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ M.TabLayout = M.Layout.extend({
that.switchToTab(element.index);
}
}
}).create();
}).create(that.scope, null, true );
},

_extendContent: function( options ) {
var that = this;
return options.content.extend({
var content = options.content.extend({
events: {
dragleft: function( event, element ) {
that.switchToTab(options.index + 1);
Expand All @@ -126,7 +126,9 @@ M.TabLayout = M.Layout.extend({
that.switchToTab(options.index - 1);
}
}
}).create();
}).create(that.scope, null, true);

return content;
},

//TODO
Expand Down
Loading