Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
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
PSDI Army
yii2
Commits
b6cc8c00
Commit
b6cc8c00
authored
Nov 18, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #1149: Filter out already included javascript files requested via ajax.
parent
49da1b4a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
9 deletions
+47
-9
yii.js
framework/yii/assets/yii.js
+47
-9
No files found.
framework/yii/assets/yii.js
View file @
b6cc8c00
...
@@ -44,6 +44,11 @@
...
@@ -44,6 +44,11 @@
yii
=
(
function
(
$
)
{
yii
=
(
function
(
$
)
{
var
pub
=
{
var
pub
=
{
/**
/**
* List of scripts that can be loaded multiple times via AJAX requests. Each script can be represented
* as either an absolute URL or a relative one.
*/
reloadableScripts
:
[],
/**
* The selector for clickable elements that need to support confirmation and form submission.
* The selector for clickable elements that need to support confirmation and form submission.
*/
*/
clickableSelector
:
'a, button, input[type="submit"], input[type="button"], input[type="reset"], input[type="image"]'
,
clickableSelector
:
'a, button, input[type="submit"], input[type="button"], input[type="reset"], input[type="image"]'
,
...
@@ -161,23 +166,34 @@ yii = (function ($) {
...
@@ -161,23 +166,34 @@ yii = (function ($) {
},
},
init
:
function
()
{
init
:
function
()
{
var
$document
=
$
(
document
);
initCsrfHandler
();
initRedirectHandler
();
// automatically send CSRF token for all AJAX requests
initScriptFilter
();
$
.
ajaxPrefilter
(
function
(
options
,
originalOptions
,
xhr
)
{
initDataMethods
();
if
(
!
options
.
crossDomain
&&
pub
.
getCsrfVar
())
{
xhr
.
setRequestHeader
(
'X-CSRF-Token'
,
pub
.
getCsrfToken
());
}
}
})
;
}
;
function
initRedirectHandler
()
{
// handle AJAX redirection
// handle AJAX redirection
$document
.
ajaxComplete
(
function
(
event
,
xhr
,
settings
)
{
$
(
document
)
.
ajaxComplete
(
function
(
event
,
xhr
,
settings
)
{
var
url
=
xhr
.
getResponseHeader
(
'X-Redirect'
);
var
url
=
xhr
.
getResponseHeader
(
'X-Redirect'
);
if
(
url
)
{
if
(
url
)
{
window
.
location
=
url
;
window
.
location
=
url
;
}
}
});
});
}
function
initCsrfHandler
()
{
// automatically send CSRF token for all AJAX requests
$
.
ajaxPrefilter
(
function
(
options
,
originalOptions
,
xhr
)
{
if
(
!
options
.
crossDomain
&&
pub
.
getCsrfVar
())
{
xhr
.
setRequestHeader
(
'X-CSRF-Token'
,
pub
.
getCsrfToken
());
}
});
}
function
initDataMethods
()
{
var
$document
=
$
(
document
);
// handle data-confirm and data-method for clickable elements
// handle data-confirm and data-method for clickable elements
$document
.
on
(
'click.yii'
,
pub
.
clickableSelector
,
function
(
event
)
{
$document
.
on
(
'click.yii'
,
pub
.
clickableSelector
,
function
(
event
)
{
var
$this
=
$
(
this
);
var
$this
=
$
(
this
);
...
@@ -200,7 +216,29 @@ yii = (function ($) {
...
@@ -200,7 +216,29 @@ yii = (function ($) {
}
}
});
});
}
}
};
function
initScriptFilter
()
{
var
hostInfo
=
location
.
protocol
+
'//'
+
location
.
host
;
var
loadedScripts
=
$
(
'script'
).
filter
(
function
()
{
return
this
.
src
;
}).
map
(
function
()
{
return
this
.
src
.
charAt
(
0
)
===
'/'
?
hostInfo
+
this
.
src
:
this
.
src
;
}).
toArray
();
$
.
ajaxPrefilter
(
'script'
,
function
(
options
,
originalOptions
,
xhr
)
{
var
url
=
options
.
url
.
charAt
(
0
)
===
'/'
?
hostInfo
+
options
.
url
:
options
.
url
;
if
(
loadedScripts
.
indexOf
(
url
)
<
0
)
{
loadedScripts
.
push
(
url
);
}
else
{
var
found
=
pub
.
reloadableScripts
.
map
(
function
()
{
return
this
.
charAt
(
0
)
===
'/'
?
hostInfo
+
this
:
this
;
}).
indexOf
(
url
)
>=
0
;
if
(
!
found
)
{
xhr
.
abort
();
}
}
});
}
return
pub
;
return
pub
;
})(
jQuery
);
})(
jQuery
);
...
...
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