Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6616

Show
Ignore:
Timestamp:
04/28/07 23:34:06 (1 year ago)
Author:
mislav
Message:

Prototype: Event Safari fixes

  • Tried to please Safari for middle click - right click seems impossible
  • added a test that listens to 'contextmenu' event and tries to prevent it
  • Event.prototype augmentation is excluded from WebKit now. Sorry Safari,
    we'll have to make a workaround for you.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • spinoffs/prototype/branches/event/src/event.js

    r6615 r6616  
    105105  }); 
    106106 
    107   var EventMethods = { 
     107  Event.Methods = { 
    108108    stop: function(){ Event.stop(this) } 
    109109  }; 
     
    119119    }); 
    120120     
    121     Object.extend(Event.prototype, EventMethods); 
     121    // Safari can't stand this; we'll have to figure out a workaround 
     122    if (!B.WebKit) Object.extend(Event.prototype, Event.Methods); 
    122123  } else if (B.IE) { 
    123124    Object.extend(Observer.prototype, { 
     
    135136    }); 
    136137 
    137     Object.extend(EventMethods, { 
     138    Object.extend(Event.Methods, { 
    138139      stopPropagation: function() { this.cancelBubble = true }, 
    139140      preventDefault:  function() { this.returnValue = false }, 
     
    157158          relatedTarget: Event.relatedTarget(event) 
    158159        }); 
    159         return Object.extend(event, EventMethods); 
     160        return Object.extend(event, Event.Methods); 
    160161      } 
    161162    }); 
     
    187188    var buttonTranslations = { 0:1, 1:4, 2:2 }; 
    188189    var isButton = function(event, code) { 
    189       return event.button === buttonTranslations[code]; 
     190      return event.button == buttonTranslations[code]; 
     191    }; 
     192  } 
     193  else if (B.WebKit) { 
     194    var isButton = function(event, code) { 
     195      switch (code) { 
     196        case 0: return event.which == 1 && !event.metaKey; 
     197        case 1: return event.which == 1 && event.metaKey; 
     198        default: return false; 
     199      } 
    190200    }; 
    191201  } 
  • spinoffs/prototype/branches/event/test/functional/event.html

    r6615 r6616  
    197197  </script> 
    198198   
     199  <p id="context">Context menu event (tries to prevent default)</p> 
     200   
     201  <script type="text/javascript"> 
     202    $('context').observe('contextmenu', function(e){ 
     203      this.passed() 
     204      Event.stop(e) 
     205      log(e) 
     206    }) 
     207  </script> 
     208   
    199209  <div id="container"><p id="stop"><strong>Stop propagation</strong> test (bubbling)</p></div> 
    200210   
  • spinoffs/prototype/branches/event/TODO

    r6612 r6616  
    11* [done] Event handling (IE) fixes and enhancements, see r6194 
    22* [done] Remove all event listeners on any element 
    3 * [wontfix] event.stop() instead of Event.stop(event) 
     3* [broken] event.stop() instead of Event.stop(event) 
    44* [done] Node constants as per DOM/ECMAScript bindings (r6205) 
    5 * [done] isLeft/Middle/RightClick (r6537) 
     5* [done] isLeft/Middle/RightClick 
    66* [done] support for "DOMContentLoaded" 
    77* [done] Event.findElement should extend the result