Make WordPress Core

Ticket #25914: 25914.2.diff

File 25914.2.diff, 5.6 KB (added by nacin, 12 years ago)
  • wp-includes/js/wplink.js

     
     1/* global ajaxurl, tinymce, wpLinkL10n, tinyMCEPopup, setUserSetting, wpActiveEditor */
    12var wpLink;
    23
    34(function($){
     
    113114                                inputs.url.val( ed.dom.getAttrib(e, 'href') );
    114115                                inputs.title.val( ed.dom.getAttrib(e, 'title') );
    115116                                // Set open in new tab.
    116                                 inputs.openInNewTab.prop('checked', ( "_blank" == ed.dom.getAttrib( e, 'target' ) ) );
     117                                inputs.openInNewTab.prop('checked', ( '_blank' == ed.dom.getAttrib( e, 'target' ) ) );
    117118                                // Update save prompt.
    118119                                inputs.submit.val( wpLinkL10n.update );
    119120
     
    156157                },
    157158
    158159                htmlUpdate : function() {
    159                         var attrs, html, begin, end, cursor,
     160                        var attrs, html, begin, end, cursor, selection,
    160161                                textarea = wpLink.textarea;
    161162
    162163                        if ( ! textarea )
     
    201202                                if ( begin == end )
    202203                                        cursor -= '</a>'.length;
    203204
    204                                 textarea.value = textarea.value.substring( 0, begin )
    205                                                + html
    206                                                + textarea.value.substring( end, textarea.value.length );
     205                                textarea.value = textarea.value.substring( 0, begin ) + html +
     206                                        textarea.value.substring( end, textarea.value.length );
    207207
    208208                                // Update cursor position
    209209                                textarea.selectionStart = textarea.selectionEnd = cursor;
     
    227227                                        b = ed.selection.getBookmark();
    228228                                        ed.dom.remove(e, 1);
    229229                                        ed.selection.moveToBookmark(b);
    230                                         tinyMCEPopup.execCommand("mceEndUndoLevel");
     230                                        tinyMCEPopup.execCommand('mceEndUndoLevel');
    231231                                        wpLink.close();
    232232                                }
    233233                                return;
     
    234234                        }
    235235
    236236                        if (e == null) {
    237                                 ed.getDoc().execCommand("unlink", false, null);
    238                                 tinyMCEPopup.execCommand("mceInsertLink", false, "#mce_temp_url#", {skip_undo : 1});
     237                                ed.getDoc().execCommand('unlink', false, null);
     238                                tinyMCEPopup.execCommand('mceInsertLink', false, '#mce_temp_url#', {skip_undo : 1});
    239239
    240                                 tinymce.each(ed.dom.select("a"), function(n) {
     240                                tinymce.each(ed.dom.select('a'), function(n) {
    241241                                        if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') {
    242242                                                e = n;
    243243                                                ed.dom.setAttribs(e, attrs);
     
    262262                                tinyMCEPopup.storeSelection();
    263263                        }
    264264
    265                         ed.execCommand("mceEndUndoLevel");
     265                        ed.execCommand('mceEndUndoLevel');
    266266                        wpLink.close();
    267267                        ed.focus();
    268268                },
     
    270270                updateFields : function( e, li, originalEvent ) {
    271271                        inputs.url.val( li.children('.item-permalink').val() );
    272272                        inputs.title.val( li.hasClass('no-title') ? '' : li.children('.item-title').text() );
    273                         if ( originalEvent && originalEvent.type == "click" )
     273                        if ( originalEvent && originalEvent.type == 'click' )
    274274                                inputs.url.focus();
    275275                },
    276276                setDefaultValues : function() {
     
    318318                keydown : function( event ) {
    319319                        var fn, key = $.ui.keyCode;
    320320
    321                         switch( event.which ) {
    322                                 case key.UP:
    323                                         fn = 'prev';
    324                                 case key.DOWN:
    325                                         fn = fn || 'next';
    326                                         clearInterval( wpLink.keyInterval );
    327                                         wpLink[ fn ]();
    328                                         wpLink.keyInterval = setInterval( wpLink[ fn ], wpLink.keySensitivity );
    329                                         break;
    330                                 default:
    331                                         return;
     321                        if ( event.which !== key.UP && event.which !== key.DOWN ) {
     322                                return;
    332323                        }
     324
     325                        fn = event.which === key.UP ? 'prev' : 'next';
     326                        clearInterval( wpLink.keyInterval );
     327                        wpLink[ fn ]();
     328                        wpLink.keyInterval = setInterval( wpLink[ fn ], wpLink.keySensitivity );
    333329                        event.preventDefault();
    334330                },
     331
    335332                keyup: function( event ) {
    336333                        var key = $.ui.keyCode;
    337334
    338                         switch( event.which ) {
    339                                 case key.ESCAPE:
    340                                         event.stopImmediatePropagation();
    341                                         if ( ! $(document).triggerHandler( 'wp_CloseOnEscape', [{ event: event, what: 'wplink', cb: wpLink.close }] ) )
    342                                                 wpLink.close();
     335                        if ( event.which === key.ESCAPE ) {
     336                                event.stopImmediatePropagation();
     337                                if ( ! $(document).triggerHandler( 'wp_CloseOnEscape', [{ event: event, what: 'wplink', cb: wpLink.close }] ) )
     338                                        wpLink.close();
     339                                return false;
     340                        }
    343341
    344                                         return false;
    345                                         break;
    346                                 case key.UP:
    347                                 case key.DOWN:
    348                                         clearInterval( wpLink.keyInterval );
    349                                         break;
    350                                 default:
    351                                         return;
     342                        if ( event.which === key.UP || event.which === key.DOWN ) {
     343                                clearInterval( wpLink.keyInterval );
     344                                event.preventDefault();
    352345                        }
    353                         event.preventDefault();
    354346                },
    355347
    356348                delayedCallback : function( func, delay ) {
     
    507499
    508500                        if ( !results ) {
    509501                                if ( firstPage ) {
    510                                         list += '<li class="unselectable"><span class="item-title"><em>'
    511                                         + wpLinkL10n.noMatchesFound
    512                                         + '</em></span></li>';
     502                                        list += '<li class="unselectable"><span class="item-title"><em>' +
     503                                        wpLinkL10n.noMatchesFound +
     504                                        '</em></span></li>';
    513505                                }
    514506                        } else {
    515507                                $.each( results, function() {
    516508                                        classes = alt ? 'alternate' : '';
    517                                         classes += this['title'] ? '' : ' no-title';
     509                                        classes += this.title ? '' : ' no-title';
    518510                                        list += classes ? '<li class="' + classes + '">' : '<li>';
    519                                         list += '<input type="hidden" class="item-permalink" value="' + this['permalink'] + '" />';
     511                                        list += '<input type="hidden" class="item-permalink" value="' + this.permalink + '" />';
    520512                                        list += '<span class="item-title">';
    521                                         list += this['title'] ? this['title'] : wpLinkL10n.noTitle;
    522                                         list += '</span><span class="item-info">' + this['info'] + '</span></li>';
     513                                        list += this.title ? this.title : wpLinkL10n.noTitle;
     514                                        list += '</span><span class="item-info">' + this.info + '</span></li>';
    523515                                        alt = ! alt;
    524516                                });
    525517                        }
     
    578570                                self.querying = false;
    579571                                self.allLoaded = !r;
    580572                                callback( r, query );
    581                         }, "json" );
     573                        }, 'json' );
    582574                }
    583575        });
    584576