Skip to content

Commit

Permalink
Item13897: Convert TinyMCE JQuery plugin to object
Browse files Browse the repository at this point in the history
Still cannot get Wysiwyg to work, but this is now not generating any
errors.

SMELL:   The plugin expects to pull the version from the TinyMCE code.
But the new object format is static.  Need guidance.
  • Loading branch information
gac410 committed Aug 12, 2016
1 parent a157744 commit f2793be
Showing 1 changed file with 62 additions and 43 deletions.
105 changes: 62 additions & 43 deletions TinyMCEPlugin/lib/Foswiki/Plugins/TinyMCEPlugin/TinyMCE.pm
@@ -1,45 +1,61 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Javascript is Copyright (C) 2012 Sven Dowideit - SvenDowideit@fosiki.com
#
# See bottom of file for license and copyright information
package Foswiki::Plugins::TinyMCEPlugin::TinyMCE;
use v5.14;

# 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
use Foswiki::Func;
use Foswiki::Plugins;
use JSON();

package Foswiki::Plugins::TinyMCEPlugin::TinyMCE;
use strict;
use warnings;
use Foswiki::Plugins::JQueryPlugin::Plugin;
our @ISA = qw( Foswiki::Plugins::JQueryPlugin::Plugin );
use Moo;
use namespace::clean;
extends qw( Foswiki::Plugins::JQueryPlugin::Plugin );

=begin TML
---+ package Foswiki::Plugins::TinyMCEPlugin::TinyMCE
---+ package Foswiki::Plugins::JQueryPlugin::FOSWIKI
This is the perl stub for tinyMCE.
This is the perl stub for the jquery.foswiki plugin.
=cut

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

our %pluginParams = (
name => 'TinyMCE',
version => 1.2,

# version => $encodedVersion; # SMELL: version should be dynamically determined.
author => 'Foswiki Contributors',
homepage => 'https://foswiki.org/Extensions/TinyMCEPlugin',
documentation => "$Foswiki::cfg{SystemWebName}.TinyMCEPlugin",
puburl => '%PUBURLPATH%/%SYSTEMWEB%/TinyMCEPlugin',
javascript => [
'foswiki_tiny.js', 'foswiki.js',
'/tinymce/jscripts/tiny_mce/tiny_mce.js'
],
dependencies => ['foswiki'],
);

=begin TML
---++ ClassMethod init( $this )
Initialize this plugin by adding the required static files to the html header
Constructor
<script type="text/javascript" src="$pluginURL/foswiki$USE_SRC.js?v=$encodedVersion"></script>
=cut

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

# URL-encode the version number to include in the .js URLs, so that
# the browser re-fetches the .js when this plugin is upgraded.
Expand All @@ -51,28 +67,14 @@ sub new {
#$encodedVersion =~
# s/([^0-9a-zA-Z-_.:~!*'\/%])/'%'.sprintf('%02x',ord($1))/ge;

my $this = bless(
$class->SUPER::new(
name => 'TinyMCE',
version => $encodedVersion,
author => 'Foswiki Contributors',
homepage => 'http://foswiki.org/Extensions/TinyMCEPlugin',
documentation => "$Foswiki::cfg{SystemWebName}.TinyMCEPlugin",
puburl => '%PUBURLPATH%/%SYSTEMWEB%/TinyMCEPlugin',
javascript => [
'foswiki_tiny.js', 'foswiki.js',
'/tinymce/jscripts/tiny_mce/tiny_mce.js'
],
dependencies => ['foswiki']
),
$class
);

return $this;
}
return;
};

sub renderJS {
my ( $this, $text ) = @_;
my $this = shift;
my $text = shift;

print STDERR "renderJS entered with $text\n";

$text .= '?version=' . $this->{version} if ( $this->{version} =~ '$Rev$' );
$text =
Expand All @@ -81,3 +83,20 @@ sub renderJS {
}

1;

__END__
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Javascript is Copyright (C) 2012 Sven Dowideit - SvenDowideit@fosiki.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
#

0 comments on commit f2793be

Please sign in to comment.