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

JavaScript Discussion :

javascript variable dans variable


Sujet :

JavaScript

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Inscrit en
    Décembre 2008
    Messages
    319
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 319
    Par défaut javascript variable dans variable
    Bonjour a tous,

    Voila j ai ce bout de code en javascript et je souhaiterais qu au niveau de la variable "textgalleryselector" mttre une variable mais ca ne fonctionne pas du tout

    Merci de votre aide

    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
    var gallerySet = new Class({
    	Extends: gallery,
    	initialize: function(element, options) {
    		this.setOptions({
    			manualSetData: [],
    			gallerySelector: "div.galleryElement",
    			galleryTitleSelector: "h2",
    			textGallerySelector: 'Kitchens Gallery',
    			textShowGallerySelector: 'Other Gallery',
    			textGalleryInfo: '{0} pictures',
    			startWithSelector: true,
    			/* Changing default options */
    			textShowCarousel: '{0}/{1} Pictures',
    			carouselPreloader: false
    		});
    		this.setOptions(options);
    		this.gallerySet = this.options.manualSetData;
    		this.addEvent('onPopulated', this.createGallerySelectorTab.bind(this));
    		this.addEvent('onPopulated', this.createGallerySelector.bind(this));
    		this.startWithSelectorFn = this.toggleGallerySelector.pass(true, this);
    		if (this.options.startWithSelector)
    			this.addEvent('onGallerySelectorCreated', this.startWithSelectorFn);
    		this.parent(element, this.options);
    	},
    	populateData: function() {
    		options = this.options;
    		var data = $A(this.gallerySet);
    		this.populateFrom.getElements(options.gallerySelector).each(function (galEl) {
    			currentGalArrayPlace = 0;
    			galleryDict = {
    				title: galEl.getElement(options.galleryTitleSelector).innerHTML,
    				elements: []
    			}
    			galleryDict.elements.extend(this.populateGallery(galEl, 0));
    			data.extend([galleryDict]);
    			if (this.options.destroyAfterPopulate)
    				galEl.dispose();
    		}, this);
    		this.gallerySet = data;
    		this.galleryData = data[0].elements;
    		this.currentGallery = 0;
    		this.fireEvent('onPopulated');
    	},
    	changeGallery: function(number)
    	{
    		if (number!=this.currentGallery)
    		{
    			this.changeData(this.gallerySet[number].elements);
    			this.maxIter = this.gallerySet[number].elements.length;
    			this.currentGallery = number;
    			this.gallerySelectorBtn.set('html', this.gallerySet[number].title);
    			this.fireEvent('onGalleryChanged');
    		}
    		this.toggleGallerySelector(false);
    	},
    	createGallerySelectorTab: function() {
    		this.gallerySelectorBtn = new Element('a').addClass('gallerySelectorBtn').setProperties({
    			title: this.options.textShowGallerySelector
    		}).set('html', this.options.textShowGallerySelector).addEvent(
    			'click',
    			function(){ this.toggleGallerySelector(true); }.bind(this)
    		).injectInside(this.galleryElement);
    		this.addEvent('onShowCarousel', function(){this.gallerySelectorBtn.setStyle('zIndex', 10)}.bind(this));
    		this.addEvent('onCarouselHidden', function(){this.gallerySelectorBtn.setStyle('zIndex', 15)}.bind(this));
    	},
    	createGallerySelector: function() {
    		this.gallerySelector = new Fx.Morph(
    			new Element('div').addClass(
    				'gallerySelector'
    			).injectInside(
    				this.galleryElement
    			).setStyles({
    				'display': 'none',
    				'opacity': '0'
    			})
    		);
    		this.gallerySelectorTitle = 
    			new Element('h2').set('html', 
    				this.options.textGallerySelector
    			).injectInside(this.gallerySelector.element);
    		var gallerySelectorHeight = this.galleryElement.offsetHeight - 50 - 10 - 2;
    		this.gallerySelectorWrapper = new Fx.Morph(
    			new Element('div').addClass(
    				'gallerySelectorWrapper'
    			).setStyle(
    				'height',
    				gallerySelectorHeight + "px"
    			).injectInside(this.gallerySelector.element)
    		);
    		this.gallerySelectorInner =	new Element('div').addClass('gallerySelectorInner').injectInside(this.gallerySelectorWrapper.element);
    		this.gallerySelectorWrapper.scroller = new Scroller(this.gallerySelectorWrapper.element, {
    			area: 100,
    			velocity: 0.3
    		}).start();
    		this.createGalleryButtons();
    		this.fireEvent('onGallerySelectorCreated');
    	},
    	createGalleryButtons: function () {
    		var galleryButtonWidth =
    			((this.galleryElement.offsetWidth - 30) / 2) - 14;
    		this.gallerySet.each(function(galleryItem, index){
    			var button = new Element('div').addClass('galleryButton').injectInside(
    				this.gallerySelectorInner
    			).addEvents({
    				'mouseover': function(myself){
    					myself.button.addClass('hover');
    				}.pass(galleryItem, this),
    				'mouseout': function(myself){
    					myself.button.removeClass('hover');
    				}.pass(galleryItem, this),
    				'click': function(myself, number){
    					this.changeGallery.pass(number,this)();
    				}.pass([galleryItem, index], this)
    			}).setStyle('width', galleryButtonWidth);
    			galleryItem.button = button;
    			var thumbnail = "";
    			if (this.options.showCarousel)
    				thumbnail = galleryItem.elements[0].thumbnail;
    			else
    				thumbnail = galleryItem.elements[0].image;
    			new Element('div').addClass('preview').setStyle(
    				'backgroundImage',
    				"url('" + thumbnail + "')"
    			).injectInside(button);
    			new Element('h3').set('html', galleryItem.title).injectInside(button);
    			new Element('p').addClass('info').set('html', formatString(this.options.textGalleryInfo, galleryItem.elements.length)).injectInside(button);
    		}, this);
    		new Element('br').injectInside(this.gallerySelectorInner).setStyle('clear','both');
    	},
    	toggleGallerySelector: function(state) {
    		if (state)
    			this.gallerySelector.start({'opacity' : 1}).element.setStyle('display','block');
    		else
    			this.gallerySelector.start({'opacity' : 0});
    	},
    	initHistory: function() {
    		this.fireEvent('onHistoryInit');
    		this.historyKey = this.galleryElement.id + '-gallery';
    		if (this.options.customHistoryKey)
    			this.historyKey = this.options.customHistoryKey();
    		this.history = new History.Route({
    			defaults: [1,1],
    			pattern: this.historyKey + '\\((\\d+)\\)-picture\\((\\d+)\\)',
    			generate: function(values) {
    				return [this.historyKey, '(', values[0], ')', '-picture','(', values[1], ')'].join('');
    			}.bind(this),
    			onMatch: function(values, defaults) {
    				this.changeGallery.pass(parseInt(values[0]) - 1, this).delay(10);
    				if(this.gallerySelector)
    					this.toggleGallerySelector.pass(false, this).delay(500);
    				this.goTo.pass(parseInt(values[1]) - 1, this).delay(100);
    			}.bind(this)
    		});
    		updateHistory = function(){
    			this.history.setValues([this.currentGallery + 1, this.currentIter + 1]);
    			this.history.defaults=[this.currentGallery + 1, this.currentIter + 1];
    		}.bind(this);		
    		
    		this.addEvent('onChanged', updateHistory);
    		this.addEvent('onGalleryChanged', updateHistory);
    		this.fireEvent('onHistoryInited');
    	}
    });
    
    <config>Windows 7 / Firefox 3.6.2</config>

  2. #2
    Rédacteur

    Avatar de Bovino
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2008
    Messages
    23 647
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2008
    Messages : 23 647
    Billets dans le blog
    20
    Par défaut
    Qu'est-ce qui ne marche pas ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    var toto = 'Kitchens Gallery';
    var gallerySet = new Class({
    	Extends: gallery,
    	initialize: function(element, options) {
    		this.setOptions({
    			manualSetData: [],
    			gallerySelector: "div.galleryElement",
    			galleryTitleSelector: "h2",
    			textGallerySelector: toto,
    Pas de question technique par MP !
    Tout le monde peut participer à developpez.com, vous avez une idée, contactez-moi !
    Mes formations video2brain : La formation complète sur JavaScriptJavaScript et le DOM par la pratiquePHP 5 et MySQL : les fondamentaux
    Mon livre sur jQuery
    Module Firefox / Chrome d'intégration de JSFiddle et CodePen sur le forum

  3. #3
    Membre éclairé
    Inscrit en
    Décembre 2008
    Messages
    319
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 319
    Par défaut
    Merci de ta réponse,

    En fait quand je declare une varaible comme tu l as fait je perds ma mise en page faites avec js ...

    Bizarre

  4. #4
    Membre chevronné
    Avatar de FMaz
    Inscrit en
    Mars 2005
    Messages
    643
    Détails du profil
    Informations forums :
    Inscription : Mars 2005
    Messages : 643
    Par défaut
    Faudrait voir de quelle facon la valeur de galleryselector est utilisée.
    À priori, je dirais que les 2 exemples sont identiques (as part que le second exemple est partiel et tronqué pour des raisons de concision, faut adapter )

  5. #5
    Membre éclairé
    Inscrit en
    Décembre 2008
    Messages
    319
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 319
    Par défaut
    Merci pour vos réponses la solution de bovino fonctionne nickel

    par contre je souhaiterais savoir comment faire une condition pour vérifier l'url et créer une variable qui récupére cette URL

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    if (self.location.href=="http://test") {
       var toto : toto test
    }
    else {
       var toto :  toto pas test
    }

  6. #6
    Membre éclairé
    Inscrit en
    Décembre 2008
    Messages
    319
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 319
    Par défaut
    Bon finalement j'ai fiat autrement

    Renvoi vers deux fichiers JS dans chaque fichier JS la valeur que je veux heureusement que j avais que deux valeurs et pas 12000...

    Mais ça me convient merci de votre aide

Discussions similaires

  1. variable dans variable
    Par gy0m76 dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 18/12/2006, 10h51
  2. [JSP/javascript] lire une variable dans un infobulle
    Par maniolo dans le forum Servlets/JSP
    Réponses: 1
    Dernier message: 20/10/2006, 14h50
  3. Variable dans variable
    Par Bobybx dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 07/07/2006, 14h35
  4. $_POST[variable] ou $variable dans lien de confimation ?
    Par psychoBob dans le forum Langage
    Réponses: 6
    Dernier message: 09/05/2006, 14h08
  5. variable dans variable boucle
    Par molesqualeux dans le forum C
    Réponses: 2
    Dernier message: 26/12/2005, 16h02

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