-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.umd.js
68 lines (57 loc) · 2.07 KB
/
index.umd.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tributejs/src')) :
typeof define === 'function' && define.amd ? define(['tributejs/src'], factory) :
(global.AngularTribute = factory(global.Tribute));
}(this, function (Tribute) { 'use strict';
Tribute = 'default' in Tribute ? Tribute['default'] : Tribute;
if (typeof Tribute === 'undefined') {
throw new Error('[AngularTribute] cannot locate tributejs!');
}
var AngularTribute = function AngularTribute($timeout) {
return {
restrict: 'A',
scope: {
values: '=',
options: '=',
onReplaced: '&',
onNoMatch: '&'
},
controller: ['$scope', function ($scope) {
this.$onDestroy = function () {
$scope.tribute.hideMenu();
};
}],
compile: function compile($element, $attrs) {
var _this = this;
return function ($scope, $element, $attrs) {
if (typeof $scope.options === 'array') {
$scope.tribute = new Tribute({
collection: $scope.options
});
} else {
$scope.tribute = new Tribute(angular.merge({
values: $scope.values
}, $scope.options || {}));
}
$scope.tribute.attach($element[0]);
$element[0].addEventListener("tribute-replaced", function (e) {
if (typeof $scope.onReplaced !== 'function') return;
$timeout($scope.onReplaced.apply(_this));
});
$element[0].addEventListener("tribute-no-match", function (e) {
if (typeof $scope.onNoMatch !== 'function') return;
$timeout($scope.onNoMatch.apply(_this));
});
$scope.$watch('values', function (newValues, oldValues) {
$scope.tribute.append(0, newValues, true);
});
$scope.$on('$destroy', function () {
$scope.tribute.detach($element[0]);
});
};
}
};
};
AngularTribute.$inject = ['$timeout'];
return AngularTribute;
}));