summaryrefslogtreecommitdiff
path: root/src/fauxton/app/api.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/fauxton/app/api.js')
-rw-r--r--src/fauxton/app/api.js101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/fauxton/app/api.js b/src/fauxton/app/api.js
new file mode 100644
index 000000000..52e861183
--- /dev/null
+++ b/src/fauxton/app/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([
+ "app",
+
+ // Modules
+ "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;
+});