ionic-cordova-gulp-seed
Version:
Ionic & Cordova & Gulp seed with organized code, tests, bower support and some other stuff. Originated from ionic-angular-cordova-seed.
569 lines (476 loc) • 16 kB
JavaScript
(function() {
window.addElement = function(container, tagName, attrs) {
var fjs, k, tag, v;
if (attrs == null) {
attrs = {};
}
if (attrs.id && container.getElementById(attrs.id)) {
return container.getElementById(attrs.id);
}
fjs = container.getElementsByTagName(tagName)[0];
tag = container.createElement(tagName);
for (k in attrs) {
v = attrs[k];
tag[k] = v;
}
fjs.parentNode.insertBefore(tag, fjs);
return tag;
};
window.log = function() {
return console.log(arguments);
};
Storage.prototype.setObject = function(key, value) {
return this.setItem(key, JSON.stringify(value));
};
Storage.prototype.getObject = function(key) {
var value;
if (!(value = this.getItem(key))) {
return;
}
return JSON.parse(value);
};
}).call(this);
(function() {
if (GLOBALS.WEINRE_ADDRESS && (ionic.Platform.isAndroid() || ionic.Platform.isIOS()) && !navigator.platform.match(/MacIntel/i)) {
window.addElement(document, "script", {
id: "weinre-js",
src: "http://" + GLOBALS.WEINRE_ADDRESS + "/target/target-script-min.js#anonymous"
});
}
}).call(this);
(function() {
var app;
app = angular.module(GLOBALS.ANGULAR_APP_NAME, ["" + GLOBALS.ANGULAR_APP_NAME + ".templates", "ionic", "angulartics.google.analytics", "angulartics.google.analytics.cordova"]);
}).call(this);
(function() {
var app, k, v;
app = angular.module(GLOBALS.ANGULAR_APP_NAME);
GLOBALS.APP_ROOT = location.href.replace(location.hash, "").replace("index.html", "");
for (k in GLOBALS) {
v = GLOBALS[k];
app.constant(k, v);
}
app.run(function($rootScope) {
return $rootScope.GLOBALS = GLOBALS;
});
}).call(this);
(function() {
var app;
app = angular.module(GLOBALS.ANGULAR_APP_NAME);
ionic.Platform.ready(function() {
if (GLOBALS.ENV !== "test") {
console.log('ionic.Platform is ready! Running `angular.bootstrap()`...');
}
return angular.bootstrap(document, [GLOBALS.ANGULAR_APP_NAME]);
});
app.run(function($log, $timeout) {
if (GLOBALS.ENV !== "test") {
$log.debug("Ionic app \"" + GLOBALS.ANGULAR_APP_NAME + "\" has just started (app.run)!");
}
return $timeout(function() {
var _ref;
return (_ref = navigator.splashscreen) != null ? _ref.hide() : void 0;
});
});
}).call(this);
(function() {
var app;
if (!GLOBALS.CORDOVA_GOOGLE_ANALYTICS_ID) {
return;
}
app = angular.module(GLOBALS.ANGULAR_APP_NAME);
ionic.Platform.ready(function() {
return app.config(function(googleAnalyticsCordovaProvider) {
googleAnalyticsCordovaProvider.debug = GLOBALS.ENV !== 'production';
return googleAnalyticsCordovaProvider.trackingId = GLOBALS.CORDOVA_GOOGLE_ANALYTICS_ID;
});
});
}).call(this);
(function() {
var app;
app = angular.module(GLOBALS.ANGULAR_APP_NAME);
app.config(function($httpProvider) {
var _base;
$httpProvider.useApplyAsync(true);
(_base = $httpProvider.defaults.headers).patch || (_base.patch = {});
$httpProvider.defaults.headers.patch['Content-Type'] = 'application/json';
$httpProvider.defaults.headers.common["X-Api-Version"] = "1.0";
return $httpProvider.interceptors.push(function($injector, $q, $log, $location) {
return {
responseError: function(response) {
if (GLOBALS.ENV !== "test") {
$log.debug("httperror: ", response.status);
}
if (response.status === 401) {
$injector.invoke(function(Auth) {
Auth.setAuthToken(null, null);
return $location.path("/");
});
}
return $q.reject(response);
}
};
});
});
}).call(this);
(function() {
var app;
app = angular.module(GLOBALS.ANGULAR_APP_NAME);
app.config(function($ionicConfigProvider) {
$ionicConfigProvider.views.maxCache(4);
$ionicConfigProvider.templates.maxPrefetch(false);
if (ionic.Platform.grade !== "a") {
$ionicConfigProvider.views.transition("none");
return $ionicConfigProvider.views.maxCache(2);
}
});
}).call(this);
(function() {
var app;
app = angular.module(GLOBALS.ANGULAR_APP_NAME);
app.config(function($logProvider, $compileProvider) {
if (GLOBALS.ENV === "production") {
$logProvider.debugEnabled(false);
return $compileProvider.debugInfoEnabled(false);
}
});
}).call(this);
(function() {
var app;
if (window.Rollbar == null) {
return;
}
app = angular.module(GLOBALS.ANGULAR_APP_NAME);
app.factory('$exceptionHandler', function($log) {
return function(e, cause) {
$log.error(e.message);
return Rollbar.error(e);
};
});
Rollbar.configure({
payload: {
deploy_time: GLOBALS.DEPLOY_TIME,
deploy_date: moment(GLOBALS.DEPLOY_TIME).format(),
bundle_name: GLOBALS.BUNDLE_NAME,
bundle_version: GLOBALS.BUNDLE_VERSION
},
transform: function(payload) {
var frame, frames, _i, _len, _ref, _ref1, _ref2, _results;
if (frames = (_ref = payload.data) != null ? (_ref1 = _ref.body) != null ? (_ref2 = _ref1.trace) != null ? _ref2.frames : void 0 : void 0 : void 0) {
_results = [];
for (_i = 0, _len = frames.length; _i < _len; _i++) {
frame = frames[_i];
_results.push(frame.filename = frame.filename.replace(GLOBALS.APP_ROOT, "" + GLOBALS.ROLLBAR_SOURCEMAPS_URL_PREFIX + "/"));
}
return _results;
}
}
});
app.run(function(Auth) {
return Auth.on("user.updated", function(user) {
return Rollbar.configure({
payload: {
person: (user ? {
id: user.id,
email: user.email
} : void 0)
}
});
});
});
app.run(function(onRouteChangeCallback) {
return onRouteChangeCallback(function(state) {
return Rollbar.configure({
payload: {
context: state.name
}
});
});
});
}).call(this);
(function() {
if (GLOBALS.WEINRE_ADDRESS && (ionic.Platform.isAndroid() || ionic.Platform.isIOS()) && !navigator.platform.match(/MacIntel/i)) {
window.addElement(document, "script", {
id: "weinre-js",
src: "http://" + GLOBALS.WEINRE_ADDRESS + "/target/target-script-min.js#anonymous"
});
}
}).call(this);
(function() {
var app;
app = angular.module(GLOBALS.ANGULAR_APP_NAME);
app.run(function($window, $injector) {
return $window.$a = $injector.get;
});
}).call(this);
(function() {
angular.module("ionicstarter").service('Auth', function($http, PromiseFactory) {
var Auth, USER_EMAIL_CACHE_KEY, USER_TOKEN_CACHE_KEY;
USER_EMAIL_CACHE_KEY = "user_email";
USER_TOKEN_CACHE_KEY = "user_token";
return new (Auth = (function() {
function Auth() {
this.setAuthToken(localStorage.getItem(USER_EMAIL_CACHE_KEY), localStorage.getItem(USER_TOKEN_CACHE_KEY));
}
Auth.prototype.setAuthToken = function(email, token, user) {
this.email = email != null ? email : null;
this.token = token != null ? token : null;
if (this.email && this.token) {
$http.defaults.headers.common["X-User-Email"] = this.email;
$http.defaults.headers.common["X-User-Token"] = this.token;
localStorage.setItem(USER_EMAIL_CACHE_KEY, this.email);
localStorage.setItem(USER_TOKEN_CACHE_KEY, this.token);
} else {
delete $http.defaults.headers.common["X-User-Email"];
delete $http.defaults.headers.common["X-User-Token"];
localStorage.removeItem(USER_EMAIL_CACHE_KEY);
localStorage.removeItem(USER_TOKEN_CACHE_KEY);
}
return this.refreshUser(user);
};
Auth.prototype.refreshUser = function(user) {
if (user == null) {
user = null;
}
return this.user = user ? (user.$promise = PromiseFactory(user), user.$resolved = true, user) : this.email && this.token ? void 0 : null;
};
Auth.prototype.isSignedIn = function() {
return !!this.token;
};
Auth.prototype.resetSession = function() {
return this.setAuthToken(null, null);
};
return Auth;
})());
});
}).call(this);
(function() {
angular.module('ionicstarter').factory('FormFactory', function($q) {
/*
Basic form class that you can extend in your actual forms.
Object attributes:
- loading[Boolean] - is the request waiting for response?
- message[String] - after response, success message
- errors[String[]] - after response, error messages
Options:
- submitPromise[function] (REQUIRED) - creates a form request promise
- onSuccess[function] - will be called on succeded promise
- onFailure[function] - will be called on failed promise
*/
var FormFactory;
return FormFactory = (function() {
function FormFactory(options) {
this.options = options != null ? options : {};
this.loading = false;
}
FormFactory.prototype.submit = function() {
if (!this.loading) {
return this._handleRequestPromise(this._createSubmitPromise());
}
};
FormFactory.prototype._onSuccess = function(response) {
this.message = response.message || response.success;
return response;
};
FormFactory.prototype._onFailure = function(response) {
var _ref, _ref1, _ref2, _ref3, _ref4;
this.errors = ((_ref = response.data) != null ? (_ref1 = _ref.data) != null ? _ref1.errors : void 0 : void 0) || ((_ref2 = response.data) != null ? _ref2.errors : void 0) || [((_ref3 = response.data) != null ? _ref3.error : void 0) || response.error || ((_ref4 = response.data) != null ? _ref4.message : void 0) || response.message || "Something has failed. Try again."];
return $q.reject(response);
};
FormFactory.prototype._createSubmitPromise = function() {
return this.options.submitPromise();
};
FormFactory.prototype._handleRequestPromise = function($promise, onSuccess, onFailure) {
this.$promise = $promise;
this.loading = true;
this.submitted = false;
this.message = null;
this.errors = [];
this.$promise.then((function(_this) {
return function(response) {
_this.errors = [];
_this.submitted = true;
return response;
};
})(this)).then(_.bind(this._onSuccess, this)).then(onSuccess || this.options.onSuccess)["catch"](_.bind(this._onFailure, this))["catch"](onFailure || this.options.onFailure)["finally"]((function(_this) {
return function() {
return _this.loading = false;
};
})(this));
return this.$promise;
};
return FormFactory;
})();
});
}).call(this);
(function() {
var __slice = [].slice;
angular.module('ionicstarter').factory('ObserverFactory', function($rootScope) {
var ObserverFactory;
return ObserverFactory = (function() {
function ObserverFactory() {}
ObserverFactory.prototype.on = function(eventName, listener) {
var _base;
if (this.listeners == null) {
this.listeners = {};
}
if ((_base = this.listeners)[eventName] == null) {
_base[eventName] = [];
}
return this.listeners[eventName].push(listener);
};
ObserverFactory.prototype.once = function(eventName, listener) {
listener.__once__ = true;
return this.on(eventName, listener);
};
ObserverFactory.prototype.off = function(eventName, listener) {
var i, v, _i, _len, _ref, _ref1, _results;
if (!((_ref = this.listeners) != null ? _ref[eventName] : void 0)) {
return;
}
if (!listener) {
return delete this.listeners[eventName];
}
_ref1 = this.listeners[eventName];
_results = [];
for (v = _i = 0, _len = _ref1.length; _i < _len; v = ++_i) {
i = _ref1[v];
if (this.listeners[eventName] === listener) {
this.listeners.splice(i, 1);
break;
} else {
_results.push(void 0);
}
}
return _results;
};
ObserverFactory.prototype.fireEvent = function() {
var eventName, params, v, _i, _len, _ref, _ref1, _ref2;
eventName = arguments[0], params = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
if (!((_ref = this.listeners) != null ? (_ref1 = _ref[eventName]) != null ? _ref1.length : void 0 : void 0)) {
return;
}
_ref2 = this.listeners[eventName];
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
v = _ref2[_i];
v.apply(this, params);
if (v.__once__) {
this.off(eventName, v);
}
}
if (!$rootScope.$$phase) {
return $rootScope.$apply();
}
};
return ObserverFactory;
})();
});
}).call(this);
(function() {
angular.module("ionicstarter").factory('PromiseFactory', function($q) {
var constructor;
return constructor = function(value, resolve) {
var deferred;
if (resolve == null) {
resolve = true;
}
if ((value != null) && typeof (value != null ? value.then : void 0) === 'function') {
return value;
} else {
deferred = $q.defer();
if (resolve) {
deferred.resolve(value);
} else {
deferred.reject(value);
}
return deferred.promise;
}
};
});
}).call(this);
(function() {
angular.module("ionicstarter").controller("PetDetailCtrl", function($scope, $stateParams, PetService) {
return $scope.pet = PetService.get($stateParams.petId);
});
}).call(this);
(function() {
angular.module("ionicstarter").controller("PetIndexCtrl", function($scope, PetService) {
return $scope.pets = PetService.all();
});
}).call(this);
/*
A simple example service that returns some data.
*/
(function() {
angular.module("ionicstarter").factory("PetService", function() {
var pets;
pets = [
{
id: 0,
title: "Cats",
description: "Furry little creatures. Obsessed with plotting assassination, but never following through on it."
}, {
id: 1,
title: "Dogs",
description: "Lovable. Loyal almost to a fault. Smarter than they let on."
}, {
id: 2,
title: "Turtles",
description: "Everyone likes turtles."
}, {
id: 3,
title: "Sharks",
description: "An advanced pet. Needs millions of gallons of salt water. Will happily eat you."
}
];
return {
all: function() {
return pets;
},
get: function(petId) {
return pets[petId];
}
};
});
}).call(this);
(function() {
angular.module("ionicstarter").config(function($stateProvider, $urlRouterProvider) {
$stateProvider.state("tab", {
url: "/tab",
abstract: true,
templateUrl: "templates/tabs.html"
}).state("tab.pet-index", {
url: "/pets",
views: {
"pets-tab": {
templateUrl: "templates/pet-index.html",
controller: "PetIndexCtrl"
}
}
}).state("tab.pet-detail", {
url: "/pet/:petId",
views: {
"pets-tab": {
templateUrl: "templates/pet-detail.html",
controller: "PetDetailCtrl"
}
}
}).state("tab.adopt", {
url: "/adopt",
views: {
"adopt-tab": {
templateUrl: "templates/adopt.html"
}
}
}).state("tab.about", {
url: "/about",
views: {
"about-tab": {
templateUrl: "templates/about.html"
}
}
});
return $urlRouterProvider.otherwise("/tab/pets");
});
}).call(this);
//# sourceMappingURL=app.js.map