-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpost-collections.js
91 lines (69 loc) · 2.2 KB
/
post-collections.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
jQuery(function($){
var searchTimer = null;
$('#post-collection-list').sortable({
handle : '.menu-item-handle',
placeholder : 'sortable-placeholder'
});
$('#post-collection-list').on('click', '.item-remove', function(e){
$(this).closest('li').slideUp(function(){
$(this).remove();
});
e.preventDefault();
});
$('#post-collection-search').keypress(function(e) {
var t = $(this);
if ( 13 == e.which ) {
post_collection_search( t );
return false;
}
if ( searchTimer )
clearTimeout( searchTimer );
searchTimer = setTimeout( function(){
post_collection_search( t );
}, 500 );
});
$('#post-collection-add').click(function(e){
checked = $('#post-collection-results').find(':checked');
if ( !checked.length )
return;
checked.each(function(i,v){
item = $(this);
item.prop('checked',false);
// clone master menu item
m = $('#post-collection-master').clone();
// fill the shit in
m.find('.item-title').text( item.attr('data-title') );
m.find('.item-type').text( item.attr('data-type') );
m.find('.item-input').val( item.attr('data-id') );
m.removeAttr('id');
// append it
m.appendTo( $('#post-collection-list' ) );
});
} );
function post_collection_search( input ) {
search = $.trim( input.val() );
if ( search.length < 2 )
return;
params = {
'action' : 'post_collection_search',
'post_type' : post_collections.post_type,
'search' : search
};
$('#post-collection-controls').find('.ajax-loading').css('visibility','visible');
$.post( ajaxurl, params, function( r ) {
if ( r.posts ) {
html = '';
$.each( r.posts, function(i,v){
html += '<li><label><input type="checkbox" value="' + v.ID + '" data-title="' + v.post_title + '" data-type="' + v.post_type + '" data-id="' + v.ID + '" /> ' + v.post_type + ': ' + v.post_title + '</label></li>';
} );
$('#post-collection-add').show();
} else {
$('#post-collection-add').hide();
html = '<li>' + post_collections.no_results + '</li>';
}
$('#post-collection-results').find('ul').html(html);
$('#post-collection-results').show();
$('#post-collection-controls').find('.ajax-loading').css('visibility','hidden');
} );
}
});