WordPress/wp-includes/js/wplink.min.js
desrosj a64be2cd83 Build/Test Tools: Support NodeJS 14.x in the 4.4 branch.
This updates the 4.4 branch to support the latest LTS version of NodeJS (currently 14.x), allowing the same version to be used across all WordPress branches that receive security updates as a courtesy.

Because older branches use (really) old versions of NodeJS, the local Docker environment cannot be backported since the needed dependencies will not run on these older versions (see #48301). This also blocks the ability to move automated testing over to GitHub Actions (see #50401).

This also replaces the `npm-shrinkwrap.json` with a `package-lock.json` file. Lock files were not supported in earlier versions of NPM, but can now be used.

In addition to backporting the package updates that happened after branching 4.4, dependencies that were removed in future releases have also been updated to their latest versions.

Props desrosj, dd32, netweb, jorbin.
Merges [35859,35862,36860-36865,36935,36978-36979,37017,37019-37020,37212,37612,38111,38688,39110,39113-39119,39478,42460-42461,42463,42887,43320,43323,43977,44219,44233,44728,45321,45765,46404,46408-46409,47404,47867-47869,47872-47873,48705,49636,49933,49937,49939,50017,50126,50176,50185,50192] to the 4.4 branch.
See #52341.
Built from https://develop.svn.wordpress.org/branches/4.4@50210


git-svn-id: http://core.svn.wordpress.org/branches/4.4@49881 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-02-05 04:23:43 +00:00

1 line
10 KiB
JavaScript

var wpLink;!function(r){var a,t,e,n,i,s={},l={},o="ontouchend"in document;wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",init:function(){s.wrap=r("#wp-link-wrap"),s.dialog=r("#wp-link"),s.backdrop=r("#wp-link-backdrop"),s.submit=r("#wp-link-submit"),s.close=r("#wp-link-close"),s.text=r("#wp-link-text"),s.url=r("#wp-link-url"),s.nonce=r("#_ajax_linking_nonce"),s.openInNewTab=r("#wp-link-target"),s.search=r("#wp-link-search"),l.search=new e(r("#search-results")),l.recent=new e(r("#most-recent-results")),l.elements=s.dialog.find(".query-results"),s.queryNotice=r("#query-notice-message"),s.queryNoticeTextDefault=s.queryNotice.find(".query-notice-default"),s.queryNoticeTextHint=s.queryNotice.find(".query-notice-hint"),s.dialog.keydown(wpLink.keydown),s.dialog.keyup(wpLink.keyup),s.submit.click(function(e){e.preventDefault(),wpLink.update()}),s.close.add(s.backdrop).add("#wp-link-cancel a").click(function(e){e.preventDefault(),wpLink.close()}),r("#wp-link-search-toggle").on("click",wpLink.toggleInternalLinking),l.elements.on("river-select",wpLink.updateFields),s.search.on("focus.wplink",function(){s.queryNoticeTextDefault.hide(),s.queryNoticeTextHint.removeClass("screen-reader-text").show()}).on("blur.wplink",function(){s.queryNoticeTextDefault.show(),s.queryNoticeTextHint.addClass("screen-reader-text").hide()}),s.search.on("keyup input",function(){var e=this;window.clearTimeout(t),t=window.setTimeout(function(){wpLink.searchInternalLinks.call(e)},500)}),s.url.on("paste",function(){setTimeout(wpLink.correctURL,0)}),s.url.on("blur",wpLink.correctURL)},correctURL:function(){var e=r.trim(s.url.val());e&&i!==e&&!/^(?:[a-z]+:|#|\?|\.|\/)/.test(e)&&(s.url.val("http://"+e),i=e)},open:function(e){var t=r(document.body);t.addClass("modal-open"),wpLink.range=null,e&&(window.wpActiveEditor=e),window.wpActiveEditor&&(this.textarea=r("#"+window.wpActiveEditor).get(0),"undefined"!=typeof tinymce&&(t.append(s.backdrop,s.wrap),t=tinymce.get(wpActiveEditor),(a=t&&!t.isHidden()?t:null)&&tinymce.isIE&&(a.windowManager.bookmark=a.selection.getBookmark())),!wpLink.isMCE()&&document.selection&&(this.textarea.focus(),this.range=document.selection.createRange()),s.wrap.show(),s.backdrop.show(),wpLink.refresh(),r(document).trigger("wplink-open",s.wrap))},isMCE:function(){return a&&!a.isHidden()},refresh:function(){var e="";l.search.refresh(),l.recent.refresh(),wpLink.isMCE()?wpLink.mceRefresh():(s.wrap.hasClass("has-text-field")||s.wrap.addClass("has-text-field"),document.selection?e=document.selection.createRange().text||"":void 0!==this.textarea.selectionStart&&this.textarea.selectionStart!==this.textarea.selectionEnd&&(e=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd)||""),s.text.val(e),wpLink.setDefaultValues()),o?s.url.focus().blur():s.url.focus()[0].select(),l.recent.ul.children().length||l.recent.ajax(),i=s.url.val().replace(/^http:\/\//,"")},hasSelectedText:function(e){var t=a.selection.getContent();if(/</.test(t)&&(!/^<a [^>]+>[^<]+<\/a>$/.test(t)||-1===t.indexOf("href=")))return!1;if(e){var n,i=e.childNodes;if(0===i.length)return!1;for(n=i.length-1;0<=n;n--)if(3!=i[n].nodeType)return!1}return!0},mceRefresh:function(){var e,t=a.selection.getNode(),n=a.dom.getParent(t,"a[href]"),t=this.hasSelectedText(n);n?(e=n.innerText||n.textContent,s.url.val(a.dom.getAttrib(n,"href")),s.openInNewTab.prop("checked","_blank"===a.dom.getAttrib(n,"target")),s.submit.val(wpLinkL10n.update)):(e=a.selection.getContent({format:"text"}),this.setDefaultValues()),t?(s.text.val(e||""),s.wrap.addClass("has-text-field")):(s.text.val(""),s.wrap.removeClass("has-text-field"))},close:function(){r(document.body).removeClass("modal-open"),wpLink.isMCE()?a.focus():(wpLink.textarea.focus(),wpLink.range&&(wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select())),s.backdrop.hide(),s.wrap.hide(),i=!1,r(document).trigger("wplink-close",s.wrap)},getAttrs:function(){return wpLink.correctURL(),{href:r.trim(s.url.val()),target:s.openInNewTab.prop("checked")?"_blank":""}},buildHtml:function(e){var t='<a href="'+e.href+'"';return e.target&&(t+=' rel="noopener" target="'+e.target+'"'),t+">"},update:function(){wpLink.isMCE()?wpLink.mceUpdate():wpLink.htmlUpdate()},htmlUpdate:function(){var e,t,n,i,a,r=wpLink.textarea;r&&(i=wpLink.getAttrs(),n=s.text.val(),(a=document.createElement("a")).href=i.href,"javascript:"!==a.protocol&&"data:"!==a.protocol||(i.href=""),i.href&&(e=wpLink.buildHtml(i),document.selection&&wpLink.range?(r.focus(),wpLink.range.text=e+(n||wpLink.range.text)+"</a>",wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select(),wpLink.range=null):void 0!==r.selectionStart&&(t=r.selectionStart,a=r.selectionEnd,n=t+(e=e+(i=n||r.value.substring(t,a))+"</a>").length,t!==a||i||(n-=4),r.value=r.value.substring(0,t)+e+r.value.substring(a,r.value.length),r.selectionStart=r.selectionEnd=n),wpLink.close(),r.focus()))},mceUpdate:function(){var e,t=wpLink.getAttrs();wpLink.close(),a.focus(),tinymce.isIE&&a.selection.moveToBookmark(a.windowManager.bookmark);var n=document.createElement("a");n.href=t.href,"javascript:"!==n.protocol&&"data:"!==n.protocol||(t.href=""),t.href?(n=a.dom.getParent(a.selection.getNode(),"a"),s.wrap.hasClass("has-text-field")&&(e=s.text.val()||t.href),n?(e&&("innerText"in n?n.innerText=e:n.textContent=e),a.dom.setAttribs(n,t)):e?a.selection.setNode(a.dom.create("a",t,a.dom.encode(e))):a.execCommand("mceInsertLink",!1,t),a.nodeChanged()):a.execCommand("unlink")},updateFields:function(e,t){s.url.val(t.children(".item-permalink").val())},setDefaultValues:function(){var e;this.isMCE()?e=a.selection.getContent():document.selection&&wpLink.range?e=wpLink.range.text:void 0!==this.textarea.selectionStart&&(e=this.textarea.value.substring(this.textarea.selectionStart,this.textarea.selectionEnd)),e&&/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(e)?s.url.val("mailto:"+e):e&&/^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i.test(e)?s.url.val(e.replace(/&amp;|&#0?38;/gi,"&")):s.url.val(""),s.submit.val(wpLinkL10n.save)},searchInternalLinks:function(){var e,t=r(this),n=t.val();2<n.length?(l.recent.hide(),l.search.show(),wpLink.lastSearch!=n&&(wpLink.lastSearch=n,e=t.parent().find(".spinner").addClass("is-active"),l.search.change(n),l.search.ajax(function(){e.removeClass("is-active")}))):(l.search.hide(),l.recent.show())},next:function(){l.search.next(),l.recent.next()},prev:function(){l.search.prev(),l.recent.prev()},keydown:function(e){var t;27===e.keyCode?(wpLink.close(),e.stopImmediatePropagation()):9===e.keyCode&&("wp-link-submit"!==(t=e.target.id)||e.shiftKey?"wp-link-close"===t&&e.shiftKey&&(s.submit.focus(),e.preventDefault()):(s.close.focus(),e.preventDefault())),38!==e.keyCode&&40!==e.keyCode||document.activeElement&&("link-title-field"===document.activeElement.id||"url-field"===document.activeElement.id)||(t=38===e.keyCode?"prev":"next",clearInterval(wpLink.keyInterval),wpLink[t](),wpLink.keyInterval=setInterval(wpLink[t],wpLink.keySensitivity),e.preventDefault())},keyup:function(e){38!==e.keyCode&&40!==e.keyCode||(clearInterval(wpLink.keyInterval),e.preventDefault())},delayedCallback:function(e,t){var n,i,a,r;return t?(setTimeout(function(){return i?e.apply(r,a):void(n=!0)},t),function(){if(n)return e.apply(this,arguments);a=arguments,r=this,i=!0}):e},toggleInternalLinking:function(e){var t=s.wrap.hasClass("search-panel-visible");s.wrap.toggleClass("search-panel-visible",!t),setUserSetting("wplink",t?"0":"1"),s[t?"url":"search"].focus(),e.preventDefault()}},e=function(e,t){var n=this;this.element=e,this.ul=e.children("ul"),this.contentHeight=e.children("#link-selector-height"),this.waiting=e.find(".river-waiting"),this.change(t),this.refresh(),r("#wp-link .query-results, #wp-link #link-selector").scroll(function(){n.maybeLoad()}),e.on("click","li",function(e){n.select(r(this),e)})},r.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(e,t){var n,i,a,r;e.hasClass("unselectable")||e==this.selected||(this.deselect(),this.selected=e.addClass("selected"),n=e.outerHeight(),i=this.element.height(),a=e.position().top,r=this.element.scrollTop(),a<0?this.element.scrollTop(r+a):i<a+n&&this.element.scrollTop(r+a-i+n),this.element.trigger("river-select",[e,t,this]))},deselect:function(){this.selected&&this.selected.removeClass("selected"),this.selected=!1},prev:function(){var e;this.visible&&this.selected&&(e=this.selected.prev("li")).length&&this.select(e)},next:function(){var e;!this.visible||(e=this.selected?this.selected.next("li"):r("li:not(.unselectable):first",this.element)).length&&this.select(e)},ajax:function(n){var i=this,e=1==this.query.page?0:wpLink.minRiverAJAXDuration,e=wpLink.delayedCallback(function(e,t){i.process(e,t),n&&n(e,t)},e);this.query.ajax(e)},change:function(e){this.query&&this._search==e||(this._search=e,this.query=new n(e),this.element.scrollTop(0))},process:function(e,t){var n,i="",a=!0,t=1==t.page;e?r.each(e,function(){n=a?"alternate":"",n+=this.title?"":" no-title",i+=n?'<li class="'+n+'">':"<li>",i+='<input type="hidden" class="item-permalink" value="'+this.permalink+'" />',i+='<span class="item-title">',i+=this.title||wpLinkL10n.noTitle,i+='</span><span class="item-info">'+this.info+"</span></li>",a=!a}):t&&(i+='<li class="unselectable no-matches-found"><span class="item-title"><em>'+wpLinkL10n.noMatchesFound+"</em></span></li>"),this.ul[t?"html":"append"](i)},maybeLoad:function(){var n=this,i=this.element,e=i.scrollTop()+i.height();!this.query.ready()||e<this.contentHeight.height()-wpLink.riverBottomThreshold||setTimeout(function(){var e=i.scrollTop(),t=e+i.height();!n.query.ready()||t<n.contentHeight.height()-wpLink.riverBottomThreshold||(n.waiting.addClass("is-active"),i.scrollTop(e+n.waiting.outerHeight()),n.ajax(function(){n.waiting.removeClass("is-active")}))},wpLink.timeToTriggerRiver)}}),n=function(e){this.page=1,this.allLoaded=!1,this.querying=!1,this.search=e},r.extend(n.prototype,{ready:function(){return!(this.querying||this.allLoaded)},ajax:function(t){var n=this,i={action:"wp-link-ajax",page:this.page,_ajax_linking_nonce:s.nonce.val()};this.search&&(i.search=this.search),this.querying=!0,r.post(ajaxurl,i,function(e){n.page++,n.querying=!1,n.allLoaded=!e,t(e,i)},"json")}}),r(document).ready(wpLink.init)}(jQuery);