forked from makeBetterEBooks/eprdctn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStorySplitterNK
147 lines (136 loc) · 7.6 KB
/
StorySplitterNK
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
---------------------------------------------------------------------- --------------------------------------------
StorySplitter
---------------------------------------------------------------------- --------------------------------------------
An InDesign CS/CS2/CS3 JavaScript by FourAces
© The Final Touch 2006
Version 3.0.0
Splits the selected Story to separate Text Frames, while maintaining their contents.
---------------------------------------------------------------------- --------------------------------------------
Update by Naomi Kennedy
*/
#target "InDesign"
#targetengine "session"
app.scriptPreferences.enableRedraw = 0;
app.doScript(thisFunction, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Split Story");
var myScriptVer = "3.0";
function thisFunction (){
if(app.documents.length != 0){
var mySelection = app.activeDocument.selection;
if(mySelection.length != 0){
myObjectType = mySelection[0].constructor.name;
if(myObjectType == "TextFrame"){
//The Interface Dialog
var myDialog = app.dialogs.add({name:"Story Splitter v"+ myScriptVer});
with(myDialog){
with(dialogColumns.add()){
with (dialogRows.add()){
with(borderPanels.add()){
var mySplitOptions = radiobuttonGroups.add();
with(mySplitOptions){
radiobuttonControls.add({staticLabel:"Split All Frames"});
radiobuttonControls.add({staticLabel:"Split Before Selected Frame", checkedState:true});
radiobuttonControls.add({staticLabel:"Split After Selected Frame"});
}
}
}
with (dialogRows.add()){
staticTexts.add({staticLabel:"© The Final Touch"});
}
}
}
var myResult = myDialog.show({name:"SplitOptions"});
if(myResult == true){
var myStory = mySelection[0].parentStory;
if(app.version.split(".")[0] >= 5){
var myTextFrames = myStory.textContainers;
}
else{
var myTextFrames = myStory.textFrames;
}
var myStoryFramesCount = myTextFrames.length;
if(myStoryFramesCount > 1){
for(f = 0; f < myStoryFramesCount; f++){
if (mySelection[0] == myStory.textFrames[f]){
var myTextFrame = f;
}
}
switch(mySplitOptions.selectedButton){
case 0:
mySplitAll();
break;
case 1:
mySplitBefore();
break;
case 2:
mySplitAfter();
break;
}
}
else{
alert("Are You Kidding Me?!\nThe Story you selected has only ONE text frame.");
}
}
}
else{
alert("Wrong Selection\nYou selected the wrong type of object. Please select a Text Frame.");
}
}
else{
alert("No Selection Made.\nPlease select a Story to split.");
}
}
else{
alert("No Active Document Found.\nPlease open an InDesign document and select a Story to split.");
}
//-------------------------------------------------------------------- --------
function mySplitAll(){
for(i = 0; i < myStoryFramesCount; i++){
myTextFrames[i].duplicate();
}
for(i = 0; i < myStoryFramesCount; i++){
if(app.version.split(".")[0] >= 5){
myTextFrames[i].remove();
}
else{
myTextFrames[0].remove();
}
}
}
function mySplitBefore(){
if(mySelection[0].previousTextFrame == null){
alert("Unable to break thread.\nThe selected Text Frame is the FIRST text frame of the thread.");
}
else{
var myBfBreakFrame = mySelection[0].previousTextFrame;
var myAfBreakFrame = mySelection[0];
var myBreakStory = myBfBreakFrame.parentStory;
mySelection[0].previousTextFrame = null;
if(myBfBreakFrame.overflows == true){
var myOversetText = myBreakStory.texts.itemByRange(myBfBreakFrame.insertionPoints[-1],myBreakStory.insertionPoints[-1]);
myOversetText.select();
app.cut();
app.select(myAfBreakFrame.insertionPoints[0]);
app.paste();
}
}
}
function mySplitAfter(){
if(mySelection[0].nextTextFrame == null){
alert("Unable Break Thread.\nThe selected Text Frame is the LAST text frame of the thread.");
}
else{
var myBfBreakFrame = mySelection[0];
var myAfBreakFrame = mySelection[0].nextTextFrame;
var myBreakStory = myBfBreakFrame.parentStory;
mySelection[0].nextTextFrame = null;
if(myBfBreakFrame.overflows == true){
var myOversetText = myBreakStory.texts.itemByRange(myBfBreakFrame.insertionPoints[-1],myBreakStory.insertionPoints[-1]);
myOversetText.select();
app.cut();
app.select(myAfBreakFrame.insertionPoints[0]);
app.paste();
}
}
}
}