marionette.modal 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +36 -0
- data/Gemfile +4 -0
- data/Gruntfile.coffee +109 -0
- data/LICENSE +22 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/backbone.marionette.modals-min.js +1 -0
- data/backbone.marionette.modals.js +104 -0
- data/backbone.modal-min.js +1 -0
- data/backbone.modal.js +382 -0
- data/examples/1_single_view.html +71 -0
- data/examples/2_tab_based.html +104 -0
- data/examples/3_stacked_modal_with_marionette.html +105 -0
- data/examples/4_wizard.html +132 -0
- data/examples/css/style.css +45 -0
- data/examples/img/tab-icons.png +0 -0
- data/examples/style.css +35 -0
- data/examples/vendor/backbone.js +1571 -0
- data/examples/vendor/backbone.marionette.modals.js +104 -0
- data/examples/vendor/backbone.modal.css +24 -0
- data/examples/vendor/backbone.modal.js +382 -0
- data/examples/vendor/backbone.modal.theme.css +324 -0
- data/examples/vendor/jquery-1.9.1.js +9597 -0
- data/examples/vendor/marionette.js +2340 -0
- data/examples/vendor/marionette.modal.css +24 -0
- data/examples/vendor/marionette.modal.js +370 -0
- data/examples/vendor/marionette.modal.theme.css +324 -0
- data/examples/vendor/underscore.js +1227 -0
- data/lib/marionette.modal/version.rb +3 -0
- data/lib/marionette.modal.rb +5 -0
- data/marionette.modal-bundled-min.js +1 -0
- data/marionette.modal-bundled.js +858 -0
- data/marionette.modal-min.js +1 -0
- data/marionette.modal.css +24 -0
- data/marionette.modal.gemspec +23 -0
- data/marionette.modal.js +370 -0
- data/marionette.modal.theme.css +324 -0
- data/package.json +18 -0
- data/src/backbone.marionette.modals.coffee +67 -0
- data/src/backbone.modal.coffee +253 -0
- data/src/marionette.modal.coffee +248 -0
- data/src/marionette.modal.sass +26 -0
- data/src/marionette.modal.theme.sass +486 -0
- data/src/style.sass +48 -0
- data/test/spec/backbone.marionette.modals.spec.js +87 -0
- data/test/spec/backbone.modal.spec.js +224 -0
- data/test/spec.html +41 -0
- data/test/src/backbone.marionette.modals.spec.coffee +47 -0
- data/test/src/backbone.modal.spec.coffee +139 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1567a22c11b9eb98b99e4cde8143f84e3a0094bb
|
4
|
+
data.tar.gz: 862358399eb5179fd4a9c1c10cdbafc3c8bd45dc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0464a85f2f28097923ae8c0e180264a14bfdbf807c34a664dc5234eddf1699a328a90f31274d0c8cea25a8578df28b63800e74ea20f7c7296e5f0d2e7670e6a8
|
7
|
+
data.tar.gz: 500ad5a1333c5eca8c49abc6ad1e3467713252dfb3af53c83ba881aa6aac6cddded523b56232660a6fe40bc372d7f821f5134d49d350841f10bd9d4ff1b0993c
|
data/.gitignore
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Ruby Gem
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
.bundle
|
5
|
+
.config
|
6
|
+
.yardoc
|
7
|
+
Gemfile.lock
|
8
|
+
InstalledFiles
|
9
|
+
_yardoc
|
10
|
+
coverage
|
11
|
+
doc/
|
12
|
+
lib/bundler/man
|
13
|
+
pkg
|
14
|
+
rdoc
|
15
|
+
spec/reports
|
16
|
+
test/tmp
|
17
|
+
test/version_tmp
|
18
|
+
tmp
|
19
|
+
|
20
|
+
# NPM
|
21
|
+
node_modules
|
22
|
+
|
23
|
+
# Grunt
|
24
|
+
.grunt
|
25
|
+
|
26
|
+
# SASS/SCSS cache files
|
27
|
+
*.scssc
|
28
|
+
*.sassc
|
29
|
+
.sass-cache
|
30
|
+
|
31
|
+
# Mac finder artifacts
|
32
|
+
.DS_Store
|
33
|
+
|
34
|
+
# Sublime Text project files
|
35
|
+
*.sublime-project
|
36
|
+
*.sublime-workspace
|
data/Gemfile
ADDED
data/Gruntfile.coffee
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
module.exports = (grunt) ->
|
2
|
+
module.exports = (grunt) ->
|
3
|
+
fs = require('fs')
|
4
|
+
|
5
|
+
grunt.initConfig
|
6
|
+
open:
|
7
|
+
default:
|
8
|
+
url: 'http://localhost:8000'
|
9
|
+
|
10
|
+
connect:
|
11
|
+
default:
|
12
|
+
options:
|
13
|
+
base: './'
|
14
|
+
middleware: (connect, options) ->
|
15
|
+
[connect.static(options.base), (req, res, next) ->
|
16
|
+
fs.readFile "#{options.base}/test/spec.html", (err, data) ->
|
17
|
+
res.writeHead(200)
|
18
|
+
res.end(data)
|
19
|
+
]
|
20
|
+
examples:
|
21
|
+
options:
|
22
|
+
port: 5000
|
23
|
+
base: './examples/'
|
24
|
+
middleware: (connect, options) ->
|
25
|
+
[connect.static(options.base), (req, res, next) ->
|
26
|
+
fs.readFile "#{options.base}/1_single_view.html", (err, data) ->
|
27
|
+
res.writeHead(200)
|
28
|
+
res.end(data)
|
29
|
+
]
|
30
|
+
|
31
|
+
uglify:
|
32
|
+
modal:
|
33
|
+
src: 'backbone.modal.js'
|
34
|
+
dest: 'backbone.modal-min.js'
|
35
|
+
marionettemodal:
|
36
|
+
src: 'marionette.modal.js'
|
37
|
+
dest: 'marionette.modal-min.js'
|
38
|
+
modals:
|
39
|
+
src: 'backbone.marionette.modals.js'
|
40
|
+
dest: 'backbone.marionette.modals-min.js'
|
41
|
+
bundled:
|
42
|
+
src: 'marionette.modal-bundled.js'
|
43
|
+
dest: 'marionette.modal-bundled-min.js'
|
44
|
+
|
45
|
+
jasmine:
|
46
|
+
all:
|
47
|
+
src: ['backbone.modal.js', 'marionette.modal.js', 'backbone.marionette.modals.js']
|
48
|
+
options:
|
49
|
+
specs: 'test/spec/**/*.js'
|
50
|
+
outfile: 'test/spec.html'
|
51
|
+
host: 'http://127.0.0.1:8000/'
|
52
|
+
vendor: ['examples/vendor/jquery-1.9.1.js', 'examples/vendor/underscore.js', 'examples/vendor/backbone.js', 'examples/vendor/marionette.js']
|
53
|
+
|
54
|
+
coffee:
|
55
|
+
all:
|
56
|
+
files:
|
57
|
+
'backbone.modal.js': 'src/backbone.modal.coffee'
|
58
|
+
'marionette.modal.js': 'src/marionette.modal.coffee'
|
59
|
+
'backbone.marionette.modals.js': 'src/backbone.marionette.modals.coffee'
|
60
|
+
'marionette.modal-bundled.js': ['src/backbone.modal.coffee', 'src/marionette.modal.coffee', 'src/backbone.marionette.modals.coffee']
|
61
|
+
|
62
|
+
'examples/vendor/backbone.modal.js': 'src/backbone.modal.coffee'
|
63
|
+
'examples/vendor/marionette.modal.js': 'src/marionette.modal.coffee'
|
64
|
+
'examples/vendor/backbone.marionette.modals.js': 'src/backbone.marionette.modals.coffee'
|
65
|
+
specs:
|
66
|
+
files:
|
67
|
+
grunt.file.expandMapping(['test/src/**/*.coffee'], 'test/spec/',
|
68
|
+
rename: (destBase, destPath) ->
|
69
|
+
return destBase + destPath.slice(9, destPath.length).replace(/\.coffee$/, '.js')
|
70
|
+
)
|
71
|
+
|
72
|
+
sass:
|
73
|
+
compile:
|
74
|
+
files:
|
75
|
+
'marionette.modal.css': 'src/marionette.modal.sass'
|
76
|
+
'marionette.modal.theme.css': 'src/marionette.modal.theme.sass'
|
77
|
+
'examples/vendor/marionette.modal.css': 'src/marionette.modal.sass'
|
78
|
+
'examples/vendor/marionette.modal.theme.css': 'src/marionette.modal.theme.sass'
|
79
|
+
'examples/style.css': 'src/style.sass'
|
80
|
+
|
81
|
+
concurrent:
|
82
|
+
compile: ['coffee', 'sass']
|
83
|
+
|
84
|
+
regarde:
|
85
|
+
livereloadJS:
|
86
|
+
files: ['test/**/*.js', 'examples/vendor/*.js']
|
87
|
+
tasks: ['livereload']
|
88
|
+
livereloadCSS:
|
89
|
+
files: ['examples/vendor/marionette.modal.css', 'examples/vendor/marionette.modal.theme.css', 'examples/style.css']
|
90
|
+
tasks: ['livereload:marionette.modal.css', 'livereload:examples/vendor/marionette.modal.theme.css', 'livereload:examples/style.css']
|
91
|
+
sass:
|
92
|
+
files: ['src/**/*.sass']
|
93
|
+
tasks: ['sass']
|
94
|
+
coffee:
|
95
|
+
files: ['src/**/*.coffee', 'test/src/**/*.coffee']
|
96
|
+
tasks: ['uglify', 'coffee']
|
97
|
+
|
98
|
+
grunt.loadNpmTasks 'grunt-contrib-coffee'
|
99
|
+
grunt.loadNpmTasks 'grunt-regarde'
|
100
|
+
grunt.loadNpmTasks 'grunt-open'
|
101
|
+
grunt.loadNpmTasks 'grunt-contrib-connect'
|
102
|
+
grunt.loadNpmTasks 'grunt-contrib-livereload'
|
103
|
+
grunt.loadNpmTasks 'grunt-contrib-jasmine'
|
104
|
+
grunt.loadNpmTasks 'grunt-contrib-uglify'
|
105
|
+
grunt.loadNpmTasks 'grunt-contrib-sass'
|
106
|
+
grunt.loadNpmTasks 'grunt-concurrent'
|
107
|
+
|
108
|
+
grunt.registerTask 'build', ['concurrent', 'uglify', 'jasmine:all:build']
|
109
|
+
grunt.registerTask 'watch', ['connect', 'build', 'livereload-start', 'open', 'regarde']
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jared Smith
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
## Marionette.Modal
|
2
|
+
|
3
|
+
A plugin for Marionette.js that simplifies creating modals for your marionette application.
|
4
|
+
|
5
|
+
This project is a fork of the original Backbone.Modal that has tighter integration with the Marionette.js framework.
|
6
|
+
|
7
|
+
Marionette.Modal.js removes boilerplate code and adds default behaviors and interactions. You can create a simple dialog modal or complex wizards with stacked modals on top of each other in a few lines of code.
|
8
|
+
|
9
|
+
Documentation is roughly the same as Backbone.Modal. The internals of the base modal view are extending Marionette.View rather than
|
10
|
+
Backbone.View in order to take advantage of the builtin functionality that marionette provides.
|
11
|
+
|
12
|
+
For a complete overview of the forked repo documentation visit: [http://awkward.github.io/backbone.modal/](http://awkward.github.io/backbone.modal/)
|
13
|
+
|
14
|
+
#### Bundled version
|
15
|
+
If you're using Backbone and Marionette.
|
16
|
+
* [marionette.modal-bundled-min.js](https://raw.github.com/Outcome-Engenuity/marionette.modal/master/marionette.modal-bundled-min.js)
|
17
|
+
|
18
|
+
#### Backbone.Modals.js and Backbone.Marionette.Modals.js separate
|
19
|
+
If you just want to use the Backbone version without Marionette.
|
20
|
+
* [backbone.modal-min.js](https://raw.github.com/Outcome-Engenuity/marionette.modal/master/backbone.modal-min.js)
|
21
|
+
* [backbone.marionette.modals-min.js](https://raw.github.com/Outcome-Engenuity/marionette.modal/master/backbone.marionette.modals-min.js)
|
22
|
+
|
23
|
+
#### CSS files
|
24
|
+
There's default style, and you can use our theme to make things look pretty.
|
25
|
+
* [marionette.modal.css](https://raw.github.com/Outcome-Engenuity/marionette.modal/master/marionette.modal.css)
|
26
|
+
* [marionette.modal.theme.css](https://raw.github.com/Outcome-Engenuity/marionette.modal/master/marionette.modal.theme.css)
|
27
|
+
|
28
|
+
### How to contribute
|
29
|
+
|
30
|
+
To get started `grunt install` to install all dependencies. If you have any requests, please create an issue. If you're working on something yourself, make a pull request and we'll make sure to check it out to get in into the next release.
|
31
|
+
|
32
|
+
### Tests
|
33
|
+
|
34
|
+
##### (Please note that there are currently no tests written for the marionette.modal view currently. I will make some when time permits.)
|
35
|
+
|
36
|
+
When you run the project by doing `grunt watch`. This will watch the tests, src and example files. It will open up a browser with the tests on `http://localhost:8000`. When you head over `http://localhost:5000`, it will show the example that's defined in the `Gruntfile.coffee`.
|
37
|
+
|
38
|
+
### Legal stuff (MIT License)
|
39
|
+
|
40
|
+
Copyright (c) 2013 jcsmith1859.
|
41
|
+
|
42
|
+
Distributed under MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1 @@
|
|
1
|
+
(function(){var a,b=function(a,b){return function(){return a.apply(b,arguments)}},c={}.hasOwnProperty,d=function(a,b){function d(){this.constructor=a}for(var e in b)c.call(b,e)&&(a[e]=b[e]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a};if("undefined"==typeof Backbone||null===Backbone)throw new Error("Backbone is not defined. Please include the latest version from http://documentcloud.github.com/backbone/backbone.js");Backbone.Marionette.Modals=function(c){function e(){return this.close=b(this.close,this),a=e.__super__.constructor.apply(this,arguments)}return d(e,c),e.prototype.modals=[],e.prototype.zIndex=0,e.prototype.show=function(a,b){var c,d,e,f,g,h;for(null==b&&(b={}),this.ensureEl(),this.modals.length>0&&(c=_.last(this.modals),c.modalEl.addClass(""+c.prefix+"-modal--stacked"),e=this.modals[this.modals.length-1],null!=e&&e.modalEl.removeClass(""+e.prefix+"-modal--stacked-reverse")),a.render(),a.regionEnabled=!0,this.$el.show(),this.$el.append(a.el),this.modals.length>0&&a.$el.css({background:"none"}),Marionette.triggerMethod.call(a,"show"),Marionette.triggerMethod.call(this,"show",a),this.currentView=a,h=this.modals,f=0,g=h.length;g>f;f++)d=h[f],d.undelegateModalEvents();return a.on("modal:close",this.close),this.modals.push(a),this.zIndex++},e.prototype.close=function(){var a,b;return b=this.currentView,b&&!b.isClosed?(b.close?b.close():b.remove&&b.remove(),b.off("modal:close",this.close),this.modals.splice(_.indexOf(this.modals,b),1),this.zIndex--,this.currentView=this.modals[this.zIndex-1],a=_.last(this.modals),a&&(a.modalEl.addClass(""+a.prefix+"-modal--stacked-reverse"),_.delay(function(){return a.modalEl.removeClass(""+a.prefix+"-modal--stacked")},300),0!==this.zIndex&&a.delegateModalEvents()),Marionette.triggerMethod.call(this,"close")):void 0},e.prototype.closeAll=function(){var a,b,c,d,e;for(d=this.modals,e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(this.close());return e},e}(Backbone.Marionette.Region)}).call(this);
|
@@ -0,0 +1,104 @@
|
|
1
|
+
(function() {
|
2
|
+
var _ref,
|
3
|
+
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
4
|
+
__hasProp = {}.hasOwnProperty,
|
5
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
6
|
+
|
7
|
+
if (typeof Backbone === "undefined" || Backbone === null) {
|
8
|
+
throw new Error("Backbone is not defined. Please include the latest version from http://documentcloud.github.com/backbone/backbone.js");
|
9
|
+
}
|
10
|
+
|
11
|
+
Backbone.Marionette.Modals = (function(_super) {
|
12
|
+
__extends(Modals, _super);
|
13
|
+
|
14
|
+
function Modals() {
|
15
|
+
this.close = __bind(this.close, this);
|
16
|
+
_ref = Modals.__super__.constructor.apply(this, arguments);
|
17
|
+
return _ref;
|
18
|
+
}
|
19
|
+
|
20
|
+
Modals.prototype.modals = [];
|
21
|
+
|
22
|
+
Modals.prototype.zIndex = 0;
|
23
|
+
|
24
|
+
Modals.prototype.show = function(modal, options) {
|
25
|
+
var lastModal, m, secondLastModal, _i, _len, _ref1;
|
26
|
+
if (options == null) {
|
27
|
+
options = {};
|
28
|
+
}
|
29
|
+
this.ensureEl();
|
30
|
+
if (this.modals.length > 0) {
|
31
|
+
lastModal = _.last(this.modals);
|
32
|
+
lastModal.modalEl.addClass("" + lastModal.prefix + "-modal--stacked");
|
33
|
+
secondLastModal = this.modals[this.modals.length - 1];
|
34
|
+
if (secondLastModal != null) {
|
35
|
+
secondLastModal.modalEl.removeClass("" + secondLastModal.prefix + "-modal--stacked-reverse");
|
36
|
+
}
|
37
|
+
}
|
38
|
+
modal.render();
|
39
|
+
modal.regionEnabled = true;
|
40
|
+
this.$el.show();
|
41
|
+
this.$el.append(modal.el);
|
42
|
+
if (this.modals.length > 0) {
|
43
|
+
modal.$el.css({
|
44
|
+
background: 'none'
|
45
|
+
});
|
46
|
+
}
|
47
|
+
Marionette.triggerMethod.call(modal, "show");
|
48
|
+
Marionette.triggerMethod.call(this, "show", modal);
|
49
|
+
this.currentView = modal;
|
50
|
+
_ref1 = this.modals;
|
51
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
52
|
+
m = _ref1[_i];
|
53
|
+
m.undelegateModalEvents();
|
54
|
+
}
|
55
|
+
modal.on('modal:close', this.close);
|
56
|
+
this.modals.push(modal);
|
57
|
+
return this.zIndex++;
|
58
|
+
};
|
59
|
+
|
60
|
+
Modals.prototype.close = function() {
|
61
|
+
var lastModal, modal,
|
62
|
+
_this = this;
|
63
|
+
modal = this.currentView;
|
64
|
+
if (!modal || modal.isClosed) {
|
65
|
+
return;
|
66
|
+
}
|
67
|
+
if (modal.close) {
|
68
|
+
modal.close();
|
69
|
+
} else if (modal.remove) {
|
70
|
+
modal.remove();
|
71
|
+
}
|
72
|
+
modal.off('modal:close', this.close);
|
73
|
+
this.modals.splice(_.indexOf(this.modals, modal), 1);
|
74
|
+
this.zIndex--;
|
75
|
+
this.currentView = this.modals[this.zIndex - 1];
|
76
|
+
lastModal = _.last(this.modals);
|
77
|
+
if (lastModal) {
|
78
|
+
lastModal.modalEl.addClass("" + lastModal.prefix + "-modal--stacked-reverse");
|
79
|
+
_.delay(function() {
|
80
|
+
return lastModal.modalEl.removeClass("" + lastModal.prefix + "-modal--stacked");
|
81
|
+
}, 300);
|
82
|
+
if (this.zIndex !== 0) {
|
83
|
+
lastModal.delegateModalEvents();
|
84
|
+
}
|
85
|
+
}
|
86
|
+
return Marionette.triggerMethod.call(this, "close");
|
87
|
+
};
|
88
|
+
|
89
|
+
Modals.prototype.closeAll = function() {
|
90
|
+
var modal, _i, _len, _ref1, _results;
|
91
|
+
_ref1 = this.modals;
|
92
|
+
_results = [];
|
93
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
94
|
+
modal = _ref1[_i];
|
95
|
+
_results.push(this.close());
|
96
|
+
}
|
97
|
+
return _results;
|
98
|
+
};
|
99
|
+
|
100
|
+
return Modals;
|
101
|
+
|
102
|
+
})(Backbone.Marionette.Region);
|
103
|
+
|
104
|
+
}).call(this);
|
@@ -0,0 +1 @@
|
|
1
|
+
(function(){var a=function(a,b){return function(){return a.apply(b,arguments)}},b={}.hasOwnProperty,c=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},d=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};if("undefined"==typeof Backbone||null===Backbone)throw new Error("Backbone is not defined. Please include the latest version from http://documentcloud.github.com/backbone/backbone.js");Backbone.Modal=function(b){function e(){this.triggerCancel=a(this.triggerCancel,this),this.triggerSubmit=a(this.triggerSubmit,this),this.triggerView=a(this.triggerView,this),this.clickOutside=a(this.clickOutside,this),this.checkKey=a(this.checkKey,this),this.args=Array.prototype.slice.apply(arguments),Backbone.View.prototype.constructor.apply(this,this.args),this.setUIElements(),this.delegateModalEvents()}return c(e,b),e.prototype.prefix="bbm",e.prototype.render=function(a){var b,c,d=this;return null==a&&(a={}),b=this.serializeData(),this.$el.addClass(""+this.prefix+"-wrapper"),this.modalEl=Backbone.$("<div />").addClass(""+this.prefix+"-modal"),this.template&&this.modalEl.html(this.template(b)),this.$el.html(this.modalEl),Backbone.$("body").on("keyup",this.checkKey),Backbone.$("body").on("click",this.clickOutside),this.viewContainer?(this.viewContainerEl=this.modalEl.find(this.viewContainer),this.viewContainerEl.addClass(""+this.prefix+"-modal__views")):this.viewContainerEl=this.modalEl,this.$el.show(),(null!=(c=this.views)?c.length:void 0)>0&&this.openAt(0),"function"==typeof this.onRender&&this.onRender(),this.modalEl.css({opacity:0}),this.$el.fadeIn({duration:100,complete:function(){return d.modalEl.css({opacity:1}).addClass(""+d.prefix+"-modal--open")}}),this},e.prototype.setUIElements=function(){var a;if(this.template=this.getOption("template"),this.views=this.getOption("views"),null!=(a=this.views)&&(a.length=_.size(this.views)),this.viewContainer=this.getOption("viewContainer"),this.$el.hide(),_.isUndefined(this.template)&&_.isUndefined(this.views))throw new Error("No template or views defined for Backbone.Modal");if(this.template&&this.views&&_.isUndefined(this.viewContainer))throw new Error("No viewContainer defined for Backbone.Modal")},e.prototype.getOption=function(a){return a?this.options&&d.call(this.options,a)>=0&&null!=this.options[a]?this.options[a]:this[a]:void 0},e.prototype.serializeData=function(){var a;return a={},this.model&&(a=_.extend(a,this.model.toJSON())),this.collection&&(a=_.extend(a,{items:this.collection.toJSON()})),a},e.prototype.delegateModalEvents=function(){var a,b,c,d,e,f,g;this.active=!0,a=this.getOption("cancelEl"),e=this.getOption("submitEl"),e&&this.$el.on("click",e,this.triggerSubmit),a&&this.$el.on("click",a,this.triggerCancel),g=[];for(b in this.views)"length"!==b?(c=b.match(/^(\S+)\s*(.*)$/),f=c[1],d=c[2],g.push(this.$el.on(f,d,this.views[b],this.triggerView))):g.push(void 0);return g},e.prototype.undelegateModalEvents=function(){var a,b,c,d,e,f,g;this.active=!1,a=this.getOption("cancelEl"),e=this.getOption("submitEl"),e&&this.$el.off("click",e,this.triggerSubmit),a&&this.$el.off("click",a,this.triggerCancel),g=[];for(b in this.views)"length"!==b?(c=b.match(/^(\S+)\s*(.*)$/),f=c[1],d=c[2],g.push(this.$el.off(f,d,this.views[b],this.triggerView))):g.push(void 0);return g},e.prototype.checkKey=function(a){if(this.active)switch(a.keyCode){case 27:return this.triggerCancel();case 13:return this.triggerSubmit()}},e.prototype.clickOutside=function(a){return Backbone.$(a.target).hasClass(""+this.prefix+"-wrapper")&&this.active?this.triggerCancel(null,!0):void 0},e.prototype.buildView=function(a){var b;if(a)return _.isFunction(a)?(b=new a(this.args[0]),b instanceof Backbone.View?{el:b.render().$el,view:b}:{el:a(this.args[0])}):{view:a,el:a.$el}},e.prototype.triggerView=function(a){var b,c,d,e;null!=a&&"function"==typeof a.preventDefault&&a.preventDefault(),e=a.data,c=this.buildView(e.view),this.currentView&&(this.previousView=this.currentView),this.currentView=c.view||c.el,b=0;for(d in this.views)e.view===this.views[d].view&&(this.currentIndex=b),b++;return e.onActive&&(_.isFunction(e.onActive)?e.onActive(this):_.isString(e.onActive)&&this[e.onActive].call(this,e)),this.shouldAnimate?this.animateToView(c.el):(this.shouldAnimate=!0,this.$(this.viewContainerEl).html(c.el))},e.prototype.animateToView=function(a){var b,c,d,e,f,g,h=this;return e={position:"relative",top:-9999,left:-9999},f=Backbone.$("<tester/>").css(e),f.html(this.$el.clone().css(e)),0!==Backbone.$("tester").length?Backbone.$("tester").replaceWith(f):Backbone.$("body").append(f),b=this.viewContainer?f.find(this.viewContainer):f.find("."+this.prefix+"-modal"),b.removeAttr("style"),d=b.outerHeight(),b.html(a),c=b.outerHeight(),d===c?(this.$(this.viewContainerEl).html(a),null!=(g=this.previousView)?"function"==typeof g.close?g.close():void 0:void 0):(this.$(this.viewContainerEl).css({opacity:0}),this.$(this.viewContainerEl).animate({height:c},100,function(){var b;return h.$(h.viewContainerEl).css({opacity:1}).removeAttr("style"),h.$(h.viewContainerEl).html(a),null!=(b=h.previousView)?"function"==typeof b.close?b.close():void 0:void 0}))},e.prototype.triggerSubmit=function(a){return a&&(null!=a&&a.preventDefault(),!this.beforeSubmit||this.beforeSubmit()!==!1)?("function"==typeof this.submit&&this.submit(),this.regionEnabled?this.trigger("modal:close"):this.close()):void 0},e.prototype.triggerCancel=function(a){return null!=a&&a.preventDefault(),this.beforeCancel&&this.beforeCancel()===!1?void 0:("function"==typeof this.cancel&&this.cancel(),this.regionEnabled?this.trigger("modal:close"):this.close())},e.prototype.close=function(){var a=this;return Backbone.$("body").off("keyup",this.checkKey),Backbone.$("body").off("click",this.clickOutside),"function"==typeof this.onClose&&this.onClose(),this.shouldAnimate=!1,this.modalEl.addClass(""+this.prefix+"-modal--close"),this.$el.fadeOut({duration:200}),_.delay(function(){var b;return null!=(b=a.currentView)&&"function"==typeof b.remove&&b.remove(),a.remove()},200)},e.prototype.openAt=function(a){var b,c,d;b=0;for(c in this.views)"length"!==c&&(b===a&&(d=this.views[c]),b++);return d&&(this.currentIndex=a,this.triggerView({data:d})),this},e.prototype.next=function(){return this.currentIndex+1<this.views.length?this.openAt(this.currentIndex+1):void 0},e.prototype.previous=function(){return this.currentIndex-1<this.views.length-1?this.openAt(this.currentIndex-1):void 0},e}(Backbone.View)}).call(this);
|