mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-03-01 05:06:24 +00:00
91 lines
2.6 KiB
JavaScript
91 lines
2.6 KiB
JavaScript
(function() {
|
|
'use strict';
|
|
|
|
|
|
angular.module('material.components.tabs')
|
|
.controller('$mdTab', TabItemController);
|
|
|
|
function TabItemController($scope, $element, $attrs, $compile, $animate, $mdUtil, $parse, $timeout) {
|
|
var self = this;
|
|
|
|
// Properties
|
|
self.contentContainer = angular.element('<div class="md-tab-content ng-hide">');
|
|
self.hammertime = new Hammer(self.contentContainer[0]);
|
|
self.element = $element;
|
|
|
|
// Methods
|
|
self.isDisabled = isDisabled;
|
|
self.onAdd = onAdd;
|
|
self.onRemove = onRemove;
|
|
self.onSelect = onSelect;
|
|
self.onDeselect = onDeselect;
|
|
|
|
var disabledParsed = $parse($attrs.ngDisabled);
|
|
function isDisabled() {
|
|
return disabledParsed($scope.$parent);
|
|
}
|
|
|
|
/**
|
|
* Add the tab's content to the DOM container area in the tabs,
|
|
* @param contentArea the contentArea to add the content of the tab to
|
|
*/
|
|
function onAdd(contentArea, shouldDisconnectScope) {
|
|
if (self.content.length) {
|
|
self.contentContainer.append(self.content);
|
|
self.contentScope = $scope.$parent.$new();
|
|
contentArea.append(self.contentContainer);
|
|
|
|
$compile(self.contentContainer)(self.contentScope);
|
|
if (shouldDisconnectScope === true) {
|
|
$timeout(function () {
|
|
$mdUtil.disconnectScope(self.contentScope);
|
|
}, 0, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
function onRemove() {
|
|
self.hammertime.destroy();
|
|
$animate.leave(self.contentContainer).then(function() {
|
|
self.contentScope && self.contentScope.$destroy();
|
|
self.contentScope = null;
|
|
});
|
|
}
|
|
|
|
function toggleAnimationClass(rightToLeft) {
|
|
self.contentContainer[rightToLeft ? 'addClass' : 'removeClass']('md-transition-rtl');
|
|
}
|
|
|
|
function onSelect(rightToLeft) {
|
|
// Resume watchers and events firing when tab is selected
|
|
$mdUtil.reconnectScope(self.contentScope);
|
|
self.hammertime.on('swipeleft swiperight', $scope.onSwipe);
|
|
|
|
$element.addClass('active');
|
|
$element.attr('aria-selected', true);
|
|
$element.attr('tabIndex', 0);
|
|
toggleAnimationClass(rightToLeft);
|
|
$animate.removeClass(self.contentContainer, 'ng-hide');
|
|
|
|
$scope.onSelect();
|
|
}
|
|
|
|
function onDeselect(rightToLeft) {
|
|
// Stop watchers & events from firing while tab is deselected
|
|
$mdUtil.disconnectScope(self.contentScope);
|
|
self.hammertime.off('swipeleft swiperight', $scope.onSwipe);
|
|
|
|
$element.removeClass('active');
|
|
$element.attr('aria-selected', false);
|
|
// Only allow tabbing to the active tab
|
|
$element.attr('tabIndex', -1);
|
|
toggleAnimationClass(rightToLeft);
|
|
$animate.addClass(self.contentContainer, 'ng-hide');
|
|
|
|
$scope.onDeselect();
|
|
}
|
|
|
|
}
|
|
|
|
})();
|