forked from ff6347/mpolauncherJSRes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Build Link Button.jsx
372 lines (260 loc) · 8.95 KB
/
Build Link Button.jsx
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/*
written by fabiantheblind 4 JM-2011
*/
#include "./meta/glue code.jsx";
var obj = new Object();
obj.DEBUG = false;
obj.WARNINGS = true;
main();
function main() {
var d;
// test for a doc
try { var d = app.activeDocument; } catch(e){
if(obj.WARNINGS) alert("No no no, you have no document.\nMaybe you should drink some coffee");
return;
}
var myItemsList = new Array;
var myList;
var myPageName;
var myPage;
try{
d.paragraphStyles.item("ERROR").appliedFont = "Arial";
}catch(e){
}
myList = d.pages.everyItem().name;
try{
var myItemsListElement = d.xmlElements.item(0).xmlElements.item("itemsList");
}catch(e){
if(obj.WARNINGS) alert("You need to import an xml with the importer");
return;
}
try{
for (var i =0 ;i < myItemsListElement.xmlElements.length;i++){
myItemsList[i] = myItemsListElement.xmlElements.item(i).markupTag.name;
}
}catch(e){
if(obj.WARNINGS) alert("you have no xml structure.\nuse the MPO_Importer");
return;
}
myUI(d, myPage,myPageName, myList,myItemsList);
}
function myGetColumns(dument, myPage){
var myPageWidth = dument.documentPreferences.pageWidth;
var myPageHeight = dument.documentPreferences.pageHeight
var myPageColumnCount= myPage.marginPreferences.columnCount;
var myPageColumnGutterWidth= myPage.marginPreferences.columnGutter;
var myX1 = myPage.marginPreferences.left;
var myY1 = myPage.marginPreferences.top;
var myX2 = myX1
+((myPageWidth-myPage.marginPreferences.left
-myPage.marginPreferences.right
-(myPageColumnGutterWidth* (myPageColumnCount-1))) /myPageColumnCount);
var myY2 = myPageHeight - myPage.marginPreferences.bottom;
return [myY1, myX1, myY2, myX2];
}
function myGetBounds(dument, myPage){
var myPageWidth = dument.documentPreferences.pageWidth;
var myPageHeight = dument.documentPreferences.pageHeight
if(myPage.side == PageSideOptions.leftHand){
var myX2 = myPage.marginPreferences.left;
var myX1 = myPage.marginPreferences.right;
}
else{
var myX1 = myPage.marginPreferences.left;
var myX2 = myPage.marginPreferences.right;
}
var myY1 = myPage.marginPreferences.top;
var myX2 = myPageWidth - myX2;
var myY2 = myPageHeight - myPage.marginPreferences.bottom;
return [myY1, myX1, myY2, myX2];
}
function placeData(d , myPage , theItem){
var myRuleSet = new Array(new makeButton(theItem, myPage, d));
with(d){
var elements = xmlElements;
__processRuleSet(elements.everyItem(), myRuleSet);
}
}
function makeButton(theItem, myPage, d){
if(obj.DEBUG) alert("DEBUG1: " + theItem + " in makeButton.\nlength of the item: "+theItem.length );
this.name = "placeButtons";
this.xpath = "//artikel[@iArtikelNr='Art-Nr. " + theItem + "']";
this.apply = function(myElement, myRuleProcessor){
var myGroup = new Array;
var myNullObjStyle = d.objectStyles.item(0);
var myPriceObjStyle = d.objectStyles.item("PREIS_schatten");
var myTempBounds = new Array;
myTempBounds = myGetColumns(d, myPage);
var myY1 = myTempBounds[0];
var myX1 = myTempBounds[1];
var myY2 = myTempBounds[2];
var myX2 = myTempBounds[3];
var myImages = myElement.xmlElements.item("images");
var OY1 = 19;//myY1 + 7.5;
var OX1 = 19.5;//myX1 + 7.5 ;
var OY2 = OY1 + 30;
var OX2 = OX1 + 30;
var myOV01 = myPage.ovals.add();
set_label(myOV01,"Art-Nr. " + theItem);
with (myOV01) {
geometricBounds = [OY1, OX1 ,OY2 , OX2];
applyObjectStyle(myNullObjStyle);
}
try{
var myString = myImages.xmlElements.item(0).xmlAttributes.item(1).value;
}catch(e){
if(obj.WARNINGS) alert("there is no image available!");
exit();
}
try {
myOV01.place(File(checkOS(myString)));
myOV01.fit(FitOptions.CENTER_CONTENT);
myGroup.push(myOV01);
} catch (e) {
if(obj.WARNINGS) alert("there is no image available!");
exit();
}
var RY1 = myY1;
var RX1 = myX1;
var RY2 = RY1 + 53.166;
var RX2 = RX1 + 84.279;
var myRect01 = myPage.rectangles.add();
set_label(myRect01,"Art-Nr. " + theItem);
with (myRect01) {
geometricBounds = [RY1, RX1, RY2, RX2];
applyObjectStyle(myNullObjStyle);
}
try{
var myFile = File.openDialog("Choose the File \"Button_Lupe_Hintergrund.bmp\"");
if(!myFile){
if(obj.WARNINGS) alert("Are you shure?\nWithout the \"Button_Lupe_Hintergrund.bmp\" it looooooooks sillyyyyyy");
}
myRect01.place(myFile);
myRect01.fit(FitOptions.CENTER_CONTENT);
//myRect01.fit(FitOptions.PROPORTIONALLY);
myRect01.fit(FitOptions.FRAME_TO_CONTENT);
myGroup.push(myRect01);
}catch(e){
}
var TY1 = 18.861;
var TX1 = 32.217;
var TY2 = 100;
var TX2 = myX2*2;
var myTF01 = myPage.textFrames.add();
if (obj.DEBUG) alert("DEBUG2: " + theItem + " in makeButton.\nlength of the item: "+theItem.length );
set_label(myTF01,"Art-Nr. " + theItem);
with (myTF01) {
geometricBounds = [TY1, TX1, TY2, TX2];
applyObjectStyle(myNullObjStyle);
}
//var myContentElement = myElement.xmlElements.add("buttontext");
//myContentElement.insertTextAsContent("Dazu passt:\n", XMLElementPosition.elementStart);
var myContentString = "Dazu passt:"+"\r"+
myElement.xmlElements.item("artikelInformation").xmlElements.item("iHersteller").contents +"\r"+
myElement.xmlElements.item("artikelInformation").xmlElements.item("iArtikelBezeichnung").contents +"\r"+
myElement.xmlElements.item("artikelInformation").xmlElements.item("iArtikelBeschreibung").contents +"\r"+
myElement.xmlElements.item("artikelInformation").xmlElements.item("iArtikelNr").contents +"\r"+
"Dies und mehr findet Ihr auf Seite XXX";
myTF01.contents = myContentString;
myTF01.paragraphs.item(0).appliedParagraphStyle = d.paragraphStyles.item("BUTTON_Headline");
myTF01.paragraphs.item(1).appliedParagraphStyle = d.paragraphStyles.item("BUTTON_Hersteller");
myTF01.paragraphs.item(2).appliedParagraphStyle = d.paragraphStyles.item("BUTTON_Bezeichnung");
myTF01.paragraphs.item(3).appliedParagraphStyle = d.paragraphStyles.item("BUTTON_Beschreibung");
myTF01.paragraphs.item(4).appliedParagraphStyle = d.paragraphStyles.item("BUTTON_Artikelnummer");
myTF01.paragraphs.item(5).appliedParagraphStyle = d.paragraphStyles.item("BUTTON_Unterzeile");
myTF01.characters.everyItem().appliedCharacterStyle = d.characterStyles.item(0);
myTF01.texts.everyItem().clearOverrides(OverrideType.all);
myTF01.fit(FitOptions.FRAME_TO_CONTENT);
myGroup.push(myTF01);
var myNewPriceElement = myElement.xmlElements.item("preis").duplicate();
var PY1 = 42.411;
var PX1 = 28.729 ;
var PY2 = PY1 + 50;
var PX2 = PX1 + 50;
var myPF01 = myPage.textFrames.add();
set_label(myPF01,"Art-Nr. " + theItem);
with (myPF01) {
geometricBounds = [PY1, PX1, PY2, PX2];
applyObjectStyle(myPriceObjStyle);
}
myNewPriceElement.placeXML(myPF01);
myNewPriceElement.untag();
myPF01.paragraphs.item(0).appliedParagraphStyle = d.paragraphStyles.item("PREIS_KLEIN");
myPF01.fit(FitOptions.FRAME_TO_CONTENT);
myGroup.push(myPF01);
myPage.groups.add(myGroup);
}
}
/*
* a function to check the operating system
*
* @returns true if the OS is windows
*/
function checkOS(myString){
var myOS = $.os;
var myOSSubString = myOS.charAt(0);
var myOSBoolean;
if (myOSSubString == "w" || myOSSubString == "W") {
myOSBoolean = true;
}
else {
myOSBoolean = false;
}
if (myOSBoolean == true) {
//this is for windows
var myHREFString = myString;
var myHREFSubString = myHREFString.substring(8);
return myHREFSubString;
} else {
// this is for macintosh
return myString;
}
}
function myUI(d, myPage,myPageName, myList,myItemsList){
var myNumOItems = 0;
var myDialog = app.dialogs.add({name:"the Link Button", canCancel:true,minWidth:300});
with(myDialog){
//Add a dialog column.
with(dialogColumns.add()){
//Create a border panel.
with(dialogRows.add()){
staticTexts.add({
staticLabel: "Article --> ",minWidth:125});
//Create a pop-up menu ("dropdown") control.
var myArtikelDropdown = dropdowns.add({
stringList: myItemsList, selectedIndex: 0,minWidth:125 });
}
//Create another border panel.
with (dialogRows.add()) {
staticTexts.add({
staticLabel: "To Page --> ",minWidth:125});
//Create a pop-up menu ("dropdown") control.
var myPageDropdown = dropdowns.add({
stringList: myList,
selectedIndex: 0, minWidth:125});
}
with(dialogColumns.add()){
var gutter = staticTexts.add({staticLabel:" ",minWidth:25});
}
}
//Display the dialog box.
if(myDialog.show() == true){
myPageName = myList[myPageDropdown.selectedIndex];
var preTheItem = myItemsList[myArtikelDropdown.selectedIndex];
var theItem = preTheItem.substring(4);
if (obj.DEBUG) alert("DEBUG: "+ theItem);
myDialog.destroy();
myPage = d.pages.item(myPageName);
placeData(d,myPage,theItem);
alert("Done");
}else{
myDialog.destroy();
}
}
}
function set_label(obj,str){
try{
obj.label = str;
}catch(e){
}
}