[Rt-commit] rt branch, 4.6/move-inline-js-to-static, created. rt-4.4.2-96-g8882f89be
Maureen Mirville
maureen at bestpractical.com
Thu May 31 19:04:35 EDT 2018
The branch, 4.6/move-inline-js-to-static has been created
at 8882f89be9de8f958d377a524a78e48fef176f6e (commit)
- Log -----------------------------------------------------------------
commit 8882f89be9de8f958d377a524a78e48fef176f6e
Author: Maureen E. Mirville <maureen at bestpractical.com>
Date: Tue May 29 14:41:36 2018 -0400
Move inline javascript to share/static directory
In an effort to comply with the new Content Security Policies,
inline javascript has been removed from share/html files, except
those containing perl variables.
diff --git a/share/html/Admin/Tools/Queries.html b/share/html/Admin/Tools/Queries.html
index 6e874ecfd..60b5d9d82 100644
--- a/share/html/Admin/Tools/Queries.html
+++ b/share/html/Admin/Tools/Queries.html
@@ -66,9 +66,7 @@ unless ($session{'CurrentUser'}->HasRight( Object=> $RT::System, Right => 'Super
% } elsif (!$history) {
<p><&|/l&>This server process has recorded no SQL queries.</&></p>
% } else {
- <script type="text/javascript">
- jQuery(function () { jQuery(".tablesorter").tablesorter(); });
- </script>
+ <script type="text/javascript" src="<%RT->Config->Get('WebPath')%>/static/js/admin.js"></script>
<ol>
% my $r = 0;
diff --git a/share/html/Prefs/AboutMe.html b/share/html/Prefs/AboutMe.html
index 67e5238de..7b995e3d3 100644
--- a/share/html/Prefs/AboutMe.html
+++ b/share/html/Prefs/AboutMe.html
@@ -181,14 +181,7 @@
Label => loc('Reset secret authentication token'),
Name => "ResetAuthToken",
id => "ResetAuthTokenContainer" &>
-<script>
- jQuery("#ResetAuthTokenContainer").hide();
- jQuery("#ResetAuthTokenPrompt").show().click(function(ev){
- jQuery(this).slideUp();
- jQuery("#ResetAuthTokenContainer").slideDown();
- ev.preventDefault();
- });
-</script>
+<script src="<%RT->Config->Get('WebPath')%>/static/js/util.js"></script>
</&>
% $m->callback( %ARGS, UserObj => $UserObj, CallbackName => 'FormRightColumn' );
diff --git a/share/html/Search/Chart.html b/share/html/Search/Chart.html
index 1a6768a51..3f1b27271 100644
--- a/share/html/Search/Chart.html
+++ b/share/html/Search/Chart.html
@@ -194,28 +194,7 @@ $m->callback( ARGSRef => \%ARGS, QueryArgsRef => \%query );
<input type="checkbox" name="ChartStyleIncludeSQL" <% $query{ChartStyle} =~ /\bsql\b/ ? 'checked="checked"' : '' |n %>> <% loc('Include TicketSQL query') %>
</div>
</&>
-<script type="text/javascript">
-var updateChartStyle = function() {
- var val = jQuery(".chart-picture [name=ChartType]").val();
- if ( val != 'table' && jQuery(".chart-picture [name=ChartStyleIncludeTable]").is(':checked') ) {
- val += '+table';
- }
- if ( jQuery(".chart-picture [name=ChartStyleIncludeSQL]").is(':checked') ) {
- val += '+sql';
- }
- jQuery(".chart-picture [name=ChartStyle]").val(val);
-};
-jQuery(".chart-picture [name=ChartType]").change(function(){
- var t = jQuery(this);
- t.closest("form").find("[name=Height]").closest(".height").toggle( t.val() == 'bar' );
- t.closest("form").find("[name=Width]").closest(".width").toggle( t.val() !== 'table' );
- t.closest("form .chart-picture").find("div.include-table").toggle( t.val() !== 'table' );
- updateChartStyle();
-}).change();
-
-jQuery(".chart-picture [name=ChartStyleIncludeTable]").change( updateChartStyle );
-jQuery(".chart-picture [name=ChartStyleIncludeSQL]").change( updateChartStyle );
-</script>
+<script type="text/javascript" src="<%RT->Config->Get('WebPath')%>/static/js/search.js"></script>
<& /Elements/Submit, Label => loc('Update Chart'), Name => 'Update' &>
</form>
diff --git a/share/html/Search/Elements/PickBasics b/share/html/Search/Elements/PickBasics
index 3f2ed237a..186b7e5e5 100644
--- a/share/html/Search/Elements/PickBasics
+++ b/share/html/Search/Elements/PickBasics
@@ -227,48 +227,7 @@ $m->callback( Conditions => \@lines );
</%INIT>
-<script type="text/javascript">
- jQuery(function() {
-
- // move the actual value to a hidden value, and shadow the others
- var hidden = jQuery('<input>').attr('type','hidden').attr('name','ValueOfQueue');
-
- // change the selector's name, but preserve the values, we'll set value via js
- var selector = jQuery("[name='ValueOfQueue']");
-
- // rename the selector so we don't get an extra term in the query
- selector[0].name = "";
- selector.bind('change',function() {
- hidden[0].value = selector[0].value;
- });
-
- // create a text input box and hide it for use with matches / doesn't match
- // NB: if you give text a name it will add an additional term to the query!
- var text = jQuery('<input>').attr('type','text');
- text.hide();
- text.bind('change',function() {
- hidden[0].value = text[0].value;
- });
-
- // hook the op field so that we can swap between the two input types
- var op = jQuery("[name='QueueOp']");
- op.bind('change',function() {
- if (op[0].value == "=" || op[0].value == "!=" ) {
- text.hide();
- selector.show();
- hidden[0].value = selector[0].value;
- } else {
- text.show();
- selector.hide();
- hidden[0].value = text[0].value;
- }
- });
-
- // add the fields to the DOM
- selector.before(hidden);
- selector.after(text);
- });
-</script>
+<script type="text/javascript" src="<%RT->Config->Get('WebPath')%>/static/js/search.js"></script>
<%ARGS>
%queues => ()
</%ARGS>
diff --git a/share/html/Ticket/Elements/ShowAssets b/share/html/Ticket/Elements/ShowAssets
index d289a2028..cae082452 100644
--- a/share/html/Ticket/Elements/ShowAssets
+++ b/share/html/Ticket/Elements/ShowAssets
@@ -151,13 +151,7 @@ if ($Ticket->CurrentUserHasRight("ModifyTicket")) {
% my $page = RT::Interface::Web::Menu->new();
% RT::Interface::Web::MenuBuilder::_BuildAssetMenuActionSubmenu( $request_path, Menu(), PageWidgets(), $page, Asset => $asset );
<& /Elements/Menu, menu => $page, id => 'asset-'.$asset->id.'-actions-menu', parent_id => 'asset-'.$asset->id &>
-<script>
-jQuery("#assets-accordion ul.toplevel").addClass('sf-menu sf-js-enabled sf-shadow').supersubs().superfish({ dropShadows: false, speed: 'fast', delay: 0 }).supposition()
- .find('a').click(function(ev){
- ev.stopPropagation();
- return true;
- });
-</script>
+<script src="<%RT->Config->Get('WebPath')%>/static/js/ticket.js"></script>
</h3>
<div class="details">
diff --git a/share/html/Ticket/Elements/UpdateCc b/share/html/Ticket/Elements/UpdateCc
index ed8b79caf..bee9b3825 100644
--- a/share/html/Ticket/Elements/UpdateCc
+++ b/share/html/Ticket/Elements/UpdateCc
@@ -106,18 +106,7 @@
%}
%if (@one_time_Ccs && $hide_cc_suggestions) {
</div>
-<script type="text/javascript">
-jQuery(function() {
- jQuery('a.ToggleSuggestions').click(function(e) {
- e.preventDefault();
- var toggleSuggestions = jQuery(this);
- var oneTimeCcs = toggleSuggestions.closest('td').find('.OneTimeCcs');
- oneTimeCcs.toggleClass('hidden');
- var hideOrShow = oneTimeCcs.hasClass('hidden') ? toggleSuggestions.data('showLabel') : toggleSuggestions.data('hideLabel');
- toggleSuggestions.find('i').html('(' + hideOrShow + ')');
- });
-});
-</script>
+<script type="text/javascript" src="<%RT->Config->Get('WebPath')%>/static/js/ticket.js"></script>
%}
</td></tr>
<%args>
diff --git a/share/static/js/admin.js b/share/static/js/admin.js
new file mode 100644
index 000000000..c2dac2d83
--- /dev/null
+++ b/share/static/js/admin.js
@@ -0,0 +1,7 @@
+var path = window.location.href;
+
+if ( path.match( /Admin\/Tools\/Queries\.html/ ) ) {
+ jQuery(function () {
+ jQuery(".tablesorter").tablesorter();
+ });
+}
diff --git a/share/static/js/assets.js b/share/static/js/assets.js
index 8d5aaa008..ff986c9bc 100644
--- a/share/static/js/assets.js
+++ b/share/static/js/assets.js
@@ -61,3 +61,26 @@ jQuery(function() {
);
});
});
+
+var path = window.location.href;
+
+if ( path.match( /Asset\/Search/ ) ) {
+ jQuery(function() {
+ var all_inputs = jQuery("#AssetSearch input, #AssetSearch select");
+ all_inputs.each(function() {
+ var elem = jQuery(this);
+ var update_elems = all_inputs.filter(function () {
+ return jQuery(this).attr("name") == elem.attr("name");
+ }).not(elem);
+ if (update_elems.length == 0) {
+ return;
+ }
+ var trigger_func = function() { update_elems.val(elem.val()) };
+ if (elem.attr("type") == "text") {
+ elem.keyup( trigger_func );
+ } else {
+ elem.change( trigger_func );
+ }
+ });
+ });
+}
diff --git a/share/static/js/search.js b/share/static/js/search.js
new file mode 100644
index 000000000..855e09df8
--- /dev/null
+++ b/share/static/js/search.js
@@ -0,0 +1,67 @@
+var path = window.location.href;
+
+if ( path.match( /Search\/Build\.html/ ) ) {
+ jQuery(function() {
+
+ // move the actual value to a hidden value, and shadow the others
+ var hidden = jQuery('<input>').attr('type','hidden').attr('name','ValueOfQueue');
+
+ // change the selector's name, but preserve the values, we'll set value via js
+ var selector = jQuery("[name='ValueOfQueue']");
+
+ // rename the selector so we don't get an extra term in the query
+ selector[0].name = "";
+ selector.bind('change',function() {
+ hidden[0].value = selector[0].value;
+ });
+
+ // create a text input box and hide it for use with matches / doesn't match
+ // NB: if you give text a name it will add an additional term to the query!
+ var text = jQuery('<input>').attr('type','text');
+ text.hide();
+ text.bind('change',function() {
+ hidden[0].value = text[0].value;
+ });
+
+ // hook the op field so that we can swap between the two input types
+ var op = jQuery("[name='QueueOp']");
+ op.bind('change',function() {
+ if (op[0].value == "=" || op[0].value == "!=" ) {
+ text.hide();
+ selector.show();
+ hidden[0].value = selector[0].value;
+ } else {
+ text.show();
+ selector.hide();
+ hidden[0].value = text[0].value;
+ }
+ });
+
+ // add the fields to the DOM
+ selector.before(hidden);
+ selector.after(text);
+ });
+}
+
+if ( path.match( /Search\/Chart\.html/ ) ) {
+ var updateChartStyle = function() {
+ var val = jQuery(".chart-picture [name=ChartType]").val();
+ if ( val != 'table' && jQuery(".chart-picture [name=ChartStyleIncludeTable]").is(':checked') ) {
+ val += '+table';
+ }
+ if ( jQuery(".chart-picture [name=ChartStyleIncludeSQL]").is(':checked') ) {
+ val += '+sql';
+ }
+ jQuery(".chart-picture [name=ChartStyle]").val(val);
+ };
+ jQuery(".chart-picture [name=ChartType]").change(function(){
+ var t = jQuery(this);
+ t.closest("form").find("[name=Height]").closest(".height").toggle( t.val() == 'bar' );
+ t.closest("form").find("[name=Width]").closest(".width").toggle( t.val() !== 'table' );
+ t.closest("form .chart-picture").find("div.include-table").toggle( t.val() !== 'table' );
+ updateChartStyle();
+ }).change();
+
+ jQuery(".chart-picture [name=ChartStyleIncludeTable]").change( updateChartStyle );
+ jQuery(".chart-picture [name=ChartStyleIncludeSQL]").change( updateChartStyle );
+}
diff --git a/share/static/js/ticket.js b/share/static/js/ticket.js
new file mode 100644
index 000000000..b232aa21e
--- /dev/null
+++ b/share/static/js/ticket.js
@@ -0,0 +1,22 @@
+var path = window.location.href;
+
+if ( path.match( /Ticket\/Update\.html/ ) ) {
+ jQuery(function() {
+ jQuery('a.ToggleSuggestions').click(function(e) {
+ e.preventDefault();
+ var toggleSuggestions = jQuery(this);
+ var oneTimeCcs = toggleSuggestions.closest('td').find('.OneTimeCcs');
+ oneTimeCcs.toggleClass('hidden');
+ var hideOrShow = oneTimeCcs.hasClass('hidden') ? toggleSuggestions.data('showLabel') : toggleSuggestions.data('hideLabel');
+ toggleSuggestions.find('i').html('(' + hideOrShow + ')');
+ });
+ });
+}
+
+if ( path.match( /SelfService\/Display\.html/ | /Asset\/Display\.html/ | /Ticket\/Display\.html/ | /Approvals\/Display\.html/ ) ) {
+ jQuery("#assets-accordion ul.toplevel").addClass('sf-menu sf-js-enabled sf-shadow').supersubs().superfish({ dropShadows: false, speed: 'fast', delay: 0 }).supposition()
+ .find('a').click(function(ev){
+ ev.stopPropagation();
+ return true;
+ });
+}
diff --git a/share/static/js/util.js b/share/static/js/util.js
index eda0127bf..6e7121518 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -591,3 +591,14 @@ function toggle_hide_unset(e) {
return false;
}
+
+var path = window.location.href;
+
+if ( path.match( /Prefs\/AboutMe\.html/ ) ) {
+ jQuery("#ResetAuthTokenContainer").hide();
+ jQuery("#ResetAuthTokenPrompt").show().click(function(ev){
+ jQuery(this).slideUp();
+ jQuery("#ResetAuthTokenContainer").slideDown();
+ ev.preventDefault();
+ });
+}
-----------------------------------------------------------------------
More information about the rt-commit
mailing list