Hi Peter,
I've reworked that function to make it more complete.
Here's my current version...
var FindWhere = function (obj, where){
var kAppVersion = parseFloat(app.version);
var getTextContainer = function (s){
if(kAppVersion<5){return s.textFrames[-1]}else{return s.textContainers[s.textContainers.length-1]}
}
var getobj = function (fm){//returns the parent text frame, or the last one of the parent story
if(fm != undefined){return fm;}else{return getTextContainer(obj.parentStory);}
}
var getobj_ptf = function (obj){//get the parent text frame or return the original object (necessary for Notes)
try{ return obj.parentTextFrames[0]}catch(e){return obj}
}
var getobj_cell = function (fm){//returns the parent text frame, or the last one of the parnet story -- for cells
if(fm != undefined){return fm;}else{return getTextContainer(obj.insertionPoints[0].parentStory);}
}
var getnote_tf = function (note){//gets the note location for both footnotes and notes in all versions...
if(kAppVersion<5){
if(note.hasOwnProperty("footnoteTextFrame")){var parentFrame = note.footnoteTextFrame}//no good for overset...
else{var parentFrame = note.parentTextFrame}
if(parentFrame){return parentFrame}
else{return note.parent}
}
else{return note.storyOffset}
}
var e;
if(!obj){return null}
if(where == undefined){var where = Page;}
if(obj.hasOwnProperty("baseline")){obj = getobj(getobj_ptf (obj))}
while(obj){
switch(obj.constructor){
case where: return obj;
case Story: obj = getTextContainer(obj);break;
case Character: obj = getobj(getobj_ptf (obj));break;
case Cell: obj = getobj_cell(getobj_ptf(obj.insertionPoints[0]));break;
case Note:
case Footnote: obj = getnote_tf(obj);break;
case Application: return null;
}
if (!obj) return null;
obj = obj.parent;
}
return null;
}
... View more