|
@@ -9,6 +9,7 @@ function card_default_options() {
|
9
|
9
|
page_size: "A4",
|
10
|
10
|
page_rows: 3,
|
11
|
11
|
page_columns: 3,
|
|
12
|
+ card_arrangement: "doublesided",
|
12
|
13
|
card_size: "25x35",
|
13
|
14
|
icon_inline: true
|
14
|
15
|
}
|
|
@@ -278,13 +279,27 @@ function card_pages_add_padding(cards, options) {
|
278
|
279
|
}
|
279
|
280
|
}
|
280
|
281
|
|
|
282
|
+function card_pages_interleave_cards(front_cards, back_cards, options) {
|
|
283
|
+ var result = [];
|
|
284
|
+ var i = 0;
|
|
285
|
+ while (i < front_cards.length) {
|
|
286
|
+ result.push(front_cards[i]);
|
|
287
|
+ result.push(back_cards[i]);
|
|
288
|
+ if (options.page_columns > 2) {
|
|
289
|
+ result.push(card_generate_empty(options.page_columns - 2, options));
|
|
290
|
+ }
|
|
291
|
+ ++i;
|
|
292
|
+ }
|
|
293
|
+ return result;
|
|
294
|
+}
|
|
295
|
+
|
281
|
296
|
function card_pages_wrap(pages, options) {
|
282
|
297
|
var size = options.page_size || "A4";
|
283
|
298
|
|
284
|
299
|
var result = "";
|
285
|
300
|
for (var i = 0; i < pages.length; ++i) {
|
286
|
301
|
var style = "";
|
287
|
|
- if (i % 2 == 1) {
|
|
302
|
+ if ((options.card_arrangement == "doublesided") && (i % 2 == 1)) {
|
288
|
303
|
style += 'style="background-color:'+options.default_color+'"';
|
289
|
304
|
}
|
290
|
305
|
result += '<page class="page page-preview" size="' + size + '" ' + style + '>\n';
|
|
@@ -310,21 +325,31 @@ function card_pages_generate_html(card_data, options) {
|
310
|
325
|
back_cards = back_cards.concat(card_repeat(back, count));
|
311
|
326
|
});
|
312
|
327
|
|
313
|
|
- // Add padding cards so that the last page is full of cards
|
314
|
|
- front_cards = card_pages_add_padding(front_cards, options);
|
315
|
|
- back_cards = card_pages_add_padding(back_cards, options);
|
316
|
|
-
|
317
|
|
- // Split cards to pages
|
318
|
|
- var front_pages = card_pages_split(front_cards, rows, cols);
|
319
|
|
- var back_pages = card_pages_split(back_cards, rows, cols);
|
320
|
|
-
|
321
|
|
- // Shuffle back cards so that they line up with their corresponding front cards
|
322
|
|
- back_pages = back_pages.map(function (page) {
|
323
|
|
- return cards_pages_flip_left_right(page, rows, cols);
|
324
|
|
- });
|
325
|
|
-
|
326
|
|
- // Interleave front and back pages so that we can print double-sided
|
327
|
|
- var pages = card_pages_merge(front_pages, back_pages);
|
|
328
|
+ var pages = [];
|
|
329
|
+ if (options.card_arrangement == "doublesided") {
|
|
330
|
+ // Add padding cards so that the last page is full of cards
|
|
331
|
+ front_cards = card_pages_add_padding(front_cards, options);
|
|
332
|
+ back_cards = card_pages_add_padding(back_cards, options);
|
|
333
|
+
|
|
334
|
+ // Split cards to pages
|
|
335
|
+ var front_pages = card_pages_split(front_cards, rows, cols);
|
|
336
|
+ var back_pages = card_pages_split(back_cards, rows, cols);
|
|
337
|
+
|
|
338
|
+ // Shuffle back cards so that they line up with their corresponding front cards
|
|
339
|
+ back_pages = back_pages.map(function (page) {
|
|
340
|
+ return cards_pages_flip_left_right(page, rows, cols);
|
|
341
|
+ });
|
|
342
|
+
|
|
343
|
+ // Interleave front and back pages so that we can print double-sided
|
|
344
|
+ pages = card_pages_merge(front_pages, back_pages);
|
|
345
|
+ } else if (options.card_arrangement == "front_only") {
|
|
346
|
+ var cards = card_pages_add_padding(front_cards, options);
|
|
347
|
+ pages = card_pages_split(cards, rows, cols);
|
|
348
|
+ } else if (options.card_arrangement == "side_by_side") {
|
|
349
|
+ var cards = card_pages_interleave_cards(front_cards, back_cards, options);
|
|
350
|
+ cards = card_pages_add_padding(cards, options);
|
|
351
|
+ pages = card_pages_split(cards, rows, cols);
|
|
352
|
+ }
|
328
|
353
|
|
329
|
354
|
// Wrap all pages in a <page> element
|
330
|
355
|
return card_pages_wrap(pages, options);
|