//
function docPageSpreadOfFrame (theFrame) {
//-------------------------------------------------------------------------
//-- D O C P A G E S P R E A D O F F R A M E
//-------------------------------------------------------------------------
//-- Generic: Yes, for Adobe InDesign. Tested with CS3 but should work
//-- will CS2 through CS4
//-------------------------------------------------------------------------
//-- Purpose: To return a reference to the document, page, and spread
//-- for the passed frame.
//-- The need for referencing a page and a spread is because an item
//-- on the pasteboard won't be on a page. If you are creating new
//-- ojbects nearby, you need to know where the object is.
//-------------------------------------------------------------------------
//-- Returns: An object of 4 properties:
//-- objectDoc: The Document Object for the frame
//-- objectPageNum: The page number from the front of the document
//-- objectPageRef: A referece to that page
//- objectSpreadRef: A reference to the spread of the object.
//-------------------------------------------------------------------------
//-- Calls: Nothing.
//-------------------------------------------------------------------------
//-- Written: 2008.08.28 by Jon S. Winters
//-- Edited: 2009.01.21 by Jon S. Winters for version 2n to reutrn object.
//-- © 2009 electronic publishing support. All rights reserved.
//-------------------------------------------------------------------------
//-- How it works:
//-- Assume we have an item on a page. If instead it is on a spread, then
//-- the normal method of finding the document (looking at the paretnt)
//-- will instead find the application. If so, then back down.
//-- Note, we will assume the page the item goes on is the right hand page
//-- of the spread. This is only if the item doesn't appear on a page
//-------------------------------------------------------------------------
//-- Version 2.05 put in controls so that it will return if a frame
//-- was not passed.
//-------------------------------------------------------------------------
if ( '|Group|TextFrame|GraphicLine|Oval|Polygon|Rectangle|'.indexOf ('|' + theFrame.reflect.name + '|' , 0 ) < 0 ) {
alert ( "The function 'docAndPageFromFrame' was not passed a frame." ) ;
return null ;
}
//-- Verify that we do not have an anchored item. 2.05
if (theFrame.parent.reflect.name == 'Character' ) {
theFrame = theFrame.parent.parentStory.textContainers[0] ;
}
//-- Version 2.05 method works when theFrame is part of a group or
//-- even if it is burried deeper.
var objRef = theFrame
var objRefParent = objRef.parent ;
while ( objRefParent.reflect.name != 'Spread' ) {
objRef = objRefParent ;
objRefParent = objRef.parent ;
}
//-- At this point, the objRef is still unknown, but we know the spread details
//-- Keep the spreadReference and build the doc reference.
var spreadRef = objRefParent ;
//-- Get the doc from the frame using the normal method.
var theDocOfTheFrame = spreadRef.parent ;
//-- Now check to see if the obeject before the spread is a page
if (objRef.reflect.name == 'Page' ) {
//--on a page
var pageRef = objRef ;
var thePageNumOfTheFrame = pageRef.documentOffset + 1 ;
}
else {
//-- likely a group or something else
//-- The below 'Page' is fake, but it works in most cases
var pageRef = spreadRef ;
var lastPageOfSpread = spreadRef.pages.item( (spreadRef.pages).length - 1 ) ;
var thePageNumOfTheFrame = lastPageOfSpread.documentOffset + 1
}
//-- Now setup a return object
return {objectDoc:theDocOfTheFrame , objectPageNum:thePageNumOfTheFrame , objectPageRef:pageRef , objectSpreadRef:spreadRef }
} //-- End of Function
//
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment