Created
March 27, 2013 14:31
-
-
Save mbritton/5254604 to your computer and use it in GitHub Desktop.
YUI Routing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <title>YUI App Framework Test Page</title> | |
| <meta name="description" content="" /> | |
| <meta name="author" content="Mike Britton" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no" /> | |
| <script src="http://yui.yahooapis.com/3.9.0/build/yui/yui-min.js"></script> | |
| <link rel="stylesheet" href="css/main.css" /> | |
| </head> | |
| <body class="yui3-skin-night"> | |
| <script src="js/models/personModel.js"></script> | |
| <script src="js/views/person.View.js"></script> | |
| <script> | |
| YUI().use('app', 'app-base', 'app-transitions', 'personModel', 'personView', function(Y) { | |
| var app = new Y.App({ | |
| views : { | |
| personView : { | |
| type : 'PersonView' | |
| } | |
| } | |
| }); | |
| app.route('/', function() { | |
| var person = new Y.Person(); | |
| this.showView('personView', { | |
| model : person | |
| }); | |
| }); | |
| app.route('/bar', function() { | |
| var person = new Y.Person(); | |
| this.showView('personView', { | |
| model : person | |
| }); | |
| }); | |
| console.dir(app); | |
| app.render().dispatch(); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div align=right> | |
| <img src="http://www.gamefromscratch.com/image.axd?picture=HTML-5-RPG_thumb_1.png" alt="GameFromScratch HTML5 RPG logo" /> | |
| </div> | |
| <p><hr /></p> | |
| <div> | |
| <h2>About {{name}}:</h2> | |
| <ul> | |
| <li>{{name}} is {{height}} feet tall and {{age}} years of age.</li> | |
| </ul> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| YUI.add('personView', function(Y) { | |
| Y.PersonView = Y.Base.create('personView', Y.View, [], { | |
| initializer : function() { | |
| var that = this, request = Y.io('js/views/templates/person.Template', { | |
| on : { | |
| complete : function(id, response) { | |
| var template = Y.Handlebars.compile(response.responseText); | |
| that.get('container').setHTML(template(that.get('model').getAttrs(['name', 'age', 'height']))); | |
| } | |
| } | |
| }); | |
| }, | |
| render : function() { | |
| return this; | |
| } | |
| }); | |
| }, '0.0.1', { | |
| requires : ['view', 'io-base', 'personModel', 'handlebars'] | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| YUI.add('personModel', function(Y) { | |
| Y.Person = Y.Base.create('person', Y.Model, [], { | |
| getName : function() { | |
| return this.get('name'); | |
| } | |
| }, { | |
| ATTRS : { | |
| name : { | |
| value : 'Mike' | |
| }, | |
| height : { | |
| value : 6 | |
| }, | |
| age : { | |
| value : 35 | |
| } | |
| } | |
| }); | |
| }, '0.0.1', { | |
| requires : ['model'] | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment