-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsaveWithKeyboard.min.js
1 lines (1 loc) · 1.75 KB
/
saveWithKeyboard.min.js
1
!function(o,a){"use strict";var e,s,l,n=o(document),i=!1,u=!!navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i);function r(e){n.on("click",function(){var t=e();t&&t.length?(console.log("Button found!"),c(t)):console.log("No buttons found!")})}function c(t){!function(t){if(t){var e="";t.attr("title")!==s&&(e=t.attr("title").replace(" - "+s,"")),t.attr("title",e)}}(e),1===(e=o(t)).length&&e.is(":visible")?(n.on("keydown",h),n.on("keyup",p),function(t){var e=t.attr("title");e&&e!=s?e+=" - ":e="";e+=s,t.attr("title",e)}(e),o(document).on("tinymce-editor-init",function(t,e){e.addShortcut(l,s,d)})):(e=a,n.off("keydown",h),n.off("keyup",p)),console.log("Button",e!==a,e)}function h(t){(t.ctrlKey&&!u||t.metaKey&&u)&&83===(t.keyCode||t.which)&&(d(),t.preventDefault())}function d(){i||(i=!0,e&&e.is(":visible")?e.click():console.log("Selected button not available/visible"))}function p(t){!0===i&&(i=!1)}o(function(){var t=o(document.body),e=o("#original_post_status"),n=e.val(),i="Ctrl+S";l="ctrl+s",u&&(i="Cmd(⌘)+S",l="meta+s"),s=window.SaveWithKeyboard&&SaveWithKeyboard.tooltipText?SaveWithKeyboard.tooltipText.replace("$SHORTCUT$",i):"Press "+i+" to click",e.length?c("publish"===n?"#publish":"#save-post"):t.hasClass("link-php")||t.hasClass("link-add-php")?c("#publish"):t.hasClass("comment-php")||t.hasClass("wp-customizer")?c("#save"):t.hasClass("widgets-php")?r(function(){var t=o(".widget-control-save:visible");if(1===t.length)return t;var e=o(document.activeElement);return e.is(":input")?e.parents("form:first").find(":submit"):a}):t.hasClass("edit-php")?r(function(){return o(".inline-editor button.save")}):t.hasClass("nav-menus-php")?c("#save_menu_header"):t.hasClass("upload-php")?r(function(){return o(".imgedit-submit-btn")}):0<o("#submit").length&&c("#submit")})}(jQuery);