This repository has been archived by the owner on Jul 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Build Link Button.jsx
414 lines (289 loc) · 10.6 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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
#targetengine "jm-2014";
var thelinkbuttonfile;
(function(thisObj){
/*
written by fabiantheblind 4 JM-2011
*/
/**
* own include 2013 replacing JSXses include. Does not work well with a linter
* #include "./meta/glue code.jsx";
*/
var script_file = File($.fileName); // get the location of the scriptfile
var script_file_folder = script_file.parent;
var script_file_path = script_file.path; // get the path
var file_to_read = File(script_file.path + "/meta/glue code.jsx");
var content = "";
// alert(file_to_read);
if(file_to_read.exists){// if it is really there
file_to_read.open('r'); // open it
content = file_to_read.read(); // read it
eval(content);
}else{
alert("The file 'glue code.jsx' is missing");
return;
}
var obj = {};
obj.DEBUG = false;
obj.WARNINGS = true;
main();
function main() {
var d;
// test for a doc
try { 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 = [];
var myList;
var myPageName, myPage, myItemsListElement;
try{
d.paragraphStyles.item("ERROR").appliedFont = "Arial";
}catch(e){
}
myList = d.pages.everyItem().name;
try{
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;
var myX1 ,myX2, myY1, myY2;
if(myPage.side == PageSideOptions.leftHand){
myX2 = myPage.marginPreferences.left;
myX1 = myPage.marginPreferences.right;
}else{
myX1 = myPage.marginPreferences.left;
myX2 = myPage.marginPreferences.right;
}
myY1 = myPage.marginPreferences.top;
myX2 = myPageWidth - myX2;
myY2 = myPageHeight - myPage.marginPreferences.bottom;
return [myY1, myX1, myY2, myX2];
}
function placeData(d , myPage , theItem){
var myRuleSet = new Array(new makeButton(theItem, myPage, d));
var elements = d.xmlElements;
__processRuleSet(elements.everyItem(), myRuleSet);
}
function makeButton(theItem, myPage, d){
if(obj.DEBUG) alert("DEBUG1: " + theItem + " in makeButton.\nlength of the item: "+theItem.length );
var myString = "";
var myFile;
this.name = "placeButtons";
this.xpath = "//artikel[@iArtikelNr='Art-Nr. " + theItem + "']";
this.apply = function(myElement, myRuleProcessor){
var myGroup = [];
var myNullObjStyle = d.objectStyles.item(0);
var myPriceObjStyle = d.objectStyles.item("PREIS_schatten");
var myTempBounds = [];
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);
myOV01.geometricBounds = [OY1, OX1 ,OY2 , OX2];
myOV01.applyObjectStyle(myNullObjStyle);
var bgov = myOV01.duplicate();
// addition in 2013_09_26 - 14_05_49
bgov.fillColor = d.swatches[1];
bgov.sendToBack(myOV01);
try{
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( d.filePath + "/" + myString ));
myOV01.fit(FitOptions.CENTER_CONTENT);
myGroup.push(myOV01);
myGroup.push(bgov);
} 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);
myRect01.geometricBounds = [RY1, RX1, RY2, RX2];
myRect01.applyObjectStyle(myNullObjStyle);
try{
if(!thelinkbuttonfile){
myFile = File.openDialog("Choose the File \"Button_Lupe_Hintergrund.bmp\"\nI will ask only once per session.");
if(!myFile){
if(obj.WARNINGS) alert("Are you shure?\nWithout the \"Button_Lupe_Hintergrund.bmp\" it looooooooks sillyyyyyy");
}
thelinkbuttonfile = myFile;
}else{
myFile = thelinkbuttonfile;
}
myRect01.place(thelinkbuttonfile);
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);
myTF01.geometricBounds = [TY1, TX1, TY2, TX2];
myTF01.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);
myPF01.geometricBounds = [PY1, PX1, PY2, PX2];
myPF01.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 ddw = 150; // dropdownwidth
var stw = 80;//static text width
myList.push("add new page");
var myPageDropdown, myArtikelDropdown;
var myDialog = app.dialogs.add({name:"the Link Button", canCancel:true,minWidth:300});
var column_one = myDialog.dialogColumns.add();
// with(myDialog){
//Add a dialog column.
// with(dialogColumns.add()){
//Create a border panel.
var row_one = column_one.dialogRows.add();
var row_two = column_one.dialogRows.add();
var art_text = row_one.staticTexts.add({
staticLabel: "Article --> ",minWidth:stw});
//Create a pop-up menu ("dropdown") control.
myArtikelDropdown = row_one.dropdowns.add({
stringList: myItemsList, selectedIndex: 0,minWidth:ddw });
row_two.staticTexts.add({staticLabel: "To Page --> ",minWidth:stw});
//Create a pop-up menu ("dropdown") control.
myPageDropdown = row_two.dropdowns.add({
stringList: myList,
selectedIndex: myList.length - 1,
minWidth:ddw});
// }
// with(dialogColumns.add()){
// var gutter = staticTexts.add({staticLabel:" ",minWidth:25});
// }
// }
//Display the dialog box.
if(myDialog.show() === true){
if(myPageDropdown.selectedIndex == myList.length -1){
myPage = d.pages.add();
myPageName = myPage.name;
}else{
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){
}
}})(this);