├── .babelrc ├── .editorconfig ├── .eslintrc ├── .gitignore ├── .npmignore ├── .travis.yml ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md ├── bower.json ├── changelog.md ├── docs ├── backbone.radio.md ├── basics.md ├── classes.md ├── common.md ├── dom.api.md ├── dom.interactions.md ├── dom.prerendered.md ├── events.class.md ├── events.entity.md ├── events.md ├── features.md ├── installation.md ├── marionette.application.md ├── marionette.behavior.md ├── marionette.collectionview.md ├── marionette.mnobject.md ├── marionette.region.md ├── marionette.view.md ├── readme.md ├── routing.md ├── upgrade-v2-v3.md ├── upgrade-v3-v4.md ├── utils.md ├── view.lifecycle.md └── view.rendering.md ├── lib ├── backbone.marionette.esm.js ├── backbone.marionette.js ├── backbone.marionette.js.map ├── backbone.marionette.min.js └── backbone.marionette.min.js.map ├── license.txt ├── marionette-logo.png ├── package.json ├── readme.md ├── rollup.config.js ├── src ├── application.js ├── backbone.marionette.js ├── behavior.js ├── child-view-container.js ├── collection-view.js ├── common │ ├── bind-events.js │ ├── bind-requests.js │ ├── build-region.js │ ├── get-option.js │ ├── merge-options.js │ ├── monitor-view-events.js │ ├── normalize-methods.js │ ├── trigger-method.js │ └── view.js ├── config │ ├── dom.js │ ├── features.js │ └── renderer.js ├── mixins │ ├── behaviors.js │ ├── common.js │ ├── delegate-entity-events.js │ ├── destroy.js │ ├── events.js │ ├── radio.js │ ├── regions.js │ ├── template-render.js │ ├── triggers.js │ ├── ui.js │ └── view.js ├── object.js ├── region.js ├── utils │ ├── deprecate.js │ ├── error.js │ ├── extend.js │ ├── get-namespaced-event-name.js │ ├── invoke.js │ └── proxy.js └── view.js ├── test ├── .eslintrc ├── .globals.json ├── .mocharc.json ├── browsersync.html ├── rollup.config.js ├── runner.html ├── setup │ ├── browser.js │ ├── node.js │ └── setup.js └── unit │ ├── README.md │ ├── application.spec.js │ ├── backbone.marionette.spec.js │ ├── behavior.spec.js │ ├── child-view-container.spec.js │ ├── collection-view │ ├── collection-view-children.spec.js │ ├── collection-view-childviewcontainer.sepc.js │ ├── collection-view-data.spec.js │ ├── collection-view-empty.spec.js │ ├── collection-view-filtering.spec.js │ ├── collection-view-sorting.spec.js │ ├── collection-view-viewmixin.spec.js │ └── collection-view.spec.js │ ├── common │ ├── bind-events.spec.js │ ├── bind-request.spec.js │ ├── build-region.spec.js │ ├── get-option.spec.js │ ├── merge-options.spec.js │ ├── monitor-view-events.js │ ├── normalize-methods.spec.js │ ├── trigger-method.spec.js │ └── view.spec.js │ ├── config │ ├── dom.js │ ├── features.spec.js │ └── renderer.spec.js │ ├── destroying-views.spec.js │ ├── get-immediate-children.spec.js │ ├── mixins │ ├── behaviors.spec.js │ ├── common.spec.js │ ├── delegate-entity-events.spec.js │ ├── destroy.spec.js │ ├── radio.spec.js │ ├── template-render.spec.js │ ├── ui.spec.js │ └── view.spec.js │ ├── object.spec.js │ ├── on-attach.spec.js │ ├── on-dom-refresh.spec.js │ ├── on-dom-remove.spec.js │ ├── region.spec.js │ ├── utils │ ├── deprecate.spec.js │ ├── error.spec.js │ ├── get-namespaced-event-name.spec.js │ └── proxy.spec.js │ ├── view.child-views.spec.js │ ├── view.dynamic-regions.spec.js │ ├── view.renderer.js │ ├── view.spec.js │ ├── view.triggers.spec.js │ ├── view.ui-bindings.spec.js │ └── view.ui-event-and-triggers.spec.js ├── trigger-deploy-mn-com.js ├── upgradeGuide.md └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/env"], 3 | "env": { 4 | "test": { 5 | "plugins": ["istanbul"] 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | root = true; 4 | 5 | [*] 6 | # Ensure there's no lingering whitespace 7 | trim_trailing_whitespace = true 8 | # Ensure a newline at the end of each file 9 | insert_final_newline = true 10 | 11 | [*.js] 12 | charset = utf-8 13 | indent_style = space 14 | indent_size = 2 -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "eslint:recommended", 3 | "parserOptions": { 4 | "ecmaVersion": 6, 5 | "sourceType": "module" 6 | }, 7 | "env": { 8 | "browser": true, 9 | "node": true 10 | }, 11 | "rules": { 12 | "array-bracket-spacing": [ 2, "never" ], 13 | "block-scoped-var": 2, 14 | "brace-style": [ 2, "1tbs", { "allowSingleLine": true } ], 15 | "camelcase": [ 2, { "properties": "always" } ], 16 | "curly": [ 2, "all" ], 17 | "dot-notation": [ 2, { "allowKeywords": true } ], 18 | "eol-last": 2, 19 | "eqeqeq": [ 2, "allow-null" ], 20 | "guard-for-in": 2, 21 | "indent": [ 2, 2, { "SwitchCase": 1 } ], 22 | "key-spacing": [ 2, 23 | { 24 | "beforeColon": false, 25 | "afterColon": true 26 | } 27 | ], 28 | "keyword-spacing": [ 2 ], 29 | "new-cap": 2, 30 | "no-bitwise": 2, 31 | "no-caller": 2, 32 | "no-eval": 2, 33 | "no-extend-native": 2, 34 | "no-iterator": 2, 35 | "no-loop-func": 2, 36 | "no-multi-spaces": "error", 37 | "no-multi-str": 2, 38 | "no-multiple-empty-lines": 2, 39 | "no-new": 2, 40 | "no-proto": 2, 41 | "no-script-url": 2, 42 | "no-sequences": 2, 43 | "no-shadow": 2, 44 | "no-spaced-func": 2, 45 | "no-trailing-spaces": 2, 46 | "no-unused-vars": [ 1, { "args": "none" } ], 47 | "no-var": 2, 48 | "no-with": 2, 49 | "object-shorthand": [ 2, "methods" ], 50 | "operator-linebreak": [ 2, "after" ], 51 | "quotes": [ 2, "single" ], 52 | "semi": [ 0, "never" ], 53 | "space-before-blocks": [ 2, "always" ], 54 | "space-before-function-paren": [ 2, "never" ], 55 | "space-in-parens": [ 2, "never" ], 56 | "space-infix-ops": 2, 57 | "space-unary-ops": [ 2, 58 | { 59 | "nonwords": false, 60 | "overrides": {} 61 | } 62 | ], 63 | "strict": 0, 64 | "valid-jsdoc": 2, 65 | "wrap-iife": [ 2, "inside" ] 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.swp 3 | *.swo 4 | *.orig 5 | .idea 6 | ext/ 7 | 8 | # Logs 9 | logs 10 | *.log 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | 17 | # Dependency directory 18 | node_modules 19 | 20 | # Testing 21 | coverage 22 | test/tmp 23 | .nyc_output 24 | 25 | # Users Environment Variables 26 | .lock-wscript 27 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | bower_components 2 | coverage 3 | docs 4 | src 5 | test 6 | tmp 7 | .babelrc 8 | .editorconfig 9 | .eslintrc 10 | .gitignore 11 | .nyc_output 12 | .travis.yml 13 | bower.json 14 | CONTRIBUTING.md 15 | ISSUE_TEMPLATE.md 16 | marionette-logo.png 17 | PULL_REQUEST_TEMPLATE.md 18 | trigger-deploy-mn-com.js 19 | upgradeGuide.md 20 | yarn.lock 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "10" 4 | cache: yarn 5 | env: 6 | - TEST_SUITE=coverage 7 | - TEST_SUITE=browser 8 | - TEST_SUITE=lodash USE_LODASH=1 9 | after_install: 10 | - yarn install travis-ci 11 | script: 12 | - if [[ $TEST_SUITE = "coverage" ]]; then yarn run coveralls; fi 13 | - if [[ $TEST_SUITE = "browser" ]] && [[ $SAUCE_USERNAME ]]; then yarn run test-cross-browser; fi 14 | - if [[ $TEST_SUITE = "lodash" ]]; then yarn run test-lodash; fi 15 | after_success: 16 | - if [[ $TRAVIS_BRANCH = "master" ]] && [[ $TRAVIS_PULL_REQUEST = "false" ]]; then node trigger-deploy-mn-com.js; fi 17 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Marionette has a few guidelines to facilitate your contribution and streamline 2 | the process of getting changes merged in and released. 3 | 4 | 1. [Setting up Marionette locally](#setting-up-marionette-locally) 5 | 2. [Reporting a bug](#reporting-a-bug) 6 | 3. [Submitting patches and fixes](#submitting-patches-and-fixes) 7 | 4. [Running Tests](#running-tests) 8 | 9 | 10 | ## Setting up Marionette locally 11 | 12 | * Fork the Marionette repo. 13 | * `git clone` your fork onto your computer. 14 | * Run `yarn install` to make sure you have all Marionette dependencies locally. 15 | * Run `yarn build` to build source files. 16 | 17 | ## Reporting a bug 18 | 19 | In order to best help out with bugs, we need to know the following information 20 | in your bug submission: 21 | 22 | * Marionette version #. 23 | * Backbone version #. 24 | 25 | Including this information in a submission will help us test the problem and 26 | ensure that the bug is both reproduced and corrected on the platforms / 27 | versions that you are having issues with. 28 | 29 | **Provide A Meaningful Description** 30 | 31 | It is very important to provide a meaningful description with your bug reports 32 | and pull requests. A good format for these descriptions will include the 33 | following things: 34 | 35 | 1. The problem you are facing (in as much detail as is necessary to describe 36 | the problem to someone who doesn't know anything about the system you're 37 | building) 38 | 39 | 2. A summary of the proposed solution 40 | 41 | 3. A description of how this solution solves the problem, in more detail than 42 | item #2 43 | 44 | 4. Any additional discussion on possible problems this might introduce, 45 | questions that you have related to the changes, etc. 46 | 47 | For a PR, we need at least the first 2 items to understand why you are changing 48 | the code. If not, we will ask that you add the necessary information. 49 | 50 | Please refrain from giving code examples in altJS languages like CoffeeScript, 51 | etc. Marionette is written in plain-old JavaScript and is generally easier for all 52 | members in the community to read. 53 | 54 | ### When you don't have a bug fix 55 | 56 | If you are stuck in a scenario that fails in your app, but you don't know how to 57 | fix it, submit a failing spec to show the failing scenario. Follow the 58 | guidelines for a pull request submission, but don't worry about fixing the 59 | problem. A failing spec to show that a problem exists is a very very very 60 | helpful pull request for us. 61 | 62 | We'll even accept a failing test pasted into the ticket description instead of a 63 | PR. That would at least get us started on creating the failing test in the code. 64 | 65 | ## Submitting patches and fixes 66 | 67 | See [Github's documentation for pull 68 | requests](https://help.github.com/articles/using-pull-requests). 69 | 70 | Pull requests are by far the best way to contribute to Marionette. They are by 71 | far the easiest way to demonstrate issues and your proposed resolution. To 72 | really help us evaluate your pull request and bring it into Marionette, please 73 | provide as much information as possible and follow the guidelines below: 74 | 75 | 1. Determine the branch as your base: `next` or `master` 76 | 2. Provide a brief summary of what your pull request is doing 77 | 3. Reference any relevant Github issue numbers 78 | 4. Include any extra detail you feel will help provide context 79 | 80 | ### Determining your branch 81 | 82 | When submitting your pull request, you need to determine whether to base off 83 | `next` or `master`: 84 | 85 | * If you're submitting a bug fix, base off `next` 86 | * If you're submitting a new feature, base off `next` 87 | * If you're submitting documentation for a new feature, base off `next` 88 | * If you're submitting documentation for the current release, base off `master` 89 | 90 | ### Submitting a Great Patch 91 | 92 | We want Marionette to provide a great experience to developers and help you 93 | write great applications using it. To help us achieve this goal, please follow 94 | these guidelines when submitting your patches. 95 | 96 | #### Solving Issues 97 | 98 | When you're submitting a bug fix, include spec tests, where applicable, showing 99 | the issue and the resolution. We strive to maintain 100% code coverage in our 100 | testing. 101 | 102 | #### Coding Guidelines 103 | 104 | The Marionette coding conventions are provided in the ESLint configuration 105 | included in the repository. Most IDEs and text editors will provide, or allow 106 | for, a plugin for ESLint to read the `.eslintrc` file. 107 | For areas where the configuration provides no guidance, try to stick to the 108 | conventions in the file you're editing. 109 | 110 | #### How we Approve Pull Requests 111 | 112 | We utilise Github's review approach. When receiving your pull request, we will 113 | comment inline and provide guidance to help you get your pull request merged 114 | into Marionette. This is not a one-way process and we're more than happy to 115 | discuss the context of your decisions. 116 | 117 | Once two Marionette.js members approve the pull request, we will then merge it 118 | into the base branch. 119 | 120 | Please remember that Marionette is a community-maintained project and, as such, 121 | many of us are working on this in our spare time. If we haven't commented on 122 | your pull request, please be patient. We may be available on our Gitter channel 123 | to discuss further. 124 | 125 | ## Running Tests 126 | 127 | * via command-line by running `yarn test` 128 | * in the browser by running `yarn test-browser` 129 | 130 | To see the test matrix - run `yarn coverage` 131 | 132 | ## Writing Tests and Code Style 133 | 134 | [More information]('test/unit/README.md') 135 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Description 2 | 3 | 1. The problem you are facing (in as much detail as is necessary to describe the problem to someone who doesn't know anything about the system you're building) 4 | 2. A summary of the proposed solution 5 | 3. A description of how this solution solves the problem, in more detail than item #2 6 | 4. Any additional discussion on possible problems this might introduce, questions that you have related to the changes, etc. 7 | 8 | ### Expected behavior 9 | 10 | Tell us what you think should happen. 11 | 12 | ### Actual behavior 13 | 14 | If possible, please create a small demo that demonstrates the issue. 15 | You can fork https://jsfiddle.net/marionettejs/adhv48ky/ for quick demo setup. 16 | Please refrain from giving code examples in altJS languages like CoffeeScript, etc. Marionette is written in plain-old JavaScript and is generally easier for all members in the community to read. 17 | 18 | ### Environment 19 | 20 | 1. Marionette version: 21 | 2. Backbone version: 22 | 3. Additional build tools, etc: 23 | -------------------------------------------------------------------------------- /PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Proposed changes 2 | - 3 | - 4 | - 5 | 6 | Link to the issue: 7 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "backbone.marionette", 3 | "description": "The Backbone Framework", 4 | "homepage": "https://marionettejs.com/", 5 | "version": "4.1.3", 6 | "main": "./lib/backbone.marionette.js", 7 | "license": "MIT", 8 | "keywords": [ 9 | "backbone", 10 | "framework", 11 | "client", 12 | "browser", 13 | "composite" 14 | ], 15 | "author": { 16 | "name": "Derick Bailey", 17 | "email": "derickbailey@gmail.com" 18 | }, 19 | "ignore": [ 20 | "docs", 21 | "src", 22 | "test", 23 | ".babelrc", 24 | ".editorconfig", 25 | ".eslintrc", 26 | ".gitignore", 27 | ".jscsrc", 28 | ".npmignore", 29 | ".travis.yml", 30 | "CONTRIBUTING.md", 31 | "upgradeGuide.md" 32 | ], 33 | "dependencies": { 34 | "backbone.radio": "^2.0.0" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /docs/classes.md: -------------------------------------------------------------------------------- 1 | # Marionette Classes 2 | 3 | Marionette follows Backbone's [pseudo-class architecture](./basics.md#class-based-inheritance). 4 | This documentation is meant to provide a comprehensive listing of those classes so that 5 | the reader can have a high-level view and understand functional similarities between the classes. 6 | All of these classes share a [common set of functionality](./common.md). 7 | 8 | ### [Marionette.View](./marionette.view.md) 9 | 10 | A `View` is used for managing portions of the DOM via a single parent DOM element or `el`. 11 | It provides a consistent interface for managing the content of the `el` which is typically 12 | administered by serializing a `Backbone.Model` or `Backbone.Collection` and rendering 13 | a template with the serialized data into the `View`s `el`. 14 | 15 | The `View` provides event delegation for capturing and handling DOM interactions as well as 16 | the ability to separate concerns into smaller, managed child views. 17 | 18 | `View` includes: 19 | - [The DOM API](./dom.api.md) 20 | - [Class Events](./events.class.md#view-events) 21 | - [DOM Interactions](./dom.interactions.md) 22 | - [Child Event Bubbling](./events.md#event-bubbling) 23 | - [Entity Events](./events.entity.md) 24 | - [View Rendering](./view.rendering.md) 25 | - [Prerendered Content](./dom.prerendered.md) 26 | - [View Lifecycle](./view.lifecycle.md) 27 | 28 | A `View` can have [`Region`s](#marionetteregion) and [`Behavior`s](#marionettebehavior) 29 | 30 | ### [Marionette.CollectionView](./marionette.collectionview.md) 31 | 32 | A `CollectionView` like `View` manages a portion of the DOM via a single parent DOM element 33 | or `el`. This view manages an ordered set of child views that are shown within the view's `el`. 34 | These children are most often created to match the models of a `Backbone.Collection` though a 35 | `CollectionView` does not require a `collection` and can manage any set of views. 36 | 37 | `CollectionView` includes: 38 | - [The DOM API](./dom.api.md) 39 | - [Class Events](./events.class.md#collectionview-events) 40 | - [DOM Interactions](./dom.interactions.md) 41 | - [Child Event Bubbling](./events.md#event-bubbling) 42 | - [Entity Events](./events.entity.md) 43 | - [View Rendering](./view.rendering.md) 44 | - [Prerendered Content](./dom.prerendered.md) 45 | - [View Lifecycle](./view.lifecycle.md) 46 | 47 | A `CollectionView` can have [`Behavior`s](#marionettebehavior). 48 | 49 | ### [Marionette.Region](./marionette.region.md) 50 | 51 | Regions provide consistent methods to manage, show and destroy views in your 52 | applications and views. 53 | 54 | `Region` includes: 55 | - [Class Events](./events.class.md#region-events) 56 | - [The DOM API](./dom.api.md) 57 | 58 | ### [Marionette.Behavior](marionette.behavior.md) 59 | 60 | A `Behavior` provides a clean separation of concerns to your view logic, allowing you to 61 | share common user-facing operations between your views. 62 | 63 | `Behavior` includes: 64 | - [Class Events](./events.class.md#behavior-events) 65 | - [DOM Interactions](./dom.interactions.md) 66 | - [Entity Events](./events.entity.md) 67 | 68 | ### [Marionette.Application](marionette.application.md) 69 | 70 | An `Application` provides hooks for organizing and initiating other elements and a view tree. 71 | 72 | `Application` includes: 73 | - [Class Events](./events.class.md#application-events) 74 | - [Radio API](./backbone.radio.md#marionette-integration) 75 | - [MnObject's API](./marionette.mnobject.md) 76 | 77 | An `Application` can have a single [region](./marionette.application.md#application-region). 78 | 79 | ### [Marionette.MnObject](marionette.mnobject.md) 80 | 81 | `MnObject` incorporates backbone conventions `initialize`, `cid` and `extend`. 82 | 83 | `MnObject` includes: 84 | - [Class Events](./events.class.md#mnobject-events) 85 | - [Radio API](./backbone.radio.md#marionette-integration). 86 | 87 | ## Routing in Marionette 88 | 89 | Users of versions of Marionette prior to v4 will notice that a router is no longer bundled. 90 | The [Marionette.AppRouter](https://github.com/marionettejs/marionette.approuter) was extracted 91 | and the core library will no longer hold an opinion on routing. 92 | 93 | [Continue Reading](./routing.md) about routing in Marionette. 94 | -------------------------------------------------------------------------------- /docs/dom.api.md: -------------------------------------------------------------------------------- 1 | # The DOM API 2 | 3 | With the release of Marionette 3.2, developers can remove the dependency on 4 | jQuery and integrate with the DOM using a custom api. 5 | 6 | ## API Methods 7 | 8 | The DOM API manages the DOM on behalf of [each view class and `Region`](./classes.md). 9 | It defines the methods that actually attach and remove views and children. 10 | 11 | [The default API](#the-default-api) depends on Backbone's jQuery `$` object however it does not 12 | rely on jQuery-specific behavior. This should make it easier to develop your own 13 | API. You will, however, [need to also handle Backbone's jQuery integration](#backbone-jquery-integration). 14 | 15 | ### `createBuffer()` 16 | 17 | Returns a new HTML DOM node instance. The resulting node can be passed into the 18 | other DOM functions. 19 | 20 | ### `getDocumentEl(el)` 21 | 22 | Look up the top level element of `el`. Used by Marionette to determine attachment. 23 | 24 | ```javascript 25 | const elIsAttached = this.Dom.hasEl(this.Dom.getDocumentEl(this.el), this.el); 26 | ``` 27 | 28 | ### `getEl(selector)` 29 | 30 | Lookup the `selector` string withing the DOM. The `selector` may also be a DOM element. 31 | It should return an array-like object of the node. 32 | 33 | ### `findEl(el, selector)` 34 | 35 | Lookup the `selector` string within the DOM node `el`. It should return an array-like object of nodes. 36 | 37 | ### `hasEl(el, childEl)` 38 | 39 | Returns true if the el contains the node childEl 40 | 41 | ### `detachEl(el)` 42 | 43 | Detach `el` from the DOM without removing listeners. 44 | 45 | ### `replaceEl(newEl, oldEl)` 46 | 47 | Remove `oldEl` from the DOM and put `newEl` in its place. 48 | 49 | ### `swapEl(el1, el2)` 50 | 51 | Swaps the location of `el1` and `el2` in the DOM. 52 | Both els must have a parentNode to be able to swap. 53 | 54 | ### `setContents(el, html)` 55 | 56 | Replace the contents of `el` with the HTML string of `html`. Unlike other DOM 57 | functions, this only takes a literal string for its second argument. 58 | 59 | ### `appendContents(el, contents)` 60 | 61 | Takes the DOM node `el` and appends the DOM node `contents` to the end of the 62 | element's contents. 63 | 64 | ### `hasContents(el)` 65 | 66 | Returns a boolean indicating if the `el` has child nodes. 67 | 68 | ### `detachContents(el)` 69 | 70 | Remove the inner contents of `el` from the DOM while leaving `el` itself in the 71 | DOM. 72 | 73 | ## The default API 74 | 75 | The API used by Marionette by default is attached as `Marionette.DomApi`. 76 | This is useful if you [change the API](#providing-your-own-dom-api) globally, 77 | but want to reuse the default in certain cases. 78 | 79 | ```javascript 80 | import { setDomApi, DomApi } from 'backbone.marionette'; 81 | 82 | import MyDOMApi from './mydom'; 83 | 84 | setDomApi(MyDOMApi); 85 | 86 | // Use MyDOMApi everywhere but `Marionette.View` 87 | View.setDomApi(DomApi); 88 | ``` 89 | 90 | ## Providing Your Own DOM API 91 | 92 | To implement your own DOM API use `setDomApi`: 93 | 94 | ```javascript 95 | import { setDomApi } from 'backbone.marionette'; 96 | import MyDOMApi from './mydom'; 97 | 98 | setDomApi(MyDOMApi); 99 | ``` 100 | 101 | You can also implement a different DOM API for a particular class: 102 | 103 | ```javascript 104 | import { View } from 'backbone.marionette'; 105 | 106 | View.setDomApi(MyDOMApi); 107 | ``` 108 | 109 | `CollectionView`, `Region`, and `View` 110 | all have `setDomApi`. Each extended class may have their own DOM API. 111 | 112 | Additionally a DOM API can be partially set: 113 | 114 | ```javascript 115 | import { View } from 'backbone.marionette'; 116 | 117 | const MyView = View.extend(); 118 | 119 | MyView.setDomApi({ 120 | setContents(el, html) { 121 | el.innerHTML = html; 122 | } 123 | }); 124 | ``` 125 | 126 | ### Backbone jQuery Integration 127 | 128 | Backbone.js is tied to jQuery's API for managing DOM manipulation. If you want 129 | to completely remove jQuery from your Marionette app, you'll also have to 130 | provide your own versions of the following methods: 131 | 132 | * [`_setAttributes`](http://backbonejs.org/docs/backbone.html#section-170) 133 | * [`delegate`](http://backbonejs.org/docs/backbone.html#section-165) 134 | * [`undelegate`](http://backbonejs.org/docs/backbone.html#section-167) 135 | 136 | #### See Also 137 | 138 | The DOM API takes care of the other DOM manipulation methods for you. The 139 | [Backbone Wiki](https://github.com/jashkenas/backbone/wiki/using-backbone-without-jquery) 140 | has a good reference for removing jQuery from the app, including Browserify and 141 | Webpack configuration hooks. 142 | -------------------------------------------------------------------------------- /docs/dom.prerendered.md: -------------------------------------------------------------------------------- 1 | # Prerendered Content 2 | 3 | [View classes](./classes.md) can be initialized with pre-rendered DOM. 4 | 5 | This can be HTML that's currently in the DOM: 6 | 7 | ```javascript 8 | import { View } from 'backbone.marionette'; 9 | 10 | const myView = new View({ el: $('#foo-selector') }); 11 | 12 | myView.isRendered(); // true if '#foo-selector` exists and has content 13 | myView.isAttached(); // true if '#foo-selector` is in the DOM 14 | ``` 15 | 16 | Or it can be DOM created in memory: 17 | 18 | ```javascript 19 | import { View } from 'backbone.marionette'; 20 | 21 | const $inMemoryHtml = $('