Skip to content

Commit

Permalink
gallery-2011.05.04-20-03 caridy gallery-get-selection
Browse files Browse the repository at this point in the history
  • Loading branch information
YUI Builder committed May 4, 2011
1 parent b8d6a01 commit 5d422ce
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/gallery-get-selection/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Selection Build Properties

# As long as the 'builder' project is cloned to the default folder
# next to the 'yui3-gallery' project folder, the 'builddir' property does not
# need to be changed
#
# If the 'builder' project is checked out to an alternate location, this
# property should be updated to point to the checkout location.
builddir=../../../builder/componentbuild

# The name of the component. E.g. event, attribute, widget
component=gallery-get-selection

# The list of files which should be concatenated to create the component
# NOTE: For a css component. (e.g. cssfonts, cssgrids etc.) use component.cssfiles instead.
# component.jsfiles=get-selection.js, get-selectionHelperClass.js, get-selectionSubComponentClass.js
component.jsfiles=get-selection.js

# The list of modules this component. requires. Used to set up the Y.add module call for YUI 3.
component.requires=node
7 changes: 7 additions & 0 deletions src/gallery-get-selection/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- YUI 3 Gallery Component Build File -->
<project name="Selection" default="local">
<description>Selection Build File</description>
<property file="build.properties" />
<import file="${builddir}/3.x/bootstrap.xml" description="Default Build Properties and Targets" />
</project>
37 changes: 37 additions & 0 deletions src/gallery-get-selection/js/get-selection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Getting a DOM fragment with the dom structure selected by the user.
* @module gallery-get-selection
* @requires node
*/

/**
* Return a DOM Fragment with the dom structure selected by the user to
* facilitate the analysis of that fragment.
* E.g., Y.getSelection().all('p').size() will give you the number of paragraphs
* selected by the user.
* @class getSelection
* @static
*/

/*
* All the credit for Dav Glass (@davglass), since he has provided the whole chunk of code,
* I just did the monkey work.
*/
Y.getSelection = function() {
var sel,
frag;

if (Y.config.win.getSelection) {
sel = Y.config.win.getSelection().getRangeAt(0);
} else if (Y.config.doc.selection) {
sel = Y.config.doc.selection.createRange();
}

if (sel.cloneContents) {
frag = sel.cloneContents();
} else if (sel.htmlText) {
frag = Y.Node.create(sel.htmlText);
}

return Y.Node.create('<div></div>').append(frag);
};

0 comments on commit 5d422ce

Please sign in to comment.