Make WordPress Core

Ticket #25994: 25994.1.diff

File 25994.1.diff, 9.8 KB (added by atimmer, 13 years ago)
  • src/wp-admin/js/post.js

     
     1/* global postL10n, ajaxurl, wpAjax, setPostThumbnailL10n, postboxes, pagenow, tinymce */
     2/* global theList: true, theExtraList: true */
     3
    14var tagBox, commentsBox, editPermalink, makeSlugeditClickable, WPSetThumbnailHTML, WPSetThumbnailID, WPRemoveThumbnail, wptitlehint;
    25
    36// return an array with any duplicate, whitespace or values removed
     
    8285
    8386        flushTags : function(el, a, f) {
    8487                a = a || false;
    85                 var tags = $('.the-tags', el),
     88                var tagsval, newtags, text,
     89                        tags = $('.the-tags', el),
    8690                        newtag = $('input.newtag', el),
    87                         comma = postL10n.comma,
    88                         newtags, text;
     91                        comma = postL10n.comma;
    8992
    9093                text = a ? $(a).text() : newtag.val();
    9194                tagsval = tags.val();
     
    108111                var tax = id.substr(id.indexOf('-')+1);
    109112
    110113                $.post(ajaxurl, {'action':'get-tagcloud', 'tax':tax}, function(r, stat) {
    111                         if ( 0 == r || 'success' != stat )
     114                        if ( 0 === r || 'success' != stat )
    112115                                r = wpAjax.broken;
    113116
    114117                        r = $('<p id="tagcloud-'+tax+'" class="the-tagcloud">'+r+'</p>');
     
    137140                });
    138141
    139142                $('input.newtag', ajaxtag).blur(function() {
    140                         if ( this.value == '' )
     143                        if ( '' === this.value )
    141144                                $(this).parent().siblings('.taghint').css('visibility', '');
    142145                }).focus(function(){
    143146                        $(this).parent().siblings('.taghint').css('visibility', 'hidden');
     
    206209                                        $('#the-comment-list').append( r.responses[0].data );
    207210
    208211                                        theList = theExtraList = null;
    209                                         $("a[className*=':']").unbind();
     212                                        $( 'a[className*=\':\']' ).unbind();
    210213
    211214                                        if ( commentsBox.st > commentsBox.total )
    212215                                                $('#show-comments').hide();
     
    240243
    241244WPRemoveThumbnail = function(nonce){
    242245        $.post(ajaxurl, {
    243                 action:"set-post-thumbnail", post_id: $('#post_ID').val(), thumbnail_id: -1, _ajax_nonce: nonce, cookie: encodeURIComponent(document.cookie)
     246                action: 'set-post-thumbnail', post_id: $( '#post_ID' ).val(), thumbnail_id: -1, _ajax_nonce: nonce, cookie: encodeURIComponent( document.cookie )
    244247        }, function(str){
    245248                if ( str == '0' ) {
    246                         alert( setPostThumbnailL10n.error );
     249                        window.alert( setPostThumbnailL10n.error );
    247250                } else {
    248251                        WPSetThumbnailHTML(str);
    249252                }
     
    259262        if ( ! post_id || ! $('#post-lock-dialog').length )
    260263                return;
    261264
    262         send['post_id'] = post_id;
     265        send.post_id = post_id;
    263266
    264267        if ( lock )
    265                 send['lock'] = lock;
     268                send.lock = lock;
    266269
    267270        data['wp-refresh-post-lock'] = send;
    268271});
     
    288291                                        });
    289292
    290293                                        // Save the latest changes and disable
    291                                         if ( ! autosave() )
     294                                        if ( ! window.autosave() )
    292295                                                window.onbeforeunload = null;
    293296
    294                                         autosave = function(){};
     297                                        window.autosave = function(){};
    295298                                }
    296299
    297300                                if ( received.lock_error.avatar_src ) {
     
    401404                        $('#' + taxonomy + '-tabs').siblings('.tabs-panel').hide();
    402405                        $(t).show();
    403406                        if ( '#' + taxonomy + '-all' == t )
    404                                 deleteUserSetting(settingName);
     407                                window.deleteUserSetting( settingName );
    405408                        else
    406                                 setUserSetting(settingName, 'pop');
     409                                window.setUserSetting( settingName, 'pop' );
    407410                        return false;
    408411                });
    409412
    410                 if ( getUserSetting(settingName) )
     413                if ( window.getUserSetting( settingName ) )
    411414                        $('a[href="#' + taxonomy + '-pop"]', '#' + taxonomy + '-tabs').click();
    412415
    413416                // Ajax Cat
    414                 $('#new' + taxonomy).one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ) } );
     417                $( '#new' + taxonomy ).one( 'focus', function() { $( this ).val( '' ).removeClass( 'form-input-tip' ); } );
    415418
    416419                $('#new' + taxonomy).keypress( function(event){
    417420                        if( 13 === event.keyCode ) {
     
    463466
    464467        // Custom Fields
    465468        if ( $('#postcustom').length ) {
    466                 $('#the-list').wpList( { addAfter: function( xml, s ) {
     469                $( '#the-list' ).wpList( { addAfter: function() {
    467470                        $('table#list-table').show();
    468471                }, addBefore: function( s ) {
    469472                        s.data += '&post_id=' + $('#post_ID').val();
     
    531534                                                .replace( '%2$s', jj )
    532535                                                .replace( '%3$s', aa )
    533536                                                .replace( '%4$s', hh )
    534                                                 .replace( '%5$s', mn )
    535                                         + '</b> '
     537                                                .replace( '%5$s', mn ) +
     538                                                '</b> '
    536539                                );
    537540                        }
    538541
    539542                        if ( $('input:radio:checked', '#post-visibility-select').val() == 'private' ) {
    540543                                $('#publish').val( postL10n.update );
    541                                 if ( optPublish.length == 0 ) {
     544                                if ( 0 === optPublish.length ) {
    542545                                        postStatus.append('<option value="publish">' + postL10n.privatelyPublished + '</option>');
    543546                                } else {
    544547                                        optPublish.html( postL10n.privatelyPublished );
     
    572575                }
    573576
    574577                $('.edit-visibility', '#visibility').click(function () {
    575                         if ($('#post-visibility-select').is(":hidden")) {
     578                        if ( $( '#post-visibility-select' ).is( ':hidden' ) ) {
    576579                                updateVisibility();
    577580                                $('#post-visibility-select').slideDown('fast');
    578581                                $(this).hide();
     
    602605                                $('#sticky').prop('checked', false);
    603606                        } // WEAPON LOCKED
    604607
    605                         if ( true == $('#sticky').prop('checked') ) {
     608                        if ( true === $('#sticky').prop('checked') ) {
    606609                                sticky = 'Sticky';
    607610                        } else {
    608611                                sticky = '';
     
    617620                });
    618621
    619622                $('#timestampdiv').siblings('a.edit-timestamp').click(function() {
    620                         if ($('#timestampdiv').is(":hidden")) {
     623                        if ( $( '#timestampdiv' ).is( ':hidden' ) ) {
    621624                                $('#timestampdiv').slideDown('fast');
    622625                                $('#mm').focus();
    623626                                $(this).hide();
     
    656659                });
    657660
    658661                $('#post-status-select').siblings('a.edit-post-status').click(function() {
    659                         if ($('#post-status-select').is(":hidden")) {
     662                        if ( $( '#post-status-select' ).is( ':hidden' ) ) {
    660663                                $('#post-status-select').slideDown('fast');
    661664                                $(this).hide();
    662665                        }
     
    682685        // permalink
    683686        if ( $('#edit-slug-box').length ) {
    684687                editPermalink = function(post_id) {
    685                         var i, c = 0, e = $('#editable-post-name'), revert_e = e.html(), real_slug = $('#post_name'), revert_slug = real_slug.val(), b = $('#edit-slug-buttons'), revert_b = b.html(), full = $('#editable-post-name-full').html();
     688                        var slug_value, i,
     689                                c = 0,
     690                                e = $( '#editable-post-name' ),
     691                                revert_e = e.html(),
     692                                real_slug = $( '#post_name' ),
     693                                revert_slug = real_slug.val(),
     694                                b = $( '#edit-slug-buttons' ),
     695                                revert_b = b.html(),
     696                                full = $( '#editable-post-name-full' ).html();
    686697
    687698                        $('#view-post-btn').hide();
    688699                        b.html('<a href="#" class="save button button-small">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+'</a>');
     
    738749                                        b.children('.cancel').click();
    739750                                        return false;
    740751                                }
    741                         }).keyup(function(e) {
     752                        } ).keyup( function() {
    742753                                real_slug.val(this.value);
    743754                        }).focus();
    744                 }
     755                };
    745756
    746757                makeSlugeditClickable = function() {
    747758                        $('#editable-post-name').click(function() {
    748759                                $('#edit-slug-buttons').children('.edit-slug').click();
    749760                        });
    750                 }
     761                };
    751762                makeSlugeditClickable();
    752763        }
    753764
     
    774785
    775786                var title = $('#' + id), titleprompt = $('#' + id + '-prompt-text');
    776787
    777                 if ( title.val() == '' )
     788                if ( '' === title.val() )
    778789                        titleprompt.removeClass('screen-reader-text');
    779790
    780791                titleprompt.click(function(){
     
    783794                });
    784795
    785796                title.blur(function(){
    786                         if ( this.value == '' )
     797                        if ( '' === this.value )
    787798                                titleprompt.removeClass('screen-reader-text');
    788799                }).focus(function(){
    789800                        titleprompt.addClass('screen-reader-text');
     
    791802                        titleprompt.addClass('screen-reader-text');
    792803                        $(this).unbind(e);
    793804                });
    794         }
     805        };
    795806
    796807        wptitlehint();
    797808
     
    807818                        return false;
    808819                }
    809820
    810                 function endDrag(e) {
     821                function endDrag() {
    811822                        var height;
    812823
    813824                        textarea.focus();
     
    817828
    818829                        // sanity check
    819830                        if ( height && height > 50 && height < 5000 )
    820                                 setUserSetting( 'ed_size', height );
     831                                window.setUserSetting( 'ed_size', height );
    821832                }
    822833
    823834                textarea.css('resize', 'none');
     
    854865                        }
    855866
    856867                        // resize TinyMCE to match the textarea height when switching Text -> Visual
    857                         ed.onLoadContent.add( function(ed, o) {
     868                        ed.onLoadContent.add( function() {
    858869                                var ifr_height, node = document.getElementById('content'),
    859870                                        height = node ? parseInt( node.style.height, 10 ) : 0,
    860871                                        tb_height = $('#content_tbl tr.mceFirst').height() || 33;
     
    863874                                if ( !height || height < 50 || height > 5000 )
    864875                                        height = 360; // default height for the main editor
    865876
    866                                 if ( getUserSetting( 'ed_size' ) > 5000  )
    867                                         setUserSetting( 'ed_size', 360 );
     877                                if ( window.getUserSetting( 'ed_size' ) > 5000  )
     878                                        window.setUserSetting( 'ed_size', 360 );
    868879
    869880                                // compensate for padding and toolbars
    870881                                ifr_height = ( height - tb_height ) + 12;
     
    877888                        });
    878889
    879890                        // resize the textarea to match TinyMCE's height when switching Visual -> Text
    880                         ed.onSaveContent.add( function(ed, o) {
     891                        ed.onSaveContent.add( function() {
    881892                                var height = getHeight();
    882893
    883894                                if ( !height || height < 50 || height > 5000 )
     
    888899
    889900                        // save on resizing TinyMCE
    890901                        ed.onPostRender.add(function() {
    891                                 $('#content_resize').on('mousedown.wp-mce-resize', function(e){
    892                                         $(document).on('mouseup.wp-mce-resize', function(e){
     902                                $( '#content_resize' ).on( 'mousedown.wp-mce-resize', function() {
     903                                        $( document ).on( 'mouseup.wp-mce-resize', function() {
    893904                                                var height;
    894905
    895906                                                $(document).off('mouseup.wp-mce-resize');
     
    897908                                                height = getHeight();
    898909                                                // sanity check
    899910                                                if ( height && height > 50 && height < 5000 )
    900                                                         setUserSetting( 'ed_size', height );
     911                                                        window.setUserSetting( 'ed_size', height );
    901912                                        });
    902913                                });
    903914                        });
    904915                });
    905916
    906917                // When changing post formats, change the editor body class
    907                 $('#post-formats-select input.post-format').on( 'change.set-editor-class', function( event ) {
     918                $( '#post-formats-select input.post-format' ).on( 'change.set-editor-class', function() {
    908919                        var editor, body, format = this.id;
    909920
    910921                        if ( format && $( this ).prop('checked') ) {