<commit_before>goog.provide('ngeo_btngroup_directive');

goog.require('ngeo');


/**
 * This directive allows creating "toggle" groups. It works with the `ngeo-btn`
 * directive.
 *
 * Example:
 *
 * <div ngeo-btn-group>
 *   <button ngeo-btn class="btn" ng-model="ctrl.drawPoint.active"></button>
 *   <button ngeo-btn class="btn" ng-model="ctrl.drawLine.active"></button>
 * </div>
 *
 * In that example the `ngeo-btn` are combined together in a "toggle group",
 * where activating a button will deactivate the others.
 *
 * See the `ngeo-btn` directive for more information.
 */
ngeoModule.directive('ngeoBtnGroup', [
  /**
   */
  function() {
    return {
      restrict: 'A',
      controller: ['$scope',
        function($scope) {
          /** @type {Array.<function(!angular.Scope, boolean)>} */
          var buttons = [];

          /**
           * @param {number} index Index of the button in buttons array.
           */
          this.activate = function(index) {
            goog.array.forEach(buttons,
                function(s, i) {
                  if (i != index) {
                    s($scope, false);
                  }
                });
          };

          /**
           * @param {function((!angular.Scope), *)} ngModelSet Setter.
           * @return {number} Index of the pushed setter.
           */
          this.addButton = function(ngModelSet) {
            buttons.push(ngModelSet);
            return buttons.length - 1;
          };
        }
      ]
    };
  }]);


/**
 * This directive allows creating toggle buttons working with `ng-model`.
 * To be typically used with Bootstrap buttons (`btn`).
 *
 * Example:
 *
 * <button ngeo-btn class="btn" ng-model="ctrl.interaction.active"></button>
 *
 * This example is about creating a Bootstrap button that can pressed/depressed
 * to activate/deactivate an OpenLayers 3 interaction.
 *
 * The `ngeo-btn` directive can be used alone, as in the above example, or
 * together with the `ngeo-btn-group` directive.
 *
 * Example:
 *
 * <div ngeo-btn-group>
 *   <button ngeo-btn class="btn" ng-model="ctrl.drawPoint.active"></button>
 *   <button ngeo-btn class="btn" ng-model="ctrl.drawLine.active"></button>
 * </div>
 *
 * In that example the `ngeo-btn` are combined together in a "toggle group",
 * where activating a button will deactivate the others.
 */
ngeoModule.directive('ngeoBtn', ['$parse',
  /**
   */
  function($parse) {
    return {
      require: ['?^ngeoBtnGroup', 'ngModel'],
      restrict: 'A',
      link:
          /**
           * @param {angular.Scope} scope Scope.
           * @param {angular.JQLite} element Element.
           * @param {angular.Attributes} attrs Attributes.<commit_msg>Better typing for ngeo-btn and ngeo-btn-group<commit_after>goog.provide('ngeo_btngroup_directive');

goog.require('ngeo');


/**
 * This directive allows creating "toggle" groups. It works with the `ngeo-btn`
 * directive.
 *
 * Example:
 *
 * <div ngeo-btn-group>
 *   <button ngeo-btn class="btn" ng-model="ctrl.drawPoint.active"></button>
 *   <button ngeo-btn class="btn" ng-model="ctrl.drawLine.active"></button>
 * </div>
 *
 * In that example the `ngeo-btn` are combined together in a "toggle group",
 * where activating a button will deactivate the others.
 *
 * See the `ngeo-btn` directive for more information.
 */
ngeoModule.directive('ngeoBtnGroup', [
  /**
   * @return {angular.Directive} The directive specs.
   */
  function() {
    return {
      restrict: 'A',
      controller: 'ngeoBtnGroupController'
    };
  }]);

ngeoModule.controller('ngeoBtnGroupController', ['$scope',
  /**
   * @param {angular.Scope} $scope Scope.
   */
  function($scope) {
    /** @type {Array.<function(!angular.Scope, boolean)>} */
    var buttons = [];

    /**
     * @param {number} index Index of the button in buttons array.
     */
    this.activate = function(index) {
      goog.array.forEach(buttons,
          function(s, i) {
            if (i != index) {
              s($scope, false);
            }
          });
    };

    /**
     * @param {function((!angular.Scope), *)} ngModelSet Setter.
     * @return {number} Index of the pushed setter.
     */
    this.addButton = function(ngModelSet) {
      buttons.push(ngModelSet);
      return buttons.length - 1;
    };
  }]);


/**
 * This directive allows creating toggle buttons working with `ng-model`.
 * To be typically used with Bootstrap buttons (`btn`).
 *
 * Example:
 *
 * <button ngeo-btn class="btn" ng-model="ctrl.interaction.active"></button>
 *
 * This example is about creating a Bootstrap button that can pressed/depressed
 * to activate/deactivate an OpenLayers 3 interaction.
 *
 * The `ngeo-btn` directive can be used alone, as in the above example, or
 * together with the `ngeo-btn-group` directive.
 *
 * Example:
 *
 * <div ngeo-btn-group>
 *   <button ngeo-btn class="btn" ng-model="ctrl.drawPoint.active"></button>
 *   <button ngeo-btn class="btn" ng-model="ctrl.drawLine.active"></button>
 * </div>
 *
 * In that example the `ngeo-btn` are combined together in a "toggle group",
 * where activating a button will deactivate the others.
 */
ngeoModule.directive('ngeoBtn', ['$parse',
  /**
   * @return {angular.Directive} The directive specs.
   */
  function($parse) {
    return {
      require: ['?^ngeoBtnGroup', 'ngModel'],
      restrict: 'A',
      link:
          /**
           * @param {angular.Scope} scope Scope.
           * @param {angular.JQLite} element Element.
           * @param {angular.Attributes} attrs Attributes.
{'fraction_non_alphanumeric': 0.14737222322557342, 'fraction_numerical': 0.0007224128589488893, 'mean_word_length': 2.5844660194174756, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5801390', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1662, 'n_words': 448}