forked from matthiassiegel/Related
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
72 lines (54 loc) · 1.57 KB
/
scripts.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
jQuery(document).ready(function($) {
/*
* On selection (change event), add the post to the list in the metabox
*/
$('.related-posts-select').change(function() {
var select = $(this),
container = $('#related-posts'),
id = select.val(),
title = this.options[this.options.selectedIndex].text;
if (id != "0") {
if ($('#related-post-' + id).length == 0) {
container.prepend('<div class="related-post" id="related-post-' +
id +
'"><input type="hidden" name="related-posts[]" value="' +
id +
'"><span class="related-post-title">' +
title +
'</span><a href="#" onClick="related_delete( this ); return false;">Delete</a></div>'
);
}
}
});
/* Delete option again on click event */
$('.related-post a').on('click', function() {
related_delete( this );
return false;
});
$('#related-posts').sortable();
});
/*
* related_delete
* Function te remove the selected post
*/
function related_delete( a_el ) {
var div = jQuery( a_el ).parent();
div.css('background-color', '#ff0000').fadeOut('normal', function() {
div.remove();
});
return false;
}
/*
* Select the right tab on the options page
*
*/
jQuery(document).ready(function($) {
jQuery( '.related-nav-tab-wrapper a' ).on('click', function() {
jQuery( '.related_options' ).removeClass( 'active' );
jQuery( '.related-nav-tab-wrapper a' ).removeClass( 'nav-tab-active' );
var rel = jQuery( this ).attr('rel');
jQuery( '.' + rel ).addClass( 'active' );
jQuery( this ).addClass( 'nav-tab-active' );
return false;
});
});