• Register
  • Log In
  • Home
  • Quick Start
    • Configurator
    • Download YUI 3
  • Documentation
    • User Guides
    • Examples
    • API Docs
    • Environments
    • Tutorials
  • Community
    • Gallery
    • Blog
    • Forums
    • YUI Theater
    • Calendar
  • Contribute
    • YUI on GitHub »
    • File a Ticket
    • View Tickets
    • Dashboard
  • Other Projects
    • Shifter »
    • Yogi »
    • YUI 2
    • YUI Doc »
    • YUI Test
    • YUI Website
    • YUI Compressor »
    • YUI Builder »
    • YUI PHP Loader
    • Grid Builder »
    • Skin Builder »
  • YUI
  • >
  • Community
  • >
  • Gallery

Gallery

Modules

  • Home
  • Featured
  • Popular
  • New
  • All

Documentation

  • Yogi Documentation
  • Shifter Documentation
  • Developer Guide
  • Module Setup

Tag Cloud

Context Navigation

    YUI Library is not responsible for bugs or support with this module. It is available as a free service. For support please contact the module owner with the provided links.

    Selection Event (gallery-event-selection) on cdn

    Last Updated: 06/20/12
    + 3 -

    Stephen Murphy

    YUI Contributor

    See 4 more by this user.

    Created: 06/2/12
    Last CDN Push: 10/3/12
    Build Tag: gallery-2012.10.03-20-02
    Project: YUI 3
    License: YUI BSD
    YUI Version: 3.6.0pr2
    Free for use.

    Cross browser/device text selection events.
    - selection: Fired when text has been selected.
    - selectionchange: Fired when text has been selected or deselected.

    Fired events have the following properties:
    - selection: Selected text.
    - pageX/pageY: Best guess on where selection ends.

    Limitations:
    - There are a few edge cases where selection events don't work well. Namely, when selecting text that crosses the boundary of a bounded node or selecting text with only keyboard selection.

    Notes:
    - Polling for selection changes is necessary because iOS doesn't tell us when the selection region has been updated and desktop browsers can use keyboard selection.
    - iOS requires a slight delay when getting selected text.

    • Tags:
    • selection
    • event
    • twobit
    • Download
    • Docs
    • Homepage
    • Bugs
    • Source
    • Example
    • Forum
    • History

    Code Sample

    <script src="http://yui.yahooapis.com/3.6.0pr2/build/yui/yui-min.js"></script>
    YUI({
        //Last Gallery Build of this module
        gallery: 'gallery-2012.10.03-20-02'
    }).use('gallery-event-selection', function(Y) {
        // Fired on text selection/deselection
        Y.one('body').on('selectionchange', function(e) {
            console.log('selectionchange: ' + e.selection);
        });
     
        // Fired only on text selection
        Y.one('body div').on('selection', function(e) {
            console.log('selection: ' + e.selection);
        });
    });

    © 2006-2013 Yahoo! Inc. All rights reserved.
    All code on this site is licensed under the BSD License unless stated otherwise.
    About This Site · Security Contact Info