From da5fa61414bba7c3331e88aad200128a8ce0d7c1 Mon Sep 17 00:00:00 2001 From: joyqi Date: Fri, 20 Dec 2013 15:52:49 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E7=BB=99markdown=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=E7=9A=84js=E8=84=9A=E6=9C=AC=E4=B8=AD=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=8F=92=E4=BB=B6=E6=8C=82=E8=BD=BD=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 让用户可以通过js扩展编辑器的功能,比如增加其他按钮等等 --- admin/editor-js.php | 2 ++ admin/js/pagedown.js | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/admin/editor-js.php b/admin/editor-js.php index bafe6e4a..eb4621e6 100644 --- a/admin/editor-js.php +++ b/admin/editor-js.php @@ -166,6 +166,8 @@ $(document).ready(function () { } }); + markdownEditor($content); ?> + var input = $('#text'), th = textarea.height(), ph = preview.height(); editor.hooks.chain('enterFakeFullScreen', function () { diff --git a/admin/js/pagedown.js b/admin/js/pagedown.js index fbb9a5b2..333713ef 100644 --- a/admin/js/pagedown.js +++ b/admin/js/pagedown.js @@ -1666,6 +1666,9 @@ else * its own image insertion dialog, this hook should return true, and the callback should be called with the chosen * image url (or null if the user cancelled). If this hook returns false, the default dialog will be used. */ + + hooks.addNoop("makeButton"); + hooks.addNoop("enterFullScreen"); hooks.addNoop("enterFakeFullScreen"); hooks.addNoop("exitFullScreen"); @@ -1699,7 +1702,7 @@ else } fullScreenManager = new FullScreenManager(hooks, getString); - uiManager = new UIManager(idPostfix, panels, undoManager, previewManager, commandManager, fullScreenManager, options.helpButton, getString); + uiManager = new UIManager(idPostfix, panels, hooks, undoManager, previewManager, commandManager, fullScreenManager, options.helpButton, getString); uiManager.setUndoRedoButtonStates(); var forceRefresh = that.refreshPreview = function () { previewManager.refresh(true); }; @@ -2788,7 +2791,7 @@ else }, 0); }; - function UIManager(postfix, panels, undoManager, previewManager, commandManager, fullScreenManager, helpOptions, getString) { + function UIManager(postfix, panels, hooks, undoManager, previewManager, commandManager, fullScreenManager, helpOptions, getString) { var inputBox = panels.input, buttons = {}; // buttons.undo, buttons.link, etc. The actual DOM elements. @@ -3094,6 +3097,9 @@ else buttons.exitFullscreen.style.display = 'none'; buttons.exitFullscreen.execute = function () { fullScreenManager.doFullScreen(buttons, false); }; + // button hooks + hooks.makeButton(buttons, makeButton, bindCommand, ui); + if (helpOptions) { var helpButton = document.createElement("li"); var helpButtonImage = document.createElement("span"); From 6c09da6bda43566d48eb01217df7eddb0762ff26 Mon Sep 17 00:00:00 2001 From: joyqi Date: Fri, 20 Dec 2013 16:17:06 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E7=BB=99markdown=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=E5=A2=9E=E5=8A=A0=E5=88=9B=E5=BB=BA=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=AF=B9=E8=AF=9D=E6=A1=86=E7=9A=84ui.dialog=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/js/pagedown.js | 126 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/admin/js/pagedown.js b/admin/js/pagedown.js index 333713ef..89e34679 100644 --- a/admin/js/pagedown.js +++ b/admin/js/pagedown.js @@ -2617,6 +2617,132 @@ else return background; }; + // 扩展了原来ui的功能 + // 允许创建一个自定义html的对话框 + ui.dialog = function (html, callback, ok, cancel) { + + // These variables need to be declared at this level since they are used + // in multiple functions. + var dialog; // The dialog box. + + // Used as a keydown event handler. Esc dismisses the prompt. + // Key code 27 is ESC. + var checkEscape = function (key) { + var code = (key.charCode || key.keyCode); + if (code === 27) { + close(true); + } + }; + + // Dismisses the hyperlink input box. + // isCancel is true if we don't care about the input text. + // isCancel is false if we are going to keep the text. + var close = function (isCancel) { + util.removeEvent(doc.body, "keydown", checkEscape); + dialog.parentNode.removeChild(dialog); + + callback(isCancel); + return false; + }; + + + + // Create the text input box form/window. + var createDialog = function () { + + // The main dialog box. + dialog = doc.createElement("div"); + dialog.className = "wmd-prompt-dialog"; + dialog.setAttribute("role", "dialog"); + /* + dialog.style.padding = "10px;"; + dialog.style.position = "fixed"; + dialog.style.width = "400px"; + dialog.style.zIndex = "1001"; + */ + + // The dialog text. + var question = doc.createElement("div"); + + // The web form container for the text box and buttons. + var form = doc.createElement("form"), + style = form.style; + form.onsubmit = function () { return close(false); }; + /* + style.padding = "0"; + style.margin = "0"; + style.cssFloat = "left"; + style.width = "100%"; + style.textAlign = "center"; + style.position = "relative"; + */ + dialog.appendChild(form); + form.appendChild(question); + + if ('function' == typeof(html)) { + html.call(this, question); + } else { + question.innerHTML = html; + } + + // The ok button + var okButton = doc.createElement("button"); + okButton.type = "button"; + okButton.className = "btn-s primary"; + okButton.onclick = function () { return close(false); }; + okButton.innerHTML = ok; + /* + style = okButton.style; + style.margin = "10px"; + style.display = "inline"; + style.width = "7em"; + */ + + // The cancel button + var cancelButton = doc.createElement("button"); + cancelButton.type = "button"; + cancelButton.className = "btn-s"; + cancelButton.onclick = function () { return close(true); }; + cancelButton.innerHTML = cancel; + /* + style = cancelButton.style; + style.margin = "10px"; + style.display = "inline"; + style.width = "7em"; + */ + + form.appendChild(okButton); + form.appendChild(cancelButton); + + util.addEvent(doc.body, "keydown", checkEscape); + /* + dialog.style.top = "50%"; + dialog.style.left = "50%"; + dialog.style.display = "block"; + if (uaSniffed.isIE_5or6) { + dialog.style.position = "absolute"; + dialog.style.top = doc.documentElement.scrollTop + 200 + "px"; + dialog.style.left = "50%"; + } + */ + doc.body.appendChild(dialog); + + // This has to be done AFTER adding the dialog to the form if you + // want it to be centered. + /* + dialog.style.marginTop = -(position.getHeight(dialog) / 2) + "px"; + dialog.style.marginLeft = -(position.getWidth(dialog) / 2) + "px"; + */ + + }; + + // Why is this in a zero-length timeout? + // Is it working around a browser bug? + setTimeout(function () { + createDialog(); + }, 0); + } + // This simulates a modal dialog box and asks for the URL when you // click the hyperlink or image buttons. // From 26adc429ee0d56ff17047cd83ccec75d527cc95e Mon Sep 17 00:00:00 2001 From: byends Date: Fri, 20 Dec 2013 23:53:01 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E7=AB=99=E7=82=B9URL=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复无法保存站点URL的BUG --- var/Widget/Options/General.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/var/Widget/Options/General.php b/var/Widget/Options/General.php index 59de4a55..66c69705 100644 --- a/var/Widget/Options/General.php +++ b/var/Widget/Options/General.php @@ -148,7 +148,7 @@ class Widget_Options_General extends Widget_Abstract_Options implements Widget_I } $settings = $this->request->from('title', 'siteUrl', 'description', 'keywords', 'allowRegister', 'timezone', 'attachmentTypes'); - $settings['siteUrl'] = rtrim('/', $settings['url']); + $settings['siteUrl'] = rtrim('/', $settings['siteUrl']); $attachmentTypes = array(); if ($this->isEnableByCheckbox($settings['attachmentTypes'], '@image@')) { From ee73a638ba8e20def202ec7cade2c24177d36c5a Mon Sep 17 00:00:00 2001 From: joyqi Date: Sat, 21 Dec 2013 09:58:26 +0800 Subject: [PATCH 4/4] fixed #142 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 尼玛,写反了。。。 --- var/Typecho/Validate.php | 3 ++- var/Widget/Options/General.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/var/Typecho/Validate.php b/var/Typecho/Validate.php index f186c0d9..f5e8fab0 100644 --- a/var/Typecho/Validate.php +++ b/var/Typecho/Validate.php @@ -110,7 +110,8 @@ class Typecho_Validate // Cycle through the rules and test for errors foreach ($rules as $key => $rules) { $this->_key = $key; - $data[$key] = (0 == strlen($data[$key])) ? NULL : $data[$key]; + $data[$key] = (is_array($data[$key]) ? 0 == count($data[$key]) + : 0 == strlen($data[$key])) ? NULL : $data[$key]; foreach ($rules as $params) { $method = $params[0]; diff --git a/var/Widget/Options/General.php b/var/Widget/Options/General.php index 66c69705..5d0bced3 100644 --- a/var/Widget/Options/General.php +++ b/var/Widget/Options/General.php @@ -148,7 +148,7 @@ class Widget_Options_General extends Widget_Abstract_Options implements Widget_I } $settings = $this->request->from('title', 'siteUrl', 'description', 'keywords', 'allowRegister', 'timezone', 'attachmentTypes'); - $settings['siteUrl'] = rtrim('/', $settings['siteUrl']); + $settings['siteUrl'] = rtrim($settings['siteUrl'], '/'); $attachmentTypes = array(); if ($this->isEnableByCheckbox($settings['attachmentTypes'], '@image@')) {