This file contains 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
jQuery(function($) { | |
// create a layout class | |
var Layout = Backbone.Marionette.Layout.extend({ | |
template: _.template($('#modals-template').html()), | |
regions: { | |
modals: { | |
selector: '.modals-container', | |
regionClass: Backbone.Marionette.Modals | |
} | |
} |
This file contains 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
class Backbone.Marionette.Modals extends Backbone.Marionette.Region | |
modals: [] | |
zIndex: 0 | |
show: (modal, options = {}) -> | |
@ensureEl() | |
modal.render() | |
@$el.append modal.el | |
This file contains 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
jQuery(function($) { | |
// create a modal view class | |
var Modal = Backbone.Modal.extend({ | |
template: _.template($('#modal-template').html()), | |
viewContainer: '.modal-view', | |
views: { | |
'click #first': { | |
view: _.template($('#modal-view1-template').html()) |
This file contains 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
describe 'views:', -> | |
view = {} | |
beforeEach -> | |
view = new modal() | |
it 'should trigger the first view when rendered', -> | |
spyOn(view, 'triggerView') | |
view.render() |
This file contains 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
unless Backbone? | |
throw new Error("Backbone is not defined. Please include | |
the latest version from http://documentcloud.github.com/backbone/backbone.js") | |
class Backbone.Modal extends Backbone.View | |
constructor: -> | |
args = Array.prototype.slice.apply(arguments) | |
Backbone.View.prototype.constructor.apply(this, args) | |
render: -> |
This file contains 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
describe 'Backbone.Modal', -> | |
view = {} | |
modal = {} | |
beforeEach -> | |
class modal extends Backbone.Modal | |
viewContainer: '' | |
cancelEl: '' | |
submitEl: '' | |
template: -> '' |
This file contains 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
describe 'Backbone.Modal', -> | |
it "should have Backbone defined", -> | |
it 'should throw an exception if there is no template or views present', -> | |
it 'should throw an exception if a template and views are defined and | |
no viewContainer is present', -> | |
describe 'views:', -> | |
it 'binds the event to the selector to open a view', -> |
This file contains 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
findArticleBySlug: (slug) -> | |
@find (chapter) -> | |
_.any(chapter.get('articles').pluck('slug'), (item) -> item is slug) |
This file contains 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
Blog.App.vent.bind 'article', (slug) -> | |
chapter = chapters.findArticleBySlug(slug) | |
chapter = chapters.last() unless chapter | |
article = chapter.get('articles').getArticle(slug) | |
unless article | |
Blog.App.vent.trigger('404') | |
return |
This file contains 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
class Blog.Models.Chapter extends Backbone.RelationalModel | |
relations: [ | |
type: Backbone.HasMany | |
key: 'articles' | |
relatedModel: 'Blog.Models.Article' | |
collectionType: 'Blog.Collections.Articles' | |
] |