Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
abd09370
Commit
abd09370
authored
Oct 28, 2015
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up JavaScript for display rules
Remove code duplication. Close #273.
parent
faa1fb1c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
20 deletions
+40
-20
format.php
qa-include/app/format.php
+40
-20
No files found.
qa-include/app/format.php
View file @
abd09370
...
...
@@ -1479,35 +1479,55 @@
{
$function
=
'qa_display_rule_'
.
count
(
@
$qa_content
[
'script_lines'
]);
$keysourceids
=
array
();
$keysourceids
=
array
();
$keysourceobjs
=
array
();
$jsVar
=
'/[A-Za-z_][A-Za-z0-9_]*/'
;
foreach
(
$effects
as
$target
=>
$sources
)
if
(
preg_match_all
(
'/[A-Za-z_][A-Za-z0-9_]*/'
,
$sources
,
$matches
))
// element names must be legal JS variable names
foreach
(
$matches
[
0
]
as
$element
)
$keysourceids
[
$element
]
=
true
;
foreach
(
$effects
as
$target
=>
$sources
)
{
if
(
preg_match_all
(
$jsVar
,
$sources
,
$matches
))
{
// element names must be legal JS variable names
foreach
(
$matches
[
0
]
as
$element
)
{
if
(
!
in_array
(
$element
,
$keysourceids
))
$keysourceids
[]
=
$element
;
}
}
}
$funcscript
=
array
(
"function "
.
$function
.
"(first) {"
);
// build the Javascripts
$loadscript
=
array
();
$funcscript
=
array
();
$loadscript
=
array
();
foreach
(
$keysourceids
as
$key
=>
$dummy
)
{
$funcscript
[]
=
"
\t
var e=document.getElementById("
.
qa_js
(
$key
)
.
");"
;
$funcscript
[]
=
"
\t
var "
.
$key
.
"=e && (e.checked || (e.options && e.options[e.selectedIndex].value));"
;
$funcscript
[]
=
"var qa_checkboxids = "
.
json_encode
(
$keysourceids
)
.
";"
;
$funcscript
[]
=
"var qa_options = {};"
;
$loadscript
[]
=
"jQuery("
.
qa_js
(
'#'
.
$key
)
.
").click(function() {"
;
$loadscript
[]
=
"
\t
"
.
$function
.
"(false);"
;
$loadscript
[]
=
"});"
;
}
// set default state of options
$loadscript
[]
=
"for (var i = 0; i < qa_checkboxids.length; i++) {"
;
$loadscript
[]
=
"
\t
jQuery('#'+qa_checkboxids[i]).click(function() { "
.
$function
.
"(false); });"
;
$loadscript
[]
=
"}"
;
$funcscript
[]
=
"function
{
$function
}
_show(target, show, first) {"
;
$funcscript
[]
=
"
\t
var e = document.getElementById(target);"
;
$funcscript
[]
=
"
\t
if (e) {"
;
$funcscript
[]
=
"
\t\t
if (first || e.nodeName == 'SPAN') { e.style.display = (show ? '' : 'none'); }"
;
$funcscript
[]
=
"
\t\t
else if (show) { $(e).fadeIn(); }"
;
$funcscript
[]
=
"
\t\t
else { $(e).fadeOut(); }"
;
$funcscript
[]
=
"
\t
}"
;
$funcscript
[]
=
"}"
;
$funcscript
[]
=
"function
{
$function
}
(first) {"
;
$funcscript
[]
=
"
\t
for (var i = 0; i < qa_checkboxids.length; i++) {"
;
$funcscript
[]
=
"
\t\t
var e = document.getElementById(qa_checkboxids[i]);"
;
$funcscript
[]
=
"
\t\t
qa_options[qa_checkboxids[i]] = e && (e.checked || (e.options && e.options[e.selectedIndex].value));"
;
$funcscript
[]
=
"
\t
}"
;
foreach
(
$effects
as
$target
=>
$sources
)
{
$
funcscript
[]
=
"
\t
var e=document.getElementById("
.
qa_js
(
$target
)
.
");"
;
$funcscript
[]
=
"
\t
if (e) { var d=("
.
$sources
.
"); if (first || (e.nodeName=='SPAN')) { e.style.display=d ? '' : 'none'; } else { if (d) { $(e).fadeIn(); } else { $(e).fadeOut(); } } }
"
;
$
sourcesobj
=
preg_replace
(
$jsVar
,
'qa_options.$0'
,
$sources
)
;
$funcscript
[]
=
"
\t
"
.
$function
.
"_show("
.
qa_js
(
$target
)
.
", ("
.
$sourcesobj
.
"), first);
"
;
}
$funcscript
[]
=
"}"
;
$loadscript
[]
=
$function
.
"
(true);"
;
$funcscript
[]
=
"}"
;
$loadscript
[]
=
"
{
$function
}
(true);"
;
$qa_content
[
'script_lines'
][]
=
$funcscript
;
$qa_content
[
'script_onloads'
][]
=
$loadscript
;
$qa_content
[
'script_lines'
][]
=
$funcscript
;
$qa_content
[
'script_onloads'
][]
=
$loadscript
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment