diff --git a/src/_core.js b/src/_core.js index 3d0195d3d..8cccf7029 100644 --- a/src/_core.js +++ b/src/_core.js @@ -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 diff --git a/src/core/backstack.js b/src/core/backstack.js new file mode 100644 index 000000000..cc483204e --- /dev/null +++ b/src/core/backstack.js @@ -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; + } + +}); \ No newline at end of file diff --git a/src/core/controller.js b/src/core/controller.js index 579b3c4f6..799d3338b 100644 --- a/src/core/controller.js +++ b/src/core/controller.js @@ -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 ) { @@ -70,5 +71,9 @@ _.extend(M.Controller.prototype, Backbone.Events, { } else { this.show.apply(this, args); } + }, + + manageStack: function(){ + M.BackStack.manage(); } }); \ No newline at end of file diff --git a/src/templates.js b/src/templates.js index 7965355f3..00593602d 100644 --- a/src/templates.js +++ b/src/templates.js @@ -1,10 +1,10 @@ -// Copyright (c) 2014 M-Way Solutions GmbH -// http://github.com/mwaylabs/The-M-Project/blob/absinthe/MIT-LICENSE.txt - -//////////////////////////////////////////////////////////////// -// DO NOT EDIT THIS FILE - it is generated by grunt -//////////////////////////////////////////////////////////////// - -/* jshint -W109 */ -M.Templates = {"default":{"accordion.ejs":"","accordionitem.ejs":"","button.ejs":"
<% if(icon) { %> \"> <% } %>
><%= value %>
","buttongroup.ejs":"
","checkboxlist.ejs":"
<%= label %>
","checkboxoption.ejs":"","debug.ejs":"
","dialog.ejs":"
","image.ejs":"\" alt=\"<%= alt %>\"/>","label.ejs":"
<%= value %>
","list.ejs":"","listitem.ejs":"
  • <%= value %>
  • ","listitemlinked.ejs":"
  • <%= value %>\">
  • ","loader.ejs":"
    ","menu.ejs":"
    <%= value %>
    ","modal.ejs":"
    ","model.ejs":"","movable.ejs":"
    <%= value %>
    ","radiolist.ejs":"
    <%= label %>
    ","radiooption.ejs":"","searchfield.ejs":"
    <%= value %>
    ","select.ejs":"
    multiple<% } %>\"> multiple<% } %>><%= value %>
    ","slider.ejs":"","tabbarbuttongroup.ejs":"
    ","text.ejs":"
    <% if(label) { %>
    <%= label %>
    <% } %>
    <% if(icon) { %>
    fa-fw\"><% } %><%= value %>
    ","textarea.ejs":"
    <% if(label) { %><% } %>
    ","textfield.ejs":"
    <% if(label) { %><% } %>
    ","toast.ejs":"
    \"><%= text %>
    ","toggle.ejs":"
    ","toggleswitch.ejs":"
    \n
    <%= value %>
    \n\n <% if(label){%>\n
    <%= label %>
    \n <% }%>\n
    \n
    \n <% if(onLabel){%>\n
    <%= onLabel %>
    \n <% }%>\n\n <% if(onLabel){%>\n
    <%= offLabel %>
    \n <% }%>\n\n <% if(onLabel){%>\n
    \n <% }%>\n
    \n
    \n
    \n\n","toolbar.ejs":"
    <%= value %>
    ","view.ejs":"
    <%= value %>
    "}}; +// Copyright (c) 2014 M-Way Solutions GmbH +// http://github.com/mwaylabs/The-M-Project/blob/absinthe/MIT-LICENSE.txt + +//////////////////////////////////////////////////////////////// +// DO NOT EDIT THIS FILE - it is generated by grunt +//////////////////////////////////////////////////////////////// + +/* jshint -W109 */ +M.Templates = {"default":{"accordion.ejs":"
      <%= value %>
    ","accordionitem.ejs":"
      <%= value %>
    ","button.ejs":"
    <% if(icon) { %> \"> <% } %>
    ><%= value %>
    ","buttongroup.ejs":"
    ","checkboxlist.ejs":"
    <%= label %>
    ","checkboxoption.ejs":"","debug.ejs":"
    ","dialog.ejs":"
    ","image.ejs":"\" alt=\"<%= alt %>\"/>","label.ejs":"
    <%= value %>
    ","list.ejs":"
      ","listitem.ejs":"
    • <%= value %>
    • ","listitemlinked.ejs":"
    • <%= value %>\">
    • ","loader.ejs":"
      ","menu.ejs":"
      <%= value %>
      ","modal.ejs":"
      ","model.ejs":"
        <%= value %>
      ","movable.ejs":"
      <%= value %>
      ","radiolist.ejs":"
      <%= label %>
      ","radiooption.ejs":"","searchfield.ejs":"
      <%= value %>
      ","select.ejs":"
      multiple<% } %>\"> multiple<% } %>><%= value %>
      ","slider.ejs":"","tabbarbuttongroup.ejs":"
      ","text.ejs":"
      <% if(label) { %>
      <%= label %>
      <% } %> <% if(icon) { %>
      fa-fw\">
      <% } %>

      <%= value %>

      \r\n\r\n\r\n","textarea.ejs":"
      <% if(label) { %><% } %>
      ","textfield.ejs":"
      <% if(label) { %><% } %>
      ","toast.ejs":"
      \"><%= text %>
      ","toggle.ejs":"
      ","toggleswitch.ejs":"
      \n
      <%= value %>
      \n\n <% if(label){%>\n
      <%= label %>
      \n <% }%>\n
      \n
      \n <% if(onLabel){%>\n
      <%= onLabel %>
      \n <% }%>\n\n <% if(onLabel){%>\n
      <%= offLabel %>
      \n <% }%>\n\n <% if(onLabel){%>\n
      \n <% }%>\n
      \n
      \n
      \n\n","toolbar.ejs":"
      <%= value %>
      ","view.ejs":"
      <%= value %>
      "}}; /* jshint +W109 */ \ No newline at end of file diff --git a/src/templates/default/text.ejs b/src/templates/default/text.ejs index 4f6251c46..072812330 100644 --- a/src/templates/default/text.ejs +++ b/src/templates/default/text.ejs @@ -1 +1,3 @@ -
      <% if(label) { %>
      <%= label %>
      <% } %>
      <% if(icon) { %>
      <% } %><%= value %>
      \ No newline at end of file +
      <% if(label) { %>
      <%= label %>
      <% } %> <% if(icon) { %>
      <% } %>

      <%= value %>

      + + diff --git a/src/ui/layouts/tab-layout.js b/src/ui/layouts/tab-layout.js index 62b4caab7..d759ac3a9 100644 --- a/src/ui/layouts/tab-layout.js +++ b/src/ui/layouts/tab-layout.js @@ -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); @@ -126,7 +126,9 @@ M.TabLayout = M.Layout.extend({ that.switchToTab(options.index - 1); } } - }).create(); + }).create(that.scope, null, true); + + return content; }, //TODO diff --git a/src/ui/themevars.js b/src/ui/themevars.js index 2d559206d..8a1d75a13 100644 --- a/src/ui/themevars.js +++ b/src/ui/themevars.js @@ -1,169 +1,169 @@ -// Copyright (c) 2014 M-Way Solutions GmbH -// http://github.com/mwaylabs/The-M-Project/blob/absinthe/MIT-LICENSE.txt - -//////////////////////////////////////////////////////////////// -// DO NOT EDIT THIS FILE - it is generated by grunt -//////////////////////////////////////////////////////////////// - -M.ThemeVars = { - _vars: { - "default": { - "blue": "#1092d3", - "lightblue": "#58b3e0", - "darkblue": "#0e7cb4", - "purple": "#6c64ff", - "lightpurple": "#9893ff", - "darkpurple": "#5c55d9", - "green": "#2dcca2", - "lightgreen": "#6cdbbe", - "darkgreen": "#26ae8a", - "red": "#ed253d", - "lightred": "#f26778", - "darkred": "#ca1f34", - "orange": "#f45b42", - "lightorange": "#f78d7b", - "darkorange": "#d04d38", - "yellow": "#eab13a", - "lightyellow": "#f0c975", - "darkyellow": "#d99731", - "grey": "#c3c3c3", - "lightgrey": "#d5d5d5", - "darkgrey": "#a6a6a6", - "black": "#000000", - "white": "#FFFFFF", - "darkwhite": "#F2F2F2", - "debug-1": "#02ccb9", - "debug-2": "#00cc09", - "debug-3": "#cc3500", - "debug-4": "#cc008d", - "debug-5": "#9f00cc", - "debug-6": "#4f00cc", - "debug-7": "#003fcc", - "debug-8": "#0073cc", - "grid-columns": "12", - "grid-gutter-width": "30px", - "lightenPercentage": "15%", - "lightenPercentageLight": "5%", - "m-button-icon-only-width": "50px", - "m-button-border-width": "1px", - "m-button-border-color": "#1092d3", - "m-button-text-color": "#1092d3", - "m-button-border-radius": "4px", - "m-button-border-style": "solid", - "m-button-padding-bottom": "10px", - "m-button-padding-top": "10px", - "m-button-padding-left-right": "10px", - "m-button-padding": "10px 10px 10px 10px", - "m-button-primary-border-color": "#6c64ff", - "m-button-primary-text-color": "#6c64ff", - "m-button-primary-background-color": "#FFFFFF", - "m-button-success-border-color": "#2dcca2", - "m-button-success-text-color": "#2dcca2", - "m-button-success-background-color": "#FFFFFF", - "m-button-error-border-color": "#ed253d", - "m-button-error-text-color": "#ed253d", - "m-button-error-background-color": "#FFFFFF", - "m-button-warning-border-color": "#f45b42", - "m-button-warning-text-color": "#f45b42", - "m-button-warning-background-color": "#FFFFFF", - "m-button-info-border-color": "#eab13a", - "m-button-info-text-color": "#eab13a", - "m-button-info-background-color": "#FFFFFF", - "m-button-fuzzy-border-color": "#c3c3c3", - "m-button-fuzzy-text-color": "#c3c3c3", - "m-button-fuzzy-background-color": "#FFFFFF", - "strong": "bold", - "normal": "normal", - "weak": "lighter", - "form-border-width": "1px", - "form-border-color": "#1092d3", - "form-border-style": "solid", - "form-element-border": "1px solid #1092d3", - "textfield-icon-padding": "30px", - "textfield-icon-x-position": "4px", - "textfield-icon-y-position": "14px", - "textfield-icon-font-size": "2.2rem", - "textfield-padding": "6px", - "m-primary-color": "#1092d3", - "m-primary-text-color": "#000000", - "m-primary-border-color": "#58b3e0", - "m-primary-active-color": "#0e7cb4", - "m-primary-active-text-color": "#FFFFFF", - "tablayout-menu-height": "50px", - "tablayout-menu-button-padding": "13px 0 0 0", - "tablayout-menu-scroll-button-width": "200px", - "switch-header-content-padding": "4px 0 0 0", - "header-top": "4px", - "m-header-icon-only-font-size": "2.4rem", - "m-primary-font-family": "\"HelveticaNeue-Light\", \"Helvetica Neue Light\", \"Helvetica Neue\", Helvetica, Arial, \"Lucida Grande\", sans-serif", - "m-primary-font-weight": "300", - "m-primary-font-size": "1.6rem", - "m-primary-calc-font-size": "16px", - "m-primary-line-height": "2.2rem", - "m-primary-font-color": "#000000", - "m-primary-margin-top": "10px", - "m-primary-margin-bottom": "20px", - "modal-backdrop-background-color": "#000000", - "content-padding": "15px", - "m-primary-disabled-color": "#d5d5d5", - "m-primary-disabled-text-color": "#c3c3c3", - "selection-color": "#c3c3c3", - "selection-checked-color": "#1092d3", - "m-list-item-color": "#2dcca2", - "m-stencil-text-shadow": "rgba(255, 255, 255, 0.5) 0px 3px 3px", - "m-menu-view-width": "200px", - "m-menu-view-device-swipe-listener-width": "20px", - "m-menu-view-transition-width": "200px - 20px", - "m-menu-transition": "500ms" - }, - "android_dark": { - "m-primary-color": "#669900", - "m-primary-border-color": "#669900", - "m-primary-active-color": "#99CC00" - }, - "android_light": { - "m-primary-color": "#669900", - "m-primary-border-color": "#669900", - "m-primary-active-color": "#99CC00" - }, - "ios": { - "blue": "#59C8FA", - "lightblue": "#46b8da", - "darkblue": "#007AFF", - "green": "#4BD964", - "red": "#FF3B30", - "lightred": "#FF2D55", - "grey": "#8E8E93", - "m-primary-font-family": "-apple-system-font, \"HelveticaNeue-Light\", \"Helvetica Neue Light\", \"Helvetica Neue\", Helvetica, Arial, \"Lucida Grande\", sans-serif", - "lightenPercentage": "25%", - "textfield-icon-y-position": "13px", - "m-primary-active-color": "$lightgrey", - "m-primary-active-text-color": "#007AFF", - "tablayout-menu-height": "50px", - "tablayout-menu-scroll-button-width": "140px", - "selection-checked-color": "#59C8FA", - "m-button-padding-bottom": "10px", - "m-button-padding": "$m-button-padding-top $m-button-padding-left-right 10px $m-button-padding-left-right-top $m-button-padding-top $m-button-padding-left-right 10px $m-button-padding-left-right-left-right 10px $m-button-padding-top $m-button-padding-left-right 10px $m-button-padding-left-right-left-right" - } -}, - get: function (name, theme) { - var theme = theme || M.Environment.device.os; - - var result = this._vars[theme] ? this._vars[theme][name] : false; - if (!result && theme != M.ThemeVars.CONST.DEFAULT) { - result = this._vars[M.ThemeVars.CONST.DEFAULT][name]; - } - if (!result) { - console.log('Can not find varibale "' + name + '".'); - } - return result; - } -} - -M.ThemeVars.CONST = { - IOS: 'ios', - ANDROID_DARK: 'android_dark', - ANDROID_LIGHT: 'android_light', - ANDROID: 'android_dark', - DEFAULT: 'default' +// Copyright (c) 2014 M-Way Solutions GmbH +// http://github.com/mwaylabs/The-M-Project/blob/absinthe/MIT-LICENSE.txt + +//////////////////////////////////////////////////////////////// +// DO NOT EDIT THIS FILE - it is generated by grunt +//////////////////////////////////////////////////////////////// + +M.ThemeVars = { + _vars: { + "default": { + "blue": "#1092d3", + "lightblue": "#58b3e0", + "darkblue": "#0e7cb4", + "purple": "#6c64ff", + "lightpurple": "#9893ff", + "darkpurple": "#5c55d9", + "green": "#2dcca2", + "lightgreen": "#6cdbbe", + "darkgreen": "#26ae8a", + "red": "#ed253d", + "lightred": "#f26778", + "darkred": "#ca1f34", + "orange": "#f45b42", + "lightorange": "#f78d7b", + "darkorange": "#d04d38", + "yellow": "#eab13a", + "lightyellow": "#f0c975", + "darkyellow": "#d99731", + "grey": "#c3c3c3", + "lightgrey": "#d5d5d5", + "darkgrey": "#a6a6a6", + "black": "#000000", + "white": "#FFFFFF", + "darkwhite": "#F2F2F2", + "debug-1": "#02ccb9", + "debug-2": "#00cc09", + "debug-3": "#cc3500", + "debug-4": "#cc008d", + "debug-5": "#9f00cc", + "debug-6": "#4f00cc", + "debug-7": "#003fcc", + "debug-8": "#0073cc", + "grid-columns": "12", + "grid-gutter-width": "30px", + "lightenPercentage": "15%", + "lightenPercentageLight": "5%", + "m-button-icon-only-width": "50px", + "m-button-border-width": "1px", + "m-button-border-color": "#1092d3", + "m-button-text-color": "#1092d3", + "m-button-border-radius": "4px", + "m-button-border-style": "solid", + "m-button-padding-bottom": "10px", + "m-button-padding-top": "10px", + "m-button-padding-left-right": "10px", + "m-button-padding": "10px 10px 10px 10px", + "m-button-primary-border-color": "#6c64ff", + "m-button-primary-text-color": "#6c64ff", + "m-button-primary-background-color": "#FFFFFF", + "m-button-success-border-color": "#2dcca2", + "m-button-success-text-color": "#2dcca2", + "m-button-success-background-color": "#FFFFFF", + "m-button-error-border-color": "#ed253d", + "m-button-error-text-color": "#ed253d", + "m-button-error-background-color": "#FFFFFF", + "m-button-warning-border-color": "#f45b42", + "m-button-warning-text-color": "#f45b42", + "m-button-warning-background-color": "#FFFFFF", + "m-button-info-border-color": "#eab13a", + "m-button-info-text-color": "#eab13a", + "m-button-info-background-color": "#FFFFFF", + "m-button-fuzzy-border-color": "#c3c3c3", + "m-button-fuzzy-text-color": "#c3c3c3", + "m-button-fuzzy-background-color": "#FFFFFF", + "strong": "bold", + "normal": "normal", + "weak": "lighter", + "form-border-width": "1px", + "form-border-color": "#1092d3", + "form-border-style": "solid", + "form-element-border": "1px solid #1092d3", + "textfield-icon-padding": "30px", + "textfield-icon-x-position": "4px", + "textfield-icon-y-position": "14px", + "textfield-icon-font-size": "2.2rem", + "textfield-padding": "6px", + "m-primary-color": "#1092d3", + "m-primary-text-color": "#000000", + "m-primary-border-color": "#58b3e0", + "m-primary-active-color": "#0e7cb4", + "m-primary-active-text-color": "#FFFFFF", + "tablayout-menu-height": "50px", + "tablayout-menu-button-padding": "13px 0 0 0", + "tablayout-menu-scroll-button-width": "200px", + "switch-header-content-padding": "4px 0 0 0", + "header-top": "4px", + "m-header-icon-only-font-size": "2.4rem", + "m-primary-font-family": "\"HelveticaNeue-Light\", \"Helvetica Neue Light\", \"Helvetica Neue\", Helvetica, Arial, \"Lucida Grande\", sans-serif", + "m-primary-font-weight": "300", + "m-primary-font-size": "1.6rem", + "m-primary-calc-font-size": "16px", + "m-primary-line-height": "2.2rem", + "m-primary-font-color": "#000000", + "m-primary-margin-top": "10px", + "m-primary-margin-bottom": "20px", + "modal-backdrop-background-color": "#000000", + "content-padding": "15px", + "m-primary-disabled-color": "#d5d5d5", + "m-primary-disabled-text-color": "#c3c3c3", + "selection-color": "#c3c3c3", + "selection-checked-color": "#1092d3", + "m-list-item-color": "#2dcca2", + "m-stencil-text-shadow": "rgba(255, 255, 255, 0.5) 0px 3px 3px", + "m-menu-view-width": "200px", + "m-menu-view-device-swipe-listener-width": "20px", + "m-menu-view-transition-width": "200px - 20px", + "m-menu-transition": "500ms" + }, + "android_dark": { + "m-primary-color": "#669900", + "m-primary-border-color": "#669900", + "m-primary-active-color": "#99CC00" + }, + "android_light": { + "m-primary-color": "#669900", + "m-primary-border-color": "#669900", + "m-primary-active-color": "#99CC00" + }, + "ios": { + "blue": "#59C8FA", + "lightblue": "#46b8da", + "darkblue": "#007AFF", + "green": "#4BD964", + "red": "#FF3B30", + "lightred": "#FF2D55", + "grey": "#8E8E93", + "m-primary-font-family": "-apple-system-font, \"HelveticaNeue-Light\", \"Helvetica Neue Light\", \"Helvetica Neue\", Helvetica, Arial, \"Lucida Grande\", sans-serif", + "lightenPercentage": "25%", + "textfield-icon-y-position": "13px", + "m-primary-active-color": "$lightgrey", + "m-primary-active-text-color": "#007AFF", + "tablayout-menu-height": "50px", + "tablayout-menu-scroll-button-width": "140px", + "selection-checked-color": "#59C8FA", + "m-button-padding-bottom": "10px", + "m-button-padding": "$m-button-padding-top $m-button-padding-left-right 10px $m-button-padding-left-right-top $m-button-padding-top $m-button-padding-left-right 10px $m-button-padding-left-right-left-right 10px $m-button-padding-top $m-button-padding-left-right 10px $m-button-padding-left-right-left-right" + } +}, + get: function (name, theme) { + var theme = theme || M.Environment.device.os; + + var result = this._vars[theme] ? this._vars[theme][name] : false; + if (!result && theme != M.ThemeVars.CONST.DEFAULT) { + result = this._vars[M.ThemeVars.CONST.DEFAULT][name]; + } + if (!result) { + console.log('Can not find varibale "' + name + '".'); + } + return result; + } +} + +M.ThemeVars.CONST = { + IOS: 'ios', + ANDROID_DARK: 'android_dark', + ANDROID_LIGHT: 'android_light', + ANDROID: 'android_dark', + DEFAULT: 'default' } \ No newline at end of file diff --git a/test/ui/views/test.text.js b/test/ui/views/test.text.js index 08076a734..7a5c6986d 100644 --- a/test/ui/views/test.text.js +++ b/test/ui/views/test.text.js @@ -48,7 +48,7 @@ describe('M.TextView', function () { assert.isDefined(testView.value); - assert.equal(testView.$el.find('.input-icon-addon').text(), VALUETEXT); + assert.equal(testView.$el.find('.inner-text').text(), VALUETEXT); assert.isDefined(testView.label); assert.equal(testView.$el.find('.label').text(), LABELTEXT);