2013-09-13 00:03:18 +04:00
|
|
|
/*globals window, $, _, Backbone, Validator */
|
2013-06-25 16:23:09 +04:00
|
|
|
(function () {
|
2013-05-31 09:58:20 +04:00
|
|
|
"use strict";
|
|
|
|
|
2013-06-04 16:38:45 +04:00
|
|
|
var Ghost = {
|
|
|
|
Layout : {},
|
|
|
|
Views : {},
|
|
|
|
Collections : {},
|
|
|
|
Models : {},
|
2013-09-13 00:03:18 +04:00
|
|
|
Validate : new Validator(),
|
2013-06-04 16:38:45 +04:00
|
|
|
|
|
|
|
settings: {
|
|
|
|
apiRoot: '/api/v0.1'
|
|
|
|
},
|
|
|
|
|
|
|
|
// This is a helper object to denote legacy things in the
|
|
|
|
// middle of being transitioned.
|
|
|
|
temporary: {},
|
|
|
|
|
|
|
|
currentView: null,
|
|
|
|
router: null
|
|
|
|
};
|
|
|
|
|
2013-08-21 14:50:49 +04:00
|
|
|
_.extend(Ghost, Backbone.Events);
|
|
|
|
|
2013-06-08 06:16:28 +04:00
|
|
|
Ghost.init = function () {
|
|
|
|
Ghost.router = new Ghost.Router();
|
2013-08-06 11:55:47 +04:00
|
|
|
|
|
|
|
// This is needed so Backbone recognizes elements already rendered server side
|
|
|
|
// as valid views, and events are bound
|
|
|
|
Ghost.notifications = new Ghost.Views.NotificationCollection({model: []});
|
|
|
|
|
2013-06-08 06:16:28 +04:00
|
|
|
Backbone.history.start({
|
|
|
|
pushState: true,
|
|
|
|
hashChange: false,
|
|
|
|
root: '/ghost'
|
|
|
|
});
|
|
|
|
};
|
2013-06-02 03:45:02 +04:00
|
|
|
|
2013-09-13 00:03:18 +04:00
|
|
|
Ghost.Validate.error = function (object) {
|
|
|
|
this._errors.push(object);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
Ghost.Validate.handleErrors = function () {
|
|
|
|
_.each(Ghost.Validate._errors, function (errorObj) {
|
2013-09-15 21:19:11 +04:00
|
|
|
|
2013-09-13 00:03:18 +04:00
|
|
|
Ghost.notifications.addItem({
|
|
|
|
type: 'error',
|
2013-09-15 21:19:11 +04:00
|
|
|
message: errorObj.message || errorObj,
|
2013-09-13 00:03:18 +04:00
|
|
|
status: 'passive'
|
|
|
|
});
|
|
|
|
if (errorObj.hasOwnProperty('el')) {
|
|
|
|
errorObj.el.addClass('input-error');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-05-31 09:58:20 +04:00
|
|
|
window.Ghost = Ghost;
|
|
|
|
|
2013-09-13 00:03:18 +04:00
|
|
|
}());
|