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

Bibliothèques & Frameworks Discussion :

Récupérer valeur Starbox


Sujet :

Bibliothèques & Frameworks

  1. #1
    Débutant  
    Profil pro
    Inscrit en
    Juin 2013
    Messages
    1 225
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2013
    Messages : 1 225
    Points : 132
    Points
    132
    Par défaut Récupérer valeur Starbox
    Bonjour,

    J'ai mis en place le système de notation Starbox et je souhaite récupérer la note pour pouvoir l'insérer dans la base de donnée. J'ai regarder sur le net mais ce qui est donné ne fonctionne pas. Voici ce que j'ai actuellement:

    starbox.js:
    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
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    var Starboxes = {
      // Configuration for all starboxes
      inverse: false,
      locked: false,
      onRate: Prototype.emptyFunction,
      overlayImages: '../images/starbox/', // relative to starbox.js
      overlay: 'default.png',
      rerate: false,
     
      REQUIRED_Prototype: '1.6.0',
      REQUIRED_Scriptaculous: '1.8.0',
     
      load: function() {
        this.require('Prototype');
        var srcMatch = /starbox\.js$/;
        this.imageSource = (($$("head script[src]").find(function(s) {
          return s.src.match(srcMatch);
        }) || {}).src || '').replace(srcMatch, '') + this.overlayImages;
      },
     
      require: function(library) {
        if ((typeof window[library] == 'undefined') ||
          (this.convertVersionString(window[library].Version) < this.convertVersionString(this['REQUIRED_' + library])))
          throw('Starbox requires ' + library + ' >= ' + this['REQUIRED_' + library]);
      },
     
      convertVersionString: function(versionString) {
        var r = versionString.split('.');
        return parseInt(r[0])*100000 + parseInt(r[1])*1000 + parseInt(r[2]);
      },
     
      fixIE: (function(agent) {
        var version = new RegExp('MSIE ([\\d.]+)').exec(agent);
        return version ? (parseFloat(version[1]) <= 6) : false;
      })(navigator.userAgent),
     
      imagecache: [],
      cacheImage: function(imageInfo) {
        if(!this.getCachedImage(imageInfo.src)) this.imagecache.push(imageInfo);
        return imageInfo;
      },
     
      getCachedImage: function(src) {
        return this.imagecache.find(function(imageInfo) { return imageInfo.src == src });
      },
     
      // speed up the initial load of the page by building in batches
      // images are cached to to minimize requests
      buildQueue: [],
      queueBuild: function(starbox) {
        this.buildQueue.push(starbox);
      },
     
      processBuildQueue: function() {
        // on empty queue, stop loading as batches
        if (!this.buildQueue[0]) { this.batchLoading = true; return; }
        this.cacheBuildBatch(this.buildQueue[0]);
      },
     
      cacheBuildBatch: function(starbox) {
        var set = [];
        var overlay = starbox.options.overlay;
        var imageInfo = this.getCachedImage(overlay);
     
        // create a batch based on images with the same overlay
        this.buildQueue.each(function(s) {
          if (s.options.overlay == overlay) {
            set.push(s);
            this.buildQueue = this.buildQueue.without(s);
          }
        }.bind(this));
     
        if (!imageInfo) {
          var starImage = new Image();
          starImage.onload=function() {
            var imageInfo = this.cacheImage({ src: overlay, height: starImage.height,
              width: starImage.width, fullsrc: starImage.src });
            this.buildBatch(set, imageInfo);
          }.bind(this);
          starImage.src = Starboxes.imageSource + overlay;
        }
        else { this.buildBatch(set, imageInfo); }
      },
     
      buildBatch: function(set, imageInfo) {
        set.each(function(s) {
          s.imageInfo = imageInfo;
          s.build();
        });
        this.processBuildQueue();
      }
    };
    Starboxes.load();
    document.observe('dom:loaded', Starboxes.processBuildQueue.bind(Starboxes));
     
    var Starbox = Class.create({
      initialize: function(element, average) {
        this.element = $(element),
        this.average = average;
     
        this.options = Object.extend({
          buttons: 5,
          className : 'default',
          color: false,
          duration: 0.6,
          effect: { mouseover: false , mouseout: (window.Effect && Effect.Morph) },
          hoverColor: false,
          hoverClass: 'hover',
          ghostColor: false,
          ghosting: false,
          ratedClass: 'rated',
          identity: false,
          indicator: false,
          inverse: Starboxes.inverse,
          locked: false,
          max: 5,
          onRate: Starboxes.onRate,
          rerate: Starboxes.rerate,
          rated: false,
          overlay: Starboxes.overlay,
          stars: 5,
          total : 0
        }, arguments[2] || {});
     
        this.rated = this.options.rated;
        this.total = this.options.total;
        this.locked =  this.options.locked || (this.rated && !this.options.rerate);
     
        if (this.options.effect && (this.options.effect.mouseover || this.options.effect.mouseout))
          Starboxes.require('Scriptaculous');
     
        Starboxes.queueBuild(this);
        if (Starboxes.batchLoading) Starboxes.processBuildQueue();
      },
     
      enable: function() {
        if (!Prototype.Browser.IE) {
          this.onMouseout = this.onMouseout.wrap(function(proceed, event) {
            var rel = event.relatedTarget, cur = event.currentTarget;
            if (rel && rel.nodeType == Node.TEXT_NODE) rel = rel.parentNode;
            if (rel && rel != cur && !(rel.descendantOf(cur)))
              proceed(event);
          });
        }
     
        $w('mouseout mouseover click').each(function(e) {
          var E = e.capitalize();
          this['on' + E + '_cached'] = this['on' + E].bindAsEventListener(this);
          this.starbar.observe(e, this['on' + E + '_cached']);
        }.bind(this));
     
        this.buttons.invoke('setStyle', { cursor: 'pointer' });
      },
     
      disable: function() {
        $w('mouseover mouseout click').each(function(e) {
          this.starbar.stopObserving(e, this['on' + e.capitalize() + '_cached']);
        }.bind(this));
     
        this.buttons.invoke('setStyle', { cursor: 'auto' });
      },
     
      build: function() {
        this.starWidth = this.imageInfo.width;
        this.starHeight = this.imageInfo.height;
        this.starSrc = this.imageInfo.fullsrc;
        this.boxWidth = this.starWidth * this.options.stars;
        this.buttonWidth = this.boxWidth / this.options.buttons;
        this.buttonRating = this.options.max / this.options.buttons;
     
        if(this.options.effect) {
          this.zeroPosition = this.getBarPosition(0);
          this.maxPosition = this.getBarPosition(this.options.max);
        }
     
        var styles = {
          absolute: { position: 'absolute', top: 0, left: 0, width: this.boxWidth + 'px', height: this.starHeight + 'px' },
          base: { position: 'relative', width: this.boxWidth + 'px', height: this.starHeight + 'px' },
          star: { position: 'absolute', top: 0, left: 0, width: this.starWidth + 'px', height: this.starHeight + 'px' }
        };
     
        this.element.addClassName('starbox');
        this.container = new Element('div', { 'class': this.options.className || '' }).setStyle({ position: 'relative' });
     
        this.status = this.container.appendChild(new Element('div'));
        if (this.rated) this.status.addClassName('rated');
        if (this.locked) this.status.addClassName('locked');
     
        this.hover = this.status.appendChild(new Element('div'));
        this.wrapper = this.hover.appendChild(new Element('div', { 'class': 'stars' }));
        this.wrapper.setStyle(Object.extend({ overflow: 'hidden' }, styles.base));
     
        if (this.options.ghosting) {
          this.ghost = this.wrapper.appendChild(new Element('div', { 'class': 'ghost' }).setStyle(styles.absolute));
          if (this.options.ghostColor) this.ghost.setStyle({ background: this.options.ghostColor });
          if (this.options.effect) this.ghost.scope = this.ghost.identify();
          this.setBarPosition(this.ghost, this.average, (window.Effect && Effect.Morph));
        }
     
        this.colorbar = this.wrapper.appendChild(new Element('div', { 'class': 'colorbar' }).setStyle(styles.absolute));
        if (this.options.color) this.colorbar.setStyle({ background: this.options.color });
        if (this.options.effect) this.colorbar.scope = this.colorbar.identify();
     
        var starWrapper = this.wrapper.appendChild(new Element('div').setStyle(styles.absolute));
        this.starbar = starWrapper.appendChild(new Element('div').setStyle(styles.base));
     
        this.options.stars.times(function(i) {
          var star = this.starbar.appendChild(new Element('div').setStyle(Object.extend({
            background: 'url(' + this.starSrc + ') top left no-repeat'
          }, styles.star)));
          star.setStyle({ left: this.starWidth * i + 'px' });
     
          if (Starboxes.fixIE) {
            star.setStyle({
              background: 'none', 'filter' : 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' +
                this.starSrc + '\'\', sizingMethod=\'scale\')'
            });
          }
        }.bind(this));
     
        this.buttons = [];
        this.options.buttons.times(function(i) {
          var leftPos = this.options.inverse ? this.boxWidth - this.buttonWidth * (i + 1) : this.buttonWidth * i;
          var button = this.starbar.appendChild(new Element('div', { href: 'javascript:;' }).setStyle({
            position: 'absolute',
            top: 0,
            left: leftPos + 'px',
            width: this.buttonWidth + (Prototype.Browser.IE ? 1 : 0) + 'px',
            height: this.starHeight + 'px'
          }));
          button.rating = this.buttonRating * i + this.buttonRating;
          this.buttons.push(button);
        }.bind(this));
     
        this.setBarPosition(this.colorbar, this.average);
        this.element.update(this.container);
     
        if (this.options.indicator) {
          this.indicator = this.hover.appendChild(new Element('div', { 'class' : 'indicator' }));
          this.updateIndicator();
        }
     
        if (!this.locked) this.enable();
      },
     
      updateAverage: function(increment) {
        if (this.rated && this.options.rerate)
          this.average = (this.total * this.average - this.rated) / (this.total-1 || 1);
     
        var total = this.rated ? this.total : this.total++;
     
        this.average = (this.average == 0) ? increment :
          (this.average * (this.rated ? total-1 : total) + increment) / (this.rated ? total : total+1);
      },
     
      updateIndicator: function() {
        this.indicator.update(new Template(this.options.indicator).evaluate({
          max: this.options.max,
          total: this.total,
          average: (this.average * 10).round() / 10
        }));
      },
     
      getBarPosition : function(rating) {
        var position = (this.boxWidth - (rating/this.buttonRating) * this.buttonWidth);
        return parseInt(this.options.inverse ? position.ceil() : -1 * position.floor());
      },
     
      setBarPosition: function(element, rating) {
        if (this.options.effect && this['activeEffect_' + element.scope])
          Effect.Queues.get(element.scope).remove(this['activeEffect_' + element.scope]);
     
        var left = this.getBarPosition(rating);
        if (arguments[2]) {
          var current = parseInt(element.getStyle('left'));
          var to = this.getBarPosition(rating);
          if (current == to) return;
          var mspeed = ((this.maxPosition - (current - to).abs()).abs() / this.zeroPosition.abs()).toFixed(2);
     
          this['activeEffect_' + element.scope] = new Effect.Morph(element, { style: { left: left + 'px' },
            queue: { position: 'end', limit: 1, scope: element.scope}, duration: (this.options.duration * mspeed) });
        }
        else { element.setStyle({ left: left + 'px' }); }
      },
     
      onClick: function(event) {
        var element = event.element();
        if (!element.rating) return;
     
        this.updateAverage(element.rating);
        if (this.options.indicator) this.updateIndicator();
        if (this.options.ghosting) this.setBarPosition(this.ghost, this.average, (window.Effect && Effect.Morph));
     
        if (!this.rated) this.status.addClassName('rated');
        var rerated = !!this.rated;
        this.rated = element.rating;
     
        if (!this.options.rerate) {
          this.disable();
          this.status.addClassName('locked');
          this.onMouseout(event);
        }
     
        var info = {
          average: this.average,
          identity: this.options.identity,
          max: this.options.max,
          rated: element.rating,
          rerated: rerated,
          total: this.total
        };
        this.options.onRate(this.element, info);
        this.element.fire('starbox:rated');
      },
     
      onMouseout: function(event) {
        this.setBarPosition(this.colorbar, this.average, (this.options.effect && this.options.effect.mouseout));
        this.hovered = false;
        if (this.options.hoverClass) this.hover.removeClassName(this.options.hoverClass);
        if (this.options.hoverColor) this.colorbar.setStyle({ background: this.options.color });
      },
     
      onMouseover: function(event) {
        var element = event.element();
        if (!element.rating) return;
     
        this.setBarPosition(this.colorbar, element.rating, (this.options.effect && this.options.effect.mouseover));
        if(!this.hovered && this.options.hoverClass) this.hover.addClassName(this.options.hoverClass);
        this.hovered = true;
        if (this.options.hoverColor) this.colorbar.setStyle({ background: this.options.hoverColor });
      }
    });
    html:
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    <div id="rating"></div>
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    valeuractuelle = <?php echo $row1['note'];?>;
    new Starbox("rating", valeuractuelle, {onRate:mafonction, overlay: 'pointy.png'});
    function mafonction(event, info) {
        alert(info.average.toFixed(2));
    }
    Merci de votre aide

  2. #2
    Rédacteur/Modérateur

    Avatar de SylvainPV
    Profil pro
    Inscrit en
    Novembre 2012
    Messages
    3 375
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2012
    Messages : 3 375
    Points : 9 944
    Points
    9 944
    Par défaut
    Un réflexe à adopter : donner le lien vers le site de la bibliothèque et être un peu plus précis que "ça ne fonctionne pas" ; décrire les tests effectués et lister les éventuels messages en console par exemple.
    One Web to rule them all

  3. #3
    Débutant  
    Profil pro
    Inscrit en
    Juin 2013
    Messages
    1 225
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2013
    Messages : 1 225
    Points : 132
    Points
    132
    Par défaut
    Je l'ai trouvé ici:
    http://www.nickstakenburg.com/projects/starbox/

    Voici ce que j'ai fais:
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    <div id="rating"></div>
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    function myOnRate(element, memo) {
    	new Ajax.Request('reqUpdFreelance.php', {
    		method: 'post',
    		parameters: {rating: memo.rated}, // Je transmets ici les variables
    		onComplete: function(xhr) {
    		}
    	});
    };
    valeuractuelle = <?php echo $row1['note'];?>;
    new Starbox("rating", valeuractuelle, {onRate:mafonction, overlay: 'pointy.png'});
    function mafonction(event, info) {
    	alert(info.average.toFixed(2));
    };
    page récup des données:
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    $rating = $_POST['rating'];

  4. #4
    Rédacteur/Modérateur

    Avatar de SylvainPV
    Profil pro
    Inscrit en
    Novembre 2012
    Messages
    3 375
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2012
    Messages : 3 375
    Points : 9 944
    Points
    9 944
    Par défaut
    Etant donné que la bibliothèque est payante, je ne peux pas reproduire ton code et le déboguer. Je te suggère toutefois de passer ton JavaScript dans un validateur et le réindenter, ce qui ne serait pas du luxe. Et sinon, rien en console ?
    One Web to rule them all

  5. #5
    Débutant  
    Profil pro
    Inscrit en
    Juin 2013
    Messages
    1 225
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2013
    Messages : 1 225
    Points : 132
    Points
    132
    Par défaut
    Rien dans la console
    Et voici la lib: Prototype.js
    Fichiers attachés Fichiers attachés

Discussions similaires

  1. [POI]Récupérer valeur cellule suivant format
    Par leminipouce dans le forum Documents
    Réponses: 1
    Dernier message: 27/10/2005, 08h52
  2. Récupérer valeur contrôle en dynamique via requête
    Par nicburger dans le forum Access
    Réponses: 10
    Dernier message: 15/09/2005, 15h41
  3. [ActionScript] Récupérer valeur balise <param />
    Par JohnBlatt dans le forum Flash
    Réponses: 1
    Dernier message: 18/07/2005, 14h50
  4. CR9 - Récupérer valeurs multiples d'un champ paramètre
    Par CR9-Deb dans le forum SAP Crystal Reports
    Réponses: 1
    Dernier message: 06/07/2005, 16h08
  5. récupérer valeur d'un ID après insertion
    Par rikidi dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 26/08/2003, 22h21

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