WP Multibyte Patch - Version 2.6

Version Description

Download this release

Release Info

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

Code changes from version 2.5 to 2.6

ext/ja/class.php CHANGED
@@ -3,9 +3,9 @@
3
  * WP Multibyte Patch Japanese Locale Extension
4
  *
5
  * @package WP_Multibyte_Patch
6
- * @version 2.5
7
  * @author Seisuke Kuraishi <210pura@gmail.com>
8
- * @copyright Copyright (c) 2015 Seisuke Kuraishi, Tinybit Inc.
9
  * @license http://opensource.org/licenses/gpl-2.0.php GPLv2
10
  * @link http://eastcoder.com/code/wp-multibyte-patch/
11
  */
3
  * WP Multibyte Patch Japanese Locale Extension
4
  *
5
  * @package WP_Multibyte_Patch
6
+ * @version 2.6
7
  * @author Seisuke Kuraishi <210pura@gmail.com>
8
+ * @copyright Copyright (c) 2016 Seisuke Kuraishi, Tinybit Inc.
9
  * @license http://opensource.org/licenses/gpl-2.0.php GPLv2
10
  * @link http://eastcoder.com/code/wp-multibyte-patch/
11
  */
js/20150818/wplink.min.js DELETED
@@ -1 +0,0 @@
1
- var wpLink;!function(a){function b(){return c.dom.getParent(c.selection.getNode(),"a")}var c,d,e,f,g,h={},i={},j="ontouchend"in document;wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",init:function(){h.wrap=a("#wp-link-wrap"),h.dialog=a("#wp-link"),h.backdrop=a("#wp-link-backdrop"),h.submit=a("#wp-link-submit"),h.close=a("#wp-link-close"),h.text=a("#wp-link-text"),h.url=a("#wp-link-url"),h.nonce=a("#_ajax_linking_nonce"),h.openInNewTab=a("#wp-link-target"),h.search=a("#wp-link-search"),i.search=new e(a("#search-results")),i.recent=new e(a("#most-recent-results")),i.elements=h.dialog.find(".query-results"),h.queryNotice=a("#query-notice-message"),h.queryNoticeTextDefault=h.queryNotice.find(".query-notice-default"),h.queryNoticeTextHint=h.queryNotice.find(".query-notice-hint"),h.dialog.keydown(wpLink.keydown),h.dialog.keyup(wpLink.keyup),h.submit.click(function(a){a.preventDefault(),wpLink.update()}),h.close.add(h.backdrop).add("#wp-link-cancel a").click(function(a){a.preventDefault(),wpLink.close()}),a("#wp-link-search-toggle").on("click",wpLink.toggleInternalLinking),i.elements.on("river-select",wpLink.updateFields),h.search.on("focus.wplink",function(){h.queryNoticeTextDefault.hide(),h.queryNoticeTextHint.removeClass("screen-reader-text").show()}).on("blur.wplink",function(){h.queryNoticeTextDefault.show(),h.queryNoticeTextHint.addClass("screen-reader-text").hide()}),h.search.on("keyup input",function(){var a=this;window.clearTimeout(d),d=window.setTimeout(function(){wpLink.searchInternalLinks.call(a)},500)}),h.url.on("paste",function(){setTimeout(wpLink.correctURL,0)}),h.url.on("blur",wpLink.correctURL)},correctURL:function(){var b=a.trim(h.url.val());b&&g!==b&&!/^(?:[a-z]+:|#|\?|\.|\/)/.test(b)&&(h.url.val("http://"+b),g=b)},open:function(b){var d,e=a(document.body);e.addClass("modal-open"),wpLink.range=null,b&&(window.wpActiveEditor=b),window.wpActiveEditor&&(this.textarea=a("#"+window.wpActiveEditor).get(0),"undefined"!=typeof tinymce&&(e.append(h.backdrop,h.wrap),d=tinymce.get(wpActiveEditor),c=d&&!d.isHidden()?d:null,c&&tinymce.isIE&&(c.windowManager.bookmark=c.selection.getBookmark())),!wpLink.isMCE()&&document.selection&&(this.textarea.focus(),this.range=document.selection.createRange()),h.wrap.show(),h.backdrop.show(),wpLink.refresh(),a(document).trigger("wplink-open",h.wrap))},isMCE:function(){return c&&!c.isHidden()},refresh:function(){var a="";i.search.refresh(),i.recent.refresh(),wpLink.isMCE()?wpLink.mceRefresh():(h.wrap.hasClass("has-text-field")||h.wrap.addClass("has-text-field"),document.selection?a=document.selection.createRange().text||"":"undefined"!=typeof this.textarea.selectionStart&&this.textarea.selectionStart!==this.textarea.selectionEnd&&(a=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd)||""),h.text.val(a),wpLink.setDefaultValues()),j?h.url.focus().blur():h.url.focus()[0].select(),i.recent.ul.children().length||i.recent.ajax(),g=h.url.val().replace(/^http:\/\//,"")},hasSelectedText:function(a){var b=c.selection.getContent();if(/</.test(b)&&(!/^<a [^>]+>[^<]+<\/a>$/.test(b)||-1===b.indexOf("href=")))return!1;if(a){var d,e=a.childNodes;if(0===e.length)return!1;for(d=e.length-1;d>=0;d--)if(3!=e[d].nodeType)return!1}return!0},mceRefresh:function(){var a,b=c.selection.getNode(),d=c.dom.getParent(b,"a[href]"),e=this.hasSelectedText(d);d?(a=d.innerText||d.textContent,h.url.val(c.dom.getAttrib(d,"href")),h.openInNewTab.prop("checked","_blank"===c.dom.getAttrib(d,"target")),h.submit.val(wpLinkL10n.update)):(a=c.selection.getContent({format:"text"}),this.setDefaultValues()),e?(h.text.val(a||""),h.wrap.addClass("has-text-field")):(h.text.val(""),h.wrap.removeClass("has-text-field"))},close:function(){a(document.body).removeClass("modal-open"),wpLink.isMCE()?c.focus():(wpLink.textarea.focus(),wpLink.range&&(wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select())),h.backdrop.hide(),h.wrap.hide(),g=!1,a(document).trigger("wplink-close",h.wrap)},getAttrs:function(){return wpLink.correctURL(),{href:a.trim(h.url.val()),target:h.openInNewTab.prop("checked")?"_blank":""}},buildHtml:function(a){var b='<a href="'+a.href+'"';return a.target&&(b+=' target="'+a.target+'"'),b+">"},update:function(){wpLink.isMCE()?wpLink.mceUpdate():wpLink.htmlUpdate()},htmlUpdate:function(){var a,b,c,d,e,f,g,i=wpLink.textarea;i&&(a=wpLink.getAttrs(),b=h.text.val(),a.href&&(c=wpLink.buildHtml(a),document.selection&&wpLink.range?(i.focus(),wpLink.range.text=c+(b||wpLink.range.text)+"</a>",wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select(),wpLink.range=null):"undefined"!=typeof i.selectionStart&&(d=i.selectionStart,e=i.selectionEnd,g=b||i.value.substring(d,e),c=c+g+"</a>",f=d+c.length,d!==e||g||(f-=4),i.value=i.value.substring(0,d)+c+i.value.substring(e,i.value.length),i.selectionStart=i.selectionEnd=f),wpLink.close(),i.focus()))},mceUpdate:function(){var a,d,e=wpLink.getAttrs();return wpLink.close(),c.focus(),tinymce.isIE&&c.selection.moveToBookmark(c.windowManager.bookmark),e.href?(a=b(),h.wrap.hasClass("has-text-field")&&(d=h.text.val()||e.href),a?(d&&("innerText"in a?a.innerText=d:a.textContent=d),c.dom.setAttribs(a,e)):d?c.selection.setNode(c.dom.create("a",e,d)):c.execCommand("mceInsertLink",!1,e),void c.nodeChanged()):void c.execCommand("unlink")},updateFields:function(a,b){h.url.val(b.children(".item-permalink").val())},setDefaultValues:function(){var a,b=/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,d=/^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i;this.isMCE()?a=c.selection.getContent():document.selection&&wpLink.range?a=wpLink.range.text:"undefined"!=typeof this.textarea.selectionStart&&(a=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd)),a&&b.test(a)?h.url.val("mailto:"+a):a&&d.test(a)?h.url.val(a.replace(/&amp;|&#0?38;/gi,"&")):h.url.val(""),h.submit.val(wpLinkL10n.save)},searchInternalLinks:function(){var b,c=a(this),d=c.val();if(d.length>1){if(i.recent.hide(),i.search.show(),wpLink.lastSearch==d)return;wpLink.lastSearch=d,b=c.parent().find(".spinner").addClass("is-active"),i.search.change(d),i.search.ajax(function(){b.removeClass("is-active")})}else i.search.hide(),i.recent.show()},next:function(){i.search.next(),i.recent.next()},prev:function(){i.search.prev(),i.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&&(h.submit.focus(),b.preventDefault()):(h.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=h.wrap.hasClass("search-panel-visible");h.wrap.toggleClass("search-panel-visible",!b),setUserSetting("wplink",b?"0":"1"),h[b?"url":"search"].focus(),a.preventDefault()}},e=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(e.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 f(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.addClass("is-active"),b.scrollTop(c+a.waiting.outerHeight()),a.ajax(function(){a.waiting.removeClass("is-active")}))},wpLink.timeToTriggerRiver)}}),f=function(a){this.page=1,this.allLoaded=!1,this.querying=!1,this.search=a},a.extend(f.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:h.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/{20150818 → 20151207}/wplink.js RENAMED
@@ -382,7 +382,7 @@ var wpLink;
382
  editor.dom.setAttribs( link, attrs );
383
  } else {
384
  if ( text ) {
385
- editor.selection.setNode( editor.dom.create( 'a', attrs, text ) );
386
  } else {
387
  editor.execCommand( 'mceInsertLink', false, attrs );
388
  }
@@ -459,13 +459,14 @@ var wpLink;
459
  },
460
 
461
  keydown: function( event ) {
462
- var fn, id,
463
- key = $.ui.keyCode;
464
 
465
- if ( key.ESCAPE === event.keyCode ) {
 
466
  wpLink.close();
467
  event.stopImmediatePropagation();
468
- } else if ( key.TAB === event.keyCode ) {
 
469
  id = event.target.id;
470
 
471
  // wp-link-submit must always be the last focusable element in the dialog.
@@ -479,7 +480,8 @@ var wpLink;
479
  }
480
  }
481
 
482
- if ( event.keyCode !== key.UP && event.keyCode !== key.DOWN ) {
 
483
  return;
484
  }
485
 
@@ -488,7 +490,8 @@ var wpLink;
488
  return;
489
  }
490
 
491
- fn = event.keyCode === key.UP ? 'prev' : 'next';
 
492
  clearInterval( wpLink.keyInterval );
493
  wpLink[ fn ]();
494
  wpLink.keyInterval = setInterval( wpLink[ fn ], wpLink.keySensitivity );
@@ -496,9 +499,8 @@ var wpLink;
496
  },
497
 
498
  keyup: function( event ) {
499
- var key = $.ui.keyCode;
500
-
501
- if ( event.which === key.UP || event.which === key.DOWN ) {
502
  clearInterval( wpLink.keyInterval );
503
  event.preventDefault();
504
  }
382
  editor.dom.setAttribs( link, attrs );
383
  } else {
384
  if ( text ) {
385
+ editor.selection.setNode( editor.dom.create( 'a', attrs, editor.dom.encode( text ) ) );
386
  } else {
387
  editor.execCommand( 'mceInsertLink', false, attrs );
388
  }
459
  },
460
 
461
  keydown: function( event ) {
462
+ var fn, id;
 
463
 
464
+ // Escape key.
465
+ if ( 27 === event.keyCode ) {
466
  wpLink.close();
467
  event.stopImmediatePropagation();
468
+ // Tab key.
469
+ } else if ( 9 === event.keyCode ) {
470
  id = event.target.id;
471
 
472
  // wp-link-submit must always be the last focusable element in the dialog.
480
  }
481
  }
482
 
483
+ // Up Arrow and Down Arrow keys.
484
+ if ( 38 !== event.keyCode && 40 !== event.keyCode ) {
485
  return;
486
  }
487
 
490
  return;
491
  }
492
 
493
+ // Up Arrow key.
494
+ fn = 38 === event.keyCode ? 'prev' : 'next';
495
  clearInterval( wpLink.keyInterval );
496
  wpLink[ fn ]();
497
  wpLink.keyInterval = setInterval( wpLink[ fn ], wpLink.keySensitivity );
499
  },
500
 
501
  keyup: function( event ) {
502
+ // Up Arrow and Down Arrow keys.
503
+ if ( 38 === event.keyCode || 40 === event.keyCode ) {
 
504
  clearInterval( wpLink.keyInterval );
505
  event.preventDefault();
506
  }
js/20151207/wplink.min.js ADDED
@@ -0,0 +1 @@
 
1
+ var wpLink;!function(a){function b(){return c.dom.getParent(c.selection.getNode(),"a")}var c,d,e,f,g,h={},i={},j="ontouchend"in document;wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",init:function(){h.wrap=a("#wp-link-wrap"),h.dialog=a("#wp-link"),h.backdrop=a("#wp-link-backdrop"),h.submit=a("#wp-link-submit"),h.close=a("#wp-link-close"),h.text=a("#wp-link-text"),h.url=a("#wp-link-url"),h.nonce=a("#_ajax_linking_nonce"),h.openInNewTab=a("#wp-link-target"),h.search=a("#wp-link-search"),i.search=new e(a("#search-results")),i.recent=new e(a("#most-recent-results")),i.elements=h.dialog.find(".query-results"),h.queryNotice=a("#query-notice-message"),h.queryNoticeTextDefault=h.queryNotice.find(".query-notice-default"),h.queryNoticeTextHint=h.queryNotice.find(".query-notice-hint"),h.dialog.keydown(wpLink.keydown),h.dialog.keyup(wpLink.keyup),h.submit.click(function(a){a.preventDefault(),wpLink.update()}),h.close.add(h.backdrop).add("#wp-link-cancel a").click(function(a){a.preventDefault(),wpLink.close()}),a("#wp-link-search-toggle").on("click",wpLink.toggleInternalLinking),i.elements.on("river-select",wpLink.updateFields),h.search.on("focus.wplink",function(){h.queryNoticeTextDefault.hide(),h.queryNoticeTextHint.removeClass("screen-reader-text").show()}).on("blur.wplink",function(){h.queryNoticeTextDefault.show(),h.queryNoticeTextHint.addClass("screen-reader-text").hide()}),h.search.on("keyup input",function(){var a=this;window.clearTimeout(d),d=window.setTimeout(function(){wpLink.searchInternalLinks.call(a)},500)}),h.url.on("paste",function(){setTimeout(wpLink.correctURL,0)}),h.url.on("blur",wpLink.correctURL)},correctURL:function(){var b=a.trim(h.url.val());b&&g!==b&&!/^(?:[a-z]+:|#|\?|\.|\/)/.test(b)&&(h.url.val("http://"+b),g=b)},open:function(b){var d,e=a(document.body);e.addClass("modal-open"),wpLink.range=null,b&&(window.wpActiveEditor=b),window.wpActiveEditor&&(this.textarea=a("#"+window.wpActiveEditor).get(0),"undefined"!=typeof tinymce&&(e.append(h.backdrop,h.wrap),d=tinymce.get(wpActiveEditor),c=d&&!d.isHidden()?d:null,c&&tinymce.isIE&&(c.windowManager.bookmark=c.selection.getBookmark())),!wpLink.isMCE()&&document.selection&&(this.textarea.focus(),this.range=document.selection.createRange()),h.wrap.show(),h.backdrop.show(),wpLink.refresh(),a(document).trigger("wplink-open",h.wrap))},isMCE:function(){return c&&!c.isHidden()},refresh:function(){var a="";i.search.refresh(),i.recent.refresh(),wpLink.isMCE()?wpLink.mceRefresh():(h.wrap.hasClass("has-text-field")||h.wrap.addClass("has-text-field"),document.selection?a=document.selection.createRange().text||"":"undefined"!=typeof this.textarea.selectionStart&&this.textarea.selectionStart!==this.textarea.selectionEnd&&(a=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd)||""),h.text.val(a),wpLink.setDefaultValues()),j?h.url.focus().blur():h.url.focus()[0].select(),i.recent.ul.children().length||i.recent.ajax(),g=h.url.val().replace(/^http:\/\//,"")},hasSelectedText:function(a){var b=c.selection.getContent();if(/</.test(b)&&(!/^<a [^>]+>[^<]+<\/a>$/.test(b)||-1===b.indexOf("href=")))return!1;if(a){var d,e=a.childNodes;if(0===e.length)return!1;for(d=e.length-1;d>=0;d--)if(3!=e[d].nodeType)return!1}return!0},mceRefresh:function(){var a,b=c.selection.getNode(),d=c.dom.getParent(b,"a[href]"),e=this.hasSelectedText(d);d?(a=d.innerText||d.textContent,h.url.val(c.dom.getAttrib(d,"href")),h.openInNewTab.prop("checked","_blank"===c.dom.getAttrib(d,"target")),h.submit.val(wpLinkL10n.update)):(a=c.selection.getContent({format:"text"}),this.setDefaultValues()),e?(h.text.val(a||""),h.wrap.addClass("has-text-field")):(h.text.val(""),h.wrap.removeClass("has-text-field"))},close:function(){a(document.body).removeClass("modal-open"),wpLink.isMCE()?c.focus():(wpLink.textarea.focus(),wpLink.range&&(wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select())),h.backdrop.hide(),h.wrap.hide(),g=!1,a(document).trigger("wplink-close",h.wrap)},getAttrs:function(){return wpLink.correctURL(),{href:a.trim(h.url.val()),target:h.openInNewTab.prop("checked")?"_blank":""}},buildHtml:function(a){var b='<a href="'+a.href+'"';return a.target&&(b+=' target="'+a.target+'"'),b+">"},update:function(){wpLink.isMCE()?wpLink.mceUpdate():wpLink.htmlUpdate()},htmlUpdate:function(){var a,b,c,d,e,f,g,i=wpLink.textarea;i&&(a=wpLink.getAttrs(),b=h.text.val(),a.href&&(c=wpLink.buildHtml(a),document.selection&&wpLink.range?(i.focus(),wpLink.range.text=c+(b||wpLink.range.text)+"</a>",wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select(),wpLink.range=null):"undefined"!=typeof i.selectionStart&&(d=i.selectionStart,e=i.selectionEnd,g=b||i.value.substring(d,e),c=c+g+"</a>",f=d+c.length,d!==e||g||(f-=4),i.value=i.value.substring(0,d)+c+i.value.substring(e,i.value.length),i.selectionStart=i.selectionEnd=f),wpLink.close(),i.focus()))},mceUpdate:function(){var a,d,e=wpLink.getAttrs();return wpLink.close(),c.focus(),tinymce.isIE&&c.selection.moveToBookmark(c.windowManager.bookmark),e.href?(a=b(),h.wrap.hasClass("has-text-field")&&(d=h.text.val()||e.href),a?(d&&("innerText"in a?a.innerText=d:a.textContent=d),c.dom.setAttribs(a,e)):d?c.selection.setNode(c.dom.create("a",e,c.dom.encode(d))):c.execCommand("mceInsertLink",!1,e),void c.nodeChanged()):void c.execCommand("unlink")},updateFields:function(a,b){h.url.val(b.children(".item-permalink").val())},setDefaultValues:function(){var a,b=/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,d=/^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i;this.isMCE()?a=c.selection.getContent():document.selection&&wpLink.range?a=wpLink.range.text:"undefined"!=typeof this.textarea.selectionStart&&(a=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd)),a&&b.test(a)?h.url.val("mailto:"+a):a&&d.test(a)?h.url.val(a.replace(/&amp;|&#0?38;/gi,"&")):h.url.val(""),h.submit.val(wpLinkL10n.save)},searchInternalLinks:function(){var b,c=a(this),d=c.val();if(d.length>1){if(i.recent.hide(),i.search.show(),wpLink.lastSearch==d)return;wpLink.lastSearch=d,b=c.parent().find(".spinner").addClass("is-active"),i.search.change(d),i.search.ajax(function(){b.removeClass("is-active")})}else i.search.hide(),i.recent.show()},next:function(){i.search.next(),i.recent.next()},prev:function(){i.search.prev(),i.recent.prev()},keydown:function(a){var b,c;27===a.keyCode?(wpLink.close(),a.stopImmediatePropagation()):9===a.keyCode&&(c=a.target.id,"wp-link-submit"!==c||a.shiftKey?"wp-link-close"===c&&a.shiftKey&&(h.submit.focus(),a.preventDefault()):(h.close.focus(),a.preventDefault())),(38===a.keyCode||40===a.keyCode)&&(!document.activeElement||"link-title-field"!==document.activeElement.id&&"url-field"!==document.activeElement.id)&&(b=38===a.keyCode?"prev":"next",clearInterval(wpLink.keyInterval),wpLink[b](),wpLink.keyInterval=setInterval(wpLink[b],wpLink.keySensitivity),a.preventDefault())},keyup:function(a){(38===a.keyCode||40===a.keyCode)&&(clearInterval(wpLink.keyInterval),a.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=h.wrap.hasClass("search-panel-visible");h.wrap.toggleClass("search-panel-visible",!b),setUserSetting("wplink",b?"0":"1"),h[b?"url":"search"].focus(),a.preventDefault()}},e=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(e.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 f(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.addClass("is-active"),b.scrollTop(c+a.waiting.outerHeight()),a.ajax(function(){a.waiting.removeClass("is-active")}))},wpLink.timeToTriggerRiver)}}),f=function(a){this.page=1,this.allLoaded=!1,this.querying=!1,this.search=a},a.extend(f.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:h.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
@@ -1,14 +1,15 @@
1
- /* global ajaxurl, tinymce, wpLinkL10n, setUserSetting, wpActiveEditor */
2
  var wpLink;
3
 
4
- ( function( $ ) {
5
- var editor, searchTimer, River, Query, correctedURL,
 
 
6
  inputs = {},
7
  rivers = {},
8
  isTouch = ( 'ontouchend' in document );
9
 
10
  function getLink() {
11
- return editor.dom.getParent( editor.selection.getNode(), 'a' );
12
  }
13
 
14
  wpLink = {
@@ -50,13 +51,12 @@ var wpLink;
50
  event.preventDefault();
51
  wpLink.update();
52
  });
53
- inputs.close.add( inputs.backdrop ).add( '#wp-link-cancel a' ).click( function( event ) {
 
54
  event.preventDefault();
55
  wpLink.close();
56
  });
57
 
58
- $( '#wp-link-search-toggle' ).on( 'click', wpLink.toggleInternalLinking );
59
-
60
  rivers.elements.on( 'river-select', wpLink.updateFields );
61
 
62
  // Display 'hint' message when search field or 'query-results' box are focused
@@ -69,11 +69,9 @@ var wpLink;
69
  } );
70
 
71
  inputs.search.on( 'keyup input', function() {
72
- var self = this;
73
-
74
  window.clearTimeout( searchTimer );
75
  searchTimer = window.setTimeout( function() {
76
- wpLink.searchInternalLinks.call( self );
77
  }, 500 );
78
  });
79
 
@@ -94,11 +92,12 @@ var wpLink;
94
  }
95
  },
96
 
97
- open: function( editorId ) {
98
  var ed,
99
  $body = $( document.body );
100
 
101
  $body.addClass( 'modal-open' );
 
102
 
103
  wpLink.range = null;
104
 
@@ -112,12 +111,12 @@ var wpLink;
112
 
113
  this.textarea = $( '#' + window.wpActiveEditor ).get( 0 );
114
 
115
- if ( typeof tinymce !== 'undefined' ) {
116
  // Make sure the link wrapper is the last element in the body,
117
  // or the inline editor toolbar may show above the backdrop.
118
  $body.append( inputs.backdrop, inputs.wrap );
119
 
120
- ed = tinymce.get( wpActiveEditor );
121
 
122
  if ( ed && ! ed.isHidden() ) {
123
  editor = ed;
@@ -125,8 +124,8 @@ var wpLink;
125
  editor = null;
126
  }
127
 
128
- if ( editor && tinymce.isIE ) {
129
- editor.windowManager.bookmark = editor.selection.getBookmark();
130
  }
131
  }
132
 
@@ -138,7 +137,7 @@ var wpLink;
138
  inputs.wrap.show();
139
  inputs.backdrop.show();
140
 
141
- wpLink.refresh();
142
 
143
  $( document ).trigger( 'wplink-open', inputs.wrap );
144
  },
@@ -147,15 +146,15 @@ var wpLink;
147
  return editor && ! editor.isHidden();
148
  },
149
 
150
- refresh: function() {
151
- var text = '';
152
 
153
  // Refresh rivers (clear links, check visibility)
154
  rivers.search.refresh();
155
  rivers.recent.refresh();
156
 
157
  if ( wpLink.isMCE() ) {
158
- wpLink.mceRefresh();
159
  } else {
160
  // For the Text editor the "Link text" field is always shown
161
  if ( ! inputs.wrap.hasClass( 'has-text-field' ) ) {
@@ -164,11 +163,11 @@ var wpLink;
164
 
165
  if ( document.selection ) {
166
  // Old IE
167
- text = document.selection.createRange().text || '';
168
  } else if ( typeof this.textarea.selectionStart !== 'undefined' &&
169
  ( this.textarea.selectionStart !== this.textarea.selectionEnd ) ) {
170
  // W3C
171
- text = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd ) || '';
172
  }
173
 
174
  inputs.text.val( text );
@@ -182,7 +181,10 @@ var wpLink;
182
  // Focus the URL field and highlight its contents.
183
  // If this is moved above the selection changes,
184
  // IE will show a flashing cursor over the dialog.
185
- inputs.url.focus()[0].select();
 
 
 
186
  }
187
 
188
  // Load the most recent results if this is the first time opening the panel.
@@ -194,7 +196,7 @@ var wpLink;
194
  },
195
 
196
  hasSelectedText: function( linkNode ) {
197
- var html = editor.selection.getContent();
198
 
199
  // Partial html and not a fully selected anchor element
200
  if ( /</.test( html ) && ( ! /^<a [^>]+>[^<]+<\/a>$/.test( html ) || html.indexOf('href=') === -1 ) ) {
@@ -202,14 +204,16 @@ var wpLink;
202
  }
203
 
204
  if ( linkNode ) {
205
- var nodes = linkNode.childNodes, i;
206
 
207
  if ( nodes.length === 0 ) {
208
  return false;
209
  }
210
 
211
  for ( i = nodes.length - 1; i >= 0; i-- ) {
212
- if ( nodes[i].nodeType != 3 ) {
 
 
213
  return false;
214
  }
215
  }
@@ -218,24 +222,49 @@ var wpLink;
218
  return true;
219
  },
220
 
221
- mceRefresh: function() {
222
- var text,
223
- selectedNode = editor.selection.getNode(),
224
- linkNode = editor.dom.getParent( selectedNode, 'a[href]' ),
225
  onlyText = this.hasSelectedText( linkNode );
226
 
227
  if ( linkNode ) {
228
- text = linkNode.innerText || linkNode.textContent;
229
- inputs.url.val( editor.dom.getAttrib( linkNode, 'href' ) );
230
- inputs.openInNewTab.prop( 'checked', '_blank' === editor.dom.getAttrib( linkNode, 'target' ) );
231
- inputs.submit.val( wpLinkL10n.update );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232
  } else {
233
- text = editor.selection.getContent({ format: 'text' });
234
- this.setDefaultValues();
235
  }
236
 
237
  if ( onlyText ) {
238
- inputs.text.val( text || '' );
239
  inputs.wrap.addClass( 'has-text-field' );
240
  } else {
241
  inputs.text.val( '' );
@@ -243,18 +272,24 @@ var wpLink;
243
  }
244
  },
245
 
246
- close: function() {
247
  $( document.body ).removeClass( 'modal-open' );
248
 
249
- if ( ! wpLink.isMCE() ) {
250
- wpLink.textarea.focus();
 
 
 
 
 
 
 
 
 
 
251
 
252
- if ( wpLink.range ) {
253
- wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
254
- wpLink.range.select();
255
  }
256
- } else {
257
- editor.focus();
258
  }
259
 
260
  inputs.backdrop.hide();
@@ -346,21 +381,23 @@ var wpLink;
346
 
347
  wpLink.close();
348
  textarea.focus();
 
 
 
349
  },
350
 
351
  mceUpdate: function() {
352
  var attrs = wpLink.getAttrs(),
353
  link, text;
354
 
355
- wpLink.close();
356
- editor.focus();
357
-
358
- if ( tinymce.isIE ) {
359
- editor.selection.moveToBookmark( editor.windowManager.bookmark );
360
  }
361
 
362
  if ( ! attrs.href ) {
363
  editor.execCommand( 'unlink' );
 
364
  return;
365
  }
366
 
@@ -379,6 +416,8 @@ var wpLink;
379
  }
380
  }
381
 
 
 
382
  editor.dom.setAttribs( link, attrs );
383
  } else {
384
  if ( text ) {
@@ -388,44 +427,56 @@ var wpLink;
388
  }
389
  }
390
 
 
 
391
  editor.nodeChanged();
 
 
 
392
  },
393
 
394
  updateFields: function( e, li ) {
395
  inputs.url.val( li.children( '.item-permalink' ).val() );
396
  },
397
 
398
- setDefaultValues: function() {
399
- var selection,
400
- emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
401
- urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i;
402
-
403
- if ( this.isMCE() ) {
404
- selection = editor.selection.getContent();
405
- } else if ( document.selection && wpLink.range ) {
406
- selection = wpLink.range.text;
407
- } else if ( typeof this.textarea.selectionStart !== 'undefined' ) {
408
- selection = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd );
409
  }
410
 
 
 
411
  if ( selection && emailRegexp.test( selection ) ) {
412
  // Selection is email address
413
- inputs.url.val( 'mailto:' + selection );
414
  } else if ( selection && urlRegexp.test( selection ) ) {
415
  // Selection is URL
416
- inputs.url.val( selection.replace( /&amp;|&#0?38;/gi, '&' ) );
417
- } else {
418
- // Set URL to default.
419
- inputs.url.val( '' );
420
  }
421
 
 
 
 
 
 
 
 
 
 
 
422
  // Update save prompt.
423
  inputs.submit.val( wpLinkL10n.save );
424
  },
425
 
426
  searchInternalLinks: function() {
427
- var t = $( this ), waiting,
428
- search = t.val();
429
 
430
  if ( search.length > 1 ) {
431
  rivers.recent.hide();
@@ -436,7 +487,7 @@ var wpLink;
436
  return;
437
 
438
  wpLink.lastSearch = search;
439
- waiting = t.parent().find( '.spinner' ).addClass( 'is-active' );
440
 
441
  rivers.search.change( search );
442
  rivers.search.ajax( function() {
@@ -527,15 +578,6 @@ var wpLink;
527
  funcContext = this;
528
  funcTriggered = true;
529
  };
530
- },
531
-
532
- toggleInternalLinking: function( event ) {
533
- var visible = inputs.wrap.hasClass( 'search-panel-visible' );
534
-
535
- inputs.wrap.toggleClass( 'search-panel-visible', ! visible );
536
- setUserSetting( 'wplink', visible ? '0' : '1' );
537
- inputs[ ! visible ? 'search' : 'url' ].focus();
538
- event.preventDefault();
539
  }
540
  };
541
 
@@ -712,7 +754,7 @@ var wpLink;
712
 
713
  this.querying = true;
714
 
715
- $.post( ajaxurl, query, function( r ) {
716
  self.page++;
717
  self.querying = false;
718
  self.allLoaded = ! r;
@@ -722,4 +764,4 @@ var wpLink;
722
  });
723
 
724
  $( document ).ready( wpLink.init );
725
- })( jQuery );
 
1
  var wpLink;
2
 
3
+ ( function( $, wpLinkL10n, wp ) {
4
+ var editor, searchTimer, River, Query, correctedURL, linkNode,
5
+ emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
6
+ urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i,
7
  inputs = {},
8
  rivers = {},
9
  isTouch = ( 'ontouchend' in document );
10
 
11
  function getLink() {
12
+ return linkNode || editor.dom.getParent( editor.selection.getNode(), 'a[href]' );
13
  }
14
 
15
  wpLink = {
51
  event.preventDefault();
52
  wpLink.update();
53
  });
54
+
55
+ inputs.close.add( inputs.backdrop ).add( '#wp-link-cancel button' ).click( function( event ) {
56
  event.preventDefault();
57
  wpLink.close();
58
  });
59
 
 
 
60
  rivers.elements.on( 'river-select', wpLink.updateFields );
61
 
62
  // Display 'hint' message when search field or 'query-results' box are focused
69
  } );
70
 
71
  inputs.search.on( 'keyup input', function() {
 
 
72
  window.clearTimeout( searchTimer );
73
  searchTimer = window.setTimeout( function() {
74
+ wpLink.searchInternalLinks();
75
  }, 500 );
76
  });
77
 
92
  }
93
  },
94
 
95
+ open: function( editorId, url, text, node ) {
96
  var ed,
97
  $body = $( document.body );
98
 
99
  $body.addClass( 'modal-open' );
100
+ linkNode = node;
101
 
102
  wpLink.range = null;
103
 
111
 
112
  this.textarea = $( '#' + window.wpActiveEditor ).get( 0 );
113
 
114
+ if ( typeof window.tinymce !== 'undefined' ) {
115
  // Make sure the link wrapper is the last element in the body,
116
  // or the inline editor toolbar may show above the backdrop.
117
  $body.append( inputs.backdrop, inputs.wrap );
118
 
119
+ ed = window.tinymce.get( window.wpActiveEditor );
120
 
121
  if ( ed && ! ed.isHidden() ) {
122
  editor = ed;
124
  editor = null;
125
  }
126
 
127
+ if ( editor && window.tinymce.isIE ) {
128
+ editor.windowManager.wplinkBookmark = editor.selection.getBookmark();
129
  }
130
  }
131
 
137
  inputs.wrap.show();
138
  inputs.backdrop.show();
139
 
140
+ wpLink.refresh( url, text );
141
 
142
  $( document ).trigger( 'wplink-open', inputs.wrap );
143
  },
146
  return editor && ! editor.isHidden();
147
  },
148
 
149
+ refresh: function( url, text ) {
150
+ var linkText = '';
151
 
152
  // Refresh rivers (clear links, check visibility)
153
  rivers.search.refresh();
154
  rivers.recent.refresh();
155
 
156
  if ( wpLink.isMCE() ) {
157
+ wpLink.mceRefresh( url, text );
158
  } else {
159
  // For the Text editor the "Link text" field is always shown
160
  if ( ! inputs.wrap.hasClass( 'has-text-field' ) ) {
163
 
164
  if ( document.selection ) {
165
  // Old IE
166
+ linkText = document.selection.createRange().text || text || '';
167
  } else if ( typeof this.textarea.selectionStart !== 'undefined' &&
168
  ( this.textarea.selectionStart !== this.textarea.selectionEnd ) ) {
169
  // W3C
170
+ text = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd ) || text || '';
171
  }
172
 
173
  inputs.text.val( text );
181
  // Focus the URL field and highlight its contents.
182
  // If this is moved above the selection changes,
183
  // IE will show a flashing cursor over the dialog.
184
+ window.setTimeout( function() {
185
+ inputs.url[0].select();
186
+ inputs.url.focus();
187
+ } );
188
  }
189
 
190
  // Load the most recent results if this is the first time opening the panel.
196
  },
197
 
198
  hasSelectedText: function( linkNode ) {
199
+ var node, nodes, i, html = editor.selection.getContent();
200
 
201
  // Partial html and not a fully selected anchor element
202
  if ( /</.test( html ) && ( ! /^<a [^>]+>[^<]+<\/a>$/.test( html ) || html.indexOf('href=') === -1 ) ) {
204
  }
205
 
206
  if ( linkNode ) {
207
+ nodes = linkNode.childNodes;
208
 
209
  if ( nodes.length === 0 ) {
210
  return false;
211
  }
212
 
213
  for ( i = nodes.length - 1; i >= 0; i-- ) {
214
+ node = nodes[i];
215
+
216
+ if ( node.nodeType != 3 && ! window.tinymce.dom.BookmarkManager.isBookmarkNode( node ) ) {
217
  return false;
218
  }
219
  }
222
  return true;
223
  },
224
 
225
+ mceRefresh: function( searchStr, text ) {
226
+ var linkText, href,
227
+ linkNode = getLink(),
 
228
  onlyText = this.hasSelectedText( linkNode );
229
 
230
  if ( linkNode ) {
231
+ linkText = linkNode.innerText || linkNode.textContent;
232
+ href = editor.dom.getAttrib( linkNode, 'href' );
233
+
234
+ if ( ! $.trim( linkText ) ) {
235
+ linkText = text || '';
236
+ }
237
+
238
+ if ( searchStr && ( urlRegexp.test( searchStr ) || emailRegexp.test( searchStr ) ) ) {
239
+ href = searchStr;
240
+ }
241
+
242
+ if ( href !== '_wp_link_placeholder' ) {
243
+ inputs.url.val( href );
244
+ inputs.openInNewTab.prop( 'checked', '_blank' === editor.dom.getAttrib( linkNode, 'target' ) );
245
+ inputs.submit.val( wpLinkL10n.update );
246
+ } else {
247
+ this.setDefaultValues( linkText );
248
+ }
249
+
250
+ if ( searchStr && searchStr !== href ) {
251
+ // The user has typed something in the inline dialog. Trigger a search with it.
252
+ inputs.search.val( searchStr );
253
+ } else {
254
+ inputs.search.val( '' );
255
+ }
256
+
257
+ // Always reset the search
258
+ window.setTimeout( function() {
259
+ wpLink.searchInternalLinks();
260
+ } );
261
  } else {
262
+ linkText = editor.selection.getContent({ format: 'text' }) || text || '';
263
+ this.setDefaultValues( linkText );
264
  }
265
 
266
  if ( onlyText ) {
267
+ inputs.text.val( linkText );
268
  inputs.wrap.addClass( 'has-text-field' );
269
  } else {
270
  inputs.text.val( '' );
272
  }
273
  },
274
 
275
+ close: function( reset ) {
276
  $( document.body ).removeClass( 'modal-open' );
277
 
278
+ if ( reset !== 'noReset' ) {
279
+ if ( ! wpLink.isMCE() ) {
280
+ wpLink.textarea.focus();
281
+
282
+ if ( wpLink.range ) {
283
+ wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
284
+ wpLink.range.select();
285
+ }
286
+ } else {
287
+ if ( editor.plugins.wplink ) {
288
+ editor.plugins.wplink.close();
289
+ }
290
 
291
+ editor.focus();
 
 
292
  }
 
 
293
  }
294
 
295
  inputs.backdrop.hide();
381
 
382
  wpLink.close();
383
  textarea.focus();
384
+
385
+ // Audible confirmation message when a link has been inserted in the Editor.
386
+ wp.a11y.speak( wpLinkL10n.linkInserted );
387
  },
388
 
389
  mceUpdate: function() {
390
  var attrs = wpLink.getAttrs(),
391
  link, text;
392
 
393
+ if ( window.tinymce.isIE && editor.windowManager.wplinkBookmark ) {
394
+ editor.selection.moveToBookmark( editor.windowManager.wplinkBookmark );
395
+ editor.windowManager.wplinkBookmark = null;
 
 
396
  }
397
 
398
  if ( ! attrs.href ) {
399
  editor.execCommand( 'unlink' );
400
+ wpLink.close();
401
  return;
402
  }
403
 
416
  }
417
  }
418
 
419
+ // Not editing any more
420
+ attrs['data-wplink-edit'] = null;
421
  editor.dom.setAttribs( link, attrs );
422
  } else {
423
  if ( text ) {
427
  }
428
  }
429
 
430
+ wpLink.close( 'noReset' );
431
+ editor.focus();
432
  editor.nodeChanged();
433
+
434
+ // Audible confirmation message when a link has been inserted in the Editor.
435
+ wp.a11y.speak( wpLinkL10n.linkInserted );
436
  },
437
 
438
  updateFields: function( e, li ) {
439
  inputs.url.val( li.children( '.item-permalink' ).val() );
440
  },
441
 
442
+ getUrlFromSelection: function( selection ) {
443
+ if ( ! selection ) {
444
+ if ( this.isMCE() ) {
445
+ selection = editor.selection.getContent({ format: 'text' });
446
+ } else if ( document.selection && wpLink.range ) {
447
+ selection = wpLink.range.text;
448
+ } else if ( typeof this.textarea.selectionStart !== 'undefined' ) {
449
+ selection = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd );
450
+ }
 
 
451
  }
452
 
453
+ selection = $.trim( selection );
454
+
455
  if ( selection && emailRegexp.test( selection ) ) {
456
  // Selection is email address
457
+ return 'mailto:' + selection;
458
  } else if ( selection && urlRegexp.test( selection ) ) {
459
  // Selection is URL
460
+ return selection.replace( /&amp;|&#0?38;/gi, '&' );
 
 
 
461
  }
462
 
463
+ return '';
464
+ },
465
+
466
+ setDefaultValues: function( selection ) {
467
+ inputs.url.val( this.getUrlFromSelection( selection ) );
468
+
469
+ // Empty the search field and swap the "rivers".
470
+ inputs.search.val('');
471
+ wpLink.searchInternalLinks();
472
+
473
  // Update save prompt.
474
  inputs.submit.val( wpLinkL10n.save );
475
  },
476
 
477
  searchInternalLinks: function() {
478
+ var waiting,
479
+ search = inputs.search.val() || '';
480
 
481
  if ( search.length > 1 ) {
482
  rivers.recent.hide();
487
  return;
488
 
489
  wpLink.lastSearch = search;
490
+ waiting = inputs.search.parent().find( '.spinner' ).addClass( 'is-active' );
491
 
492
  rivers.search.change( search );
493
  rivers.search.ajax( function() {
578
  funcContext = this;
579
  funcTriggered = true;
580
  };
 
 
 
 
 
 
 
 
 
581
  }
582
  };
583
 
754
 
755
  this.querying = true;
756
 
757
+ $.post( window.ajaxurl, query, function( r ) {
758
  self.page++;
759
  self.querying = false;
760
  self.allLoaded = ! r;
764
  });
765
 
766
  $( document ).ready( wpLink.init );
767
+ })( jQuery, window.wpLinkL10n, window.wp );
js/wplink.min.js CHANGED
@@ -1 +1 @@
1
- var wpLink;!function(a){function b(){return c.dom.getParent(c.selection.getNode(),"a")}var c,d,e,f,g,h={},i={},j="ontouchend"in document;wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",init:function(){h.wrap=a("#wp-link-wrap"),h.dialog=a("#wp-link"),h.backdrop=a("#wp-link-backdrop"),h.submit=a("#wp-link-submit"),h.close=a("#wp-link-close"),h.text=a("#wp-link-text"),h.url=a("#wp-link-url"),h.nonce=a("#_ajax_linking_nonce"),h.openInNewTab=a("#wp-link-target"),h.search=a("#wp-link-search"),i.search=new e(a("#search-results")),i.recent=new e(a("#most-recent-results")),i.elements=h.dialog.find(".query-results"),h.queryNotice=a("#query-notice-message"),h.queryNoticeTextDefault=h.queryNotice.find(".query-notice-default"),h.queryNoticeTextHint=h.queryNotice.find(".query-notice-hint"),h.dialog.keydown(wpLink.keydown),h.dialog.keyup(wpLink.keyup),h.submit.click(function(a){a.preventDefault(),wpLink.update()}),h.close.add(h.backdrop).add("#wp-link-cancel a").click(function(a){a.preventDefault(),wpLink.close()}),a("#wp-link-search-toggle").on("click",wpLink.toggleInternalLinking),i.elements.on("river-select",wpLink.updateFields),h.search.on("focus.wplink",function(){h.queryNoticeTextDefault.hide(),h.queryNoticeTextHint.removeClass("screen-reader-text").show()}).on("blur.wplink",function(){h.queryNoticeTextDefault.show(),h.queryNoticeTextHint.addClass("screen-reader-text").hide()}),h.search.on("keyup input",function(){var a=this;window.clearTimeout(d),d=window.setTimeout(function(){wpLink.searchInternalLinks.call(a)},500)}),h.url.on("paste",function(){setTimeout(wpLink.correctURL,0)}),h.url.on("blur",wpLink.correctURL)},correctURL:function(){var b=a.trim(h.url.val());b&&g!==b&&!/^(?:[a-z]+:|#|\?|\.|\/)/.test(b)&&(h.url.val("http://"+b),g=b)},open:function(b){var d,e=a(document.body);e.addClass("modal-open"),wpLink.range=null,b&&(window.wpActiveEditor=b),window.wpActiveEditor&&(this.textarea=a("#"+window.wpActiveEditor).get(0),"undefined"!=typeof tinymce&&(e.append(h.backdrop,h.wrap),d=tinymce.get(wpActiveEditor),c=d&&!d.isHidden()?d:null,c&&tinymce.isIE&&(c.windowManager.bookmark=c.selection.getBookmark())),!wpLink.isMCE()&&document.selection&&(this.textarea.focus(),this.range=document.selection.createRange()),h.wrap.show(),h.backdrop.show(),wpLink.refresh(),a(document).trigger("wplink-open",h.wrap))},isMCE:function(){return c&&!c.isHidden()},refresh:function(){var a="";i.search.refresh(),i.recent.refresh(),wpLink.isMCE()?wpLink.mceRefresh():(h.wrap.hasClass("has-text-field")||h.wrap.addClass("has-text-field"),document.selection?a=document.selection.createRange().text||"":"undefined"!=typeof this.textarea.selectionStart&&this.textarea.selectionStart!==this.textarea.selectionEnd&&(a=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd)||""),h.text.val(a),wpLink.setDefaultValues()),j?h.url.focus().blur():h.url.focus()[0].select(),i.recent.ul.children().length||i.recent.ajax(),g=h.url.val().replace(/^http:\/\//,"")},hasSelectedText:function(a){var b=c.selection.getContent();if(/</.test(b)&&(!/^<a [^>]+>[^<]+<\/a>$/.test(b)||-1===b.indexOf("href=")))return!1;if(a){var d,e=a.childNodes;if(0===e.length)return!1;for(d=e.length-1;d>=0;d--)if(3!=e[d].nodeType)return!1}return!0},mceRefresh:function(){var a,b=c.selection.getNode(),d=c.dom.getParent(b,"a[href]"),e=this.hasSelectedText(d);d?(a=d.innerText||d.textContent,h.url.val(c.dom.getAttrib(d,"href")),h.openInNewTab.prop("checked","_blank"===c.dom.getAttrib(d,"target")),h.submit.val(wpLinkL10n.update)):(a=c.selection.getContent({format:"text"}),this.setDefaultValues()),e?(h.text.val(a||""),h.wrap.addClass("has-text-field")):(h.text.val(""),h.wrap.removeClass("has-text-field"))},close:function(){a(document.body).removeClass("modal-open"),wpLink.isMCE()?c.focus():(wpLink.textarea.focus(),wpLink.range&&(wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select())),h.backdrop.hide(),h.wrap.hide(),g=!1,a(document).trigger("wplink-close",h.wrap)},getAttrs:function(){return wpLink.correctURL(),{href:a.trim(h.url.val()),target:h.openInNewTab.prop("checked")?"_blank":""}},buildHtml:function(a){var b='<a href="'+a.href+'"';return a.target&&(b+=' target="'+a.target+'"'),b+">"},update:function(){wpLink.isMCE()?wpLink.mceUpdate():wpLink.htmlUpdate()},htmlUpdate:function(){var a,b,c,d,e,f,g,i=wpLink.textarea;i&&(a=wpLink.getAttrs(),b=h.text.val(),a.href&&(c=wpLink.buildHtml(a),document.selection&&wpLink.range?(i.focus(),wpLink.range.text=c+(b||wpLink.range.text)+"</a>",wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select(),wpLink.range=null):"undefined"!=typeof i.selectionStart&&(d=i.selectionStart,e=i.selectionEnd,g=b||i.value.substring(d,e),c=c+g+"</a>",f=d+c.length,d!==e||g||(f-=4),i.value=i.value.substring(0,d)+c+i.value.substring(e,i.value.length),i.selectionStart=i.selectionEnd=f),wpLink.close(),i.focus()))},mceUpdate:function(){var a,d,e=wpLink.getAttrs();return wpLink.close(),c.focus(),tinymce.isIE&&c.selection.moveToBookmark(c.windowManager.bookmark),e.href?(a=b(),h.wrap.hasClass("has-text-field")&&(d=h.text.val()||e.href),a?(d&&("innerText"in a?a.innerText=d:a.textContent=d),c.dom.setAttribs(a,e)):d?c.selection.setNode(c.dom.create("a",e,c.dom.encode(d))):c.execCommand("mceInsertLink",!1,e),void c.nodeChanged()):void c.execCommand("unlink")},updateFields:function(a,b){h.url.val(b.children(".item-permalink").val())},setDefaultValues:function(){var a,b=/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,d=/^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i;this.isMCE()?a=c.selection.getContent():document.selection&&wpLink.range?a=wpLink.range.text:"undefined"!=typeof this.textarea.selectionStart&&(a=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd)),a&&b.test(a)?h.url.val("mailto:"+a):a&&d.test(a)?h.url.val(a.replace(/&amp;|&#0?38;/gi,"&")):h.url.val(""),h.submit.val(wpLinkL10n.save)},searchInternalLinks:function(){var b,c=a(this),d=c.val();if(d.length>1){if(i.recent.hide(),i.search.show(),wpLink.lastSearch==d)return;wpLink.lastSearch=d,b=c.parent().find(".spinner").addClass("is-active"),i.search.change(d),i.search.ajax(function(){b.removeClass("is-active")})}else i.search.hide(),i.recent.show()},next:function(){i.search.next(),i.recent.next()},prev:function(){i.search.prev(),i.recent.prev()},keydown:function(a){var b,c;27===a.keyCode?(wpLink.close(),a.stopImmediatePropagation()):9===a.keyCode&&(c=a.target.id,"wp-link-submit"!==c||a.shiftKey?"wp-link-close"===c&&a.shiftKey&&(h.submit.focus(),a.preventDefault()):(h.close.focus(),a.preventDefault())),(38===a.keyCode||40===a.keyCode)&&(!document.activeElement||"link-title-field"!==document.activeElement.id&&"url-field"!==document.activeElement.id)&&(b=38===a.keyCode?"prev":"next",clearInterval(wpLink.keyInterval),wpLink[b](),wpLink.keyInterval=setInterval(wpLink[b],wpLink.keySensitivity),a.preventDefault())},keyup:function(a){(38===a.keyCode||40===a.keyCode)&&(clearInterval(wpLink.keyInterval),a.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=h.wrap.hasClass("search-panel-visible");h.wrap.toggleClass("search-panel-visible",!b),setUserSetting("wplink",b?"0":"1"),h[b?"url":"search"].focus(),a.preventDefault()}},e=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(e.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 f(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.addClass("is-active"),b.scrollTop(c+a.waiting.outerHeight()),a.ajax(function(){a.waiting.removeClass("is-active")}))},wpLink.timeToTriggerRiver)}}),f=function(a){this.page=1,this.allLoaded=!1,this.querying=!1,this.search=a},a.extend(f.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:h.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,b,c){function d(){return j||e.dom.getParent(e.selection.getNode(),"a[href]")}var e,f,g,h,i,j,k=/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,l=/^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i,m={},n={},o="ontouchend"in document;wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",init:function(){m.wrap=a("#wp-link-wrap"),m.dialog=a("#wp-link"),m.backdrop=a("#wp-link-backdrop"),m.submit=a("#wp-link-submit"),m.close=a("#wp-link-close"),m.text=a("#wp-link-text"),m.url=a("#wp-link-url"),m.nonce=a("#_ajax_linking_nonce"),m.openInNewTab=a("#wp-link-target"),m.search=a("#wp-link-search"),n.search=new g(a("#search-results")),n.recent=new g(a("#most-recent-results")),n.elements=m.dialog.find(".query-results"),m.queryNotice=a("#query-notice-message"),m.queryNoticeTextDefault=m.queryNotice.find(".query-notice-default"),m.queryNoticeTextHint=m.queryNotice.find(".query-notice-hint"),m.dialog.keydown(wpLink.keydown),m.dialog.keyup(wpLink.keyup),m.submit.click(function(a){a.preventDefault(),wpLink.update()}),m.close.add(m.backdrop).add("#wp-link-cancel button").click(function(a){a.preventDefault(),wpLink.close()}),n.elements.on("river-select",wpLink.updateFields),m.search.on("focus.wplink",function(){m.queryNoticeTextDefault.hide(),m.queryNoticeTextHint.removeClass("screen-reader-text").show()}).on("blur.wplink",function(){m.queryNoticeTextDefault.show(),m.queryNoticeTextHint.addClass("screen-reader-text").hide()}),m.search.on("keyup input",function(){window.clearTimeout(f),f=window.setTimeout(function(){wpLink.searchInternalLinks()},500)}),m.url.on("paste",function(){setTimeout(wpLink.correctURL,0)}),m.url.on("blur",wpLink.correctURL)},correctURL:function(){var b=a.trim(m.url.val());b&&i!==b&&!/^(?:[a-z]+:|#|\?|\.|\/)/.test(b)&&(m.url.val("http://"+b),i=b)},open:function(b,c,d,f){var g,h=a(document.body);h.addClass("modal-open"),j=f,wpLink.range=null,b&&(window.wpActiveEditor=b),window.wpActiveEditor&&(this.textarea=a("#"+window.wpActiveEditor).get(0),"undefined"!=typeof window.tinymce&&(h.append(m.backdrop,m.wrap),g=window.tinymce.get(window.wpActiveEditor),e=g&&!g.isHidden()?g:null,e&&window.tinymce.isIE&&(e.windowManager.wplinkBookmark=e.selection.getBookmark())),!wpLink.isMCE()&&document.selection&&(this.textarea.focus(),this.range=document.selection.createRange()),m.wrap.show(),m.backdrop.show(),wpLink.refresh(c,d),a(document).trigger("wplink-open",m.wrap))},isMCE:function(){return e&&!e.isHidden()},refresh:function(a,b){var c="";n.search.refresh(),n.recent.refresh(),wpLink.isMCE()?wpLink.mceRefresh(a,b):(m.wrap.hasClass("has-text-field")||m.wrap.addClass("has-text-field"),document.selection?c=document.selection.createRange().text||b||"":"undefined"!=typeof this.textarea.selectionStart&&this.textarea.selectionStart!==this.textarea.selectionEnd&&(b=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd)||b||""),m.text.val(b),wpLink.setDefaultValues()),o?m.url.focus().blur():window.setTimeout(function(){m.url[0].select(),m.url.focus()}),n.recent.ul.children().length||n.recent.ajax(),i=m.url.val().replace(/^http:\/\//,"")},hasSelectedText:function(a){var b,c,d,f=e.selection.getContent();if(/</.test(f)&&(!/^<a [^>]+>[^<]+<\/a>$/.test(f)||-1===f.indexOf("href=")))return!1;if(a){if(c=a.childNodes,0===c.length)return!1;for(d=c.length-1;d>=0;d--)if(b=c[d],3!=b.nodeType&&!window.tinymce.dom.BookmarkManager.isBookmarkNode(b))return!1}return!0},mceRefresh:function(c,f){var g,h,i=d(),j=this.hasSelectedText(i);i?(g=i.innerText||i.textContent,h=e.dom.getAttrib(i,"href"),a.trim(g)||(g=f||""),c&&(l.test(c)||k.test(c))&&(h=c),"_wp_link_placeholder"!==h?(m.url.val(h),m.openInNewTab.prop("checked","_blank"===e.dom.getAttrib(i,"target")),m.submit.val(b.update)):this.setDefaultValues(g),c&&c!==h?m.search.val(c):m.search.val(""),window.setTimeout(function(){wpLink.searchInternalLinks()})):(g=e.selection.getContent({format:"text"})||f||"",this.setDefaultValues(g)),j?(m.text.val(g),m.wrap.addClass("has-text-field")):(m.text.val(""),m.wrap.removeClass("has-text-field"))},close:function(b){a(document.body).removeClass("modal-open"),"noReset"!==b&&(wpLink.isMCE()?(e.plugins.wplink&&e.plugins.wplink.close(),e.focus()):(wpLink.textarea.focus(),wpLink.range&&(wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select()))),m.backdrop.hide(),m.wrap.hide(),i=!1,a(document).trigger("wplink-close",m.wrap)},getAttrs:function(){return wpLink.correctURL(),{href:a.trim(m.url.val()),target:m.openInNewTab.prop("checked")?"_blank":""}},buildHtml:function(a){var b='<a href="'+a.href+'"';return a.target&&(b+=' target="'+a.target+'"'),b+">"},update:function(){wpLink.isMCE()?wpLink.mceUpdate():wpLink.htmlUpdate()},htmlUpdate:function(){var a,d,e,f,g,h,i,j=wpLink.textarea;j&&(a=wpLink.getAttrs(),d=m.text.val(),a.href&&(e=wpLink.buildHtml(a),document.selection&&wpLink.range?(j.focus(),wpLink.range.text=e+(d||wpLink.range.text)+"</a>",wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select(),wpLink.range=null):"undefined"!=typeof j.selectionStart&&(f=j.selectionStart,g=j.selectionEnd,i=d||j.value.substring(f,g),e=e+i+"</a>",h=f+e.length,f!==g||i||(h-=4),j.value=j.value.substring(0,f)+e+j.value.substring(g,j.value.length),j.selectionStart=j.selectionEnd=h),wpLink.close(),j.focus(),c.a11y.speak(b.linkInserted)))},mceUpdate:function(){var a,f,g=wpLink.getAttrs();return window.tinymce.isIE&&e.windowManager.wplinkBookmark&&(e.selection.moveToBookmark(e.windowManager.wplinkBookmark),e.windowManager.wplinkBookmark=null),g.href?(a=d(),m.wrap.hasClass("has-text-field")&&(f=m.text.val()||g.href),a?(f&&("innerText"in a?a.innerText=f:a.textContent=f),g["data-wplink-edit"]=null,e.dom.setAttribs(a,g)):f?e.selection.setNode(e.dom.create("a",g,e.dom.encode(f))):e.execCommand("mceInsertLink",!1,g),wpLink.close("noReset"),e.focus(),e.nodeChanged(),void c.a11y.speak(b.linkInserted)):(e.execCommand("unlink"),void wpLink.close())},updateFields:function(a,b){m.url.val(b.children(".item-permalink").val())},getUrlFromSelection:function(b){return b||(this.isMCE()?b=e.selection.getContent({format:"text"}):document.selection&&wpLink.range?b=wpLink.range.text:"undefined"!=typeof this.textarea.selectionStart&&(b=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd))),b=a.trim(b),b&&k.test(b)?"mailto:"+b:b&&l.test(b)?b.replace(/&amp;|&#0?38;/gi,"&"):""},setDefaultValues:function(a){m.url.val(this.getUrlFromSelection(a)),m.search.val(""),wpLink.searchInternalLinks(),m.submit.val(b.save)},searchInternalLinks:function(){var a,b=m.search.val()||"";if(b.length>1){if(n.recent.hide(),n.search.show(),wpLink.lastSearch==b)return;wpLink.lastSearch=b,a=m.search.parent().find(".spinner").addClass("is-active"),n.search.change(b),n.search.ajax(function(){a.removeClass("is-active")})}else n.search.hide(),n.recent.show()},next:function(){n.search.next(),n.recent.next()},prev:function(){n.search.prev(),n.recent.prev()},keydown:function(a){var b,c;27===a.keyCode?(wpLink.close(),a.stopImmediatePropagation()):9===a.keyCode&&(c=a.target.id,"wp-link-submit"!==c||a.shiftKey?"wp-link-close"===c&&a.shiftKey&&(m.submit.focus(),a.preventDefault()):(m.close.focus(),a.preventDefault())),(38===a.keyCode||40===a.keyCode)&&(!document.activeElement||"link-title-field"!==document.activeElement.id&&"url-field"!==document.activeElement.id)&&(b=38===a.keyCode?"prev":"next",clearInterval(wpLink.keyInterval),wpLink[b](),wpLink.keyInterval=setInterval(wpLink[b],wpLink.keySensitivity),a.preventDefault())},keyup:function(a){(38===a.keyCode||40===a.keyCode)&&(clearInterval(wpLink.keyInterval),a.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}},g=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(g.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 h(a),this.element.scrollTop(0))},process:function(c,d){var e="",f=!0,g="",h=1==d.page;c?a.each(c,function(){g=f?"alternate":"",g+=this.title?"":" no-title",e+=g?'<li class="'+g+'">':"<li>",e+='<input type="hidden" class="item-permalink" value="'+this.permalink+'" />',e+='<span class="item-title">',e+=this.title?this.title:b.noTitle,e+='</span><span class="item-info">'+this.info+"</span></li>",f=!f}):h&&(e+='<li class="unselectable no-matches-found"><span class="item-title"><em>'+b.noMatchesFound+"</em></span></li>"),this.ul[h?"html":"append"](e)},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.addClass("is-active"),b.scrollTop(c+a.waiting.outerHeight()),a.ajax(function(){a.waiting.removeClass("is-active")}))},wpLink.timeToTriggerRiver)}}),h=function(a){this.page=1,this.allLoaded=!1,this.querying=!1,this.search=a},a.extend(h.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:m.nonce.val()};this.search&&(d.search=this.search),this.querying=!0,a.post(window.ajaxurl,d,function(a){c.page++,c.querying=!1,c.allLoaded=!a,b(a,d)},"json")}}),a(document).ready(wpLink.init)}(jQuery,window.wpLinkL10n,window.wp);
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === WP Multibyte Patch ===
2
  Contributors: tenpura
3
  Tags: multibyte,i18n,wp-multibyte-patch,Japanese
4
- Requires at least: 4.3-RC3
5
- Tested up to: 4.4
6
- Stable tag: 2.5
7
 
8
  Multibyte functionality enhancement for the WordPress Japanese package.
9
 
1
  === WP Multibyte Patch ===
2
  Contributors: tenpura
3
  Tags: multibyte,i18n,wp-multibyte-patch,Japanese
4
+ Requires at least: 4.4-RC1
5
+ Tested up to: 4.5
6
+ Stable tag: 2.6
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.5
6
  Plugin URI: http://eastcoder.com/code/wp-multibyte-patch/
7
  Author: Seisuke Kuraishi
8
  Author URI: http://tinybit.co.jp/
@@ -15,9 +15,9 @@ Domain Path: /languages
15
  * Multibyte functionality enhancement for the WordPress Japanese package.
16
  *
17
  * @package WP_Multibyte_Patch
18
- * @version 2.5
19
  * @author Seisuke Kuraishi <210pura@gmail.com>
20
- * @copyright Copyright (c) 2015 Seisuke Kuraishi, Tinybit Inc.
21
  * @license http://opensource.org/licenses/gpl-2.0.php GPLv2
22
  * @link http://eastcoder.com/code/wp-multibyte-patch/
23
  */
@@ -62,7 +62,7 @@ class multibyte_patch {
62
  var $debug_suffix = '';
63
  var $textdomain = 'wp-multibyte-patch';
64
  var $lang_dir = 'languages';
65
- var $required_version = '4.3-RC3';
66
  var $query_based_vars = array();
67
 
68
  // For fallback purpose only. (1.6)
@@ -126,10 +126,10 @@ class multibyte_patch {
126
  return $commentdata;
127
  }
128
 
129
- function pre_remote_source( $linea, $pagelinkedto ) {
130
- $this->pingback_ping_linea = $linea;
131
  $this->pingback_ping_pagelinkedto = $pagelinkedto;
132
- return $linea;
133
  }
134
 
135
  function incoming_pingback( $commentdata ) {
@@ -140,23 +140,23 @@ class multibyte_patch {
140
  return $commentdata;
141
 
142
  $pagelinkedto = $this->pingback_ping_pagelinkedto;
143
- $linea = $this->pingback_ping_linea;
144
 
145
- $linea = preg_replace( "/" . preg_quote( '<!DOC', '/' ) . "/i", '<DOC', $linea );
146
- $linea = preg_replace( "/[\r\n\t ]+/", ' ', $linea );
147
- $linea = preg_replace( "/<\/*(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/i", "\n\n", $linea );
148
 
149
- preg_match( '|<title>([^<]*?)</title>|is', $linea, $matchtitle );
150
  $title = $matchtitle[1];
151
 
152
- preg_match( "/<meta[^<>]+charset=\"*([a-zA-Z0-9\-_]+)\"*[^<>]*>/i", $linea, $matches );
153
  $charset = isset( $matches[1] ) ? $matches[1] : '';
154
- $from_encoding = $this->guess_encoding( strip_tags( $linea ), $charset );
155
  $blog_encoding = $this->blog_encoding;
156
 
157
- $linea = strip_tags( $linea, '<a>' );
158
- $linea = $this->convenc( $linea, $blog_encoding, $from_encoding );
159
- $p = explode( "\n\n", $linea );
160
 
161
  foreach ( $p as $para ) {
162
  if ( strpos( $para, $pagelinkedto ) !== false && preg_match( "/^([^<>]*)(\<a[^<>]+[\"']" . preg_quote( $pagelinkedto, '/' ) . "[\"'][^<>]*\>)([^<>]+)(\<\/a\>)(.*)$/i", $para, $context ) )
@@ -270,12 +270,12 @@ class multibyte_patch {
270
  }
271
 
272
  function wplink_js( &$scripts ) {
273
- $script_required_version = '4.4-RC1';
274
 
275
  if ( !$this->is_wp_required_version( $script_required_version ) )
276
- $scripts->add( 'wplink', plugin_dir_url( __FILE__ ) . "js/20150818/wplink{$this->debug_suffix}.js", array( 'jquery' ), '20150818', 1 );
277
  else
278
- $scripts->add( 'wplink', plugin_dir_url( __FILE__ ) . "js/wplink{$this->debug_suffix}.js", array( 'jquery' ), '20151207', 1 );
279
  }
280
 
281
  function force_character_count( $translations = '', $text = '', $context = '' ) {
2
  /*
3
  Plugin Name: WP Multibyte Patch
4
  Description: Multibyte functionality enhancement for the WordPress Japanese package.
5
+ Version: 2.6
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.6
19
  * @author Seisuke Kuraishi <210pura@gmail.com>
20
+ * @copyright Copyright (c) 2016 Seisuke Kuraishi, Tinybit Inc.
21
  * @license http://opensource.org/licenses/gpl-2.0.php GPLv2
22
  * @link http://eastcoder.com/code/wp-multibyte-patch/
23
  */
62
  var $debug_suffix = '';
63
  var $textdomain = 'wp-multibyte-patch';
64
  var $lang_dir = 'languages';
65
+ var $required_version = '4.4-RC1';
66
  var $query_based_vars = array();
67
 
68
  // For fallback purpose only. (1.6)
126
  return $commentdata;
127
  }
128
 
129
+ function pre_remote_source( $remote_source, $pagelinkedto ) {
130
+ $this->pingback_ping_remote_source = $remote_source;
131
  $this->pingback_ping_pagelinkedto = $pagelinkedto;
132
+ return $remote_source;
133
  }
134
 
135
  function incoming_pingback( $commentdata ) {
140
  return $commentdata;
141
 
142
  $pagelinkedto = $this->pingback_ping_pagelinkedto;
143
+ $remote_source = $this->pingback_ping_remote_source;
144
 
145
+ $remote_source = preg_replace( "/" . preg_quote( '<!DOC', '/' ) . "/i", '<DOC', $remote_source );
146
+ $remote_source = preg_replace( "/[\r\n\t ]+/", ' ', $remote_source );
147
+ $remote_source = preg_replace( "/<\/*(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/i", "\n\n", $remote_source );
148
 
149
+ preg_match( '|<title>([^<]*?)</title>|is', $remote_source, $matchtitle );
150
  $title = $matchtitle[1];
151
 
152
+ preg_match( "/<meta[^<>]+charset=\"*([a-zA-Z0-9\-_]+)\"*[^<>]*>/i", $remote_source, $matches );
153
  $charset = isset( $matches[1] ) ? $matches[1] : '';
154
+ $from_encoding = $this->guess_encoding( strip_tags( $remote_source ), $charset );
155
  $blog_encoding = $this->blog_encoding;
156
 
157
+ $remote_source = strip_tags( $remote_source, '<a>' );
158
+ $remote_source = $this->convenc( $remote_source, $blog_encoding, $from_encoding );
159
+ $p = explode( "\n\n", $remote_source );
160
 
161
  foreach ( $p as $para ) {
162
  if ( strpos( $para, $pagelinkedto ) !== false && preg_match( "/^([^<>]*)(\<a[^<>]+[\"']" . preg_quote( $pagelinkedto, '/' ) . "[\"'][^<>]*\>)([^<>]+)(\<\/a\>)(.*)$/i", $para, $context ) )
270
  }
271
 
272
  function wplink_js( &$scripts ) {
273
+ $script_required_version = '4.5-RC2';
274
 
275
  if ( !$this->is_wp_required_version( $script_required_version ) )
276
+ $scripts->add( 'wplink', plugin_dir_url( __FILE__ ) . "js/20151207/wplink{$this->debug_suffix}.js", array( 'jquery' ), '20151207', 1 );
277
  else
278
+ $scripts->add( 'wplink', plugin_dir_url( __FILE__ ) . "js/wplink{$this->debug_suffix}.js", array( 'jquery', 'wp-a11y' ), '20160411', 1 );
279
  }
280
 
281
  function force_character_count( $translations = '', $text = '', $context = '' ) {