~canonical-sysadmins/wordpress/4.7.2

« back to all changes in this revision

Viewing changes to wp-admin/js/updates.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
window.wp = window.wp || {};
 
2
 
 
3
(function( $, wp ) {
 
4
 
 
5
        wp.updates = {};
 
6
 
 
7
        /**
 
8
         * Decrement update counts throughout the various menus
 
9
         *
 
10
         * @param {string} updateType
 
11
         */
 
12
        wp.updates.decrementCount = function( upgradeType ) {
 
13
                var count, pluginCount, $elem;
 
14
 
 
15
                $elem = $( '#wp-admin-bar-updates .ab-label' );
 
16
                count = $elem.text();
 
17
                count = parseInt( count, 10 ) - 1;
 
18
                if ( count < 0 ) {
 
19
                        return;
 
20
                }
 
21
                $( '#wp-admin-bar-updates .ab-item' ).removeAttr( 'title' );
 
22
                $elem.text( count );
 
23
 
 
24
                $elem = $( 'a[href="update-core.php"] .update-plugins' );
 
25
                $elem.each( function( index, elem ) {
 
26
                        elem.className = elem.className.replace( /count-\d+/, 'count-' + count );
 
27
                } );
 
28
                $elem.removeAttr( 'title' );
 
29
                $elem.find( '.update-count' ).text( count );
 
30
 
 
31
                if ( 'plugin' === upgradeType ) {
 
32
                        $elem = $( '#menu-plugins' );
 
33
                        pluginCount = $elem.find( '.plugin-count' ).eq(0).text();
 
34
                        pluginCount = parseInt( pluginCount, 10 ) - 1;
 
35
                        if ( pluginCount < 0 ) {
 
36
                                return;
 
37
                        }
 
38
                        $elem.find( '.plugin-count' ).text( pluginCount );
 
39
                        $elem.find( '.update-plugins' ).each( function( index, elem ) {
 
40
                                elem.className = elem.className.replace( /count-\d+/, 'count-' + pluginCount );
 
41
                        } );
 
42
                }
 
43
        };
 
44
 
 
45
        $( window ).on( 'message', function( e ) {
 
46
                var event = e.originalEvent,
 
47
                        message,
 
48
                        loc = document.location,
 
49
                        expectedOrigin = loc.protocol + '//' + loc.hostname;
 
50
 
 
51
                if ( event.origin !== expectedOrigin ) {
 
52
                        return;
 
53
                }
 
54
 
 
55
                message = $.parseJSON( event.data );
 
56
 
 
57
                if ( typeof message.action === 'undefined' || message.action !== 'decrementUpdateCount' ) {
 
58
                        return;
 
59
                }
 
60
 
 
61
                wp.updates.decrementCount( message.upgradeType );
 
62
 
 
63
        } );
 
64
 
 
65
})( jQuery, window.wp );