forked from lloc/Multisite-Language-Switcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmsls-quick-create.js
More file actions
1 lines (1 loc) · 1.3 KB
/
Copy pathmsls-quick-create.js
File metadata and controls
1 lines (1 loc) · 1.3 KB
1
jQuery(document).ready(function($){$(document).on("click",".msls-quick-create",function(){var $button=$(this);if($button.hasClass("msls-loading")){return}$button.addClass("msls-loading");$button.find(".dashicons").removeClass("dashicons-plus").addClass("dashicons-update");wp.apiFetch({path:"/msls/v1/create-translation",method:"POST",data:{source_post_id:parseInt($button.data("source-post-id"),10),source_blog_id:parseInt($button.data("source-blog-id"),10),target_blog_id:parseInt($button.data("target-blog-id"),10)}}).then(function(response){var $link=$("<a>").attr("href",response.edit_url).attr("title",$button.attr("title").replace(/Create/,"Edit")).html($button.html());$link.find(".dashicons").removeClass("dashicons-update dashicons-plus").addClass("dashicons-edit");$button.replaceWith($link);var $container=$link.closest("li");if(!$container.length){return}var $hiddenInput=$container.find('input[type="hidden"][name^="msls_input_"]');if($hiddenInput.length){$hiddenInput.val(response.post_id)}var $select=$container.find('select[name^="msls_input_"]');if($select.length){$select.append($("<option>").val(response.post_id).text(response.edit_url).prop("selected",true))}}).catch(function(){$button.removeClass("msls-loading");$button.find(".dashicons").removeClass("dashicons-update").addClass("dashicons-plus")})})});