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
a52aa5ca
Commit
a52aa5ca
authored
Oct 28, 2015
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix JS display rules when called twice
parent
0d976995
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
23 deletions
+26
-23
qa-page.js
qa-content/qa-page.js
+13
-0
format.php
qa-include/app/format.php
+13
-23
No files found.
qa-content/qa-page.js
View file @
a52aa5ca
...
...
@@ -175,3 +175,16 @@ function qa_ajax_error()
{
alert
(
'Unexpected response from server - please try again or switch off Javascript.'
);
}
function
qa_display_rule_show
(
target
,
show
,
first
)
{
var
e
=
document
.
getElementById
(
target
);
if
(
e
)
{
if
(
first
||
e
.
nodeName
==
'SPAN'
)
e
.
style
.
display
=
(
show
?
''
:
'none'
);
else
if
(
show
)
$
(
e
).
fadeIn
();
else
$
(
e
).
fadeOut
();
}
}
qa-include/app/format.php
View file @
a52aa5ca
...
...
@@ -1484,8 +1484,8 @@
$keysourceids
=
array
();
$jsVarRegex
=
'/[A-Za-z_][A-Za-z0-9_]*/'
;
// extract all JS variable names in all sources
foreach
(
$effects
as
$target
=>
$sources
)
{
// element names must be legal JS variable names
if
(
preg_match_all
(
$jsVarRegex
,
$sources
,
$matches
))
{
foreach
(
$matches
[
0
]
as
$element
)
{
if
(
!
in_array
(
$element
,
$keysourceids
))
...
...
@@ -1494,40 +1494,30 @@
}
}
$function
=
'qa_display_rule_'
.
count
(
@
$qa_content
[
'script_lines'
]);
$funcOrd
=
isset
(
$qa_content
[
'script_lines'
])
?
count
(
$qa_content
[
'script_lines'
])
:
0
;
$function
=
"qa_display_rule_
$funcOrd
"
;
$optVar
=
"qa_optids_
$funcOrd
"
;
$funcscript
=
array
(
// set up variables
"var qa_checkboxids = "
.
json_encode
(
$keysourceids
)
.
";"
,
// show/hide an element
"function
{
$function
}
_show(target, show, first) {"
,
"
\t
var e = document.getElementById(target);"
,
"
\t
if (e) {"
,
"
\t\t
if (first || e.nodeName == 'SPAN') { e.style.display = (show ? '' : 'none'); }"
,
"
\t\t
else if (show) { $(e).fadeIn(); }"
,
"
\t\t
else { $(e).fadeOut(); }"
,
"
\t
}"
,
"}"
,
);
$funcscript
=
array
(
"var
$optVar
= "
.
json_encode
(
$keysourceids
)
.
";"
);
// check and set all display rules
$funcscript
[]
=
"function
{
$function
}
(first) {"
;
$funcscript
[]
=
"
\t
var
qa_option
s = {};"
;
$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
var
opt
s = {};"
;
$funcscript
[]
=
"
\t
for (var i = 0; i <
{
$optVar
}
.length; i++) {"
;
$funcscript
[]
=
"
\t\t
var e = document.getElementById(
{
$optVar
}
[i]);"
;
$funcscript
[]
=
"
\t\t
opts[
{
$optVar
}
[i]] = e && (e.checked || (e.options && e.options[e.selectedIndex].value));"
;
$funcscript
[]
=
"
\t
}"
;
foreach
(
$effects
as
$target
=>
$sources
)
{
$sourcesobj
=
preg_replace
(
$jsVarRegex
,
'
qa_option
s.$0'
,
$sources
);
$funcscript
[]
=
"
\t
"
.
$function
.
"
_show("
.
qa_js
(
$target
)
.
", ("
.
$sourcesobj
.
"), first);"
;
$sourcesobj
=
preg_replace
(
$jsVarRegex
,
'
opt
s.$0'
,
$sources
);
$funcscript
[]
=
"
\t
qa_display_rule
_show("
.
qa_js
(
$target
)
.
", ("
.
$sourcesobj
.
"), first);"
;
}
$funcscript
[]
=
"}"
;
// set default state of options
$loadscript
=
array
(
"for (var i = 0; i <
qa_checkboxids
.length; i++) {"
,
"
\t
jQuery('#'+
qa_checkboxids
[i]).click(function() { "
.
$function
.
"(false); });"
,
"for (var i = 0; i <
{
$optVar
}
.length; i++) {"
,
"
\t
jQuery('#'+
{
$optVar
}
[i]).click(function() { "
.
$function
.
"(false); });"
,
"}"
,
"
{
$function
}
(true);"
,
);
...
...
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