Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
315
Merge Requests
315
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
e599787b
Commit
e599787b
authored
Aug 26, 2012
by
webchick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1685140
by frega, seutje, ethanw, nod_: Refactor collapse.js.
parent
aa9cb31b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
132 additions
and
85 deletions
+132
-85
core/misc/collapse.js
core/misc/collapse.js
+132
-85
No files found.
core/misc/collapse.js
View file @
e599787b
(
function
(
$
)
{
(
function
(
$
,
Drupal
)
{
"
use strict
"
;
/**
* T
oggle the visibility of a fieldset using smooth animations
.
* T
he collapsible fieldset object represents a single collapsible fieldset
.
*/
Drupal
.
toggleFieldset
=
function
(
fieldset
)
{
var
$fieldset
=
$
(
fieldset
);
if
(
$fieldset
.
is
(
'
.collapsed
'
))
{
var
$content
=
$fieldset
.
find
(
'
> .fieldset-wrapper
'
).
hide
();
$fieldset
.
removeClass
(
'
collapsed
'
)
.
trigger
({
type
:
'
collapsed
'
,
value
:
false
})
.
find
(
'
> legend span.fieldset-legend-prefix
'
).
html
(
Drupal
.
t
(
'
Hide
'
));
$content
.
slideDown
({
duration
:
'
fast
'
,
easing
:
'
linear
'
,
complete
:
function
()
{
Drupal
.
collapseScrollIntoView
(
fieldset
);
fieldset
.
animating
=
false
;
},
step
:
function
()
{
// Scroll the fieldset into view.
Drupal
.
collapseScrollIntoView
(
fieldset
);
}
});
}
else
{
$fieldset
.
trigger
({
type
:
'
collapsed
'
,
value
:
true
});
$fieldset
.
find
(
'
> .fieldset-wrapper
'
).
slideUp
(
'
fast
'
,
function
()
{
$fieldset
.
addClass
(
'
collapsed
'
)
.
find
(
'
> legend span.fieldset-legend-prefix
'
).
html
(
Drupal
.
t
(
'
Show
'
));
fieldset
.
animating
=
false
;
});
function
CollapsibleFieldset
(
node
,
settings
)
{
this
.
$node
=
$
(
node
);
this
.
$node
.
data
(
'
fieldset
'
,
this
);
this
.
settings
=
$
.
extend
({
duration
:
'
fast
'
,
easing
:
'
linear
'
},
settings
);
// Expand fieldset if there are errors inside, or if it contains an
// element that is targeted by the uri fragment identifier.
var
anchor
=
location
.
hash
&&
location
.
hash
!==
'
#
'
?
'
,
'
+
location
.
hash
:
''
;
if
(
this
.
$node
.
find
(
'
.error
'
+
anchor
).
length
)
{
this
.
$node
.
removeClass
(
'
collapsed
'
);
}
};
// Initialize and setup the summary,
this
.
setupSummary
();
// Initialize and setup the legend.
this
.
setupLegend
();
}
/**
* Extend CollapsibleFieldset function.
*/
$
.
extend
(
CollapsibleFieldset
,
{
/**
* Holds references to instantiated CollapsibleFieldset objects.
*/
fieldsets
:
[]
});
/**
*
Scroll a given fieldset into view as much as possibl
e.
*
Extend CollapsibleFieldset prototyp
e.
*/
Drupal
.
collapseScrollIntoView
=
function
(
node
)
{
var
h
=
document
.
documentElement
.
clientHeight
||
document
.
body
.
clientHeight
||
0
;
var
offset
=
document
.
documentElement
.
scrollTop
||
document
.
body
.
scrollTop
||
0
;
var
posY
=
$
(
node
).
offset
().
top
;
var
fudge
=
55
;
if
(
posY
+
node
.
offsetHeight
+
fudge
>
h
+
offset
)
{
if
(
node
.
offsetHeight
>
h
)
{
window
.
scrollTo
(
0
,
posY
);
$
.
extend
(
CollapsibleFieldset
.
prototype
,
{
/**
* Flag preventing multiple simultaneous animations.
*/
animating
:
false
,
/**
* Initialize and setup summary events and markup.
*/
setupSummary
:
function
()
{
this
.
$summary
=
$
(
'
<span class="summary"></span>
'
);
this
.
$node
.
bind
(
'
summaryUpdated
'
,
$
.
proxy
(
this
.
onSummaryUpdated
,
this
))
.
trigger
(
'
summaryUpdated
'
);
},
/**
* Initialize and setup legend markup.
*/
setupLegend
:
function
()
{
// Turn the legend into a clickable link, but retain span.fieldset-legend
// for CSS positioning.
var
$legend
=
this
.
$node
.
find
(
'
> legend .fieldset-legend
'
);
$
(
'
<span class="fieldset-legend-prefix element-invisible"></span>
'
)
.
append
(
this
.
$node
.
hasClass
(
'
collapsed
'
)
?
Drupal
.
t
(
'
Show
'
)
:
Drupal
.
t
(
'
Hide
'
))
.
prependTo
(
$legend
)
.
after
(
'
'
);
// .wrapInner() does not retain bound events.
var
$link
=
$
(
'
<a class="fieldset-title" href="#"></a>
'
)
.
prepend
(
$legend
.
contents
())
.
appendTo
(
$legend
)
.
click
(
$
.
proxy
(
this
.
onLegendClick
,
this
));
$legend
.
append
(
this
.
$summary
);
},
/**
* Handle legend clicks
*/
onLegendClick
:
function
(
e
)
{
e
.
preventDefault
();
this
.
toggle
();
},
/**
* Update summary
*/
onSummaryUpdated
:
function
()
{
var
text
=
$
.
trim
(
this
.
$node
.
drupalGetSummary
());
this
.
$summary
.
html
(
text
?
'
(
'
+
text
+
'
)
'
:
''
);
},
/**
* Toggle the visibility of a fieldset using smooth animations.
*/
toggle
:
function
()
{
// Don't animate multiple times.
if
(
this
.
animating
)
{
return
;
}
if
(
this
.
$node
.
is
(
'
.collapsed
'
))
{
var
$content
=
this
.
$node
.
find
(
'
> .fieldset-wrapper
'
).
hide
();
this
.
$node
.
removeClass
(
'
collapsed
'
)
.
trigger
({
type
:
'
collapsed
'
,
value
:
false
})
.
find
(
'
> legend span.fieldset-legend-prefix
'
).
html
(
Drupal
.
t
(
'
Hide
'
));
$content
.
slideDown
(
$
.
extend
(
this
.
settings
,
{
complete
:
$
.
proxy
(
this
.
onCompleteSlideDown
,
this
)
})
);
}
else
{
window
.
scrollTo
(
0
,
posY
+
node
.
offsetHeight
-
h
+
fudge
);
this
.
$node
.
trigger
({
type
:
'
collapsed
'
,
value
:
true
});
this
.
$node
.
find
(
'
> .fieldset-wrapper
'
).
slideUp
(
$
.
extend
(
this
.
settings
,
{
complete
:
$
.
proxy
(
this
.
onCompleteSlideUp
,
this
)
})
);
}
},
/**
* Completed opening fieldset.
*/
onCompleteSlideDown
:
function
()
{
this
.
$node
.
trigger
(
'
completeSlideDown
'
);
this
.
animating
=
false
;
},
/**
* Completed closing fieldset.
*/
onCompleteSlideUp
:
function
()
{
this
.
$node
.
addClass
(
'
collapsed
'
)
.
find
(
'
> legend span.fieldset-legend-prefix
'
).
html
(
Drupal
.
t
(
'
Show
'
));
this
.
$node
.
trigger
(
'
completeSlideUp
'
);
this
.
animating
=
false
;
}
};
}
)
;
Drupal
.
behaviors
.
collapse
=
{
attach
:
function
(
context
,
settings
)
{
$
(
context
).
find
(
'
fieldset.collapsible
'
).
once
(
'
collapse
'
,
function
()
{
var
$fieldset
=
$
(
this
);
// Expand fieldset if there are errors inside, or if it contains an
// element that is targeted by the uri fragment identifier.
var
anchor
=
location
.
hash
&&
location
.
hash
!==
'
#
'
?
'
,
'
+
location
.
hash
:
''
;
if
(
$fieldset
.
find
(
'
.error
'
+
anchor
).
length
)
{
$fieldset
.
removeClass
(
'
collapsed
'
);
var
$collapsibleFieldsets
=
$
(
context
).
find
(
'
fieldset.collapsible
'
).
once
(
'
collapse
'
);
if
(
$collapsibleFieldsets
.
length
)
{
for
(
var
i
=
0
;
i
<
$collapsibleFieldsets
.
length
;
i
++
)
{
CollapsibleFieldset
.
fieldsets
.
push
(
new
CollapsibleFieldset
(
$collapsibleFieldsets
[
i
],
settings
.
collapsibleFieldset
));
}
var
summary
=
$
(
'
<span class="summary"></span>
'
);
$fieldset
.
bind
(
'
summaryUpdated
'
,
function
()
{
var
text
=
$
.
trim
(
$fieldset
.
drupalGetSummary
());
summary
.
html
(
text
?
'
(
'
+
text
+
'
)
'
:
''
);
})
.
trigger
(
'
summaryUpdated
'
);
// Turn the legend into a clickable link, but retain span.fieldset-legend
// for CSS positioning.
var
$legend
=
$fieldset
.
find
(
'
> legend .fieldset-legend
'
);
$
(
'
<span class="fieldset-legend-prefix element-invisible"></span>
'
)
.
append
(
$fieldset
.
hasClass
(
'
collapsed
'
)
?
Drupal
.
t
(
'
Show
'
)
:
Drupal
.
t
(
'
Hide
'
))
.
prependTo
(
$legend
)
.
after
(
'
'
);
// .wrapInner() does not retain bound events.
var
$link
=
$
(
'
<a class="fieldset-title" href="#"></a>
'
)
.
prepend
(
$legend
.
contents
())
.
appendTo
(
$legend
)
.
click
(
function
(
e
)
{
e
.
preventDefault
();
var
fieldset
=
$fieldset
.
get
(
0
);
// Don't animate multiple times.
if
(
!
fieldset
.
animating
)
{
fieldset
.
animating
=
true
;
Drupal
.
toggleFieldset
(
fieldset
);
}
});
$legend
.
append
(
summary
);
});
}
}
};
})(
jQuery
);
// Expose constructor in the public space.
Drupal
.
CollapsibleFieldset
=
CollapsibleFieldset
;
})(
jQuery
,
Drupal
);
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