Skip to content

Instantly share code, notes, and snippets.

View davidvanleeuwen's full-sized avatar
✌️
Sharing is caring

David van Leeuwen davidvanleeuwen

✌️
Sharing is caring
View GitHub Profile
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
}
}
class Backbone.Marionette.Modals extends Backbone.Marionette.Region
modals: []
zIndex: 0
show: (modal, options = {}) ->
@ensureEl()
modal.render()
@$el.append modal.el
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())
describe 'views:', ->
view = {}
beforeEach ->
view = new modal()
it 'should trigger the first view when rendered', ->
spyOn(view, 'triggerView')
view.render()
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: ->
describe 'Backbone.Modal', ->
view = {}
modal = {}
beforeEach ->
class modal extends Backbone.Modal
viewContainer: ''
cancelEl: ''
submitEl: ''
template: -> ''
@davidvanleeuwen
davidvanleeuwen / gist:5293941
Last active December 15, 2015 17:09
Describe all functionality
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', ->
@davidvanleeuwen
davidvanleeuwen / gist:5241925
Created March 25, 2013 23:40
find article by slug
findArticleBySlug: (slug) ->
@find (chapter) ->
_.any(chapter.get('articles').pluck('slug'), (item) -> item is slug)
@davidvanleeuwen
davidvanleeuwen / gist:5241905
Created March 25, 2013 23:37
Change events for articles to use chapters
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
@davidvanleeuwen
davidvanleeuwen / gist:5241820
Created March 25, 2013 23:24
Chapter model
class Blog.Models.Chapter extends Backbone.RelationalModel
relations: [
type: Backbone.HasMany
key: 'articles'
relatedModel: 'Blog.Models.Article'
collectionType: 'Blog.Collections.Articles'
]