Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <header class="global-header js-header">
	<nav class="main-nav">
		<a href="/" class="main-nav__link is-active js-nav-link">Popular</a>
		<a href="/watchlist" class="main-nav__link js-nav-link">Watchlist</a>
	</nav>
</header>

<div class="main-content js-app"></div>

<!-- Templates -->
<script type="text/template" class="tmpl-movies">
	<% _.each(movies, function(movie) { %>
		<a href="/movie/<%= movie.id %>" class="movie js-movie--show" data-id="<%= movie.id %>">
			<img src="<%= movie.backdrop_small %>" alt="" class="trans-img is-hidden js-trans-img">

			<span class="movie__info">
				<h2><%= movie.title %></h2>
			</span>
		</a>
	<% }); %>
</script>
			
<script type="text/template" class="tmpl-movie-detailed">
	<div class="poster-holder js-img-placeholder">
		<img src="<%= backdrop_large %>" alt="" class="movie-detailed__poster trans-img is-hidden js-trans-img">
	</div>		
	
	<div class="movie-details">
		<a href="/" class="action action--back js-action--back">
			<svg height="80px" width="80px" class="action__icon action__icon--back" viewBox="0 0 80 80"><rect height="38" width="5" x="19" y="20.547"/><polygon points="46.371,59 49.906,55.465 36.488,42.047 61,42.047 61,37.047 36.652,37.047 49.906,23.793 46.371,20.258 27,39.629"/></svg>
		</a>

		<h1 class="movie-details__title"><%= title %></h1>

		<div class="movie-details__content">
			<p><%= overview %></p>
		</div>

		<button class="action action-watchlist--added js-watchlist--add">
			<svg height="80px" width="80px" class="action__icon action__icon--add" viewBox="0 0 80 80"><polygon points="61,37 43,37 43,19 37,19 37,37 19,37 19,43 37,43 37,61 43,61 43,43 61,43 "/></svg>
			Add to watchlist
		</button>
	</div>
</script>
	
<script type="text/template" class="tmpl-watchlist">
	<% if(this.collection.length <= 0) { %>
		<div class="notification">
			<img src="http://cdn.meme.am/instances2/500x/3145144.jpg" alt="" class="sadface" />
		</div>
	<% } %>
</script>
	
<script type="text/template" class="tmpl-watchlist-movie">
	<a href="/movie/<%= id %>" class="js-movie--show" data-id="<%= id %>">
		<img src="<%= backdrop_small %>" alt="" class="trans-img is-hidden js-trans-img">

		<span class="movie__info">
			<h2><%= title %></h2>

			<button class="action action-watchlist--remove js-watchlist--remove">
				<svg height="80px" width="80px" class="action__icon action__icon--remove" viewBox="0 0 80 80"><polygon points="56.971,52.728 44.243,40 56.971,27.272 52.728,23.029 40,35.757 27.272,23.029 23.029,27.272 35.757,40 23.029,52.728 27.272,56.971 40,44.243 52.728,56.971"/></svg>
			</button>
		</span>
	</a>
</script>
	
<script type="text/template" class="tmpl-watchlist-movie-btn">
	 <% if(!watchlist) { %>
		<button class="action action-watchlist--added js-watchlist--add">
			<svg height="80px" width="80px" class="action__icon action__icon--add" viewBox="0 0 80 80"><polygon points="61,37 43,37 43,19 37,19 37,37 19,37 19,43 37,43 37,61 43,61 43,43 61,43 "/></svg>
			Add to watchlist
		</button>
	<% } else { %>
		<button class="action action-watchlist--removed js-watchlist--remove">
			<svg height="80px" width="80px" class="action__icon action__icon--remove" viewBox="0 0 80 80"><polygon points="56.971,52.728 44.243,40 56.971,27.272 52.728,23.029 40,35.757 27.272,23.029 23.029,27.272 35.757,40 23.029,52.728 27.272,56.971 40,44.243 52.728,56.971"/></svg>
			Remove from watchlist
		</button>
	<% } %>
</script>
		
<script type="text/template" class="tmpl-loader">
	<div class="loader">Loading...</div>
</script>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Raleway:400,700);

$bps: (
    mobileUp: 660px
);

@mixin bp($point) {
    @if $point == mob-up {
        @media (min-width: map-get($bps, mobileUp)) { @content; }
    }
}

$headerHeight: (
    small: 55px,
    medium: 70px
);

$keyline: (
    small: 0.8rem,
    medium: 1.6rem,
    large: 3.2rem
);

* {
    -webkit-font-smoothing: antialiased;
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

html {
    font-size: 62.5%;
}

body {
    font-family: Raleway, Arial;
    font-weight: 400;
    font-size: 1.6em;
    line-height: 1.4;
    color: black;
    letter-spacing: 0.02em;
	background: white;
    padding-top: map-get($headerHeight, small);

    @include bp(mob-up) {
        padding-top: map-get($headerHeight, medium);
    }
}

h1, h2, h3 {
    font-weight: 700;
    text-transform: uppercase;
    line-height: 1;
}

h2 {
    font-size: 2rem;

    @include bp(mob-up) {
        font-size: 2.4rem;
    }
}

a {
    text-decoration: none;
    color: black;
}

.global-header {
    background: black;
    color: white;
    height: map-get($headerHeight, small);
    width: 100%;

    display: flex;
    justify-content: center;
    align-items: center;

    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;

    @include bp(mob-up) {
        /* position: static; */
        height: map-get($headerHeight, medium);
    }
}

.main-nav {

    &__link {
        font-weight: 700;
        color: white;
        text-transform: uppercase;
        font-size: 2rem;
        margin: 0 1rem;

        &.is-active {
            border-bottom: 0.3rem solid white;
        }
    }
}

// Homepage

.movie-grid {
    @include bp(mob-up) {
        display: flex;
        flex-wrap: wrap;
        margin: auto;
    }
}

.movie {
    display: block;
    position: relative;
    color: black;
    background: black;
    overflow: hidden;

    @include bp(mob-up) {
        width: 50%;
        display: inline-block;
    }

    &__info {
        padding: map-get($keyline, medium);
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        background: linear-gradient(to bottom, rgba(0,0,0,0) 0%,rgba(0,0,0,1) 100%);
        color: white;
    }

    .action-watchlist--remove {
        position: absolute;
        top: 0;
        right: 0;
    }

    img {
        width: 100%;
        display: block;
        transform: scale(1);
        backface-visibility: hidden;
        opacity: 1;
        transition: transform 15s, opacity .5s .1s;

        &.is-hidden {
            opacity: 0;
        }
    }

	h2 {
        margin: 0;
    }

    &:hover {

        img {
            transform: scale(1.2);
        }
    }

    &.is-removed {
        height: 0;
        transition: height 0.15s ease-in;
    }
}

.main-content {
    height: 100%;
	margin: auto;

    @media (orientation: landscape) {
        height: auto;
    }
}


// Detailed Movie View
.movie-detailed {
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;

    &__poster {
        max-width: 100%;
        display: block;

        @media (orientation: landscape) {
            position: relative;
            height: 100%;
			width: 100%;
            max-width: none;
        }
    }

    @media (orientation: landscape) {
        height: calc(100vh - #{map-get($headerHeight, medium)});
        overflow: hidden;
        display: block;
    }
}

.movie-details {
    background: white;
    display: flex;
    flex-direction: column;
    flex: 1;

    @media (orientation: landscape) {
        position: absolute;
        top: 0;
        bottom: 0;
        width: 35%;
        max-width: 37rem;
        overflow: auto;
        padding: 0 map-get($keyline, medium) map-get($keyline, large);
    }

    &__title {
        margin-top: 0;
        margin-bottom: 0;
        padding: 0 map-get($keyline, medium);

        @media (orientation: landscape) {
            margin-top: 1rem;
            padding: 0;
        }
    }

    &__content {
        flex: 1;
        padding: 0 map-get($keyline, medium);

        @media (orientation: landscape) {
            padding: 0;
        }
    }

    p {
        &:last-of-type {
            margin-bottom: 2rem;
        }
    }
}

.trans-img {
    opacity: 1;
    transition: opacity .5s .05s;

    &.is-hidden {
        opacity: 0;
    }
}

svg {
    overflow: hidden;
    vertical-align: middle;
    position: relative;
    box-sizing: content-box;
    pointer-events: none;
}

.action {
    $dim: 45px;

    border: none;
    outline: none;
    background: none;
    position: relative;
    padding: 0;
    width: auto;
    height: auto;
    text-transform: uppercase;
    font-weight: 700;
    transition: all .3s;
    display: block;

    &__icon {
        fill: black;
        width: $dim;
        height: $dim;
    }

    &-watchlist--added,
    &-watchlist--removed {
        width: auto;
        height: auto;
        width: 100%;
        padding: 8px 0 5px;
        color: white;
        background: black;

        @media (orientation: landscape) {
            position: absolute;
            left: 0;
            bottom: 0;
        }

        svg {
            top: -3px;
            width: 35px;
            height: 35px;
            fill: white;
        }
    }

    &--back {
        position: relative;

        @media (orientation: landscape) {
            left: -1rem;
        }

        svg {
            fill: rgba(black, 0.35);
        }
    }

    &-watchlist--remove svg {
        fill: white;
    }
}

.poster-holder {
	position: relative;
	padding-bottom: 56.25%;
    height: 0;
	
	@media (orientation: landscape) {
		height: 100vh;
		padding-bottom: 0;
	}
}

.loading {
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	margin: 0;
	display: flex;
    align-items: center;
	
	.loader,
	.loader:before,
	.loader:after {
		background: black;
		animation: load1 1s infinite ease-in-out;
		width: 1em;
		height: 4em;
	}
	
	.loader:before,
	.loader:after {
		position: absolute;
		top: 0;
		content: '';
	}
	
	.loader:before {
		left: -1.5em;
		animation-delay: -0.32s;
	}
	
	.loader {
		text-indent: -9999em;
		margin: 88px auto;
		position: relative;
		font-size: 11px;
		transform: translateZ(0);
		animation-delay: -0.16s;

		@media (orientation:landscape) {
			left: 175px;
		}
	}

	.loader:after {
		left: 1.5em;
	}
	
	@keyframes load1 {
		0%,
		80%,
		100% {
			box-shadow: 0 0 black;
			height: 4em;
		}

		40% {
			box-shadow: 0 -2em black;
			height: 5em;
		}
	}
}

.notification {
    padding: 0 1.6rem;
	width: 100%;
}

.sadface {
	display: block;
	margin: 1.6rem auto;
	max-width: 100%;
}

.tt {
    opacity: 1;
    visibility: visible;
    transition: visibility 0s linear,
                opacity 500ms linear;

    &.is-hidden {
        opacity: 0;
        visibility: hidden;
        transition-delay: 500ms, 0ms;
    }
}
              
            
!

JS

              
                console.clear();

// Plain old javascript object
var App = {
	Models: {}, 
	Views: {}, 
	Collections: {}, 
	utils: {},
	
	currentView: null,

    _firstLoad: true,
	
	appEl: $('.js-app'),
	
	start: function() {
		_.extend(this, Backbone.Events);
				
		// Set up some listeners
		this.listenTo(Backbone.Events, 'show:movies', this.onShowMovies);
        this.listenTo(Backbone.Events, 'show:movie', this.onShowMovie, this);
        this.listenTo(Backbone.Events, 'show:watchlist', this.onShowWatchlist);

        this.listenTo(Backbone.Events, 'add:watchlist', this.onWatchlistAdd, this);
        this.listenTo(Backbone.Events, 'remove:watchlist', this.onWatchlistRemove, this);
		
		// Start History API.
		Backbone.history.start();
	},
	
	onShowMovies: function() {
		
        var movieCollectionView = new App.Views.MovieCollectionView({
            collection: dataStore.movies
        });

        this._changeView(movieCollectionView);

        if(dataStore.movies.length <= 0) {
            dataStore.movies.fetch();
        }
    },

    onShowMovie: function(id) {
		
        var deferred = $.Deferred(),
            self = this;

        if(dataStore.movies.length > 0) {
            deferred.resolve();
        } else {
            dataStore.movies.fetch().done(function() {
                deferred.resolve();
            });
        }

        deferred.done(function() {

            var movieModel = dataStore.movies.get(id);

            var detailedMovieView = new App.Views.DetailedMovieView({
                model: movieModel
            });

            this._changeView(detailedMovieView);
        }.bind(this));
    },

    onShowWatchlist: function() {

        if(this._firstLoad && dataStore.watchlist.length <= 0) {
            dataStore.watchlist.fetch().done(function(response) {
                console.log(response);

                var watchlistCollectionView = new App.Views.WatchlistCollectionView({
                    collection: dataStore.watchlist
                });

                this._changeView(watchlistCollectionView);
                this._firstLoad = false;
            }.bind(this));
        } else {
            var watchlistCollectionView = new App.Views.WatchlistCollectionView({
                collection: dataStore.watchlist
            });

            this._changeView(watchlistCollectionView);
        }
    },

    _changeView: function(view) {

        if (this.currentView) {
            this.currentView.dispose();
            this.currentView = null;
        }

        this.currentView = view;
        this.appEl.html(this.currentView.render().el);
    },

    onWatchlistAdd: function(model) {
		
        model.set('watchlist', true);

        var clonedFilm = model.clone();

        dataStore.watchlist.add(clonedFilm);

        clonedFilm.save(null, {
            success: function(model, response, options) {
                console.log('Success::', model, response, options);
            },
            error: function(model, response, options) {
                console.log('Error::', model, response, options);
            }
        });
    },

    onWatchlistRemove: function(model) {
		
        model.set('watchlist', false);

        //@todo need to add a url to model
        var clonedFilm = model.clone();

        dataStore.watchlist.remove(model);

        clonedFilm.destroy(null, {
            success: function(model, response, options) {
                console.log('Success::', model, response, options);
            },
            error: function(model, response, options) {
                console.log('Error::', model, response, options);
            }
        });
    }
};

// Model Classes
App.Models.MovieModel = Backbone.Model.extend({
	
	localStorage: new Store('watchlist'),

    defaults: {
        watchlist: false
    },
	
	toggleWatchlist: function() {
        this.set( 'watchlist', !this.get('watchlist') );
    },

    parse: function(response) {
        if(response.backdrop_path) {
            response.backdrop_small = 'http://image.tmdb.org/t/p/w500/'+response.backdrop_path;
            response.backdrop_large = 'http://image.tmdb.org/t/p/w1280/'+response.backdrop_path;
        } else {
            response.backdrop_small = 'https://placeimg.com/500/281/any/grayscale/1';
            response.backdrop_large = 'https://placeimg.com/1280/720/grayscale/1';
        }
		
		//delete response.backdrop_path;

        return response;
    }
});

// Collection Classes
App.Collections.MovieCollection = Backbone.Collection.extend({
	
	model: App.Models.MovieModel,
	
	url: 'https://codepen.io/styler/pen/yYmWWY.js',
	// Original https://codepen.io/styler/pen/yYmWWY.js
	// IMDB Swap out https://codepen.io/styler/pen/yeNLZy.js
		// >>> Changed overview -> Plot, title -> Title, id -> imdbID
	// Missing attributes https://codepen.io/styler/pen/PZYjOr.js
	// Updated attribute names https://codepen.io/styler/pen/Rrbgxv.js
			
	parse: function(response) {
        return response[0].results;
    }

});

App.Collections.WatchlistCollection = Backbone.Collection.extend({
	
	model: App.Models.MovieModel,
	
	localStorage: new Store('watchlist'),
	
	initialize: function() {
		this.listenTo(this, 'remove', this.hideModel);
	},
	
	hideModel: function(model) {
		model.trigger('hide:model');
	}
});

// View Classes
App.Views.MainHeaderView = Backbone.View.extend({
	
	events: {
        'click .js-nav-link': 'onNavItemClicked'
    },

    initialize: function() {
        console.log('MainHeaderView::initialize', this.$el);

        Backbone.Events.on('route:change', this.onDeeplink, this);
    },

    onNavItemClicked: function(event) {
        event.preventDefault();

        var $clickedEl = $(event.currentTarget),
            clickedHref = $clickedEl.attr('href');

        this.toggleActiveNavClass($clickedEl);

        App.utils.router.navigate(clickedHref, {
            trigger: true
        });
    },

    onDeeplink: function(route) {
        console.log('onDeeplink', route);

        var $element = $('.js-nav-link[href="/'+route+'"]');

        this.toggleActiveNavClass($element);
    },

    toggleActiveNavClass: function(element) {

        $('.js-nav-link').removeClass('is-active');

        element.addClass('is-active');
    }
});

App.Views.MovieCollectionView = Backbone.View.extend({
	className: 'movie-grid',

    events: {
        'click .js-movie--show': 'onMovieClick'
    },

	template: _.template( $('.tmpl-movies').html() ),

    initialize: function() {
        console.log('MovieCollectionView::initialize');

        this.collection.on('sync', this.render, this);
    },

    render: function() {
        console.log('MovieCollectionView::render');

        this.$el.html(this.template({
            movies: this.collection.toJSON()
        }));

        setTimeout(function() {
            this.afterRender();
        }.bind(this), 0);

        return this;
    },

    afterRender: function() {
        console.log('MovieCollectionView::afterRender');

        var $images = imagesLoaded( this.$el.find('.js-trans-img') );

        $images.on('progress', function(instance, image) {
            $(image.img).removeClass('is-hidden');
        });
    },

    onMovieClick: function(event) {
        event.preventDefault();

        var $clickedEl = $(event.currentTarget),
            clickedHref = $clickedEl.attr('href'),
            movieId = $clickedEl.data('id');

        Backbone.Events.trigger('show:movie', movieId);

        App.utils.router.navigate(clickedHref, {trigger: false});
    },

    dispose: function() {
        this.remove();

        console.info('MovieCollectionView::dispose', this);
    }
});

App.Views.DetailedMovieView = Backbone.View.extend({
	
	className: 'movie-detailed',

    events: {
        'click .js-action--back': 'onBackBtnClick',
        'click .js-watchlist--add': 'onAddClick',
        'click .js-watchlist--remove': 'onRemoveClick'
    },

    template: _.template( $('.tmpl-movie-detailed').html() ),

    initialize: function() {
        console.log('DetailedMovieView::initialize');
    },

    render: function() {
        
        this.$el.html( this.template( this.model.toJSON() ) );

        setTimeout(function() {
            this.afterRender();
        }.bind(this), 0);

        return this;
    },

    afterRender: function() {
		
		var loader = new App.Views.LoaderView();
		
		this.$('.js-img-placeholder').append(loader.render().el);
		
		loader.show();

        imagesLoaded(this.$('.js-trans-img'), function() {
            this.images.forEach(function(i) {
                var $image = $(i.img);
                $image.removeClass('is-hidden');
				
				loader.hide();
            });
        });

        this.createWatchlistBtn();
    },

    createWatchlistBtn: function() {

        var watchlistBtn = new App.Views.WatchlistBtnSubview({
            model: this.model
        });

        this.$('.js-watchlist--add').replaceWith( watchlistBtn.render().el );
    },

    onBackBtnClick: function(event) {
        event.preventDefault();

        window.history.back();
    },

    onAddClick: function(event) {
        event.preventDefault();

        Backbone.Events.trigger('add:watchlist', this.model);
    },

    onRemoveClick: function(event) {
        event.preventDefault();

        Backbone.Events.trigger('remove:watchlist', this.model);
    },

    dispose: function() {
        this.remove();

        console.info('DetailedMovieView::dispose', this);
    }
});

App.Views.WatchlistCollectionView = Backbone.View.extend({
	
	className: 'movie-grid',

    events: {
        'click .js-movie--show': 'onMovieClick'
    },

	template: _.template( $('.tmpl-watchlist').html() ),

    initialize: function() {
        console.log('MovieListItemView::initialize', this.collection.toJSON());

        this.listenTo(this.collection, 'add', this.onAddMovie, this);
        this.listenTo(this.collection, 'remove', this.onMovieRemoved, this);
    },

    render: function() {
        console.log('MovieListItemView::render', this.collection.toJSON());

        this.$el.html(this.template());

        if(this.collection.length > 0) {
            this.collection.forEach(this.onAddMovie, this);
        }

        setTimeout(function() {
            this.afterRender();
        }.bind(this), 0);

        return this;
    },

    afterRender: function() {
        console.log('WatchlistCollectionView::afterRender');

        var $images = imagesLoaded( this.$el.find('.js-trans-img') );

        $images.on('progress', function(instance, image) {
            $(image.img).removeClass('is-hidden');
        });
    },

    onAddMovie: function(movie) {
        console.log('ADD MOVIE');

        var watchlistMovie = new App.Views.WatchlistItemView({
            model: movie
        });

        this.$el.prepend(watchlistMovie.render().el);
    },

    onMovieClick: function(event) {
        event.preventDefault();

        var $clickedEl = $(event.currentTarget),
            clickedHref = $clickedEl.attr('href'),
            movieId = $clickedEl.data('id');

        Backbone.Events.trigger('show:movie', movieId);

        App.utils.router.navigate(clickedHref, {trigger: false});
    },

    onMovieRemoved: function(model) {
        console.log('REMOVE MOVIE', model.toJSON());

        // this.collection.remove(model);
        console.log(this.collection.toJSON());

        if(this.collection.length === 0) {
            this.$el.html(this.template());
        }
    },

    dispose: function() {
        this.remove();

        console.info('WatchlistCollectionView::dispose', this);
    }
});

App.Views.WatchlistItemView = Backbone.View.extend({
	className: 'movie',

	template: _.template( $('.tmpl-watchlist-movie').html() ),

    events: {
        'click .js-watchlist--remove': 'onWatchlistRemove'
    },
	
	initialize: function() {
		
		this.listenTo(this.model, 'hide:model', this.dispose, this);
	},

    render: function() {
        this.$el.html( this.template( this.model.toJSON() ) );

        return this;
    },

    onWatchlistRemove: function(event) {
        event.preventDefault();
        event.stopPropagation();

        var model = dataStore.movies.get(this.model.get('id'));

        Backbone.Events.trigger('remove:watchlist', model);
    },

    dispose: function() {
        this.remove();
    }
});

App.Views.WatchlistBtnSubview = Backbone.View.extend({
	
	template: _.template( $('.tmpl-watchlist-movie-btn').html() ),

    initialize: function() {
        console.log('WatchlistBtnSubview::initialize', this.model.toJSON());

        this.listenTo(this.model, 'change:watchlist', this.render, this);
    },

    render: function() {
        console.log('WatchlistBtnSubview::render', this.model.toJSON());

        this.$el.html( this.template( this.model.toJSON() ) );

        return this;
    }
});

App.Views.LoaderView = Backbone.View.extend({
	
	className: 'loading tt is-hidden',
	
	stateClass: 'is-hidden',
	
	template: _.template( $('.tmpl-loader').html() ),
	
	initialize: function() {
		
		this.listenTo(Backbone.Events, 'loader:show', this.show, this);
		this.listenTo(Backbone.Events, 'loader:hide', this.hide, this);
	},
	
	render: function() {
		
		this.$el.html( this.template() );
		
		return this;
	},
	
	show: function() {
		this.$el.removeClass(this.stateClass);
	},
	
	hide: function() {
			
		this.$el.addClass(this.stateClass);
		
		this.$el.one('transitionend', function() {
			this.dispose();
		}.bind(this));
	},
	
	dispose: function() {
		this.remove();
	}
});

// Utilities
App.utils.router = new (Backbone.Router.extend({
	routes: {
        '': 'onShowMovies',
        'movie/:id': 'onShowMovie',
        'watchlist': 'onShowWatchlist'
    },

    initialize: function() {
        console.log('Router Started');

        this.on('all', this._signalRouteChange);
    },

    onShowMovies: function() {
        console.log('router::onShowMovies', this);

        Backbone.Events.trigger('show:movies');
    },

    /**
     * [onShowMovie description]
     * @param {[number]} id movie id
     */
    onShowMovie: function(id) {
        console.log('router::onShowMovie', this);

        Backbone.Events.trigger('show:movie', id);
    },

    onShowWatchlist: function() {
        console.log('router::onShowWatchlist');

        Backbone.Events.trigger('show:watchlist');
    },

    _signalRouteChange: function(route) {
        if(route === 'route') return;

        var fragment = Backbone.history.getFragment();

        if(fragment.split('/')[0] === 'movie') {
            fragment = '';
        }

        Backbone.Events.trigger('route:change', fragment);
    }
}));
						
// Create a data store
var dataStore = {};
dataStore.movies = new App.Collections.MovieCollection();
dataStore.watchlist = new App.Collections.WatchlistCollection();

(function() {
	new App.Views.MainHeaderView({
        el: '.js-header'
    });
	
	App.start();
})();
              
            
!
999px

Console