-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.makepage.js
151 lines (129 loc) · 4.35 KB
/
jquery.makepage.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
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
/*
makePage: Removes all of the work from doing complicated HTML coding.
options:
title: this text gets put in the header element, in an H1
subtitle: this text gets put in the header element in an H2 tag
subsubtitle: this text gets put in the header element in an H3 tag
nav: an array of objects, each of which has a "url" and a "text" property
content: anything that could be passed to jQuery.append, or an array of
things that could be passed to jQuery.append
footer: content in the footer
*/
(function($) {
$.makePage = {
list: function(items, klass)
{
var i,
list = $('<ul>'),
item;
for (i = 0; i < items.length; i++)
{
item = $('<li />');
item.append(items[i]);
list.append(item);
}
if (klass)
{
list.addClass(klass);
}
return list;
},
paragraph: function(content, klass)
{
var $p = $('<p />');
$p.append(content);
if (klass)
{
$p.addClass(klass);
}
return $p;
},
link: function(url, text, blank)
{
var $a = $('<a />', {href: url});
$a.append(text);
if (blank)
{
$a.attr('target', '_blank');
}
return $a;
}
};
$.fn.makePage = function(args)
{
if (args && typeof args === 'object')
{
var $container = $('<div>', {'class': 'container'}),
$header,
$h1,
$h2,
$h3,
$left,
$nav,
$right = $('<div>', {'class': 'second'}),
$footer,
$li,
i;
if (args['class'])
{
$container.addClass(args['class']);
}
if (args.title || args.subtitle || args.subsubtitle)
{
$header = $('<div>', {'class': 'header'});
if (args.title)
{
$h1 = $('<h1>' + args.title + '</h1>');
$header.append($h1);
}
if (args.subtitle)
{
$h2 = $('<h2>' + args.subtitle + '</h1>');
$header.append($h2);
}
if (args.subsubtitle)
{
$h3 = $('<h3>' + args.subsubtitle + '</h3>');
$header.append($h3);
}
$container.append($header);
}
if (args.nav && args.nav.length)
{
$left = $('<div>', {'class': 'first'});
$nav = $('<ul>', {'class': 'nav'});
for (i = 0; i < args.nav.length; i++)
{
$li = $('<li />');
$li.append($.makePage.link(args.nav[i].url, args.nav[i].text, args.nav[i].blank));
$nav.append($li);
}
$left.append($nav);
$container.append($left);
}
if (args.content)
{
if (args.content.length)
{
for (i = 0; i < args.content.length; i++)
{
$right.append(args.content[i]);
}
}
else
{
$right.append(args.content);
}
}
$container.append($right);
if (args.footer)
{
$footer = $('<div>', {'class': 'footer'});
$footer.append(args.footer);
$container.append($footer);
}
this.append($container);
}
return $(this);
};
})(jQuery);