From 757cef5e42aca6a9b4731e0d38a6332e5acd7531 Mon Sep 17 00:00:00 2001 From: Mathieu Lavigne Date: Tue, 7 Mar 2017 13:42:58 -0500 Subject: [PATCH] Undo and Redo Buttons Plugin --- redactorextras/redactorExtrasPlugin.php | 24 ++++++++++++------- .../resources/plugins/bufferbuttons.js | 22 +++++++++++++++++ redactorextras/templates/_settings.html | 11 ++++++++- 3 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 redactorextras/resources/plugins/bufferbuttons.js diff --git a/redactorextras/redactorExtrasPlugin.php b/redactorextras/redactorExtrasPlugin.php index d4c6e92..39f4c5f 100644 --- a/redactorextras/redactorExtrasPlugin.php +++ b/redactorextras/redactorExtrasPlugin.php @@ -38,15 +38,18 @@ public function getReleaseFeedUrl() { return 'https://raw.githubusercontent.com/elliotlewis/Redactor-Extras/master/changelog.json'; } - + public function getSourceLanguage() { return 'en'; } - + protected function defineSettings() { return array( + 'bufferButtons' => array( + AttributeType::Bool, 'default' => false + ), 'scriptButtons' => array( AttributeType::Bool, 'default' => false ), @@ -69,14 +72,14 @@ protected function defineSettings() 'extraPluginCss' => AttributeType::String, ); } - + public function getSettingsHtml() { return craft()->templates->render('redactorextras/_settings', array( 'settings' => $this->getSettings() )); } - + public function init() { if (craft()->request->isCpRequest()) @@ -84,6 +87,11 @@ public function init() // Get settings $settings = $this->getSettings(); + if($settings->bufferButtons === "1") + { + craft()->templates->includeJsResource('redactorextras/plugins/bufferbuttons.js'); + } + if($settings->scriptButtons === "1") { craft()->templates->includeJsResource('redactorextras/plugins/scriptbuttons.js'); @@ -99,12 +107,12 @@ public function init() craft()->templates->includeJsResource('redactorextras/plugins/alignment.js'); craft()->templates->includeCssResource('redactorextras/plugins/alignment.css'); } - + if($settings->properties === "1") { craft()->templates->includeJsResource('redactorextras/plugins/properties.js'); } - + if($settings->definedlinks === "1") { craft()->templates->includeJsResource('redactorextras/plugins/definedlinks.js'); @@ -114,7 +122,7 @@ public function init() { craft()->templates->includeJsResource('redactorextras/plugins/limiter.js'); } - + if($settings->extraPluginJs != "") { craft()->templates->includeJsFile($settings->extraPluginJs); @@ -125,4 +133,4 @@ public function init() } } } -} \ No newline at end of file +} diff --git a/redactorextras/resources/plugins/bufferbuttons.js b/redactorextras/resources/plugins/bufferbuttons.js new file mode 100644 index 0000000..7c0a82a --- /dev/null +++ b/redactorextras/resources/plugins/bufferbuttons.js @@ -0,0 +1,22 @@ +// Undo and Redo Buttons +// Adapted from offical Redactor site +// https://imperavi.com/redactor/examples/buttons-undo-and-redo/ + +if (!RedactorPlugins) var RedactorPlugins = {}; + +RedactorPlugins.bufferbuttons = function() +{ + return { + init: function() + { + var undo = this.button.addFirst('undo', 'Undo'); + var redo = this.button.addAfter('undo', 'redo', 'Redo'); + + this.button.addCallback(undo, this.buffer.undo); + this.button.addCallback(redo, this.buffer.redo); + + this.button.setIcon(undo, ''); + this.button.setIcon(redo, ''); + } + }; +}; diff --git a/redactorextras/templates/_settings.html b/redactorextras/templates/_settings.html index 15319ac..3c93eb3 100755 --- a/redactorextras/templates/_settings.html +++ b/redactorextras/templates/_settings.html @@ -44,6 +44,15 @@

Extra plugins

Choose from the available extra Redactor plugins:

+{{ forms.lightswitchField({ + label: "Undo and Redo"|t, + id: "bufferButtons", + name: "bufferButtons", + instructions: "Add undo and redo buttons. 'bufferbuttons'"|t, + on: settings.bufferButtons, + errors: settings.getErrors('bufferButtons') +}) }} + {{ forms.lightswitchField({ label: "Superscript and Subscript"|t, id: "scriptButtons", @@ -152,4 +161,4 @@

Custom plugin

id: "extraPluginCss", name: "extraPluginCss", value: settings.extraPluginCss, -}) }} \ No newline at end of file +}) }}