From bebc4244d87513b3e990d88f0bddb6d08152df65 Mon Sep 17 00:00:00 2001 From: Giuseppe Criscione Date: Thu, 6 Sep 2018 18:40:52 +0200 Subject: [PATCH] Add keyboard shortcut to all views with Save command --- admin/assets/js/app.js | 15 ++++++++++++--- admin/assets/js/app.min.js | 2 +- admin/assets/js/src/components/editor.js | 3 --- admin/assets/js/src/main.js | 12 ++++++++++++ admin/views/options/site.php | 2 +- admin/views/options/system.php | 2 +- admin/views/users/profile.php | 2 +- 7 files changed, 28 insertions(+), 10 deletions(-) mode change 100755 => 100644 admin/assets/js/app.js mode change 100755 => 100644 admin/assets/js/app.min.js diff --git a/admin/assets/js/app.js b/admin/assets/js/app.js old mode 100755 new mode 100644 index 1f1a085f..1bff019b --- a/admin/assets/js/app.js +++ b/admin/assets/js/app.js @@ -20,6 +20,18 @@ var Formwork = { new Formwork.Notification($this.attr('content'), $this.data('type'), $this.data('interval')); $this.remove(); }); + + if ($('[data-command=save]').length > 0) { + $(document).keydown(function() { + if (!event.altKey && (event.ctrlKey || event.metaKey)) { + if (event.which == 83) { // ctrl/cmd + S + $('[data-command=save]').click(); + return false; + } + } + }); + } + } }; @@ -167,9 +179,6 @@ Formwork.Editor = function(id) { case 73: // ctrl/cmd + I $('[data-command=italic]', $toolbar).click(); return false; - case 83: // ctrl/cmd + S - $('[data-command=save]').click(); - return false; case 89: //ctrl/cmd + Y case 90: // ctrl/cmd + Z return false; diff --git a/admin/assets/js/app.min.js b/admin/assets/js/app.min.js old mode 100755 new mode 100644 index 68972b27..9128445f --- a/admin/assets/js/app.min.js +++ b/admin/assets/js/app.min.js @@ -1 +1 @@ -var Formwork={init:function(){Formwork.Modals.init(),Formwork.Forms.init(),Formwork.Tooltips.init(),Formwork.Dashboard.init(),Formwork.Pages.init(),$(".toggle-navigation").click(function(){$(".sidebar").toggleClass("show")}),$("[data-chart-data]").each(function(){new Formwork.Chart(this,$(this).data("chart-data"))}),$("meta[name=notification]").each(function(){var t=$(this);new Formwork.Notification(t.attr("content"),t.data("type"),t.data("interval")),t.remove()})}};$(function(){Formwork.init()}),Formwork.Chart=function(t,e){var a=new Chartist.Line(t,e,{showArea:!0,fullWidth:!0,scaleMinSpace:20,divisor:5,chartPadding:20,lineSmooth:!1,low:0,axisX:{showGrid:!1,labelOffset:{x:0,y:10}},axisY:{onlyInteger:!0,offset:15,labelOffset:{x:0,y:5}}}),n=-1!==navigator.userAgent.indexOf("Firefox");$(a.container).on("mouseover",".ct-point",function(){var t=$(this),e={x:0,y:-8};if(n){var a=parseFloat(t.css("stroke-width"));e.x+=a/2,e.y+=a/2}new Formwork.Tooltip(t.attr("ct:value"),{referenceElement:t,offset:e}).show()})},Formwork.Dashboard={init:function(){$("#clear-cache").click(function(){new Formwork.Request({method:"POST",url:Formwork.Utils.uriPrependBase("/admin/cache/clear/",location.pathname),data:{"csrf-token":$("meta[name=csrf-token]").attr("content")}},function(t){Formwork.Notification(t.message,t.status,5e3)})})}},Formwork.Editor=function(t){var i=$("#"+t)[0],e=".editor-toolbar[data-for="+t+"]";function a(){return/\n+===\n+/.test(i.value)}function n(){$("[data-command=summary]",e).attr("disabled",a())}function r(){var t=i.selectionStart;return 0===t?void 0:i.value.substring(t-1,t)}function s(t,e){void 0===e&&(e=t);var a=i.selectionStart,n=i.selectionEnd,o=a===n?"":i.value.substring(a,n);i.value=i.value.substring(0,a)+t+o+e+i.value.substring(n,i.value.length),i.setSelectionRange(a+t.length,a+t.length+o.length),$(i).blur().focus()}$("[data-command=bold]",e).click(function(){s("**")}),$("[data-command=italic]",e).click(function(){s("_")}),$("[data-command=ul]",e).click(function(){var t=r();s(void 0===t?"- ":("\n"===t?"\n":"\n\n")+"- ","")}),$("[data-command=ol]",e).click(function(){var t,e,a=r(),n="\n"===a?"\n":"\n\n",o=/^\d+\./.exec((t=i.value,-1!=(e=t.lastIndexOf("\n"))?t.substring(e+1):t));s(o?"\n"+(parseInt(o)+1)+". ":void 0===a?"1. ":n+"1. ","")}),$("[data-command=quote]",e).click(function(){var t=r();s(void 0===t?"> ":("\n"===t?"\n":"\n\n")+"> ","")}),$("[data-command=link]",e).click(function(){var t=i.selectionStart,e=i.selectionEnd,a=t===e?"":i.value.substring(t,e),n=i.value.substring(0,t),o=i.value.substring(e,i.value.length);/^(https?:\/\/|mailto:)/i.test(a)?(i.value=n+"[]("+a+")"+o,i.focus(),i.setSelectionRange(t+1,t+1)):""!==a?(i.value=n+"["+a+"](http://)"+o,i.focus(),i.setSelectionRange(t+a.length+10,t+a.length+10)):s("[","](http://)")}),$("[data-command=image]",e).click(function(){var t=r(),e="\n\n";"\n"===t?e="\n":void 0===t&&(e=""),s(e+"![](",")")}),$("[data-command=summary]",e).click(function(){var t=r();a()||(console.log(t),s((void 0===t||"\n"===t?"":"\n")+"\n===\n\n",""),$(this).attr("disabled",!0))}),$(i).keyup(Formwork.Utils.debounce(n,1e3)),n(),$(document).keydown(function(t){if(!t.altKey&&(t.ctrlKey||t.metaKey))switch(t.which){case 66:return $("[data-command=bold]",e).click(),!1;case 73:return $("[data-command=italic]",e).click(),!1;case 83:return $("[data-command=save]").click(),!1;case 89:case 90:return!1}})},Formwork.Form=function(t){var a=$(window),n=$(t);function o(){var t=n.find(":file");if(0",{class:"image-picker-thumbnails"}),n=0;n",{class:"image-picker-thumbnail","data-value":e[n].value,"data-text":e[n].text}).css({"background-image":"url("+e[n].value+")"}).appendTo(a);t.before(a),$(".image-picker-empty-state").hide()}t.hide()}),$(".image-picker-confirm").click(function(){var t=$(this);t.data("target").val(t.parent().find(".image-picker-thumbnail.selected").data("text"))}),$(".image-picker-thumbnail").click(function(){var t=$(this);t.siblings().removeClass("selected"),t.addClass("selected"),t.parent().siblings(".image-input").val(t.data("value"))}),$(".image-picker-upload").click(function(){$("#"+$(this).data("upload-target")).click()}),$(".editor-textarea").each(function(){new Formwork.Editor($(this).attr("id"))})}},Formwork.Modals={init:function(){$("[data-modal]").click(function(){var t=$(this),e=t.data("modal"),a=t.data("modal-action");a?Formwork.Modals.show(e,a):Formwork.Modals.show(e)}),$(".modal [data-dismiss]").click(function(){if($(this).is("[data-validate]")&&!Formwork.Modals.validate($(this).data("dismiss")))return;Formwork.Modals.hide($(this).data("dismiss"))}),$(".modal").click(function(t){t.target===this&&Formwork.Modals.hide()}),$(document).keyup(function(t){27==t.which&&Formwork.Modals.hide()})},show:function(t,e,a){var n=$("#"+t);n.addClass("show"),null!==e&&n.find("form").attr("action",e),n.find("[autofocus]").first().focus(),"function"==typeof a&&a(n),this.createBackdrop()},hide:function(t){(void 0===t?$(".modal"):$("#"+t)).removeClass("show"),this.removeBackdrop()},createBackdrop:function(){$(".modal-backdrop").length||$("
",{class:"modal-backdrop"}).appendTo("body")},removeBackdrop:function(){$(".modal-backdrop").remove()},validate:function(t){var e=!1,a=$("#"+t);return a.find("[required]").each(function(){if(""===$(this).val())return $(this).addClass("animated shake"),$(this).focus(),a.find(".modal-error").show(),e=!1;e=!0}),e}},Formwork.Notification=function(t,e,a){var n=$("
",{class:"notification"}).text(t);if(0<$(".notification").length){var o=$(".notification:last"),i=o.offset().top+o.outerHeight(!0);n.css("top",i)}e&&n.addClass("notification-"+e),n.appendTo("body");var r=setTimeout(s,a);function s(){var e=!1,a=n.outerHeight(!0);$(".notification").each(function(){var t=$(this);t.is(n)?(e=!0,t.addClass("fadeout")):e&&t.css("top","-="+a)}),setTimeout(function(){n.remove()},400)}n.click(s),n.mouseenter(function(){clearTimeout(r)}),n.mouseleave(function(){r=setTimeout(s,1e3)})},Formwork.Pages={init:function(){$(".page-children-toggle").click(function(t){t.stopPropagation(),$(this).closest("li").children(".pages-list").toggle(),$(this).toggleClass("toggle-expanded toggle-collapsed")}),$(".page-details a").click(function(t){t.stopPropagation()}),$("#expand-all-pages").click(function(){$(this).blur(),$(".pages-children").show(),$(".pages-list").find(".page-children-toggle").removeClass("toggle-collapsed").addClass("toggle-expanded")}),$("#collapse-all-pages").click(function(){$(this).blur(),$(".pages-children").hide(),$(".pages-list").find(".page-children-toggle").removeClass("toggle-expanded").addClass("toggle-collapsed")}),$(".page-search").focus(function(){$(".pages-children").each(function(){var t=$(this);t.data("visible",t.is(":visible"))})}),$(".page-search").keyup(Formwork.Utils.debounce(function(){var t=$(this).val();if(0===t.length)$(".pages-children").each(function(){$(this).toggle($(this).data("visible"))}),$(".page-details").css("padding-left",""),$(".pages-item, .page-children-toggle").show();else{var a=new RegExp(Formwork.Utils.escapeRegExp(t),"i");$(".pages-children").show(),$(".page-children-toggle").hide(),$(".page-details").css("padding-left","0"),$(".page-title a").each(function(){var t=$(this).closest(".pages-item"),e=!!$(this).text().match(a);e&&0,t.toggle(e)})}},100)),$(".page-details").click(function(){var t=$(this).find(".page-children-toggle").first();t.length&&t.click()}),$("#page-title","#newPageModal").keyup(function(){$("#page-slug","#newPageModal").val(Formwork.Utils.slug($(this).val()))}),$("#page-slug","#newPageModal").keyup(function(){$(this).val($(this).val().replace(" ","-").replace(/[^A-Za-z0-9\-]/g,""))}).blur(function(){""===$(this).val()&&$("#page-title","#newPageModal").trigger("keyup")}),$("#page-parent","#newPageModal").change(function(){var t=$(this).find("option:selected"),e=$("#page-template","#newPageModal"),a=t.data("allowed-templates");a?(a=a.split(", "),e.data("previous-value",e.val()).val(a[0]).find("option").each(function(){-1==a.indexOf($(this).val())&&$(this).attr("disabled",!0)})):e.find("option[disabled]").length&&e.val(e.data("previous-value")).removeData("previous-value").find("option").removeAttr("disabled")}),$(".pages-list").each(function(){var t=$(this);if(!1!==t.data("sortable-children")){var a=Sortable.create(this,{filter:"[data-sortable=false]",forceFallback:!0,onStart:function(t){$(t.item).closest(".pages-list").addClass("dragging"),$(".pages-children",t.item).hide(),$(".page-children-toggle").removeClass("toggle-expanded").addClass("toggle-collapsed").css("opacity","0.5")},onMove:function(t){if(!1===$(t.related).data("sortable"))return!1;$(".pages-children",t.related).hide()},onEnd:function(e){if($(e.item).closest(".pages-list").removeClass("dragging"),$(".page-children-toggle").css("opacity",""),e.newIndex!=e.oldIndex){a.option("disabled",!0);var t={"csrf-token":$("meta[name=csrf-token]").attr("content"),parent:$(this.el).data("parent"),from:e.oldIndex,to:e.newIndex};new Formwork.Request({method:"POST",url:Formwork.Utils.uriPrependBase("/admin/pages/reorder/",location.pathname),data:t},function(t){t.status&&Formwork.Notification(t.message,t.status,5e3),t.status&&"error"!=t.status||a.sort($(e.from).data("originalOrder")),a.option("disabled",!1),$(e.from).data("originalOrder",a.toArray())})}}});t.data("originalOrder",a.toArray())}}),$(document).keydown(function(t){if((t.ctrlKey||t.metaKey)&&70==t.which&&$(".page-search:not(:focus)").length)return $(".page-search").focus(),!1})}},Formwork.Request=function(t,e){var a=$.ajax(t);return"function"==typeof e&&a.always(function(){var t=a.responseJSON||{};403==(t.code||a.status)?location.reload():e(t,a)}),a},Formwork.Tooltip=function(t,s){var e,a,n={container:document.body,referenceElement:document.body,position:"top",offset:{x:0,y:0},delay:500},l=$(s.referenceElement);function o(){clearTimeout(a),void 0!==e&&e.fadeOut(100,function(){e.remove()})}return s=$.extend({},n,s),l.on("mouseout",o),{show:function(){a=setTimeout(function(){(e=$(' - +