forked from yui/yui3-gallery
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gallery-2011.05.04-20-03 caridy gallery-get-selection
- Loading branch information
YUI Builder
committed
May 4, 2011
1 parent
b8d6a01
commit 5d422ce
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |