Sha256: c7deecb5f98f4acdfddc86d9193816d67e949cd47ba7f0c472784931fb8177e9

Contents?: true

Size: 1.62 KB

Versions: 10

Compression:

Stored size: 1.62 KB

Contents

angular.module('TryApi').directive('url', [
  '$filter', '$sce', function($filter, $sce) {
    var link;
    link = function(scope, element, attrs, ctrl) {
      scope.isParameter = function(value) {
        if (value) {
          return value.indexOf(':') !== -1;
        } else {
          return false;
        }
      };
      scope.parts = scope.pattern.split('/').filter(Boolean).map(function(i) {
        var value;
        value = scope.isParameter(i) ? '' : i;
        return {
          value: value,
          placeholder: i
        };
      });
      scope.$watch('parts', function() {
        return scope.url = scope.parts.map(function(i) {
          if (i.value === '') {
            return '0';
          } else {
            return i.value;
          }
        }).join('/');
      }, true);
      return scope.inputStyle = function(part) {
        var charWidth;
        charWidth = 11.5;
        return {
          "width": (part.value.length + 1) * charWidth + "px",
          "min-width": part.placeholder.length * charWidth + "px"
        };
      };
    };
    return {
      link: link,
      restrict: 'A',
      require: 'ngModel',
      scope: {
        url: '=ngModel',
        pattern: '=pattern'
      },
      template: '' +
        '<span ng-repeat="part in parts track by $index">' +
          '/' +
          '<span ng-if="!isParameter(part.placeholder)">{{ part.value }}</span>' +
          '<input ng-if="isParameter(part.placeholder)" ng-model="part.value" class="url-input" ng-style="inputStyle(part)" placeholder="{{ part.placeholder }}" scope="max-width: 90%; font-family:monospace;"/>' +
        '</span>'
    };
  }
]);

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
try_api-0.1.18 app/assets/javascripts/try_api/url.directive.js
try_api-0.1.17 app/assets/javascripts/try_api/url.directive.js
try_api-0.1.16 app/assets/javascripts/try_api/url.directive.js
try_api-0.1.15 app/assets/javascripts/try_api/url.directive.js
try_api-0.1.14 app/assets/javascripts/try_api/url.directive.js
try_api-0.1.13 app/assets/javascripts/try_api/url.directive.js
try_api-0.1.12 app/assets/javascripts/try_api/url.directive.js
try_api-0.1.11 app/assets/javascripts/try_api/url.directive.js
try_api-0.1.10 app/assets/javascripts/try_api/url.directive.js
try_api-0.1.9 app/assets/javascripts/try_api/url.directive.js