Archive for the ‘Backbone.js’ Tag

Developing E-Learning Web Applications in the Multi-Platform Digital Landscape

Foreword

My blog has been a bit neglected of late…. In the interest of turning this around I wanted to dust off an old entry that never saw the light of day. I wrote this piece in 2013 so things have definitely changed since then…. but a great deal of the content is relevant and useful, particularly to the e-learning scene. With this in mind, please read on 🙂

_______

Background

The Digital Landscape is ever-changing. Recently though, it has been changing faster than ever before. After a decade of Flash and desktop computers being the best tool and platform for delivering highly interactive e-learning content, we now live in a world where people are using tablets and phones more frequently than laptops or desktops. The once unstoppable, ever-present Flash player is in its sunset years having been mortally wounded by a certain blog article – http://www.apple.com/hotnews/thoughts-on-flash . Web-based Flash content won’t work on iPads, iPhones and other mobile devices and this is becoming a more frequent deal breaker.

Solutions

The question we are facing is, “How best do we continue to make exciting e-learning that can be reached by all of our users?” It’s a fascinating question and one that I have spent considerable time thinking about. The answer is that there are many ways to do this… but they all come with their own set of pros and cons. The challenges and problems are multi-tiered, interdependent, and the direction you take will relate strongly to your own needs, parameters and requirements:

  • Go Native – In some situations, building a native app is a great path, particularly in terms of performance and being able to use the devices’ built-in UI component libraries. But you’ll need to consider how to tackle deployment and security— do you have your own enterprise-level app store? Can you push your app to your users devices? How many platforms do you need to develop for?Can a cross-platform compiling solution like AIR(http://www.adobe.com/products/air.html) or Haxe(http://haxe.org/) meet your needs?How you will handle user-tracking when you are no longer in the domain of the LMS?And can your user base be covered with the platforms you are able to build the app for?
  • Use an RDT – Alternatively a Rapid Development Tool like Storyline (http://www.articulate.com/products/storyline-overview.php), Captivate (http://www.adobe.com/uk/products/captivate.html), Lectora (http://lectora.com) or Zebra Zapps (https://zebrazapps.com/) can be a good option, particularly for smaller projects on a lower budget. These products are able to quickly get a course up and running. But you want to be sure you are going to be able to leverage enough customizable power and excitement out of the end product and be able to actually achieve the interactive or visual complexities you desire. It may also be that the features you need are going to only exist in the Flash version of the RDT output or that the HTML5 output isn’t performant enough or only actually plays in a native app wrapper.
  • Flash – A Flash solution can still be a very effective option if you know your user base will be using desktops and not tablets, but this is a scenario that is happening less and less. In any case, you will get to use a powerful, stable platform perfect for generating highly-interactive web content.
  • HTML5 – For high-end, customizable, bespoke content that can work on anything running a modern browser (tablets and smartphones included), a straight HTML, CSS and Javascript solution is more and more frequently the strongest option.

Exploring the HTML Approach

For the remainder of this article I want to take a deeper look at the HTML approach. One of the benefits of this technology are that it can reach as many users and work on as many platforms as possible. It can also integrate into as many LMSs as possible, regardless of their TinCan API capabilities. The Javascript and HTML5 spheres of development have been on fire for many years now, with probably the biggest development community behind them, and so let’s take a look at the kind of elements you can integrate into your own e-learning framework by using these technologies. One of the common denominators of all modern devices and computers is the browser and with recent developments in HTML5, Javascript libraries and CSS3 you are able to deliver a cutting edge, high-performance product that works across many platforms.

HTML HTML HTML HTML HTML

Did you see how many times I wrote HTML just then? 5. HTML5. It’s big right now and it has been big for a while. It could be argued that there has been somewhat of a rose-tinted temporal distortion field around this word— but what does it actually mean? In essence, it’s a markup language designed to enable the presentation of multimedia content across the World Wide Web. It isn’t a final specification but currently a Candidate Recommendation of the W3C and its first public draft arrived in 2008. Some of the most exciting features include:

  • Video playback
  • The Canvas element
  • Drag’n’Drop
  • Offline web-apps
  • Web Storage

Say What?

A lot of confusion arises when people talk about HTML5 because quite often they are talking about other technologies like Javascript and CSS. HTML5 can do some new stuff and it’s exciting but actually most of the exciting stuff comes from Javascript libraries like jQuery and the new CSS3 bells and whistles—features like drop shadows, rounded corners and transitions. What’s more surprising, given the hype around HTML5, is that loads of really cool stuff can be done without it, instead just using HTML(4), Javascript and CSS. In fact, if you want to support IE7 and 8, these browsers don’t actually support HTML5 and so you must provide fallbacks or just omit functionality. I mention this because it’s critical to understand what is actually possible in different browsers when building interactive digital content.

The Technical Shopping List

Lets’ explore what’s possible within this approach. Here’s a list of desirable features to include in an HTML/Javascript e-learning framework:-

  • Multi-platform compatibility
  • LMS compatibility
  • High performance content
  • A seamless single-page application experience
  • On-demand loading
  • A structured, maintainable, modular codebase

The Nuts and Bolts

In order to achieve this I have brought together a number of technologies and libraries:

The technologies used in this e-learning framework - html5, css3 require.js, backbone.js, marionette.js, jQuery, Sass  and GSAP

The technologies used in this e-learning framework

  • HTML5 and CSS3 – See above
  • Require.js (http://requirejs.org) – This is a Javascript file and module loader. It’s helpful in two ways:-
    • Asynchronous Module Definition – Large web apps can contain thousands and thousands of lines of code. In our case these are predominantly Javascript files. It is common practice to list your needed js files in the header of the HTML page your site exists in. With larger sites, though, these lists of imported files can become very unwieldy, unmaintainable, and ultimately hard to debug. As projects grow it quickly becomes hard to tell what code you are missing, if you have the imports in the right order or where an error might be coming from. Require lets you define application level dependencies which can be accessed by any Require module. Require also lets you specifically list any dependencies that a particular module may need, a lot like importing classes in a Flash, Java, or Haxe class. In this way it becomes very, very easy to build discreet, modular, reusable and maintainable class files.
    • Web Modules – Large-scale web apps can be big and take a long time to download. Require lets you load Modules on-demand at runtime. This is key for large web-apps because it allows you to only load what you need when you need it. The user no longer has to sit and wait for everything to have finished loading, instead they can load the module they want to look at and access it as soon as possible.
  • Backbone.js (http://backbonejs.org) – Backbone is a Model View * framework for writing Javascript web applications. Backbone, as its name implies, is a bare-bones framework that provides the mechanisms for MV* OOP development without telling you how you should do it. There are now dozens and dozens of Javascript MVC frameworks out there―so many that it is impossible to keep up with them all. Backbone has been established for quite a while. It has one of the largest developer communities and one the biggest range of high profile use-cases. It may not be the most cutting edge or prescriptively powerful framework out there but it will be one of the most. Like many js frameworks, it is created alongside multiple js libraries. Backbone depends on jQuery and Underscore and ultimately it helps you create large-scale web applications in a modular, graceful way. It enables you to separate your visuals, data, and business logic into specific areas of code. For smaller sites it’s not necessarily worth using, but for anything sizeable with multiple developers working on the same codebase it can be a lifesaver. It will make your code cleaner, more reusable, more accessible for others to work on, and ultimately speed up the process of generating your application. Also, when it comes to re-using the same codebase across different platforms and devices, having your presentation layer separated out allows for much easier development because your data and logic don’t need to be changed. Ultimately it can be about budget and Backbone helps to keep the budget down.
  • Marionette.js (http://marionettejs.com/) – “Make your Backbone applications dance!” Marionette is a composite application library for Backbone.js. Essentially it is designed to add huge improvements to Backbone. Backbone is incredibly non-prescriptive. Marionette adds deliciously useful and valuable functionality to Backbone by extending the Backbone classes and adding a few of its own. It adds items such as:
    • A dedicated Application object
    • Module objects
    • A Controller class
    • Layout and Region objects
    • ItemViews and CompositeViews
    • The Vent object (which is a Global Event Aggregator)
    • Memory management and event killing

It also drastically helps reduce boilerplate code―this can save you a great deal of development time.

  • jQuery (http://jquery.com) – This is probably the most popular Javascript library in existence. It has revolutionized web development in the years it has been around by drastically reducing browser incompatibilities, making the DOM much easier to traverse and manipulate and generally simplifying the way people code websites. It provides decent event handling, has a solid Ajax API and allows you to control and bend the DOM to your will. I won’t say much more about it other than it’s amazing, and now, pretty much taken for granted.
  • GSAP (http://www.greensock.com/gsap-js) – The GreenSock Animation Platform is a truly wonderful animation library. It was arguably the best Flashtweening library out there(TweenMax/TweenLite) and it has been ported over to Javascript with much of its API intact.It provides many benefits:
    • It is fast― up to 20 times faster than jQuery’s animation library and even quicker than CSS3 animations and transitions.
    • Its browser compatibility is phenomenal. It will work well even with older browsers…even IE7.
    • Animate anything…scale, rotate, skew, 3D transform and move DOM elements, JQuery selectors, Canvas library objects or even individual CSS properties. You can even animate objects or arrays.
    • GSAP has it’s own Timeline engine which allows you to string together, append, merge or delay multiple animations into one Timeline object. This can then be paused, repeated, scrubbed or controlled in any way you like: very powerful indeed.
  • Sass (http://sass-lang.com) – This stands for Syntactically awesome stylesheets. Sass takes CSS and gives it a massive kick up the backside. CSS is great but CSS compiled with Sass is AWESOME!
    • Variables – Sass lets you use global variables in your CSS. No longer do you have to find and replace all instances of a color value. Instead, put it in a variable and if you need to change it, you only have to do it once.
    • Selector Inheritance – Want to apply specific styling rules to only the children of a parent class? No problem! Just inline those rules into your particular class and Sass will sort out the rest.
    • Mixins – Have a number of boilerplate style sections that you use everywhere? Set them up as a mixin and then just include your mixin wherever you want. Like the variable, this saves you a silly amount of time during the lifecycle of a project.
    • Operations – Sass allows you to put logic into your CSS and even concatenate data types to form selectors.
    • Compass – Sass can work hand–in-hand with the Compass framework to massively simplify your CSS3 style definitions. You no longer list out three or four separate lines of vendor-prefix CSS to achieve the same result cross-browser. Compass allows you to use single phrases for things like drop-shadows and rounded corners. It also lets you manipulate color values with ease by calling functions like darken or lighten and applying a percentage value.

And to sum up….

Ultimately the point of bringing about these technologies is to be able to generate exciting, powerful, dynamic and meaningful interactive experiences. The above approach tries to garner some of the best that is out there on the web and use it to generate products that work on as many platforms as possible. The high-end goal is to make interactive content as meaningful, valuable, far-reaching and memorable as possible. It’s also about doing so effectively and efficiently so that projects come in on budget and schedule.

Advertisements

Backbone.js – Nested Collections and Arrays

I have recently been wrestling with Backbone.js to get it to correctly parse nested collections. There are numerous ways you can do this including using the plugin Backbone Relational. However, if you just want to do it yourself without the plugin then this is the approach that I found worked for me….

I have a collection of models. Some of these models might contain a nested collection of the same models. In my JSON this is set up as an array. The issue I was getting was that it was remaining as an array and not getting parsed into the collection of models I wanted it to be. This was a problem because I was navigating through the data recursively and I wanted to be able to treat each model as a Backbone model and not just a plain old object.

My model class is called ShellMenuModel and my collection class is called ShellMenuCollection. The model attribute where the nested collection would live is called subMods. Here is the model code:-

Image

 

The key to solving this problem was using the initialize function to manually parse the collection. In this function we check to see if the subMods collection attribute exists, if it does exist then you instantiate a new collection and in the constructor pass in the subMods array. The collection then gets parsed into a collection and set up as the subMods attribute on the parent model.