From fa48866443119acd0b8aae89b472b9af8adc9623 Mon Sep 17 00:00:00 2001 From: joyqi Date: Wed, 23 Oct 2013 22:32:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3markdown=E7=9A=84=E5=85=A8?= =?UTF-8?q?=E5=B1=8Fbug=EF=BC=8C=E5=8D=B3=E6=8C=89esc=E6=88=96=E8=80=85F11?= =?UTF-8?q?=E9=80=80=E5=87=BA=E5=85=A8=E5=B1=8F=E7=8A=B6=E6=80=81=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E7=BC=96=E8=BE=91=E5=99=A8=E4=B8=8D=E8=83=BD=E8=BF=98?= =?UTF-8?q?=E5=8E=9F=EF=BC=8C=E5=BF=85=E9=A1=BB=E5=86=8D=E6=8C=89=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E6=8C=89=E9=92=AE=E6=89=8D=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/js/markdown.js | 118 ++++++++++++++++++++++++++----------------- admin/write-js.php | 2 + 2 files changed, 74 insertions(+), 46 deletions(-) diff --git a/admin/js/markdown.js b/admin/js/markdown.js index fbe343d2..cc3aa9cb 100644 --- a/admin/js/markdown.js +++ b/admin/js/markdown.js @@ -3057,6 +3057,8 @@ else heading: "Heading

/

Ctrl+H", headingexample: "Heading", + fullscreen: 'FullScreen Ctrl+M', + hr: "Horizontal Rule
Ctrl+R", undo: "Undo - Ctrl+Z", @@ -3565,56 +3567,77 @@ else refreshState(); }; + var getFullScreenAdapter = function () { + var selector = { + fullScreenChange : ['onfullscreenchange', 'onwebkitfullscreenchange', 'onmozfullscreenchange'], + requestFullscreen : ['requestFullscreen', 'webkitRequestFullScreen', 'mozRequestFullScreen'], + cancelFullscreen : ['cancelFullscreen', 'webkitCancelFullScreen', 'mozCancelFullScreen'] + }, adapter = {}; + + for (var name in selector) { + var len = selector[name].length, found = false; + + for (var i = 0; i < len; i ++) { + var method = selector[name][i]; + + if ('undefined' != typeof(document[method]) || 'undefined' != typeof(document.body[method])) { + adapter[name] = method; + found = true; + break; + } + } + + if (!found) { + return false; + } + } + + return adapter; + } + + var isFullScreen = function () { + return document.fullScreen || + document.mozFullScreen || + document.webkitIsFullScreen; + } + + var fullScreenBind = false; + // fullscreen this.fullscreen = function () { - var nativeFsWebkit = document.body.webkitRequestFullScreen ? true : false; - var nativeFsMoz = document.body.mozRequestFullScreen ? true : false; - var nativeFsW3C = document.body.requestFullscreen ? true : false; - var nativeFs = nativeFsWebkit || nativeFsMoz || nativeFsW3C; - var input = panels.input, preview = panels.preview, buttonBar = panels.buttonBar, parent = buttonBar.parentNode; - parent.style.display = 'none'; - var isFullScreen = parent.getAttribute('isFullScreen'); - if (isFullScreen != 'true') { - parent.setAttribute('isFullScreen', true); - var windowHeight; - if (nativeFs) { - if (nativeFsWebkit) { - parent.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT); - } - else if (nativeFsMoz) { - parent.mozRequestFullScreen(); - } - else if (nativeFsW3C) { - parent.requestFullscreen(); - } - } + var input = panels.input, preview = panels.preview, buttonBar = panels.buttonBar, + adapter = getFullScreenAdapter(); - windowHeight = window.screen.height - 32; - - input.style.cssText = "width:50%;background-color:#000000;color:#ffffff;position:absolute;z-index:999;top:32px;left:0;box-sizing: border-box;"; - input.style.height = windowHeight + 'px'; - buttonBar.style.cssText = "width:100%;background-color:#ffffff;position:absolute;z-index:1000;top:0;left:0"; - preview.style.cssText = "width:50%;background-color:#ffffff;position:absolute;z-index:999;top:32px;right:0;box-sizing: border-box;overflow: auto;"; - preview.style.height = windowHeight + 'px'; - - } else { - parent.setAttribute('isFullScreen', false); - if (nativeFs) { - if (nativeFsWebkit) { - document.webkitCancelFullScreen(); - } - else if (nativeFsMoz) { - document.mozCancelFullScreen(); - } - else if (nativeFsW3C) { - document.exitFullscreen(); - } - } - input.style.cssText = 'height:350px;'; - preview.style.cssText = ''; - buttonBar.style.cssText = ''; + if (!adapter) { + return false; + } + + if (!fullScreenBind) { + util.addEvent(document, adapter.fullScreenChange.substring(2), function () { + if (!isFullScreen()) { + input.style.cssText = 'height:350px;'; + preview.style.cssText = ''; + buttonBar.style.cssText = ''; + } else { + var windowHeight = window.screen.height - 32; + + input.style.cssText = "width:50%;background-color:#000000;color:#ffffff;position:absolute;z-index:999;top:32px;left:0;box-sizing: border-box;"; + input.style.height = windowHeight + 'px'; + buttonBar.style.cssText = "width:100%;background-color:#ffffff;position:absolute;z-index:1000;top:0;left:0"; + preview.style.cssText = "width:50%;background-color:#ffffff;position:absolute;z-index:999;top:32px;right:0;box-sizing: border-box;overflow: auto;"; + preview.style.height = windowHeight + 'px'; + } + }); + + fullScreenBind = true; + } + + if (!isFullScreen()) { + document.body[adapter.requestFullscreen]('webkitRequestFullScreen' == adapter.requestFullscreen + ? Element.ALLOW_KEYBOARD_INPUT : null); + } else { + document[adapter.cancelFullscreen](); } - parent.style.display = ''; }; // Push the input area state to the stack. @@ -4350,6 +4373,9 @@ else case "u": doClick(buttons.ulist); break; + case 'm': + doClick(buttons.fullscreen); + break; case "h": doClick(buttons.heading); break; diff --git a/admin/write-js.php b/admin/write-js.php index 89c1a6f8..18bb0f52 100644 --- a/admin/write-js.php +++ b/admin/write-js.php @@ -239,6 +239,8 @@ $(document).ready(function () { redo: ' - Ctrl+Y', redomac: ' - Ctrl+Shift+Z', + fullscreen: ' - Ctrl+M', + imagedialog: '

', linkdialog: '

',