Просмотр исходного кода

Merge pull request #15383 from overleaf/jpa-remove-unused-angular-deps

[web] remove unused angular dependencies

GitOrigin-RevId: 58efeb5755b5f7d0f893e343b319bc4f1a6a3d76
Jakob Ackermann 3 лет назад
Родитель
Сommit
488825efc4

+ 2 - 2
services/web/app/src/Features/Authentication/AuthenticationManager.js

@@ -196,8 +196,8 @@ const AuthenticationManager = {
     return null
   },
 
-  // validates a password based on a similar set of rules to `complexPassword.js` on the frontend
-  // note that `passfield.js` enforces more rules than this, but these are the most commonly set.
+  // validates a password based on a similar set of rules previously used by `passfield.js` on the frontend
+  // note that `passfield.js` enforced more rules than this, but these are the most commonly set.
   // returns null on success, or an error object.
   validatePassword(password, email) {
     if (password == null) {

+ 0 - 3
services/web/frontend/js/base.js

@@ -27,11 +27,8 @@ import { configureMathJax } from './features/mathjax/configure'
 const App = angular
   .module('SharelatexApp', [
     'ui.bootstrap',
-    'autocomplete',
     'RecursionHelper',
-    'ng-context-menu',
     'ngSanitize',
-    'ipCookie',
     'ErrorCatcher',
     'localStorage',
     'sessionStorage',

+ 0 - 1
services/web/frontend/js/directives/asyncForm.js

@@ -1,5 +1,4 @@
 import App from '../base'
-import '../vendor/libs/passfield'
 App.directive('asyncForm', [
   '$http',
   'validateCaptcha',

+ 0 - 93
services/web/frontend/js/directives/complexPassword.js

@@ -1,93 +0,0 @@
-import _ from 'lodash'
-/* global PassField */
-
-/* eslint-disable
-    max-len
-*/
-import App from '../base'
-import '../vendor/libs/passfield'
-App.directive('complexPassword', function () {
-  return {
-    require: ['^asyncForm', 'ngModel'],
-
-    link(scope, element, attrs, ctrl) {
-      PassField.Config.blackList = []
-      const defaultPasswordOpts = {
-        pattern: '',
-        length: {
-          min: 6,
-          max: 72,
-        },
-        allowEmpty: false,
-        allowAnyChars: false,
-        isMasked: true,
-        showToggle: false,
-        showGenerate: false,
-        showTip: false,
-        showWarn: false,
-        checkMode: PassField.CheckModes.STRICT,
-        chars: {
-          digits: '1234567890',
-          letters: 'abcdefghijklmnopqrstuvwxyz',
-          letters_up: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
-          symbols: '@#$%^&*()-_=+[]{};:<>/?!£€.,',
-        },
-      }
-
-      const opts = _.defaults(
-        window.passwordStrengthOptions || {},
-        defaultPasswordOpts
-      )
-
-      if (opts.length.min === 1) {
-        // this allows basically anything to be a valid password
-        opts.acceptRate = 0
-      }
-
-      if (opts.length.max > 72) {
-        // there is a hard limit of 71 characters in the password at the backend
-        opts.length.max = 72
-      }
-
-      if (opts.length.max > 0) {
-        // PassField's notion of 'max' is non-inclusive
-        opts.length.max += 1
-      }
-
-      const passField = new PassField.Field('passwordField', opts)
-      const [asyncFormCtrl, ngModelCtrl] = Array.from(ctrl)
-
-      ngModelCtrl.$parsers.unshift(function (modelValue) {
-        let isValid = passField.validatePass()
-        const email = asyncFormCtrl.getEmail() || window.usersEmail
-
-        if (!isValid) {
-          scope.complexPasswordErrorMessage =
-            passField.getPassValidationMessage()
-        } else if (typeof email === 'string' && email !== '') {
-          const startOfEmail = email.split('@')[0]
-          if (
-            modelValue.indexOf(email) !== -1 ||
-            modelValue.indexOf(startOfEmail) !== -1
-          ) {
-            isValid = false
-            scope.complexPasswordErrorMessage =
-              'Password can not contain email address'
-          }
-        }
-        if (opts.length.max != null && modelValue.length >= opts.length.max) {
-          isValid = false
-          scope.complexPasswordErrorMessage = `Maximum password length ${
-            opts.length.max - 1
-          } exceeded`
-        }
-        if (opts.length.min != null && modelValue.length < opts.length.min) {
-          isValid = false
-          scope.complexPasswordErrorMessage = `Password too short, minimum ${opts.length.min}`
-        }
-        ngModelCtrl.$setValidity('complexPassword', isValid)
-        return modelValue
-      })
-    },
-  }
-})

+ 0 - 4
services/web/frontend/js/libraries.js

@@ -2,12 +2,8 @@ import 'jquery'
 import 'angular'
 import 'angular-sanitize'
 import 'lodash'
-import './vendor/libs/angular-autocomplete/angular-autocomplete'
 import './vendor/libs/ui-bootstrap'
-import './vendor/libs/ng-context-menu-0.1.4'
 import './vendor/libs/jquery.storage'
-import './vendor/libs/angular-cookie'
-import './vendor/libs/passfield'
 import './vendor/libs/select/select'
 
 // CSS

+ 0 - 2
services/web/frontend/js/main.js

@@ -16,7 +16,6 @@ import './main/scribtex-popup'
 import './main/event'
 import './main/bonus'
 import './main/system-messages'
-import './main/translations'
 import './main/annual-upgrade'
 import './main/subscription/team-invite-controller'
 import './main/learn'
@@ -24,7 +23,6 @@ import './main/keys'
 import './main/importing'
 import './directives/autoSubmitForm'
 import './directives/asyncForm'
-import './directives/complexPassword'
 import './directives/stopPropagation'
 import './directives/focus'
 import './directives/equals'

+ 0 - 34
services/web/frontend/js/main/translations.js

@@ -1,34 +0,0 @@
-import App from '../base'
-
-App.controller('TranslationsPopupController', [
-  '$scope',
-  'ipCookie',
-  'localStorage',
-  function ($scope, ipCookie, localStorage) {
-    function getStoredDismissal() {
-      const localStore = localStorage('hide-i18n-notification')
-
-      if (localStore === null) {
-        // Not stored in localStorage, check cookie
-        const cookieStore = ipCookie('hidei18nNotification')
-
-        // If stored in cookie, set on localStorage for forwards compat
-        if (cookieStore) {
-          localStorage('hide-i18n-notification', cookieStore)
-          ipCookie.remove('hidei18nNotification')
-        }
-
-        return cookieStore
-      }
-
-      return localStore
-    }
-
-    $scope.hidei18nNotification = getStoredDismissal()
-
-    $scope.dismiss = function () {
-      localStorage('hide-i18n-notification', true)
-      $scope.hidei18nNotification = true
-    }
-  },
-])

+ 0 - 18
services/web/frontend/js/vendor/libs/angular-autocomplete/ac_template.html

@@ -1,18 +0,0 @@
-<div class="autocomplete {{ attrs.class }}" id="{{ attrs.id }}">
-  <input
-    type="text"
-    ng-model="searchParam"
-    placeholder="{{ attrs.placeholder }}"
-    class="{{ attrs.inputclass }}"
-    id="{{ attrs.inputid }}"/>
-  <ul ng-show="completing">
-    <li
-      suggestion
-      ng-repeat="suggestion in suggestions | filter:searchFilter | orderBy:'toString()' track by $index"
-      index="{{ $index }}"
-      val="{{ suggestion }}"
-      ng-class="{ active: ($index === selectedIndex) }"
-      ng-click="select(suggestion)"
-      ng-bind-html="suggestion | highlight:searchParam"></li>
-  </ul>
-</div>

+ 0 - 258
services/web/frontend/js/vendor/libs/angular-autocomplete/angular-autocomplete.js

@@ -1,258 +0,0 @@
-/* --- Made by justgoscha and licensed under MIT license --- */
-
-var app = angular.module('autocomplete', []);
-
-app.directive('autocomplete', function() {
-  var index = -1;
-
-  return {
-    restrict: 'E',
-    scope: {
-      searchParam: '=ngModel',
-      suggestions: '=data',
-      onType: '=onType',
-      onSelect: '=onSelect'
-    },
-    controller: ['$scope', function($scope){
-      // the index of the suggestions that's currently selected
-      $scope.selectedIndex = -1;
-
-      // set new index
-      $scope.setIndex = function(i){
-        $scope.selectedIndex = parseInt(i);
-      };
-
-      this.setIndex = function(i){
-        $scope.setIndex(i);
-        $scope.$apply();
-      };
-
-      $scope.getIndex = function(i){
-        return $scope.selectedIndex;
-      };
-
-      // watches if the parameter filter should be changed
-      var watching = true;
-
-      // autocompleting drop down on/off
-      $scope.completing = false;
-
-      // starts autocompleting on typing in something
-      $scope.$watch('searchParam', function(newValue, oldValue){
-        if (oldValue === newValue) {
-          return;
-        }
-
-        if(watching && $scope.searchParam) {
-          $scope.completing = true;
-          $scope.searchFilter = $scope.searchParam;
-          $scope.selectedIndex = -1;
-        }
-
-        // function thats passed to on-type attribute gets executed
-        if($scope.onType)
-          $scope.onType($scope.searchParam);
-      });
-
-      // for hovering over suggestions
-      this.preSelect = function(suggestion){
-
-        watching = false;
-
-        // this line determines if it is shown
-        // in the input field before it's selected:
-        //$scope.searchParam = suggestion;
-
-        $scope.$apply();
-        watching = true;
-
-      };
-
-      $scope.preSelect = this.preSelect;
-
-      this.preSelectOff = function(){
-        watching = true;
-      };
-
-      $scope.preSelectOff = this.preSelectOff;
-
-      // selecting a suggestion with RIGHT ARROW or ENTER
-      $scope.select = function(suggestion){
-        if(suggestion){
-          $scope.searchParam = suggestion;
-          $scope.searchFilter = suggestion;
-          if($scope.onSelect)
-            $scope.onSelect(suggestion);
-        }
-        watching = false;
-        $scope.completing = false;
-        setTimeout(function(){watching = true;},1000);
-        $scope.setIndex(-1);
-      };
-
-
-    }],
-    link: function(scope, element, attrs){
-
-      var attr = '';
-
-      // Default atts
-      scope.attrs = {
-        "placeholder": "start typing...",
-        "class": "",
-        "id": "",
-        "inputclass": "",
-        "inputid": ""
-      };
-
-      for (var a in attrs) {
-        attr = a.replace('attr', '').toLowerCase();
-        // add attribute overriding defaults
-        // and preventing duplication
-        if (a.indexOf('attr') === 0) {
-          scope.attrs[attr] = attrs[a];
-        }
-      }
-
-      if (attrs.clickActivation) {
-        element[0].onclick = function(e){
-          if(!scope.searchParam){
-            scope.completing = true;
-            scope.$apply();
-          }
-        };
-      }
-
-      var key = {left: 37, up: 38, right: 39, down: 40 , enter: 13, esc: 27};
-
-      document.addEventListener("keydown", function(e){
-        var keycode = e.keyCode || e.which;
-
-        switch (keycode){
-          case key.esc:
-            // disable suggestions on escape
-            scope.select();
-            scope.setIndex(-1);
-            scope.$apply();
-            e.preventDefault();
-        }
-      }, true);
-
-      document.addEventListener("blur", function(e){
-        // disable suggestions on blur
-        // we do a timeout to prevent hiding it before a click event is registered
-        setTimeout(function() {
-          scope.select();
-          scope.setIndex(-1);
-          scope.$apply();
-        }, 200);
-      }, true);
-
-      element[0].addEventListener("keydown",function (e){
-        var keycode = e.keyCode || e.which;
-
-        var l = angular.element(this).find('li').length;
-
-        // implementation of the up and down movement in the list of suggestions
-        switch (keycode){
-          case key.up:
-
-            index = scope.getIndex()-1;
-            if(index<-1){
-              index = l-1;
-            } else if (index >= l ){
-              index = -1;
-              scope.setIndex(index);
-              scope.preSelectOff();
-              break;
-            }
-            scope.setIndex(index);
-
-            if(index!==-1)
-              scope.preSelect(angular.element(angular.element(this).find('li')[index]).text());
-
-            scope.$apply();
-
-            break;
-          case key.down:
-            index = scope.getIndex()+1;
-            if(index<-1){
-              index = l-1;
-            } else if (index >= l ){
-              index = -1;
-              scope.setIndex(index);
-              scope.preSelectOff();
-              scope.$apply();
-              break;
-            }
-            scope.setIndex(index);
-
-            if(index!==-1)
-              scope.preSelect(angular.element(angular.element(this).find('li')[index]).text());
-
-            break;
-          case key.left:
-            break;
-          case key.right:
-          case key.enter:
-
-            index = scope.getIndex();
-            // scope.preSelectOff();
-            if(index !== -1)
-              scope.select(angular.element(angular.element(this).find('li')[index]).text());
-            scope.setIndex(-1);
-            scope.$apply();
-
-            break;
-          case key.esc:
-            // disable suggestions on escape
-            scope.select();
-            scope.setIndex(-1);
-            scope.$apply();
-            e.preventDefault();
-            break;
-          default:
-            return;
-        }
-
-        if(scope.getIndex()!==-1 || keycode == key.enter)
-          e.preventDefault();
-      });
-    },
-    templateUrl: 'js/libs/angular-autocomplete/ac_template.html'
-  };
-});
-
-app.filter('highlight', ['$sce', function ($sce) {
-  return function (input, searchParam) {
-    if (typeof input === 'function') return '';
-    if (searchParam) {
-      var words = '(' +
-            searchParam.split(/\ /).join(' |') + '|' +
-            searchParam.split(/\ /).join('|') +
-          ')',
-          exp = new RegExp(words, 'gi');
-      if (words.length) {
-        input = input.replace(exp, "<span class=\"highlight\">$1</span>");
-      }
-    }
-    return $sce.trustAsHtml(input);
-  };
-}]);
-
-app.directive('suggestion', function(){
-  return {
-    restrict: 'A',
-    require: '^autocomplete', // ^look for controller on parents element
-    link: function(scope, element, attrs, autoCtrl){
-      element.bind('mouseenter', function() {
-        autoCtrl.preSelect(attrs.val);
-        autoCtrl.setIndex(attrs.index);
-      });
-
-      element.bind('mouseleave', function() {
-        autoCtrl.preSelectOff();
-      });
-    }
-  };
-});

+ 0 - 112
services/web/frontend/js/vendor/libs/angular-cookie.js

@@ -1,112 +0,0 @@
-/*
- * Copyright 2013 Ivan Pusic
- * Contributors:
- *   Matjaz Lipus
- */
- //https://github.com/ivpusic/angular-cookie/blob/master/angular-cookie.js
-angular.module('ivpusic.cookie', ['ipCookie']);
-angular.module('ipCookie', ['ng']).
-factory('ipCookie', ['$document',
-  function ($document) {
-    'use strict';
-
-    return (function () {
-      function cookieFun(key, value, options) {
-
-        var cookies,
-          list,
-          i,
-          cookie,
-          pos,
-          name,
-          hasCookies,
-          all,
-          expiresFor;
-
-        options = options || {};
-
-        if (value !== undefined) {
-          // we are setting value
-          value = typeof value === 'object' ? JSON.stringify(value) : String(value);
-
-          if (typeof options.expires === 'number') {
-            expiresFor = options.expires;
-            options.expires = new Date();
-            // Trying to delete a cookie; set a date far in the past
-            if (expiresFor === -1) {
-              options.expires = new Date('Thu, 01 Jan 1970 00:00:00 GMT');
-              // A new 
-            } else if (options.expirationUnit !== undefined) {
-              if (options.expirationUnit === 'hours') {
-                options.expires.setHours(options.expires.getHours() + expiresFor);
-              } else if (options.expirationUnit === 'minutes') {
-                options.expires.setMinutes(options.expires.getMinutes() + expiresFor);
-              } else if (options.expirationUnit === 'seconds') {
-                options.expires.setSeconds(options.expires.getSeconds() + expiresFor);
-              } else {
-                options.expires.setDate(options.expires.getDate() + expiresFor);
-              }
-            } else {
-              options.expires.setDate(options.expires.getDate() + expiresFor);
-            }
-          }
-          return ($document[0].cookie = [
-            encodeURIComponent(key),
-            '=',
-            encodeURIComponent(value),
-            options.expires ? '; expires=' + options.expires.toUTCString() : '',
-            options.path ? '; path=' + options.path : '',
-            options.domain ? '; domain=' + options.domain : '',
-            options.secure ? '; secure' : ''
-          ].join(''));
-        }
-
-        list = [];
-        all = $document[0].cookie;
-        if (all) {
-          list = all.split('; ');
-        }
-
-        cookies = {};
-        hasCookies = false;
-
-        for (i = 0; i < list.length; ++i) {
-          if (list[i]) {
-            cookie = list[i];
-            pos = cookie.indexOf('=');
-            name = cookie.substring(0, pos);
-            value = decodeURIComponent(cookie.substring(pos + 1));
-
-            if (key === undefined || key === name) {
-              try {
-                cookies[name] = JSON.parse(value);
-              } catch (e) {
-                cookies[name] = value;
-              }
-              if (key === name) {
-                return cookies[name];
-              }
-              hasCookies = true;
-            }
-          }
-        }
-        if (hasCookies && key === undefined) {
-          return cookies;
-        }
-      }
-      cookieFun.remove = function (key, options) {
-        var hasCookie = cookieFun(key) !== undefined;
-
-        if (hasCookie) {
-          if (!options) {
-            options = {};
-          }
-          options.expires = -1;
-          cookieFun(key, '', options);
-        }
-        return hasCookie;
-      };
-      return cookieFun;
-    }());
-  }
-]);

+ 0 - 108
services/web/frontend/js/vendor/libs/ng-context-menu-0.1.4.js

@@ -1,108 +0,0 @@
-/**
- * ng-context-menu - v0.1.4 - An AngularJS directive to display a context menu when a right-click event is triggered
- *
- * @author Ian Kennington Walter (http://ianvonwalter.com)
- */
-angular
-  .module('ng-context-menu', [])
-  .factory('ContextMenuService', function() {
-    return {
-      element: null,
-      menuElement: null,
-      container: null
-    };
-  })
-  .directive('contextMenu', ['$document', 'ContextMenuService', function($document, ContextMenuService) {
-    return {
-      restrict: 'A',
-      scope: {
-        'callback': '&contextMenu',
-        'disabled': '&contextMenuDisabled'
-      },
-      link: function($scope, $element, $attrs) {
-        var opened = false;
-
-        function open(event, menuElement, container) {
-          menuElement.addClass('open');
-
-          if (container) {
-            container.append(menuElement);
-          }
-
-          var doc = $document[0].documentElement;
-          var docLeft = (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0),
-            docTop = (window.pageYOffset || doc.scrollTop)  - (doc.clientTop || 0),
-            elementHeight = menuElement[0].scrollHeight;
-          var docHeight = doc.clientHeight + docTop,
-            totalHeight = elementHeight + event.pageY,
-            top = Math.max(event.pageY - docTop, 0);
-
-          if (totalHeight > docHeight) {
-            top = top - (totalHeight - docHeight);
-          }
-
-          menuElement.css('top', top + 'px');
-          menuElement.css('left', Math.max(event.pageX - docLeft, 0) + 'px');
-          opened = true;
-        }
-
-        function close(menuElement) {
-          menuElement.removeClass('open');
-          opened = false;
-        }
-
-        $element.bind('contextmenu', function(event) {
-          if (!$scope.disabled()) {
-            if (ContextMenuService.menuElement !== null) {
-              close(ContextMenuService.menuElement);
-            }
-            ContextMenuService.menuElement = angular.element(document.getElementById($attrs.target));
-            if (typeof($attrs.contextMenuContainer) != "undefined") {
-              ContextMenuService.container = angular.element($attrs.contextMenuContainer)
-            }
-            ContextMenuService.element = event.target;
-            // console.log('set', ContextMenuService.element);
-
-            event.preventDefault();
-            event.stopPropagation();
-            $scope.$apply(function() {
-              $scope.callback({ $event: event });
-              open(event, ContextMenuService.menuElement, ContextMenuService.container);
-            });
-          }
-        });
-
-        function handleKeyUpEvent(event) {
-          //console.log('keyup');
-          if (!$scope.disabled() && opened && event.keyCode === 27) {
-            $scope.$apply(function() {
-              close(ContextMenuService.menuElement);
-            });
-          }
-        }
-
-        function handleClickEvent(event) {
-          if (!$scope.disabled() &&
-            opened &&
-            (event.button !== 2 || event.target !== ContextMenuService.element)) {
-            $scope.$apply(function() {
-              close(ContextMenuService.menuElement);
-            });
-          }
-        }
-
-        $document.bind('keyup', handleKeyUpEvent);
-        // Firefox treats a right-click as a click and a contextmenu event while other browsers
-        // just treat it as a contextmenu event
-        $document.bind('click', handleClickEvent);
-        $document.bind('contextmenu', handleClickEvent);
-
-        $scope.$on('$destroy', function() {
-          //console.log('destroy');
-          $document.unbind('keyup', handleKeyUpEvent);
-          $document.unbind('click', handleClickEvent);
-          $document.unbind('contextmenu', handleClickEvent);
-        });
-      }
-    };
-  }]);

Разница между файлами не показана из-за своего большого размера
+ 0 - 1
services/web/frontend/js/vendor/libs/passfield.js


Некоторые файлы не были показаны из-за большого количества измененных файлов