-
Notifications
You must be signed in to change notification settings - Fork 0
/
advanced-excerpt.js
70 lines (62 loc) · 2.12 KB
/
advanced-excerpt.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
// Advanced Excerpt options script
jQuery(function($)
{
var plugin_prefix = 'advancedexcerpt';
var tag_cols = $('#' + plugin_prefix + '_tags_table tr:eq(1) td').length;
var tag_list = new Array();
$('#' + plugin_prefix + '_tags_table input').each(function(i, el)
{
tag_list.push($(el).val());
});
// Add a tag to the checkbox table
$('#' + plugin_prefix + '_add_tag').click(function(event)
{
event.preventDefault();
var tag = $('#' + plugin_prefix + '_more_tags option:selected').val();
// No duplicate tags in the table
if($.inArray(tag, tag_list) > -1)
{
return;
}
tag_list.push(tag);
var last_row = $('#' + plugin_prefix + '_tags_table tr:last-child');
var tag_count = last_row.find('input').length;
var tag_cell = $(
'<td>' +
'<input name="' + plugin_prefix + '_allowed_tags[]" type="checkbox" value="' + tag + '" checked="checked" />' +
'<code>' + tag + '</code>' +
'</td>'
);
if(tag_count < tag_cols)
{
// Add to last row
var span = last_row.find('td[colspan]');
if(span.attr('colspan') > 1)
{
span.attr('colspan', span.attr('colspan') - 1);
tag_cell.insertBefore(span);
}
else
{
span.replaceWith(tag_cell);
}
}
else
{
// New row
$('<tr><td colspan="' + (tag_cols - 1) + '"> </td></tr>').insertAfter(last_row).prepend(tag_cell);
}
});
// Check all boxes
$('#' + plugin_prefix + '_select_all').click(function(event)
{
event.preventDefault();
$('input[name="' + plugin_prefix + '_allowed_tags[]"]:gt(0)').attr('checked', 'checked');
});
// Uncheck all boxes
$('#' + plugin_prefix + '_select_none').click(function(event)
{
event.preventDefault();
$('input[name="' + plugin_prefix + '_allowed_tags[]"]:gt(0)').removeAttr('checked');
});
});