marionette-modal 1.0.0.8
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 +111 -0
- data/LICENSE +22 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/dist/backbone.marionette.modals-min.js +1 -0
- data/dist/backbone.marionette.modals.js +104 -0
- data/dist/backbone.modal-min.js +1 -0
- data/dist/backbone.modal.js +382 -0
- data/dist/marionette.modal-bundled-min.js +1 -0
- data/dist/marionette.modal-bundled.js +858 -0
- data/dist/marionette.modal-min.js +1 -0
- data/dist/marionette.modal.css +24 -0
- data/dist/marionette.modal.js +370 -0
- data/dist/marionette.modal.theme.css +324 -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 +1591 -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 +2466 -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 +1314 -0
- data/lib/marionette-modal/version.rb +3 -0
- data/lib/marionette-modal.rb +22 -0
- data/marionette-modal.gemspec +23 -0
- data/package.json +19 -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 +120 -0
- data/test/spec/backbone.modal.spec.js +224 -0
- data/test/spec.html +41 -0
- data/test/src/backbone.marionette.modals.spec.coffee +56 -0
- data/test/src/backbone.modal.spec.coffee +139 -0
- metadata +128 -0
| @@ -0,0 +1,382 @@ | |
| 1 | 
            +
            (function() {
         | 
| 2 | 
            +
              var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
         | 
| 3 | 
            +
                __hasProp = {}.hasOwnProperty,
         | 
| 4 | 
            +
                __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; },
         | 
| 5 | 
            +
                __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
         | 
| 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.Modal = (function(_super) {
         | 
| 12 | 
            +
                __extends(Modal, _super);
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                Modal.prototype.prefix = 'bbm';
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                function Modal() {
         | 
| 17 | 
            +
                  this.triggerCancel = __bind(this.triggerCancel, this);
         | 
| 18 | 
            +
                  this.triggerSubmit = __bind(this.triggerSubmit, this);
         | 
| 19 | 
            +
                  this.triggerView = __bind(this.triggerView, this);
         | 
| 20 | 
            +
                  this.clickOutside = __bind(this.clickOutside, this);
         | 
| 21 | 
            +
                  this.checkKey = __bind(this.checkKey, this);
         | 
| 22 | 
            +
                  this.args = Array.prototype.slice.apply(arguments);
         | 
| 23 | 
            +
                  Backbone.View.prototype.constructor.apply(this, this.args);
         | 
| 24 | 
            +
                  this.setUIElements();
         | 
| 25 | 
            +
                  this.delegateModalEvents();
         | 
| 26 | 
            +
                }
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                Modal.prototype.render = function(options) {
         | 
| 29 | 
            +
                  var data, _ref,
         | 
| 30 | 
            +
                    _this = this;
         | 
| 31 | 
            +
                  if (options == null) {
         | 
| 32 | 
            +
                    options = {};
         | 
| 33 | 
            +
                  }
         | 
| 34 | 
            +
                  data = this.serializeData();
         | 
| 35 | 
            +
                  this.$el.addClass("" + this.prefix + "-wrapper");
         | 
| 36 | 
            +
                  this.modalEl = Backbone.$('<div />').addClass("" + this.prefix + "-modal");
         | 
| 37 | 
            +
                  if (this.template) {
         | 
| 38 | 
            +
                    this.modalEl.html(this.template(data));
         | 
| 39 | 
            +
                  }
         | 
| 40 | 
            +
                  this.$el.html(this.modalEl);
         | 
| 41 | 
            +
                  Backbone.$('body').on('keyup', this.checkKey);
         | 
| 42 | 
            +
                  Backbone.$('body').on('click', this.clickOutside);
         | 
| 43 | 
            +
                  if (this.viewContainer) {
         | 
| 44 | 
            +
                    this.viewContainerEl = this.modalEl.find(this.viewContainer);
         | 
| 45 | 
            +
                    this.viewContainerEl.addClass("" + this.prefix + "-modal__views");
         | 
| 46 | 
            +
                  } else {
         | 
| 47 | 
            +
                    this.viewContainerEl = this.modalEl;
         | 
| 48 | 
            +
                  }
         | 
| 49 | 
            +
                  this.$el.show();
         | 
| 50 | 
            +
                  if (((_ref = this.views) != null ? _ref.length : void 0) > 0) {
         | 
| 51 | 
            +
                    this.openAt(0);
         | 
| 52 | 
            +
                  }
         | 
| 53 | 
            +
                  if (typeof this.onRender === "function") {
         | 
| 54 | 
            +
                    this.onRender();
         | 
| 55 | 
            +
                  }
         | 
| 56 | 
            +
                  this.modalEl.css({
         | 
| 57 | 
            +
                    opacity: 0
         | 
| 58 | 
            +
                  });
         | 
| 59 | 
            +
                  this.$el.fadeIn({
         | 
| 60 | 
            +
                    duration: 100,
         | 
| 61 | 
            +
                    complete: function() {
         | 
| 62 | 
            +
                      return _this.modalEl.css({
         | 
| 63 | 
            +
                        opacity: 1
         | 
| 64 | 
            +
                      }).addClass("" + _this.prefix + "-modal--open");
         | 
| 65 | 
            +
                    }
         | 
| 66 | 
            +
                  });
         | 
| 67 | 
            +
                  return this;
         | 
| 68 | 
            +
                };
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                Modal.prototype.setUIElements = function() {
         | 
| 71 | 
            +
                  var _ref;
         | 
| 72 | 
            +
                  this.template = this.getOption('template');
         | 
| 73 | 
            +
                  this.views = this.getOption('views');
         | 
| 74 | 
            +
                  if ((_ref = this.views) != null) {
         | 
| 75 | 
            +
                    _ref.length = _.size(this.views);
         | 
| 76 | 
            +
                  }
         | 
| 77 | 
            +
                  this.viewContainer = this.getOption('viewContainer');
         | 
| 78 | 
            +
                  this.$el.hide();
         | 
| 79 | 
            +
                  if (_.isUndefined(this.template) && _.isUndefined(this.views)) {
         | 
| 80 | 
            +
                    throw new Error('No template or views defined for Backbone.Modal');
         | 
| 81 | 
            +
                  }
         | 
| 82 | 
            +
                  if (this.template && this.views && _.isUndefined(this.viewContainer)) {
         | 
| 83 | 
            +
                    throw new Error('No viewContainer defined for Backbone.Modal');
         | 
| 84 | 
            +
                  }
         | 
| 85 | 
            +
                };
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                Modal.prototype.getOption = function(option) {
         | 
| 88 | 
            +
                  if (!option) {
         | 
| 89 | 
            +
                    return;
         | 
| 90 | 
            +
                  }
         | 
| 91 | 
            +
                  if (this.options && __indexOf.call(this.options, option) >= 0 && (this.options[option] != null)) {
         | 
| 92 | 
            +
                    return this.options[option];
         | 
| 93 | 
            +
                  } else {
         | 
| 94 | 
            +
                    return this[option];
         | 
| 95 | 
            +
                  }
         | 
| 96 | 
            +
                };
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                Modal.prototype.serializeData = function() {
         | 
| 99 | 
            +
                  var data;
         | 
| 100 | 
            +
                  data = {};
         | 
| 101 | 
            +
                  if (this.model) {
         | 
| 102 | 
            +
                    data = _.extend(data, this.model.toJSON());
         | 
| 103 | 
            +
                  }
         | 
| 104 | 
            +
                  if (this.collection) {
         | 
| 105 | 
            +
                    data = _.extend(data, {
         | 
| 106 | 
            +
                      items: this.collection.toJSON()
         | 
| 107 | 
            +
                    });
         | 
| 108 | 
            +
                  }
         | 
| 109 | 
            +
                  return data;
         | 
| 110 | 
            +
                };
         | 
| 111 | 
            +
             | 
| 112 | 
            +
                Modal.prototype.delegateModalEvents = function() {
         | 
| 113 | 
            +
                  var cancelEl, key, match, selector, submitEl, trigger, _results;
         | 
| 114 | 
            +
                  this.active = true;
         | 
| 115 | 
            +
                  cancelEl = this.getOption('cancelEl');
         | 
| 116 | 
            +
                  submitEl = this.getOption('submitEl');
         | 
| 117 | 
            +
                  if (submitEl) {
         | 
| 118 | 
            +
                    this.$el.on('click', submitEl, this.triggerSubmit);
         | 
| 119 | 
            +
                  }
         | 
| 120 | 
            +
                  if (cancelEl) {
         | 
| 121 | 
            +
                    this.$el.on('click', cancelEl, this.triggerCancel);
         | 
| 122 | 
            +
                  }
         | 
| 123 | 
            +
                  _results = [];
         | 
| 124 | 
            +
                  for (key in this.views) {
         | 
| 125 | 
            +
                    if (key !== 'length') {
         | 
| 126 | 
            +
                      match = key.match(/^(\S+)\s*(.*)$/);
         | 
| 127 | 
            +
                      trigger = match[1];
         | 
| 128 | 
            +
                      selector = match[2];
         | 
| 129 | 
            +
                      _results.push(this.$el.on(trigger, selector, this.views[key], this.triggerView));
         | 
| 130 | 
            +
                    } else {
         | 
| 131 | 
            +
                      _results.push(void 0);
         | 
| 132 | 
            +
                    }
         | 
| 133 | 
            +
                  }
         | 
| 134 | 
            +
                  return _results;
         | 
| 135 | 
            +
                };
         | 
| 136 | 
            +
             | 
| 137 | 
            +
                Modal.prototype.undelegateModalEvents = function() {
         | 
| 138 | 
            +
                  var cancelEl, key, match, selector, submitEl, trigger, _results;
         | 
| 139 | 
            +
                  this.active = false;
         | 
| 140 | 
            +
                  cancelEl = this.getOption('cancelEl');
         | 
| 141 | 
            +
                  submitEl = this.getOption('submitEl');
         | 
| 142 | 
            +
                  if (submitEl) {
         | 
| 143 | 
            +
                    this.$el.off('click', submitEl, this.triggerSubmit);
         | 
| 144 | 
            +
                  }
         | 
| 145 | 
            +
                  if (cancelEl) {
         | 
| 146 | 
            +
                    this.$el.off('click', cancelEl, this.triggerCancel);
         | 
| 147 | 
            +
                  }
         | 
| 148 | 
            +
                  _results = [];
         | 
| 149 | 
            +
                  for (key in this.views) {
         | 
| 150 | 
            +
                    if (key !== 'length') {
         | 
| 151 | 
            +
                      match = key.match(/^(\S+)\s*(.*)$/);
         | 
| 152 | 
            +
                      trigger = match[1];
         | 
| 153 | 
            +
                      selector = match[2];
         | 
| 154 | 
            +
                      _results.push(this.$el.off(trigger, selector, this.views[key], this.triggerView));
         | 
| 155 | 
            +
                    } else {
         | 
| 156 | 
            +
                      _results.push(void 0);
         | 
| 157 | 
            +
                    }
         | 
| 158 | 
            +
                  }
         | 
| 159 | 
            +
                  return _results;
         | 
| 160 | 
            +
                };
         | 
| 161 | 
            +
             | 
| 162 | 
            +
                Modal.prototype.checkKey = function(e) {
         | 
| 163 | 
            +
                  if (this.active) {
         | 
| 164 | 
            +
                    switch (e.keyCode) {
         | 
| 165 | 
            +
                      case 27:
         | 
| 166 | 
            +
                        return this.triggerCancel();
         | 
| 167 | 
            +
                      case 13:
         | 
| 168 | 
            +
                        return this.triggerSubmit();
         | 
| 169 | 
            +
                    }
         | 
| 170 | 
            +
                  }
         | 
| 171 | 
            +
                };
         | 
| 172 | 
            +
             | 
| 173 | 
            +
                Modal.prototype.clickOutside = function(e) {
         | 
| 174 | 
            +
                  if (Backbone.$(e.target).hasClass("" + this.prefix + "-wrapper") && this.active) {
         | 
| 175 | 
            +
                    return this.triggerCancel(null, true);
         | 
| 176 | 
            +
                  }
         | 
| 177 | 
            +
                };
         | 
| 178 | 
            +
             | 
| 179 | 
            +
                Modal.prototype.buildView = function(viewType) {
         | 
| 180 | 
            +
                  var view;
         | 
| 181 | 
            +
                  if (!viewType) {
         | 
| 182 | 
            +
                    return;
         | 
| 183 | 
            +
                  }
         | 
| 184 | 
            +
                  if (_.isFunction(viewType)) {
         | 
| 185 | 
            +
                    view = new viewType(this.args[0]);
         | 
| 186 | 
            +
                    if (view instanceof Backbone.View) {
         | 
| 187 | 
            +
                      return {
         | 
| 188 | 
            +
                        el: view.render().$el,
         | 
| 189 | 
            +
                        view: view
         | 
| 190 | 
            +
                      };
         | 
| 191 | 
            +
                    } else {
         | 
| 192 | 
            +
                      return {
         | 
| 193 | 
            +
                        el: viewType(this.args[0])
         | 
| 194 | 
            +
                      };
         | 
| 195 | 
            +
                    }
         | 
| 196 | 
            +
                  }
         | 
| 197 | 
            +
                  return {
         | 
| 198 | 
            +
                    view: viewType,
         | 
| 199 | 
            +
                    el: viewType.$el
         | 
| 200 | 
            +
                  };
         | 
| 201 | 
            +
                };
         | 
| 202 | 
            +
             | 
| 203 | 
            +
                Modal.prototype.triggerView = function(e) {
         | 
| 204 | 
            +
                  var index, instance, key, options;
         | 
| 205 | 
            +
                  if (e != null) {
         | 
| 206 | 
            +
                    if (typeof e.preventDefault === "function") {
         | 
| 207 | 
            +
                      e.preventDefault();
         | 
| 208 | 
            +
                    }
         | 
| 209 | 
            +
                  }
         | 
| 210 | 
            +
                  options = e.data;
         | 
| 211 | 
            +
                  instance = this.buildView(options.view);
         | 
| 212 | 
            +
                  if (this.currentView) {
         | 
| 213 | 
            +
                    this.previousView = this.currentView;
         | 
| 214 | 
            +
                  }
         | 
| 215 | 
            +
                  this.currentView = instance.view || instance.el;
         | 
| 216 | 
            +
                  index = 0;
         | 
| 217 | 
            +
                  for (key in this.views) {
         | 
| 218 | 
            +
                    if (options.view === this.views[key].view) {
         | 
| 219 | 
            +
                      this.currentIndex = index;
         | 
| 220 | 
            +
                    }
         | 
| 221 | 
            +
                    index++;
         | 
| 222 | 
            +
                  }
         | 
| 223 | 
            +
                  if (options.onActive) {
         | 
| 224 | 
            +
                    if (_.isFunction(options.onActive)) {
         | 
| 225 | 
            +
                      options.onActive(this);
         | 
| 226 | 
            +
                    } else if (_.isString(options.onActive)) {
         | 
| 227 | 
            +
                      this[options.onActive].call(this, options);
         | 
| 228 | 
            +
                    }
         | 
| 229 | 
            +
                  }
         | 
| 230 | 
            +
                  if (this.shouldAnimate) {
         | 
| 231 | 
            +
                    return this.animateToView(instance.el);
         | 
| 232 | 
            +
                  } else {
         | 
| 233 | 
            +
                    this.shouldAnimate = true;
         | 
| 234 | 
            +
                    return this.$(this.viewContainerEl).html(instance.el);
         | 
| 235 | 
            +
                  }
         | 
| 236 | 
            +
                };
         | 
| 237 | 
            +
             | 
| 238 | 
            +
                Modal.prototype.animateToView = function(view) {
         | 
| 239 | 
            +
                  var container, newHeight, previousHeight, style, tester, _ref,
         | 
| 240 | 
            +
                    _this = this;
         | 
| 241 | 
            +
                  style = {
         | 
| 242 | 
            +
                    position: 'relative',
         | 
| 243 | 
            +
                    top: -9999,
         | 
| 244 | 
            +
                    left: -9999
         | 
| 245 | 
            +
                  };
         | 
| 246 | 
            +
                  tester = Backbone.$('<tester/>').css(style);
         | 
| 247 | 
            +
                  tester.html(this.$el.clone().css(style));
         | 
| 248 | 
            +
                  if (Backbone.$('tester').length !== 0) {
         | 
| 249 | 
            +
                    Backbone.$('tester').replaceWith(tester);
         | 
| 250 | 
            +
                  } else {
         | 
| 251 | 
            +
                    Backbone.$('body').append(tester);
         | 
| 252 | 
            +
                  }
         | 
| 253 | 
            +
                  if (this.viewContainer) {
         | 
| 254 | 
            +
                    container = tester.find(this.viewContainer);
         | 
| 255 | 
            +
                  } else {
         | 
| 256 | 
            +
                    container = tester.find("." + this.prefix + "-modal");
         | 
| 257 | 
            +
                  }
         | 
| 258 | 
            +
                  container.removeAttr('style');
         | 
| 259 | 
            +
                  previousHeight = container.outerHeight();
         | 
| 260 | 
            +
                  container.html(view);
         | 
| 261 | 
            +
                  newHeight = container.outerHeight();
         | 
| 262 | 
            +
                  if (previousHeight === newHeight) {
         | 
| 263 | 
            +
                    this.$(this.viewContainerEl).html(view);
         | 
| 264 | 
            +
                    return (_ref = this.previousView) != null ? typeof _ref.close === "function" ? _ref.close() : void 0 : void 0;
         | 
| 265 | 
            +
                  } else {
         | 
| 266 | 
            +
                    this.$(this.viewContainerEl).css({
         | 
| 267 | 
            +
                      opacity: 0
         | 
| 268 | 
            +
                    });
         | 
| 269 | 
            +
                    return this.$(this.viewContainerEl).animate({
         | 
| 270 | 
            +
                      height: newHeight
         | 
| 271 | 
            +
                    }, 100, function() {
         | 
| 272 | 
            +
                      var _ref1;
         | 
| 273 | 
            +
                      _this.$(_this.viewContainerEl).css({
         | 
| 274 | 
            +
                        opacity: 1
         | 
| 275 | 
            +
                      }).removeAttr('style');
         | 
| 276 | 
            +
                      _this.$(_this.viewContainerEl).html(view);
         | 
| 277 | 
            +
                      return (_ref1 = _this.previousView) != null ? typeof _ref1.close === "function" ? _ref1.close() : void 0 : void 0;
         | 
| 278 | 
            +
                    });
         | 
| 279 | 
            +
                  }
         | 
| 280 | 
            +
                };
         | 
| 281 | 
            +
             | 
| 282 | 
            +
                Modal.prototype.triggerSubmit = function(e) {
         | 
| 283 | 
            +
                  if (!e) {
         | 
| 284 | 
            +
                    return;
         | 
| 285 | 
            +
                  }
         | 
| 286 | 
            +
                  if (e != null) {
         | 
| 287 | 
            +
                    e.preventDefault();
         | 
| 288 | 
            +
                  }
         | 
| 289 | 
            +
                  if (this.beforeSubmit) {
         | 
| 290 | 
            +
                    if (this.beforeSubmit() === false) {
         | 
| 291 | 
            +
                      return;
         | 
| 292 | 
            +
                    }
         | 
| 293 | 
            +
                  }
         | 
| 294 | 
            +
                  if (typeof this.submit === "function") {
         | 
| 295 | 
            +
                    this.submit();
         | 
| 296 | 
            +
                  }
         | 
| 297 | 
            +
                  if (this.regionEnabled) {
         | 
| 298 | 
            +
                    return this.trigger('modal:close');
         | 
| 299 | 
            +
                  } else {
         | 
| 300 | 
            +
                    return this.close();
         | 
| 301 | 
            +
                  }
         | 
| 302 | 
            +
                };
         | 
| 303 | 
            +
             | 
| 304 | 
            +
                Modal.prototype.triggerCancel = function(e) {
         | 
| 305 | 
            +
                  if (e != null) {
         | 
| 306 | 
            +
                    e.preventDefault();
         | 
| 307 | 
            +
                  }
         | 
| 308 | 
            +
                  if (this.beforeCancel) {
         | 
| 309 | 
            +
                    if (this.beforeCancel() === false) {
         | 
| 310 | 
            +
                      return;
         | 
| 311 | 
            +
                    }
         | 
| 312 | 
            +
                  }
         | 
| 313 | 
            +
                  if (typeof this.cancel === "function") {
         | 
| 314 | 
            +
                    this.cancel();
         | 
| 315 | 
            +
                  }
         | 
| 316 | 
            +
                  if (this.regionEnabled) {
         | 
| 317 | 
            +
                    return this.trigger('modal:close');
         | 
| 318 | 
            +
                  } else {
         | 
| 319 | 
            +
                    return this.close();
         | 
| 320 | 
            +
                  }
         | 
| 321 | 
            +
                };
         | 
| 322 | 
            +
             | 
| 323 | 
            +
                Modal.prototype.close = function() {
         | 
| 324 | 
            +
                  var _this = this;
         | 
| 325 | 
            +
                  Backbone.$('body').off('keyup', this.checkKey);
         | 
| 326 | 
            +
                  Backbone.$('body').off('click', this.clickOutside);
         | 
| 327 | 
            +
                  if (typeof this.onClose === "function") {
         | 
| 328 | 
            +
                    this.onClose();
         | 
| 329 | 
            +
                  }
         | 
| 330 | 
            +
                  this.shouldAnimate = false;
         | 
| 331 | 
            +
                  this.modalEl.addClass("" + this.prefix + "-modal--close");
         | 
| 332 | 
            +
                  this.$el.fadeOut({
         | 
| 333 | 
            +
                    duration: 200
         | 
| 334 | 
            +
                  });
         | 
| 335 | 
            +
                  return _.delay(function() {
         | 
| 336 | 
            +
                    var _ref;
         | 
| 337 | 
            +
                    if ((_ref = _this.currentView) != null) {
         | 
| 338 | 
            +
                      if (typeof _ref.remove === "function") {
         | 
| 339 | 
            +
                        _ref.remove();
         | 
| 340 | 
            +
                      }
         | 
| 341 | 
            +
                    }
         | 
| 342 | 
            +
                    return _this.remove();
         | 
| 343 | 
            +
                  }, 200);
         | 
| 344 | 
            +
                };
         | 
| 345 | 
            +
             | 
| 346 | 
            +
                Modal.prototype.openAt = function(index) {
         | 
| 347 | 
            +
                  var i, key, view;
         | 
| 348 | 
            +
                  i = 0;
         | 
| 349 | 
            +
                  for (key in this.views) {
         | 
| 350 | 
            +
                    if (key !== 'length') {
         | 
| 351 | 
            +
                      if (i === index) {
         | 
| 352 | 
            +
                        view = this.views[key];
         | 
| 353 | 
            +
                      }
         | 
| 354 | 
            +
                      i++;
         | 
| 355 | 
            +
                    }
         | 
| 356 | 
            +
                  }
         | 
| 357 | 
            +
                  if (view) {
         | 
| 358 | 
            +
                    this.currentIndex = index;
         | 
| 359 | 
            +
                    this.triggerView({
         | 
| 360 | 
            +
                      data: view
         | 
| 361 | 
            +
                    });
         | 
| 362 | 
            +
                  }
         | 
| 363 | 
            +
                  return this;
         | 
| 364 | 
            +
                };
         | 
| 365 | 
            +
             | 
| 366 | 
            +
                Modal.prototype.next = function() {
         | 
| 367 | 
            +
                  if (this.currentIndex + 1 < this.views.length) {
         | 
| 368 | 
            +
                    return this.openAt(this.currentIndex + 1);
         | 
| 369 | 
            +
                  }
         | 
| 370 | 
            +
                };
         | 
| 371 | 
            +
             | 
| 372 | 
            +
                Modal.prototype.previous = function() {
         | 
| 373 | 
            +
                  if (this.currentIndex - 1 < this.views.length - 1) {
         | 
| 374 | 
            +
                    return this.openAt(this.currentIndex - 1);
         | 
| 375 | 
            +
                  }
         | 
| 376 | 
            +
                };
         | 
| 377 | 
            +
             | 
| 378 | 
            +
                return Modal;
         | 
| 379 | 
            +
             | 
| 380 | 
            +
              })(Backbone.View);
         | 
| 381 | 
            +
             | 
| 382 | 
            +
            }).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),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};if("undefined"==typeof Marionette||null===Marionette)throw new Error("Marionette is not defined. Please include the latest version from https://github.com/marionettejs/backbone.marionette");Marionette.Modal=function(b){function d(){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),Marionette.View.prototype.constructor.apply(this,this.args),this.setUIElements(),this.delegateModalEvents()}return c(d,b),d.prototype.prefix="bbm",d.prototype.render=function(a){var b,c,d=this;return null==a&&(a={}),b=this.serializeData(),this.$el.addClass(""+this.prefix+"-wrapper"),this.modalEl=Marionette.$("<div />").addClass(""+this.prefix+"-modal"),this.template&&this.modalEl.html(this.template(b)),this.$el.html(this.modalEl),Marionette.$("body").on("keyup",this.checkKey),Marionette.$("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},d.prototype.setUIElements=function(){var a;if(this.template=Marionette.getOption(this,"template"),this.views=Marionette.getOption(this,"views"),null!=(a=this.views)&&(a.length=_.size(this.views)),this.viewContainer=Marionette.getOption(this,"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")},d.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},d.prototype.delegateModalEvents=function(){var a,b,c,d,e,f,g;this.active=!0,a=Marionette.getOption(this,"cancelEl"),e=Marionette.getOption(this,"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},d.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},d.prototype.checkKey=function(a){if(this.active)switch(a.keyCode){case 27:return this.triggerCancel();case 13:return this.triggerSubmit()}},d.prototype.clickOutside=function(a){return Marionette.$(a.target).hasClass(""+this.prefix+"-wrapper")&&this.active?this.triggerCancel(null,!0):void 0},d.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}},d.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))},d.prototype.animateToView=function(a){var b,c,d,e,f,g,h=this;return e={position:"relative",top:-9999,left:-9999},f=Marionette.$("<tester/>").css(e),f.html(this.$el.clone().css(e)),0!==Marionette.$("tester").length?Marionette.$("tester").replaceWith(f):Marionette.$("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}))},d.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},d.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.triggerMethod("modal:close"):this.close())},d.prototype.close=function(){var a=this;return Marionette.$("body").off("keyup",this.checkKey),Marionette.$("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)},d.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},d.prototype.next=function(){return this.currentIndex+1<this.views.length?this.openAt(this.currentIndex+1):void 0},d.prototype.previous=function(){return this.currentIndex-1<this.views.length-1?this.openAt(this.currentIndex-1):void 0},d}(Marionette.View)}.call(this),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);
         |