jQuery(document).ready(function(n){var i=function(i){if(i.length&&!i.data("ff-ranking-ready")){var e="yes"===i.attr("data-ranking-required"),t="no"!==i.attr("data-ranking-submit-default"),f=!t&&e,a=!e,r=i.closest(".ff-el-group").find(".ff-ranking-field__reset"),o=function(n){r.length&&r.toggleClass("ff-ranking-field__reset--visible",!!n)},d=function(){var e=i.find(".ff-ranking-field__item"),f=e.length-1;e.each(function(i){var e=n(this);e.find(".ff-ranking-field__position").text(i+1),e.find(".ff-ranking-field__move--up").prop("disabled",0===i),e.find(".ff-ranking-field__move--down").prop("disabled",i===f);var r=e.find('input[data-ranking-input="1"]');r.length&&(a||t?(r.val(e.attr("data-ranking-value")||r.attr("data-ranking-hidden-value")||""),r.prop("disabled",!1)):(r.val(""),r.prop("disabled",!0)))}),i.trigger("change")},l=null,s=function(i){l!==i&&(l&&n(l).removeClass("ff-ranking-field__item--over"),(l=i||null)&&n(l).addClass("ff-ranking-field__item--over"))},g=function(){s(null)},u=function(n){var e=i.find(".ff-ranking-field__item").get(),t=new Map;e.forEach(function(n){t.set(n,n.getBoundingClientRect())}),n(),i.find(".ff-ranking-field__item").get().forEach(function(n){var i=t.get(n);if(i){var e=n.getBoundingClientRect(),f=i.left-e.left,a=i.top-e.top;if(f||a){n.style.transition="none",n.style.transform="translate(".concat(f,"px, ").concat(a,"px)"),requestAnimationFrame(function(){n.style.transition="transform 220ms ease",n.style.transform=""});var r=function(){n.style.transition="",n.style.transform="",n.removeEventListener("transitionend",r)};n.addEventListener("transitionend",r)}}})},c=function(n,i){var e=i<0?n.prev(".ff-ranking-field__item"):n.next(".ff-ranking-field__item");e.length&&(u(function(){i<0?n.insertBefore(e):n.insertAfter(e)}),a=!0,o(!0),d())},_=function(e){var t=i.find(".ff-ranking-field__item").get().sort(function(i,e){return parseInt(n(i).attr("data-ranking-initial-index"),10)-parseInt(n(e).attr("data-ranking-initial-index"),10)});u(function(){t.forEach(function(n){i.append(n)})}),a=!e,g(),o(!1),d()},v=null;i.on("click",".ff-ranking-field__move--up",function(i){i.preventDefault();var e=n(this).closest(".ff-ranking-field__item");c(e,-1),m(e,-1)}),i.on("click",".ff-ranking-field__move--down",function(i){i.preventDefault();var e=n(this).closest(".ff-ranking-field__item");c(e,1),m(e,1)}),i.closest(".ff-el-group").on("click",".ff-ranking-field__reset",function(n){n.preventDefault(),_(f);var e=i.find(".ff-ranking-field__item").first().find(".ff-ranking-field__move--down");e.length&&e.trigger("focus")}),i.on("dragstart",".ff-ranking-field__item",function(i){v=this,i.originalEvent.dataTransfer.effectAllowed="move",i.originalEvent.dataTransfer.setData("text/plain",n(this).attr("data-ranking-value")||""),n(this).addClass("ff-ranking-field__item--dragging")}),i.on("dragend",".ff-ranking-field__item",function(){n(this).removeClass("ff-ranking-field__item--dragging"),g(),v=null}),i.on("dragover",".ff-ranking-field__item",function(n){n.preventDefault(),n.originalEvent.dataTransfer.dropEffect="move",v&&v!==this?s(this):g()}),i.on("dragenter",".ff-ranking-field__item",function(){v&&v!==this&&s(this)}),i.on("dragleave",".ff-ranking-field__item",function(){l===this&&g()}),i.on("drop",".ff-ranking-field__item",function(i){if(i.preventDefault(),v&&v!==this){var e=n(this),t=n(v);u(function(){t.index()<e.index()?t.insertAfter(e):t.insertBefore(e)}),a=!0,o(!0),g(),d()}else g()}),i.closest("form").on("reset",function(){a=!e,window.setTimeout(function(){_(f)},0)}),i.data("ff-ranking-ready",!0),d()}function m(n,i){var e=n.find(i<0?".ff-ranking-field__move--up":".ff-ranking-field__move--down");if(!e.length||e.prop("disabled")){var t=n.find(i<0?".ff-ranking-field__move--down":".ff-ranking-field__move--up");t.length&&!t.prop("disabled")&&t.trigger("focus")}else e.trigger("focus")}},e=function(e){n(e||document).find(".ff-ranking-field").each(function(){i(n(this))})};e(document),n(document).on("reInitExtras","form.frm-fluent-form",function(){e(this)})});