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 :

Event OnKeyPress


Sujet :

Bibliothèques & Frameworks

  1. #1
    Membre régulier Avatar de keub51
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    349
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 349
    Points : 116
    Points
    116
    Par défaut Event OnKeyPress
    Bonjour, je travaille actuellement sur un framework de javascript. il me sert a afficher une pop-up. je souhaite que cette pop up se ferme avec la touche echap.

    voici le code :

    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
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    var Window = Class.create();
    Window.keepMultiModalWindow = false;
    Window.prototype = {
    	// Constructor
    	// Available parameters : className, title, minWidth, minHeight, maxWidth, maxHeight, width, height, top, left, bottom, right, resizable, zIndex, opacity, 
    	//                        hideEffect, showEffect, showEffectOptions, hideEffectOptions, effectOptions, url, draggable, closable, minimizable, maximizable, parent, onload
    	initialize: function(id) {
    	  //if ($(id))
    	    //alert("Window " + id + " is already register is the DOM!!, be sure to use setDestroyOnClose()")
    	    
    		this.hasEffectLib = String.prototype.parseColor != null;
    		this.options = Object.extend({
    		  className:         "dialog",
          minWidth:          100,
          minHeight:         20,
          resizable:         true,
          closable:          true,
          minimizable:       true,
          maximizable:       true,
          draggable:         true,
          userData:          null,
          showEffect:        (this.hasEffectLib ? Effect.Appear : Element.show),
          hideEffect:        (this.hasEffectLib ? Effect.Fade : Element.hide),
          showEffectOptions: {},
          hideEffectOptions: {},
          effectOptions:     null,
          parent:            document.getElementsByTagName("body").item(0),
          title:             " ",
          url:               null,
          onload:            Prototype.emptyFunction,
          width:             200,
          height:            300,
          opacity:           1,
          recenterAuto:      true
        }, arguments[1] || {});
        		
    	  if (this.options.effectOptions) {
    	    Object.extend(this.options.hideEffectOptions, this.options.effectOptions);
    	    Object.extend(this.options.showEffectOptions, this.options.effectOptions);
    	  }
    		if (this.options.hideEffect == Element.hide)
    		  this.options.hideEffect = function(){ Element.hide(this.element); if (this.destroyOnClose) this.destroy(); }.bind(this)
    		  
    		this.element = this._createWindow(id);
    		
    		// Bind event listener
        this.eventMouseDown = this._initDrag.bindAsEventListener(this);
      	this.eventMouseUp   = this._endDrag.bindAsEventListener(this);
      	this.eventMouseMove = this._updateDrag.bindAsEventListener(this);
      	this.eventOnLoad    = this._getWindowBorderSize.bindAsEventListener(this);
        this.eventMouseDownContent = this.toFront.bindAsEventListener(this);
        if (this.options.recenterAuto)
          this.eventResize = this._recenter.bindAsEventListener(this);
     
    		this.topbar = $(this.element.id + "_top");
    		this.bottombar = $(this.element.id + "_bottom");
        this.content = $(this.element.id + "_content");
        
    		Event.observe(this.topbar, "mousedown", this.eventMouseDown);
    		Event.observe(this.bottombar, "mousedown", this.eventMouseDown);
    		Event.observe(this.content, "mousedown", this.eventMouseDownContent);
    		Event.observe(window, "load", this.eventOnLoad);
        if (this.options.recenterAuto) {
    		  Event.observe(window, "resize", this.eventResize);
      	  Event.observe(window, "scroll", this.eventResize);
    	  }
      	
    		if (this.options.draggable)  {
    			this.bottombar.addClassName("bottom_draggable");
    			this.topbar.addClassName("top_draggable");
        }		
        
    		if (this.options.resizable) {
    			this.sizer = $(this.element.id + "_sizer");
        	Event.observe(this.sizer, "mousedown", this.eventMouseDown);
        }	
        
        this.useLeft = null;
        this.useTop = null;
    		if (arguments[1].left != null) {
    			this.element.setStyle({left: parseFloat(arguments[1].left) + 'px'});
    			this.useLeft = true;
    		}
    		if (arguments[1].right != null) {
    			this.element.setStyle({right: parseFloat(arguments[1].right) + 'px'});
    			this.useLeft = false;
    		}
        if (this.useLeft == null) {
    	    this.element.setStyle({left: "0px"});
    			this.useLeft = true;
        }
        
    		if (arguments[1].top != null) {
    			this.element.setStyle({top: parseFloat(arguments[1].top) + 'px'});
    			this.useTop = true;
    		}
    		if (arguments[1].bottom != null) {
    			this.element.setStyle({bottom: parseFloat(arguments[1].bottom) + 'px'});			
    			this.useTop = false;
    		}
        if (this.useTop == null) {
    			this.element.setStyle({top: "0px"});
    			this.useTop = true;
        }
    
        this.storedLocation = null;
        
    		this.setOpacity(this.options.opacity);
    		if (this.options.zIndex)
    			this.setZIndex(this.options.zIndex)
    
    		this.destroyOnClose = false;
    
        this._getWindowBorderSize();
        this.width = this.options.width;
        this.height = this.options.height;
        this.visible = false;
        
        if (this.width && this.height)
    		  this.setSize(this.options.width, this.options.height);
    		this.setTitle(this.options.title)
    		Windows.register(this);	    
      },
    
    	// Destructor
     	destroy: function() {
    		Windows.notify("onDestroy", this);
      	Event.stopObserving(this.topbar, "mousedown", this.eventMouseDown);
      	Event.stopObserving(this.bottombar, "mousedown", this.eventMouseDown);
      	Event.stopObserving(this.content, "mousedown", this.eventMouseDownContent);
        
    		Event.stopObserving(window, "load", this.eventOnLoad);
    		if (this.options.recenterAuto) {
    		  Event.stopObserving(window, "resize", this.eventResize);
      	  Event.stopObserving(window, "scroll", this.eventResize);
    	  }
    		
    		Event.stopObserving(this.content, "load", this.options.onload);
    
    		if (this._oldParent) {
    			var content = this.getContent();
    			var originalContent = null;
    			for(var i = 0; i < content.childNodes.length; i++) {
    				originalContent = content.childNodes[i];
    				if (Node.ELEMENT_NODE == originalContent.nodeType) break;
    				originalContent = null;
    			}
    			if (originalContent)
    			  this._oldParent.appendChild(originalContent);
    			this._oldParent = null;
    		}
    
    		if (this.sizer)
        		Event.stopObserving(this.sizer, "mousedown", this.eventMouseDown);
    
    		if (this.options.url)
    		  this.content.src = null
    
    	 	if(this.iefix) 
    			Element.remove(this.iefix);
    
        Element.remove(this.element);
    		Windows.unregister(this);	    
    	},
      	
    	// Sets window deleagte, should have functions: "canClose(window)" 
    	setDelegate: function(delegate) {
    		this.delegate = delegate
    	},
    	
    	// Gets current window delegate
    	getDelegate: function() {
    		return this.delegate;
    	},
    	
    	// Gets window content
    	getContent: function () {
    		return this.content;
    	},
    	
    	// Sets the content with an element id
    	setContent: function(id, autoresize, autoposition) {
    		var element = $(id);
    		if (null == element) throw "Unable to find element '" + id + "' in DOM";
    		this._oldParent = element.parentNode;
    
    		var d = null;
    		var p = null;
    
    		if (autoresize) 
    			d = Element.getDimensions(element);
    		if (autoposition) 
    			p = Position.cumulativeOffset(element);
    
    		var content = this.getContent()
    		content.appendChild(element);
    		element.show();
    		if (autoresize) 
    			this.setSize(d.width, d.height);
    		if (autoposition) 
    		  this.setLocation(p[1] - this.heightN, p[0] - this.widthW);	  
    	},
    	
    	setAjaxContent: function(url, options, showCentered, showModal) {
    	  this.showFunction = showCentered ? "showCenter" : "show";
    	  this.showModal = showModal || false;
    	
    	  if (options == null)
    	    options = {}  
    	  this.onComplete = options.onComplete;
    	  options.onComplete = this._setAjaxContent.bind(this);
    	  
    	  new Ajax.Request(url, options);
    	},
    	
    	_setAjaxContent: function(originalRequest) {
    	  Element.update(this.getContent(), originalRequest.responseText);
    	  if (this.onComplete)
    	    this.onComplete(originalRequest);
    	  this[this.showFunction](this.showModal)
    	},
    	
    	// Stores position/size in a cookie, by default named with window id
    	setCookie: function(name, expires, path, domain, secure) {
    		name = name || this.element.id;
    		this.cookie = [name, expires, path, domain, secure];
    		
    		// Get cookie
    		var value = WindowUtilities.getCookie(name)
    		// If exists
    		if (value) {
    			var values = value.split(',');
    			var x = values[0].split(':');
    			var y = values[1].split(':');
    
    			var w = parseFloat(values[2]), h = parseFloat(values[3]);
    			var mini = values[4];
    			var maxi = values[5];
    
    		  this.setSize(w, h);
    			if (mini == "true")
    		    this.doMinimize = true; // Minimize will be done at onload window event
    			else if (maxi == "true")
    			  this.doMaximize = true; // Maximize will be done at onload window event
    
    			this.useLeft = x[0] == "l";
    			this.useTop = y[0] == "t";
    
    			this.element.setStyle(this.useLeft ? {left: x[1]} : {right: x[1]});
    			this.element.setStyle(this.useTop ? {top: y[1]} : {bottom: y[1]});
    		}
    	},
    	
    	// Gets window ID
    	getId: function() {
    		return this.element.id;
    	},
    	
    	// Detroys itself when closing 
    	setDestroyOnClose: function() {
        var destroyFunc = this.destroy.bind(this);
    	  if (this.options.hideEffectOptions.afterFinish) {
    	    var func = this.options.hideEffectOptions.afterFinish;
    	    this.options.hideEffectOptions.afterFinish = function() {func();destroyFunc() }
        }
        else 
          this.options.hideEffectOptions.afterFinish = function() {destroyFunc() }
    	  this.destroyOnClose = true;
    	},
    	
    	// initDrag event
    	_initDrag: function(event) {
        // Get pointer X,Y
      	this.pointer = [Event.pointerX(event), Event.pointerY(event)];
    
        // Resize
    		if (Event.element(event) == this.sizer) {
    			this.doResize = true;
        	this.widthOrg = this.width;
        	this.heightOrg = this.height;
        	this.bottomOrg = parseFloat(this.element.getStyle('bottom'));
        	this.rightOrg = parseFloat(this.element.getStyle('right'));
    			Windows.notify("onStartResize", this);
    		}
        else {
    		  this.doResize = false;
    
      		// Check if click on close button, 
      		var closeButton = $(this.getId() + '_close');
      		if (closeButton && Position.within(closeButton, this.pointer[0], this.pointer[1])) 
      			return;
    
      		this.toFront();
    
      		if (! this.options.draggable) 
      		  return;
      		Windows.notify("onStartMove", this);
        }  	
      	// Register global event to capture mouseUp and mouseMove
      	Event.observe(document, "mouseup", this.eventMouseUp, false);
        Event.observe(document, "mousemove", this.eventMouseMove, false);
    		
      	// Add an invisible div to keep catching mouse event over iframes
      	WindowUtilities.disableScreen('__invisible__', '__invisible__');
    
        // Stop selection while dragging
        document.body.ondrag = function () { return false; };
        document.body.onselectstart = function () { return false; };
        
        Event.stop(event);
      },
    
      // updateDrag event
    	_updateDrag: function(event) {
       	var pointer = [Event.pointerX(event), Event.pointerY(event)];    
    		var dx = pointer[0] - this.pointer[0];
    		var dy = pointer[1] - this.pointer[1];
    		
    		// Resize case, update width/height
    		if (this.doResize) {
    			this.setSize(this.widthOrg + dx , this.heightOrg + dy);
    			
          dx = this.width - this.widthOrg
          dy = this.height - this.heightOrg
    			
    		  // Check if it's a right position, update it to keep upper-left corner at the same position
    			if (! this.useLeft) 
    				this.element.setStyle({right: (this.rightOrg -dx) + 'px'});
    			// Check if it's a bottom position, update it to keep upper-left corner at the same position
    			if (! this.useTop) 
    				this.element.setStyle({bottom: (this.bottomOrg -dy) + 'px'});
    		}
    		// Move case, update top/left
    		else {
    		  this.pointer = pointer;
      		
    			if (this.useLeft) 
    				this.element.setStyle({left: parseFloat(this.element.getStyle('left')) + dx + 'px'});
    			else 
    				this.element.setStyle({right: parseFloat(this.element.getStyle('right')) - dx + 'px'});
    			
    			if (this.useTop) 
    				this.element.setStyle({top: parseFloat(this.element.getStyle('top')) + dy + 'px'});
    		  else 
    				this.element.setStyle({bottom: parseFloat(this.element.getStyle('bottom')) - dy + 'px'});
    		}
    		if (this.iefix) 
    			this._fixIEOverlapping(); 
    			
    		this._removeStoreLocation();
        Event.stop(event);
    	},
    
    	 // endDrag callback
     	_endDrag: function(event) {
    		// Remove temporary div over iframes
     	  WindowUtilities.enableScreen('__invisible__');
    		
    		if (this.doResize)
    			Windows.notify("onEndResize", this);
    		else
    			Windows.notify("onEndMove", this);
    		
    		// Release event observing
    		Event.stopObserving(document, "mouseup", this.eventMouseUp,false);
        Event.stopObserving(document, "mousemove", this.eventMouseMove, false);
    
    		// Store new location/size if need be
    		this._saveCookie()
    
        Event.stop(event);
        
        // Restore selection
        document.body.ondrag = null;
        document.body.onselectstart = null;
      },
    
    	// Creates HTML window code
    	_createWindow: function(id) {
    	  var className = this.options.className;
    		var win = document.createElement("div");
    		win.setAttribute('id', id);
    		win.className = "dialog";
    
    		var content;
    		if (this.options.url)
    			content= "<iframe frameborder=\"0\" name=\"" + id + "_content\"  id=\"" + id + "_content\" src=\"" + this.options.url + "\"> </iframe>";
    		else
    			content ="<div id=\"" + id + "_content\" class=\"" +className + "_content\"> </div>";
    
    		var closeDiv = this.options.closable ? "<div class='"+ className +"_close' id='"+ id +"_close' onclick='Windows.close(\""+ id +"\", event)'> </div>" : "";
    		var minDiv = this.options.minimizable ? "<div class='"+ className + "_minimize' id='"+ id +"_minimize' onclick='Windows.minimize(\""+ id +"\", event)'> </div>" : "";
    		var maxDiv = this.options.maximizable ? "<div class='"+ className + "_maximize' id='"+ id +"_maximize' onclick='Windows.maximize(\""+ id +"\", event)'> </div>" : "";
    		var seAttributes = this.options.resizable ? "class='" + className + "_sizer' id='" + id + "_sizer'" : "class='"  + className + "_se'";
    		
        win.innerHTML = closeDiv + minDiv + maxDiv + "\
          <table id='"+ id +"_row1' class=\"top table_window\">\
            <tr>\
              <td class='"+ className +"_nw'>&nbsp;</td>\
              <td class='"+ className +"_n'><div id='"+ id +"_top' class='"+ className +"_title title_window'>"+ this.options.title +"</div></td>\
              <td class='"+ className +"_ne'>&nbsp;</td>\
            </tr>\
          </table>\
          <table id='"+ id +"_row2' class=\"mid table_window\">\
            <tr>\
              <td class='"+ className +"_w'></td>\
                <td id='"+ id +"_table_content' class='"+ className +"_content' valign='top'>" + content + "</td>\
              <td class='"+ className +"_e'></td>\
            </tr>\
          </table>\
            <table id='"+ id +"_row3' class=\"bot table_window\">\
            <tr>\
              <td class='"+ className +"_sw'>&nbsp;</td>\
                <td class='"+ className +"_s'><div id='"+ id +"_bottom' class='status_bar'>&nbsp;</div></td>\
                <td " + seAttributes + ">&nbsp;</td>\
            </tr>\
          </table>\
        ";
    		Element.hide(win);
    		this.options.parent.insertBefore(win, this.options.parent.firstChild);
    		Event.observe($(id + "_content"), "load", this.options.onload);
    		return win;
    	},
    
    [ . . . ][ . . . ]
    je pense qu'il faut ajouter une ligne dans le style de

    this.EventOnKeyPress = this.fonction à appeler ()

    mais ca ne marche pas.

  2. #2
    Modérateur
    Avatar de Bisûnûrs
    Profil pro
    Développeur Web
    Inscrit en
    Janvier 2004
    Messages
    9 889
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2004
    Messages : 9 889
    Points : 16 336
    Points
    16 336
    Par défaut
    Essaie plutôt :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    element.onkeypress = function(){ functionAAppeler(); };

  3. #3
    Membre régulier Avatar de keub51
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    349
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 349
    Points : 116
    Points
    116
    Par défaut
    ok l'evenement est bien intercepté avec ton code merci

    et maintenant il faut verifier que la touche pressé est " échap "

    this.onkeypress = function(){ if("c'est touche echap") this.destroy(); };

  4. #4
    Modérateur
    Avatar de Bisûnûrs
    Profil pro
    Développeur Web
    Inscrit en
    Janvier 2004
    Messages
    9 889
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2004
    Messages : 9 889
    Points : 16 336
    Points
    16 336

  5. #5
    Membre régulier Avatar de keub51
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    349
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 349
    Points : 116
    Points
    116
    Par défaut
    heu en fait jme suis trompé :

    this.onKeyPress = function()
    {
    alert("hihi");
    };

    n'intercepte pas levenement clavier ... pas d'alert ...

  6. #6
    Membre régulier Avatar de keub51
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    349
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 349
    Points : 116
    Points
    116
    Par défaut
    il ne faudrait aps ajouter une ligne de ce style :


    Event.observe(this.topbar, "mousedown", this.eventMouseDown);
    Event.observe(this.bottombar, "mousedown", this.eventMouseDown);
    Event.observe(this.content, "mousedown", this.eventMouseDownContent);
    Event.observe(window, "load", this.eventOnLoad);

    mais spécifique a onkeypress ?

  7. #7
    Modérateur
    Avatar de Bisûnûrs
    Profil pro
    Développeur Web
    Inscrit en
    Janvier 2004
    Messages
    9 889
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2004
    Messages : 9 889
    Points : 16 336
    Points
    16 336
    Par défaut
    Bizarre. Essaie comme ça alors :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    this.onkeypress = uneFonction;
     
    function uneFonction(){
       alert('test');
    }
    ou :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    this.onkeydown = uneFonction;
     
    function uneFonction(){
       alert('test');
    }

  8. #8
    Membre régulier Avatar de keub51
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    349
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 349
    Points : 116
    Points
    116
    Par défaut
    voici ce que deviens mon code :

    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
    		// Bind event listener
        this.eventMouseDown = this._initDrag.bindAsEventListener(this);
      	this.eventMouseUp   = this._endDrag.bindAsEventListener(this);
      	this.eventMouseMove = this._updateDrag.bindAsEventListener(this);
      	this.eventOnLoad    = this._getWindowBorderSize.bindAsEventListener(this);
        this.eventMouseDownContent = this.toFront.bindAsEventListener(this);
        this.eventOnKeyPress = this.myfunction;
     
        function myfunction()
        {alert("hihi");};
     
     
        if (this.options.recenterAuto)
          this.eventResize = this._recenter.bindAsEventListener(this);
     
    		this.topbar = $(this.element.id + "_top");
    		this.bottombar = $(this.element.id + "_bottom");
            this.content = $(this.element.id + "_content");
            Event.observe(this.content, "onkeypress", this.eventOnKeyPress);
    mais ca ne fonctionne toujours pas ...

  9. #9
    Modérateur
    Avatar de Bisûnûrs
    Profil pro
    Développeur Web
    Inscrit en
    Janvier 2004
    Messages
    9 889
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2004
    Messages : 9 889
    Points : 16 336
    Points
    16 336
    Par défaut
    Ben déjà là tu mets une fonction dans une autre fonction.

    Créé une fonction en dehors de celle-ci, sur la base des autres fonctions toFront, endrag, etc.

    Et appelle comme ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    this.eventOnKeyPress = this.myFunction.bindAsEventListener(this);
    Je ne sais pas si ça va marcher vu que je ne connais pas prototype, mais c'est ce qui me paraît le plus logique.

  10. #10
    Membre régulier Avatar de keub51
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    349
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 349
    Points : 116
    Points
    116
    Par défaut
    j'ai modifié mon script comme dit mais rien ne se passe la pop - up ne se charge plus et aucune erreur detectée par la console javascript de ff ...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    // Bind event listener
        this.eventMouseDown = this._initDrag.bindAsEventListener(this);
      	this.eventMouseUp   = this._endDrag.bindAsEventListener(this);
      	this.eventMouseMove = this._updateDrag.bindAsEventListener(this);
      	this.eventOnLoad    = this._getWindowBorderSize.bindAsEventListener(this);
        this.eventMouseDownContent = this.toFront.bindAsEventListener(this);
        this.eventOnKeyPress = this.myFunction.bindAsEventListener(this);
    voici la fonction de destruction appellée :
    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
     
    // Destructor
     	destroy: function() {
    		Windows.notify("onDestroy", this);
      	Event.stopObserving(this.topbar, "mousedown", this.eventMouseDown);
      	Event.stopObserving(this.bottombar, "mousedown", this.eventMouseDown);
      	Event.stopObserving(this.content, "mousedown", this.eventMouseDownContent);
     
    		Event.stopObserving(window, "load", this.eventOnLoad);
    		if (this.options.recenterAuto) {
    		  Event.stopObserving(window, "resize", this.eventResize);
      	  Event.stopObserving(window, "scroll", this.eventResize);
    	  }
     
    		Event.stopObserving(this.content, "load", this.options.onload);
     
    		if (this._oldParent) {
    			var content = this.getContent();
    			var originalContent = null;
    			for(var i = 0; i < content.childNodes.length; i++) {
    				originalContent = content.childNodes[i];
    				if (Node.ELEMENT_NODE == originalContent.nodeType) break;
    				originalContent = null;
    			}
    			if (originalContent)
    			  this._oldParent.appendChild(originalContent);
    			this._oldParent = null;
    		}
     
    		if (this.sizer)
        		Event.stopObserving(this.sizer, "mousedown", this.eventMouseDown);
     
    		if (this.options.url)
    		  this.content.src = null
     
    	 	if(this.iefix) 
    			Element.remove(this.iefix);
     
        Element.remove(this.element);
    		Windows.unregister(this);	    
    	},
    le code de MyFunction :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    myFunction: function() {
    	  	this.destroy();	
    	},

  11. #11
    Membre régulier Avatar de keub51
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    349
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 349
    Points : 116
    Points
    116
    Par défaut
    ca fait une heure que je cherche apres la solution mais il m'a l'air que ce framework n'a pas beaucoup de doc dispo ... c'est dommage ... quelqu'u pourrait t'il se pencher sur ma question ?


    je pense qu'il ne faut pas reflechir sur :

    Event.observe(element HTML | id , nom de l'evenement, fonction à executer, [useCapture])

    car on ne peut surveiller que des element HTML, div ... et pas d'evenement clavier.

  12. #12
    Membre régulier Avatar de keub51
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    349
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 349
    Points : 116
    Points
    116
    Par défaut
    lol une question qui restera sans reponses ...

    pour faire simple : comment gère t'on des événements claviers avec le framework prototype javascript ?

  13. #13
    Membre régulier Avatar de keub51
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    349
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 349
    Points : 116
    Points
    116
    Par défaut
    Up. mais j'ai vraiment besoin d'une réponse

Discussions similaires

  1. [AJAX] Tutoriel, Autocompletion et event onkeypress
    Par Kael dans le forum Général JavaScript
    Réponses: 12
    Dernier message: 21/06/2007, 11h21
  2. Gérer les events d'un tableau de boutons
    Par lord_kalipsy dans le forum wxWidgets
    Réponses: 7
    Dernier message: 20/10/2004, 10h13
  3. Réponses: 4
    Dernier message: 21/05/2004, 09h13
  4. Accès à une case d'un DBGrid dans l'event OnKeyDown
    Par fba dans le forum Bases de données
    Réponses: 2
    Dernier message: 02/03/2004, 12h48

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