background preloader

Backbonenotes

Facebook Twitter

Our First Node.js App: Backbone on the Client and Server. Here at Airbnb, we’ve been looking curiously at Node.js for a long time now.

Our First Node.js App: Backbone on the Client and Server

We’ve used it for odds and ends, such as the build process for some of our libraries, but we hadn’t built anything production-scale. Until now. The Problem There’s a disconnect in the way we build rich web apps these days. In order to provide a snappy, fluid UI, more and more of the application logic is moving to the client. But all too often, it’s not so clean; application logic is somewhat arbitrarily split between client and server, or in some cases needs to be duplicated on both sides. If you’ve seen my tech talk or last blog post, then all this should sound familiar. Backbone.js - Backbone model persistence. Backbone.js - Using Bootstrap carousel with Backbone routes. How To Build a Custom Carousel with jQuery and Roundabout. Sliders and Carousels are one of the coolest ways to display information on websites.

How To Build a Custom Carousel with jQuery and Roundabout

They can contain tons of information in a smaller area, and the animation of automatic sliding and the large, beautiful images that are usually included draw the user's attention. Well, I'll show you how to set up an awesome carousel with jQuery and the Roundabout plugin. Terminology and Background Generally, the words "slider" and "carousel" refer to the same thing. To me, however, a carousel is actually a specific type of slider that shows the slides moving in what seems to be a 3D circle (like a real-life carousel). At my job, I've been working on a project where I designed what the Carousel would look like and all of the features it would need before I looked around to see if I could even find a plugin with all of these features. So what you'll be reading about is how I made that plugin do more than it said it could, so that I could have exactly what I wanted.

Demo | Download The Starting Markup. Edit fiddle. Create a simple carousel in Backbone.js. Let’s create a basic slider using the next technologies: Backbone to handle models and viewsUnderscore to handle the templates So first we would need to create a basic model for the slide with the id and headline atributes, and show, getEl and getControl methods.

Create a simple carousel in Backbone.js

We will also create a collection of this model named Slides. After we will create the main logic, the view, this will host the templates for the controllers and the displaying the slides. Finally we iniciate this model with a set of Slides And we add the html that will adopt all this logic. A simple carousel implemented with a single Backbone view. Rendering Nested Views Backbone.js - Code Hustler. Introduction I’d like to start this post with a disclaimer: this is my first Javascript development so hopefully I won’t say anything silly.

Rendering Nested Views Backbone.js - Code Hustler

If I do, I’d love to here about it in the comments! I’m currently developing a set of third party Javascript widgets and opted for Backbone.js as the main library supported by Lo-dash (rather than underscore.js). Shortly after beginning I started seeing the need for rendering nested views to maximise re-use and be as DRY as possible. Rendering Nested Views in Backbone.js. Rendering a Backbone View is simple.

Rendering Nested Views in Backbone.js

The view’s container element (affectionately known as its el) swaps out all of its html for new html, probably fetched from a template. This works great for any top-level view. Page Transitions in Backbone. Page Transitions in Backbone. While page transitions aren't typically something you think of in the context of the web, this changes the first time you work on a webapp where the goal is a native feel.

Page Transitions in Backbone

The precedent set by native apps on iOS and Android devices all but mandate a user experience that includes smooth transitions. With regard to animations and adding/removing elements from the DOM, Backbone gives almost zero opinions. The documentation refers only to using a view's render method to append content to the view itself, and makes no reference to the concept of a “global” application view. So, while it is opinionated and not without limitations, here is just one way of implementing page transitions in a Backbone application. The Code In implementing page transitions, we want to be able to navigate from one route to another and have the current view transition out while the next view transitions in. In our app we have a router and an “app” view which handles adding & removing all other views from the DOM.

Demo. 10. Template helpers in backbone js – Learning BackboneJs. This entry is part 10 of 14 in the series for A Complete Guide for Learning Backbone Js Templates make your code look more neat and clean and helps in lot of other ways.

10. Template helpers in backbone js – Learning BackboneJs

So far we are using embeeded templates in our html file ie <script id="personTemplate" type="text/template"><strong><%= name %></strong> (<%= age %>) - <%= occupation %></script> In our view we are calling this template like this: template: _.template( $('#personTemplate').html()), One good thing over here is we can define a template helpers in backbone js (as a global function) and optimise our code like this. var template = function(id){ return _.template( $('#' + id).html() );};

Cant apply CSS to Backbone View. VIISON - How to switch views using Backbone.js. Introduction When we started developing with Backbone.js, we had some trouble setting up a basic application that simply switches between views.

VIISON - How to switch views using Backbone.js

There are great tutorials explaining what a Router is used for and the documentation gives you a good place to start, but we didn’t find a tutorial that explained how to use this in real life applications. To make things worse, some of our jQuery events inside the views stopped working once a view was switched and some CSS styles did not apply as they were supposed to. Filter a Backbone Collection Using the Decorator Pattern. There are often times when I want to filter Backbone collections and prevent some of the collection items from being displayed in my view.

Filter a Backbone Collection Using the Decorator Pattern

For instance, say I’m looking at a page of houses for sale. When I set a limit on the maximum price of a house either by entering a number or adjusting some type of slider, all the expensive houses should disappear from the page. Implementing this can be tricky, and I’d like to show you an especially nice solution using the decorator pattern. What’s the Decorator Pattern, again? The decorator pattern offers a way to “decorate” individual objects with new behaviors. Let’s say your program needs to process orders for tacos, and let’s say customers can order beef or chicken tacos. Now, let’s say customers can also add sour cream, guacamole, or salsa to their tacos. Javascipt : building an image gallery with backbone. Rendering A Filtered Backbone.Collection - Tech.pro. Ben.Knows.Code(): Filtering in Backbone: Let the Model Do the Work. I had previously posted about different approaches to filtering Backbone collections.

Ben.Knows.Code(): Filtering in Backbone: Let the Model Do the Work

However, as I spent time trying to solve my problem I kept finding that the solutions did not offer the flexibility I needed. I liked the overall approach but felt that it might be better to decouple the collections of filters from the application of the filters. The solution I arrived at was to move the decision of whether a filter matched into the model. Image Gallery With Backbone - Paracode. Update: dive into some of the finer details regarding this post here: image gallery aftermath. Backbone.js. By now you have probably already heard about it, and you’re assuming it can solve all of your problems. Lets start by clearing up the dust. Javascipt : building an image gallery with backbone. Very simple, basic backbone.js example with comments - Demonstrates how to get a value from one porition of UI and update it in another portion of UI via the model. Backbone Stickit Slider Example.

Binding a jQuery UI Slider · Issue #104 · NYTimes/backbone.stickit. How to do backbone image slider.