X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/fa11948979fd6a4ea5705dc613b239699a459db3..6359b807ff8b4ffa151d8756cdefb861c6c1d4db:/wp-includes/js/wplink.min.js diff --git a/wp-includes/js/wplink.min.js b/wp-includes/js/wplink.min.js index 0db2cd2a..f787c3df 100644 --- a/wp-includes/js/wplink.min.js +++ b/wp-includes/js/wplink.min.js @@ -1 +1 @@ -var wpLink;!function(a){var b,c,d,e={},f={};wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",init:function(){e.dialog=a("#wp-link"),e.submit=a("#wp-link-submit"),e.url=a("#url-field"),e.nonce=a("#_ajax_linking_nonce"),e.title=a("#link-title-field"),e.openInNewTab=a("#link-target-checkbox"),e.search=a("#search-field"),f.search=new c(a("#search-results")),f.recent=new c(a("#most-recent-results")),f.elements=a(".query-results",e.dialog),e.dialog.keydown(wpLink.keydown),e.dialog.keyup(wpLink.keyup),e.submit.click(function(a){a.preventDefault(),wpLink.update()}),a("#wp-link-cancel").click(function(a){a.preventDefault(),wpLink.close()}),a("#internal-toggle").click(wpLink.toggleInternalLinking),f.elements.bind("river-select",wpLink.updateFields),e.search.keyup(wpLink.searchInternalLinks),e.dialog.bind("wpdialogrefresh",wpLink.refresh),e.dialog.bind("wpdialogbeforeopen",wpLink.beforeOpen),e.dialog.bind("wpdialogclose",wpLink.onClose)},beforeOpen:function(){wpLink.range=null,!wpLink.isMCE()&&document.selection&&(wpLink.textarea.focus(),wpLink.range=document.selection.createRange())},open:function(){wpActiveEditor&&(this.textarea=a("#"+wpActiveEditor).get(0),e.dialog.data("wpdialog")||e.dialog.wpdialog({title:wpLinkL10n.title,width:480,height:"auto",modal:!0,dialogClass:"wp-dialog"}),e.dialog.wpdialog("open"))},isMCE:function(){return tinyMCEPopup&&(b=tinyMCEPopup.editor)&&!b.isHidden()},refresh:function(){f.search.refresh(),f.recent.refresh(),wpLink.isMCE()?wpLink.mceRefresh():wpLink.setDefaultValues(),e.url.focus()[0].select(),f.recent.ul.children().length||f.recent.ajax()},mceRefresh:function(){var a;b=tinyMCEPopup.editor,tinyMCEPopup.restoreSelection(),(a=b.dom.getParent(b.selection.getNode(),"A"))?(e.url.val(b.dom.getAttrib(a,"href")),e.title.val(b.dom.getAttrib(a,"title")),e.openInNewTab.prop("checked","_blank"==b.dom.getAttrib(a,"target")),e.submit.val(wpLinkL10n.update)):wpLink.setDefaultValues()},close:function(){wpLink.isMCE()?tinyMCEPopup.close():e.dialog.wpdialog("close")},onClose:function(){wpLink.isMCE()||(wpLink.textarea.focus(),wpLink.range&&(wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select()))},getAttrs:function(){return{href:e.url.val(),title:e.title.val(),target:e.openInNewTab.prop("checked")?"_blank":""}},update:function(){wpLink.isMCE()?wpLink.mceUpdate():wpLink.htmlUpdate()},htmlUpdate:function(){var a,b,c,d,e,f=wpLink.textarea;f&&(a=wpLink.getAttrs(),a.href&&"http://"!=a.href&&(b='",wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select(),wpLink.range=null):"undefined"!=typeof f.selectionStart&&(c=f.selectionStart,d=f.selectionEnd,selection=f.value.substring(c,d),b=b+selection+"",e=c+b.length,c==d&&(e-="".length),f.value=f.value.substring(0,c)+b+f.value.substring(d,f.value.length),f.selectionStart=f.selectionEnd=e),wpLink.close(),f.focus()))},mceUpdate:function(){var b,c,d=tinyMCEPopup.editor,e=wpLink.getAttrs();return tinyMCEPopup.restoreSelection(),b=d.dom.getParent(d.selection.getNode(),"A"),e.href&&"http://"!=e.href?(null==b?(d.getDoc().execCommand("unlink",!1,null),tinyMCEPopup.execCommand("mceInsertLink",!1,"#mce_temp_url#",{skip_undo:1}),tinymce.each(d.dom.select("a"),function(a){"#mce_temp_url#"==d.dom.getAttrib(a,"href")&&(b=a,d.dom.setAttribs(b,e))}),tinymce.isWebKit&&"#mce_temp_url#"==a(b).text()&&(d.dom.remove(b),b=null)):d.dom.setAttribs(b,e),!b||1==b.childNodes.length&&"IMG"==b.firstChild.nodeName||(d.selection.select(b),d.selection.collapse(0),tinyMCEPopup.storeSelection()),d.execCommand("mceEndUndoLevel"),wpLink.close(),d.focus(),void 0):(b&&(c=d.selection.getBookmark(),d.dom.remove(b,1),d.selection.moveToBookmark(c),tinyMCEPopup.execCommand("mceEndUndoLevel"),wpLink.close()),void 0)},updateFields:function(a,b,c){e.url.val(b.children(".item-permalink").val()),e.title.val(b.hasClass("no-title")?"":b.children(".item-title").text()),c&&"click"==c.type&&e.url.focus()},setDefaultValues:function(){e.url.val("http://"),e.title.val(""),e.submit.val(wpLinkL10n.save)},searchInternalLinks:function(){var b,c=a(this),d=c.val();if(d.length>2){if(f.recent.hide(),f.search.show(),wpLink.lastSearch==d)return;wpLink.lastSearch=d,b=c.parent().find(".spinner").show(),f.search.change(d),f.search.ajax(function(){b.hide()})}else f.search.hide(),f.recent.show()},next:function(){f.search.next(),f.recent.next()},prev:function(){f.search.prev(),f.recent.prev()},keydown:function(b){var c,d=a.ui.keyCode;switch(b.which){case d.UP:c="prev";case d.DOWN:c=c||"next",clearInterval(wpLink.keyInterval),wpLink[c](),wpLink.keyInterval=setInterval(wpLink[c],wpLink.keySensitivity);break;default:return}b.preventDefault()},keyup:function(b){var c=a.ui.keyCode;switch(b.which){case c.ESCAPE:return b.stopImmediatePropagation(),a(document).triggerHandler("wp_CloseOnEscape",[{event:b,what:"wplink",cb:wpLink.close}])||wpLink.close(),!1;case c.UP:case c.DOWN:clearInterval(wpLink.keyInterval);break;default:return}b.preventDefault()},delayedCallback:function(a,b){var c,d,e,f;return b?(setTimeout(function(){return d?a.apply(f,e):(c=!0,void 0)},b),function(){return c?a.apply(this,arguments):(e=arguments,f=this,d=!0,void 0)}):a},toggleInternalLinking:function(b){var c=a("#search-panel"),d=e.dialog.wpdialog("widget"),f=!c.is(":visible"),g=a(window);a(this).toggleClass("toggle-arrow-active",f),e.dialog.height("auto"),c.slideToggle(300,function(){setUserSetting("wplink",f?"1":"0"),e[f?"search":"url"].focus();var a=g.scrollTop(),b=d.offset().top,c=b+d.outerHeight(),h=c-g.height();h>a&&d.animate({top:b>h?b-h:a},200)}),b.preventDefault()}},c=function(b,c){var d=this;this.element=b,this.ul=b.children("ul"),this.waiting=b.find(".river-waiting"),this.change(c),this.refresh(),b.scroll(function(){d.maybeLoad()}),b.delegate("li","click",function(b){d.select(a(this),b)})},a.extend(c.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 d(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?'
  • ':"
  • ",d+='',d+='',d+=this.title?this.title:wpLinkL10n.noTitle,d+=''+this.info+"
  • ",e=!e}):g&&(d+='
  • '+wpLinkL10n.noMatchesFound+"
  • "),this.ul[g?"html":"append"](d)},maybeLoad:function(){var a=this,b=this.element,c=b.scrollTop()+b.height();!this.query.ready()||c]+>[^<]+<\/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='",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+"",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(/&|�?38;/gi,"&"):""),h.submit.val(wpLinkL10n.save)},searchInternalLinks:function(){var b,c=a(this),d=c.val();if(d.length>2){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?'
  • ':"
  • ",d+='',d+='',d+=this.title?this.title:wpLinkL10n.noTitle,d+=''+this.info+"
  • ",e=!e}):g&&(d+='
  • '+wpLinkL10n.noMatchesFound+"
  • "),this.ul[g?"html":"append"](d)},maybeLoad:function(){var a=this,b=this.element,c=b.scrollTop()+b.height();!this.query.ready()||c