mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-02 08:13:34 +03:00
31f41822e0
Conflicts: .gitignore Gruntfile.js bower.json core/client/assets/lib/showdown/extensions/ghostdown.js core/client/assets/vendor/showdown/extensions/ghostdown.js core/client/router.js core/clientold/assets/vendor/chart.min.js core/clientold/assets/vendor/codemirror/addon/mode/overlay.js core/clientold/assets/vendor/codemirror/codemirror.js core/clientold/assets/vendor/codemirror/mode/gfm/gfm.js core/clientold/assets/vendor/codemirror/mode/gfm/index.html core/clientold/assets/vendor/codemirror/mode/gfm/test.js core/clientold/assets/vendor/codemirror/mode/markdown/index.html core/clientold/assets/vendor/codemirror/mode/markdown/markdown.js core/clientold/assets/vendor/codemirror/mode/markdown/test.js core/clientold/assets/vendor/countable.js core/clientold/assets/vendor/fastclick.js core/clientold/assets/vendor/icheck/jquery.icheck.min.js core/clientold/assets/vendor/jquery.hammer.min.js core/clientold/assets/vendor/nprogress.js core/clientold/assets/vendor/packery.pkgd.min.js core/clientold/assets/vendor/showdown/extensions/ghostdown.js core/clientold/assets/vendor/showdown/showdown.js core/clientold/assets/vendor/validator-client.js core/test/unit/client_ghostdown_spec.js core/test/unit/client_showdown_int_spec.js
84 lines
2.4 KiB
JavaScript
84 lines
2.4 KiB
JavaScript
/*globals window, $, _, Backbone, validator */
|
|
(function () {
|
|
'use strict';
|
|
|
|
function ghostPaths() {
|
|
var path = window.location.pathname,
|
|
subdir = path.substr(0, path.search('/ghost/'));
|
|
|
|
return {
|
|
subdir: subdir,
|
|
apiRoot: subdir + '/ghost/api/v0.1'
|
|
};
|
|
}
|
|
|
|
var Ghost = {
|
|
Layout : {},
|
|
Views : {},
|
|
Collections : {},
|
|
Models : {},
|
|
|
|
paths: ghostPaths(),
|
|
|
|
// This is a helper object to denote legacy things in the
|
|
// middle of being transitioned.
|
|
temporary: {},
|
|
|
|
currentView: null,
|
|
router: null
|
|
};
|
|
|
|
_.extend(Ghost, Backbone.Events);
|
|
|
|
Backbone.oldsync = Backbone.sync;
|
|
// override original sync method to make header request contain csrf token
|
|
Backbone.sync = function (method, model, options, error) {
|
|
options.beforeSend = function (xhr) {
|
|
xhr.setRequestHeader('X-CSRF-Token', $("meta[name='csrf-param']").attr('content'));
|
|
};
|
|
/* call the old sync method */
|
|
return Backbone.oldsync(method, model, options, error);
|
|
};
|
|
|
|
Backbone.oldModelProtoUrl = Backbone.Model.prototype.url;
|
|
//overwrite original url method to add slash to end of the url if needed.
|
|
Backbone.Model.prototype.url = function () {
|
|
var url = Backbone.oldModelProtoUrl.apply(this, arguments);
|
|
return url + (url.charAt(url.length - 1) === '/' ? '' : '/');
|
|
};
|
|
|
|
Ghost.init = function () {
|
|
Ghost.router = new Ghost.Router();
|
|
|
|
// 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: []});
|
|
|
|
Backbone.history.start({
|
|
pushState: true,
|
|
hashChange: false,
|
|
root: Ghost.paths.subdir + '/ghost'
|
|
});
|
|
};
|
|
|
|
validator.handleErrors = function (errors) {
|
|
Ghost.notifications.clearEverything();
|
|
_.each(errors, function (errorObj) {
|
|
|
|
Ghost.notifications.addItem({
|
|
type: 'error',
|
|
message: errorObj.message || errorObj,
|
|
status: 'passive'
|
|
});
|
|
|
|
if (errorObj.hasOwnProperty('el')) {
|
|
errorObj.el.addClass('input-error');
|
|
}
|
|
});
|
|
};
|
|
|
|
window.Ghost = Ghost;
|
|
|
|
window.addEventListener("load", Ghost.init, false);
|
|
}());
|