Skip to content

Commit

Permalink
Item8189: detwikify+enhance NatEdit
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@4363 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Jul 2, 2009
1 parent e534311 commit 0811725
Show file tree
Hide file tree
Showing 54 changed files with 1,694 additions and 870 deletions.
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1209484064" format="1.1" reprev="1.2" version="$Rev$"}%
%META:TOPICINFO{author="ProjectContributor" date="1233664112" format="1.1" version="1.2"}%
---+!! Natural Edit Plugin
<!--

Expand Down Expand Up @@ -42,7 +42,7 @@ same button layout for now.
jquery.natedit docu

---++ Screenshot
<img src="%ATTACHURLPATH%/screenshot1.png" alt="screenshot1.png" />
<a href="%ATTACHURLPATH%/screenshot1.png" title="screenshot"><img src="%ATTACHURLPATH%/screenshot1.png" alt="screenshot" border="0" /></a>

---++ Configuration
*PatternSkin:* %BR%
Expand Down Expand Up @@ -84,8 +84,14 @@ Sponsored by [[http://www.trivadis.com][Trivadis AG]]
| Author: | Michael Daum |
| Copyright &copy;: | 2007-2009 Michael Daum http://michaeldaumconsulting.com |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Version: | v3.32 |
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | |
| 23 Jun 2009 | converted to foswiki, lots of feature enhancements |
| 03 Feb 2009 | fixed preview+save on Foswiki/<nop>PatternSkin; \
fixed force new revision; \
added a workaround to bind the submit event to the return key in input fields \
(gets hijacked by jscalendar popup otherwise) |
| 15 Jan 2009 | fixed buttons in preview screen |
| 07 Jan 2009 | support for <nop>TinyMCEPlugin wysiwyg editor; \
removed non-maintained "word" style; \
Expand Down Expand Up @@ -113,10 +119,10 @@ Sponsored by [[http://www.trivadis.com][Trivadis AG]]
fixed initialization not to use Behaviour anymore, \
fixed autohide/showing of word toolbar together with tinymce |
| 08 Oct 2007 | fixed word toolbar together with <nop>TinyMCEPlugin; \
fixed launching a popup by not relying on twiki's javascript; \
fixed launching a popup by not relying on standard javascript; \
using css sprites instead of individual buttons |
| 02 Oct 2007 | be compatible with <nop>TinyMCEPlugin |
| 23 Aug 2007 | bug fixes for IE6&7 - [[http://develop.twiki.org/~twiki4/cgi-bin/view/Bugs/Item4430][Item4430]] |
| 23 Aug 2007 | bug fixes for IE6&7 - Item4430 |
| 04 Aug 2007 | added Word theme \
added bullet and numbered lists buttons & Javascript \
added create Table button and Javascript \
Expand All @@ -136,7 +142,7 @@ Sponsored by [[http://www.trivadis.com][Trivadis AG]]
minor refactoring of the javascript; \
removed non-standard tags FORMATLIST and IFDEFINED |
| 03 Apr 2007 | added NATEDIT_HELPTEXT variable; \
be backwards compatible to <nop>PatternSkin (TWiki-4.1.2) |
be backwards compatible to <nop>PatternSkin |
| 31 Mar 2007 | Initial version |
| Dependencies: | %$DEPENDENCIES% |
| Perl Version: | - |
Expand Down
Expand Up @@ -217,4 +217,4 @@ txtarea = areas[0];
<a href="javascript:testLineLineNumberedBullet2()" ><span>testLineLineNumberedBullet2</span></a>


<textarea class="twikiEditboxStyleProportional" id="topic" name="text" rows="22" cols="70" style='width: 99%' onkeydown='handleKeyDown(event)'></textarea>
<textarea class="foswikiEditboxStyleProportional" id="topic" name="text" rows="22" cols="70" style='width: 99%' onkeydown='handleKeyDown(event)'></textarea>
Expand Up @@ -10,61 +10,53 @@
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

package TWiki::Plugins::NatEditPlugin;
package Foswiki::Plugins::NatEditPlugin;

use strict;
use TWiki::Func;
use Foswiki::Func;


use vars qw(
$VERSION $RELEASE $SHORTDESCRIPTION $NO_PREFS_IN_TOPIC
$baseWeb $baseTopic $doneHeader $header
$baseWeb $baseTopic
);

$VERSION = '$Rev$';
$RELEASE = 'v3.32';
$RELEASE = 'v4.00';

$NO_PREFS_IN_TOPIC = 1;
$SHORTDESCRIPTION = 'A Wikiwyg Editor';

use constant DEBUG => 0; # toggle me

$header = <<'HERE';
<style type="text/css" media="all">
@import url("%PUBURLPATH%/%TWIKIWEB%/NatEditPlugin/styles.css");
@import url("%PUBURLPATH%/%TWIKIWEB%/NatEditPlugin/%IF{"defined NATEDIT_THEME" then="%NATEDIT_THEME%" else="default"}%/styles.css");
</style>
<script type="text/javascript" src="%PUBURLPATH%/%TWIKIWEB%/NatEditPlugin/edit.js"></script>
<script type="text/javascript" src="%PUBURLPATH%/%TWIKIWEB%/NatEditPlugin/jquery.natedit.js"></script>
HERE
use Foswiki::Plugins::JQueryPlugin ();

###############################################################################
sub writeDebug {
return unless DEBUG;
print STDERR "- NatEditPlugin - " . $_[0] . "\n";
#TWiki::Func::writeDebug("- NatEditPlugin - $_[0]");
#Foswiki::Func::writeDebug("- NatEditPlugin - $_[0]");
}


###############################################################################
sub initPlugin {
($baseTopic, $baseWeb) = @_;

TWiki::Func::registerTagHandler('FORMBUTTON', \&handleFORMBUTTON);
TWiki::Func::registerTagHandler('NATFORMLIST', \&handleNATFORMLIST);

Foswiki::Func::registerTagHandler('FORMBUTTON', \&handleFORMBUTTON);
Foswiki::Func::registerTagHandler('NATFORMLIST', \&handleNATFORMLIST);

my $skin = TWiki::Func::getPreferencesValue('SKIN');
# not using TWiki::Func::getSkin() to prevent
my $skin = Foswiki::Func::getPreferencesValue('SKIN');
# not using Foswiki::Func::getSkin() to prevent
# getting the cover as well

unless ($skin =~ /\b(natedit)\b/) {
$skin = "natedit,$skin";
my $prefs = $TWiki::Plugins::SESSION->{prefs} || $Foswiki::Plugins::SESSION->{prefs};
$prefs->pushPreferenceValues('SESSION', { SKIN => $skin } );
Foswiki::Func::setPreferencesValue('SKIN', $skin);
}

TWiki::Func::addToHEAD("natedit", $header);
# register the natedit jquery plugin
Foswiki::Plugins::JQueryPlugin::registerPlugin("NatEdit",
'Foswiki::Plugins::NatEditPlugin::NATEDIT');

return 1;
}
Expand All @@ -82,15 +74,17 @@ sub initPlugin {
sub handleFORMBUTTON {
my ($session, $params, $theTopic, $theWeb) = @_;

Foswiki::Plugins::JQueryPlugin::createPlugin("natedit");

my $saveCmd = '';
my $request = TWiki::Func::getCgiQuery();
my $request = Foswiki::Func::getCgiQuery();
$saveCmd = $request->param('cmd') || '' if $request;
return '' if $saveCmd eq 'repRev';

my $form = $request->param('formtemplate') || '';

unless ($form) {
my ($meta, $dumy) = TWiki::Func::readTopic($theWeb, $theTopic);
my ($meta, $dumy) = Foswiki::Func::readTopic($theWeb, $theTopic);
my $formMeta = $meta->get('FORM');
$form = $formMeta->{"name"} if $formMeta;
}
Expand All @@ -110,7 +104,7 @@ sub handleFORMBUTTON {
if ($form) {
$actionText = $session->{i18n}->maketext("Change form");
$actionTitle = $session->{i18n}->maketext("Change the current form of <nop>[_1]", "$theWeb.$theTopic");
} elsif (TWiki::Func::getPreferencesValue('WEBFORMS', $theWeb)) {
} elsif (Foswiki::Func::getPreferencesValue('WEBFORMS', $theWeb)) {
$actionText = $session->{i18n}->maketext("Add form");
$actionTitle = $session->{i18n}->maketext("Add a new form to <nop>[_1]", "$theWeb.$theTopic");
} else {
Expand All @@ -123,22 +117,23 @@ sub handleFORMBUTTON {
$theFormat =~ s/\$script/submitEditForm('save', '$action');/g;
$theFormat =~ s/\$title/$actionTitle/g;
$theFormat =~ s/\$action/$actionText/g;
$theFormat = TWiki::Func::expandCommonVariables($theFormat, $theTopic, $theWeb)
$theFormat =~ s/\$id/$action/g;
$theFormat = Foswiki::Func::expandCommonVariables($theFormat, $theTopic, $theWeb)
if escapeParameter($theFormat);

return $theFormat;
}

###############################################################################
# This function will store the TopicTitle in a preference variable if it isn't
# part of the TWikiForm of this topic. In a way, we do the reverse of
# part of the DataForm of this topic. In a way, we do the reverse of
# WebDB::onReload() where the TopicTitle is extracted and put into the cache.
sub beforeSaveHandler {
my ($text, $topic, $web, $meta) = @_;

#writeDebug("called beforeSaveHandler");
# find out if we received a TopicTitle
my $request = TWiki::Func::getCgiQuery();
my $request = Foswiki::Func::getCgiQuery();
my $topicTitle = $request->param('TopicTitle');

unless (defined $topicTitle) {
Expand Down Expand Up @@ -197,7 +192,7 @@ sub beforeSaveHandler {
#writeDebug("no TopicTitle stored anywhere. creating a new preference setting");

if ($topicTitle) { # but only if we don't set it to the empty string
$meta->put('PREFERENCE', {
$meta->putKeyed('PREFERENCE', {
name=>'TOPICTITLE',
title=>'TOPICTITLE',
type=>'Local',
Expand All @@ -208,7 +203,7 @@ sub beforeSaveHandler {
}

###############################################################################
# taken from TWiki::UI::ChangeForm and leveraged to normal formatting standards
# taken from Foswiki::UI::ChangeForm and leveraged to normal formatting standards
sub handleNATFORMLIST {
my ($session, $params, $theTopic, $theWeb) = @_;

Expand All @@ -223,18 +218,18 @@ sub handleNATFORMLIST {
my $theFooter = $params->{footer} || '';
my $theSelected = $params->{selected};

my $request = TWiki::Func::getCgiQuery();
my $request = Foswiki::Func::getCgiQuery();
$theSelected = $request->param('formtemplate') unless defined $theSelected;
$theSeparator = '<br />' unless defined $theSeparator;

unless ($theSelected) {
my ($meta) = TWiki::Func::readTopic($theWeb, $theTopic);
my ($meta) = Foswiki::Func::readTopic($theWeb, $theTopic);
my $form = $meta->get( 'FORM' );
$theSelected = $form->{name} if $form;
}
$theSelected = 'none' unless $theSelected;

my $legalForms = TWiki::Func::getPreferencesValue('WEBFORMS', $theWeb);
my $legalForms = Foswiki::Func::getPreferencesValue('WEBFORMS', $theWeb);
$legalForms =~ s/^\s*//;
$legalForms =~ s/\s*$//;
my %forms = map {$_ => 1} split( /[,\s]+/, $legalForms );
Expand Down Expand Up @@ -262,7 +257,7 @@ sub handleNATFORMLIST {
$result =~ s/\$count/$index/g;
$result =~ s/\$web/$theWeb/g;
$result =~ s/\$topic/$theTopic/g;
$result = TWiki::Func::expandCommonVariables($result, $theTopic, $theWeb)
$result = Foswiki::Func::expandCommonVariables($result, $theTopic, $theWeb)
if escapeParameter($result);

return $result;
Expand Down
3 changes: 3 additions & 0 deletions NatEditPlugin/lib/Foswiki/Plugins/NatEditPlugin/DEPENDENCIES
@@ -0,0 +1,3 @@
Foswiki::Plugins::JQueryPlugin,>=1.00,perl,Required.
Foswiki::Plugins::SetVariablePlugin,>=1.00,perl,Required.
Foswiki::Plugins::UploadPlugin,>=1.00,perl,Required.
52 changes: 52 additions & 0 deletions NatEditPlugin/lib/Foswiki/Plugins/NatEditPlugin/MANIFEST
@@ -0,0 +1,52 @@
data/System/NatEditHelpText.txt 0644
data/System/NatEditPluginJSUnitTests.txt 0644
data/System/NatEditPlugin.txt 0644
data/System/NatEditWordHelpText.txt 0644
lib/Foswiki/Plugins/NatEditPlugin/NATEDIT.pm 0644
lib/Foswiki/Plugins/NatEditPlugin.pm 0644
pub/System/NatEditPlugin/default/btn_cyan_left.gif 0644
pub/System/NatEditPlugin/default/btn_cyan_right.gif 0644
pub/System/NatEditPlugin/default/btn_green_left.gif 0644
pub/System/NatEditPlugin/default/btn_green_right.gif 0644
pub/System/NatEditPlugin/default/btn_left.gif 0644
pub/System/NatEditPlugin/default/btn_red_left.gif 0644
pub/System/NatEditPlugin/default/btn_red_right.gif 0644
pub/System/NatEditPlugin/default/btn_right.gif 0644
pub/System/NatEditPlugin/default/buttons_sprite.gif 0644
pub/System/NatEditPlugin/default/buttons_sprite.png 0644
pub/System/NatEditPlugin/default/Makefile 0644
pub/System/NatEditPlugin/default/styles.css 0644
pub/System/NatEditPlugin/default/styles.css.gz 0644
pub/System/NatEditPlugin/edit.js 0644
pub/System/NatEditPlugin/edit.js.gz 0644
pub/System/NatEditPlugin/edit.uncompressed.js 0644
pub/System/NatEditPlugin/jquery.natedit.insertattachment.js 0644
pub/System/NatEditPlugin/jquery.natedit.insertattachment.js.gz 0644
pub/System/NatEditPlugin/jquery.natedit.insertlink.js 0644
pub/System/NatEditPlugin/jquery.natedit.insertlink.js.gz 0644
pub/System/NatEditPlugin/jquery.natedit.inserttable.js 0644
pub/System/NatEditPlugin/jquery.natedit.inserttable.js.gz 0644
pub/System/NatEditPlugin/jquery.natedit.js 0644
pub/System/NatEditPlugin/jquery.natedit.js.gz 0644
pub/System/NatEditPlugin/jquery.natedit.uncompressed.js 0644
pub/System/NatEditPlugin/Makefile 0644
pub/System/NatEditPlugin/screenshot1.png 0644
pub/System/NatEditPlugin/styles.css 0644
pub/System/NatEditPlugin/styles.css.gz 0644
pub/System/NatEditPlugin/styles.uncompressed.css 0644
pub/System/NatEditPlugin/wikiringlogo40x40.png 0644
templates/addform.natedit.tmpl 0644
templates/editdialog.natedit.tmpl 0644
templates/editform.natedit.tmpl 0644
templates/edithelp.natedit.tmpl 0644
templates/editjavascript.natedit.tmpl 0644
templates/edit.natedit.tmpl 0644
templates/editsection.natedit.tmpl 0644
templates/edittext.natedit.tmpl 0644
templates/edittoolbar.natedit.tmpl 0644
templates/edittoolbar.word.natedit.tmpl 0644
templates/form.natedit.tmpl 0644
templates/preview.natedit.tmpl 0644
templates/previewtoolbar.natedit.tmpl 0644
templates/settings.natedit.tmpl 0644
templates/settingstoolbar.natedit.tmpl 0644
81 changes: 81 additions & 0 deletions NatEditPlugin/lib/Foswiki/Plugins/NatEditPlugin/NATEDIT.pm
@@ -0,0 +1,81 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2006-2009 Michael Daum, http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details, published at
# http://www.gnu.org/copyleft/gpl.html

package Foswiki::Plugins::NatEditPlugin::NATEDIT;
use strict;

use base 'Foswiki::Plugins::JQueryPlugin::Plugin';

=begin TML
---+ package Foswiki::Plugins::NatEditPlugin::NATEDIT
This is the perl stub for the jquery.natedit plugin.
=cut

=begin TML
---++ ClassMethod new( $class, $session, ... )
Constructor
=cut

sub new {
my $class = shift;
my $session = shift || $Foswiki::Plugins::SESSION;

my $this = bless($class->SUPER::new(
$session,
name => 'NatEdit',
version => '1.0',
author => 'Michael Daum',
homepage => 'http://foswiki.org/Extensions/NatEditPlugin',
puburl => '%PUBURLPATH%/%SYSTEMWEB%/NatEditPlugin',
css => ['styles.css'],
javascript => ['edit.js', 'jquery.natedit.js'],
dependencies => ['simplemodal', 'textboxlist', 'form'],
), $class);

$this->{summary} = <<'HERE';
HERE

return $this;
}

=begin TML
---++ ClassMethod init( $this )
Initialize this plugin by adding the required static files to the html header
=cut

sub init {
my $this = shift;

return unless $this->SUPER::init();

Foswiki::Func::addToHEAD("JQUERYPLUGIN::NATEDIT::THEME", <<'HERE', 'JQUERYPLUGIN::NATEDIT');
<style type="text/css" media="all">
@import url("%PUBURLPATH%/%SYSTEMWEB%/NatEditPlugin/styles.css");
@import url("%PUBURLPATH%/%SYSTEMWEB%/NatEditPlugin/%IF{"defined NATEDIT_THEME" then="%NATEDIT_THEME%" else="default"}%/styles.css");
</style>
HERE

}

1;
1 change: 0 additions & 1 deletion NatEditPlugin/lib/TWiki/Plugins/NatEditPlugin/DEPENDENCIES

This file was deleted.

0 comments on commit 0811725

Please sign in to comment.