Commit 4ec59e82 by Torkel Ödegaard

Tech: cleanup unused angular-strap directives, Closes #1029

parent 1e6a5ff8
...@@ -26,7 +26,7 @@ function (angular, $, _) { ...@@ -26,7 +26,7 @@ function (angular, $, _) {
template += '</div>'; template += '</div>';
template += '<div class="panel-menu-row">'; template += '<div class="panel-menu-row">';
template += '<a class="panel-menu-link" bs-dropdown="extendedMenu"><i class="icon-th-list"></i></a>'; template += '<a class="panel-menu-link" gf-dropdown="extendedMenu"><i class="icon-th-list"></i></a>';
_.each($scope.panelMeta.menu, function(item) { _.each($scope.panelMeta.menu, function(item) {
template += '<a class="panel-menu-link" '; template += '<a class="panel-menu-link" ';
......
...@@ -75,8 +75,8 @@ function (angular, app, _, moment, kbn) { ...@@ -75,8 +75,8 @@ function (angular, app, _, moment, kbn) {
// Date picker needs the date to be at the start of the day // Date picker needs the date to be at the start of the day
if(new Date().getTimezoneOffset() < 0) { if(new Date().getTimezoneOffset() < 0) {
$scope.temptime.from.date = moment($scope.temptime.from.date).add('days',1).toDate(); $scope.temptime.from.date = moment($scope.temptime.from.date).add(1, 'days').toDate();
$scope.temptime.to.date = moment($scope.temptime.to.date).add('days',1).toDate(); $scope.temptime.to.date = moment($scope.temptime.to.date).add(1, 'days').toDate();
} }
$scope.appEvent('show-dash-editor', {src: 'app/panels/timepicker/custom.html', scope: $scope }); $scope.appEvent('show-dash-editor', {src: 'app/panels/timepicker/custom.html', scope: $scope });
......
...@@ -14,235 +14,6 @@ angular.module('$strap', [ ...@@ -14,235 +14,6 @@ angular.module('$strap', [
'$strap.config' '$strap.config'
]); ]);
'use strict'; 'use strict';
angular.module('$strap.directives').directive('bsAlert', [
'$parse',
'$timeout',
'$compile',
function ($parse, $timeout, $compile) {
return {
restrict: 'A',
link: function postLink(scope, element, attrs) {
var getter = $parse(attrs.bsAlert), setter = getter.assign, value = getter(scope);
var closeAlert = function closeAlertFn(delay) {
$timeout(function () {
element.alert('close');
}, delay * 1);
};
if (!attrs.bsAlert) {
if (angular.isUndefined(attrs.closeButton) || attrs.closeButton !== '0' && attrs.closeButton !== 'false') {
element.prepend('<button type="button" class="close" data-dismiss="alert">&times;</button>');
}
if (attrs.closeAfter)
closeAlert(attrs.closeAfter);
} else {
scope.$watch(attrs.bsAlert, function (newValue, oldValue) {
value = newValue;
element.html((newValue.title ? '<strong>' + newValue.title + '</strong>&nbsp;' : '') + newValue.content || '');
if (!!newValue.closed) {
element.hide();
}
$compile(element.contents())(scope);
if (newValue.type || oldValue.type) {
oldValue.type && element.removeClass('alert-' + oldValue.type);
newValue.type && element.addClass('alert-' + newValue.type);
}
if (angular.isDefined(newValue.closeAfter))
closeAlert(newValue.closeAfter);
else if (attrs.closeAfter)
closeAlert(attrs.closeAfter);
if (angular.isUndefined(attrs.closeButton) || attrs.closeButton !== '0' && attrs.closeButton !== 'false') {
element.prepend('<button type="button" class="close" data-dismiss="alert">&times;</button>');
}
}, true);
}
element.addClass('alert').alert();
if (element.hasClass('fade')) {
element.removeClass('in');
setTimeout(function () {
element.addClass('in');
});
}
var parentArray = attrs.ngRepeat && attrs.ngRepeat.split(' in ').pop();
element.on('close', function (ev) {
var removeElement;
if (parentArray) {
ev.preventDefault();
element.removeClass('in');
removeElement = function () {
element.trigger('closed');
if (scope.$parent) {
scope.$parent.$apply(function () {
var path = parentArray.split('.');
var curr = scope.$parent;
for (var i = 0; i < path.length; ++i) {
if (curr) {
curr = curr[path[i]];
}
}
if (curr) {
curr.splice(scope.$index, 1);
}
});
}
};
$.support.transition && element.hasClass('fade') ? element.on($.support.transition.end, removeElement) : removeElement();
} else if (value) {
ev.preventDefault();
element.removeClass('in');
removeElement = function () {
element.trigger('closed');
scope.$apply(function () {
value.closed = true;
});
};
$.support.transition && element.hasClass('fade') ? element.on($.support.transition.end, removeElement) : removeElement();
} else {
}
});
}
};
}
]);
'use strict';
angular.module('$strap.directives').directive('bsButton', [
'$parse',
'$timeout',
function ($parse, $timeout) {
return {
restrict: 'A',
require: '?ngModel',
link: function postLink(scope, element, attrs, controller) {
if (controller) {
if (!element.parent('[data-toggle="buttons-checkbox"], [data-toggle="buttons-radio"]').length) {
element.attr('data-toggle', 'button');
}
var startValue = !!scope.$eval(attrs.ngModel);
if (startValue) {
element.addClass('active');
}
scope.$watch(attrs.ngModel, function (newValue, oldValue) {
var bNew = !!newValue, bOld = !!oldValue;
if (bNew !== bOld) {
$.fn.button.Constructor.prototype.toggle.call(button);
} else if (bNew && !startValue) {
element.addClass('active');
}
});
}
if (!element.hasClass('btn')) {
element.on('click.button.data-api', function (ev) {
element.button('toggle');
});
}
element.button();
var button = element.data('button');
button.toggle = function () {
if (!controller) {
return $.fn.button.Constructor.prototype.toggle.call(this);
}
var $parent = element.parent('[data-toggle="buttons-radio"]');
if ($parent.length) {
element.siblings('[ng-model]').each(function (k, v) {
$parse($(v).attr('ng-model')).assign(scope, false);
});
scope.$digest();
if (!controller.$modelValue) {
controller.$setViewValue(!controller.$modelValue);
scope.$digest();
}
} else {
scope.$apply(function () {
controller.$setViewValue(!controller.$modelValue);
});
}
};
}
};
}
]).directive('bsButtonsCheckbox', [
'$parse',
function ($parse) {
return {
restrict: 'A',
require: '?ngModel',
compile: function compile(tElement, tAttrs, transclude) {
tElement.attr('data-toggle', 'buttons-checkbox').find('a, button').each(function (k, v) {
$(v).attr('bs-button', '');
});
}
};
}
]).directive('bsButtonsRadio', [
'$timeout',
function ($timeout) {
return {
restrict: 'A',
require: '?ngModel',
compile: function compile(tElement, tAttrs, transclude) {
tElement.attr('data-toggle', 'buttons-radio');
if (!tAttrs.ngModel) {
tElement.find('a, button').each(function (k, v) {
$(v).attr('bs-button', '');
});
}
return function postLink(scope, iElement, iAttrs, controller) {
if (controller) {
$timeout(function () {
iElement.find('[value]').button().filter('[value="' + controller.$viewValue + '"]').addClass('active');
});
iElement.on('click.button.data-api', function (ev) {
scope.$apply(function () {
controller.$setViewValue($(ev.target).closest('button').attr('value'));
});
});
scope.$watch(iAttrs.ngModel, function (newValue, oldValue) {
if (newValue !== oldValue) {
var $btn = iElement.find('[value="' + scope.$eval(iAttrs.ngModel) + '"]');
if ($btn.length) {
$btn.button('toggle');
}
}
});
}
};
}
};
}
]);
'use strict';
angular.module('$strap.directives').directive('bsButtonSelect', [
'$parse',
'$timeout',
function ($parse, $timeout) {
return {
restrict: 'A',
require: '?ngModel',
link: function postLink(scope, element, attrs, ctrl) {
var getter = $parse(attrs.bsButtonSelect), setter = getter.assign;
if (ctrl) {
element.text(scope.$eval(attrs.ngModel));
scope.$watch(attrs.ngModel, function (newValue, oldValue) {
element.text(newValue);
});
}
var values, value, index, newValue;
element.bind('click', function (ev) {
values = getter(scope);
value = ctrl ? scope.$eval(attrs.ngModel) : element.text();
index = values.indexOf(value);
newValue = index > values.length - 2 ? values[0] : values[index + 1];
scope.$apply(function () {
element.text(newValue);
if (ctrl) {
ctrl.$setViewValue(newValue);
}
});
});
}
};
}
]);
'use strict';
angular.module('$strap.directives').directive('bsDatepicker', [ angular.module('$strap.directives').directive('bsDatepicker', [
'$timeout', '$timeout',
'$strapConfig', '$strapConfig',
...@@ -379,46 +150,6 @@ angular.module('$strap.directives').directive('bsDatepicker', [ ...@@ -379,46 +150,6 @@ angular.module('$strap.directives').directive('bsDatepicker', [
} }
]); ]);
'use strict'; 'use strict';
angular.module('$strap.directives').directive('bsDropdown', [
'$parse',
'$compile',
'$timeout',
function ($parse, $compile, $timeout) {
var buildTemplate = function (items, ul) {
if (!ul)
ul = [
'<ul class="dropdown-menu" role="menu" aria-labelledby="drop1">',
'</ul>'
];
angular.forEach(items, function (item, index) {
if (item.divider)
return ul.splice(index + 1, 0, '<li class="divider"></li>');
var li = '<li' + (item.submenu && item.submenu.length ? ' class="dropdown-submenu"' : '') + '>' + '<a tabindex="1" ng-href="' + (item.href || '') + '"' + (item.click ? '" ng-click="' + item.click + '"' : '') + (item.target ? '" target="' + item.target + '"' : '') + (item.method ? ' data-method="' + item.method + '"' : '') + '>' + (item.text || '') + '</a>';
if (item.submenu && item.submenu.length)
li += buildTemplate(item.submenu).join('\n');
li += '</li>';
ul.splice(index + 1, 0, li);
});
return ul;
};
return {
restrict: 'EA',
scope: true,
link: function postLink(scope, iElement, iAttrs) {
var getter = $parse(iAttrs.bsDropdown), items = getter(scope);
$timeout(function () {
if (!angular.isArray(items)) {
}
var dropdown = angular.element(buildTemplate(items).join(''));
dropdown.insertAfter(iElement);
$compile(iElement.next('ul.dropdown-menu'))(scope);
});
iElement.addClass('dropdown-toggle').attr('data-toggle', 'dropdown');
}
};
}
]);
'use strict';
angular.module('$strap.directives').factory('$modal', [ angular.module('$strap.directives').factory('$modal', [
'$rootScope', '$rootScope',
'$compile', '$compile',
...@@ -483,183 +214,7 @@ angular.module('$strap.directives').factory('$modal', [ ...@@ -483,183 +214,7 @@ angular.module('$strap.directives').factory('$modal', [
}; };
return ModalFactory; return ModalFactory;
} }
]).directive('bsModal', [ ])
'$q',
'$modal',
function ($q, $modal) {
return {
restrict: 'A',
scope: true,
link: function postLink(scope, iElement, iAttrs, controller) {
var options = {
template: scope.$eval(iAttrs.bsModal),
persist: true,
show: false,
scope: scope
};
angular.forEach([
'modalClass',
'backdrop',
'keyboard'
], function (key) {
if (angular.isDefined(iAttrs[key]))
options[key] = iAttrs[key];
});
$q.when($modal(options)).then(function onSuccess(modal) {
iElement.attr('data-target', '#' + modal.attr('id')).attr('data-toggle', 'modal');
});
}
};
}
]);
'use strict';
angular.module('$strap.directives').directive('bsNavbar', [
'$location',
function ($location) {
return {
restrict: 'A',
link: function postLink(scope, element, attrs, controller) {
scope.$watch(function () {
return $location.path();
}, function (newValue, oldValue) {
$('li[data-match-route]', element).each(function (k, li) {
var $li = angular.element(li), pattern = $li.attr('data-match-route'), regexp = new RegExp('^' + pattern + '$', ['i']);
if (regexp.test(newValue)) {
$li.addClass('active').find('.collapse.in').collapse('hide');
} else {
$li.removeClass('active');
}
});
});
}
};
}
]);
'use strict';
angular.module('$strap.directives').directive('bsPopover', [
'$parse',
'$compile',
'$http',
'$timeout',
'$q',
'$templateCache',
function ($parse, $compile, $http, $timeout, $q, $templateCache) {
$('body').on('keyup', function (ev) {
if (ev.keyCode === 27) {
$('.popover.in').each(function () {
$(this).popover('hide');
});
}
});
return {
restrict: 'A',
scope: true,
link: function postLink(scope, element, attr, ctrl) {
var getter = $parse(attr.bsPopover), setter = getter.assign, value = getter(scope), options = {};
if (angular.isObject(value)) {
options = value;
}
$q.when(options.content || $templateCache.get(value) || $http.get(value, { cache: true })).then(function onSuccess(template) {
if (angular.isObject(template)) {
template = template.data;
}
if (!!attr.unique) {
element.on('show', function (ev) {
$('.popover.in').each(function () {
var $this = $(this), popover = $this.data('popover');
if (popover && !popover.$element.is(element)) {
$this.popover('hide');
}
});
});
}
if (!!attr.hide) {
scope.$watch(attr.hide, function (newValue, oldValue) {
if (!!newValue) {
popover.hide();
} else if (newValue !== oldValue) {
popover.show();
}
});
}
if (!!attr.show) {
scope.$watch(attr.show, function (newValue, oldValue) {
if (!!newValue) {
$timeout(function () {
popover.show();
});
} else if (newValue !== oldValue) {
popover.hide();
}
});
}
element.popover(angular.extend({}, options, {
content: template,
html: true
}));
var popover = element.data('popover');
popover.hasContent = function () {
return this.getTitle() || template;
};
popover.getPosition = function () {
var r = $.fn.popover.Constructor.prototype.getPosition.apply(this, arguments);
$compile(this.$tip)(scope);
scope.$digest();
this.$tip.data('popover', this);
return r;
};
scope.$popover = function (name) {
popover(name);
};
angular.forEach([
'show',
'hide'
], function (name) {
scope[name] = function () {
popover[name]();
};
});
scope.dismiss = scope.hide;
angular.forEach([
'show',
'shown',
'hide',
'hidden'
], function (name) {
element.on(name, function (ev) {
scope.$emit('popover-' + name, ev);
});
});
});
}
};
}
]);
'use strict';
angular.module('$strap.directives').directive('bsSelect', [
'$timeout',
function ($timeout) {
var NG_OPTIONS_REGEXP = /^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+for\s+(?:([\$\w][\$\w\d]*)|(?:\(\s*([\$\w][\$\w\d]*)\s*,\s*([\$\w][\$\w\d]*)\s*\)))\s+in\s+(.*)$/;
return {
restrict: 'A',
require: '?ngModel',
link: function postLink(scope, element, attrs, controller) {
var options = scope.$eval(attrs.bsSelect) || {};
$timeout(function () {
element.selectpicker(options);
element.next().removeClass('ng-scope');
});
if (controller) {
scope.$watch(attrs.ngModel, function (newValue, oldValue) {
if (!angular.equals(newValue, oldValue)) {
element.selectpicker('refresh');
}
});
}
}
};
}
]);
'use strict'; 'use strict';
angular.module('$strap.directives').directive('bsTabs', [ angular.module('$strap.directives').directive('bsTabs', [
'$parse', '$parse',
...@@ -731,45 +286,6 @@ angular.module('$strap.directives').directive('bsTabs', [ ...@@ -731,45 +286,6 @@ angular.module('$strap.directives').directive('bsTabs', [
} }
]); ]);
'use strict'; 'use strict';
angular.module('$strap.directives').directive('bsTimepicker', [
'$timeout',
'$strapConfig',
function ($timeout, $strapConfig) {
var TIME_REGEXP = '((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\\s?(?:am|AM|pm|PM))?)';
return {
restrict: 'A',
require: '?ngModel',
link: function postLink(scope, element, attrs, controller) {
if (controller) {
element.on('changeTime.timepicker', function (ev) {
$timeout(function () {
controller.$setViewValue(element.val());
});
});
var timeRegExp = new RegExp('^' + TIME_REGEXP + '$', ['i']);
controller.$parsers.unshift(function (viewValue) {
if (!viewValue || timeRegExp.test(viewValue)) {
controller.$setValidity('time', true);
return viewValue;
} else {
controller.$setValidity('time', false);
return;
}
});
}
element.attr('data-toggle', 'timepicker');
element.parent().addClass('bootstrap-timepicker');
element.timepicker($strapConfig.timepicker || {});
var timepicker = element.data('timepicker');
var component = element.siblings('[data-toggle="timepicker"]');
if (component.length) {
component.on('click', $.proxy(timepicker.showWidget, timepicker));
}
}
};
}
]);
'use strict';
angular.module('$strap.directives').directive('bsTooltip', [ angular.module('$strap.directives').directive('bsTooltip', [
'$parse', '$parse',
'$compile', '$compile',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment