: Indesign API built-in events paragraph-style Does Indesign trigger any events when a paragraph style object does change? Or is there any built in javascript functionality that can observe an object?
Does Indesign trigger any events when a paragraph style object does change? Or is there any built in javascript functionality that can observe an object? Object.obserce and Proxy are not working in CS6.
More posts by @Angela777
1 Comments
Sorted by latest first Latest Oldest Best
The documentation states that you can attach event listeners to DOM objects such as myParaStyle.addEventListener but I could never got something to work with those.
But you can use an idleEvent listener and look around at possible styles edits:
#targetengine "onAfterSelectionChanged"
var main = function() {
var currDocId, stylesDB = {};
var onAfterParagraphStyleEdit = function ( evt ) {
var doc = evt.parent, docId;
if ( !app.documents.length ) return;
doc = app.activeDocument;
docId = doc.id;
if ( !currDocId
||
currDocId!=docId ) {
currDocId = docId;
stylesDB = getStylesDB(doc);
return;
}
try {
compareStyles ( doc, stylesDB ) ;
}
catch(err) {
alert ( err.line+"//"+err.message );
}
}
var it = app.idleTasks.itemByName ("onAfterParagraphStyleEdit" );
if ( !it.isValid ) {
it =app.idleTasks.add({name:"onAfterParagraphStyleEdit", sleep:100});
it.addEventListener(IdleEvent.ON_IDLE, onAfterParagraphStyleEdit, false);
}
}
main();
var compareStyles = function ( doc, db ) {
var pss = doc.allParagraphStyles, ps, psId, psProps,
n = pss.length, diffs = [];
while ( n-- ) {
ps = pss[n];
psId = ps.id;
if ( !db[psId] ) {
db[psId] = ps.properties.toSource();
}
else {
psProps = ps.properties.toSource();
if ( db[psId] != psProps) {
diffs.push ( ps.name +"["+ps.id+"]" );
db[psId] = psProps;
}
}
}
diffs.length && alert("Those styles were modified…r"+diffs.join("r"
) );
}
var getStylesDB = function ( doc ) {
var db = {};
var pss = doc.allParagraphStyles, ps,
n = pss.length;
while ( n-- ) {
ps = pss[n];
db[pss[n].id] = ps.properties.toSource();
}
return db;
}
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.