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
74b5b36c
Commit
74b5b36c
authored
May 25, 2013
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1889394
by droplet, nod_: Choose one JS debounce function.
parent
7002e6ba
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
33 deletions
+18
-33
core/misc/debounce.js
core/misc/debounce.js
+12
-4
core/misc/matchmedia.js
core/misc/matchmedia.js
+3
-29
core/modules/system/system.module
core/modules/system/system.module
+3
-0
No files found.
core/misc/debounce.js
View file @
74b5b36c
/**
* Limits the invocations of a function in a given time frame.
*
* Adapted from underscore.js with the addition Drupal namespace.
*
* The debounce function wrapper should be used sparingly. One clear use case
* is limiting the invocation of a callback attached to the window resize event.
*
...
...
@@ -17,7 +19,7 @@
* invoked once. For example if the wait period is 250ms, then the callback
* will only be called at most 4 times per second.
*/
Drupal
.
debounce
=
function
(
callback
,
wait
)
{
Drupal
.
debounce
=
function
(
func
,
wait
,
immediate
)
{
"
use strict
"
;
...
...
@@ -27,10 +29,16 @@ Drupal.debounce = function (callback, wait) {
var
args
=
arguments
;
var
later
=
function
()
{
timeout
=
null
;
result
=
callback
.
apply
(
context
,
args
);
if
(
!
immediate
)
{
result
=
func
.
apply
(
context
,
args
);
}
};
window
.
clearTimeout
(
timeout
);
timeout
=
window
.
setTimeout
(
later
,
wait
);
var
callNow
=
immediate
&&
!
timeout
;
clearTimeout
(
timeout
);
timeout
=
setTimeout
(
later
,
wait
);
if
(
callNow
)
{
result
=
func
.
apply
(
context
,
args
);
}
return
result
;
};
};
core/misc/matchmedia.js
View file @
74b5b36c
...
...
@@ -12,7 +12,7 @@
* This polyfill triggers tests on window resize and orientationchange.
*/
window
.
matchMedia
=
window
.
matchMedia
||
(
function
(
doc
,
window
)
{
window
.
matchMedia
=
window
.
matchMedia
||
(
function
(
doc
,
window
,
Drupal
)
{
"
use strict
"
;
...
...
@@ -79,7 +79,7 @@ window.matchMedia = window.matchMedia || (function (doc, window) {
debounced
.
call
(
mql
,
mql
);
}
};
}(
this
,
debounce
(
callback
,
250
)));
}(
this
,
Drupal
.
debounce
(
callback
,
250
)));
this
.
listeners
.
push
({
'
callback
'
:
callback
,
'
handler
'
:
handler
...
...
@@ -120,32 +120,6 @@ window.matchMedia = window.matchMedia || (function (doc, window) {
}
};
/**
* Limits the invocations of a function in a given time frame.
*
* @param {Function} callback
* The function to be invoked.
*
* @param {Number} wait
* The time period within which the callback function should only be
* invoked once. For example if the wait period is 250ms, then the callback
* will only be called at most 4 times per second.
*/
function
debounce
(
callback
,
wait
)
{
var
timeout
,
result
;
return
function
()
{
var
context
=
this
;
var
args
=
arguments
;
var
later
=
function
()
{
timeout
=
null
;
result
=
callback
.
apply
(
context
,
args
);
};
window
.
clearTimeout
(
timeout
);
timeout
=
window
.
setTimeout
(
later
,
wait
);
return
result
;
};
}
/**
* Return a MediaQueryList.
*
...
...
@@ -157,4 +131,4 @@ window.matchMedia = window.matchMedia || (function (doc, window) {
// Build a new MediaQueryList object with the result of the check.
return
new
MediaQueryList
(
q
);
};
}(
document
,
window
));
}(
document
,
window
,
Drupal
));
core/modules/system/system.module
View file @
74b5b36c
...
...
@@ -1538,6 +1538,9 @@ function system_library_info() {
'js'
=>
array
(
'core/misc/matchmedia.js'
=>
array
(),
),
'dependencies'
=>
array
(
array
(
'system'
,
'drupal.debounce'
),
),
);
// Farbtastic.
...
...
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