How to modify events (for ex. +ctrlKey)?

Discussion in 'Javascript' started by niels.froehling@seies.de, Mar 1, 2006.

  1. Guest

    Hy;

    I'm stucked in modifying events to make a multi-select select-input
    being additive/subtractive only. Because I should offer a solution
    similar to that select for DAUs (aka. MostIdioticUser) I have to
    make something else (checkboxes?).
    It's not that want to fiddle around with events, but it seemed to be
    the
    most simply-plug-in-working-no-change-html-php solution.

    Here is a fragment (the select and the plug-in code, I guess it's
    explanatory for people fimilar with events, and it's not production-
    code, it's only trying, trying, trying, ...):

    <select size="10" name="uniqueMember[]" multiple="multiple"
    id="members">
    <option>ABC</option>
    <option>DEF</option>
    <option>GHI</option>
    <option>JKL</option>
    <option>MNO</option>
    <option>PQR</option>
    </select>
    <script type="text/javascript">
    function cloneEventMouse(nevt, oevt) {
    if (nevt.initMouseEvent)
    nevt.initMouseEvent(
    oevt.bubbles, // PRBool canBubbleArg
    oevt.cancelable, // PRBool cancelableArg
    oevt.view, // nsIDOMAbstractView viewArg
    oevt.detail, // PRInt32 detailArg
    oevt.screenX, // PRInt32 screenXArg
    oevt.screenY, // PRInt32 screenYArg
    oevt.clientX, // PRInt32 clientXArg
    oevt.clientY, // PRInt32 clientYArg
    oevt.ctrlKey, // PRBool ctrlKeyArg
    oevt.altKey, // PRBool altKeyArg
    oevt.shiftKey, // PRBool shiftKeyArg
    oevt.metaKey, // PRBool metkeyArg
    oevt.button, // PRUint16 buttonArg
    oevt.relatedTarget // nsIDOMEventTarget relatedTargetArg
    );
    else
    for (var key in oevt)
    try {
    nevt[key] = oevt[key];
    } catch(e) {}

    nevt.cloned = true;
    }

    function modifyEvent(receiver, oevt, templ) {
    var nevt = null;
    var typeEvent = null;
    var cloneEvent = null;

    /* determine type of event-cloning */
    switch (oevt.type) {
    case 'mousedown':
    case 'mouseover':
    case 'mouseout':
    case 'mouseup':
    typeEvent = "MouseEvents";
    cloneEvent = cloneEventMouse;
    break;
    default:
    return null;
    }

    /* get a template */
    if (!templ)
    templ = new Array();

    /* clone infos into template */
    for (var key in oevt)
    if (typeof oevt[key] != 'function' )
    if (typeof templ[key] == 'undefined')
    // try {
    templ[key] = oevt[key];
    // } catch(e) {}

    /* clone the event */
    if (document.createEvent && (nevt =
    document.createEvent(typeEvent))) {
    cloneEvent(nevt, templ);

    receiver.dispatchEvent(nevt);
    }
    else if (document.createEventObject && (nevt =
    document.createEventObject())) {
    cloneEvent(nevt, templ);

    receiver.fireEvent("on" + oevt.type, nevt);
    }

    if (nevt) {
    /* cancel the old event if possible */
    // if (oevt.bubbles) {
    if (oevt.stopPropagation)
    oevt.stopPropagation();
    oevt.cancelBubble = true; //}
    // if (oevt.cancelable)
    oevt.returnValue = false;
    }

    return nevt;
    }

    function tunnelEvent(obj, type, templ) {
    if (obj.addEventListener)
    obj.addEventListener(type,
    function m(event) {
    var cloned = (typeof event.cloned != 'undefined' &&
    event.cloned);

    /* modify if it's not allready */
    if (!cloned)
    modifyEvent(obj, event, templ);
    return cloned;
    }, true);
    else
    if (obj.attachEvent)
    obj.attachEvent('on' + type,
    function m(event) {
    var cloned = (typeof event.cloned != 'undefined' &&
    event.cloned);

    /* modify if it's not allready */
    if (!cloned) {
    modifyEvent(obj, event, templ);

    /* this is disgusting:
    *
    * reason to do it this way:
    * - internet explorer doesn't cancel events for inouts
    * - internet explorer rejects events for disabled inputs
    * - fireEvent is synchronous, the new event occurs before the
    old event
    *
    * so I do this
    * - create and send the new event with enabled field,
    everything works fine
    * - disable the input for the old event, after the new has
    been processed
    * - reactivate the input after old event rejected
    (setTimeout(0) seem to need longer)
    */
    obj.disabled = true;
    setTimeout(function ar() {
    obj.disabled = false;
    }, 0);
    }

    return cloned;
    });
    }

    tunnelEvent(document.getElementById('members'), 'mousedown', {
    'ctrlKey' : true });
    </script>

    Thanks for any suggestions
    Niels
    , Mar 1, 2006
    #1
    1. Advertising

  2. RobG Guest

    wrote:
    > Hy;
    >
    > I'm stucked in modifying events to make a multi-select select-input
    > being additive/subtractive only. Because I should offer a solution
    > similar to that select for DAUs (aka. MostIdioticUser) I have to
    > make something else (checkboxes?).
    > It's not that want to fiddle around with events, but it seemed to be
    > the
    > most simply-plug-in-working-no-change-html-php solution.
    >
    > Here is a fragment (the select and the plug-in code, I guess it's
    > explanatory for people fimilar with events, and it's not production-
    > code, it's only trying, trying, trying, ...):


    Your code looks like a rather horrible kludge, can you explain what you
    are trying to achieve? Modifying standard browser behaviour to suit a
    small set of users is nearly always counter-productive.

    Un-obtrusive on-screen help will usually solve the problem far more
    effectively. Where possible, provide a few moments of instruction to
    show users how to use a multiple-select element.

    Having learned to use the standard behaviour, your users will now be
    equipped to use any multiple-select anywhere, even in applications other
    than a browser (provided someone hasn't mucked-around with the UI). :)

    [...]


    --
    Rob
    RobG, Mar 2, 2006
    #2
    1. Advertising

  3. Guest

    > Your code looks like a rather horrible kludge, can you explain what you
    > are trying to achieve?


    I try to do

    onmousedown="event.ctrlKey = true; return true;"

    but I'm not allowed to do so with the IE/W3C-model it seems.
    So I tried to make cloneEventWithModifications().

    > Modifying standard browser behaviour to suit a
    > small set of users is nearly always counter-productive.


    Sadly I'm not living in a world were people want to _learn_ something,
    I'm
    living in a world were people are not even able to read titles like
    "Document-Tree" within a defined framework: 'Where am I?'. (BTW:
    world means: El Salvador)

    > Un-obtrusive on-screen help will usually solve the problem far more
    > effectively. Where possible, provide a few moments of instruction to
    > show users how to use a multiple-select element.
    >
    > Having learned to use the standard behaviour, your users will now be
    > equipped to use any multiple-select anywhere, even in applications other
    > than a browser (provided someone hasn't mucked-around with the UI). :)
    >
    > [...]


    I also suffer from programmation-illness, classification,
    encapsulation,
    logics etc., so I have severe down-grade problems. I thought the
    multiple
    select is soooo nice. :) But my Chief is too DAU, in everything, so I'm
    fighting clean concept against clean mind, everyday. 8ยด^[

    Okay, enough cried out, thanks for the response, you don't maybe have
    ....
    another ... idea? *duck*

    > Rob


    Ciao
    Niels
    , Mar 2, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shiv
    Replies:
    0
    Views:
    462
  2. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    334
    Chris
    Aug 30, 2005
  3. Hiroshi Ochi

    ctrlKey property in IE

    Hiroshi Ochi, Apr 4, 2004, in forum: Javascript
    Replies:
    10
    Views:
    206
    Hiroshi Ochi
    Apr 19, 2004
  4. Loony

    event.ctrlKey

    Loony, Aug 2, 2005, in forum: Javascript
    Replies:
    1
    Views:
    76
    Stephen Chalmers
    Aug 2, 2005
  5. Ziliang Chen
    Replies:
    0
    Views:
    65
    Ziliang Chen
    Jul 12, 2013
Loading...

Share This Page