~ubuntu-branches/debian/sid/wordpress/sid

« back to all changes in this revision

Viewing changes to wp-includes/js/wplink.js

  • Committer: Package Import Robot
  • Author(s): Craig Small
  • Date: 2014-09-05 20:58:06 UTC
  • mfrom: (1.2.38)
  • Revision ID: package-import@ubuntu.com-20140905205806-e4h6dkg4190n0svf
Tags: 4.0+dfsg-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
var wpLink;
3
3
 
4
4
( function( $ ) {
5
 
        var inputs = {}, rivers = {}, editor, searchTimer, River, Query;
 
5
        var editor, searchTimer, River, Query,
 
6
                inputs = {},
 
7
                rivers = {},
 
8
                isTouch = ( 'ontouchend' in document );
6
9
 
7
10
        wpLink = {
8
11
                timeToTriggerRiver: 150,
31
34
                        rivers.recent = new River( $( '#most-recent-results' ) );
32
35
                        rivers.elements = inputs.dialog.find( '.query-results' );
33
36
 
 
37
                        // Get search notice text
 
38
                        inputs.queryNotice = $( '#query-notice-message' );
 
39
                        inputs.queryNoticeTextDefault = inputs.queryNotice.find( '.query-notice-default' );
 
40
                        inputs.queryNoticeTextHint = inputs.queryNotice.find( '.query-notice-hint' );
 
41
 
34
42
                        // Bind event handlers
35
43
                        inputs.dialog.keydown( wpLink.keydown );
36
44
                        inputs.dialog.keyup( wpLink.keyup );
43
51
                                wpLink.close();
44
52
                        });
45
53
 
46
 
                        $( '#wp-link-search-toggle' ).click( wpLink.toggleInternalLinking );
 
54
                        $( '#wp-link-search-toggle' ).on( 'click', wpLink.toggleInternalLinking );
47
55
 
48
56
                        rivers.elements.on( 'river-select', wpLink.updateFields );
49
57
 
 
58
                        // Display 'hint' message when search field or 'query-results' box are focused
 
59
                        inputs.search.on( 'focus.wplink', function() {
 
60
                                inputs.queryNoticeTextDefault.hide();
 
61
                                inputs.queryNoticeTextHint.removeClass( 'screen-reader-text' ).show();
 
62
                        } ).on( 'blur.wplink', function() {
 
63
                                inputs.queryNoticeTextDefault.show();
 
64
                                inputs.queryNoticeTextHint.addClass( 'screen-reader-text' ).hide();
 
65
                        } );
 
66
 
50
67
                        inputs.search.keyup( function() {
51
68
                                var self = this;
52
69
 
59
76
 
60
77
                open: function( editorId ) {
61
78
                        var ed;
62
 
                        
 
79
 
63
80
                        wpLink.range = null;
64
81
 
65
82
                        if ( editorId ) {
95
112
                        inputs.backdrop.show();
96
113
 
97
114
                        wpLink.refresh();
 
115
                        $( document ).trigger( 'wplink-open', inputs.wrap );
98
116
                },
99
117
 
100
118
                isMCE: function() {
106
124
                        rivers.search.refresh();
107
125
                        rivers.recent.refresh();
108
126
 
109
 
                        if ( wpLink.isMCE() )
 
127
                        if ( wpLink.isMCE() ) {
110
128
                                wpLink.mceRefresh();
111
 
                        else
 
129
                        } else {
112
130
                                wpLink.setDefaultValues();
113
 
 
114
 
                        // Focus the URL field and highlight its contents.
115
 
                        //     If this is moved above the selection changes,
116
 
                        //     IE will show a flashing cursor over the dialog.
117
 
                        inputs.url.focus()[0].select();
 
131
                        }
 
132
 
 
133
                        if ( isTouch ) {
 
134
                                // Close the onscreen keyboard
 
135
                                inputs.url.focus().blur();
 
136
                        } else {
 
137
                                // Focus the URL field and highlight its contents.
 
138
                                // If this is moved above the selection changes,
 
139
                                // IE will show a flashing cursor over the dialog.
 
140
                                inputs.url.focus()[0].select();
 
141
                        }
 
142
 
118
143
                        // Load the most recent results if this is the first time opening the panel.
119
 
                        if ( ! rivers.recent.ul.children().length )
 
144
                        if ( ! rivers.recent.ul.children().length ) {
120
145
                                rivers.recent.ajax();
 
146
                        }
121
147
                },
122
148
 
123
149
                mceRefresh: function() {
153
179
 
154
180
                        inputs.backdrop.hide();
155
181
                        inputs.wrap.hide();
 
182
                        $( document ).trigger( 'wplink-close', inputs.wrap );
156
183
                },
157
184
 
158
185
                getAttrs: function() {
260
287
                        editor.selection.collapse();
261
288
                },
262
289
 
263
 
                updateFields: function( e, li, originalEvent ) {
 
290
                updateFields: function( e, li ) {
264
291
                        inputs.url.val( li.children( '.item-permalink' ).val() );
265
292
                        inputs.title.val( li.hasClass( 'no-title' ) ? '' : li.children( '.item-title' ).text() );
266
 
                        if ( originalEvent && originalEvent.type == 'click' )
267
 
                                inputs.url.focus();
268
293
                },
269
294
 
270
295
                setDefaultValues: function() {
271
 
                        // Set URL and description to defaults.
272
 
                        // Leave the new tab setting as-is.
273
 
                        inputs.url.val( 'http://' );
 
296
                        var selection = editor && editor.selection.getContent(),
 
297
                                emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
 
298
                                urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i;
 
299
 
 
300
                        if ( selection && emailRegexp.test( selection ) ) {
 
301
                                // Selection is email address
 
302
                                inputs.url.val( 'mailto:' + selection );
 
303
                        } else if ( selection && urlRegexp.test( selection ) ) {
 
304
                                // Selection is URL
 
305
                                inputs.url.val( selection.replace( /&|&#0?38;/gi, '&' ) );
 
306
                        } else {
 
307
                                // Set URL to default.
 
308
                                inputs.url.val( 'http://' );
 
309
                        }
 
310
 
 
311
                        // Set description to default.
274
312
                        inputs.title.val( '' );
275
313
 
276
314
                        // Update save prompt.
322
360
                        } else if ( key.TAB === event.keyCode ) {
323
361
                                id = event.target.id;
324
362
 
 
363
                                // wp-link-submit must always be the last focusable element in the dialog.
 
364
                                // following focusable elements will be skipped on keyboard navigation.
325
365
                                if ( id === 'wp-link-submit' && ! event.shiftKey ) {
326
366
                                        inputs.close.focus();
327
367
                                        event.preventDefault();
335
375
                                return;
336
376
                        }
337
377
 
 
378
                        if ( document.activeElement &&
 
379
                                ( document.activeElement.id === 'link-title-field' || document.activeElement.id === 'url-field' ) ) {
 
380
                                return;
 
381
                        }
 
382
 
338
383
                        fn = event.keyCode === key.UP ? 'prev' : 'next';
339
384
                        clearInterval( wpLink.keyInterval );
340
385
                        wpLink[ fn ]();
374
419
                        };
375
420
                },
376
421
 
377
 
                toggleInternalLinking: function() {
 
422
                toggleInternalLinking: function( event ) {
378
423
                        var visible = inputs.wrap.hasClass( 'search-panel-visible' );
379
424
 
380
425
                        inputs.wrap.toggleClass( 'search-panel-visible', ! visible );
381
426
                        setUserSetting( 'wplink', visible ? '0' : '1' );
382
427
                        inputs[ ! visible ? 'search' : 'url' ].focus();
 
428
                        event.preventDefault();
383
429
                }
384
430
        };
385
431
 
489
535
 
490
536
                        if ( ! results ) {
491
537
                                if ( firstPage ) {
492
 
                                        list += '<li class="unselectable"><span class="item-title"><em>' +
 
538
                                        list += '<li class="unselectable no-matches-found"><span class="item-title"><em>' +
493
539
                                                wpLinkL10n.noMatchesFound + '</em></span></li>';
494
540
                                }
495
541
                        } else {