Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Commit

Permalink
Changed and improved the functionality to include JavaScript code tha…
Browse files Browse the repository at this point in the history
…t is supposed to be run inside of $(document).ready(). Script tags will now be cut out.
  • Loading branch information
mgruner committed Apr 22, 2010
1 parent da59e85 commit 180e560
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
41 changes: 31 additions & 10 deletions Kernel/Output/HTML/Layout.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Kernel/Output/HTML/Layout.pm - provides generic HTML output
# Copyright (C) 2001-2010 OTRS AG, http://otrs.org/
# --
# $Id: Layout.pm,v 1.231 2010-04-19 18:17:34 martin Exp $
# $Id: Layout.pm,v 1.232 2010-04-22 17:45:15 mg Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
Expand All @@ -22,7 +22,7 @@ use Kernel::System::JSON;
use Mail::Address;

use vars qw(@ISA $VERSION);
$VERSION = qw($Revision: 1.231 $) [1];
$VERSION = qw($Revision: 1.232 $) [1];

=head1 NAME
Expand Down Expand Up @@ -680,24 +680,24 @@ sub Output {

# find document ready
$Output =~ s{
<!--\s{0,1}dtl:document_ready\s{0,1}-->(.+?)<!--\s{0,1}dtl:document_ready\s{0,1}-->
<!--\s{0,1}dtl:JSOnDocumentComplete\s{0,1}-->(.+?)<!--\s{0,1}dtl:JSOnDocumentComplete\s{0,1}-->
}
{
if (!$Self->{DocumentReady}->{$1}) {
$Self->{DocumentReady}->{$1} = 1;
$Self->{EnvRef}->{DocumentReady} .= $1;
if (!$Self->{JSOnDocumentComplete}->{$1}) {
$Self->{JSOnDocumentComplete}->{$1} = 1;
$Self->{EnvRef}->{JSOnDocumentComplete} .= $Self->_RemoveScriptTags(Code => $1);
}
"";
}segxm;

# replace document ready placeholder (only if it's not included via $Include{""})
if ( !$Param{Include} ) {
$Output =~ s{
<!--\s{0,1}dtl:document_ready_placeholder\s{0,1}-->
<!--\s{0,1}dtl:JSOnDocumentCompletePlaceholder\s{0,1}-->
}
{
if ( $Self->{EnvRef}->{DocumentReady} ) {
$Self->{EnvRef}->{DocumentReady};
if ( $Self->{EnvRef}->{JSOnDocumentComplete} ) {
$Self->{EnvRef}->{JSOnDocumentComplete};
}
else {
"";
Expand Down Expand Up @@ -4556,6 +4556,27 @@ sub _DisableBannerCheck {
return 1
}

=item _RemoveScriptTags()
This function will remove the surrounding <script> tags of a
piece of JavaScript code, if they are present, and return the result.
my $CodeContent = $LayoutObject->_RemoveScriptTags(Code => $SomeCode);
=cut

sub _RemoveScriptTags {
my ( $Self, %Param ) = @_;

my $Code = $Param{Code} || '';

if ( $Code =~ m/<script/ ) {
$Code =~ s{<script[^>]+>\s*(?:<!--)?(?://<!\[CDATA\[)?\s*}{};
$Code =~ s{(?:-->)?(?://\]\]>)?</script>}{};
}
return $Code;
}

1;

=end Internal:
Expand All @@ -4572,6 +4593,6 @@ did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
=head1 VERSION
$Revision: 1.231 $ $Date: 2010-04-19 18:17:34 $
$Revision: 1.232 $ $Date: 2010-04-22 17:45:15 $
=cut
8 changes: 4 additions & 4 deletions Kernel/Output/HTML/Standard/Footer.dtl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Footer.dtl - provides global HTML footer
# Copyright (C) 2001-2010 OTRS AG, http://otrs.org/
# --
# $Id: Footer.dtl,v 1.35 2010-04-21 23:07:41 mn Exp $
# $Id: Footer.dtl,v 1.36 2010-04-22 17:45:16 mg Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
Expand Down Expand Up @@ -66,10 +66,12 @@
Images: '$Config{"Frontend::ImagePath"}'
});
OTRS.App.Init();

<!-- dtl:JSOnDocumentCompletePlaceholder -->

});
//]]></script>


<!--[if IE 7]>
<script type="text/javascript" src="$Config{"Frontend::WebPath"}js_new/OTRS.UI.IE7Fixes.js"></script>
<script type="text/javascript">//<![CDATA[
Expand All @@ -80,7 +82,5 @@
//]]></script>
<![endif]-->

<!-- dtl:document_ready_placeholder -->

</body>
</html>
19 changes: 8 additions & 11 deletions Kernel/Output/HTML/Standard/Header.dtl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Header.dtl - provides global HTML header
# Copyright (C) 2001-2010 OTRS AG, http://otrs.org/
# --
# $Id: Header.dtl,v 1.75 2010-04-22 15:46:36 mg Exp $
# $Id: Header.dtl,v 1.76 2010-04-22 17:45:16 mg Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
Expand Down Expand Up @@ -96,19 +96,16 @@ $Include{"Copyright"}
# <a href="#" id="ToolbarProfileSearch" title="$Text{"$QData{"Description"}"}" accesskey="$QData{"AccessKey"}" $Data{"LinkOption"}>$Text{"$QData{"Name"}"}<span class="Gloss"></span></a>
</form>
</li>
<!-- dtl:document_ready -->
<!-- dtl:JSOnDocumentComplete -->
<script type="text/javascript">//<![CDATA[
"use strict";
$(document).ready(function () {
OTRS.UI.Toolbar.RegisterEvent('change', 'Profile', function (Event) {
$(Event.target).closest('form').submit();
Event.preventDefault();
Event.stopPropagation();
return false;
});
OTRS.UI.Toolbar.RegisterEvent('change', 'Profile', function (Event) {
$(Event.target).closest('form').submit();
Event.preventDefault();
Event.stopPropagation();
return false;
});
//]]></script>
<!-- dtl:document_ready -->
<!-- dtl:JSOnDocumentComplete -->
<!-- dtl:block:ToolBarSearchProfile -->
<!-- dtl:block:ToolBarSearchFulltext -->
<li class="Extended SearchFulltext">
Expand Down

0 comments on commit 180e560

Please sign in to comment.