/**
* Create a wrapping module to ease having to include too many
* modules.
*/
angular.module('ionic.ui', ['ionic.ui.content',
'ionic.ui.tabs',
'ionic.ui.nav',
'ionic.ui.sideMenu',
'ionic.ui.list',
'ionic.ui.checkbox',
'ionic.ui.toggle'
]);
;
angular.module('ionic.service.actionSheet', ['ionic.service.templateLoad', 'ionic.ui.actionSheet'])
.factory('ActionSheet', ['$rootScope', '$document', '$compile', 'TemplateLoader', function($rootScope, $document, $compile, TemplateLoader) {
return {
/**
* Load an action sheet with the given template string.
*
* A new isolated scope will be created for the
* action sheet and the new element will be appended into the body.
*
* @param {object} opts the options for this ActionSheet (see docs)
*/
show: function(opts) {
var scope = $rootScope.$new(true);
angular.extend(scope, opts);
scope.cancel = function() {
scope.sheet.hide();
//scope.$destroy();
opts.cancel();
};
scope.buttonClicked = function(index) {
// Check if the button click event returned true, which means
// we can close the action sheet
if((opts.buttonClicked && opts.buttonClicked(index)) === true) {
scope.sheet.hide();
//scope.$destroy();
}
};
scope.destructiveButtonClicked = function() {
// Check if the destructive button click event returned true, which means
// we can close the action sheet
if((opts.destructiveButtonClicked && opts.destructiveButtonClicked()) === true) {
scope.sheet.hide();
//scope.$destroy();
}
};
// Compile the template
var element = $compile('')(scope);
var s = element.scope();
$document[0].body.appendChild(element[0]);
var sheet = new ionic.views.ActionSheet({el: element[0] });
s.sheet = sheet;
sheet.show();
return sheet;
}
};
}]);
;
angular.module('ionic.service.gesture', [])
.factory('Gesture', [function() {
return {
on: function(eventType, cb, element) {
return window.ionic.onGesture(eventType, cb, element);
}
};
}]);
;
angular.module('ionic.service.loading', ['ionic.ui.loading'])
.factory('Loading', ['$rootScope', '$document', '$compile', function($rootScope, $document, $compile) {
return {
/**
* Load an action sheet with the given template string.
*
* A new isolated scope will be created for the
* action sheet and the new element will be appended into the body.
*
* @param {object} opts the options for this ActionSheet (see docs)
*/
show: function(opts) {
var defaults = {
content: '',
animation: 'fade-in',
showBackdrop: true,
maxWidth: 200,
showDelay: 2000
};
opts = angular.extend(defaults, opts);
var scope = $rootScope.$new(true);
angular.extend(scope, opts);
// Make sure there is only one loading element on the page at one point in time
var existing = angular.element($document[0].querySelector('.loading-backdrop'));
if(existing.length) {
var scope = existing.scope();
if(scope.loading) {
scope.loading.show();
return scope.loading;
}
}
// Compile the template
var element = $compile('' + opts.content + '')(scope);
$document[0].body.appendChild(element[0]);
var loading = new ionic.views.Loading({
el: element[0],
maxWidth: opts.maxWidth,
showDelay: opts.showDelay
});
loading.show();
scope.loading = loading;
return loading;
}
};
}]);
;
angular.module('ionic.service.modal', ['ionic.service.templateLoad'])
.factory('Modal', ['$rootScope', '$document', '$compile', 'TemplateLoader', function($rootScope, $document, $compile, TemplateLoader) {
return {
/**
* Load a modal with the given template string.
*
* A new isolated scope will be created for the
* modal and the new element will be appended into the body.
*/
fromTemplate: function(templateString) {
// Create a new isolated scope for the modal
var scope = $rootScope.$new(true);
// Compile the template
var element = $compile(templateString)(scope);
$document[0].body.appendChild(element[0]);
var modal = new ionic.views.Modal({el: element[0] });
scope.modal = modal;
return modal;
},
fromTemplateUrl: function(url, cb) {
TemplateLoader.load(url).then(function(templateString) {
// Create a new isolated scope for the modal
var scope = $rootScope.$new(true);
// Compile the template
var element = $compile(templateString)(scope);
$document[0].body.appendChild(element[0]);
var modal = new ionic.views.Modal({ el: element[0] });
scope.modal = modal;
cb(modal);
});
}
};
}]);
;
angular.module('ionic.service.popup', ['ionic.service.templateLoad'])
.factory('Popup', ['$rootScope', '$document', '$compile', 'TemplateLoader', function($rootScope, $document, $compile, TemplateLoader) {
var getPopup = function() {
// Make sure there is only one loading element on the page at one point in time
var existing = angular.element($document[0].querySelector('.popup'));
if(existing.length) {
var scope = existing.scope();
if(scope.popup) {
return scope;
}
}
};
return {
alert: function(message) {
// If there is an existing popup, just show that one
var existing = getPopup();
if(existing) {
return existing.popup.alert(message);
}
var defaults = {
title: message,
animation: 'fade-in',
};
opts = angular.extend(defaults, opts);
var scope = $rootScope.$new(true);
angular.extend(scope, opts);
// Compile the template
var element = $compile('' + opts.content + '')(scope);
$document[0].body.appendChild(element[0]);
var popup = new ionic.views.Popup({el: element[0] });
popup.alert(message);
scope.popup = popup;
return popup;
},
confirm: function(cb) {
},
prompt: function(cb) {
},
show: function(data) {
// data.title
// data.template
// data.buttons
}
};
}]);
;
angular.module('ionic.service.templateLoad', [])
.factory('TemplateLoader', ['$q', '$http', '$templateCache', function($q, $http, $templateCache) {
return {
load: function(url) {
var deferred = $q.defer();
$http.get(url, { cache: $templateCache }).success(function(html) {
deferred.resolve(html && html.trim());
});
return deferred.promise;
}
};
}]);
;
(function() {
'use strict';
angular.module('ionic.ui.actionSheet', [])
.directive('actionSheet', function() {
return {
restrict: 'E',
scope: true,
replace: true,
link: function($scope, $element){
$scope.$on('$destroy', function() {
$element.remove();
});
},
template: '