-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnewacq.js
362 lines (274 loc) · 8.29 KB
/
newacq.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
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
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||""
}
mycategory = getURLParameter('category');
myaudience = getURLParameter('audience');
// begin main function
$(document).ready(function(){
// create table headers
function createTableColumns(){
var tableColumns = [
{'data': 'image', 'title': 'Image', 'className':'image' },
{'data': 'cite', 'title': 'Cite', 'sWidth':'360px', 'className':'cite preLoad' },
{'data': 'subject', 'title': 'Subject', 'className':'Subject', 'visible':false },
{'data': 'month', 'title': 'Month', 'visible':false },
{'data': 'issue', 'title': 'Issue', 'visible':false }
];
return tableColumns;
}
//function that runs on init to creat the menu
function createMenu() {
//Create Issue List
var issueList=
oTable
.columns( 3, {order:'index'} )
.data()
.eq( 0 ) // Reduce the 2D array into a 1D array of data
.unique(); // Reduce to unique values
var mList = $('div.monthList')
$.each(issueList, function(i)
{
var span = $('<span/>')
.addClass('ui-menu-item btn btn-maroon btn-default')
.attr('role', 'menuitem')
.appendTo(mList);
var aaa = $('<a/>')
.addClass('issueLink')
.text(issueList[i])
.attr('href','#')
.appendTo(span);
});
$(".monthList span a:first, .monthList span:first").addClass("highlight-issue");
//Filter to current issue
var currentIssue = oTable
.column(4)
.data()
.sort(function(a, b){return a-b})
.reverse()[0];
oTable
.columns(4)
.search(currentIssue)
.draw();
var subjectList=
oTable
.columns( 2, {search:'applied'} )
.data()
.eq( 0 ) // Reduce the 2D array into a 1D array of data
.sort() // Sort data alphabetically
.unique(); // Reduce to unique values
var cList = $('ul.mylist')
$.each(subjectList, function(i)//create subject menu
{
var li = $('<li/>')
.addClass('ui-menu-item')
.attr('role', 'menuitem')
.appendTo(cList);
var aaa = $('<a/>')
.addClass('subjectLink')
.text(subjectList[i])
.attr('href','#')
.appendTo(li);
});
var li = $('<li/>') //add Show All link at end of subject menu
.addClass('all')
.attr('role', 'menuitem')
.appendTo(cList);
var aaa = $('<a/>')
.addClass('all')
.text('Show all items in this issue')
.attr('href','#')
.appendTo(li);
if (mycategory.length >0) {
var highlightclass="li#"+mycategory;
$ (highlightclass).addClass ("highlight-subject");
oTable.fnFilter(mycategory, 2);
}
else {$(".all").addClass ("highlight-subject").parent('li').addClass('highlight-li');}
if (myaudience.length >0) {
var highlightclass="li."+myaudience;
$ (highlightclass).addClass ("highlight-audience");
oTable.fnFilter(myaudience, 3);
}
$("ul.category li.filter")
.click(function(event){
event.preventDefault();
$ (".highlight-category").removeClass ("highlight-category");
mycategory=$(this).attr("id");
var highlightclass="li#"+mycategory;
$ (highlightclass)
.addClass ("highlight-category");
oTable.fnFilter(mycategory, 2);
});
$("a.issueLink")
.click(function(event){
event.preventDefault();
$(".prev").slideUp();
myissue=$(this).text();
$ (".highlight-issue").removeClass ("highlight-issue");
$ (this)
.addClass ("highlight-issue")
.parent()
.addClass ("highlight-issue");
oTable
.columns()
.search("")
.columns(3)
.search(myissue)
.draw();
var subjectList=
oTable
.columns( 2, {search:'applied'} )
.data()
.eq( 0 ) // Reduce the 2D array into a 1D array of data
.sort() // Sort data alphabetically
.unique(); // Reduce to unique values
$('ul.mylist').html("");
var cList = $('ul.mylist')
$.each(subjectList, function(i)
{
var li = $('<li/>')
.addClass('ui-menu-item')
.attr('role', 'menuitem')
.appendTo(cList);
var aaa = $('<a/>')
.addClass('subjectLink')
.text(subjectList[i])
.attr('href','#')
.appendTo(li);
});
var li = $('<li/>') //add Show All link at end of subject menu
.addClass('all')
.attr('role', 'menuitem')
.appendTo(cList);
var aaa = $('<a/>')
.addClass('all')
.text('Show all items in this issue')
.attr('href','#')
.appendTo(li);
$("a.subjectLink")
.click(function(event){
event.preventDefault();
mycategory=$(this).text();
$ (".highlight-subject").removeClass("highlight-subject");
$ (".highlight-li").removeClass("highlight-li");
$ (this)
.addClass ("highlight-subject")
.parent('li')
.addClass('highlight-li');
oTable
.columns(2)
.search(mycategory)
.draw();
});
$("li.all")
.click(function(event){
event.preventDefault();
$ (".highlight-subject").removeClass ("highlight-subject");
$ (".highlight-li").removeClass("highlight-li");
mycategory=$(this).attr("class");
var highlightclass="a."+mycategory;
$ (highlightclass)
.addClass ("highlight-subject")
.parent('li')
.addClass('highlight-li');
oTable
.columns(2)
.search("")
.draw();
});
});
$("a.subjectLink")
.click(function(event){
event.preventDefault();
mycategory=$(this).text();
$ (".highlight-subject").removeClass("highlight-subject");
$ (".highlight-li").removeClass("highlight-li");
$ (this)
.addClass ("highlight-subject")
.parent('li')
.addClass('highlight-li');
oTable
.columns(2)
.search(mycategory)
.draw();
});
$("li.all")
.click(function(event){
event.preventDefault();
$ (".highlight-subject").removeClass ("highlight-subject");
$ (".highlight-li").removeClass("highlight-li");
mycategory=$(this).attr("class");
var highlightclass="a."+mycategory;
$ (highlightclass)
.addClass ("highlight-subject")
.parent('li')
.addClass('highlight-li');
oTable
.columns(2)
.search("")
.draw();
});
$("a.prevLink")
.click(function() {
$(".rss").slideUp();
$(".prev").slideToggle();
});
}
// create the table container and object
$('#newacq').html('<table cellpadding="0" cellspacing="0" border="0" class="display table" id="data-table-container" style="width:100%"></table>');
var oTable = $('#data-table-container').DataTable({
'sPaginationType': 'bootstrap',
'bPaginate': false,
'bInfo': false,
'dom' : 'tr',
'ajax' : {
url:'https://sheets.googleapis.com/v4/spreadsheets/1Ym_DjK2JNfwv5HeTvF8wVtmOg-TXQZKwzEJg5gJunuA/values/A:M?key=AIzaSyD8Y28YJpVhE4XlVlOoA74Ws47YdPz5nGA',
cache: true,
'dataSrc': function(json) {
var myData = json['values']; //spreadsheet data lives in an array with the name values
//rewrite data to an object with key-value pairs. This is also a chance to rename or ignore columns
myData= myData.map(function( n, i ) {
var myObject = {
image:n[11],
cite:n[12],
subject:n[2],
month:n[8],
issue:n[9]
};
return myObject;
});
myData.splice(0,1); //remove the first row, which contains the orginal column headers
return myData;
}
},
'iDisplayLength': 200,
'columns': createTableColumns(),
'oLanguage': {
'sLengthMenu': '_MENU_ records per page'
},
'order': [[ 2, "asc" ],[ 1, "asc" ] ],
'initComplete' : function (settings) {
createMenu();
},
'drawCallback': function ( settings ) {
var api = this.api();
var rows = api.rows( {page:'current'} ).nodes();
var last=null;
api.column(2, {page:'current'} ).data().each( function ( group, i ) {
if ( last !== group ) {
$(rows).eq( i ).before(
'<tr class="group"><td colspan="2"><h4>'+group+'</h4></td></tr>'
);
last = group;
}
} );
}
});
});
//define two custom functions (asc and desc) for string sorting
jQuery.fn.dataTableExt.oSort['string-case-asc'] = function(x,y) {
return ((x < y) ? -1 : ((x > y) ? 0 : 0));
};
jQuery.fn.dataTableExt.oSort['string-case-desc'] = function(x,y) {
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};