Sha256: b32b9d2c9d4fca12389214701a443c2f84905cec0a2310fab24716a21ded2e50

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

class window.Cartilage.Application

  @Collections: {}
  @Models: {}
  @Routers: {}
  @Views: {}

  @sharedInstance: null
  @contentView: null

  @launch: ->
    @sharedInstance = new @
    @sharedInstance.initialize()
    @hijackLinks()

  @show: (view) ->
    @contentView = new Cartilage.Views.ContentView unless @contentView?
    @contentView.show(view)

  @hijackLinks: ->
    if Backbone.history and Backbone.history._hasPushState
      $(document).delegate "a", "click", (event) ->
        href = $(this).attr("href")
        protocol = this.protocol + "//"

        # Ignore anchors without hrefs.
        return unless href

        # Ensure that the link element does not define data-passthrough="true",
        # which denotes that the link should be passed through to the backend
        # application.
        return if $(this).attr("data-passthrough") is "true"

        # Ensure the protocol is not part of URL, meaning its relative.
        return if href.match(/\:\/\//)

        # Stop the event bubbling to ensure the link will not cause a page
        # refresh.
        event.preventDefault()

        # Note by using Backbone.history.navigate, router events will not be
        # triggered. If this is a problem, change this to navigate on your
        # router.
        Backbone.history.navigate(href, true)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cartilage-0.1.2 app/assets/javascripts/cartilage/application.js.coffee
cartilage-0.1.1 app/assets/javascripts/cartilage/application.js.coffee