Bug 1451342 - Unvendor ng-text-truncate-2 (#3393)

Since we've moving away from vendored packages.

The only differences between the vendored file and that in the NPM
package were the changes to `require('angular')` and export the
created AngularJS module. However Angular is already imported prior
to this package being imported, and we can just pass the module name
as a string instead of relying on the export.
This commit is contained in:
Ed Morley 2018-04-04 16:08:11 +01:00 коммит произвёл GitHub
Родитель 0e7d4ed854
Коммит 062317c8ee
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 7 добавлений и 159 удалений

Просмотреть файл

@ -46,6 +46,7 @@
"neutrino": "4.3.1",
"neutrino-lint-base": "4.3.1",
"neutrino-preset-react": "4.2.3",
"ng-text-truncate-2": "1.0.1",
"ngreact": "0.5.1",
"numeral": "2.0.6",
"popper.js": "1.14.2",

Просмотреть файл

@ -2,8 +2,8 @@ import angular from 'angular';
import angularClipboardModule from 'angular-clipboard';
import uiBootstrap from 'angular1-ui-bootstrap4';
import uiRouter from 'angular-ui-router';
import 'ng-text-truncate-2';
import ngTextTruncateModule from '../vendor/ng-text-truncate';
import treeherderModule from './treeherder';
export default angular.module('perf', [
@ -11,5 +11,5 @@ export default angular.module('perf', [
uiBootstrap,
treeherderModule.name,
angularClipboardModule.name,
ngTextTruncateModule.name
'ngTextTruncate'
]);

157
ui/vendor/ng-text-truncate.js поставляемый
Просмотреть файл

@ -1,157 +0,0 @@
// vendored in to use more modern module syntax, based off of:
// https://www.npmjs.com/package/ng-text-truncate-2
(function (root, factory) {
/* istanbul ignore next */
if (typeof define === 'function' && define.amd) {
define(['angular'], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('angular'));
} else {
root.ngTextTruncate = factory(root.angular);
}
}(this, function (angular) {
'use strict';
return angular.module( 'ngTextTruncate', [] )
.directive( "ngTextTruncate", [ "$compile", "ValidationServices", "CharBasedTruncation", "WordBasedTruncation",
function( $compile, ValidationServices, CharBasedTruncation, WordBasedTruncation ) {
return {
restrict: "A",
scope: {
text: "=ngTextTruncate",
charsThreshould: "@ngTtCharsThreshold",
wordsThreshould: "@ngTtWordsThreshold",
customMoreLabel: "@ngTtMoreLabel",
customLessLabel: "@ngTtLessLabel"
},
controller: ["$scope", "$element", "$attrs", function( $scope, $element, $attrs ) {
$scope.toggleShow = function() {
$scope.open = !$scope.open;
};
$scope.useToggling = $attrs.ngTtNoToggling === undefined;
}],
link: function( $scope, $element, $attrs ) {
$scope.open = false;
ValidationServices.failIfWrongThreshouldConfig( $scope.charsThreshould, $scope.wordsThreshould );
var CHARS_THRESHOLD = parseInt( $scope.charsThreshould );
var WORDS_THRESHOLD = parseInt( $scope.wordsThreshould );
$scope.$watch( "text", function() {
$element.empty();
if( CHARS_THRESHOLD ) {
if( $scope.text && CharBasedTruncation.truncationApplies( $scope, CHARS_THRESHOLD ) ) {
CharBasedTruncation.applyTruncation( CHARS_THRESHOLD, $scope, $element );
} else {
$element.append( $scope.text );
}
} else {
if( $scope.text && WordBasedTruncation.truncationApplies( $scope, WORDS_THRESHOLD ) ) {
WordBasedTruncation.applyTruncation( WORDS_THRESHOLD, $scope, $element );
} else {
$element.append( $scope.text );
}
}
} );
}
};
}] )
.factory( "ValidationServices", function() {
return {
failIfWrongThreshouldConfig: function( firstThreshould, secondThreshould ) {
if( (! firstThreshould && ! secondThreshould) || (firstThreshould && secondThreshould) ) {
throw "You must specify one, and only one, type of threshould (chars or words)";
}
}
};
})
.factory( "CharBasedTruncation", [ "$compile", function( $compile ) {
return {
truncationApplies: function( $scope, threshould ) {
return $scope.text.length > threshould;
},
applyTruncation: function( threshould, $scope, $element ) {
if( $scope.useToggling ) {
var el = angular.element( "<span>" +
$scope.text.substr( 0, threshould ) +
"<span ng-show='!open'>...</span>" +
"<span class='btn-link ngTruncateToggleText' " +
"ng-click='toggleShow()'" +
"ng-show='!open'>" +
" " + ($scope.customMoreLabel ? $scope.customMoreLabel : "More") +
"</span>" +
"<span ng-show='open'>" +
$scope.text.substring( threshould ) +
"<span class='btn-link ngTruncateToggleText'" +
"ng-click='toggleShow()'>" +
" " + ($scope.customLessLabel ? $scope.customLessLabel : "Less") +
"</span>" +
"</span>" +
"</span>" );
$compile( el )( $scope );
$element.append( el );
} else {
$element.append( $scope.text.substr( 0, threshould ) + "..." );
}
}
};
}])
.factory( "WordBasedTruncation", [ "$compile", function( $compile ) {
return {
truncationApplies: function( $scope, threshould ) {
return $scope.text.split( " " ).length > threshould;
},
applyTruncation: function( threshould, $scope, $element ) {
var splitText = $scope.text.split( " " );
if( $scope.useToggling ) {
var el = angular.element( "<span>" +
splitText.slice( 0, threshould ).join( " " ) + " " +
"<span ng-show='!open'>...</span>" +
"<span class='btn-link ngTruncateToggleText' " +
"ng-click='toggleShow()'" +
"ng-show='!open'>" +
" " + ($scope.customMoreLabel ? $scope.customMoreLabel : "More") +
"</span>" +
"<span ng-show='open'>" +
splitText.slice( threshould, splitText.length ).join( " " ) +
"<span class='btn-link ngTruncateToggleText'" +
"ng-click='toggleShow()'>" +
" " + ($scope.customLessLabel ? $scope.customLessLabel : "Less") +
"</span>" +
"</span>" +
"</span>" );
$compile( el )( $scope );
$element.append( el );
} else {
$element.append( splitText.slice( 0, threshould ).join( " " ) + "..." );
}
}
};
}]);
}));

Просмотреть файл

@ -5095,6 +5095,10 @@ neutrino@4.3.1:
webpack-dev-server "^2.4.1"
yargs "^6.6.0"
ng-text-truncate-2@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/ng-text-truncate-2/-/ng-text-truncate-2-1.0.1.tgz#167b92b04f092e940cc6d60a336fa604570392bd"
ngreact@0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/ngreact/-/ngreact-0.5.1.tgz#2dcccc1541771796689d13e51bb8d5010af41c57"