WP Multibyte Patch - Version 2.1.1

Version Description

Download this release

Release Info

Developer tenpura
Plugin Icon wp plugin WP Multibyte Patch
Version 2.1.1
Comparing to
See all releases

Code changes from version 2.0 to 2.1.1

ext/ja/class.php CHANGED
@@ -3,7 +3,7 @@
3
  * WP Multibyte Patch Japanese Locale Extension
4
  *
5
  * @package WP_Multibyte_Patch
6
- * @version 2.0
7
  * @author Seisuke Kuraishi <210pura@gmail.com>
8
  * @copyright Copyright (c) 2014 Seisuke Kuraishi, Tinybit Inc.
9
  * @license http://opensource.org/licenses/gpl-2.0.php GPLv2
3
  * WP Multibyte Patch Japanese Locale Extension
4
  *
5
  * @package WP_Multibyte_Patch
6
+ * @version 2.1.1
7
  * @author Seisuke Kuraishi <210pura@gmail.com>
8
  * @copyright Copyright (c) 2014 Seisuke Kuraishi, Tinybit Inc.
9
  * @license http://opensource.org/licenses/gpl-2.0.php GPLv2
js/20140410/wplink.js ADDED
@@ -0,0 +1,569 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* global ajaxurl, tinymce, wpLinkL10n, setUserSetting, wpActiveEditor */
2
+ var wpLink;
3
+
4
+ ( function( $ ) {
5
+ var inputs = {}, rivers = {}, editor, searchTimer, River, Query;
6
+
7
+ wpLink = {
8
+ timeToTriggerRiver: 150,
9
+ minRiverAJAXDuration: 200,
10
+ riverBottomThreshold: 5,
11
+ keySensitivity: 100,
12
+ lastSearch: '',
13
+ textarea: '',
14
+
15
+ init: function() {
16
+ inputs.wrap = $('#wp-link-wrap');
17
+ inputs.dialog = $( '#wp-link' );
18
+ inputs.backdrop = $( '#wp-link-backdrop' );
19
+ inputs.submit = $( '#wp-link-submit' );
20
+ inputs.close = $( '#wp-link-close' );
21
+ // URL
22
+ inputs.url = $( '#url-field' );
23
+ inputs.nonce = $( '#_ajax_linking_nonce' );
24
+ // Secondary options
25
+ inputs.title = $( '#link-title-field' );
26
+ // Advanced Options
27
+ inputs.openInNewTab = $( '#link-target-checkbox' );
28
+ inputs.search = $( '#search-field' );
29
+ // Build Rivers
30
+ rivers.search = new River( $( '#search-results' ) );
31
+ rivers.recent = new River( $( '#most-recent-results' ) );
32
+ rivers.elements = inputs.dialog.find( '.query-results' );
33
+
34
+ // Bind event handlers
35
+ inputs.dialog.keydown( wpLink.keydown );
36
+ inputs.dialog.keyup( wpLink.keyup );
37
+ inputs.submit.click( function( event ) {
38
+ event.preventDefault();
39
+ wpLink.update();
40
+ });
41
+ inputs.close.add( inputs.backdrop ).add( '#wp-link-cancel a' ).click( function( event ) {
42
+ event.preventDefault();
43
+ wpLink.close();
44
+ });
45
+
46
+ $( '#wp-link-search-toggle' ).click( wpLink.toggleInternalLinking );
47
+
48
+ rivers.elements.on( 'river-select', wpLink.updateFields );
49
+
50
+ inputs.search.keyup( function() {
51
+ var self = this;
52
+
53
+ window.clearTimeout( searchTimer );
54
+ searchTimer = window.setTimeout( function() {
55
+ wpLink.searchInternalLinks.call( self );
56
+ }, 500 );
57
+ });
58
+ },
59
+
60
+ open: function( editorId ) {
61
+ var ed;
62
+
63
+ wpLink.range = null;
64
+
65
+ if ( editorId ) {
66
+ window.wpActiveEditor = editorId;
67
+ }
68
+
69
+ if ( ! window.wpActiveEditor ) {
70
+ return;
71
+ }
72
+
73
+ this.textarea = $( '#' + window.wpActiveEditor ).get( 0 );
74
+
75
+ if ( typeof tinymce !== 'undefined' ) {
76
+ ed = tinymce.get( wpActiveEditor );
77
+
78
+ if ( ed && ! ed.isHidden() ) {
79
+ editor = ed;
80
+ } else {
81
+ editor = null;
82
+ }
83
+
84
+ if ( editor && tinymce.isIE ) {
85
+ editor.windowManager.bookmark = editor.selection.getBookmark();
86
+ }
87
+ }
88
+
89
+ if ( ! wpLink.isMCE() && document.selection ) {
90
+ this.textarea.focus();
91
+ this.range = document.selection.createRange();
92
+ }
93
+
94
+ inputs.wrap.show();
95
+ inputs.backdrop.show();
96
+
97
+ wpLink.refresh();
98
+ },
99
+
100
+ isMCE: function() {
101
+ return editor && ! editor.isHidden();
102
+ },
103
+
104
+ refresh: function() {
105
+ // Refresh rivers (clear links, check visibility)
106
+ rivers.search.refresh();
107
+ rivers.recent.refresh();
108
+
109
+ if ( wpLink.isMCE() )
110
+ wpLink.mceRefresh();
111
+ else
112
+ 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();
118
+ // Load the most recent results if this is the first time opening the panel.
119
+ if ( ! rivers.recent.ul.children().length )
120
+ rivers.recent.ajax();
121
+ },
122
+
123
+ mceRefresh: function() {
124
+ var e;
125
+
126
+ // If link exists, select proper values.
127
+ if ( e = editor.dom.getParent( editor.selection.getNode(), 'A' ) ) {
128
+ // Set URL and description.
129
+ inputs.url.val( editor.dom.getAttrib( e, 'href' ) );
130
+ inputs.title.val( editor.dom.getAttrib( e, 'title' ) );
131
+ // Set open in new tab.
132
+ inputs.openInNewTab.prop( 'checked', ( '_blank' === editor.dom.getAttrib( e, 'target' ) ) );
133
+ // Update save prompt.
134
+ inputs.submit.val( wpLinkL10n.update );
135
+
136
+ // If there's no link, set the default values.
137
+ } else {
138
+ wpLink.setDefaultValues();
139
+ }
140
+ },
141
+
142
+ close: function() {
143
+ if ( ! wpLink.isMCE() ) {
144
+ wpLink.textarea.focus();
145
+
146
+ if ( wpLink.range ) {
147
+ wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
148
+ wpLink.range.select();
149
+ }
150
+ } else {
151
+ editor.focus();
152
+ }
153
+
154
+ inputs.backdrop.hide();
155
+ inputs.wrap.hide();
156
+ },
157
+
158
+ getAttrs: function() {
159
+ return {
160
+ href: inputs.url.val(),
161
+ title: inputs.title.val(),
162
+ target: inputs.openInNewTab.prop( 'checked' ) ? '_blank' : ''
163
+ };
164
+ },
165
+
166
+ update: function() {
167
+ if ( wpLink.isMCE() )
168
+ wpLink.mceUpdate();
169
+ else
170
+ wpLink.htmlUpdate();
171
+ },
172
+
173
+ htmlUpdate: function() {
174
+ var attrs, html, begin, end, cursor, title, selection,
175
+ textarea = wpLink.textarea;
176
+
177
+ if ( ! textarea )
178
+ return;
179
+
180
+ attrs = wpLink.getAttrs();
181
+
182
+ // If there's no href, return.
183
+ if ( ! attrs.href || attrs.href == 'http://' )
184
+ return;
185
+
186
+ // Build HTML
187
+ html = '<a href="' + attrs.href + '"';
188
+
189
+ if ( attrs.title ) {
190
+ title = attrs.title.replace( /</g, '&lt;' ).replace( />/g, '&gt;' ).replace( /"/g, '&quot;' );
191
+ html += ' title="' + title + '"';
192
+ }
193
+
194
+ if ( attrs.target ) {
195
+ html += ' target="' + attrs.target + '"';
196
+ }
197
+
198
+ html += '>';
199
+
200
+ // Insert HTML
201
+ if ( document.selection && wpLink.range ) {
202
+ // IE
203
+ // Note: If no text is selected, IE will not place the cursor
204
+ // inside the closing tag.
205
+ textarea.focus();
206
+ wpLink.range.text = html + wpLink.range.text + '</a>';
207
+ wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
208
+ wpLink.range.select();
209
+
210
+ wpLink.range = null;
211
+ } else if ( typeof textarea.selectionStart !== 'undefined' ) {
212
+ // W3C
213
+ begin = textarea.selectionStart;
214
+ end = textarea.selectionEnd;
215
+ selection = textarea.value.substring( begin, end );
216
+ html = html + selection + '</a>';
217
+ cursor = begin + html.length;
218
+
219
+ // If no text is selected, place the cursor inside the closing tag.
220
+ if ( begin == end )
221
+ cursor -= '</a>'.length;
222
+
223
+ textarea.value = textarea.value.substring( 0, begin ) + html +
224
+ textarea.value.substring( end, textarea.value.length );
225
+
226
+ // Update cursor position
227
+ textarea.selectionStart = textarea.selectionEnd = cursor;
228
+ }
229
+
230
+ wpLink.close();
231
+ textarea.focus();
232
+ },
233
+
234
+ mceUpdate: function() {
235
+ var link,
236
+ attrs = wpLink.getAttrs();
237
+
238
+ wpLink.close();
239
+ editor.focus();
240
+
241
+ if ( tinymce.isIE ) {
242
+ editor.selection.moveToBookmark( editor.windowManager.bookmark );
243
+ }
244
+
245
+ link = editor.dom.getParent( editor.selection.getNode(), 'a[href]' );
246
+
247
+ // If the values are empty, unlink and return
248
+ if ( ! attrs.href || attrs.href == 'http://' ) {
249
+ editor.execCommand( 'unlink' );
250
+ return;
251
+ }
252
+
253
+ if ( link ) {
254
+ editor.dom.setAttribs( link, attrs );
255
+ } else {
256
+ editor.execCommand( 'mceInsertLink', false, attrs );
257
+ }
258
+
259
+ // Move the cursor to the end of the selection
260
+ editor.selection.collapse();
261
+ },
262
+
263
+ updateFields: function( e, li, originalEvent ) {
264
+ inputs.url.val( li.children( '.item-permalink' ).val() );
265
+ inputs.title.val( li.hasClass( 'no-title' ) ? '' : li.children( '.item-title' ).text() );
266
+ if ( originalEvent && originalEvent.type == 'click' )
267
+ inputs.url.focus();
268
+ },
269
+
270
+ setDefaultValues: function() {
271
+ // Set URL and description to defaults.
272
+ // Leave the new tab setting as-is.
273
+ inputs.url.val( 'http://' );
274
+ inputs.title.val( '' );
275
+
276
+ // Update save prompt.
277
+ inputs.submit.val( wpLinkL10n.save );
278
+ },
279
+
280
+ searchInternalLinks: function() {
281
+ var t = $( this ), waiting,
282
+ search = t.val();
283
+
284
+ if ( search.length > 1 ) {
285
+ rivers.recent.hide();
286
+ rivers.search.show();
287
+
288
+ // Don't search if the keypress didn't change the title.
289
+ if ( wpLink.lastSearch == search )
290
+ return;
291
+
292
+ wpLink.lastSearch = search;
293
+ waiting = t.parent().find('.spinner').show();
294
+
295
+ rivers.search.change( search );
296
+ rivers.search.ajax( function() {
297
+ waiting.hide();
298
+ });
299
+ } else {
300
+ rivers.search.hide();
301
+ rivers.recent.show();
302
+ }
303
+ },
304
+
305
+ next: function() {
306
+ rivers.search.next();
307
+ rivers.recent.next();
308
+ },
309
+
310
+ prev: function() {
311
+ rivers.search.prev();
312
+ rivers.recent.prev();
313
+ },
314
+
315
+ keydown: function( event ) {
316
+ var fn, id,
317
+ key = $.ui.keyCode;
318
+
319
+ if ( key.ESCAPE === event.keyCode ) {
320
+ wpLink.close();
321
+ event.stopImmediatePropagation();
322
+ } else if ( key.TAB === event.keyCode ) {
323
+ id = event.target.id;
324
+
325
+ if ( id === 'wp-link-submit' && ! event.shiftKey ) {
326
+ inputs.close.focus();
327
+ event.preventDefault();
328
+ } else if ( id === 'wp-link-close' && event.shiftKey ) {
329
+ inputs.submit.focus();
330
+ event.preventDefault();
331
+ }
332
+ }
333
+
334
+ if ( event.keyCode !== key.UP && event.keyCode !== key.DOWN ) {
335
+ return;
336
+ }
337
+
338
+ fn = event.keyCode === key.UP ? 'prev' : 'next';
339
+ clearInterval( wpLink.keyInterval );
340
+ wpLink[ fn ]();
341
+ wpLink.keyInterval = setInterval( wpLink[ fn ], wpLink.keySensitivity );
342
+ event.preventDefault();
343
+ },
344
+
345
+ keyup: function( event ) {
346
+ var key = $.ui.keyCode;
347
+
348
+ if ( event.which === key.UP || event.which === key.DOWN ) {
349
+ clearInterval( wpLink.keyInterval );
350
+ event.preventDefault();
351
+ }
352
+ },
353
+
354
+ delayedCallback: function( func, delay ) {
355
+ var timeoutTriggered, funcTriggered, funcArgs, funcContext;
356
+
357
+ if ( ! delay )
358
+ return func;
359
+
360
+ setTimeout( function() {
361
+ if ( funcTriggered )
362
+ return func.apply( funcContext, funcArgs );
363
+ // Otherwise, wait.
364
+ timeoutTriggered = true;
365
+ }, delay );
366
+
367
+ return function() {
368
+ if ( timeoutTriggered )
369
+ return func.apply( this, arguments );
370
+ // Otherwise, wait.
371
+ funcArgs = arguments;
372
+ funcContext = this;
373
+ funcTriggered = true;
374
+ };
375
+ },
376
+
377
+ toggleInternalLinking: function() {
378
+ var visible = inputs.wrap.hasClass( 'search-panel-visible' );
379
+
380
+ inputs.wrap.toggleClass( 'search-panel-visible', ! visible );
381
+ setUserSetting( 'wplink', visible ? '0' : '1' );
382
+ inputs[ ! visible ? 'search' : 'url' ].focus();
383
+ }
384
+ };
385
+
386
+ River = function( element, search ) {
387
+ var self = this;
388
+ this.element = element;
389
+ this.ul = element.children( 'ul' );
390
+ this.contentHeight = element.children( '#link-selector-height' );
391
+ this.waiting = element.find('.river-waiting');
392
+
393
+ this.change( search );
394
+ this.refresh();
395
+
396
+ $( '#wp-link .query-results, #wp-link #link-selector' ).scroll( function() {
397
+ self.maybeLoad();
398
+ });
399
+ element.on( 'click', 'li', function( event ) {
400
+ self.select( $( this ), event );
401
+ });
402
+ };
403
+
404
+ $.extend( River.prototype, {
405
+ refresh: function() {
406
+ this.deselect();
407
+ this.visible = this.element.is( ':visible' );
408
+ },
409
+ show: function() {
410
+ if ( ! this.visible ) {
411
+ this.deselect();
412
+ this.element.show();
413
+ this.visible = true;
414
+ }
415
+ },
416
+ hide: function() {
417
+ this.element.hide();
418
+ this.visible = false;
419
+ },
420
+ // Selects a list item and triggers the river-select event.
421
+ select: function( li, event ) {
422
+ var liHeight, elHeight, liTop, elTop;
423
+
424
+ if ( li.hasClass( 'unselectable' ) || li == this.selected )
425
+ return;
426
+
427
+ this.deselect();
428
+ this.selected = li.addClass( 'selected' );
429
+ // Make sure the element is visible
430
+ liHeight = li.outerHeight();
431
+ elHeight = this.element.height();
432
+ liTop = li.position().top;
433
+ elTop = this.element.scrollTop();
434
+
435
+ if ( liTop < 0 ) // Make first visible element
436
+ this.element.scrollTop( elTop + liTop );
437
+ else if ( liTop + liHeight > elHeight ) // Make last visible element
438
+ this.element.scrollTop( elTop + liTop - elHeight + liHeight );
439
+
440
+ // Trigger the river-select event
441
+ this.element.trigger( 'river-select', [ li, event, this ] );
442
+ },
443
+ deselect: function() {
444
+ if ( this.selected )
445
+ this.selected.removeClass( 'selected' );
446
+ this.selected = false;
447
+ },
448
+ prev: function() {
449
+ if ( ! this.visible )
450
+ return;
451
+
452
+ var to;
453
+ if ( this.selected ) {
454
+ to = this.selected.prev( 'li' );
455
+ if ( to.length )
456
+ this.select( to );
457
+ }
458
+ },
459
+ next: function() {
460
+ if ( ! this.visible )
461
+ return;
462
+
463
+ var to = this.selected ? this.selected.next( 'li' ) : $( 'li:not(.unselectable):first', this.element );
464
+ if ( to.length )
465
+ this.select( to );
466
+ },
467
+ ajax: function( callback ) {
468
+ var self = this,
469
+ delay = this.query.page == 1 ? 0 : wpLink.minRiverAJAXDuration,
470
+ response = wpLink.delayedCallback( function( results, params ) {
471
+ self.process( results, params );
472
+ if ( callback )
473
+ callback( results, params );
474
+ }, delay );
475
+
476
+ this.query.ajax( response );
477
+ },
478
+ change: function( search ) {
479
+ if ( this.query && this._search == search )
480
+ return;
481
+
482
+ this._search = search;
483
+ this.query = new Query( search );
484
+ this.element.scrollTop( 0 );
485
+ },
486
+ process: function( results, params ) {
487
+ var list = '', alt = true, classes = '',
488
+ firstPage = params.page == 1;
489
+
490
+ if ( ! results ) {
491
+ if ( firstPage ) {
492
+ list += '<li class="unselectable"><span class="item-title"><em>' +
493
+ wpLinkL10n.noMatchesFound + '</em></span></li>';
494
+ }
495
+ } else {
496
+ $.each( results, function() {
497
+ classes = alt ? 'alternate' : '';
498
+ classes += this.title ? '' : ' no-title';
499
+ list += classes ? '<li class="' + classes + '">' : '<li>';
500
+ list += '<input type="hidden" class="item-permalink" value="' + this.permalink + '" />';
501
+ list += '<span class="item-title">';
502
+ list += this.title ? this.title : wpLinkL10n.noTitle;
503
+ list += '</span><span class="item-info">' + this.info + '</span></li>';
504
+ alt = ! alt;
505
+ });
506
+ }
507
+
508
+ this.ul[ firstPage ? 'html' : 'append' ]( list );
509
+ },
510
+ maybeLoad: function() {
511
+ var self = this,
512
+ el = this.element,
513
+ bottom = el.scrollTop() + el.height();
514
+
515
+ if ( ! this.query.ready() || bottom < this.contentHeight.height() - wpLink.riverBottomThreshold )
516
+ return;
517
+
518
+ setTimeout(function() {
519
+ var newTop = el.scrollTop(),
520
+ newBottom = newTop + el.height();
521
+
522
+ if ( ! self.query.ready() || newBottom < self.contentHeight.height() - wpLink.riverBottomThreshold )
523
+ return;
524
+
525
+ self.waiting.show();
526
+ el.scrollTop( newTop + self.waiting.outerHeight() );
527
+
528
+ self.ajax( function() {
529
+ self.waiting.hide();
530
+ });
531
+ }, wpLink.timeToTriggerRiver );
532
+ }
533
+ });
534
+
535
+ Query = function( search ) {
536
+ this.page = 1;
537
+ this.allLoaded = false;
538
+ this.querying = false;
539
+ this.search = search;
540
+ };
541
+
542
+ $.extend( Query.prototype, {
543
+ ready: function() {
544
+ return ! ( this.querying || this.allLoaded );
545
+ },
546
+ ajax: function( callback ) {
547
+ var self = this,
548
+ query = {
549
+ action : 'wp-link-ajax',
550
+ page : this.page,
551
+ '_ajax_linking_nonce' : inputs.nonce.val()
552
+ };
553
+
554
+ if ( this.search )
555
+ query.search = this.search;
556
+
557
+ this.querying = true;
558
+
559
+ $.post( ajaxurl, query, function( r ) {
560
+ self.page++;
561
+ self.querying = false;
562
+ self.allLoaded = ! r;
563
+ callback( r, query );
564
+ }, 'json' );
565
+ }
566
+ });
567
+
568
+ $( document ).ready( wpLink.init );
569
+ })( jQuery );
js/20140410/wplink.min.js ADDED
@@ -0,0 +1 @@
 
1
+ var wpLink;!function(a){var b,c,d,e,f={},g={};wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",init:function(){f.wrap=a("#wp-link-wrap"),f.dialog=a("#wp-link"),f.backdrop=a("#wp-link-backdrop"),f.submit=a("#wp-link-submit"),f.close=a("#wp-link-close"),f.url=a("#url-field"),f.nonce=a("#_ajax_linking_nonce"),f.title=a("#link-title-field"),f.openInNewTab=a("#link-target-checkbox"),f.search=a("#search-field"),g.search=new d(a("#search-results")),g.recent=new d(a("#most-recent-results")),g.elements=f.dialog.find(".query-results"),f.dialog.keydown(wpLink.keydown),f.dialog.keyup(wpLink.keyup),f.submit.click(function(a){a.preventDefault(),wpLink.update()}),f.close.add(f.backdrop).add("#wp-link-cancel a").click(function(a){a.preventDefault(),wpLink.close()}),a("#wp-link-search-toggle").click(wpLink.toggleInternalLinking),g.elements.on("river-select",wpLink.updateFields),f.search.keyup(function(){var a=this;window.clearTimeout(c),c=window.setTimeout(function(){wpLink.searchInternalLinks.call(a)},500)})},open:function(c){var d;wpLink.range=null,c&&(window.wpActiveEditor=c),window.wpActiveEditor&&(this.textarea=a("#"+window.wpActiveEditor).get(0),"undefined"!=typeof tinymce&&(d=tinymce.get(wpActiveEditor),b=d&&!d.isHidden()?d:null,b&&tinymce.isIE&&(b.windowManager.bookmark=b.selection.getBookmark())),!wpLink.isMCE()&&document.selection&&(this.textarea.focus(),this.range=document.selection.createRange()),f.wrap.show(),f.backdrop.show(),wpLink.refresh())},isMCE:function(){return b&&!b.isHidden()},refresh:function(){g.search.refresh(),g.recent.refresh(),wpLink.isMCE()?wpLink.mceRefresh():wpLink.setDefaultValues(),f.url.focus()[0].select(),g.recent.ul.children().length||g.recent.ajax()},mceRefresh:function(){var a;(a=b.dom.getParent(b.selection.getNode(),"A"))?(f.url.val(b.dom.getAttrib(a,"href")),f.title.val(b.dom.getAttrib(a,"title")),f.openInNewTab.prop("checked","_blank"===b.dom.getAttrib(a,"target")),f.submit.val(wpLinkL10n.update)):wpLink.setDefaultValues()},close:function(){wpLink.isMCE()?b.focus():(wpLink.textarea.focus(),wpLink.range&&(wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select())),f.backdrop.hide(),f.wrap.hide()},getAttrs:function(){return{href:f.url.val(),title:f.title.val(),target:f.openInNewTab.prop("checked")?"_blank":""}},update:function(){wpLink.isMCE()?wpLink.mceUpdate():wpLink.htmlUpdate()},htmlUpdate:function(){var a,b,c,d,e,f,g,h=wpLink.textarea;h&&(a=wpLink.getAttrs(),a.href&&"http://"!=a.href&&(b='<a href="'+a.href+'"',a.title&&(f=a.title.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),b+=' title="'+f+'"'),a.target&&(b+=' target="'+a.target+'"'),b+=">",document.selection&&wpLink.range?(h.focus(),wpLink.range.text=b+wpLink.range.text+"</a>",wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select(),wpLink.range=null):"undefined"!=typeof h.selectionStart&&(c=h.selectionStart,d=h.selectionEnd,g=h.value.substring(c,d),b=b+g+"</a>",e=c+b.length,c==d&&(e-="</a>".length),h.value=h.value.substring(0,c)+b+h.value.substring(d,h.value.length),h.selectionStart=h.selectionEnd=e),wpLink.close(),h.focus()))},mceUpdate:function(){var a,c=wpLink.getAttrs();return wpLink.close(),b.focus(),tinymce.isIE&&b.selection.moveToBookmark(b.windowManager.bookmark),a=b.dom.getParent(b.selection.getNode(),"a[href]"),c.href&&"http://"!=c.href?(a?b.dom.setAttribs(a,c):b.execCommand("mceInsertLink",!1,c),void b.selection.collapse()):void b.execCommand("unlink")},updateFields:function(a,b,c){f.url.val(b.children(".item-permalink").val()),f.title.val(b.hasClass("no-title")?"":b.children(".item-title").text()),c&&"click"==c.type&&f.url.focus()},setDefaultValues:function(){f.url.val("http://"),f.title.val(""),f.submit.val(wpLinkL10n.save)},searchInternalLinks:function(){var b,c=a(this),d=c.val();if(d.length>1){if(g.recent.hide(),g.search.show(),wpLink.lastSearch==d)return;wpLink.lastSearch=d,b=c.parent().find(".spinner").show(),g.search.change(d),g.search.ajax(function(){b.hide()})}else g.search.hide(),g.recent.show()},next:function(){g.search.next(),g.recent.next()},prev:function(){g.search.prev(),g.recent.prev()},keydown:function(b){var c,d,e=a.ui.keyCode;e.ESCAPE===b.keyCode?(wpLink.close(),b.stopImmediatePropagation()):e.TAB===b.keyCode&&(d=b.target.id,"wp-link-submit"!==d||b.shiftKey?"wp-link-close"===d&&b.shiftKey&&(f.submit.focus(),b.preventDefault()):(f.close.focus(),b.preventDefault())),(b.keyCode===e.UP||b.keyCode===e.DOWN)&&(c=b.keyCode===e.UP?"prev":"next",clearInterval(wpLink.keyInterval),wpLink[c](),wpLink.keyInterval=setInterval(wpLink[c],wpLink.keySensitivity),b.preventDefault())},keyup:function(b){var c=a.ui.keyCode;(b.which===c.UP||b.which===c.DOWN)&&(clearInterval(wpLink.keyInterval),b.preventDefault())},delayedCallback:function(a,b){var c,d,e,f;return b?(setTimeout(function(){return d?a.apply(f,e):void(c=!0)},b),function(){return c?a.apply(this,arguments):(e=arguments,f=this,void(d=!0))}):a},toggleInternalLinking:function(){var a=f.wrap.hasClass("search-panel-visible");f.wrap.toggleClass("search-panel-visible",!a),setUserSetting("wplink",a?"0":"1"),f[a?"url":"search"].focus()}},d=function(b,c){var d=this;this.element=b,this.ul=b.children("ul"),this.contentHeight=b.children("#link-selector-height"),this.waiting=b.find(".river-waiting"),this.change(c),this.refresh(),a("#wp-link .query-results, #wp-link #link-selector").scroll(function(){d.maybeLoad()}),b.on("click","li",function(b){d.select(a(this),b)})},a.extend(d.prototype,{refresh:function(){this.deselect(),this.visible=this.element.is(":visible")},show:function(){this.visible||(this.deselect(),this.element.show(),this.visible=!0)},hide:function(){this.element.hide(),this.visible=!1},select:function(a,b){var c,d,e,f;a.hasClass("unselectable")||a==this.selected||(this.deselect(),this.selected=a.addClass("selected"),c=a.outerHeight(),d=this.element.height(),e=a.position().top,f=this.element.scrollTop(),0>e?this.element.scrollTop(f+e):e+c>d&&this.element.scrollTop(f+e-d+c),this.element.trigger("river-select",[a,b,this]))},deselect:function(){this.selected&&this.selected.removeClass("selected"),this.selected=!1},prev:function(){if(this.visible){var a;this.selected&&(a=this.selected.prev("li"),a.length&&this.select(a))}},next:function(){if(this.visible){var b=this.selected?this.selected.next("li"):a("li:not(.unselectable):first",this.element);b.length&&this.select(b)}},ajax:function(a){var b=this,c=1==this.query.page?0:wpLink.minRiverAJAXDuration,d=wpLink.delayedCallback(function(c,d){b.process(c,d),a&&a(c,d)},c);this.query.ajax(d)},change:function(a){this.query&&this._search==a||(this._search=a,this.query=new e(a),this.element.scrollTop(0))},process:function(b,c){var d="",e=!0,f="",g=1==c.page;b?a.each(b,function(){f=e?"alternate":"",f+=this.title?"":" no-title",d+=f?'<li class="'+f+'">':"<li>",d+='<input type="hidden" class="item-permalink" value="'+this.permalink+'" />',d+='<span class="item-title">',d+=this.title?this.title:wpLinkL10n.noTitle,d+='</span><span class="item-info">'+this.info+"</span></li>",e=!e}):g&&(d+='<li class="unselectable"><span class="item-title"><em>'+wpLinkL10n.noMatchesFound+"</em></span></li>"),this.ul[g?"html":"append"](d)},maybeLoad:function(){var a=this,b=this.element,c=b.scrollTop()+b.height();!this.query.ready()||c<this.contentHeight.height()-wpLink.riverBottomThreshold||setTimeout(function(){var c=b.scrollTop(),d=c+b.height();!a.query.ready()||d<a.contentHeight.height()-wpLink.riverBottomThreshold||(a.waiting.show(),b.scrollTop(c+a.waiting.outerHeight()),a.ajax(function(){a.waiting.hide()}))},wpLink.timeToTriggerRiver)}}),e=function(a){this.page=1,this.allLoaded=!1,this.querying=!1,this.search=a},a.extend(e.prototype,{ready:function(){return!(this.querying||this.allLoaded)},ajax:function(b){var c=this,d={action:"wp-link-ajax",page:this.page,_ajax_linking_nonce:f.nonce.val()};this.search&&(d.search=this.search),this.querying=!0,a.post(ajaxurl,d,function(a){c.page++,c.querying=!1,c.allLoaded=!a,b(a,d)},"json")}}),a(document).ready(wpLink.init)}(jQuery);
js/wplink.js CHANGED
@@ -2,7 +2,10 @@
2
  var wpLink;
3
 
4
  ( function( $ ) {
5
- var inputs = {}, rivers = {}, editor, searchTimer, River, Query;
 
 
 
6
 
7
  wpLink = {
8
  timeToTriggerRiver: 150,
@@ -31,6 +34,11 @@ var wpLink;
31
  rivers.recent = new River( $( '#most-recent-results' ) );
32
  rivers.elements = inputs.dialog.find( '.query-results' );
33
 
 
 
 
 
 
34
  // Bind event handlers
35
  inputs.dialog.keydown( wpLink.keydown );
36
  inputs.dialog.keyup( wpLink.keyup );
@@ -43,10 +51,19 @@ var wpLink;
43
  wpLink.close();
44
  });
45
 
46
- $( '#wp-link-search-toggle' ).click( wpLink.toggleInternalLinking );
47
 
48
  rivers.elements.on( 'river-select', wpLink.updateFields );
49
 
 
 
 
 
 
 
 
 
 
50
  inputs.search.keyup( function() {
51
  var self = this;
52
 
@@ -59,7 +76,7 @@ var wpLink;
59
 
60
  open: function( editorId ) {
61
  var ed;
62
-
63
  wpLink.range = null;
64
 
65
  if ( editorId ) {
@@ -95,6 +112,7 @@ var wpLink;
95
  inputs.backdrop.show();
96
 
97
  wpLink.refresh();
 
98
  },
99
 
100
  isMCE: function() {
@@ -106,18 +124,26 @@ var wpLink;
106
  rivers.search.refresh();
107
  rivers.recent.refresh();
108
 
109
- if ( wpLink.isMCE() )
110
  wpLink.mceRefresh();
111
- else
112
  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();
118
  // Load the most recent results if this is the first time opening the panel.
119
- if ( ! rivers.recent.ul.children().length )
120
  rivers.recent.ajax();
 
121
  },
122
 
123
  mceRefresh: function() {
@@ -153,6 +179,7 @@ var wpLink;
153
 
154
  inputs.backdrop.hide();
155
  inputs.wrap.hide();
 
156
  },
157
 
158
  getAttrs: function() {
@@ -260,17 +287,28 @@ var wpLink;
260
  editor.selection.collapse();
261
  },
262
 
263
- updateFields: function( e, li, originalEvent ) {
264
  inputs.url.val( li.children( '.item-permalink' ).val() );
265
  inputs.title.val( li.hasClass( 'no-title' ) ? '' : li.children( '.item-title' ).text() );
266
- if ( originalEvent && originalEvent.type == 'click' )
267
- inputs.url.focus();
268
  },
269
 
270
  setDefaultValues: function() {
271
- // Set URL and description to defaults.
272
- // Leave the new tab setting as-is.
273
- inputs.url.val( 'http://' );
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  inputs.title.val( '' );
275
 
276
  // Update save prompt.
@@ -322,6 +360,8 @@ var wpLink;
322
  } else if ( key.TAB === event.keyCode ) {
323
  id = event.target.id;
324
 
 
 
325
  if ( id === 'wp-link-submit' && ! event.shiftKey ) {
326
  inputs.close.focus();
327
  event.preventDefault();
@@ -335,6 +375,11 @@ var wpLink;
335
  return;
336
  }
337
 
 
 
 
 
 
338
  fn = event.keyCode === key.UP ? 'prev' : 'next';
339
  clearInterval( wpLink.keyInterval );
340
  wpLink[ fn ]();
@@ -374,12 +419,13 @@ var wpLink;
374
  };
375
  },
376
 
377
- toggleInternalLinking: function() {
378
  var visible = inputs.wrap.hasClass( 'search-panel-visible' );
379
 
380
  inputs.wrap.toggleClass( 'search-panel-visible', ! visible );
381
  setUserSetting( 'wplink', visible ? '0' : '1' );
382
  inputs[ ! visible ? 'search' : 'url' ].focus();
 
383
  }
384
  };
385
 
@@ -489,7 +535,7 @@ var wpLink;
489
 
490
  if ( ! results ) {
491
  if ( firstPage ) {
492
- list += '<li class="unselectable"><span class="item-title"><em>' +
493
  wpLinkL10n.noMatchesFound + '</em></span></li>';
494
  }
495
  } else {
2
  var wpLink;
3
 
4
  ( function( $ ) {
5
+ var editor, searchTimer, River, Query,
6
+ inputs = {},
7
+ rivers = {},
8
+ isTouch = ( 'ontouchend' in document );
9
 
10
  wpLink = {
11
  timeToTriggerRiver: 150,
34
  rivers.recent = new River( $( '#most-recent-results' ) );
35
  rivers.elements = inputs.dialog.find( '.query-results' );
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
+
42
  // Bind event handlers
43
  inputs.dialog.keydown( wpLink.keydown );
44
  inputs.dialog.keyup( wpLink.keyup );
51
  wpLink.close();
52
  });
53
 
54
+ $( '#wp-link-search-toggle' ).on( 'click', wpLink.toggleInternalLinking );
55
 
56
  rivers.elements.on( 'river-select', wpLink.updateFields );
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
+
67
  inputs.search.keyup( function() {
68
  var self = this;
69
 
76
 
77
  open: function( editorId ) {
78
  var ed;
79
+
80
  wpLink.range = null;
81
 
82
  if ( editorId ) {
112
  inputs.backdrop.show();
113
 
114
  wpLink.refresh();
115
+ $( document ).trigger( 'wplink-open', inputs.wrap );
116
  },
117
 
118
  isMCE: function() {
124
  rivers.search.refresh();
125
  rivers.recent.refresh();
126
 
127
+ if ( wpLink.isMCE() ) {
128
  wpLink.mceRefresh();
129
+ } else {
130
  wpLink.setDefaultValues();
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
 
 
 
 
 
143
  // Load the most recent results if this is the first time opening the panel.
144
+ if ( ! rivers.recent.ul.children().length ) {
145
  rivers.recent.ajax();
146
+ }
147
  },
148
 
149
  mceRefresh: function() {
179
 
180
  inputs.backdrop.hide();
181
  inputs.wrap.hide();
182
+ $( document ).trigger( 'wplink-close', inputs.wrap );
183
  },
184
 
185
  getAttrs: function() {
287
  editor.selection.collapse();
288
  },
289
 
290
+ updateFields: function( e, li ) {
291
  inputs.url.val( li.children( '.item-permalink' ).val() );
292
  inputs.title.val( li.hasClass( 'no-title' ) ? '' : li.children( '.item-title' ).text() );
 
 
293
  },
294
 
295
  setDefaultValues: function() {
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( /&amp;|&#0?38;/gi, '&' ) );
306
+ } else {
307
+ // Set URL to default.
308
+ inputs.url.val( 'http://' );
309
+ }
310
+
311
+ // Set description to default.
312
  inputs.title.val( '' );
313
 
314
  // Update save prompt.
360
  } else if ( key.TAB === event.keyCode ) {
361
  id = event.target.id;
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.
365
  if ( id === 'wp-link-submit' && ! event.shiftKey ) {
366
  inputs.close.focus();
367
  event.preventDefault();
375
  return;
376
  }
377
 
378
+ if ( document.activeElement &&
379
+ ( document.activeElement.id === 'link-title-field' || document.activeElement.id === 'url-field' ) ) {
380
+ return;
381
+ }
382
+
383
  fn = event.keyCode === key.UP ? 'prev' : 'next';
384
  clearInterval( wpLink.keyInterval );
385
  wpLink[ fn ]();
419
  };
420
  },
421
 
422
+ toggleInternalLinking: function( event ) {
423
  var visible = inputs.wrap.hasClass( 'search-panel-visible' );
424
 
425
  inputs.wrap.toggleClass( 'search-panel-visible', ! visible );
426
  setUserSetting( 'wplink', visible ? '0' : '1' );
427
  inputs[ ! visible ? 'search' : 'url' ].focus();
428
+ event.preventDefault();
429
  }
430
  };
431
 
535
 
536
  if ( ! results ) {
537
  if ( firstPage ) {
538
+ list += '<li class="unselectable no-matches-found"><span class="item-title"><em>' +
539
  wpLinkL10n.noMatchesFound + '</em></span></li>';
540
  }
541
  } else {
js/wplink.min.js CHANGED
@@ -1 +1 @@
1
- var wpLink;!function(a){var b,c,d,e,f={},g={};wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",init:function(){f.wrap=a("#wp-link-wrap"),f.dialog=a("#wp-link"),f.backdrop=a("#wp-link-backdrop"),f.submit=a("#wp-link-submit"),f.close=a("#wp-link-close"),f.url=a("#url-field"),f.nonce=a("#_ajax_linking_nonce"),f.title=a("#link-title-field"),f.openInNewTab=a("#link-target-checkbox"),f.search=a("#search-field"),g.search=new d(a("#search-results")),g.recent=new d(a("#most-recent-results")),g.elements=f.dialog.find(".query-results"),f.dialog.keydown(wpLink.keydown),f.dialog.keyup(wpLink.keyup),f.submit.click(function(a){a.preventDefault(),wpLink.update()}),f.close.add(f.backdrop).add("#wp-link-cancel a").click(function(a){a.preventDefault(),wpLink.close()}),a("#wp-link-search-toggle").click(wpLink.toggleInternalLinking),g.elements.on("river-select",wpLink.updateFields),f.search.keyup(function(){var a=this;window.clearTimeout(c),c=window.setTimeout(function(){wpLink.searchInternalLinks.call(a)},500)})},open:function(c){var d;wpLink.range=null,c&&(window.wpActiveEditor=c),window.wpActiveEditor&&(this.textarea=a("#"+window.wpActiveEditor).get(0),"undefined"!=typeof tinymce&&(d=tinymce.get(wpActiveEditor),b=d&&!d.isHidden()?d:null,b&&tinymce.isIE&&(b.windowManager.bookmark=b.selection.getBookmark())),!wpLink.isMCE()&&document.selection&&(this.textarea.focus(),this.range=document.selection.createRange()),f.wrap.show(),f.backdrop.show(),wpLink.refresh())},isMCE:function(){return b&&!b.isHidden()},refresh:function(){g.search.refresh(),g.recent.refresh(),wpLink.isMCE()?wpLink.mceRefresh():wpLink.setDefaultValues(),f.url.focus()[0].select(),g.recent.ul.children().length||g.recent.ajax()},mceRefresh:function(){var a;(a=b.dom.getParent(b.selection.getNode(),"A"))?(f.url.val(b.dom.getAttrib(a,"href")),f.title.val(b.dom.getAttrib(a,"title")),f.openInNewTab.prop("checked","_blank"===b.dom.getAttrib(a,"target")),f.submit.val(wpLinkL10n.update)):wpLink.setDefaultValues()},close:function(){wpLink.isMCE()?b.focus():(wpLink.textarea.focus(),wpLink.range&&(wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select())),f.backdrop.hide(),f.wrap.hide()},getAttrs:function(){return{href:f.url.val(),title:f.title.val(),target:f.openInNewTab.prop("checked")?"_blank":""}},update:function(){wpLink.isMCE()?wpLink.mceUpdate():wpLink.htmlUpdate()},htmlUpdate:function(){var a,b,c,d,e,f,g,h=wpLink.textarea;h&&(a=wpLink.getAttrs(),a.href&&"http://"!=a.href&&(b='<a href="'+a.href+'"',a.title&&(f=a.title.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),b+=' title="'+f+'"'),a.target&&(b+=' target="'+a.target+'"'),b+=">",document.selection&&wpLink.range?(h.focus(),wpLink.range.text=b+wpLink.range.text+"</a>",wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select(),wpLink.range=null):"undefined"!=typeof h.selectionStart&&(c=h.selectionStart,d=h.selectionEnd,g=h.value.substring(c,d),b=b+g+"</a>",e=c+b.length,c==d&&(e-="</a>".length),h.value=h.value.substring(0,c)+b+h.value.substring(d,h.value.length),h.selectionStart=h.selectionEnd=e),wpLink.close(),h.focus()))},mceUpdate:function(){var a,c=wpLink.getAttrs();return wpLink.close(),b.focus(),tinymce.isIE&&b.selection.moveToBookmark(b.windowManager.bookmark),a=b.dom.getParent(b.selection.getNode(),"a[href]"),c.href&&"http://"!=c.href?(a?b.dom.setAttribs(a,c):b.execCommand("mceInsertLink",!1,c),void b.selection.collapse()):void b.execCommand("unlink")},updateFields:function(a,b,c){f.url.val(b.children(".item-permalink").val()),f.title.val(b.hasClass("no-title")?"":b.children(".item-title").text()),c&&"click"==c.type&&f.url.focus()},setDefaultValues:function(){f.url.val("http://"),f.title.val(""),f.submit.val(wpLinkL10n.save)},searchInternalLinks:function(){var b,c=a(this),d=c.val();if(d.length>1){if(g.recent.hide(),g.search.show(),wpLink.lastSearch==d)return;wpLink.lastSearch=d,b=c.parent().find(".spinner").show(),g.search.change(d),g.search.ajax(function(){b.hide()})}else g.search.hide(),g.recent.show()},next:function(){g.search.next(),g.recent.next()},prev:function(){g.search.prev(),g.recent.prev()},keydown:function(b){var c,d,e=a.ui.keyCode;e.ESCAPE===b.keyCode?(wpLink.close(),b.stopImmediatePropagation()):e.TAB===b.keyCode&&(d=b.target.id,"wp-link-submit"!==d||b.shiftKey?"wp-link-close"===d&&b.shiftKey&&(f.submit.focus(),b.preventDefault()):(f.close.focus(),b.preventDefault())),(b.keyCode===e.UP||b.keyCode===e.DOWN)&&(c=b.keyCode===e.UP?"prev":"next",clearInterval(wpLink.keyInterval),wpLink[c](),wpLink.keyInterval=setInterval(wpLink[c],wpLink.keySensitivity),b.preventDefault())},keyup:function(b){var c=a.ui.keyCode;(b.which===c.UP||b.which===c.DOWN)&&(clearInterval(wpLink.keyInterval),b.preventDefault())},delayedCallback:function(a,b){var c,d,e,f;return b?(setTimeout(function(){return d?a.apply(f,e):void(c=!0)},b),function(){return c?a.apply(this,arguments):(e=arguments,f=this,void(d=!0))}):a},toggleInternalLinking:function(){var a=f.wrap.hasClass("search-panel-visible");f.wrap.toggleClass("search-panel-visible",!a),setUserSetting("wplink",a?"0":"1"),f[a?"url":"search"].focus()}},d=function(b,c){var d=this;this.element=b,this.ul=b.children("ul"),this.contentHeight=b.children("#link-selector-height"),this.waiting=b.find(".river-waiting"),this.change(c),this.refresh(),a("#wp-link .query-results, #wp-link #link-selector").scroll(function(){d.maybeLoad()}),b.on("click","li",function(b){d.select(a(this),b)})},a.extend(d.prototype,{refresh:function(){this.deselect(),this.visible=this.element.is(":visible")},show:function(){this.visible||(this.deselect(),this.element.show(),this.visible=!0)},hide:function(){this.element.hide(),this.visible=!1},select:function(a,b){var c,d,e,f;a.hasClass("unselectable")||a==this.selected||(this.deselect(),this.selected=a.addClass("selected"),c=a.outerHeight(),d=this.element.height(),e=a.position().top,f=this.element.scrollTop(),0>e?this.element.scrollTop(f+e):e+c>d&&this.element.scrollTop(f+e-d+c),this.element.trigger("river-select",[a,b,this]))},deselect:function(){this.selected&&this.selected.removeClass("selected"),this.selected=!1},prev:function(){if(this.visible){var a;this.selected&&(a=this.selected.prev("li"),a.length&&this.select(a))}},next:function(){if(this.visible){var b=this.selected?this.selected.next("li"):a("li:not(.unselectable):first",this.element);b.length&&this.select(b)}},ajax:function(a){var b=this,c=1==this.query.page?0:wpLink.minRiverAJAXDuration,d=wpLink.delayedCallback(function(c,d){b.process(c,d),a&&a(c,d)},c);this.query.ajax(d)},change:function(a){this.query&&this._search==a||(this._search=a,this.query=new e(a),this.element.scrollTop(0))},process:function(b,c){var d="",e=!0,f="",g=1==c.page;b?a.each(b,function(){f=e?"alternate":"",f+=this.title?"":" no-title",d+=f?'<li class="'+f+'">':"<li>",d+='<input type="hidden" class="item-permalink" value="'+this.permalink+'" />',d+='<span class="item-title">',d+=this.title?this.title:wpLinkL10n.noTitle,d+='</span><span class="item-info">'+this.info+"</span></li>",e=!e}):g&&(d+='<li class="unselectable"><span class="item-title"><em>'+wpLinkL10n.noMatchesFound+"</em></span></li>"),this.ul[g?"html":"append"](d)},maybeLoad:function(){var a=this,b=this.element,c=b.scrollTop()+b.height();!this.query.ready()||c<this.contentHeight.height()-wpLink.riverBottomThreshold||setTimeout(function(){var c=b.scrollTop(),d=c+b.height();!a.query.ready()||d<a.contentHeight.height()-wpLink.riverBottomThreshold||(a.waiting.show(),b.scrollTop(c+a.waiting.outerHeight()),a.ajax(function(){a.waiting.hide()}))},wpLink.timeToTriggerRiver)}}),e=function(a){this.page=1,this.allLoaded=!1,this.querying=!1,this.search=a},a.extend(e.prototype,{ready:function(){return!(this.querying||this.allLoaded)},ajax:function(b){var c=this,d={action:"wp-link-ajax",page:this.page,_ajax_linking_nonce:f.nonce.val()};this.search&&(d.search=this.search),this.querying=!0,a.post(ajaxurl,d,function(a){c.page++,c.querying=!1,c.allLoaded=!a,b(a,d)},"json")}}),a(document).ready(wpLink.init)}(jQuery);
1
+ var wpLink;!function(a){var b,c,d,e,f={},g={},h="ontouchend"in document;wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",init:function(){f.wrap=a("#wp-link-wrap"),f.dialog=a("#wp-link"),f.backdrop=a("#wp-link-backdrop"),f.submit=a("#wp-link-submit"),f.close=a("#wp-link-close"),f.url=a("#url-field"),f.nonce=a("#_ajax_linking_nonce"),f.title=a("#link-title-field"),f.openInNewTab=a("#link-target-checkbox"),f.search=a("#search-field"),g.search=new d(a("#search-results")),g.recent=new d(a("#most-recent-results")),g.elements=f.dialog.find(".query-results"),f.queryNotice=a("#query-notice-message"),f.queryNoticeTextDefault=f.queryNotice.find(".query-notice-default"),f.queryNoticeTextHint=f.queryNotice.find(".query-notice-hint"),f.dialog.keydown(wpLink.keydown),f.dialog.keyup(wpLink.keyup),f.submit.click(function(a){a.preventDefault(),wpLink.update()}),f.close.add(f.backdrop).add("#wp-link-cancel a").click(function(a){a.preventDefault(),wpLink.close()}),a("#wp-link-search-toggle").on("click",wpLink.toggleInternalLinking),g.elements.on("river-select",wpLink.updateFields),f.search.on("focus.wplink",function(){f.queryNoticeTextDefault.hide(),f.queryNoticeTextHint.removeClass("screen-reader-text").show()}).on("blur.wplink",function(){f.queryNoticeTextDefault.show(),f.queryNoticeTextHint.addClass("screen-reader-text").hide()}),f.search.keyup(function(){var a=this;window.clearTimeout(c),c=window.setTimeout(function(){wpLink.searchInternalLinks.call(a)},500)})},open:function(c){var d;wpLink.range=null,c&&(window.wpActiveEditor=c),window.wpActiveEditor&&(this.textarea=a("#"+window.wpActiveEditor).get(0),"undefined"!=typeof tinymce&&(d=tinymce.get(wpActiveEditor),b=d&&!d.isHidden()?d:null,b&&tinymce.isIE&&(b.windowManager.bookmark=b.selection.getBookmark())),!wpLink.isMCE()&&document.selection&&(this.textarea.focus(),this.range=document.selection.createRange()),f.wrap.show(),f.backdrop.show(),wpLink.refresh(),a(document).trigger("wplink-open",f.wrap))},isMCE:function(){return b&&!b.isHidden()},refresh:function(){g.search.refresh(),g.recent.refresh(),wpLink.isMCE()?wpLink.mceRefresh():wpLink.setDefaultValues(),h?f.url.focus().blur():f.url.focus()[0].select(),g.recent.ul.children().length||g.recent.ajax()},mceRefresh:function(){var a;(a=b.dom.getParent(b.selection.getNode(),"A"))?(f.url.val(b.dom.getAttrib(a,"href")),f.title.val(b.dom.getAttrib(a,"title")),f.openInNewTab.prop("checked","_blank"===b.dom.getAttrib(a,"target")),f.submit.val(wpLinkL10n.update)):wpLink.setDefaultValues()},close:function(){wpLink.isMCE()?b.focus():(wpLink.textarea.focus(),wpLink.range&&(wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select())),f.backdrop.hide(),f.wrap.hide(),a(document).trigger("wplink-close",f.wrap)},getAttrs:function(){return{href:f.url.val(),title:f.title.val(),target:f.openInNewTab.prop("checked")?"_blank":""}},update:function(){wpLink.isMCE()?wpLink.mceUpdate():wpLink.htmlUpdate()},htmlUpdate:function(){var a,b,c,d,e,f,g,h=wpLink.textarea;h&&(a=wpLink.getAttrs(),a.href&&"http://"!=a.href&&(b='<a href="'+a.href+'"',a.title&&(f=a.title.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),b+=' title="'+f+'"'),a.target&&(b+=' target="'+a.target+'"'),b+=">",document.selection&&wpLink.range?(h.focus(),wpLink.range.text=b+wpLink.range.text+"</a>",wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select(),wpLink.range=null):"undefined"!=typeof h.selectionStart&&(c=h.selectionStart,d=h.selectionEnd,g=h.value.substring(c,d),b=b+g+"</a>",e=c+b.length,c==d&&(e-="</a>".length),h.value=h.value.substring(0,c)+b+h.value.substring(d,h.value.length),h.selectionStart=h.selectionEnd=e),wpLink.close(),h.focus()))},mceUpdate:function(){var a,c=wpLink.getAttrs();return wpLink.close(),b.focus(),tinymce.isIE&&b.selection.moveToBookmark(b.windowManager.bookmark),a=b.dom.getParent(b.selection.getNode(),"a[href]"),c.href&&"http://"!=c.href?(a?b.dom.setAttribs(a,c):b.execCommand("mceInsertLink",!1,c),void b.selection.collapse()):void b.execCommand("unlink")},updateFields:function(a,b){f.url.val(b.children(".item-permalink").val()),f.title.val(b.hasClass("no-title")?"":b.children(".item-title").text())},setDefaultValues:function(){var a=b&&b.selection.getContent(),c=/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,d=/^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i;f.url.val(a&&c.test(a)?"mailto:"+a:a&&d.test(a)?a.replace(/&amp;|&#0?38;/gi,"&"):"http://"),f.title.val(""),f.submit.val(wpLinkL10n.save)},searchInternalLinks:function(){var b,c=a(this),d=c.val();if(d.length>1){if(g.recent.hide(),g.search.show(),wpLink.lastSearch==d)return;wpLink.lastSearch=d,b=c.parent().find(".spinner").show(),g.search.change(d),g.search.ajax(function(){b.hide()})}else g.search.hide(),g.recent.show()},next:function(){g.search.next(),g.recent.next()},prev:function(){g.search.prev(),g.recent.prev()},keydown:function(b){var c,d,e=a.ui.keyCode;e.ESCAPE===b.keyCode?(wpLink.close(),b.stopImmediatePropagation()):e.TAB===b.keyCode&&(d=b.target.id,"wp-link-submit"!==d||b.shiftKey?"wp-link-close"===d&&b.shiftKey&&(f.submit.focus(),b.preventDefault()):(f.close.focus(),b.preventDefault())),(b.keyCode===e.UP||b.keyCode===e.DOWN)&&(!document.activeElement||"link-title-field"!==document.activeElement.id&&"url-field"!==document.activeElement.id)&&(c=b.keyCode===e.UP?"prev":"next",clearInterval(wpLink.keyInterval),wpLink[c](),wpLink.keyInterval=setInterval(wpLink[c],wpLink.keySensitivity),b.preventDefault())},keyup:function(b){var c=a.ui.keyCode;(b.which===c.UP||b.which===c.DOWN)&&(clearInterval(wpLink.keyInterval),b.preventDefault())},delayedCallback:function(a,b){var c,d,e,f;return b?(setTimeout(function(){return d?a.apply(f,e):void(c=!0)},b),function(){return c?a.apply(this,arguments):(e=arguments,f=this,void(d=!0))}):a},toggleInternalLinking:function(a){var b=f.wrap.hasClass("search-panel-visible");f.wrap.toggleClass("search-panel-visible",!b),setUserSetting("wplink",b?"0":"1"),f[b?"url":"search"].focus(),a.preventDefault()}},d=function(b,c){var d=this;this.element=b,this.ul=b.children("ul"),this.contentHeight=b.children("#link-selector-height"),this.waiting=b.find(".river-waiting"),this.change(c),this.refresh(),a("#wp-link .query-results, #wp-link #link-selector").scroll(function(){d.maybeLoad()}),b.on("click","li",function(b){d.select(a(this),b)})},a.extend(d.prototype,{refresh:function(){this.deselect(),this.visible=this.element.is(":visible")},show:function(){this.visible||(this.deselect(),this.element.show(),this.visible=!0)},hide:function(){this.element.hide(),this.visible=!1},select:function(a,b){var c,d,e,f;a.hasClass("unselectable")||a==this.selected||(this.deselect(),this.selected=a.addClass("selected"),c=a.outerHeight(),d=this.element.height(),e=a.position().top,f=this.element.scrollTop(),0>e?this.element.scrollTop(f+e):e+c>d&&this.element.scrollTop(f+e-d+c),this.element.trigger("river-select",[a,b,this]))},deselect:function(){this.selected&&this.selected.removeClass("selected"),this.selected=!1},prev:function(){if(this.visible){var a;this.selected&&(a=this.selected.prev("li"),a.length&&this.select(a))}},next:function(){if(this.visible){var b=this.selected?this.selected.next("li"):a("li:not(.unselectable):first",this.element);b.length&&this.select(b)}},ajax:function(a){var b=this,c=1==this.query.page?0:wpLink.minRiverAJAXDuration,d=wpLink.delayedCallback(function(c,d){b.process(c,d),a&&a(c,d)},c);this.query.ajax(d)},change:function(a){this.query&&this._search==a||(this._search=a,this.query=new e(a),this.element.scrollTop(0))},process:function(b,c){var d="",e=!0,f="",g=1==c.page;b?a.each(b,function(){f=e?"alternate":"",f+=this.title?"":" no-title",d+=f?'<li class="'+f+'">':"<li>",d+='<input type="hidden" class="item-permalink" value="'+this.permalink+'" />',d+='<span class="item-title">',d+=this.title?this.title:wpLinkL10n.noTitle,d+='</span><span class="item-info">'+this.info+"</span></li>",e=!e}):g&&(d+='<li class="unselectable no-matches-found"><span class="item-title"><em>'+wpLinkL10n.noMatchesFound+"</em></span></li>"),this.ul[g?"html":"append"](d)},maybeLoad:function(){var a=this,b=this.element,c=b.scrollTop()+b.height();!this.query.ready()||c<this.contentHeight.height()-wpLink.riverBottomThreshold||setTimeout(function(){var c=b.scrollTop(),d=c+b.height();!a.query.ready()||d<a.contentHeight.height()-wpLink.riverBottomThreshold||(a.waiting.show(),b.scrollTop(c+a.waiting.outerHeight()),a.ajax(function(){a.waiting.hide()}))},wpLink.timeToTriggerRiver)}}),e=function(a){this.page=1,this.allLoaded=!1,this.querying=!1,this.search=a},a.extend(e.prototype,{ready:function(){return!(this.querying||this.allLoaded)},ajax:function(b){var c=this,d={action:"wp-link-ajax",page:this.page,_ajax_linking_nonce:f.nonce.val()};this.search&&(d.search=this.search),this.querying=!0,a.post(ajaxurl,d,function(a){c.page++,c.querying=!1,c.allLoaded=!a,b(a,d)},"json")}}),a(document).ready(wpLink.init)}(jQuery);
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: tenpura
3
  Tags: multibyte,i18n,wp-multibyte-patch,Japanese
4
  Requires at least: 3.9-RC1
5
- Tested up to: 3.9
6
- Stable tag: 2.0
7
 
8
  Multibyte functionality enhancement for the WordPress Japanese package.
9
 
2
  Contributors: tenpura
3
  Tags: multibyte,i18n,wp-multibyte-patch,Japanese
4
  Requires at least: 3.9-RC1
5
+ Tested up to: 4.0
6
+ Stable tag: 2.1.1
7
 
8
  Multibyte functionality enhancement for the WordPress Japanese package.
9
 
wp-multibyte-patch.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: WP Multibyte Patch
4
  Description: Multibyte functionality enhancement for the WordPress Japanese package.
5
- Version: 2.0
6
  Plugin URI: http://eastcoder.com/code/wp-multibyte-patch/
7
  Author: Seisuke Kuraishi
8
  Author URI: http://tinybit.co.jp/
@@ -15,7 +15,7 @@ Domain Path: /languages
15
  * Multibyte functionality enhancement for the WordPress Japanese package.
16
  *
17
  * @package WP_Multibyte_Patch
18
- * @version 2.0
19
  * @author Seisuke Kuraishi <210pura@gmail.com>
20
  * @copyright Copyright (c) 2014 Seisuke Kuraishi, Tinybit Inc.
21
  * @license http://opensource.org/licenses/gpl-2.0.php GPLv2
@@ -270,7 +270,13 @@ class multibyte_patch {
270
  }
271
 
272
  function wplink_js( &$scripts ) {
273
- $scripts->add( 'wplink', plugin_dir_url( __FILE__ ) . "js/wplink{$this->debug_suffix}.js", array( 'jquery' ), '20140410', 1 );
 
 
 
 
 
 
274
  }
275
 
276
  function word_count_js( &$scripts ) {
2
  /*
3
  Plugin Name: WP Multibyte Patch
4
  Description: Multibyte functionality enhancement for the WordPress Japanese package.
5
+ Version: 2.1.1
6
  Plugin URI: http://eastcoder.com/code/wp-multibyte-patch/
7
  Author: Seisuke Kuraishi
8
  Author URI: http://tinybit.co.jp/
15
  * Multibyte functionality enhancement for the WordPress Japanese package.
16
  *
17
  * @package WP_Multibyte_Patch
18
+ * @version 2.1.1
19
  * @author Seisuke Kuraishi <210pura@gmail.com>
20
  * @copyright Copyright (c) 2014 Seisuke Kuraishi, Tinybit Inc.
21
  * @license http://opensource.org/licenses/gpl-2.0.php GPLv2
270
  }
271
 
272
  function wplink_js( &$scripts ) {
273
+ global $wp_version;
274
+ $script_required_version = '4.0-beta4';
275
+
276
+ if ( version_compare( substr( $wp_version, 0, strlen( $script_required_version ) ), $script_required_version, '<' ) )
277
+ $scripts->add( 'wplink', plugin_dir_url( __FILE__ ) . "js/20140410/wplink{$this->debug_suffix}.js", array( 'jquery' ), '20140410', 1 );
278
+ else
279
+ $scripts->add( 'wplink', plugin_dir_url( __FILE__ ) . "js/wplink{$this->debug_suffix}.js", array( 'jquery' ), '20140817', 1 );
280
  }
281
 
282
  function word_count_js( &$scripts ) {