mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-13 22:26:06 +01:00
7c466f7c74
This updates the 5.3 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. In addition to backporting the package updates that happened after branching 5.3, dependencies that were removed in future releases have also been updated to their latest versions. Props desrosj, dd32, netweb, jorbin. Merges [47404,47867,47872-47873,48213,48705,49636,49933,49937,49939,49940,49983,49989,50017,50126,50176,50185] to the 5.3 branch. See #52341. Built from https://develop.svn.wordpress.org/branches/5.3@50190 git-svn-id: http://core.svn.wordpress.org/branches/5.3@49868 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
!function(w){var l=w(document);window.wpWidgets={hoveredSidebar:null,l10n:{save:"{save}",saved:"{saved}",saveAlert:"{saveAlert}",widgetAdded:"{widgetAdded}"},dirtyWidgets:{},init:function(){var r,o,c=this,d=w(".widgets-chooser"),a=d.find(".widgets-chooser-sidebars"),e=w("div.widgets-sortables"),g=!("undefined"==typeof isRtl||!isRtl);w("#widgets-right .sidebar-name").click(function(){var e=w(this),i=e.closest(".widgets-holder-wrap "),t=e.find(".handlediv");i.hasClass("closed")?(i.removeClass("closed"),t.attr("aria-expanded","true"),e.parent().sortable("refresh")):(i.addClass("closed"),t.attr("aria-expanded","false")),l.triggerHandler("wp-pin-menu")}).find(".handlediv").each(function(e){0!==e&&w(this).attr("aria-expanded","false")}),w(window).on("beforeunload.widgets",function(e){var i,t=[];if(w.each(c.dirtyWidgets,function(e,i){i&&t.push(e)}),0!==t.length)return(i=w("#widgets-right").find(".widget").filter(function(){return-1!==t.indexOf(w(this).prop("id").replace(/^widget-\d+_/,""))})).each(function(){w(this).hasClass("open")||w(this).find(".widget-title-action:first").click()}),i.first().each(function(){this.scrollIntoViewIfNeeded?this.scrollIntoViewIfNeeded():this.scrollIntoView(),w(this).find(".widget-inside :tabbable:first").focus()}),e.returnValue=wpWidgets.l10n.saveAlert,e.returnValue}),w("#widgets-left .sidebar-name").click(function(){var e=w(this).closest(".widgets-holder-wrap");e.toggleClass("closed").find(".handlediv").attr("aria-expanded",!e.hasClass("closed")),l.triggerHandler("wp-pin-menu")}),w(document.body).bind("click.widgets-toggle",function(e){var i,t,d,s,a,n,r=w(e.target),o={"z-index":100},l=r.closest(".widget").find(".widget-top button.widget-action");r.parents(".widget-top").length&&!r.parents("#available-widgets").length?(t=(i=r.closest("div.widget")).children(".widget-inside"),d=parseInt(i.find("input.widget-width").val(),10),s=i.parent().width(),n=t.find(".widget-id").val(),i.data("dirty-state-initialized")||((a=t.find(".widget-control-save")).prop("disabled",!0).val(wpWidgets.l10n.saved),t.on("input change",function(){c.dirtyWidgets[n]=!0,i.addClass("widget-dirty"),a.prop("disabled",!1).val(wpWidgets.l10n.save)}),i.data("dirty-state-initialized",!0)),t.is(":hidden")?(250<d&&s<d+30&&i.closest("div.widgets-sortables").length&&(o[i.closest("div.widget-liquid-right").length?g?"margin-right":"margin-left":g?"margin-left":"margin-right"]=s-(d+30)+"px",i.css(o)),l.attr("aria-expanded","true"),t.slideDown("fast",function(){i.addClass("open")})):(l.attr("aria-expanded","false"),t.slideUp("fast",function(){i.attr("style",""),i.removeClass("open")}))):r.hasClass("widget-control-save")?(wpWidgets.save(r.closest("div.widget"),0,1,0),e.preventDefault()):r.hasClass("widget-control-remove")?wpWidgets.save(r.closest("div.widget"),1,1,0):r.hasClass("widget-control-close")?((i=r.closest("div.widget")).removeClass("open"),l.attr("aria-expanded","false"),wpWidgets.close(i)):"inactive-widgets-control-remove"===r.attr("id")&&(wpWidgets.removeInactiveWidgets(),e.preventDefault())}),e.children(".widget").each(function(){var e=w(this);wpWidgets.appendTitle(this),e.find("p.widget-error").length&&e.find(".widget-action").trigger("click").attr("aria-expanded","true")}),w("#widget-list").children(".widget").draggable({connectToSortable:"div.widgets-sortables",handle:"> .widget-top > .widget-title",distance:2,helper:"clone",zIndex:100,containment:"#wpwrap",refreshPositions:!0,start:function(e,i){var t=w(this).find(".widgets-chooser");i.helper.find("div.widget-description").hide(),o=this.id,t.length&&(w("#wpbody-content").append(t.hide()),i.helper.find(".widgets-chooser").remove(),c.clearWidgetSelection())},stop:function(){r&&w(r).hide(),r=""}}),e.droppable({tolerance:"intersect",over:function(e){var i=w(e.target).parent();wpWidgets.hoveredSidebar&&!i.is(wpWidgets.hoveredSidebar)&&wpWidgets.closeSidebar(e),i.hasClass("closed")&&(wpWidgets.hoveredSidebar=i).removeClass("closed").find(".handlediv").attr("aria-expanded","true"),w(this).sortable("refresh")},out:function(e){wpWidgets.hoveredSidebar&&wpWidgets.closeSidebar(e)}}),e.sortable({placeholder:"widget-placeholder",items:"> .widget",handle:"> .widget-top > .widget-title",cursor:"move",distance:2,containment:"#wpwrap",tolerance:"pointer",refreshPositions:!0,start:function(e,i){var t=w(this),d=t.parent(),s=i.item.children(".widget-inside");"block"===s.css("display")&&(i.item.removeClass("open"),i.item.find(".widget-top button.widget-action").attr("aria-expanded","false"),s.hide(),w(this).sortable("refreshPositions")),d.hasClass("closed")||(i=i.item.hasClass("ui-draggable")?t.height():1+t.height(),t.css("min-height",i+"px"))},stop:function(e,i){var t,d,s,a=i.item,n=o;if(wpWidgets.hoveredSidebar=null,a.hasClass("deleting"))return wpWidgets.save(a,1,0,1),void a.remove();t=a.find("input.add_new").val(),d=a.find("input.multi_number").val(),a.attr("style","").removeClass("ui-draggable"),o="",t&&("multi"===t?(a.html(a.html().replace(/<[^<>]+>/g,function(e){return e.replace(/__i__|%i%/g,d)})),a.attr("id",n.replace("__i__",d)),d++,w("div#"+n).find("input.multi_number").val(d)):"single"===t&&(a.attr("id","new-"+n),r="div#"+n),wpWidgets.save(a,0,0,1),a.find("input.add_new").val(""),l.trigger("widget-added",[a])),(s=a.parent()).parent().hasClass("closed")&&(s.parent().removeClass("closed").find(".handlediv").attr("aria-expanded","true"),1<(i=s.children(".widget")).length&&(n=i.get(0),i=a.get(0),n.id&&i.id&&n.id!==i.id&&w(n).before(a))),t?a.find(".widget-action").trigger("click"):wpWidgets.saveOrder(s.attr("id"))},activate:function(){w(this).parent().addClass("widget-hover")},deactivate:function(){w(this).css("min-height","").parent().removeClass("widget-hover")},receive:function(e,i){i=w(i.sender);-1<this.id.indexOf("orphaned_widgets")?i.sortable("cancel"):-1<i.attr("id").indexOf("orphaned_widgets")&&!i.children(".widget").length&&i.parents(".orphan-sidebar").slideUp(400,function(){w(this).remove()})}}).sortable("option","connectWith","div.widgets-sortables"),w("#available-widgets").droppable({tolerance:"pointer",accept:function(e){return"widget-list"!==w(e).parent().attr("id")},drop:function(e,i){i.draggable.addClass("deleting"),w("#removing-widget").hide().children("span").empty()},over:function(e,i){i.draggable.addClass("deleting"),w("div.widget-placeholder").hide(),i.draggable.hasClass("ui-sortable-helper")&&w("#removing-widget").show().children("span").html(i.draggable.find("div.widget-title").children("h3").html())},out:function(e,i){i.draggable.removeClass("deleting"),w("div.widget-placeholder").show(),w("#removing-widget").hide().children("span").empty()}}),w("#widgets-right .widgets-holder-wrap").each(function(e,i){var t=w(i),d=t.find(".sidebar-name h2").text(),s=t.find(".sidebar-name").data("add-to"),i=t.find(".widgets-sortables").attr("id"),t=w("<li>"),d=w("<button>",{type:"button","aria-pressed":"false",class:"widgets-chooser-button","aria-label":s}).text(w.trim(d));t.append(d),0===e&&(t.addClass("widgets-chooser-selected"),d.attr("aria-pressed","true")),a.append(t),t.data("sidebarId",i)}),w("#available-widgets .widget .widget-top").on("click.widgets-chooser",function(){var e=w(this).closest(".widget"),i=w(this).find(".widget-action"),t=a.find(".widgets-chooser-button");e.hasClass("widget-in-question")||w("#widgets-left").hasClass("chooser")?(i.attr("aria-expanded","false"),c.closeChooser()):(c.clearWidgetSelection(),w("#widgets-left").addClass("chooser"),e.addClass("widget-in-question").children(".widget-description").after(d),d.slideDown(300,function(){i.attr("aria-expanded","true")}),t.on("click.widgets-chooser",function(){a.find(".widgets-chooser-selected").removeClass("widgets-chooser-selected"),t.attr("aria-pressed","false"),w(this).attr("aria-pressed","true").closest("li").addClass("widgets-chooser-selected")}))}),d.on("click.widgets-chooser",function(e){e=w(e.target);e.hasClass("button-primary")?(c.addWidget(d),c.closeChooser()):e.hasClass("widgets-chooser-cancel")&&c.closeChooser()}).on("keyup.widgets-chooser",function(e){e.which===w.ui.keyCode.ESCAPE&&c.closeChooser()})},saveOrder:function(e){var i={action:"widgets-order",savewidgets:w("#_wpnonce_widgets").val(),sidebars:[]};e&&w("#"+e).find(".spinner:first").addClass("is-active"),w("div.widgets-sortables").each(function(){w(this).sortable&&(i["sidebars["+w(this).attr("id")+"]"]=w(this).sortable("toArray").join(","))}),w.post(ajaxurl,i,function(){w("#inactive-widgets-control-remove").prop("disabled",!w("#wp_inactive_widgets .widget").length),w(".spinner").removeClass("is-active")})},save:function(t,d,s,a){var n=this,r=t.closest("div.widgets-sortables").attr("id"),e=t.find("form"),i=t.find("input.add_new").val();(d||i||!e.prop("checkValidity")||e[0].checkValidity())&&(i=e.serialize(),t=w(t),w(".spinner",t).addClass("is-active"),e={action:"save-widget",savewidgets:w("#_wpnonce_widgets").val(),sidebar:r},d&&(e.delete_widget=1),i+="&"+w.param(e),w.post(ajaxurl,i,function(e){var i=w("input.widget-id",t).val();d?(w("input.widget_number",t).val()||w("#available-widgets").find("input.widget-id").each(function(){w(this).val()===i&&w(this).closest("div.widget").show()}),s?(a=0,t.slideUp("fast",function(){w(this).remove(),wpWidgets.saveOrder(),delete n.dirtyWidgets[i]})):(t.remove(),delete n.dirtyWidgets[i],"wp_inactive_widgets"===r&&w("#inactive-widgets-control-remove").prop("disabled",!w("#wp_inactive_widgets .widget").length))):(w(".spinner").removeClass("is-active"),e&&2<e.length&&(w("div.widget-content",t).html(e),wpWidgets.appendTitle(t),t.find(".widget-control-save").prop("disabled",!0).val(wpWidgets.l10n.saved),t.removeClass("widget-dirty"),delete n.dirtyWidgets[i],l.trigger("widget-updated",[t]),"wp_inactive_widgets"===r&&w("#inactive-widgets-control-remove").prop("disabled",!w("#wp_inactive_widgets .widget").length))),a&&wpWidgets.saveOrder()}))},removeInactiveWidgets:function(){var e,i=w(".remove-inactive-widgets"),t=this;w(".spinner",i).addClass("is-active"),e={action:"delete-inactive-widgets",removeinactivewidgets:w("#_wpnonce_remove_inactive_widgets").val()},e=w.param(e),w.post(ajaxurl,e,function(){w("#wp_inactive_widgets .widget").each(function(){var e=w(this);delete t.dirtyWidgets[e.find("input.widget-id").val()],e.remove()}),w("#inactive-widgets-control-remove").prop("disabled",!0),w(".spinner",i).removeClass("is-active")})},appendTitle:function(e){var i=(i=w('input[id*="-title"]',e).val()||"")&&": "+i.replace(/<[^<>]+>/g,"").replace(/</g,"<").replace(/>/g,">");w(e).children(".widget-top").children(".widget-title").children().children(".in-widget-title").html(i)},close:function(e){e.children(".widget-inside").slideUp("fast",function(){e.attr("style","").find(".widget-top button.widget-action").attr("aria-expanded","false").focus()})},addWidget:function(e){var i=e.find(".widgets-chooser-selected").data("sidebarId"),t=w("#"+i),d=w("#available-widgets").find(".widget-in-question").clone(),s=d.attr("id"),e=d.find("input.add_new").val(),a=d.find("input.multi_number").val();d.find(".widgets-chooser").remove(),"multi"===e?(d.html(d.html().replace(/<[^<>]+>/g,function(e){return e.replace(/__i__|%i%/g,a)})),d.attr("id",s.replace("__i__",a)),a++,w("#"+s).find("input.multi_number").val(a)):"single"===e&&(d.attr("id","new-"+s),w("#"+s).hide()),t.closest(".widgets-holder-wrap").removeClass("closed").find(".handlediv").attr("aria-expanded","true"),t.append(d),t.sortable("refresh"),wpWidgets.save(d,0,0,1),d.find("input.add_new").val(""),l.trigger("widget-added",[d]),e=(i=w(window).scrollTop())+w(window).height(),(s=t.offset()).bottom=s.top+t.outerHeight(),(i>s.bottom||e<s.top)&&w("html, body").animate({scrollTop:s.top-130},200),window.setTimeout(function(){d.find(".widget-title").trigger("click"),window.wp.a11y.speak(wpWidgets.l10n.widgetAdded,"assertive")},250)},closeChooser:function(){var e=this,i=w("#available-widgets .widget-in-question");w(".widgets-chooser").slideUp(200,function(){w("#wpbody-content").append(this),e.clearWidgetSelection(),i.find(".widget-action").attr("aria-expanded","false").focus()})},clearWidgetSelection:function(){w("#widgets-left").removeClass("chooser"),w(".widget-in-question").removeClass("widget-in-question")},closeSidebar:function(e){this.hoveredSidebar.addClass("closed").find(".handlediv").attr("aria-expanded","false"),w(e.target).css("min-height",""),this.hoveredSidebar=null}},l.ready(function(){wpWidgets.init()})}(jQuery); |