Sha256: c5667e792e5a406b7e63d7b12bb1c0ba465b8771ca7b9d04a85886bc4c5c5958

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

angular.module('TryApi').directive 'url', [
  '$filter',
  '$sce'
  ($filter, $sce) ->

    link = (scope, element, attrs, ctrl) ->

      scope.isParameter = (value) ->
        if value
          return value.indexOf(':') != -1
        else
          return false

      scope.parts = scope.pattern.split('/').filter(Boolean).map (i)->
        value = if scope.isParameter(i) then '' else i
        {
          value: value,
          placeholder: i
        }

      scope.$watch 'parts', ->
        scope.url = scope.parts.map((i)->
          if i.value == '' then '0' else i.value
        ).join('/')
      , true

      scope.inputStyle = (part) ->
        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

4 entries across 4 versions & 1 rubygems

Version Path
try_api-0.1.8 app/assets/javascripts/try_api/url.directive.js.coffee
try_api-0.1.7 app/assets/javascripts/try_api/url.directive.js.coffee
try_api-0.1.6 app/assets/javascripts/try_api/url.directive.js.coffee
try_api-0.1.5 app/assets/javascripts/try_api/url.directive.js.coffee