-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexam.js
62 lines (49 loc) · 1.7 KB
/
exam.js
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
---
layout: null
---
$(document).ready(function(){
console.log("exam.js: document is ready");
$('.template').each(function(i) {
$(this).css('display','none');
});
// Use with <div class="copy-of" data-id="foo"></div>
// Use <div id="foo" class="template"></div> on the stuff you want to copy
// The class="template" will hide it the first time.
// The class="copy-of" data-id="foo" signals that you want a copy of foo inserted here.
$('.copy-of').each(function(i) {
var id = $(this).data('id')
$(this).html($(document.getElementById(id)).clone().html());
});
$('.page-break-before').each(function(i) {
var pageNum = i+1;
var prev = $(this).prev();
var evenOddClass = (pageNum % 2 == 0)?
"even-page" : "odd-page";
$(this).addClass(evenOddClass);
var $div = $("<div>", {class: "pagebreak " + evenOddClass});
prev.append($div);
$('.exam-page-header-template').first().clone().appendTo($div);
if (pageNum %2 ==0) {
var img = $('<img>');
img.addClass("even-page-staple-img");
img.attr('src', "/images/Staple-Even-Pages.png");
img.appendTo($div);
} else {
$('.exam-name-header-template').first().clone().appendTo($div);
}
prev.css('margin-bottom','0');
});
$('td.page-num').each(function(i) {
var pageNum = i + 1
$(this).html(pageNum); // re-calculate page numbers
$(this).data("pageNum",pageNum);
if (pageNum % 2==0) {
$(this).parents(".pagebreak").removeClass("odd-page");
$(this).parents(".pagebreak").addClass("even-page");
} else {
$(this).parents(".pagebreak").removeClass("even-page");
$(this).parents(".pagebreak").addClass("odd-page");
}
});
console.log("exam.js: done");
});