Labs/Jetpack/JEP/12: Difference between revisions
(3 intermediate revisions by the same user not shown) | |||
Line 20: | Line 20: | ||
The functions to manipulate and access the selection lives in <code>jetpack.selection</code>. | The functions to manipulate and access the selection lives in <code>jetpack.selection</code>. | ||
==== Getting and Setting ==== | ==== Getting and Setting the Selection ==== | ||
Getting and setting the selection live in a family of getters and setters, dependent on the format. | Getting and setting the selection live in a family of getters and setters, dependent on the format. For the first version of <code>.selection</code> we include to formats: text, and html. | ||
'''Setting the selection''' | '''Setting the selection''' | ||
Line 28: | Line 28: | ||
<pre class="brush:js;toolbar:false;"> | <pre class="brush:js;toolbar:false;"> | ||
jetpack.selection.text = "Hello"; | jetpack.selection.text = "Hello"; | ||
jetpack.selection.html = "<b>Hello</b>"; | jetpack.selection.html = "<b>Hello</b>";</pre> | ||
var | |||
''' Getting the selection''' | |||
jetpack.selection.html = | |||
<pre class="brush:js;toolbar:false;"> | |||
var textOfSel = jetpack.selection.text; | |||
var htmlOfSel = jetpack.selection.html;</pre> | |||
Eventually, one may be able to do <code>jetpack.selection.fragment</code> which would let you manipulate the selection live. That is, however, outside the scope of JEP 12. | |||
==== onSelection ==== | |||
A very common desire is to perform some sort of action when a selection is made. Often that is looking up the selection, or creating an actionable nib. <code>jetpack.selection.onSelection</code> enables Jetpack authors to easily get notified when a selection is made. | |||
<pre class="brush:js;toolbar:false;">jetpack.selection.onSelection( callback );</pre> | |||
''Arguments'' | |||
* '''callback''': Is the function to be called when a selection is made. It receives no arguments. Instead, use <code>jetpack.selection.*</code>. | |||
To remove an event handler is done the normal Jetpack way: | |||
<pre class="brush:js;toolbar:false;">jetpack.selection.onSelection.unbind( callback );</pre> | |||
''Arguments'' | |||
* '''callback''': A pointer to the event handler to be unbound. | |||
'''Example''' | |||
<pre class="brush:js;toolbar:false;">jetpack.selection.onSelection(function(){ | |||
var html = jetpack.selection.html; | |||
jetpack.selection.html = ">>>" + html + "<<<"; | |||
});</pre> |
Latest revision as of 05:58, 26 June 2009
JEP 12 - jetpack.selection
- Champion: Aza Raskin <aza at mozilla dot com>
- Status: Implementing
- Type: API Track
- Created: 24 June 2009
- Reference Implementation: jetpack.future.import("selection")
- JEP Index
Introduction and Rationale
Performing a selection is one of fundamental computer-human interactions, acting as a close proxy for a users locus of attention. Even at the time of the writing of this JEP, numerous Jetpacks have already implemented disparate ways of getting and detecting selections.
Jetpacks should be able to set, get, and listen for selection events.
Proposal
The functions to manipulate and access the selection lives in jetpack.selection
.
Getting and Setting the Selection
Getting and setting the selection live in a family of getters and setters, dependent on the format. For the first version of .selection
we include to formats: text, and html.
Setting the selection
jetpack.selection.text = "Hello"; jetpack.selection.html = "<b>Hello</b>";
Getting the selection
var textOfSel = jetpack.selection.text; var htmlOfSel = jetpack.selection.html;
Eventually, one may be able to do jetpack.selection.fragment
which would let you manipulate the selection live. That is, however, outside the scope of JEP 12.
onSelection
A very common desire is to perform some sort of action when a selection is made. Often that is looking up the selection, or creating an actionable nib. jetpack.selection.onSelection
enables Jetpack authors to easily get notified when a selection is made.
jetpack.selection.onSelection( callback );
Arguments
- callback: Is the function to be called when a selection is made. It receives no arguments. Instead, use
jetpack.selection.*
.
To remove an event handler is done the normal Jetpack way:
jetpack.selection.onSelection.unbind( callback );
Arguments
- callback: A pointer to the event handler to be unbound.
Example
jetpack.selection.onSelection(function(){ var html = jetpack.selection.html; jetpack.selection.html = ">>>" + html + "<<<"; });