~canonical-sysadmins/wordpress/4.7.2

« back to all changes in this revision

Viewing changes to wp-admin/js/link.js

  • Committer: Jacek Nykis
  • Date: 2015-01-05 16:17:05 UTC
  • Revision ID: jacek.nykis@canonical.com-20150105161705-w544l1h5mcg7u4w9
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* global postboxes, deleteUserSetting, setUserSetting, getUserSetting */
 
2
 
 
3
jQuery(document).ready( function($) {
 
4
 
 
5
        var newCat, noSyncChecks = false, syncChecks, catAddAfter;
 
6
 
 
7
        $('#link_name').focus();
 
8
        // postboxes
 
9
        postboxes.add_postbox_toggles('link');
 
10
 
 
11
        // category tabs
 
12
        $('#category-tabs a').click(function(){
 
13
                var t = $(this).attr('href');
 
14
                $(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
 
15
                $('.tabs-panel').hide();
 
16
                $(t).show();
 
17
                if ( '#categories-all' == t )
 
18
                        deleteUserSetting('cats');
 
19
                else
 
20
                        setUserSetting('cats','pop');
 
21
                return false;
 
22
        });
 
23
        if ( getUserSetting('cats') )
 
24
                $('#category-tabs a[href="#categories-pop"]').click();
 
25
 
 
26
        // Ajax Cat
 
27
        newCat = $('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ); } );
 
28
        $('#link-category-add-submit').click( function() { newCat.focus(); } );
 
29
        syncChecks = function() {
 
30
                if ( noSyncChecks )
 
31
                        return;
 
32
                noSyncChecks = true;
 
33
                var th = $(this), c = th.is(':checked'), id = th.val().toString();
 
34
                $('#in-link-category-' + id + ', #in-popular-link_category-' + id).prop( 'checked', c );
 
35
                noSyncChecks = false;
 
36
        };
 
37
 
 
38
        catAddAfter = function( r, s ) {
 
39
                $(s.what + ' response_data', r).each( function() {
 
40
                        var t = $($(this).text());
 
41
                        t.find( 'label' ).each( function() {
 
42
                                var th = $(this), val = th.find('input').val(), id = th.find('input')[0].id, name = $.trim( th.text() ), o;
 
43
                                $('#' + id).change( syncChecks );
 
44
                                o = $( '<option value="' +  parseInt( val, 10 ) + '"></option>' ).text( name );
 
45
                        } );
 
46
                } );
 
47
        };
 
48
 
 
49
        $('#categorychecklist').wpList( {
 
50
                alt: '',
 
51
                what: 'link-category',
 
52
                response: 'category-ajax-response',
 
53
                addAfter: catAddAfter
 
54
        } );
 
55
 
 
56
        $('a[href="#categories-all"]').click(function(){deleteUserSetting('cats');});
 
57
        $('a[href="#categories-pop"]').click(function(){setUserSetting('cats','pop');});
 
58
        if ( 'pop' == getUserSetting('cats') )
 
59
                $('a[href="#categories-pop"]').click();
 
60
 
 
61
        $('#category-add-toggle').click( function() {
 
62
                $(this).parents('div:first').toggleClass( 'wp-hidden-children' );
 
63
                $('#category-tabs a[href="#categories-all"]').click();
 
64
                $('#newcategory').focus();
 
65
                return false;
 
66
        } );
 
67
 
 
68
        $('.categorychecklist :checkbox').change( syncChecks ).filter( ':checked' ).change();
 
69
});