Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undo and Redo Buttons Plugin #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions redactorextras/redactorExtrasPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
Expand All @@ -69,21 +72,26 @@ 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())
{
// 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');
Expand All @@ -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');
Expand All @@ -114,7 +122,7 @@ public function init()
{
craft()->templates->includeJsResource('redactorextras/plugins/limiter.js');
}

if($settings->extraPluginJs != "")
{
craft()->templates->includeJsFile($settings->extraPluginJs);
Expand All @@ -125,4 +133,4 @@ public function init()
}
}
}
}
}
22 changes: 22 additions & 0 deletions redactorextras/resources/plugins/bufferbuttons.js
Original file line number Diff line number Diff line change
@@ -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, '<i class="re-icon-undo"></i>');
this.button.setIcon(redo, '<i class="re-icon-redo"></i>');
}
};
};
11 changes: 10 additions & 1 deletion redactorextras/templates/_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ <h2>Extra plugins</h2>

<p>Choose from the available extra Redactor plugins:</p>

{{ forms.lightswitchField({
label: "Undo and Redo"|t,
id: "bufferButtons",
name: "bufferButtons",
instructions: "Add undo and redo buttons. <code class=\"inlinecode\">'bufferbuttons'</code>"|t,
on: settings.bufferButtons,
errors: settings.getErrors('bufferButtons')
}) }}

{{ forms.lightswitchField({
label: "Superscript and Subscript"|t,
id: "scriptButtons",
Expand Down Expand Up @@ -152,4 +161,4 @@ <h3>Custom plugin</h3>
id: "extraPluginCss",
name: "extraPluginCss",
value: settings.extraPluginCss,
}) }}
}) }}