advertisement
![Working with eventListeners. Adobe InCopy CS6 | Manualzz Working with eventListeners. Adobe InCopy CS6 | Manualzz](http://s3.manualzz.com/store/data/053735944_1-9a07498f63a38018bc60cb3051c12045-360x466.png)
Events Working with eventListeners 78
Property
Bubbles
Cancelable
Captures
Description
If true, the event
propagates to scripting objects above the object initiating the event
.
If true, the default behavior of the event
on its target
can be canceled. To do this, use the PreventDefault method.
If true, the event
may be handled by eventListeners
registered to scripting objects above the target object of the event during the capturing phase of event propagation. This means an eventListener
on the application, for example, can respond to a document event before an eventListener is triggered.
CurrentTarget
DefaultPrevented
TimeStamp
The current scripting object processing the event
. See target
in this table.
If true, the default behavior of the event
on the current target
(see target
in this table) was prevented, thereby cancelling the action.
The current stage of the event
propagation process.
EventPhase
EventType
The type of the event
, as a string (for example,
"beforeNew"
).
PropagationStopped
If true, the event
has stopped propagating beyond the current target
(see target in this table). To stop event propagation, use the stopPropagation method.
Target
The object from which the event
originates. For example, the target
of a beforeImport
event is a document; of a beforeNew
event, the application.
The time and date the event occurred.
Working with eventListeners
When you create an eventListener
, you specify the event type (as a string) the event handler (as a
JavaScript function or file reference), and whether the eventListener can be triggered in the capturing phase of the event. The following script fragment shows how to add an eventListener
for a specific event (for the complete script, see AddEventListener).
#targetengine "session" main(); function main(){ var myEventListener = app.addEventListener("afterNew", myDisplayEventType, false);
} function myDisplayEventType(myEvent){ alert("This event is the " + myEvent.eventType + " event.");
}
To remove the eventListener
created by the above script, run the following script (from the
RemoveEventListener tutorial script): app.removeEventListener("afterNew", myDisplayEventType, false);
When an eventListener
responds an event, the event may still be processed by other eventListeners that might be monitoring the event (depending on the propagation of the event). For example, the
Events Working with eventListeners 79 afterOpen
event can be observed by eventListeners
associated with both the application and the document.
eventListeners
do not persist beyond the current InCopy session. To make an eventListener
available in every InCopy session, add the script to the startup scripts folder (for more on installing scripts, see
). When you add an eventListener script to a document, it is not saved with the document or exported to INX.
N OTE : If you are having trouble with a script that defines an eventListener , you can either run a script that removes the eventListener
or quit and restart InCopy.
eventListeners that use handler functions defined inside the script (rather than in an external file) must use
#targetengine "session"
. If the script is run using
#targetengine "main"
(the default), the function is not available when the event occurs, and the script generates an error.
An event can trigger multiple eventListeners
as it propagates through the scripting object model. The following sample script demonstrates an event triggering eventListeners
registered to different objects
(for the full script, see MultipleEventListeners):
#targetengine "session" main(); function main(){ var myApplicationEventListener = app.eventListeners.add("beforeImport", myEventInfo, false); var myDocumentEventListener = app.documents.item(0).eventListeners.add
("beforeImport", myEventInfo, false);
} function myEventInfo(myEvent){ var myString = "Current Target: " + myEvent.currentTarget.name; alert(myString);
}
When you run the preceding script and place a file, InCopy displays alerts showing, in sequence, the name of the document, then the name of the application.
The following sample script creates an eventListener
for each supported event and displays information about the event in a simple dialog box. For the complete script, see EventListenersOn.
main() function main(){ app.scriptPreferences.version = 5.0; var myEventNames = [
"beforeQuit", "afterQuit",
"beforeNew", "afterNew",
"beforeOpen", "afterOpen",
"beforeClose", "afterClose",
"beforeSave", "afterSave",
"beforeSaveAs", "afterSaveAs",
"beforeSaveACopy", "afterSaveACopy",
"beforeRevert", "afterRevert",
"beforePrint", "afterPrint",
"beforeExport", "afterExport",
"beforeImport", "afterImport"
] ; for (var myCounter = 0; myCounter < myEventNames.length; myCounter ++){ app.addEventListener(myEventNames[myCounter], myEventInfo, false);
}
} function myEventInfo(myEvent){
advertisement
Related manuals
advertisement
Table of contents
- 7 Introduction
- 7 How to use the scripts in this document
- 7 About the structure of the scripts
- 8 For more information
- 8 About InCopy
- 8 Relationships between InCopy and InDesign files
- 8 Stories
- 9 Page geometry
- 9 Metadata
- 9 The document model
- 10 User-interface differences
- 10 Design and architecture
- 11 Getting Started
- 11 Installing scripts
- 12 Running scripts
- 12 Using the scripts panel
- 12 JavaScript language details
- 13 Other JavaScript development options
- 13 Using the scripts in this document
- 14 Your first InCopy script
- 14 Walking through the script
- 15 Scripting terminology and the InCopy object model
- 15 Scripting terminology
- 18 Understanding the InDesign and InCopy object model
- 21 Measurements and positioning
- 22 Adding features to “Hello World
- 24 Scripting Features
- 24 Script preferences
- 25 Getting the current script
- 25 Script versioning
- 26 Targeting
- 26 Compilation
- 26 Interpretation
- 27 Using the doScript method
- 27 Sending parameters to doScript
- 27 Returning values from doScript
- 28 Running scripts at start-up
- 28 Session and main script execution
- 30 Text and Type
- 30 Entering and importing text
- 30 Stories and text frames
- 30 Adding text to a story
- 31 Replacing text
- 31 Inserting special characters
- 32 Placing text and setting text-import preferences
- 35 Exporting text and setting text-export preferences
- 39 Text objects
- 40 Selections
- 40 Moving and copying text
- 42 Text objects and iteration
- 43 Formatting text
- 43 Setting text defaults
- 45 Fonts
- 46 Applying a font
- 46 Changing text properties
- 47 Changing text color
- 48 Creating and applying styles
- 49 Deleting a style
- 49 Importing paragraph and character styles
- 50 Finding and changing text
- 50 Find/change preferences
- 51 Finding text
- 52 Finding and changing formatting
- 53 Using grep
- 55 Using glyph search
- 55 Tables
- 58 Autocorrect
- 59 Footnotes
- 60 User Interfaces
- 60 Dialog-box overview
- 61 Your first InCopy dialog box
- 62 Adding a user interface to “Hello World
- 63 Creating a more complex user interface
- 65 Working with ScriptUI
- 65 Creating a progress bar with ScriptUI
- 65 Creating a button-bar panel with ScriptUI
- 68 Menus
- 68 Understanding the menu model
- 70 Localization and menu names
- 71 Running a menu action from a script
- 71 Adding menus and menu items
- 72 Menus and events
- 73 Working with script menu actions
- 75 Events
- 75 Understanding the event scripting model
- 77 About event properties and event propagation
- 78 Working with eventListeners
- 80 A sample “afterNew” eventListener
- 82 Notes
- 82 Entering and importing a note
- 82 Adding a note to a story
- 82 Replacing text of a note
- 83 Converting between notes and text
- 83 Converting a note to text
- 83 Converting text to a note
- 83 Expanding and collapsing notes
- 83 Collapsing a note
- 83 Expanding a note
- 84 Removing a note
- 84 Navigating among notes
- 84 Going to the first note in a story
- 84 Going to the next note in a story
- 84 Going to the previous note in a story
- 85 Going to the last note in a story
- 86 Tracking Changes
- 86 Navigating tracked changes
- 87 Accepting and reject tracked changes
- 87 Information about tracked changes
- 88 Preferences for tracking changes
- 90 Assignments
- 90 Assignment object
- 90 Opening assignment files
- 90 Iterating through assignment properties
- 91 Assignment packages
- 91 An assignment story
- 91 Assigned-story object
- 91 Iterating through the assigned-story properties
- 93 Overview
- 93 The best approach to scripting XML in InCopy
- 94 Scripting XML Elements
- 94 Setting XML preferences
- 94 Setting XML import preferences
- 95 Importing XML
- 95 Creating an XML tag
- 96 Loading XML tags
- 96 Saving XML tags
- 96 Creating an XML element
- 96 Moving an XML element
- 97 Deleting an XML element
- 97 Duplicating an XML element
- 97 Removing items from the XML structure
- 97 Creating an XML comment
- 98 Creating an XML processing instruction
- 98 Working with XML attributes
- 99 Working with XML stories
- 99 Exporting XML
- 99 Adding XML elements to a story
- 100 Associating XML elements with text
- 102 Applying styles to XML elements
- 103 Working with XML tables