diff options
Diffstat (limited to 'src/fauxton/js/api.js')
-rw-r--r-- | src/fauxton/js/api.js | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/fauxton/js/api.js b/src/fauxton/js/api.js new file mode 100644 index 000000000..f1c5543b8 --- /dev/null +++ b/src/fauxton/js/api.js @@ -0,0 +1,101 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +define([ + "js/app", + + // Modules + "js/modules/fauxton/base" +], + +function(app, Fauxton) { + var FauxtonAPI = app.module(); + + FauxtonAPI.moduleExtensions = { + Routes: { + } + }; + + FauxtonAPI.addonExtensions = { + initialize: function() {} + }; + + // List of JSHINT errors to ignore + // Gets around problem of anonymous functions not being a valid statement + FauxtonAPI.excludedViewErrors = [ + "Missing name in function declaration." + ]; + + FauxtonAPI.isIgnorableError = function(msg) { + return _.contains(FauxtonAPI.excludedViewErrors, msg); + }; + + FauxtonAPI.View = Backbone.View.extend({ + // This should return an array of promises, an empty array, or null + establish: function() { + return null; + } + }); + + FauxtonAPI.navigate = function(url) { + Backbone.history.navigate(url, true); + }; + + FauxtonAPI.addHeaderLink = function(link) { + app.masterLayout.navBar.addLink(link); + }; + + FauxtonAPI.Deferred = function() { + return $.Deferred(); + }; + + FauxtonAPI.addRoute = function(route) { + app.router.route(route.route, route.name, route.callback); + }; + + FauxtonAPI.module = function(extra) { + return app.module(_.extend(FauxtonAPI.moduleExtensions, extra)); + }; + + FauxtonAPI.addon = function(extra) { + return FauxtonAPI.module(FauxtonAPI.addonExtensions, extra); + }; + + FauxtonAPI.addNotification = function(options) { + options = _.extend({ + msg: "Notification Event Triggered!", + type: "info", + selector: "#global-notifications" + }, options); + var view = new Fauxton.Notification(options); + + return view.renderNotification(); + }; + + FauxtonAPI.UUID = Backbone.Model.extend({ + initialize: function(options) { + options = _.extend({count: 1}, options); + this.count = options.count; + }, + + url: function() { + return app.host + "/_uuids?count=" + this.count; + }, + + next: function() { + return this.get("uuids").pop(); + } + }); + + app.fauxtonAPI = FauxtonAPI; + return app.fauxtonAPI; +}); |