Skip to content

Instantly share code, notes, and snippets.

@nem035
Last active November 5, 2016 02:54
Show Gist options
  • Select an option

  • Save nem035/d2ff4a2b862a6fbf4056 to your computer and use it in GitHub Desktop.

Select an option

Save nem035/d2ff4a2b862a6fbf4056 to your computer and use it in GitHub Desktop.

Revisions

  1. nem035 revised this gist Jul 13, 2016. No changes.
  2. nem035 created this gist Dec 30, 2015.
    14 changes: 14 additions & 0 deletions application.controller.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    import Ember from 'ember';

    export default Ember.Controller.extend({
    selectedMenuIndex: 0,
    menuItems: [
    { text: 'A' },
    { text: 'B' }
    ],
    actions: {
    selectMenuItem: function(itemIndex) {
    this.set('selectedMenuIndex', itemIndex);
    }
    }
    });
    3 changes: 3 additions & 0 deletions application.template.hbs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    {{#each menuItems as |item index|}}
    <li class="item {{active-class index selectedMenuIndex}}" {{action "selectMenuItem" index}}>{{item.text}}</li>
    {{/each}}
    10 changes: 10 additions & 0 deletions helpers.active-class.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    import Ember from 'ember';

    export function activeClass(params/*, hash*/) {
    const index = params[0];
    const active = params[1];

    return (index === active) ? 'active-class': '';
    }

    export default Ember.Helper.helper(activeClass);
    14 changes: 14 additions & 0 deletions styles.app.css
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    body {
    margin: 12px 16px;
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 12pt;
    }

    .active-class {
    color: blue;
    }

    .item {
    list-style: none;
    cursor: pointer
    }
    12 changes: 12 additions & 0 deletions twiddle.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    {
    "version": "0.4.17",
    "EmberENV": {
    "FEATURES": {}
    },
    "dependencies": {
    "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
    "ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember.debug.js",
    "ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js",
    "ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js"
    }
    }