Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

stub missing specs, extract core into multiple files. add modal

  • Loading branch information...
commit f549d622882892e8d4a7e73bb9d50349664fd08c 1 parent cb9b4bc
@brentkirby brentkirby authored
Showing with 2,103 additions and 1,408 deletions.
  1. +1 −1  .rbenv-gemsets
  2. +16 −9 Cakefile
  3. +9 −0 Rakefile
  4. +43 −6 build/themes/bootstrap.js
  5. +1 −1  build/themes/bootstrap.min.js
  6. +797 −595 build/transit.js
  7. +1 −1  build/transit.min.js
  8. +7 −3 demo/index.html
  9. +797 −595 demo/transit.js
  10. +22 −0 public/javascripts/Player.js
  11. +7 −0 public/javascripts/Song.js
  12. +5 −3 spec.html
  13. +1 −0  spec/core/browser_spec.coffee
  14. +1 −0  spec/core/selection_spec.coffee
  15. +61 −0 spec/core/template_spec.coffee
  16. +0 −1  spec/core/uploader_spec.coffee
  17. +1 −44 spec/core_spec.coffee
  18. +1 −0  spec/model/asset_spec.coffee
  19. +1 −0  spec/model/assets_spec.coffee
  20. +12 −1 spec/support/helpers.js
  21. 0  spec/{views → ui}/manager_spec.coffee
  22. +37 −0 spec/ui/modal_spec.coffee
  23. 0  spec/{views → ui}/panel_spec.coffee
  24. +1 −1  spec/{views → ui}/toolbar_spec.coffee
  25. +1 −0  spec/ui/uploader_spec.coffee
  26. +1 −0  spec/views/asset_manager_spec.coffee
  27. +1 −0  spec/views/context_spec.coffee
  28. +49 −69 src/core.coffee
  29. +47 −0 src/core/template.coffee
  30. +1 −0  src/css/transit.scss
  31. +2 −22 src/model/asset.coffee
  32. +6 −0 src/model/assets.coffee
  33. +49 −7 src/themes/bootstrap.coffee
  34. +2 −12 src/{views → ui}/manager.coffee
  35. +50 −0 src/ui/modal.coffee
  36. +1 −1  src/{core → ui}/notify.coffee
  37. +7 −9 src/{views → ui}/panel.coffee
  38. +5 −11 src/{views → ui}/toolbar.coffee
  39. +2 −9 src/{core → ui}/uploader.coffee
  40. +57 −7 src/views/asset_manager.coffee
View
2  .rbenv-gemsets
@@ -1 +1 @@
-jasmine static utils
+node static utils
View
25 Cakefile
@@ -28,19 +28,26 @@ less = require 'less'
javascripts = {
'build/transit.js': [
'src/core.coffee'
- 'src/core/notify.coffee'
- 'src/core/uploader.coffee'
- 'src/core/selection.coffee'
'src/core/browser.coffee'
+ 'src/core/selection.coffee'
+ 'src/core/template.coffee'
+
+ 'src/ui/manager.coffee'
+ 'src/ui/modal.coffee'
+ 'src/ui/notify.coffee'
+ 'src/ui/panel.coffee'
+ 'src/ui/toolbar.coffee'
+ 'src/ui/uploader.coffee'
+
+ 'src/model/asset.coffee'
+ 'src/model/assets.coffee'
'src/model/context.coffee'
- 'src/model/deliverable.coffee'
'src/model/contexts.coffee'
- 'src/model/asset.coffee'
- 'src/views/context.coffee'
- 'src/views/manager.coffee'
- 'src/views/toolbar.coffee'
- 'src/views/panel.coffee'
+ 'src/model/deliverable.coffee'
+
'src/views/asset_manager.coffee'
+ 'src/views/context.coffee'
+
],
'build/themes/bootstrap.js':[
'src/themes/bootstrap.coffee'
View
9 Rakefile
@@ -0,0 +1,9 @@
+
+begin
+ require 'jasmine'
+ load 'jasmine/tasks/jasmine.rake'
+rescue LoadError
+ task :jasmine do
+ abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
+ end
+end
View
49 build/themes/bootstrap.js
@@ -1,29 +1,66 @@
(function() {
var root;
- root = Transit.config.template_path;
+ root = Transit.Template.url;
- Transit.template.set("" + root + "/core/save-button.jst", '<button class="save btn primary"><i class="icon-ok"></i> <%= text %></button>');
+ Transit.Template.set("" + root + "/core/save-button.jst", '<button class="save btn primary"><i class="icon-ok"></i> <%= text %></button>');
- Transit.template.set("" + root + "/core/tab-bar.jst", '\
+ Transit.Template.set("" + root + "/core/nav-bar.jst", '\
<div class="navbar">\
<div class="navbar-inner">\
- <ul class = "transit-tab-bar nav"></ul>\
+ <ul class="transit-nav-bar nav"></ul>\
</div>\
</div>\
');
- Transit.template.set("" + root + "/core/notification.jst", '\
+ Transit.Template.set("" + root + "/core/tab-bar.jst", '\
+ <ul class="transit-tab-bar nav nav-tabs"></ul>\
+');
+
+ Transit.Template.set("" + root + "/core/pill-bar.jst", '\
+ <ul class="transit-pill-bar nav nav-pills"></ul>\
+');
+
+ Transit.Template.set("" + root + "/core/notification.jst", '\
<div class="alert alert-<%= type %>">\
<button type="button" class="close" data-dismiss="alert">×</button>\
<%= message %>\
</div>\
');
- Transit.template.set("" + root + "/core/progress-bar.jst", '\
+ Transit.Template.set("" + root + "/core/modal.jst", '\
+ <div class="modal fade">\
+ <div class="modal-header">\
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>\
+ <h3><%= title %></h3>\
+ </div>\
+ <div class="modal-body">\
+ <%= content %>\
+ </div>\
+ <div class="modal-footer">\
+ <% _.each(buttons, function(button){ %>\
+ <a href="#" class="btn <%= button.css %>" data-action="<%= button.action %>"><%= button.text %></a>\
+ <% }); %>\
+ </div>\
+</div>\
+');
+
+ Transit.Template.set("" + root + "/core/progress-bar.jst", '\
<div class="progress progress-striped active">\
<div class="bar" style="width:<%= percent %>"></div>\
</div>\
');
+ Transit.Template.set("" + root + "/core/assets/image.jst", '\
+ <img src="<%= asset.get("url") %>" />\
+ <a href="#" class="icon-remove" data-action="remove"></a>\
+');
+
+ Transit.Template.set("" + root + "/core/assets/file.jst", '\
+ <a href="<%= asset.get("url") %>"><%= asset.get("filename") %></a>\
+ <a href="#" class="icon-remove" data-action="remove"></a>\
+');
+
+ Transit.Template.set("" + root + "/core/assets/uploader.jst", '');
+
}).call(this);
View
2  build/themes/bootstrap.min.js
@@ -1 +1 @@
-(function(){var e;e=Transit.config.template_path,Transit.template.set(""+e+"/core/save-button.jst",'<button class="save btn primary"><i class="icon-ok"></i> <%= text %></button>'),Transit.template.set(""+e+"/core/tab-bar.jst",' <div class="navbar"> <div class="navbar-inner"> <ul class = "transit-tab-bar nav"></ul> </div> </div>'),Transit.template.set(""+e+"/core/notification.jst",' <div class="alert alert-<%= type %>"> <button type="button" class="close" data-dismiss="alert">×</button> <%= message %> </div>'),Transit.template.set(""+e+"/core/progress-bar.jst",' <div class="progress progress-striped active"> <div class="bar" style="width:<%= percent %>"></div> </div>')}).call(this)
+(function(){var e;e=Transit.Template.url,Transit.Template.set(""+e+"/core/save-button.jst",'<button class="save btn primary"><i class="icon-ok"></i> <%= text %></button>'),Transit.Template.set(""+e+"/core/nav-bar.jst",' <div class="navbar"> <div class="navbar-inner"> <ul class="transit-nav-bar nav"></ul> </div> </div>'),Transit.Template.set(""+e+"/core/tab-bar.jst",' <ul class="transit-tab-bar nav nav-tabs"></ul>'),Transit.Template.set(""+e+"/core/pill-bar.jst",' <ul class="transit-pill-bar nav nav-pills"></ul>'),Transit.Template.set(""+e+"/core/notification.jst",' <div class="alert alert-<%= type %>"> <button type="button" class="close" data-dismiss="alert">×</button> <%= message %> </div>'),Transit.Template.set(""+e+"/core/modal.jst",' <div class="modal fade"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> <h3><%= title %></h3> </div> <div class="modal-body"> <%= content %> </div> <div class="modal-footer"> <% _.each(buttons, function(button){ %> <a href="#" class="btn <%= button.css %>" data-action="<%= button.action %>"><%= button.text %></a> <% }); %> </div></div>'),Transit.Template.set(""+e+"/core/progress-bar.jst",' <div class="progress progress-striped active"> <div class="bar" style="width:<%= percent %>"></div> </div>'),Transit.Template.set(""+e+"/core/assets/image.jst",' <img src="<%= asset.get("url") %>" /> <a href="#" class="icon-remove" data-action="remove"></a>'),Transit.Template.set(""+e+"/core/assets/file.jst",' <a href="<%= asset.get("url") %>"><%= asset.get("filename") %></a> <a href="#" class="icon-remove" data-action="remove"></a>'),Transit.Template.set(""+e+"/core/assets/uploader.jst","")}).call(this)
View
1,392 build/transit.js
@@ -1,8 +1,12 @@
(function() {
- var Cache, Settings, Template, Transit, setting, _ready,
+ var Cache, Transit, _ready, _winready,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__slice = [].slice;
+ _ready = true;
+
+ _winready = false;
+
Cache = (function() {
function Cache() {
@@ -47,228 +51,94 @@
})();
- Settings = {
- template_path: '/transit/views',
- asset_path: '/transit/assets'
- };
-
- Template = (function() {
-
- function Template() {
- this._pathify = __bind(this._pathify, this);
-
- this.set = __bind(this.set, this);
-
- this.load = __bind(this.load, this);
-
- this.compile = __bind(this.compile, this);
-
- }
-
- Template.prototype.compile = function(html) {
- return _.template(html);
- };
-
- Template.prototype.load = function(path, callback) {
- var exists,
- _this = this;
- exists = Transit.cache.get('tpl', path);
- if (exists !== void 0) {
- return callback(exists);
- }
- return $.get(this._pathify(path), function(data) {
- var result;
- result = _this.compile(data);
- Transit.cache.set('tpl', path, result);
- return callback(result);
- });
- };
-
- Template.prototype.set = function(name, html) {
- if (typeof html === 'string') {
- html = this.compile(html);
- }
- Transit.cache.set('tpl', name, html);
- return this;
- };
-
- Template.prototype._pathify = function(path) {
- if (path.indexOf(setting('template_path')) !== -1) {
- return path;
+ Transit = {};
+
+ _.extend(Transit, {
+ cache: new Cache(),
+ on: Backbone.Events.on,
+ trigger: Backbone.Events.trigger,
+ off: Backbone.Events.off,
+ one: function(events, callback, context) {
+ var callone;
+ callone = function() {
+ var args;
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ callback.apply(null, args);
+ return Transit.off(events, callone, context);
+ };
+ return Transit.on(events, callone, context);
+ },
+ set: function() {
+ var args, _ref;
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ return (_ref = Transit.cache).set.apply(_ref, args);
+ },
+ get: function() {
+ var args, _ref;
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ return (_ref = Transit.cache).get.apply(_ref, args);
+ },
+ ready: function(callback) {
+ return Transit.one('ready', callback);
+ },
+ init: function(model) {
+ if (_ready === false) {
+ return Transit.one('ready', function() {
+ Transit.Manager.attach(model);
+ return Transit.trigger('init');
+ });
} else {
- return "" + (setting('template_path')) + "/" + (path.replace(/^\//, ''));
+ Transit.Manager.attach(model);
+ return Transit.trigger('init');
}
- };
-
- return Template;
-
- })();
-
- Transit = this.Transit = {};
-
- Transit.cache = new Cache();
-
- Transit.config = Settings;
-
- Transit.template = new Template();
-
- Transit.setup = function(options) {
- if (options == null) {
- options = {};
- }
- return Transit.settings = _.extend(Transit.settings, options);
- };
-
- Transit.on = Backbone.Events.on;
-
- Transit.trigger = Backbone.Events.trigger;
-
- Transit.off = Backbone.Events.off;
-
- Transit.one = function(events, callback, context) {
- var callone;
- callone = function() {
- var args;
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
- callback.apply(null, args);
- return Transit.off(events, callone, context);
- };
- return Transit.on(events, callone, context);
- };
-
- Transit.set = Transit.cache.set;
-
- Transit.get = Transit.cache.get;
-
- _ready = false;
-
- jQuery(window).one('load', function() {
- _ready = true;
- return Transit.trigger("ready");
+ },
+ version: "0.3.0"
});
- Transit.ready = function(callback) {
- return Transit.one('ready', callback);
- };
-
- Transit.init = function(model) {
- Transit.Manager.attach(model);
- return Transit.trigger('init');
- };
-
- Transit.version = "0.3.0";
-
- setting = function(name) {
- return Transit.config[name];
- };
-
- this.Transit;
-
-}).call(this);
-(function() {
- var Notify,
- __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
-
- Notify = (function() {
-
- Notify.prototype.template = function() {};
-
- function Notify() {
- this._setup = __bind(this._setup, this);
-
- this._render = __bind(this._render, this);
-
- this.success = __bind(this.success, this);
-
- this.info = __bind(this.info, this);
-
- this.error = __bind(this.error, this);
- Transit.one('ready', this._setup);
+ jQuery(window).one('load', function() {
+ var counter, total;
+ _winready = true;
+ if (_ready === true) {
+ Transit.trigger("ready");
+ return true;
}
-
- Notify.prototype.error = function(message) {
- return this._render(message, 'error');
- };
-
- Notify.prototype.info = function(message) {
- return this._render(message, 'info');
- };
-
- Notify.prototype.success = function(message) {
- return this._render(message, 'success');
- };
-
- Notify.prototype._render = function(message, type) {
- return Transit.Manager.append($(this.template({
- message: message,
- type: type
- })));
- };
-
- Notify.prototype._setup = function() {
- var _this = this;
- return Transit.template.load("/transit/views/core/notification.jst", function(templ) {
- return _this.template = templ;
+ counter = 0;
+ total = _.size(Transit.template.preloads);
+ return _.each(Transit.template.preloads, function(jst) {
+ return Transit.template.load(jst, function() {
+ counter++;
+ if (counter === total) {
+ _ready = true;
+ }
+ if (_winready === true && _ready === true) {
+ return Transit.trigger('ready');
+ }
});
- };
-
- return Notify;
-
- })();
-
- Transit.Notify = new Notify();
+ });
+ });
- if (typeof module !== "undefined" && module !== null) {
- module.exports = Transit.Notify;
- }
+ this.Transit || (this.Transit = Transit);
}).call(this);
(function() {
- var Uploader, XHRUploadSupport, fileApiSupport,
- __hasProp = {}.hasOwnProperty,
- __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; };
+ var Browser, agent;
- XHRUploadSupport = function() {
- var xhr;
- if (XMLHttpRequest === void 0) {
- return false;
- }
- xhr = new XMLHttpRequest();
- if (xhr['upload'] === void 0) {
- return false;
- }
- return xhr.upload['onprogress'] !== void 0;
- };
+ agent = navigator.userAgent;
- fileApiSupport = function() {
- var input;
- input = document.createElement('INPUT');
- input.type = 'file';
- return input['files'] !== void 0;
+ Browser = {
+ msie: agent.indexOf("MSIE") !== -1 && agent.indexOf("Opera") === -1,
+ gecko: agent.indexOf("Gecko") !== -1 && agent.indexOf("KHTML") === -1,
+ webkit: agent.indexOf("AppleWebKit/") !== -1,
+ chrome: agent.indexOf("Chrome/") !== -1,
+ opera: agent.indexOf("Opera/") !== -1,
+ ios: /ipad|iphone|ipod/i.test(agent),
+ android: /android (\d+)/i.test(agent)
};
- Uploader = (function(_super) {
-
- __extends(Uploader, _super);
-
- function Uploader() {
- return Uploader.__super__.constructor.apply(this, arguments);
- }
-
- Uploader.prototype.tagName = 'div';
-
- Uploader.prototype.className = 'transit-uploader';
-
- Uploader["native"] = XHRUploadSupport();
-
- return Uploader;
-
- })(Backbone.View);
-
- Transit.Uploader = Uploader;
+ Transit.browser = Browser;
if (typeof module !== "undefined" && module !== null) {
- module.exports = Transit.Uploader;
+ module.exports = Transit.browser;
}
}).call(this);
@@ -357,439 +227,398 @@
}).call(this);
(function() {
- var Browser, agent;
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
- agent = navigator.userAgent;
+ this.Transit.Template = (function() {
- Browser = {
- msie: agent.indexOf("MSIE") !== -1 && agent.indexOf("Opera") === -1,
- gecko: agent.indexOf("Gecko") !== -1 && agent.indexOf("KHTML") === -1,
- webkit: agent.indexOf("AppleWebKit/") !== -1,
- chrome: agent.indexOf("Chrome/") !== -1,
- opera: agent.indexOf("Opera/") !== -1,
- ios: /ipad|iphone|ipod/i.test(agent),
- android: /android (\d+)/i.test(agent)
- };
+ Template.cache = {};
- Transit.browser = Browser;
+ Template.compile = function(html) {
+ return _.template(html);
+ };
- if (typeof module !== "undefined" && module !== null) {
- module.exports = Transit.browser;
- }
+ Template.find = function(path) {
+ var found;
+ found = Template.cache[Template.pathify(path)];
+ if (found === void 0) {
+ return false;
+ } else {
+ return found;
+ }
+ };
-}).call(this);
+ Template.pathify = function(path) {
+ if (path.indexOf(this.url) !== -1) {
+ return path;
+ } else {
+ return "" + this.url + "/" + (path.replace(/^\//, ''));
+ }
+ };
-/*
+ Template.set = function(path, html) {
+ var func, template;
+ path = Template.pathify(path);
+ func = Template.compile(html);
+ template = new Transit.Template(path, html, func);
+ Template.cache[path] = template;
+ return template;
+ };
-Context base class, all content contexts should inherit
-this model. Creates a default _type value, as well as
-sensible defaults for all models to inherit.
-*/
+ Template.url = '/transit/views';
+
+ Template.prototype.path = '';
+
+ Template.prototype.source = "";
+
+ Template.prototype.func = null;
+
+ function Template(path, html, func) {
+ this.render = __bind(this.render, this);
+ this.path = path;
+ this.source = html;
+ this.func = func;
+ this;
+ }
+
+ Template.prototype.render = function(data) {
+ if (this.func === null) {
+ return this.source;
+ }
+ return this.func(data);
+ };
+
+ return Template;
+
+ }).call(this);
+
+ this.Transit.tpl = function(path, callback) {
+ var existing;
+ path = Transit.Template.pathify(path);
+ existing = Transit.Template.find(path);
+ if (existing === false) {
+ return $.get(path, function(data) {
+ var template;
+ template = Transit.Template.set(path, data);
+ return callback(template);
+ });
+ } else {
+ return callback(existing);
+ }
+ };
+}).call(this);
(function() {
- var Context,
+ var Manager,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__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; };
- Context = (function(_super) {
+ Manager = (function(_super) {
- __extends(Context, _super);
+ __extends(Manager, _super);
- function Context() {
- this._setType = __bind(this._setType, this);
+ function Manager() {
+ this._save = __bind(this._save, this);
- this._cleanup = __bind(this._cleanup, this);
- return Context.__super__.constructor.apply(this, arguments);
+ this.show = __bind(this.show, this);
+
+ this.render = __bind(this.render, this);
+
+ this.hide = __bind(this.hide, this);
+ return Manager.__super__.constructor.apply(this, arguments);
}
- Context.build_as = 'contexts_attributes';
+ Manager.prototype.tagName = 'div';
- Context.prototype.view = null;
+ Manager.prototype.className = 'transit-ui';
- Context.prototype.type = null;
+ Manager.prototype.events = {
+ 'click button.save': '_save'
+ };
- Context.prototype._pendingDestroy = false;
+ Manager.prototype.toolBar = null;
- Context.prototype.initialize = function() {
- var klass;
- this._setType();
- if (this.view === null) {
- klass = Transit.get('view', this.type);
- if (klass === null) {
- klass = Transit.get('view', 'Context');
- }
- if (this.isNew()) {
- this.view = new klass({
- model: this
- });
- } else {
- this.view = new klass({
- model: this,
- el: ".managed-context[data-context-id='\#\{@id\}']"
- });
+ Manager.prototype.initialize = function() {
+ return Transit.one('init', this.render);
+ };
+
+ Manager.prototype.append = function(node) {
+ return this.$el.append(node);
+ };
+
+ Manager.prototype.attach = function(model) {
+ this.model = model;
+ return this;
+ };
+
+ Manager.prototype.hide = function() {
+ this.$el.addClass('hidden');
+ $('html').addClass('transit-ui-hidden').removeClass('transit-ui-active');
+ Transit.trigger('ui:hide');
+ return this;
+ };
+
+ Manager.prototype.prepend = function(node) {
+ return this.$el.prepend(node);
+ };
+
+ Manager.prototype.render = function() {
+ if ($('#transit_ui').length === 0) {
+ Manager.__super__.render.apply(this, arguments);
+ $('html').addClass('transit-ui-hidden');
+ this.$el.addClass('hidden').attr('id', 'transit_ui').appendTo($('body'));
+ if (this.toolBar === null) {
+ this.toolBar = Transit.Toolbar = new Transit.Toolbar();
+ this.append(this.toolBar.$el);
}
}
- this.on('change', function(options) {
- var name, value, _ref;
- _ref = options.changes;
- for (name in _ref) {
- value = _ref[name];
- this.view.trigger("change:" + name);
- }
- return this.view.trigger('change');
- });
- this.on('destroy', this.cleanup);
- this.view.render();
return this;
};
- Context.prototype._cleanup = function() {
- this.view.remove();
- return delete this.view;
+ Manager.prototype.show = function() {
+ this.$el.removeClass('hidden');
+ $('html').removeClass('transit-ui-hidden').addClass('transit-ui-active');
+ Transit.trigger('ui:show');
+ return this;
};
- Context.prototype._setType = function() {
- if (this.type !== null) {
- return true;
+ Manager.prototype._save = function(event) {
+ if (event) {
+ event.preventDefault();
}
- if (!this.has('_type')) {
- this.set('_type', this.constructor.name);
+ if (!this.model) {
+ return false;
}
- return this.type = this.get('_type');
+ return this.model.save;
};
- return Context;
-
- })(Backbone.Model);
+ return Manager;
- Transit.Context = Context;
+ })(Backbone.View);
- if (typeof module !== "undefined" && module !== null) {
- module.exports = Transit.Context;
- }
+ this.Transit.Manager = new Manager();
}).call(this);
(function() {
- var $, Deliverable,
- __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__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; };
- $ = window.$ || Backbone.$;
+ this.Transit.Modal = (function(_super) {
- Deliverable = (function(_super) {
-
- __extends(Deliverable, _super);
+ __extends(Modal, _super);
- function Deliverable() {
- this._build_contexts = __bind(this._build_contexts, this);
+ function Modal() {
+ this.render = __bind(this.render, this);
- this.invalidate = __bind(this.invalidate, this);
- return Deliverable.__super__.constructor.apply(this, arguments);
+ this.perform = __bind(this.perform, this);
+ return Modal.__super__.constructor.apply(this, arguments);
}
- Deliverable.prototype.contexts = null;
-
- Deliverable.prototype.initialize = function() {
- this.contexts || (this.contexts = new Transit.Contexts());
- this.on('change:contexts', this._build_contexts);
- this._build_contexts();
- return this;
+ Modal.handler = function(instance) {
+ return $(instance.$el).modal({
+ show: true
+ }).one('hidden', function(event) {
+ Transit.trigger('modal:close', instance);
+ return instance.trigger('close');
+ });
};
- Deliverable.prototype.invalidate = function(model, xhr, options) {
- var attr, messages, response, _ref, _results;
- if (xhr && xhr.responseText) {
- response = $.parseJSON(xhr.responseText);
- if (response['errors']) {
- _ref = response.errors;
- _results = [];
- for (attr in _ref) {
- messages = _ref[attr];
- _results.push(model.trigger("error:" + attr, messages));
- }
- return _results;
- }
- }
+ Modal.prototype.tagName = 'div';
+
+ Modal.prototype.className = 'transit-modal';
+
+ Modal.prototype.events = {
+ 'click a[data-action]': 'perform'
};
- Deliverable.prototype.toJSON = function() {
- var data, result;
- data = {};
- this.contexts.each(function(con, index) {
- return data[index.toString()] = con.toJSON();
+ Modal.prototype.initialize = function() {
+ Modal.__super__.initialize.apply(this, arguments);
+ this.on('close', this.remove, this);
+ return this.options = _.defaults(this.options, {
+ buttons: [],
+ title: "Title Missing",
+ content: "Content missing"
});
- result = {};
- result["" + Transit.Contexts.build_as] = data;
- return {
- page: _.extend(Deliverable.__super__.toJSON.apply(this, arguments), result)
- };
};
- Deliverable.prototype._build_contexts = function() {
- var contexts;
- contexts = this.attributes.contexts || [];
- this.contexts.reset(contexts);
- delete this.attributes['contexts'];
- return this;
+ Modal.prototype.perform = function(event) {
+ var link;
+ event.preventDefault();
+ link = $(event.currentTarget);
+ return Transit.trigger('modal:action', link.attr('data-action'), this);
};
- return Deliverable;
-
- })(Backbone.Model);
-
- Transit.Deliverable = Deliverable;
-
- if (typeof module !== "undefined" && module !== null) {
- module.exports = Transit.Deliverable;
- }
+ Modal.prototype.remove = function() {
+ this.off();
+ this.trigger('remove');
+ return Modal.__super__.remove.apply(this, arguments);
+ };
-}).call(this);
-(function() {
- var Contexts,
- __hasProp = {}.hasOwnProperty,
- __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; };
+ Modal.prototype.render = function() {
+ var _this = this;
+ Transit.tpl("/core/modal.jst", function(template) {
+ var el;
+ el = $(template.render(_this.options)).attr('id', "transit_modal_" + _this.cid);
+ _this.setElement(el);
+ _this.trigger('open');
+ Transit.trigger('modal:show', _this);
+ _this.$el.addClass('out');
+ Transit.Manager.append(_this.$el);
+ Transit.Modal.handler(_this);
+ return _this.$el.removeClass('out').addClass('in');
+ });
+ return this;
+ };
- Contexts = (function(_super) {
+ return Modal;
- __extends(Contexts, _super);
+ })(Backbone.View);
- function Contexts() {
- return Contexts.__super__.constructor.apply(this, arguments);
+ this.Transit.modal = function(options) {
+ var view;
+ if (options == null) {
+ options = {};
}
-
- Contexts.build_as = 'contexts_attributes';
-
- Contexts.prototype._deliverable = null;
-
- Contexts.prototype.model = function(data) {
- var klass;
- klass = Transit.get('context', data['_type']);
- if (klass !== null) {
- return new klass(data);
- } else {
- return new Transit.Context(data);
+ view = new Transit.Modal(options);
+ Transit.one('modal:show', function(mod) {
+ if (mod !== view) {
+ return false;
}
- };
-
- return Contexts;
-
- })(Backbone.Collection);
-
- Transit.Contexts = Contexts;
-
- if (typeof module !== "undefined" && module !== null) {
- module.exports = Transit.Contexts;
- }
+ });
+ return view.render();
+ };
}).call(this);
+(function() {
+ var Notify,
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
-/*
+ Notify = (function() {
-All deliverables can contain one or more assets.
-*/
+ Notify.prototype.template = function() {};
+ function Notify() {
+ this._setup = __bind(this._setup, this);
-(function() {
- var Asset, Assets,
- __hasProp = {}.hasOwnProperty,
- __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; };
+ this._render = __bind(this._render, this);
- Asset = (function(_super) {
+ this.success = __bind(this.success, this);
- __extends(Asset, _super);
+ this.info = __bind(this.info, this);
- function Asset() {
- return Asset.__super__.constructor.apply(this, arguments);
+ this.error = __bind(this.error, this);
+ Transit.one('ready', this._setup);
}
- Asset.prototype.defaults = {
- deliverable_id: null,
- deliverable_type: null,
- urls: [],
- url: null,
- image: true,
- filename: null
+ Notify.prototype.error = function(message) {
+ return this._render(message, 'error');
};
- Asset.prototype.isImage = function() {
- return this.get('image');
+ Notify.prototype.info = function(message) {
+ return this._render(message, 'info');
};
- return Asset;
-
- })(Backbone.Model);
-
- Assets = (function(_super) {
-
- __extends(Assets, _super);
-
- function Assets() {
- return Assets.__super__.constructor.apply(this, arguments);
- }
-
- Assets.prototype.model = Asset;
-
- Assets.prototype.url = function() {
- return Transit.settings.asset_path;
+ Notify.prototype.success = function(message) {
+ return this._render(message, 'success');
};
- Assets.prototype.fetch = function(options) {
- if (options == null) {
- options = {};
- }
- options.data = this.deliverable;
- return Backbone.Collection.prototype.fetch.apply(this, [options]);
+ Notify.prototype._render = function(message, type) {
+ return Transit.Manager.append($(this.template({
+ message: message,
+ type: type
+ })));
};
- return Assets;
+ Notify.prototype._setup = function() {
+ var _this = this;
+ return Transit.tpl("/core/notification.jst", function(templ) {
+ return _this.template = templ;
+ });
+ };
- })(Backbone.Collection);
+ return Notify;
- Transit.Asset = Asset;
+ })();
- Transit.Assets = Assets;
+ Transit.Notify = new Notify();
if (typeof module !== "undefined" && module !== null) {
- module.exports = {
- Asset: Asset,
- Assets: Assets
- };
+ module.exports = Transit.Notify;
}
}).call(this);
-
-/*
-
-Context view class.
-*/
-
-
(function() {
- var Context,
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__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; };
- Context = (function(_super) {
-
- __extends(Context, _super);
+ this.Transit.Panel = (function(_super) {
- function Context() {
- return Context.__super__.constructor.apply(this, arguments);
- }
-
- return Context;
-
- })(Backbone.View);
-
- Transit.set('view', 'Context', Context);
-
-}).call(this);
-
-/*
-
-The manager contains the global "shell" that contains
-all additional ui elements
-*/
-
-
-(function() {
- var Manager,
- __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
- __hasProp = {}.hasOwnProperty,
- __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; };
-
- Manager = (function(_super) {
-
- __extends(Manager, _super);
-
- function Manager() {
- this._save = __bind(this._save, this);
-
- this.show = __bind(this.show, this);
-
- this.render = __bind(this.render, this);
+ __extends(Panel, _super);
- this.hide = __bind(this.hide, this);
- return Manager.__super__.constructor.apply(this, arguments);
- }
+ Panel.prototype.tagName = 'div';
- Manager.prototype.tagName = 'div';
+ Panel.prototype.className = 'transit-panel';
- Manager.prototype.className = 'transit-ui';
+ Panel.prototype.title = 'Detail';
- Manager.prototype.events = {
- 'click button.save': '_save'
- };
+ Panel.prototype.icon = '';
- Manager.prototype.toolBar = null;
+ Panel.prototype.active = false;
- Manager.prototype.initialize = function() {
- return Transit.one('init', this.render);
- };
+ function Panel() {
+ this.remove = __bind(this.remove, this);
- Manager.prototype.append = function(node) {
- return this.$el.append(node);
- };
+ this.render = __bind(this.render, this);
- Manager.prototype.attach = function(model) {
- this.model = model;
- return this;
- };
+ this.deactivate = __bind(this.deactivate, this);
- Manager.prototype.hide = function() {
- this.$el.addClass('hidden');
- $('html').addClass('transit-ui-hidden').removeClass('transit-ui-active');
- Transit.trigger('ui:hide');
- return this;
- };
+ this.activate = __bind(this.activate, this);
- Manager.prototype.prepend = function(node) {
- return this.$el.prepend(node);
- };
+ this.initialize = __bind(this.initialize, this);
- Manager.prototype.render = function() {
- if ($('#transit_ui').length === 0) {
- Manager.__super__.render.apply(this, arguments);
- $('html').addClass('transit-ui-hidden');
- this.$el.addClass('hidden').attr('id', 'transit_ui').appendTo($('body'));
- if (this.toolBar === null) {
- this.toolBar = Transit.Toolbar = new Transit.Toolbar();
- this.append(this.toolBar.$el);
+ var prop, _i, _len, _ref;
+ Panel.__super__.constructor.apply(this, arguments);
+ _ref = ['title', 'icon'];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ prop = _ref[_i];
+ if (this.options[prop] !== void 0) {
+ this[prop] = this.options[prop];
}
}
- return this;
+ if (this.$el.attr('id') === void 0) {
+ this.$el.attr("id", "transit_panel_" + this.cid);
+ }
+ }
+
+ Panel.prototype.initialize = function() {};
+
+ Panel.prototype.activate = function() {
+ this.active = true;
+ return this.$el.addClass('active');
};
- Manager.prototype.show = function() {
- this.$el.removeClass('hidden');
- $('html').removeClass('transit-ui-hidden').addClass('transit-ui-active');
- Transit.trigger('ui:show');
+ Panel.prototype.deactivate = function() {
+ this.active = false;
+ return this.$el.removeClass('active');
+ };
+
+ Panel.prototype.render = function() {
+ Panel.__super__.render.apply(this, arguments);
return this;
};
- Manager.prototype._save = function(event) {
- if (event) {
- event.preventDefault();
- }
- if (!this.model) {
- return false;
- }
- return this.model.save;
+ Panel.prototype.remove = function() {
+ Panel.__super__.remove.apply(this, arguments);
+ return this.trigger('remove', this);
};
- return Manager;
+ return Panel;
})(Backbone.View);
- Transit.Manager = new Manager();
-
- if (typeof module !== "undefined" && module !== null) {
- module.exports = Transit.Manager;
- }
-
}).call(this);
/*
@@ -801,13 +630,13 @@ functionality of the manager.
(function() {
- var TabBar, Toolbar,
+ var TabBar,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__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; },
__slice = [].slice;
- Toolbar = (function(_super) {
+ this.Transit.Toolbar = (function(_super) {
__extends(Toolbar, _super);
@@ -937,10 +766,10 @@ functionality of the manager.
var _this = this;
this.tabs = {};
- Transit.template.load('/transit/views/core/tab-bar.jst', function(templ) {
+ Transit.tpl('/transit/views/core/nav-bar.jst', function(templ) {
var id, tab, _ref, _results;
- _this.el = $(templ());
- _this.list = _this.el.find('ul.transit-tab-bar');
+ _this.el = $(templ.render());
+ _this.list = _this.el.find('ul.transit-nav-bar');
_ref = _this.tabs;
_results = [];
for (id in _ref) {
@@ -1002,122 +831,359 @@ functionality of the manager.
link.attr(option, value);
}
}
- if (panel.$el.attr("id") === void 0) {
- panel.$el.attr('id', "#transit_panel_" + cid);
- }
- link.attr({
- href: panel.$el.attr('id'),
- "data-toggle": 'tab'
- }).text(text);
- item.append(link).attr({
- id: "#transit_panel_tab_" + id
+ if (panel.$el.attr("id") === void 0) {
+ panel.$el.attr('id', "#transit_panel_" + cid);
+ }
+ link.attr({
+ href: panel.$el.attr('id'),
+ "data-toggle": 'tab'
+ }).text(text);
+ item.append(link).attr({
+ id: "#transit_panel_tab_" + id
+ });
+ this.tabs[id] = item;
+ return item;
+ };
+
+ TabBar.prototype.prepend = function(panel) {
+ return this.list.prepend(this.make(panel));
+ };
+
+ TabBar.prototype.remove = function(id) {
+ return this.find(id).remove();
+ };
+
+ return TabBar;
+
+ })();
+
+}).call(this);
+(function() {
+ var XHRUploadSupport, fileApiSupport,
+ __hasProp = {}.hasOwnProperty,
+ __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; };
+
+ XHRUploadSupport = function() {
+ var xhr;
+ if (XMLHttpRequest === void 0) {
+ return false;
+ }
+ xhr = new XMLHttpRequest();
+ if (xhr['upload'] === void 0) {
+ return false;
+ }
+ return xhr.upload['onprogress'] !== void 0;
+ };
+
+ fileApiSupport = function() {
+ var input;
+ input = document.createElement('INPUT');
+ input.type = 'file';
+ return input['files'] !== void 0;
+ };
+
+ this.Transit.Uploader = (function(_super) {
+
+ __extends(Uploader, _super);
+
+ function Uploader() {
+ return Uploader.__super__.constructor.apply(this, arguments);
+ }
+
+ Uploader.prototype.tagName = 'div';
+
+ Uploader.prototype.className = 'transit-uploader';
+
+ Uploader["native"] = XHRUploadSupport();
+
+ return Uploader;
+
+ })(Backbone.View);
+
+}).call(this);
+(function() {
+ var __hasProp = {}.hasOwnProperty,
+ __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; };
+
+ this.Transit.Asset = (function(_super) {
+
+ __extends(Asset, _super);
+
+ function Asset() {
+ return Asset.__super__.constructor.apply(this, arguments);
+ }
+
+ Asset.prototype.defaults = {
+ deliverable_id: null,
+ deliverable_type: null,
+ urls: [],
+ url: null,
+ image: true,
+ filename: null
+ };
+
+ Asset.prototype.isImage = function() {
+ return this.get('image');
+ };
+
+ return Asset;
+
+ })(Backbone.Model);
+
+}).call(this);
+(function() {
+ var __hasProp = {}.hasOwnProperty,
+ __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; };
+
+ this.Transit.Assets = (function(_super) {
+
+ __extends(Assets, _super);
+
+ function Assets() {
+ return Assets.__super__.constructor.apply(this, arguments);
+ }
+
+ Assets.prototype.model = function() {
+ return Transit.Asset;
+ };
+
+ Assets.prototype.url = function() {
+ return Transit.settings.asset_path;
+ };
+
+ Assets.prototype.fetch = function(options) {
+ if (options == null) {
+ options = {};
+ }
+ options.data = this.deliverable;
+ return Backbone.Collection.prototype.fetch.apply(this, [options]);
+ };
+
+ return Assets;
+
+ })(Backbone.Collection);
+
+}).call(this);
+
+/*
+
+Context base class, all content contexts should inherit
+this model. Creates a default _type value, as well as
+sensible defaults for all models to inherit.
+*/
+
+
+(function() {
+ var Context,
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
+ __hasProp = {}.hasOwnProperty,
+ __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; };
+
+ Context = (function(_super) {
+
+ __extends(Context, _super);
+
+ function Context() {
+ this._setType = __bind(this._setType, this);
+
+ this._cleanup = __bind(this._cleanup, this);
+ return Context.__super__.constructor.apply(this, arguments);
+ }
+
+ Context.build_as = 'contexts_attributes';
+
+ Context.prototype.view = null;
+
+ Context.prototype.type = null;
+
+ Context.prototype._pendingDestroy = false;
+
+ Context.prototype.initialize = function() {
+ var klass;
+ this._setType();
+ if (this.view === null) {
+ klass = Transit.get('view', this.type);
+ if (klass === null) {
+ klass = Transit.get('view', 'Context');
+ }
+ if (this.isNew()) {
+ this.view = new klass({
+ model: this
+ });
+ } else {
+ this.view = new klass({
+ model: this,
+ el: ".managed-context[data-context-id='\#\{@id\}']"
+ });
+ }
+ }
+ this.on('change', function(options) {
+ var name, value, _ref;
+ _ref = options.changes;
+ for (name in _ref) {
+ value = _ref[name];
+ this.view.trigger("change:" + name);
+ }
+ return this.view.trigger('change');
});
- this.tabs[id] = item;
- return item;
+ this.on('destroy', this.cleanup);
+ this.view.render();
+ return this;
};
- TabBar.prototype.prepend = function(panel) {
- return this.list.prepend(this.make(panel));
+ Context.prototype._cleanup = function() {
+ this.view.remove();
+ return delete this.view;
};
- TabBar.prototype.remove = function(id) {
- return this.find(id).remove();
+ Context.prototype._setType = function() {
+ if (this.type !== null) {
+ return true;
+ }
+ if (!this.has('_type')) {
+ this.set('_type', this.constructor.name);
+ }
+ return this.type = this.get('_type');
};
- return TabBar;
+ return Context;
- })();
+ })(Backbone.Model);
- Transit.Toolbar = Toolbar;
+ Transit.Context = Context;
if (typeof module !== "undefined" && module !== null) {
- module.exports = Transit.Toolbar;
+ module.exports = Transit.Context;
}
}).call(this);
(function() {
- var Panel,
- __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
+ var Contexts,
__hasProp = {}.hasOwnProperty,
__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; };
- Panel = (function(_super) {
+ Contexts = (function(_super) {
- __extends(Panel, _super);
+ __extends(Contexts, _super);
- Panel.prototype.tagName = 'div';
+ function Contexts() {
+ return Contexts.__super__.constructor.apply(this, arguments);
+ }
- Panel.prototype.className = 'transit-panel';
+ Contexts.build_as = 'contexts_attributes';
- Panel.prototype.title = 'Detail';
+ Contexts.prototype._deliverable = null;
- Panel.prototype.icon = '';
+ Contexts.prototype.model = function(data) {
+ var klass;
+ klass = Transit.get('context', data['_type']);
+ if (klass !== null) {
+ return new klass(data);
+ } else {
+ return new Transit.Context(data);
+ }
+ };
- Panel.prototype.active = false;
+ return Contexts;
- function Panel() {
- this.remove = __bind(this.remove, this);
+ })(Backbone.Collection);
- this.deactivate = __bind(this.deactivate, this);
+ Transit.Contexts = Contexts;
- this.activate = __bind(this.activate, this);
+ if (typeof module !== "undefined" && module !== null) {
+ module.exports = Transit.Contexts;
+ }
- this.initialize = __bind(this.initialize, this);
+}).call(this);
+(function() {
+ var $, Deliverable,
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
+ __hasProp = {}.hasOwnProperty,
+ __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; };
- var prop, _i, _len, _ref;
- Panel.__super__.constructor.apply(this, arguments);
- _ref = ['title', 'icon'];
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- prop = _ref[_i];
- if (this.options[prop] !== void 0) {
- this[prop] = this.options[prop];
- }
- }
- if (this.$el.attr('id') === void 0) {
- this.$el.attr("id", "transit_panel_" + this.cid);
- }
+ $ = window.$ || Backbone.$;
+
+ Deliverable = (function(_super) {
+
+ __extends(Deliverable, _super);
+
+ function Deliverable() {
+ this._build_contexts = __bind(this._build_contexts, this);
+
+ this.invalidate = __bind(this.invalidate, this);
+ return Deliverable.__super__.constructor.apply(this, arguments);
}
- Panel.prototype.initialize = function() {};
+ Deliverable.prototype.contexts = null;
- Panel.prototype.activate = function() {
- this.active = true;
- return this.$el.addClass('active');
+ Deliverable.prototype.initialize = function() {
+ this.contexts || (this.contexts = new Transit.Contexts());
+ this.on('change:contexts', this._build_contexts);
+ this._build_contexts();
+ return this;
};
- Panel.prototype.deactivate = function() {
- this.active = false;
- return this.$el.removeClass('active');
+ Deliverable.prototype.invalidate = function(model, xhr, options) {
+ var attr, messages, response, _ref, _results;
+ if (xhr && xhr.responseText) {
+ response = $.parseJSON(xhr.responseText);
+ if (response['errors']) {
+ _ref = response.errors;
+ _results = [];
+ for (attr in _ref) {
+ messages = _ref[attr];
+ _results.push(model.trigger("error:" + attr, messages));
+ }
+ return _results;
+ }
+ }
};
- Panel.prototype.remove = function() {
- Panel.__super__.remove.apply(this, arguments);
- return this.trigger('remove', this);
+ Deliverable.prototype.toJSON = function() {
+ var data, result;
+ data = {};
+ this.contexts.each(function(con, index) {
+ return data[index.toString()] = con.toJSON();
+ });
+ result = {};
+ result["" + Transit.Contexts.build_as] = data;
+ return {
+ page: _.extend(Deliverable.__super__.toJSON.apply(this, arguments), result)
+ };
};
- return Panel;
+ Deliverable.prototype._build_contexts = function() {
+ var contexts;
+ contexts = this.attributes.contexts || [];
+ this.contexts.reset(contexts);
+ delete this.attributes['contexts'];
+ return this;
+ };
- })(Backbone.View);
+ return Deliverable;
- Transit.Panel = Panel;
+ })(Backbone.Model);
+
+ Transit.Deliverable = Deliverable;
if (typeof module !== "undefined" && module !== null) {
- module.exports = Transit.Panel;
+ module.exports = Transit.Deliverable;
}
}).call(this);
(function() {
- var AssetManager,
- __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__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; };
- AssetManager = (function(_super) {
+ this.Transit.AssetManager = (function(_super) {
__extends(AssetManager, _super);
function AssetManager() {
this.render = __bind(this.render, this);
+
+ this.add = __bind(this.add, this);
return AssetManager.__super__.constructor.apply(this, arguments);
}
@@ -1125,23 +1191,159 @@ functionality of the manager.
AssetManager.prototype.collection = null;
+ AssetManager.prototype.images = null;
+
+ AssetManager.prototype.files = null;
+
+ AssetManager.prototype.title = 'Assets';
+
+ AssetManager.prototype.attach = function(model) {
+ this.model = model;
+ if (this.model.assets === void 0) {
+ return this.model.assets = new Transit.Assets();
+ }
+ };
+
+ AssetManager.prototype.add = function(asset) {
+ if (asset.isImage()) {
+ return this.images.add(asset);
+ } else {
+ return this.files.add(asset);
+ }
+ };
+
AssetManager.prototype.render = function() {
AssetManager.__super__.render.apply(this, arguments);
this.$el.addClass('transit-asset-manager');
if (this.uploader === null) {
this.uploader = new Transit.Uploader();
- return this.$el.prepend(this.uploader.render().$el);
+ this.$el.prepend(this.uploader.render().$el);
+ }
+ if (this.files === null) {
+ this.files = new Transit.AssetManager.List({
+ "class": 'files'
+ });
}
+ if (this.images === null) {
+ this.images = new Transit.AssetManager.List({
+ "class": 'images'
+ });
+ }
+ this.$el.append(this.images.render().$el);
+ this.$el.append(this.files.render().$el);
+ return this;
};
return AssetManager;
})(Transit.Panel);
- Transit.AssetManager = AssetManager;
+ this.Transit.AssetManager.List = (function(_super) {
- if (typeof module !== "undefined" && module !== null) {
- module.exports = Transit.AssetManager;
- }
+ __extends(List, _super);
+
+ function List() {
+ this.add = __bind(this.add, this);
+ return List.__super__.constructor.apply(this, arguments);
+ }
+
+ List.prototype.tagName = 'ul';
+
+ List.prototype.initialize = function() {
+ List.__super__.initialize.apply(this, arguments);
+ if (this.options['class']) {
+ return this.$el.addClass(this.options['class']);
+ }
+ };
+
+ List.prototype.add = function(asset) {
+ var item;
+ item = new Transit.AssetManager.Item({
+ model: asset
+ });
+ return this.$el.append(item.render.$el());
+ };
+
+ return List;
+
+ })(Backbone.View);
+
+ this.Transit.AssetManager.Item = (function(_super) {
+
+ __extends(Item, _super);
+
+ function Item() {
+ this.remove = __bind(this.remove, this);
+
+ this.render = __bind(this.render, this);
+ return Item.__super__.constructor.apply(this, arguments);
+ }
+
+ Item.prototype.events = {
+ 'click a[data-action="remove"]': 'remove'
+ };
+
+ Item.prototype.tagName = 'li';
+
+ Item.prototype.type = null;
+
+ Item.prototype.template = null;
+
+ Item.prototype.initialize = function() {
+ var _this = this;
+ this.type = this.model.isImage() ? 'image' : 'file';
+ this.$el.addClass(this.type);
+ return Transit.tpl("/core/assets/" + this.type + ".jst", function(templ) {
+ _this.template = templ;
+ return _this.render();
+ });
+ };
+
+ Item.prototype.render = function() {
+ return this.$el.html(this.template({
+ asset: this.model
+ }));
+ };
+
+ Item.prototype.remove = function() {
+ if (confirm("Are you sure you want to delete this " + this.type + "?")) {
+ this.model.destroy();
+ Transit.trigger('asset:removed', this.model);
+ return Item.__super__.remove.apply(this, arguments);
+ } else {
+ return false;
+ }
+ };
+
+ return Item;
+
+ })(Backbone.View);
+
+}).call(this);
+
+/*
+
+Context view class.
+*/
+
+
+(function() {
+ var Context,
+ __hasProp = {}.hasOwnProperty,
+ __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; };
+
+ Context = (function(_super) {
+
+ __extends(Context, _super);
+
+ function Context() {
+ return Context.__super__.constructor.apply(this, arguments);
+ }
+
+ return Context;
+
+ })(Backbone.View);
+
+ Transit.set('view', 'Context', Context);
}).call(this);
View
2  build/transit.min.js
@@ -1 +1 @@
-(function(){var e,t,n,r,i,s,o=function(e,t){return function(){return e.apply(t,arguments)}},u=[].slice;e=function(){function e(){this.drop=o(this.drop,this),this.set=o(this.set,this),this.get=o(this.get,this)}return e.prototype.view={},e.prototype.context={},e.prototype.tpl={},e.prototype.get=function(e,t){var n;return e=e.toLowerCase(),t=t.toLowerCase(),n=this[e][t],n===void 0?null:n},e.prototype.set=function(e,t,n){return e=e.toLowerCase(),t=t.toLowerCase(),this[e][t]=n},e.prototype.drop=function(e,t){return delete this[e][t],this},e}(),t={template_path:"/transit/views",asset_path:"/transit/assets"},n=function(){function e(){this._pathify=o(this._pathify,this),this.set=o(this.set,this),this.load=o(this.load,this),this.compile=o(this.compile,this)}return e.prototype.compile=function(e){return _.template(e)},e.prototype.load=function(e,t){var n,i=this;return n=r.cache.get("tpl",e),n!==void 0?t(n):$.get(this._pathify(e),function(n){var s;return s=i.compile(n),r.cache.set("tpl",e,s),t(s)})},e.prototype.set=function(e,t){return typeof t=="string"&&(t=this.compile(t)),r.cache.set("tpl",e,t),this},e.prototype._pathify=function(e){return e.indexOf(i("template_path"))!==-1?e:""+i("template_path")+"/"+e.replace(/^\//,"")},e}(),r=this.Transit={},r.cache=new e,r.config=t,r.template=new n,r.setup=function(e){return e==null&&(e={}),r.settings=_.extend(r.settings,e)},r.on=Backbone.Events.on,r.trigger=Backbone.Events.trigger,r.off=Backbone.Events.off,r.one=function(e,t,n){var i;return i=function(){var s;return s=1<=arguments.length?u.call(arguments,0):[],t.apply(null,s),r.off(e,i,n)},r.on(e,i,n)},r.set=r.cache.set,r.get=r.cache.get,s=!1,jQuery(window).one("load",function(){return s=!0,r.trigger("ready")}),r.ready=function(e){return r.one("ready",e)},r.init=function(e){return r.Manager.attach(e),r.trigger("init")},r.version="0.3.0",i=function(e){return r.config[e]},this.Transit}).call(this),function(){var e,t=function(e,t){return function(){return e.apply(t,arguments)}};e=function(){function e(){this._setup=t(this._setup,this),this._render=t(this._render,this),this.success=t(this.success,this),this.info=t(this.info,this),this.error=t(this.error,this),Transit.one("ready",this._setup)}return e.prototype.template=function(){},e.prototype.error=function(e){return this._render(e,"error")},e.prototype.info=function(e){return this._render(e,"info")},e.prototype.success=function(e){return this._render(e,"success")},e.prototype._render=function(e,t){return Transit.Manager.append($(this.template({message:e,type:t})))},e.prototype._setup=function(){var e=this;return Transit.template.load("/transit/views/core/notification.jst",function(t){return e.template=t})},e}(),Transit.Notify=new e,typeof module!="undefined"&&module!==null&&(module.exports=Transit.Notify)}.call(this),function(){var e,t,n,r={}.hasOwnProperty,i=function(e,t){function i(){this.constructor=e}for(var n in t)r.call(t,n)&&(e[n]=t[n]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e};t=function(){var e;return XMLHttpRequest===void 0?!1:(e=new XMLHttpRequest,e.upload===void 0?!1:e.upload.onprogress!==void 0)},n=function(){var e;return e=document.createElement("INPUT"),e.type="file",e.files!==void 0},e=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return i(n,e),n.prototype.tagName="div",n.prototype.className="transit-uploader",n["native"]=t(),n}(Backbone.View),Transit.Uploader=e,typeof module!="undefined"&&module!==null&&(module.exports=Transit.Uploader)}.call(this),function(){var e;e=function(){function e(){_.bindAll(this)}return e.selection=null,e.prototype.cursor=function(){var e,t,n,r;return r=this.get(),r===null?null:(e=$("<span/>"),t=document.createRange(),t.setStart(r.endContainer,r.endOffset),t.insertNode(e.get(0)),n=e.offset(),e.remove(),n)},e.prototype.get=function(){var e,t;return t=null,window.getSelection?(e=window.getSelection(),t=e.rangeCount>0?e.getRangeAt(0):null):document.selection&&document.selection.createRange&&(t=document.selection.createRange()),t},e.prototype.restore=function(e){var t;return e==null&&(e=null),e===null&&(e=this.selection),e===null?!0:(window.getSelection?(t=window.getSelection(),t.removeAllRanges(),t.addRange(e)):document.selection&&e.select&&e.select(),this.selection=null,this)},e.prototype.save=function(){return this.selection=this.get(),this.selection},e}(),Transit.Selection=new e,typeof module!="undefined"&&module!==null&&(module.exports=Transit.Selection)}.call(this),function(){var e,t;t=navigator.userAgent,e={msie:t.indexOf("MSIE")!==-1&&t.indexOf("Opera")===-1,gecko:t.indexOf("Gecko")!==-1&&t.indexOf("KHTML")===-1,webkit:t.indexOf("AppleWebKit/")!==-1,chrome:t.indexOf("Chrome/")!==-1,opera:t.indexOf("Opera/")!==-1,ios:/ipad|iphone|ipod/i.test(t),android:/android (\d+)/i.test(t)},Transit.browser=e,typeof module!="undefined"&&module!==null&&(module.exports=Transit.browser)}.call(this),function(){var e,t=function(e,t){return function(){return e.apply(t,arguments)}},n={}.hasOwnProperty,r=function(e,t){function i(){this.constructor=e}for(var r in t)n.call(t,r)&&(e[r]=t[r]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e};e=function(e){function n(){return this._setType=t(this._setType,this),this._cleanup=t(this._cleanup,this),n.__super__.constructor.apply(this,arguments)}return r(n,e),n.build_as="contexts_attributes",n.prototype.view=null,n.prototype.type=null,n.prototype._pendingDestroy=!1,n.prototype.initialize=function(){var e;return this._setType(),this.view===null&&(e=Transit.get("view",this.type),e===null&&(e=Transit.get("view","Context")),this.isNew()?this.view=new e({model:this}):this.view=new e({model:this,el:".managed-context[data-context-id='#{@id}']"})),this.on("change",function(e){var t,n,r;r=e.changes;for(t in r)n=r[t],this.view.trigger("change:"+t);return this.view.trigger("change")}),this.on("destroy",this.cleanup),this.view.render(),this},n.prototype._cleanup=function(){return this.view.remove(),delete this.view},n.prototype._setType=function(){return this.type!==null?!0:(this.has("_type")||this.set("_type",this.constructor.name),this.type=this.get("_type"))},n}(Backbone.Model),Transit.Context=e,typeof module!="undefined"&&module!==null&&(module.exports=Transit.Context)}.call(this),function(){var e,t,n=function(e,t){return function(){return e.apply(t,arguments)}},r={}.hasOwnProperty,i=function(e,t){function i(){this.constructor=e}for(var n in t)r.call(t,n)&&(e[n]=t[n]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e};e=window.$||Backbone.$,t=function(t){function r(){return this._build_contexts=n(this._build_contexts,this),this.invalidate=n(this.invalidate,this),r.__super__.constructor.apply(this,arguments)}return i(r,t),r.prototype.contexts=null,r.prototype.initialize=function(){return this.contexts||(this.contexts=new Transit.Contexts),this.on("change:contexts",this._build_contexts),this._build_contexts(),this},r.prototype.invalidate=function(t,n,r){var i,s,o,u,a;if(n&&n.responseText){o=e.parseJSON(n.responseText);if(o.errors){u=o.errors,a=[];for(i in u)s=u[i],a.push(t.trigger("error:"+i,s));return a}}},r.prototype.toJSON=function(){var e,t;return e={},this.contexts.each(function(t,n){return e[n.toString()]=t.toJSON()}),t={},t[""+Transit.Contexts.build_as]=e,{page:_.extend(r.__super__.toJSON.apply(this,arguments),t)}},r.prototype._build_contexts=function(){var e;return e=this.attributes.contexts||[],this.contexts.reset(e),delete this.attributes.contexts,this},r}(Backbone.Model),Transit.Deliverable=t,typeof module!="undefined"&&module!==null&&(module.exports=Transit.Deliverable)}.call(this),function(){var e,t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};e=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return n(t,e),t.build_as="contexts_attributes",t.prototype._deliverable=null,t.prototype.model=function(e){var t;return t=Transit.get("context",e._type),t!==null?new t(e):new Transit.Context(e)},t}(Backbone.Collection),Transit.Contexts=e,typeof module!="undefined"&&module!==null&&(module.exports=Transit.Contexts)}.call(this),function(){var e,t,n={}.hasOwnProperty,r=function(e,t){function i(){this.constructor=e}for(var r in t)n.call(t,r)&&(e[r]=t[r]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e};e=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return r(t,e),t.prototype.defaults={deliverable_id:null,deliverable_type:null,urls:[],url:null,image:!0,filename:null},t.prototype.isImage=function(){return this.get("image")},t}(Backbone.Model),t=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return r(n,t),n.prototype.model=e,n.prototype.url=function(){return Transit.settings.asset_path},n.prototype.fetch=function(e){return e==null&&(e={}),e.data=this.deliverable,Backbone.Collection.prototype.fetch.apply(this,[e])},n}(Backbone.Collection),Transit.Asset=e,Transit.Assets=t,typeof module!="undefined"&&module!==null&&(module.exports={Asset:e,Assets:t})}.call(this),function(){var e,t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};e=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return n(t,e),t}(Backbone.View),Transit.set("view","Context",e)}.call(this),function(){var e,t=function(e,t){return function(){return e.apply(t,arguments)}},n={}.hasOwnProperty,r=function(e,t){function i(){this.constructor=e}for(var r in t)n.call(t,r)&&(e[r]=t[r]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e};e=function(e){function n(){return this._save=t(this._save,this),this.show=t(this.show,this),this.render=t(this.render,this),this.hide=t(this.hide,this),n.__super__.constructor.apply(this,arguments)}return r(n,e),n.prototype.tagName="div",n.prototype.className="transit-ui",n.prototype.events={"click button.save":"_save"},n.prototype.toolBar=null,n.prototype.initialize=function(){return Transit.one("init",this.render)},n.prototype.append=function(e){return this.$el.append(e)},n.prototype.attach=function(e){return this.model=e,this},n.prototype.hide=function(){return this.$el.addClass("hidden"),$("html").addClass("transit-ui-hidden").removeClass("transit-ui-active"),Transit.trigger("ui:hide"),this},n.prototype.prepend=function(e){return this.$el.prepend(e)},n.prototype.render=function(){return $("#transit_ui").length===0&&(n.__super__.render.apply(this,arguments),$("html").addClass("transit-ui-hidden"),this.$el.addClass("hidden").attr("id","transit_ui").appendTo($("body")),this.toolBar===null&&(this.toolBar=Transit.Toolbar=new Transit.Toolbar,this.append(this.toolBar.$el))),this},n.prototype.show=function(){return this.$el.removeClass("hidden"),$("html").removeClass("transit-ui-hidden").addClass("transit-ui-active"),Transit.trigger("ui:show"),this},n.prototype._save=function(e){return e&&e.preventDefault(),this.model?this.model.save:!1},n}(Backbone.View),Transit.Manager=new e,typeof module!="undefined"&&module!==null&&(module.exports=Transit.Manager)}.call(this),function(){var e,t,n=function(e,t){return function(){return e.apply(t,arguments)}},r={}.hasOwnProperty,i=function(e,t){function i(){this.constructor=e}for(var n in t)r.call(t,n)&&(e[n]=t[n]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e},s=[].slice;t=function(t){function r(){this.set=n(this.set,this),this.reset=n(this.reset,this),this.remove=n(this.remove,this),r.__super__.constructor.apply(this,arguments),this.$el.attr("id","transit_ui_toolbar")}return i(r,t),r.prototype.panels={},r.prototype.tabBar=null,r.prototype.heading=null,r.prototype.tagName="div",r.prototype.className="transit-toolbar",r.prototype.initialize=function(){return r.__super__.initialize.apply(this,arguments),this.render()},r.prototype.add=function(){var e,t,n,r,i,o=this;t=1<=arguments.length?s.call(arguments,0):[],i=[];for(n=0,r=t.length;n<r;n++)e=t[n],_.has(this.panels,e.cid)!==!0?(this.$("div.panels").append(e.render().$el),this.tabBar.append(e),this.panels[e.cid]=e,e.on("active",function(){return o.tabBar.find(e.cid).find("a").click()}),e.on("remove",function(){return o.tabBar.remove(e.cid),Transit.trigger("panel:removed",e)}),i.push(Transit.trigger("panel:added",e))):i.push(void 0);return i},r.prototype.render=function(){return r.__super__.render.apply(this,arguments),this.tabBar===null&&(this.tabBar=new e),this.$el.append("<h1>Title</h1>").append(this.tabBar.el).append("<div class='panels'></div>"),this.$el.wrapInner("<div class='toolbar-inner'></div>"),this.heading=this.$("h1"),this.tabBar.el.find("a:eq(0)").click(),this},r.prototype.remove=function(e){return _.isString(e)&&(e=this.panels[e]),e===void 0?!1:(e.remove(),delete this.panels[e.cid],e)},r.prototype.reset=function(){var e,t,n;n=this.panels;for(e in n)t=n[e],t.remove(),delete this.panels[e];return this.panels={}},r.prototype.set=function(e,t){switch(e){case"heading":this.heading.html(t);break;default:return!1}return!0},r}(Backbone.View),e=function(){function e(){this.remove=n(this.remove,this),this.prepend=n(this.prepend,this),this.make=n(this.make,this),this.insert=n(this.insert,this),this.find=n(this.find,this),this.change=n(this.change,this),this.append=n(this.append,this);var e=this;this.tabs={},Transit.template.load("/transit/views/core/tab-bar.jst",function(t){var n,r,i,s;e.el=$(t()),e.list=e.el.find("ul.transit-tab-bar"),i=e.tabs,s=[];for(n in i)r=i[n],s.push(e.el.append(r));return s}),this}return e.prototype.el=null,e.prototype.list=null,e.prototype.tabs={},e.prototype.append=function(e){return this.list.append(this.make(e))},e.prototype.change=function(e){return $("li",this.list).removeClass("active"),this.find(e)===void 0?!0:(this.find(e).addClass("active"),this)},e.prototype.find=function(e){return $(this.tabs[e])},e.prototype.insert=function(e,t){var n;return n=this.make(t),e<_.size(this.tabs)?this.el.append(n):this.list.find("> li").eq(e).after(n)},e.prototype.make=function(e){var t,n,r,i,s,o,u;t=e.cid,o=e.title,n=$("<li></li>"),r=$("<a></a>").text(o),s=_.pick(e,"class","icon","id","href","rel","target");if(this.tabs[t]!==void 0)return this.tabs[t];for(i in s){u=s[i];switch(i){case"class":r.addClass(u);break;case"icon":r.prepend($("<i></i>").addClass("icon-"+u));break;default:r.attr(i,u)}}return e.$el.attr("id")===void 0&&e.$el.attr("id","#transit_panel_"+cid),r.attr({href:e.$el.attr("id"),"data-toggle":"tab"}).text(o),n.append(r).attr({id:"#transit_panel_tab_"+t}),this.tabs[t]=n,n},e.prototype.prepend=function(e){return this.list.prepend(this.make(e))},e.prototype.remove=function(e){return this.find(e).remove()},e}(),Transit.Toolbar=t,typeof module!="undefined"&&module!==null&&(module.exports=Transit.Toolbar)}.call(this),function(){var e,t=function(e,t){return function(){return e.apply(t,arguments)}},n={}.hasOwnProperty,r=function(e,t){function i(){this.constructor=e}for(var r in t)n.call(t,r)&&(e[r]=t[r]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e};e=function(e){function n(){this.remove=t(this.remove,this),this.deactivate=t(this.deactivate,this),this.activate=t(this.activate,this),this.initialize=t(this.initialize,this);var e,r,i,s;n.__super__.constructor.apply(this,arguments),s=["title","icon"];for(r=0,i=s.length;r<i;r++)e=s[r],this.options[e]!==void 0&&(this[e]=this.options[e]);this.$el.attr("id")===void 0&&this.$el.attr("id","transit_panel_"+this.cid)}return r(n,e),n.prototype.tagName="div",n.prototype.className="transit-panel",n.prototype.title="Detail",n.prototype.icon="",n.prototype.active=!1,n.prototype.initialize=function(){},n.prototype.activate=function(){return this.active=!0,this.$el.addClass("active")},n.prototype.deactivate=function(){return this.active=!1,this.$el.removeClass("active")},n.prototype.remove=function(){return n.__super__.remove.apply(this,arguments),this.trigger("remove",this)},n}(Backbone.View),Transit.Panel=e,typeof module!="undefined"&&module!==null&&(module.exports=Transit.Panel)}.call(this),function(){var e,t=function(e,t){return function(){return e.apply(t,arguments)}},n={}.hasOwnProperty,r=function(e,t){function i(){this.constructor=e}for(var r in t)n.call(t,r)&&(e[r]=t[r]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e};e=function(e){function n(){return this.render=t(this.render,this),n.__super__.constructor.apply(this,arguments)}return r(n,e),n.prototype.uploader=null,n.prototype.collection=null,n.prototype.render=function(){n.__super__.render.apply(this,arguments),this.$el.addClass("transit-asset-manager");if(this.uploader===null)return this.uploader=new Transit.Uploader,this.$el.prepend(this.uploader.render().$el)},n}(Transit.Panel),Transit.AssetManager=e,typeof module!="undefined"&&module!==null&&(module.exports=Transit.AssetManager)}.call(this)
+(function(){var e,t,n,r,i=function(e,t){return function(){return e.apply(t,arguments)}},s=[].slice;n=!0,r=!1,e=function(){function e(){this.drop=i(this.drop,this),this.set=i(this.set,this),this.get=i(this.get,this)}return e.prototype.view={},e.prototype.context={},e.prototype.tpl={},e.prototype.get=function(e,t){var n;return e=e.toLowerCase(),t=t.toLowerCase(),n=this[e][t],n===void 0?null:n},e.prototype.set=function(e,t,n){return e=e.toLowerCase(),t=t.toLowerCase(),this[e][t]=n},e.prototype.drop=function(e,t){return delete this[e][t],this},e}(),t={},_.extend(t,{cache:new e,on:Backbone.Events.on,trigger:Backbone.Events.trigger,off:Backbone.Events.off,one:function(e,n,r){var i;return i=function(){var o;return o=1<=arguments.length?s.call(arguments,0):[],n.apply(null,o),t.off(e,i,r)},t.on(e,i,r)},set:function(){var e,n;return e=1<=arguments.length?s.call(arguments,0):[],(n=t.cache).set.apply(n,e)},get:function(){var e,n;return e=1<=arguments.length?s.call(arguments,0):[],(n=t.cache).get.apply(n,e)},ready:function(e){return t.one("ready",e)},init:function(e){return n===!1?t.one("ready",function(){return t.Manager.attach(e),t.trigger("init")}):(t.Manager.attach(e),t.trigger("init"))},version:"0.3.0"}),jQuery(window).one("load",function(){var e,i;return r=!0,n===!0?(t.trigger("ready"),!0):(e=0,i=_.size(t.template.preloads),_.each(t.template.preloads,function(s){return t.template.load(s,function(){e++,e===i&&(n=!0);if(r===!0&&n===!0)return t.trigger("ready")})}))}),this.Transit||(this.Transit=t)}).call(this),function(){var e,t;t=navigator.userAgent,e={msie:t.indexOf("MSIE")!==-1&&t.indexOf("Opera")===-1,gecko:t.indexOf("Gecko")!==-1&&t.indexOf("KHTML")===-1,webkit:t.indexOf("AppleWebKit/")!==-1,chrome:t.indexOf("Chrome/")!==-1,opera:t.indexOf("Opera/")!==-1,ios:/ipad|iphone|ipod/i.test(t),android:/android (\d+)/i.test(t)},Transit.browser=e,typeof module!="undefined"&&module!==null&&(module.exports=Transit.browser)}.call(this),function(){var e;e=function(){function e(){_.bindAll(this)}return e.selection=null,e.prototype.cursor=function(){var e,t,n,r;return r=this.get(),r===null?null:(e=$("<span/>"),t=document.createRange(),t.setStart(r.endContainer,r.endOffset),t.insertNode(e.get(0)),n=e.offset(),e.remove(),n)},e.prototype.get=function(){var e,t;return t=null,window.getSelection?(e=window.getSelection(),t=e.rangeCount>0?e.getRangeAt(0):null):document.selection&&document.selection.createRange&&(t=document.selection.createRange()),t},e.prototype.restore=function(e){var t;return e==null&&(e=null),e===null&&(e=this.selection),e===null?!0:(window.getSelection?(t=window.getSelection(),t.removeAllRanges(),t.addRange(e)):document.selection&&e.select&&e.select(),this.selection=null,this)},e.prototype.save=function(){return this.selection=this.get(),this.selection},e}(),Transit.Selection=new e,typeof module!="undefined"&&module!==null&&(module.exports=Transit.Selection)}.call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}};this.Transit.Template=function(){function t(t,n,r){this.render=e(this.render,this),this.path=t,this.source=n,this.func=r,this}return t.cache={},t.compile=function(e){return _.template(e)},t.find=function(e){var n;return n=t.cache[t.pathify(e)],n===void 0?!1:n},t.pathify=function(e){return e.indexOf(this.url)!==-1?e:""+this.url+"/"+e.replace(/^\//,"")},t.set=function(e,n){var r,i;return e=t.pathify(e),r=t.compile(n),i=new Transit.Template(e,n,r),t.cache[e]=i,i},t.url="/transit/views",t.prototype.path="",t.prototype.source="",t.prototype.func=null,t.prototype.render=function(e){return this.func===null?this.source:this.func(e)},t}.call(this),this.Transit.tpl=function(e,t){var n;return e=Transit.Template.pathify(e),n=Transit.Template.find(e),n===!1?$.get(e,function(n){var r;return r=Transit.Template.set(e,n),t(r)}):t(n)}}.call(this),function(){var e,t=function(e,t){return function(){return e.apply(t,arguments)}},n={}.hasOwnProperty,r=function(e,t){function i(){this.constructor=e}for(var r in t)n.call(t,r)&&(e[r]=t[r]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e};e=function(e){function n(){return this._save=t(this._save,this),this.show=t(this.show,this),this.render=t(this.render,this),this.hide=t(this.hide,this),n.__super__.constructor.apply(this,arguments)}return r(n,e),n.prototype.tagName="div",n.prototype.className="transit-ui",n.prototype.events={"click button.save":"_save"},n.prototype.toolBar=null,n.prototype.initialize=function(){return Transit.one("init",this.render)},n.prototype.append=function(e){return this.$el.append(e)},n.prototype.attach=function(e){return this.model=e,this},n.prototype.hide=function(){return this.$el.addClass("hidden"),$("html").addClass("transit-ui-hidden").removeClass("transit-ui-active"),Transit.trigger("ui:hide"),this},n.prototype.prepend=function(e){return this.$el.prepend(e)},n.prototype.render=function(){return $("#transit_ui").length===0&&(n.__super__.render.apply(this,arguments),$("html").addClass("transit-ui-hidden"),this.$el.addClass("hidden").attr("id","transit_ui").appendTo($("body")),this.toolBar===null&&(this.toolBar=Transit.Toolbar=new Transit.Toolbar,this.append(this.toolBar.$el))),this},n.prototype.show=function(){return this.$el.removeClass("hidden"),$("html").removeClass("transit-ui-hidden").addClass("transit-ui-active"),Transit.trigger("ui:show"),this},n.prototype._save=function(e){return e&&e.preventDefault(),this.model?this.model.save:!1},n}(Backbone.View),this.Transit.Manager=new e}.call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}},t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};this.Transit.Modal=function(t){function r(){return this.render=e(this.render,this),this.perform=e(this.perform,this),r.__super__.constructor.apply(this,arguments)}return n(r,t),r.handler=function(e){return $(e.$el).modal({show:!0}).one("hidden",function(t){return Transit.trigger("modal:close",e),e.trigger("close")})},r.prototype.tagName="div",r.prototype.className="transit-modal",r.prototype.events={"click a[data-action]":"perform"},r.prototype.initialize=function(){return r.__super__.initialize.apply(this,arguments),this.on("close",this.remove,this),this.options=_.defaults(this.options,{buttons:[],title:"Title Missing",content:"Content missing"})},r.prototype.perform=function(e){var t;return e.preventDefault(),t=$(e.currentTarget),Transit.trigger("modal:action",t.attr("data-action"),this)},r.prototype.remove=function(){return this.off(),this.trigger("remove"),r.__super__.remove.apply(this,arguments)},r.prototype.render=function(){var e=this;return Transit.tpl("/core/modal.jst",function(t){var n;return n=$(t.render(e.options)).attr("id","transit_modal_"+e.cid),e.setElement(n),e.trigger("open"),Transit.trigger("modal:show",e),e.$el.addClass("out"),Transit.Manager.append(e.$el),Transit.Modal.handler(e),e.$el.removeClass("out").addClass("in")}),this},r}(Backbone.View),this.Transit.modal=function(e){var t;return e==null&&(e={}),t=new Transit.Modal(e),Transit.one("modal:show",function(e){if(e!==t)return!1}),t.render()}}.call(this),function(){var e,t=function(e,t){return function(){return e.apply(t,arguments)}};e=function(){function e(){this._setup=t(this._setup,this),this._render=t(this._render,this),this.success=t(this.success,this),this.info=t(this.info,this),this.error=t(this.error,this),Transit.one("ready",this._setup)}return e.prototype.template=function(){},e.prototype.error=function(e){return this._render(e,"error")},e.prototype.info=function(e){return this._render(e,"info")},e.prototype.success=function(e){return this._render(e,"success")},e.prototype._render=function(e,t){return Transit.Manager.append($(this.template({message:e,type:t})))},e.prototype._setup=function(){var e=this;return Transit.tpl("/core/notification.jst",function(t){return e.template=t})},e}(),Transit.Notify=new e,typeof module!="undefined"&&module!==null&&(module.exports=Transit.Notify)}.call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}},t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};this.Transit.Panel=function(t){function r(){this.remove=e(this.remove,this),this.render=e(this.render,this),this.deactivate=e(this.deactivate,this),this.activate=e(this.activate,this),this.initialize=e(this.initialize,this);var t,n,i,s;r.__super__.constructor.apply(this,arguments),s=["title","icon"];for(n=0,i=s.length;n<i;n++)t=s[n],this.options[t]!==void 0&&(this[t]=this.options[t]);this.$el.attr("id")===void 0&&this.$el.attr("id","transit_panel_"+this.cid)}return n(r,t),r.prototype.tagName="div",r.prototype.className="transit-panel",r.prototype.title="Detail",r.prototype.icon="",r.prototype.active=!1,r.prototype.initialize=function(){},r.prototype.activate=function(){return this.active=!0,this.$el.addClass("active")},r.prototype.deactivate=function(){return this.active=!1,this.$el.removeClass("active")},r.prototype.render=function(){return r.__super__.render.apply(this,arguments),this},r.prototype.remove=function(){return r.__super__.remove.apply(this,arguments),this.trigger("remove",this)},r}(Backbone.View)}.call(this),function(){var e,t=function(e,t){return function(){return e.apply(t,arguments)}},n={}.hasOwnProperty,r=function(e,t){function i(){this.constructor=e}for(var r in t)n.call(t,r)&&(e[r]=t[r]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e},i=[].slice;this.Transit.Toolbar=function(n){function s(){this.set=t(this.set,this),this.reset=t(this.reset,this),this.remove=t(this.remove,this),s.__super__.constructor.apply(this,arguments),this.$el.attr("id","transit_ui_toolbar")}return r(s,n),s.prototype.panels={},s.prototype.tabBar=null,s.prototype.heading=null,s.prototype.tagName="div",s.prototype.className="transit-toolbar",s.prototype.initialize=function(){return s.__super__.initialize.apply(this,arguments),this.render()},s.prototype.add=function(){var e,t,n,r,s,o=this;t=1<=arguments.length?i.call(arguments,0):[],s=[];for(n=0,r=t.length;n<r;n++)e=t[n],_.has(this.panels,e.cid)!==!0?(this.$("div.panels").append(e.render().$el),this.tabBar.append(e),this.panels[e.cid]=e,e.on("active",function(){return o.tabBar.find(e.cid).find("a").click()}),e.on("remove",function(){return o.tabBar.remove(e.cid),Transit.trigger("panel:removed",e)}),s.push(Transit.trigger("panel:added",e))):s.push(void 0);return s},s.prototype.render=function(){return s.__super__.render.apply(this,arguments),this.tabBar===null&&(this.tabBar=new e),this.$el.append("<h1>Title</h1>").append(this.tabBar.el).append("<div class='panels'></div>"),this.$el.wrapInner("<div class='toolbar-inner'></div>"),this.heading=this.$("h1"),this.tabBar.el.find("a:eq(0)").click(),this},s.prototype.remove=function(e){return _.isString(e)&&(e=this.panels[e]),e===void 0?!1:(e.remove(),delete this.panels[e.cid],e)},s.prototype.reset=function(){var e,t,n;n=this.panels;for(e in n)t=n[e],t.remove(),delete this.panels[e];return this.panels={}},s.prototype.set=function(e,t){switch(e){case"heading":this.heading.html(t);break;default:return!1}return!0},s}(Backbone.View),e=function(){function e(){this.remove=t(this.remove,this),this.prepend=t(this.prepend,this),this.make=t(this.make,this),this.insert=t(this.insert,this),this.find=t(this.find,this),this.change=t(this.change,this),this.append=t(this.append,this);var e=this;this.tabs={},Transit.tpl("/transit/views/core/nav-bar.jst",function(t){var n,r,i,s;e.el=$(t.render()),e.list=e.el.find("ul.transit-nav-bar"),i=e.tabs,s=[];for(n in i)r=i[n],s.push(e.el.append(r));return s}),this}return e.prototype.el=null,e.prototype.list=null,e.prototype.tabs={},e.prototype.append=function(e){return this.list.append(this.make(e))},e.prototype.change=function(e){return $("li",this.list).removeClass("active"),this.find(e)===void 0?!0:(this.find(e).addClass("active"),this)},e.prototype.find=function(e){return $(this.tabs[e])},e.prototype.insert=function(e,t){var n;return n=this.make(t),e<_.size(this.tabs)?this.el.append(n):this.list.find("> li").eq(e).after(n)},e.prototype.make=function(e){var t,n,r,i,s,o,u;t=e.cid,o=e.title,n=$("<li></li>"),r=$("<a></a>").text(o),s=_.pick(e,"class","icon","id","href","rel","target");if(this.tabs[t]!==void 0)return this.tabs[t];for(i in s){u=s[i];switch(i){case"class":r.addClass(u);break;case"icon":r.prepend($("<i></i>").addClass("icon-"+u));break;default:r.attr(i,u)}}return e.$el.attr("id")===void 0&&e.$el.attr("id","#transit_panel_"+cid),r.attr({href:e.$el.attr("id"),"data-toggle":"tab"}).text(o),n.append(r).attr({id:"#transit_panel_tab_"+t}),this.tabs[t]=n,n},e.prototype.prepend=function(e){return this.list.prepend(this.make(e))},e.prototype.remove=function(e){return this.find(e).remove()},e}()}.call(this),function(){var e,t,n={}.hasOwnProperty,r=function(e,t){function i(){this.constructor=e}for(var r in t)n.call(t,r)&&(e[r]=t[r]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e};e=function(){var e;return XMLHttpRequest===void 0?!1:(e=new XMLHttpRequest,e.upload===void 0?!1:e.upload.onprogress!==void 0)},t=function(){var e;return e=document.createElement("INPUT"),e.type="file",e.files!==void 0},this.Transit.Uploader=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return r(n,t),n.prototype.tagName="div",n.prototype.className="transit-uploader",n["native"]=e(),n}(Backbone.View)}.call(this),function(){var e={}.hasOwnProperty,t=function(t,n){function i(){this.constructor=t}for(var r in n)e.call(n,r)&&(t[r]=n[r]);return i.prototype=n.prototype,t.prototype=new i,t.__super__=n.prototype,t};this.Transit.Asset=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return t(n,e),n.prototype.defaults={deliverable_id:null,deliverable_type:null,urls:[],url:null,image:!0,filename:null},n.prototype.isImage=function(){return this.get("image")},n}(Backbone.Model)}.call(this),function(){var e={}.hasOwnProperty,t=function(t,n){function i(){this.constructor=t}for(var r in n)e.call(n,r)&&(t[r]=n[r]);return i.prototype=n.prototype,t.prototype=new i,t.__super__=n.prototype,t};this.Transit.Assets=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return t(n,e),n.prototype.model=function(){return Transit.Asset},n.prototype.url=function(){return Transit.settings.asset_path},n.prototype.fetch=function(e){return e==null&&(e={}),e.data=this.deliverable,Backbone.Collection.prototype.fetch.apply(this,[e])},n}(Backbone.Collection)}.call(this),function(){var e,t=function(e,t){return function(){return e.apply(t,arguments)}},n={}.hasOwnProperty,r=function(e,t){function i(){this.constructor=e}for(var r in t)n.call(t,r)&&(e[r]=t[r]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e};e=function(e){function n(){return this._setType=t(this._setType,this),this._cleanup=t(this._cleanup,this),n.__super__.constructor.apply(this,arguments)}return r(n,e),n.build_as="contexts_attributes",n.prototype.view=null,n.prototype.type=null,n.prototype._pendingDestroy=!1,n.prototype.initialize=function(){var e;return this._setType(),this.view===null&&(e=Transit.get("view",this.type),e===null&&(e=Transit.get("view","Context")),this.isNew()?this.view=new e({model:this}):this.view=new e({model:this,el:".managed-context[data-context-id='#{@id}']"})),this.on("change",function(e){var t,n,r;r=e.changes;for(t in r)n=r[t],this.view.trigger("change:"+t);return this.view.trigger("change")}),this.on("destroy",this.cleanup),this.view.render(),this},n.prototype._cleanup=function(){return this.view.remove(),delete this.view},n.prototype._setType=function(){return this.type!==null?!0:(this.has("_type")||this.set("_type",this.constructor.name),this.type=this.get("_type"))},n}(Backbone.Model),Transit.Context=e,typeof module!="undefined"&&module!==null&&(module.exports=Transit.Context)}.call(this),function(){var e,t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};e=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return n(t,e),t.build_as="contexts_attributes",t.prototype._deliverable=null,t.prototype.model=function(e){var t;return t=Transit.get("context",e._type),t!==null?new t(e):new Transit.Context(e)},t}(Backbone.Collection),Transit.Contexts=e,typeof module!="undefined"&&module!==null&&(module.exports=Transit.Contexts)}.call(this),function(){var e,t,n=function(e,t){return function(){return e.apply(t,arguments)}},r={}.hasOwnProperty,i=function(e,t){function i(){this.constructor=e}for(var n in t)r.call(t,n)&&(e[n]=t[n]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e};e=window.$||Backbone.$,t=function(t){function r(){return this._build_contexts=n(this._build_contexts,this),this.invalidate=n(this.invalidate,this),r.__super__.constructor.apply(this,arguments)}return i(r,t),r.prototype.contexts=null,r.prototype.initialize=function(){return this.contexts||(this.contexts=new Transit.Contexts),this.on("change:contexts",this._build_contexts),this._build_contexts(),this},r.prototype.invalidate=function(t,n,r){var i,s,o,u,a;if(n&&n.responseText){o=e.parseJSON(n.responseText);if(o.errors){u=o.errors,a=[];for(i in u)s=u[i],a.push(t.trigger("error:"+i,s));return a}}},r.prototype.toJSON=function(){var e,t;return e={},this.contexts.each(function(t,n){return e[n.toString()]=t.toJSON()}),t={},t[""+Transit.Contexts.build_as]=e,{page:_.extend(r.__super__.toJSON.apply(this,arguments),t)}},r.prototype._build_contexts=function(){var e;return e=this.attributes.contexts||[],this.contexts.reset(e),delete this.attributes.contexts,this},r}(Backbone.Model),Transit.Deliverable=t,typeof module!="undefined"&&module!==null&&(module.exports=Transit.Deliverable)}.call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}},t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};this.Transit.AssetManager=function(t){function r(){return this.render=e(this.render,this),this.add=e(this.add,this),r.__super__.constructor.apply(this,arguments)}return n(r,t),r.prototype.uploader=null,r.prototype.collection=null,r.prototype.images=null,r.prototype.files=null,r.prototype.title="Assets",r.prototype.attach=function(e){this.model=e;if(this.model.assets===void 0)return this.model.assets=new Transit.Assets},r.prototype.add=function(e){return e.isImage()?this.images.add(e):this.files.add(e)},r.prototype.render=function(){return r.__super__.render.apply(this,arguments),this.$el.addClass("transit-asset-manager"),this.uploader===null&&(this.uploader=new Transit.Uploader,this.$el.prepend(this.uploader.render().$el)),this.files===null&&(this.files=new Transit.AssetManager.List({"class":"files"})),this.images===null&&(this.images=new Transit.AssetManager.List({"class":"images"})),this.$el.append(this.images.render().$el),this.$el.append(this.files.render().$el),this},r}(Transit.Panel),this.Transit.AssetManager.List=function(t){function r(){return this.add=e(this.add,this),r.__super__.constructor.apply(this,arguments)}return n(r,t),r.prototype.tagName="ul",r.prototype.initialize=function(){r.__super__.initialize.apply(this,arguments);if(this.options["class"])return this.$el.addClass(this.options["class"])},r.prototype.add=function(e){var t;return t=new Transit.AssetManager.Item({model:e}),this.$el.append(t.render.$el())},r}(Backbone.View),this.Transit.AssetManager.Item=function(t){function r(){return this.remove=e(this.remove,this),this.render=e(this.render,this),r.__super__.constructor.apply(this,arguments)}return n(r,t),r.prototype.events={'click a[data-action="remove"]':"remove"},r.prototype.tagName="li",r.prototype.type=null,r.prototype.template=null,r.prototype.initialize=function(){var e=this;return this.type=this.model.isImage()?"image":"file",this.$el.addClass(this.type),Transit.tpl("/core/assets/"+this.type+".jst",function(t){return e.template=t,e.render()})},r.prototype.render=function(){return this.$el.html(this.template({asset:this.model}))},r.prototype.remove=function(){return confirm("Are you sure you want to delete this "+this.type+"?")?(this.model.destroy(),Transit.trigger("asset:removed",this.model),r.__super__.remove.apply(this,arguments)):!1},r}(Backbone.View)}.call(this),function(){var e,t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};e=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return n(t,e),t}(Backbone.View),Transit.set("view","Context",e)}.call(this)
View
10 demo/index.html
@@ -25,16 +25,20 @@
<script type="text/javascript" charset="utf-8">
//<![CDATA[
(function(){
- var Page, panel, content;
+ var Page, panel, content, assets;
Transit.ready(function(){
+ var template;
+
Page = new Transit.Deliverable();
Transit.init(Page);
Transit.Toolbar.set('heading', 'Manage Page');
panel = new Transit.Panel({title: 'Info'});
content = new Transit.Panel({ title: 'Content' });
- Transit.Toolbar.add(panel, content);
- Transit.Manager.append(Transit.cache.get('tpl', '/transit/views/core/save-button.jst')({ text: 'Save' }));
+ assets = new Transit.AssetManager();
+ Transit.Toolbar.add(panel, content, assets);
+ template = Transit.Template.find('/transit/views/core/save-button.jst')
+ Transit.Manager.append(template.render({ text: 'Save' }));
window.Page = Page;
Transit.Manager.show();
panel.trigger('active');
View
1,392 demo/transit.js
@@ -1,8 +1,12 @@
(function() {
- var Cache, Settings, Template, Transit, setting, _ready,
+ var Cache, Transit, _ready, _winready,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__slice = [].slice;
+ _ready = true;
+
+ _winready = false;
+
Cache = (function() {
function Cache() {
@@ -47,228 +51,94 @@
})();
- Settings = {
- template_path: '/transit/views',
- asset_path: '/transit/assets'
- };
-
- Template = (function() {
-
- function Template() {
- this._pathify = __bind(this._pathify, this);
-
- this.set = __bind(this.set, this);
-
- this.load = __bind(this.load, this);
-
- this.compile = __bind(this.compile, this);
-
- }
-
- Template.prototype.compile = function(html) {
- return _.template(html);
- };
-
- Template.prototype.load = function(path, callback) {
- var exists,
- _this = this;
- exists = Transit.cache.get('tpl', path);
- if (exists !== void 0) {
- return callback(exists);
- }
- return $.get(this._pathify(path), function(data) {
- var result;
- result = _this.compile(data);
- Transit.cache.set('tpl', path, result);
- return callback(result);
- });
- };
-
- Template.prototype.set = function(name, html) {
- if (typeof html === 'string') {
- html = this.compile(html);
- }
- Transit.cache.set('tpl', name, html);
- return this;
- };
-
- Template.prototype._pathify = function(path) {
- if (path.indexOf(setting('template_path')) !== -1) {
- return path;
+ Transit = {};
+
+ _.extend(Transit, {
+ cache: new Cache(),
+ on: Backbone.Events.on,
+ trigger: Backbone.Events.trigger,
+ off: Backbone.Events.off,
+ one: function(events, callback, context) {
+ var callone;
+ callone = function() {
+ var args;
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ callback.apply(null, args);
+ return Transit.off(events, callone, context);
+ };
+ return Transit.on(events, callone, context);
+ },
+ set: function() {
+ var args, _ref;
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ return (_ref = Transit.cache).set.apply(_ref, args);
+ },
+ get: function() {
+ var args, _ref;
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ return (_ref = Transit.cache).get.apply(_ref, args);
+ },
+ ready: function(callback) {
+ return Transit.one('ready', callback);
+ },
+ init: function(model) {
+ if (_ready === false) {
+ return Transit.one('ready', function() {
+ Transit.Manager.attach(model);
+ return Transit.trigger('init');
+ });
} else {
- return "" + (setting('template_path')) + "/" + (path.replace(/^\//, ''));
+ Transit.Manager.attach(model);
+ return Transit.trigger('init');
}
- };
-
- return Template;
-
- })();
-
- Transit = this.Transit = {};
-
- Transit.cache = new Cache();
-
- Transit.config = Settings;
-
- Transit.template = new Template();
-
- Transit.setup = function(options) {
- if (options == null) {
- options = {};
- }
- return Transit.settings = _.extend(Transit.settings, options);
- };
-
- Transit.on = Backbone.Events.on;
-
- Transit.trigger = Backbone.Events.trigger;
-
- Transit.off = Backbone.Events.off;
-
- Transit.one = function(events, callback, context) {
- var callone;
- callone = function() {
- var args;
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
- callback.apply(null, args);
- return Transit.off(events, callone, context);
- };
- return Transit.on(events, callone, context);
- };
-
- Transit.set = Transit.cache.set;
-
- Transit.get = Transit.cache.get;
-
- _ready = false;
-
- jQuery(window).one('load', function() {
- _ready = true;
- return Transit.trigger("ready");
+ },
+ version: "0.3.0"
});
- Transit.ready = function(callback) {
- return Transit.one('ready', callback);
- };
-
- Transit.init = function(model) {
- Transit.Manager.attach(model);
- return Transit.trigger('init');
- };
-
- Transit.version = "0.3.0";
-
- setting = function(name) {
- return Transit.config[name];
- };
-
- this.Transit;
-
-}).call(this);
-(function() {
- var Notify,
- __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
-
- Notify = (function() {
-
- Notify.prototype.template = function() {};
-
- function Notify() {
- this._setup = __bind(this._setup, this);
-
- this._render = __bind(this._render, this);
-
- this.success = __bind(this.success, this);
-
- this.info = __bind(this.info, this);
-
- this.error = __bind(this.error, this);
- Transit.one('ready', this._setup);
+ jQuery(window).one('load', function() {
+ var counter, total;
+ _winready = true;
+ if (_ready === true) {
+ Transit.trigger("ready");
+ return true;
}
-
- Notify.prototype.error = function(message) {
- return this._render(message, 'error');
- };
-
- Notify.prototype.info = function(message) {
- return this._render(message, 'info');
- };
-
- Notify.prototype.success = function(message) {
- return this._render(message, 'success');
- };
-
- Notify.prototype._render = function(message, type) {
- return Transit.Manager.append($(this.template({
- message: message,
- type: type
- })));
- };
-
- Notify.prototype._setup = function() {
- var _this = this;
- return Transit.template.load("/transit/views/core/notification.jst", function(templ) {
- return _this.template = templ;
+ counter = 0;
+ total = _.size(Transit.template.preloads);
+ return _.each(Transit.template.preloads, function(jst) {
+ return Transit.template.load(jst, function() {
+ counter++;
+ if (counter === total) {
+ _ready = true;
+ }
+ if (_winready === true && _ready === true) {
+ return Transit.trigger('ready');
+ }
});
- };
-
- return Notify;
-
- })();
-
- Transit.Notify = new Notify();
+ });
+ });
- if (typeof module !== "undefined" && module !== null) {
- module.exports = Transit.Notify;
- }
+ this.Transit || (this.Transit = Transit);
}).call(this);
(function() {
- var Uploader, XHRUploadSupport, fileApiSupport,
- __hasProp = {}.hasOwnProperty,
- __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; };
+ var Browser, agent;
- XHRUploadSupport = function() {
- var xhr;
- if (XMLHttpRequest === void 0) {
- return false;
- }
- xhr = new XMLHttpRequest();
- if (xhr['upload'] === void 0) {
- return false;
- }
- return xhr.upload['onprogress'] !== void 0;
- };
+ agent = navigator.userAgent;
- fileApiSupport = function() {
- var input;
- input = document.createElement('INPUT');
- input.type = 'file';
- return input['files'] !== void 0;
+ Browser = {
+ msie: agent.indexOf("MSIE") !== -1 && agent.indexOf("Opera") === -1,
+ gecko: agent.indexOf("Gecko") !== -1 && agent.indexOf("KHTML") === -1,
+ webkit: agent.indexOf("AppleWebKit/") !== -1,
+ chrome: agent.indexOf("Chrome/") !== -1,
+ opera: agent.indexOf("Opera/") !== -1,
+ ios: /ipad|iphone|ipod/i.test(agent),
+ android: /android (\d+)/i.test(agent)
};
- Uploader = (function(_super) {
-
- __extends(Uploader, _super);
-
- function Uploader() {
- return Uploader.__super__.constructor.apply(this, arguments);
- }
-
- Uploader.prototype.tagName = 'div';
-
- Uploader.prototype.className = 'transit-uploader';
-
- Uploader["native"] = XHRUploadSupport();
-
- return Uploader;
-
- })(Backbone.View);
-
- Transit.Uploader = Uploader;
+ Transit.browser = Browser;