WP Multibyte Patch - Version 2.4

Version Description

Download this release

Release Info

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

Code changes from version 2.3.1 to 2.4

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.3.1
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
@@ -150,11 +150,14 @@ if ( class_exists( 'multibyte_patch' ) ) :
150
  }
151
 
152
  function wp_trim_words( $text = '', $num_words = 110, $more = '', $original_text = '' ) {
153
- if ( 'characters' != _x( 'words', 'word count: words or characters?' ) )
 
 
 
154
  return $text;
155
 
156
  // If the caller is wp_dashboard_recent_drafts()
157
- if( false !== $this->conf['patch_dashboard_recent_drafts'] && 10 === $num_words && is_admin() && strpos( wp_debug_backtrace_summary(), 'wp_dashboard_recent_drafts' ) )
158
  $num_words = $this->conf['dashboard_recent_drafts_mblength'];
159
 
160
  $text = $original_text;
3
  * WP Multibyte Patch Japanese Locale Extension
4
  *
5
  * @package WP_Multibyte_Patch
6
+ * @version 2.4
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
150
  }
151
 
152
  function wp_trim_words( $text = '', $num_words = 110, $more = '', $original_text = '' ) {
153
+ if (
154
+ $this->is_wp_required_version( '4.3-RC1' ) && 0 !== strpos( _x( 'words', 'Word count type. Do not translate!' ), 'characters' ) ||
155
+ !$this->is_wp_required_version( '4.3-RC1' ) && 'characters' != _x( 'words', 'word count: words or characters?' )
156
+ )
157
  return $text;
158
 
159
  // If the caller is wp_dashboard_recent_drafts()
160
+ if ( false !== $this->conf['patch_dashboard_recent_drafts'] && 10 === $num_words && is_admin() && strpos( wp_debug_backtrace_summary(), 'wp_dashboard_recent_drafts' ) )
161
  $num_words = $this->conf['dashboard_recent_drafts_mblength'];
162
 
163
  $text = $original_text;
js/20131219/word-count.js ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* global wordCountL10n */
2
+ var wpWordCount;
3
+ (function($,undefined) {
4
+ wpWordCount = {
5
+
6
+ settings : {
7
+ strip : /<[a-zA-Z\/][^<>]*>/g, // strip HTML tags
8
+ clean : /[0-9.(),;:!?%#$¿'"_+=\\/-]+/g, // regexp to remove punctuation, etc.
9
+ count : /\S\s+/g // word-counting regexp
10
+ },
11
+
12
+ block : 0,
13
+
14
+ wc : function(tx, type) {
15
+ var t = this, w = $('.word-count'), tc = 0;
16
+
17
+ if ( type === undefined )
18
+ type = wordCountL10n.type;
19
+ if ( type !== 'w' && type !== 'c' )
20
+ type = 'w';
21
+
22
+ if ( t.block )
23
+ return;
24
+
25
+ t.block = 1;
26
+
27
+ setTimeout( function() {
28
+ if ( tx ) {
29
+ if ( type == 'w' ) { // word-counting
30
+ tx = tx.replace( t.settings.strip, ' ' ).replace( /&nbsp;|&#160;/gi, ' ' );
31
+ tx = tx.replace( t.settings.clean, '' );
32
+ tx.replace( t.settings.count, function(){tc++;} );
33
+ }
34
+ else if ( type == 'c' ) { // char-counting for asian languages
35
+ tx = tx.replace( t.settings.strip, '' ).replace( /^ +| +$/gm, '' );
36
+ tx = tx.replace( / +|&nbsp;|&#160;/gi, ' ' );
37
+ tx.replace( /[\S \u00A0\u3000]/g, function(){tc++;} );
38
+ }
39
+ }
40
+ w.html(tc.toString());
41
+
42
+ setTimeout( function() { t.block = 0; }, 2000 );
43
+ }, 1 );
44
+ }
45
+ };
46
+
47
+ $(document).bind( 'wpcountwords', function(e, txt) {
48
+ wpWordCount.wc(txt);
49
+ });
50
+ }(jQuery));
js/20131219/word-count.min.js ADDED
@@ -0,0 +1 @@
 
1
+ var wpWordCount;(function(a,b){wpWordCount={settings:{strip:/<[a-zA-Z\/][^<>]*>/g,clean:/[0-9.(),;:!?%#$¿'"_+=\\/-]+/g,count:/\S\s+/g},block:0,wc:function(e,g){var f=this,d=a(".word-count"),c=0;if(g===b){g=wordCountL10n.type}if(g!=="w"&&g!=="c"){g="w"}if(f.block){return}f.block=1;setTimeout(function(){if(e){if(g=="w"){e=e.replace(f.settings.strip," ").replace(/&nbsp;|&#160;/gi," ");e=e.replace(f.settings.clean,"");e.replace(f.settings.count,function(){c++})}else{if(g=="c"){e=e.replace(f.settings.strip,"").replace(/^ +| +$/gm,"");e=e.replace(/ +|&nbsp;|&#160;/gi," ");e.replace(/[\S \u00A0\u3000]/g,function(){c++})}}}d.html(c.toString());setTimeout(function(){f.block=0},2000)},1)}};a(document).bind("wpcountwords",function(d,c){wpWordCount.wc(c)})}(jQuery));
js/20141213/wplink.min.js DELETED
@@ -1 +0,0 @@
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;a(document.body).addClass("modal-open"),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(){a(document.body).removeClass("modal-open"),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);
 
js/{20141213 → 20150424}/wplink.js RENAMED
@@ -2,11 +2,15 @@
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,
12
  minRiverAJAXDuration: 200,
@@ -21,14 +25,14 @@ var wpLink;
21
  inputs.backdrop = $( '#wp-link-backdrop' );
22
  inputs.submit = $( '#wp-link-submit' );
23
  inputs.close = $( '#wp-link-close' );
24
- // URL
25
- inputs.url = $( '#url-field' );
 
 
26
  inputs.nonce = $( '#_ajax_linking_nonce' );
27
- // Secondary options
28
- inputs.title = $( '#link-title-field' );
29
- // Advanced Options
30
- inputs.openInNewTab = $( '#link-target-checkbox' );
31
- inputs.search = $( '#search-field' );
32
  // Build Rivers
33
  rivers.search = new River( $( '#search-results' ) );
34
  rivers.recent = new River( $( '#most-recent-results' ) );
@@ -72,6 +76,21 @@ var wpLink;
72
  wpLink.searchInternalLinks.call( self );
73
  }, 500 );
74
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  },
76
 
77
  open: function( editorId ) {
@@ -114,6 +133,7 @@ var wpLink;
114
  inputs.backdrop.show();
115
 
116
  wpLink.refresh();
 
117
  $( document ).trigger( 'wplink-open', inputs.wrap );
118
  },
119
 
@@ -122,6 +142,8 @@ var wpLink;
122
  },
123
 
124
  refresh: function() {
 
 
125
  // Refresh rivers (clear links, check visibility)
126
  rivers.search.refresh();
127
  rivers.recent.refresh();
@@ -129,6 +151,21 @@ var wpLink;
129
  if ( wpLink.isMCE() ) {
130
  wpLink.mceRefresh();
131
  } else {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  wpLink.setDefaultValues();
133
  }
134
 
@@ -146,24 +183,57 @@ var wpLink;
146
  if ( ! rivers.recent.ul.children().length ) {
147
  rivers.recent.ajax();
148
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  },
150
 
151
  mceRefresh: function() {
152
- var e;
153
-
154
- // If link exists, select proper values.
155
- if ( e = editor.dom.getParent( editor.selection.getNode(), 'A' ) ) {
156
- // Set URL and description.
157
- inputs.url.val( editor.dom.getAttrib( e, 'href' ) );
158
- inputs.title.val( editor.dom.getAttrib( e, 'title' ) );
159
- // Set open in new tab.
160
- inputs.openInNewTab.prop( 'checked', ( '_blank' === editor.dom.getAttrib( e, 'target' ) ) );
161
- // Update save prompt.
162
  inputs.submit.val( wpLinkL10n.update );
 
 
 
 
163
 
164
- // If there's no link, set the default values.
 
 
165
  } else {
166
- wpLink.setDefaultValues();
 
167
  }
168
  },
169
 
@@ -183,45 +253,46 @@ var wpLink;
183
 
184
  inputs.backdrop.hide();
185
  inputs.wrap.hide();
 
 
 
186
  $( document ).trigger( 'wplink-close', inputs.wrap );
187
  },
188
 
189
  getAttrs: function() {
190
  return {
191
- href: inputs.url.val(),
192
- title: inputs.title.val(),
193
  target: inputs.openInNewTab.prop( 'checked' ) ? '_blank' : ''
194
  };
195
  },
196
 
197
  update: function() {
198
- if ( wpLink.isMCE() )
199
  wpLink.mceUpdate();
200
- else
201
  wpLink.htmlUpdate();
 
202
  },
203
 
204
  htmlUpdate: function() {
205
- var attrs, html, begin, end, cursor, title, selection,
206
  textarea = wpLink.textarea;
207
 
208
- if ( ! textarea )
209
  return;
 
210
 
211
  attrs = wpLink.getAttrs();
 
212
 
213
  // If there's no href, return.
214
- if ( ! attrs.href || attrs.href == 'http://' )
215
  return;
 
216
 
217
  // Build HTML
218
  html = '<a href="' + attrs.href + '"';
219
 
220
- if ( attrs.title ) {
221
- title = attrs.title.replace( /</g, '&lt;' ).replace( />/g, '&gt;' ).replace( /"/g, '&quot;' );
222
- html += ' title="' + title + '"';
223
- }
224
-
225
  if ( attrs.target ) {
226
  html += ' target="' + attrs.target + '"';
227
  }
@@ -234,25 +305,29 @@ var wpLink;
234
  // Note: If no text is selected, IE will not place the cursor
235
  // inside the closing tag.
236
  textarea.focus();
237
- wpLink.range.text = html + wpLink.range.text + '</a>';
238
  wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
239
  wpLink.range.select();
240
 
241
  wpLink.range = null;
242
  } else if ( typeof textarea.selectionStart !== 'undefined' ) {
243
  // W3C
244
- begin = textarea.selectionStart;
245
- end = textarea.selectionEnd;
246
- selection = textarea.value.substring( begin, end );
247
- html = html + selection + '</a>';
248
- cursor = begin + html.length;
249
 
250
  // If no text is selected, place the cursor inside the closing tag.
251
- if ( begin == end )
252
- cursor -= '</a>'.length;
 
253
 
254
- textarea.value = textarea.value.substring( 0, begin ) + html +
255
- textarea.value.substring( end, textarea.value.length );
 
 
 
256
 
257
  // Update cursor position
258
  textarea.selectionStart = textarea.selectionEnd = cursor;
@@ -263,8 +338,8 @@ var wpLink;
263
  },
264
 
265
  mceUpdate: function() {
266
- var link,
267
- attrs = wpLink.getAttrs();
268
 
269
  wpLink.close();
270
  editor.focus();
@@ -273,34 +348,50 @@ var wpLink;
273
  editor.selection.moveToBookmark( editor.windowManager.bookmark );
274
  }
275
 
276
- link = editor.dom.getParent( editor.selection.getNode(), 'a[href]' );
277
-
278
- // If the values are empty, unlink and return
279
- if ( ! attrs.href || attrs.href == 'http://' ) {
280
  editor.execCommand( 'unlink' );
281
  return;
282
  }
283
 
 
 
 
284
  if ( link ) {
 
 
 
 
 
 
 
 
285
  editor.dom.setAttribs( link, attrs );
286
  } else {
287
- editor.execCommand( 'mceInsertLink', false, attrs );
 
 
 
 
288
  }
289
-
290
- // Move the cursor to the end of the selection
291
- editor.selection.collapse();
292
  },
293
 
294
  updateFields: function( e, li ) {
295
  inputs.url.val( li.children( '.item-permalink' ).val() );
296
- inputs.title.val( li.hasClass( 'no-title' ) ? '' : li.children( '.item-title' ).text() );
297
  },
298
 
299
  setDefaultValues: function() {
300
- var selection = editor && editor.selection.getContent(),
301
  emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
302
  urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i;
303
 
 
 
 
 
 
 
 
 
304
  if ( selection && emailRegexp.test( selection ) ) {
305
  // Selection is email address
306
  inputs.url.val( 'mailto:' + selection );
@@ -309,12 +400,9 @@ var wpLink;
309
  inputs.url.val( selection.replace( /&amp;|&#0?38;/gi, '&' ) );
310
  } else {
311
  // Set URL to default.
312
- inputs.url.val( 'http://' );
313
  }
314
 
315
- // Set description to default.
316
- inputs.title.val( '' );
317
-
318
  // Update save prompt.
319
  inputs.submit.val( wpLinkL10n.save );
320
  },
@@ -332,11 +420,11 @@ var wpLink;
332
  return;
333
 
334
  wpLink.lastSearch = search;
335
- waiting = t.parent().find('.spinner').show();
336
 
337
  rivers.search.change( search );
338
  rivers.search.ajax( function() {
339
- waiting.hide();
340
  });
341
  } else {
342
  rivers.search.hide();
@@ -572,11 +660,11 @@ var wpLink;
572
  if ( ! self.query.ready() || newBottom < self.contentHeight.height() - wpLink.riverBottomThreshold )
573
  return;
574
 
575
- self.waiting.show();
576
  el.scrollTop( newTop + self.waiting.outerHeight() );
577
 
578
  self.ajax( function() {
579
- self.waiting.hide();
580
  });
581
  }, wpLink.timeToTriggerRiver );
582
  }
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 = {
15
  timeToTriggerRiver: 150,
16
  minRiverAJAXDuration: 200,
25
  inputs.backdrop = $( '#wp-link-backdrop' );
26
  inputs.submit = $( '#wp-link-submit' );
27
  inputs.close = $( '#wp-link-close' );
28
+
29
+ // Input
30
+ inputs.text = $( '#wp-link-text' );
31
+ inputs.url = $( '#wp-link-url' );
32
  inputs.nonce = $( '#_ajax_linking_nonce' );
33
+ inputs.openInNewTab = $( '#wp-link-target' );
34
+ inputs.search = $( '#wp-link-search' );
35
+
 
 
36
  // Build Rivers
37
  rivers.search = new River( $( '#search-results' ) );
38
  rivers.recent = new River( $( '#most-recent-results' ) );
76
  wpLink.searchInternalLinks.call( self );
77
  }, 500 );
78
  });
79
+
80
+ function correctURL() {
81
+ var url = $.trim( inputs.url.val() );
82
+
83
+ if ( url && correctedURL !== url && ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( url ) ) {
84
+ inputs.url.val( 'http://' + url );
85
+ correctedURL = url;
86
+ }
87
+ }
88
+
89
+ inputs.url.on( 'paste', function() {
90
+ setTimeout( correctURL, 0 );
91
+ } );
92
+
93
+ inputs.url.on( 'blur', correctURL );
94
  },
95
 
96
  open: function( editorId ) {
133
  inputs.backdrop.show();
134
 
135
  wpLink.refresh();
136
+
137
  $( document ).trigger( 'wplink-open', inputs.wrap );
138
  },
139
 
142
  },
143
 
144
  refresh: function() {
145
+ var text = '';
146
+
147
  // Refresh rivers (clear links, check visibility)
148
  rivers.search.refresh();
149
  rivers.recent.refresh();
151
  if ( wpLink.isMCE() ) {
152
  wpLink.mceRefresh();
153
  } else {
154
+ // For the Text editor the "Link text" field is always shown
155
+ if ( ! inputs.wrap.hasClass( 'has-text-field' ) ) {
156
+ inputs.wrap.addClass( 'has-text-field' );
157
+ }
158
+
159
+ if ( document.selection ) {
160
+ // Old IE
161
+ text = document.selection.createRange().text || '';
162
+ } else if ( typeof this.textarea.selectionStart !== 'undefined' &&
163
+ ( this.textarea.selectionStart !== this.textarea.selectionEnd ) ) {
164
+ // W3C
165
+ text = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd ) || '';
166
+ }
167
+
168
+ inputs.text.val( text );
169
  wpLink.setDefaultValues();
170
  }
171
 
183
  if ( ! rivers.recent.ul.children().length ) {
184
  rivers.recent.ajax();
185
  }
186
+
187
+ correctedURL = inputs.url.val().replace( /^http:\/\//, '' );
188
+ },
189
+
190
+ hasSelectedText: function( linkNode ) {
191
+ var html = editor.selection.getContent();
192
+
193
+ // Partial html and not a fully selected anchor element
194
+ if ( /</.test( html ) && ( ! /^<a [^>]+>[^<]+<\/a>$/.test( html ) || html.indexOf('href=') === -1 ) ) {
195
+ return false;
196
+ }
197
+
198
+ if ( linkNode ) {
199
+ var nodes = linkNode.childNodes, i;
200
+
201
+ if ( nodes.length === 0 ) {
202
+ return false;
203
+ }
204
+
205
+ for ( i = nodes.length - 1; i >= 0; i-- ) {
206
+ if ( nodes[i].nodeType != 3 ) {
207
+ return false;
208
+ }
209
+ }
210
+ }
211
+
212
+ return true;
213
  },
214
 
215
  mceRefresh: function() {
216
+ var text,
217
+ selectedNode = editor.selection.getNode(),
218
+ linkNode = editor.dom.getParent( selectedNode, 'a[href]' ),
219
+ onlyText = this.hasSelectedText( linkNode );
220
+
221
+ if ( linkNode ) {
222
+ text = linkNode.innerText || linkNode.textContent;
223
+ inputs.url.val( editor.dom.getAttrib( linkNode, 'href' ) );
224
+ inputs.openInNewTab.prop( 'checked', '_blank' === editor.dom.getAttrib( linkNode, 'target' ) );
 
225
  inputs.submit.val( wpLinkL10n.update );
226
+ } else {
227
+ text = editor.selection.getContent({ format: 'text' });
228
+ this.setDefaultValues();
229
+ }
230
 
231
+ if ( onlyText ) {
232
+ inputs.text.val( text || '' );
233
+ inputs.wrap.addClass( 'has-text-field' );
234
  } else {
235
+ inputs.text.val( '' );
236
+ inputs.wrap.removeClass( 'has-text-field' );
237
  }
238
  },
239
 
253
 
254
  inputs.backdrop.hide();
255
  inputs.wrap.hide();
256
+
257
+ correctedURL = false;
258
+
259
  $( document ).trigger( 'wplink-close', inputs.wrap );
260
  },
261
 
262
  getAttrs: function() {
263
  return {
264
+ href: $.trim( inputs.url.val() ),
 
265
  target: inputs.openInNewTab.prop( 'checked' ) ? '_blank' : ''
266
  };
267
  },
268
 
269
  update: function() {
270
+ if ( wpLink.isMCE() ) {
271
  wpLink.mceUpdate();
272
+ } else {
273
  wpLink.htmlUpdate();
274
+ }
275
  },
276
 
277
  htmlUpdate: function() {
278
+ var attrs, text, html, begin, end, cursor, selection,
279
  textarea = wpLink.textarea;
280
 
281
+ if ( ! textarea ) {
282
  return;
283
+ }
284
 
285
  attrs = wpLink.getAttrs();
286
+ text = inputs.text.val();
287
 
288
  // If there's no href, return.
289
+ if ( ! attrs.href ) {
290
  return;
291
+ }
292
 
293
  // Build HTML
294
  html = '<a href="' + attrs.href + '"';
295
 
 
 
 
 
 
296
  if ( attrs.target ) {
297
  html += ' target="' + attrs.target + '"';
298
  }
305
  // Note: If no text is selected, IE will not place the cursor
306
  // inside the closing tag.
307
  textarea.focus();
308
+ wpLink.range.text = html + ( text || wpLink.range.text ) + '</a>';
309
  wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
310
  wpLink.range.select();
311
 
312
  wpLink.range = null;
313
  } else if ( typeof textarea.selectionStart !== 'undefined' ) {
314
  // W3C
315
+ begin = textarea.selectionStart;
316
+ end = textarea.selectionEnd;
317
+ selection = text || textarea.value.substring( begin, end );
318
+ html = html + selection + '</a>';
319
+ cursor = begin + html.length;
320
 
321
  // If no text is selected, place the cursor inside the closing tag.
322
+ if ( begin === end && ! selection ) {
323
+ cursor -= 4;
324
+ }
325
 
326
+ textarea.value = (
327
+ textarea.value.substring( 0, begin ) +
328
+ html +
329
+ textarea.value.substring( end, textarea.value.length )
330
+ );
331
 
332
  // Update cursor position
333
  textarea.selectionStart = textarea.selectionEnd = cursor;
338
  },
339
 
340
  mceUpdate: function() {
341
+ var attrs = wpLink.getAttrs(),
342
+ link, text;
343
 
344
  wpLink.close();
345
  editor.focus();
348
  editor.selection.moveToBookmark( editor.windowManager.bookmark );
349
  }
350
 
351
+ if ( ! attrs.href ) {
 
 
 
352
  editor.execCommand( 'unlink' );
353
  return;
354
  }
355
 
356
+ link = getLink();
357
+ text = inputs.text.val();
358
+
359
  if ( link ) {
360
+ if ( text ) {
361
+ if ( 'innerText' in link ) {
362
+ link.innerText = text;
363
+ } else {
364
+ link.textContent = text;
365
+ }
366
+ }
367
+
368
  editor.dom.setAttribs( link, attrs );
369
  } else {
370
+ if ( text ) {
371
+ editor.selection.setNode( editor.dom.create( 'a', attrs, text ) );
372
+ } else {
373
+ editor.execCommand( 'mceInsertLink', false, attrs );
374
+ }
375
  }
 
 
 
376
  },
377
 
378
  updateFields: function( e, li ) {
379
  inputs.url.val( li.children( '.item-permalink' ).val() );
 
380
  },
381
 
382
  setDefaultValues: function() {
383
+ var selection,
384
  emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
385
  urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i;
386
 
387
+ if ( this.isMCE() ) {
388
+ selection = editor.selection.getContent();
389
+ } else if ( document.selection && wpLink.range ) {
390
+ selection = wpLink.range.text;
391
+ } else if ( typeof this.textarea.selectionStart !== 'undefined' ) {
392
+ selection = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd );
393
+ }
394
+
395
  if ( selection && emailRegexp.test( selection ) ) {
396
  // Selection is email address
397
  inputs.url.val( 'mailto:' + selection );
400
  inputs.url.val( selection.replace( /&amp;|&#0?38;/gi, '&' ) );
401
  } else {
402
  // Set URL to default.
403
+ inputs.url.val( '' );
404
  }
405
 
 
 
 
406
  // Update save prompt.
407
  inputs.submit.val( wpLinkL10n.save );
408
  },
420
  return;
421
 
422
  wpLink.lastSearch = search;
423
+ waiting = t.parent().find( '.spinner' ).addClass( 'is-active' );
424
 
425
  rivers.search.change( search );
426
  rivers.search.ajax( function() {
427
+ waiting.removeClass( 'is-active' );
428
  });
429
  } else {
430
  rivers.search.hide();
660
  if ( ! self.query.ready() || newBottom < self.contentHeight.height() - wpLink.riverBottomThreshold )
661
  return;
662
 
663
+ self.waiting.addClass( 'is-active' );
664
  el.scrollTop( newTop + self.waiting.outerHeight() );
665
 
666
  self.ajax( function() {
667
+ self.waiting.removeClass( 'is-active' );
668
  });
669
  }, wpLink.timeToTriggerRiver );
670
  }
js/20150424/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(){function b(){var b=a.trim(h.url.val());b&&g!==b&&!/^(?:[a-z]+:|#|\?|\.|\/)/.test(b)&&(h.url.val("http://"+b),g=b)}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.keyup(function(){var a=this;window.clearTimeout(d),d=window.setTimeout(function(){wpLink.searchInternalLinks.call(a)},500)}),h.url.on("paste",function(){setTimeout(b,0)}),h.url.on("blur",b)},open:function(b){var d;a(document.body).addClass("modal-open"),wpLink.range=null,b&&(window.wpActiveEditor=b),window.wpActiveEditor&&(this.textarea=a("#"+window.wpActiveEditor).get(0),"undefined"!=typeof tinymce&&(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{href:a.trim(h.url.val()),target:h.openInNewTab.prop("checked")?"_blank":""}},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='<a href="'+a.href+'"',a.target&&(c+=' target="'+a.target+'"'),c+=">",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(),d=h.text.val(),void(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.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)),h.url.val(a&&b.test(a)?"mailto:"+a:a&&d.test(a)?a.replace(/&amp;|&#0?38;/gi,"&"):""),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/word-count.js CHANGED
@@ -1,50 +1,112 @@
1
- /* global wordCountL10n */
2
- var wpWordCount;
3
- (function($,undefined) {
4
- wpWordCount = {
5
-
6
- settings : {
7
- strip : /<[a-zA-Z\/][^<>]*>/g, // strip HTML tags
8
- clean : /[0-9.(),;:!?%#$¿'"_+=\\/-]+/g, // regexp to remove punctuation, etc.
9
- count : /\S\s+/g // word-counting regexp
10
- },
11
-
12
- block : 0,
13
-
14
- wc : function(tx, type) {
15
- var t = this, w = $('.word-count'), tc = 0;
16
-
17
- if ( type === undefined )
18
- type = wordCountL10n.type;
19
- if ( type !== 'w' && type !== 'c' )
20
- type = 'w';
21
-
22
- if ( t.block )
23
- return;
24
-
25
- t.block = 1;
26
-
27
- setTimeout( function() {
28
- if ( tx ) {
29
- if ( type == 'w' ) { // word-counting
30
- tx = tx.replace( t.settings.strip, ' ' ).replace( /&nbsp;|&#160;/gi, ' ' );
31
- tx = tx.replace( t.settings.clean, '' );
32
- tx.replace( t.settings.count, function(){tc++;} );
33
- }
34
- else if ( type == 'c' ) { // char-counting for asian languages
35
- tx = tx.replace( t.settings.strip, '' ).replace( /^ +| +$/gm, '' );
36
- tx = tx.replace( / +|&nbsp;|&#160;/gi, ' ' );
37
- tx.replace( /[\S \u00A0\u3000]/g, function(){tc++;} );
38
- }
39
  }
40
- w.html(tc.toString());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
- setTimeout( function() { t.block = 0; }, 2000 );
43
- }, 1 );
44
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  };
46
 
47
- $(document).bind( 'wpcountwords', function(e, txt) {
48
- wpWordCount.wc(txt);
49
- });
50
- }(jQuery));
1
+ ( function() {
2
+ function WordCounter( settings ) {
3
+ var key,
4
+ shortcodes;
5
+
6
+ if ( settings ) {
7
+ for ( key in settings ) {
8
+ if ( settings.hasOwnProperty( key ) ) {
9
+ this.settings[ key ] = settings[ key ];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  }
11
+ }
12
+ }
13
+
14
+ shortcodes = this.settings.l10n.shortcodes;
15
+
16
+ if ( shortcodes && shortcodes.length ) {
17
+ this.settings.shortcodesRegExp = new RegExp( '\\[\\/?(?:' + shortcodes.join( '|' ) + ')[^\\]]*?\\]', 'g' );
18
+ }
19
+ }
20
+
21
+ WordCounter.prototype.settings = {
22
+ HTMLRegExp: /<\/?[a-z][^>]*?>/gi,
23
+ HTMLcommentRegExp: /<!--[\s\S]*?-->/g,
24
+ spaceRegExp: /&nbsp;|&#160;/gi,
25
+ HTMLEntityRegExp: /&\S+?;/g,
26
+ connectorRegExp: /--|\u2014/g,
27
+ removeRegExp: new RegExp( [
28
+ '[',
29
+ // Basic Latin (extract)
30
+ '\u0021-\u0040\u005B-\u0060\u007B-\u007E',
31
+ // Latin-1 Supplement (extract)
32
+ '\u0080-\u00BF\u00D7\u00F7',
33
+ // General Punctuation
34
+ // Superscripts and Subscripts
35
+ // Currency Symbols
36
+ // Combining Diacritical Marks for Symbols
37
+ // Letterlike Symbols
38
+ // Number Forms
39
+ // Arrows
40
+ // Mathematical Operators
41
+ // Miscellaneous Technical
42
+ // Control Pictures
43
+ // Optical Character Recognition
44
+ // Enclosed Alphanumerics
45
+ // Box Drawing
46
+ // Block Elements
47
+ // Geometric Shapes
48
+ // Miscellaneous Symbols
49
+ // Dingbats
50
+ // Miscellaneous Mathematical Symbols-A
51
+ // Supplemental Arrows-A
52
+ // Braille Patterns
53
+ // Supplemental Arrows-B
54
+ // Miscellaneous Mathematical Symbols-B
55
+ // Supplemental Mathematical Operators
56
+ // Miscellaneous Symbols and Arrows
57
+ '\u2000-\u2BFF',
58
+ // Supplemental Punctuation
59
+ '\u2E00-\u2E7F',
60
+ ']'
61
+ ].join( '' ), 'g' ),
62
+ astralRegExp: /[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
63
+ wordsRegExp: /\S\s+/g,
64
+ characters_excluding_spacesRegExp: /\S/g,
65
+ characters_including_spacesRegExp: /[^\f\n\r\t\v\u00AD\u2028\u2029]/g,
66
+ l10n: window.wordCountL10n || {}
67
+ };
68
+
69
+ WordCounter.prototype.count = function( text, type ) {
70
+ var count = 0;
71
+
72
+ type = type || this.settings.l10n.type;
73
 
74
+ if ( type !== 'characters_excluding_spaces' && type !== 'characters_including_spaces' ) {
75
+ type = 'words';
76
  }
77
+
78
+ if ( text ) {
79
+ text = text + '\n';
80
+
81
+ text = text.replace( this.settings.HTMLRegExp, '\n' );
82
+ text = text.replace( this.settings.HTMLcommentRegExp, '' );
83
+
84
+ if ( this.settings.shortcodesRegExp ) {
85
+ text = text.replace( this.settings.shortcodesRegExp, '\n' );
86
+ }
87
+
88
+ text = text.replace( this.settings.spaceRegExp, ' ' );
89
+
90
+ if ( type === 'words' ) {
91
+ text = text.replace( this.settings.HTMLEntityRegExp, '' );
92
+ text = text.replace( this.settings.connectorRegExp, ' ' );
93
+ text = text.replace( this.settings.removeRegExp, '' );
94
+ } else {
95
+ text = text.replace( this.settings.HTMLEntityRegExp, 'a' );
96
+ text = text.replace( this.settings.astralRegExp, 'a' );
97
+ }
98
+
99
+ text = text.match( this.settings[ type + 'RegExp' ] );
100
+
101
+ if ( text ) {
102
+ count = text.length;
103
+ }
104
+ }
105
+
106
+ return count;
107
  };
108
 
109
+ window.wp = window.wp || {};
110
+ window.wp.utils = window.wp.utils || {};
111
+ window.wp.utils.WordCounter = WordCounter;
112
+ } )();
js/word-count.min.js CHANGED
@@ -1 +1 @@
1
- var wpWordCount;(function(a,b){wpWordCount={settings:{strip:/<[a-zA-Z\/][^<>]*>/g,clean:/[0-9.(),;:!?%#$¿'"_+=\\/-]+/g,count:/\S\s+/g},block:0,wc:function(e,g){var f=this,d=a(".word-count"),c=0;if(g===b){g=wordCountL10n.type}if(g!=="w"&&g!=="c"){g="w"}if(f.block){return}f.block=1;setTimeout(function(){if(e){if(g=="w"){e=e.replace(f.settings.strip," ").replace(/&nbsp;|&#160;/gi," ");e=e.replace(f.settings.clean,"");e.replace(f.settings.count,function(){c++})}else{if(g=="c"){e=e.replace(f.settings.strip,"").replace(/^ +| +$/gm,"");e=e.replace(/ +|&nbsp;|&#160;/gi," ");e.replace(/[\S \u00A0\u3000]/g,function(){c++})}}}d.html(c.toString());setTimeout(function(){f.block=0},2000)},1)}};a(document).bind("wpcountwords",function(d,c){wpWordCount.wc(c)})}(jQuery));
1
+ !function(){function a(a){var b,c;if(a)for(b in a)a.hasOwnProperty(b)&&(this.settings[b]=a[b]);c=this.settings.l10n.shortcodes,c&&c.length&&(this.settings.shortcodesRegExp=new RegExp("\\[\\/?(?:"+c.join("|")+")[^\\]]*?\\]","g"))}a.prototype.settings={HTMLRegExp:/<\/?[a-z][^>]*?>/gi,HTMLcommentRegExp:/<!--[\s\S]*?-->/g,spaceRegExp:/&nbsp;|&#160;/gi,HTMLEntityRegExp:/&\S+?;/g,connectorRegExp:/--|\u2014/g,removeRegExp:new RegExp(["[","!-@[-`{-~","\x80-\xbf\xd7\xf7","\u2000-\u2bff","\u2e00-\u2e7f","]"].join(""),"g"),astralRegExp:/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,wordsRegExp:/\S\s+/g,characters_excluding_spacesRegExp:/\S/g,characters_including_spacesRegExp:/[^\f\n\r\t\v\u00AD\u2028\u2029]/g,l10n:window.wordCountL10n||{}},a.prototype.count=function(a,b){var c=0;return b=b||this.settings.l10n.type,"characters_excluding_spaces"!==b&&"characters_including_spaces"!==b&&(b="words"),a&&(a+="\n",a=a.replace(this.settings.HTMLRegExp,"\n"),a=a.replace(this.settings.HTMLcommentRegExp,""),this.settings.shortcodesRegExp&&(a=a.replace(this.settings.shortcodesRegExp,"\n")),a=a.replace(this.settings.spaceRegExp," "),"words"===b?(a=a.replace(this.settings.HTMLEntityRegExp,""),a=a.replace(this.settings.connectorRegExp," "),a=a.replace(this.settings.removeRegExp,"")):(a=a.replace(this.settings.HTMLEntityRegExp,"a"),a=a.replace(this.settings.astralRegExp,"a")),a=a.match(this.settings[b+"RegExp"]),a&&(c=a.length)),c},window.wp=window.wp||{},window.wp.utils=window.wp.utils||{},window.wp.utils.WordCounter=a}();
js/wplink.js CHANGED
@@ -68,7 +68,7 @@ var wpLink;
68
  inputs.queryNoticeTextHint.addClass( 'screen-reader-text' ).hide();
69
  } );
70
 
71
- inputs.search.keyup( function() {
72
  var self = this;
73
 
74
  window.clearTimeout( searchTimer );
@@ -77,26 +77,28 @@ var wpLink;
77
  }, 500 );
78
  });
79
 
80
- function correctURL() {
81
- var url = $.trim( inputs.url.val() );
82
-
83
- if ( url && correctedURL !== url && ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( url ) ) {
84
- inputs.url.val( 'http://' + url );
85
- correctedURL = url;
86
- }
87
- }
88
-
89
  inputs.url.on( 'paste', function() {
90
- setTimeout( correctURL, 0 );
91
  } );
92
 
93
- inputs.url.on( 'blur', correctURL );
 
 
 
 
 
 
 
 
 
 
94
  },
95
 
96
  open: function( editorId ) {
97
- var ed;
 
98
 
99
- $( document.body ).addClass( 'modal-open' );
100
 
101
  wpLink.range = null;
102
 
@@ -111,6 +113,10 @@ var wpLink;
111
  this.textarea = $( '#' + window.wpActiveEditor ).get( 0 );
112
 
113
  if ( typeof tinymce !== 'undefined' ) {
 
 
 
 
114
  ed = tinymce.get( wpActiveEditor );
115
 
116
  if ( ed && ! ed.isHidden() ) {
@@ -260,12 +266,24 @@ var wpLink;
260
  },
261
 
262
  getAttrs: function() {
 
 
263
  return {
264
  href: $.trim( inputs.url.val() ),
265
  target: inputs.openInNewTab.prop( 'checked' ) ? '_blank' : ''
266
  };
267
  },
268
 
 
 
 
 
 
 
 
 
 
 
269
  update: function() {
270
  if ( wpLink.isMCE() ) {
271
  wpLink.mceUpdate();
@@ -290,14 +308,7 @@ var wpLink;
290
  return;
291
  }
292
 
293
- // Build HTML
294
- html = '<a href="' + attrs.href + '"';
295
-
296
- if ( attrs.target ) {
297
- html += ' target="' + attrs.target + '"';
298
- }
299
-
300
- html += '>';
301
 
302
  // Insert HTML
303
  if ( document.selection && wpLink.range ) {
@@ -354,7 +365,10 @@ var wpLink;
354
  }
355
 
356
  link = getLink();
357
- text = inputs.text.val();
 
 
 
358
 
359
  if ( link ) {
360
  if ( text ) {
@@ -373,6 +387,8 @@ var wpLink;
373
  editor.execCommand( 'mceInsertLink', false, attrs );
374
  }
375
  }
 
 
376
  },
377
 
378
  updateFields: function( e, li ) {
68
  inputs.queryNoticeTextHint.addClass( 'screen-reader-text' ).hide();
69
  } );
70
 
71
+ inputs.search.on( 'keyup input', function() {
72
  var self = this;
73
 
74
  window.clearTimeout( searchTimer );
77
  }, 500 );
78
  });
79
 
 
 
 
 
 
 
 
 
 
80
  inputs.url.on( 'paste', function() {
81
+ setTimeout( wpLink.correctURL, 0 );
82
  } );
83
 
84
+ inputs.url.on( 'blur', wpLink.correctURL );
85
+ },
86
+
87
+ // If URL wasn't corrected last time and doesn't start with http:, https:, ? # or /, prepend http://
88
+ correctURL: function () {
89
+ var url = $.trim( inputs.url.val() );
90
+
91
+ if ( url && correctedURL !== url && ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( url ) ) {
92
+ inputs.url.val( 'http://' + url );
93
+ correctedURL = url;
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
 
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() ) {
266
  },
267
 
268
  getAttrs: function() {
269
+ wpLink.correctURL();
270
+
271
  return {
272
  href: $.trim( inputs.url.val() ),
273
  target: inputs.openInNewTab.prop( 'checked' ) ? '_blank' : ''
274
  };
275
  },
276
 
277
+ buildHtml: function(attrs) {
278
+ var html = '<a href="' + attrs.href + '"';
279
+
280
+ if ( attrs.target ) {
281
+ html += ' target="' + attrs.target + '"';
282
+ }
283
+
284
+ return html + '>';
285
+ },
286
+
287
  update: function() {
288
  if ( wpLink.isMCE() ) {
289
  wpLink.mceUpdate();
308
  return;
309
  }
310
 
311
+ html = wpLink.buildHtml(attrs);
 
 
 
 
 
 
 
312
 
313
  // Insert HTML
314
  if ( document.selection && wpLink.range ) {
365
  }
366
 
367
  link = getLink();
368
+
369
+ if ( inputs.wrap.hasClass( 'has-text-field' ) ) {
370
+ text = inputs.text.val() || attrs.href;
371
+ }
372
 
373
  if ( link ) {
374
  if ( text ) {
387
  editor.execCommand( 'mceInsertLink', false, attrs );
388
  }
389
  }
390
+
391
+ editor.nodeChanged();
392
  },
393
 
394
  updateFields: function( e, li ) {
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(){function b(){var b=a.trim(h.url.val());b&&g!==b&&!/^(?:[a-z]+:|#|\?|\.|\/)/.test(b)&&(h.url.val("http://"+b),g=b)}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.keyup(function(){var a=this;window.clearTimeout(d),d=window.setTimeout(function(){wpLink.searchInternalLinks.call(a)},500)}),h.url.on("paste",function(){setTimeout(b,0)}),h.url.on("blur",b)},open:function(b){var d;a(document.body).addClass("modal-open"),wpLink.range=null,b&&(window.wpActiveEditor=b),window.wpActiveEditor&&(this.textarea=a("#"+window.wpActiveEditor).get(0),"undefined"!=typeof tinymce&&(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{href:a.trim(h.url.val()),target:h.openInNewTab.prop("checked")?"_blank":""}},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='<a href="'+a.href+'"',a.target&&(c+=' target="'+a.target+'"'),c+=">",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(),d=h.text.val(),void(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.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)),h.url.val(a&&b.test(a)?"mailto:"+a:a&&d.test(a)?a.replace(/&amp;|&#0?38;/gi,"&"):""),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);
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);
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.1-RC1
5
- Tested up to: 4.2
6
- Stable tag: 2.3.1
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.2-RC1
5
+ Tested up to: 4.3
6
+ Stable tag: 2.4
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.3.1
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.3.1
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
@@ -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.1-RC1';
66
  var $query_based_vars = array();
67
 
68
  // For fallback purpose only. (1.6)
@@ -272,22 +272,30 @@ class multibyte_patch {
272
  }
273
 
274
  function wplink_js( &$scripts ) {
275
- global $wp_version;
276
- $script_required_version = '4.2-RC1';
277
 
278
- if ( version_compare( substr( $wp_version, 0, strlen( $script_required_version ) ), $script_required_version, '<' ) )
279
- $scripts->add( 'wplink', plugin_dir_url( __FILE__ ) . "js/20141213/wplink{$this->debug_suffix}.js", array( 'jquery' ), '20141213', 1 );
280
  else
281
- $scripts->add( 'wplink', plugin_dir_url( __FILE__ ) . "js/wplink{$this->debug_suffix}.js", array( 'jquery' ), '20150424', 1 );
282
  }
283
 
284
  function word_count_js( &$scripts ) {
285
- $scripts->add( 'word-count', plugin_dir_url( __FILE__ ) . "js/word-count{$this->debug_suffix}.js", array( 'jquery' ), '20131219', 1 );
 
 
 
 
 
286
  }
287
 
288
  function force_character_count( $translations = '', $text = '', $context = '' ) {
289
  if ( 'word count: words or characters?' == $context && 'words' == $text )
290
  return 'characters';
 
 
 
 
291
  return $translations;
292
  }
293
 
@@ -336,10 +344,20 @@ class multibyte_patch {
336
  return preg_match_all( "/./us", $str, $match );
337
  }
338
 
 
 
 
 
 
339
  function filters_after_setup_theme() {
340
  // add filter
341
- if ( false !== $this->conf['patch_force_character_count'] && 'characters' != _x( 'words', 'word count: words or characters?' ) )
 
 
 
 
342
  add_filter( 'gettext_with_context', array( $this, 'force_character_count' ), 10, 3 );
 
343
 
344
  if ( false !== $this->conf['patch_force_twentytwelve_open_sans_off'] && 'twentytwelve' == get_template() ) {
345
  add_action( 'wp_enqueue_scripts', array( $this, 'force_twentytwelve_open_sans_off' ), 99 );
@@ -421,10 +439,9 @@ class multibyte_patch {
421
  }
422
 
423
  function activation_check() {
424
- global $wp_version;
425
  $required_version = $this->required_version;
426
 
427
- if ( version_compare( substr( $wp_version, 0, strlen( $required_version ) ), $required_version, '<' ) ) {
428
  deactivate_plugins( __FILE__ );
429
  exit( sprintf( __( 'Sorry, WP Multibyte Patch requires WordPress %s or later.', 'wp-multibyte-patch' ), $required_version ) );
430
  }
2
  /*
3
  Plugin Name: WP Multibyte Patch
4
  Description: Multibyte functionality enhancement for the WordPress Japanese package.
5
+ Version: 2.4
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.4
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
62
  var $debug_suffix = '';
63
  var $textdomain = 'wp-multibyte-patch';
64
  var $lang_dir = 'languages';
65
+ var $required_version = '4.2-RC1';
66
  var $query_based_vars = array();
67
 
68
  // For fallback purpose only. (1.6)
272
  }
273
 
274
  function wplink_js( &$scripts ) {
275
+ $script_required_version = '4.3-RC3';
 
276
 
277
+ if ( !$this->is_wp_required_version( $script_required_version ) )
278
+ $scripts->add( 'wplink', plugin_dir_url( __FILE__ ) . "js/20150424/wplink{$this->debug_suffix}.js", array( 'jquery' ), '20150424', 1 );
279
  else
280
+ $scripts->add( 'wplink', plugin_dir_url( __FILE__ ) . "js/wplink{$this->debug_suffix}.js", array( 'jquery' ), '20150818', 1 );
281
  }
282
 
283
  function word_count_js( &$scripts ) {
284
+ $script_required_version = '4.3-RC1';
285
+
286
+ if ( !$this->is_wp_required_version( $script_required_version ) )
287
+ $scripts->add( 'word-count', plugin_dir_url( __FILE__ ) . "js/20131219/word-count{$this->debug_suffix}.js", array( 'jquery' ), 20131219, 1 );
288
+ //else
289
+ // $scripts->add( 'word-count', plugin_dir_url( __FILE__ ) . "js/word-count{$this->debug_suffix}.js", array(), '20150818', 1 );
290
  }
291
 
292
  function force_character_count( $translations = '', $text = '', $context = '' ) {
293
  if ( 'word count: words or characters?' == $context && 'words' == $text )
294
  return 'characters';
295
+
296
+ if ( 'Word count type. Do not translate!' == $context && 'words' == $text )
297
+ return 'characters_including_spaces';
298
+
299
  return $translations;
300
  }
301
 
344
  return preg_match_all( "/./us", $str, $match );
345
  }
346
 
347
+ function is_wp_required_version( $required_version ) {
348
+ global $wp_version;
349
+ return version_compare( $wp_version, $required_version, '<' ) ? false : true;
350
+ }
351
+
352
  function filters_after_setup_theme() {
353
  // add filter
354
+ if ( false !== $this->conf['patch_force_character_count']) {
355
+ if (
356
+ $this->is_wp_required_version( '4.3-RC1' ) && 'characters_including_spaces' != _x( 'words', 'Word count type. Do not translate!' ) ||
357
+ !$this->is_wp_required_version( '4.3-RC1' ) && 'characters' != _x( 'words', 'word count: words or characters?' )
358
+ )
359
  add_filter( 'gettext_with_context', array( $this, 'force_character_count' ), 10, 3 );
360
+ }
361
 
362
  if ( false !== $this->conf['patch_force_twentytwelve_open_sans_off'] && 'twentytwelve' == get_template() ) {
363
  add_action( 'wp_enqueue_scripts', array( $this, 'force_twentytwelve_open_sans_off' ), 99 );
439
  }
440
 
441
  function activation_check() {
 
442
  $required_version = $this->required_version;
443
 
444
+ if ( !$this->is_wp_required_version( $required_version ) ) {
445
  deactivate_plugins( __FILE__ );
446
  exit( sprintf( __( 'Sorry, WP Multibyte Patch requires WordPress %s or later.', 'wp-multibyte-patch' ), $required_version ) );
447
  }