IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Angular Discussion :

[Angular 2] Inclure un fichier js externe


Sujet :

Angular

  1. #1
    Membre éclairé
    Homme Profil pro
    Symfony - CMS Wordpress - Zend
    Inscrit en
    Septembre 2011
    Messages
    306
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Symfony - CMS Wordpress - Zend
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2011
    Messages : 306
    Par défaut [Angular 2] Inclure un fichier js externe
    Bonjour,

    Au cours de mon développement d'un site cote client avec Angular2.
    Pour une raison ou pour un autre inclure des fichiers js..
    je suis donc confronter a recoder ou a inclure ce fichier JS.

    voici mon fichier JS qui utilise une libraire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    var colors = [
      ['#ced7df', '#9E290D'], ['#ced7df', '#FF6E2E'], ['#ced7df', '#9E290D'], ['#ced7df', '#FF6E2E'],
      ['#ced7df', '#FF6E2E'], ['#ced7df', '#9E290D'],['#ced7df', '#FF6E2E'], ['#ced7df', '#9E290D'],
      ['#ced7df', '#9E290D'], ['#ced7df', '#FF6E2E'], ['#ced7df', '#9E290D'], ['#ced7df', '#FF6E2E'],
      ['#ced7df', '#FF6E2E'], ['#ced7df', '#9E290D'],['#ced7df', '#FF6E2E'], ['#ced7df', '#9E290D'],
     
    ];
    var i = 1;
    var child = document.getElementById('circles-' + i),
      percentage = 65 ;
     
    Circles.create({
      id:         child.id,
      percentage: percentage,
      radius:     80,
      width:      10,
      number:   	percentage,
      text:       '%',
      colors:     colors[i - 1]
    });
    var i = 2;
    var child = document.getElementById('circles-' + i),
      percentage = 70;
     
    Circles.create({
      id:         child.id,
      percentage: percentage,
      radius:     80,
      width:      10,
      number:   	percentage,
      text:       '%',
      colors:     colors[i - 1]
    });
    var i = 3;
    var child = document.getElementById('circles-' + i),
      percentage = 80;
     
    Circles.create({
      id:         child.id,
      percentage: percentage,
      radius:     80,
      width:      10,
      number:   	percentage,
      text:       '%',
      colors:     colors[i - 1]
    });
    var i = 4;
    var child = document.getElementById('circles-' + i),
      percentage = 83;
     
    Circles.create({
      id:         child.id,
      percentage: percentage,
      radius:     80,
      width:      10,
      number:   	percentage,
      text:       '%',
      colors:     colors[i - 1]
    });
    var i = 5;
    var child = document.getElementById('circles-' + i),
      percentage = 85;
     
    Circles.create({
      id:         child.id,
      percentage: percentage,
      radius:     80,
      width:      10,
      number:   	percentage,
      text:       '%',
      colors:     colors[i - 1]
    });
    var i = 6;
    var child = document.getElementById('circles-' + i),
      percentage = 65;
     
    Circles.create({
      id:         child.id,
      percentage: percentage,
      radius:     80,
      width:      10,
      number:   	percentage,
      text:       '%',
      colors:     colors[i - 1]
    });
    var i = 7;
    var child = document.getElementById('circles-' + i),
      percentage = 75;
     
    Circles.create({
      id:         child.id,
      percentage: percentage,
      radius:     80,
      width:      10,
      number:   	percentage,
      text:       '%',
      colors:     colors[i - 1]
    });
    var i = 8;
    var child = document.getElementById('circles-' + i),
      percentage = 85;
     
    Circles.create({
      id:         child.id,
      percentage: percentage,
      radius:     80,
      width:      10,
      number:   	percentage,
      text:       '%',
      colors:     colors[i - 1]
    });
    var i = 9;
    var child = document.getElementById('circles-' + i),
      percentage = 86;
     
    Circles.create({
      id:         child.id,
      percentage: percentage,
      radius:     80,
      width:      10,
      number:   	percentage,
      text:       '%',
      colors:     colors[i - 1]
    });
    var i = 10;
    var child = document.getElementById('circles-' + i),
      percentage = 75;
     
    Circles.create({
      id:         child.id,
      percentage: percentage,
      radius:     80,
      width:      10,
      number:   	percentage,
      text:       '%',
      colors:     colors[i - 1]
    });
    var i = 11;
    var child = document.getElementById('circles-' + i),
      percentage = 75;
     
    Circles.create({
      id:         child.id,
      percentage: percentage,
      radius:     80,
      width:      10,
      number:   	percentage,
      text:       '%',
      colors:     colors[i - 1]
    });
    var i = 12;
    var child = document.getElementById('circles-' + i),
      percentage = 70;
     
    Circles.create({
      id:         child.id,
      percentage: percentage,
      radius:     80,
      width:      10,
      number:   	percentage,
      text:       '%',
      colors:     colors[i - 1]
    });
    var i = 13;
    var child = document.getElementById('circles-' + i),
      percentage = 69;
     
    Circles.create({
      id:         child.id,
      percentage: percentage,
      radius:     80,
      width:      10,
      number:   	percentage,
      text:       '%',
      colors:     colors[i - 1]
    });
     
     
     
    /*for (var i = 1; i <= 5; i++) {
     var child = document.getElementById('circles-' + i),
     percentage = 50 + (i * 10);
     
     Circles.create({
     id:         child.id,
     percentage: percentage,
     radius:     80,
     width:      10,
     number:   	percentage,
     text:       '%',
     colors:     colors[i - 1]
     });
     }*/
    la libraire est :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    // circles
    // copyright Artan Sinani
    // https://github.com/lugolabs/circles
     
    /*
      Lightwheight JavaScript library that generates circular graphs in SVG.
     
      Call Circles.create(options) with the following options:
     
        id         - the DOM element that will hold the graph
        percentage - the percentage dictating the smaller circle
        radius     - the radius of the circles
        width      - the width of the ring (optional, has value 10, if not specified)
        number     - the number to display at the centre of the graph (optional, the percentage will show if not specified)
        text       - the text to display after the number (optional, nothing will show if not specified)
        colors     - an array of colors, with the first item coloring the full circle
                     (optional, it will be `['#EEE', '#F00']` if not specified)
        duration   - value in ms of animation duration; (optional, defaults to 500);
                     if `null` is passed, the animation will not run
     
      API:
        generate(radius) - regenerates the circle with the given radius (see spec/responsive.html for an example hot to create a responsive circle)
     
    */
     
    (function() {
      var Circles = window.Circles = function(options) {
        var elId = options.id;
        this._el = document.getElementById(elId);
     
        if (this._el === null) return;
     
     
        this._radius         = options.radius;
        this._percentage     = options.percentage;
        this._text           = options.text; // #3
        this._number         = options.number || this._percentage;
        this._strokeWidth    = options.width  || 10;
        this._colors         = options.colors || ['#EEE', '#F00'];
        this._interval       = 16;
        this._textWrpClass   = 'circles-text-wrp';
        this._textClass      = 'circles-text';
        this._numberClass    = 'circles-number';
     
        this._confirmAnimation(options.duration);
     
        var endAngleRad      = Math.PI / 180 * 270;
        this._start          = -Math.PI / 180 * 90;
        this._startPrecise   = this._precise(this._start);
        this._circ           = endAngleRad - this._start;
     
        this.generate();
     
        if (this._canAnimate) this._animate();
      };
     
      Circles.prototype = {
        VERSION: '0.0.4',
     
        generate: function(radius) {
          if (radius) {
            this._radius = radius;
            this._canAnimate = false;
          }
          this._svgSize        = this._radius * 2;
          this._radiusAdjusted = this._radius - (this._strokeWidth / 2);
          this._el.innerHTML   = this._wrap(this._generateSvg() + this._generateText());
        },
     
        _confirmAnimation: function(duration) {
          if (duration === null) {
            this._canAnimate = false;
            return;
          }
     
          duration = duration || 500;
     
          var step     = duration / this._interval,
            pathFactor = this._percentage / step,
            numberFactor = this._number / step;
     
          if (this._percentage <= (1 + pathFactor)) {
            this._canAnimate = false;
          } else {
            this._canAnimate   = true;
            this._pathFactor   = pathFactor;
            this._numberFactor = numberFactor;
          }
        },
     
        _animate: function() {
          var i      = 1,
            self     = this,
            path     = this._el.getElementsByTagName('path')[1],
            numberEl = this._getNumberElement(),
     
            isInt    = this._number % 1 === 0,
     
            requestAnimFrame = window.requestAnimationFrame       ||
                               window.webkitRequestAnimationFrame ||
                               window.mozRequestAnimationFrame    ||
                               window.oRequestAnimationFrame      ||
                               window.msRequestAnimationFrame     ||
                               function (callback) {
                                   setTimeout(callback, self._interval);
                               },
     
            animate = function() {
              var percentage   = self._pathFactor * i,
                nextPercentage = self._pathFactor * (i + 1),
                number         = self._numberFactor * i,
                canContinue    = true;
              if (isInt) {
                number = Math.round(number);
              }
              if (nextPercentage > self._percentage) {
                percentage  = self._percentage;
                number      = self._number;
                canContinue = false;
              }
              if (percentage > self._percentage) return;
              path.setAttribute('d', self._calculatePath(percentage, true));
              numberEl.innerHTML = self._calculateNumber(number);
              i++;
              if (canContinue) requestAnimFrame(animate);
            };
     
          requestAnimFrame(animate);
        },
     
        _getNumberElement: function() {
          var divs = this._el.getElementsByTagName('span');
          for (var i = 0, l = divs.length; i < l; i++) {
            if (divs[i].className === this._numberClass) return divs[i];
          }
        },
     
        _wrap: function(content) {
          return '<div class="circles-wrp" style="position:relative; display:inline-block;">' + content + '</div>';
        },
     
        _generateText: function() {
          var html =  '<div class="' + this._textWrpClass + '" style="position:absolute; top:0; left:0; text-align:center; width:100%;' +
            ' font-size:' + this._radius * .7 + 'px; height:' + this._svgSize + 'px; line-height:' + this._svgSize + 'px;">' +
            this._calculateNumber(this._canAnimate ? 0 : this._number);
          if (this._text) {
            html += '<span class="' + this._textClass + '">' + this._text + '</span>';
          }
          html += '</div>';
          return html;
        },
     
        _calculateNumber: function(number) {
          var parts = (number + '').split('.'),
            html = '<span class="' + this._numberClass + '">' + parts[0];
          if (parts.length > 1) {
            html += '.<span style="font-size:.4em">' + parts[1].substring(0, 2) + '</span>';
          }
          return html + '</span>';
        },
     
        _generateSvg: function() {
          return '<svg width="' + this._svgSize + '" height="' + this._svgSize + '">' +
            this._generatePath(100, false, this._colors[0]) +
            this._generatePath(this._canAnimate ? 1 : this._percentage, true, this._colors[1]) +
          '</svg>';
        },
     
        _generatePath: function(percentage, open, color) {
          return '<path fill="transparent" stroke="' + color + '" stroke-width="' + this._strokeWidth + '" d="' + this._calculatePath(percentage, open) + '"/>';
        },
     
        _calculatePath: function(percentage, open) {
          var end      = this._start + ((percentage / 100) * this._circ),
            endPrecise = this._precise(end);
          return this._arc(endPrecise, open);
        },
     
        _arc: function(end, open) {
          var endAdjusted = end - 0.001,
            longArc       = end - this._startPrecise < Math.PI ? 0 : 1;
     
          return [
            'M',
            this._radius + this._radiusAdjusted * Math.cos(this._startPrecise),
            this._radius + this._radiusAdjusted * Math.sin(this._startPrecise),
            'A', // arcTo
            this._radiusAdjusted, // x radius
            this._radiusAdjusted, // y radius
            0, // slanting
            longArc, // long or short arc
            1, // clockwise
            this._radius + this._radiusAdjusted * Math.cos(endAdjusted),
            this._radius + this._radiusAdjusted * Math.sin(endAdjusted),
            open ? '' : 'Z' // close
          ].join(' ');
        },
     
        _precise: function(value) {
          return Math.round(value * 1000) / 1000;
        }
      };
     
      Circles.create = function(options) {
        return new Circles(options);
      };
    })();
    ma questions est comment faire pour que mon fichier js lise la bibliothèque,

    Ou comment l'inclure dans mon html.
    Une simple inclusion ne se gère pas sous Angular2.

    merci pour vos réactions.

  2. #2
    Membre éclairé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2008
    Messages
    764
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Février 2008
    Messages : 764
    Par défaut
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    <script type="text/javascript" src="cheminVersTonFichier/tonFichier.js"></script>


Discussions similaires

  1. [PDF] Inclure un fichier externe
    Par runcafre91 dans le forum Bibliothèques et frameworks
    Réponses: 14
    Dernier message: 06/04/2010, 11h16
  2. Inclure fichier php externe
    Par gazza dans le forum Général JavaScript
    Réponses: 11
    Dernier message: 08/08/2006, 11h22
  3. Inclure un fichier externe sans utiliser les frames
    Par gazza dans le forum Général JavaScript
    Réponses: 7
    Dernier message: 12/07/2006, 08h52
  4. Inclure un fichier html
    Par krfa1 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 7
    Dernier message: 08/02/2005, 14h40
  5. [HTML] inclure un fichier...
    Par mohican13 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 5
    Dernier message: 17/01/2005, 17h23

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo