mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
Merge remote-tracking branch 'upstream/master' into enh-link-submission-form-attribute-9893
This commit is contained in:
@ -16,7 +16,7 @@
|
||||
*
|
||||
* A module may be structured as follows:
|
||||
*
|
||||
* ~~~
|
||||
* ```javascript
|
||||
* yii.sample = (function($) {
|
||||
* var pub = {
|
||||
* // whether this module is currently active. If false, init() will not be called for this module
|
||||
@ -33,7 +33,7 @@
|
||||
*
|
||||
* return pub;
|
||||
* })(jQuery);
|
||||
* ~~~
|
||||
* ```
|
||||
*
|
||||
* Using this structure, you can define public and private functions/properties for a module.
|
||||
* Private functions/properties are only visible within the module, while public functions/properties
|
||||
@ -153,6 +153,9 @@ yii = (function ($) {
|
||||
pjaxReplaceState = !!$e.data('pjax-replace-state'),
|
||||
pjaxTimeout = $e.data('pjax-timeout'),
|
||||
pjaxScrollTo = $e.data('pjax-scrollto'),
|
||||
pjaxPushRedirect = $e.data('pjax-push-redirect'),
|
||||
pjaxReplaceRedirect = $e.data('pjax-replace-redirect'),
|
||||
pjaxSkipOuterContainers = $e.data('pjax-skip-outer-containers'),
|
||||
pjaxContainer,
|
||||
pjaxOptions = {};
|
||||
|
||||
@ -171,7 +174,12 @@ yii = (function ($) {
|
||||
push: pjaxPushState,
|
||||
replace: pjaxReplaceState,
|
||||
scrollTo: pjaxScrollTo,
|
||||
timeout: pjaxTimeout
|
||||
pushRedirect: pjaxPushRedirect,
|
||||
replaceRedirect: pjaxReplaceRedirect,
|
||||
pjaxSkipOuterContainers: pjaxSkipOuterContainers,
|
||||
timeout: pjaxTimeout,
|
||||
originalEvent: event,
|
||||
originalTarget: $e
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,20 +206,19 @@ yii = (function ($) {
|
||||
if (!action || !action.match(/(^\/|:\/\/)/)) {
|
||||
action = window.location.href;
|
||||
}
|
||||
$form = $('<form method="' + method + '"></form>');
|
||||
$form.attr('action', action);
|
||||
$form = $('<form/>', {method: method, action: action});
|
||||
var target = $e.attr('target');
|
||||
if (target) {
|
||||
$form.attr('target', target);
|
||||
}
|
||||
if (!method.match(/(get|post)/i)) {
|
||||
$form.append('<input name="_method" value="' + method + '" type="hidden">');
|
||||
$form.append($('<input/>', {name: '_method', value: method, type: 'hidden'}));
|
||||
method = 'POST';
|
||||
}
|
||||
if (!method.match(/(get|head|options)/i)) {
|
||||
var csrfParam = pub.getCsrfParam();
|
||||
if (csrfParam) {
|
||||
$form.append('<input name="' + csrfParam + '" value="' + pub.getCsrfToken() + '" type="hidden">');
|
||||
$form.append($('<input/>', {name: csrfParam, value: pub.getCsrfToken(), type: 'hidden'}));
|
||||
}
|
||||
}
|
||||
$form.hide().appendTo('body');
|
||||
@ -226,7 +233,7 @@ yii = (function ($) {
|
||||
// temporarily add hidden inputs according to data-params
|
||||
if (params && $.isPlainObject(params)) {
|
||||
$.each(params, function (idx, obj) {
|
||||
$form.append($('<input>').attr({name: idx, value: obj, type: 'hidden'}));
|
||||
$form.append($('<input/>').attr({name: idx, value: obj, type: 'hidden'}));
|
||||
});
|
||||
}
|
||||
|
||||
@ -269,12 +276,28 @@ yii = (function ($) {
|
||||
if (pos < 0) {
|
||||
return {};
|
||||
}
|
||||
var qs = url.substring(pos + 1).split('&');
|
||||
for (var i = 0, result = {}; i < qs.length; i++) {
|
||||
qs[i] = qs[i].split('=');
|
||||
result[decodeURIComponent(qs[i][0])] = decodeURIComponent(qs[i][1]);
|
||||
|
||||
var pairs = url.substring(pos + 1).split('&'),
|
||||
params = {},
|
||||
pair,
|
||||
i;
|
||||
|
||||
for (i = 0; i < pairs.length; i++) {
|
||||
pair = pairs[i].split('=');
|
||||
var name = decodeURIComponent(pair[0]);
|
||||
var value = decodeURIComponent(pair[1]);
|
||||
if (name.length) {
|
||||
if (params[name] !== undefined) {
|
||||
if (!$.isArray(params[name])) {
|
||||
params[name] = [params[name]];
|
||||
}
|
||||
params[name].push(value || '');
|
||||
} else {
|
||||
params[name] = value || '';
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return params;
|
||||
},
|
||||
|
||||
initModule: function (module) {
|
||||
@ -330,7 +353,7 @@ yii = (function ($) {
|
||||
}
|
||||
|
||||
if (message !== undefined) {
|
||||
pub.confirm(message, function () {
|
||||
$.proxy(pub.confirm, this)(message, function () {
|
||||
pub.handleAction($this, event);
|
||||
});
|
||||
} else {
|
||||
@ -347,6 +370,7 @@ yii = (function ($) {
|
||||
|
||||
function initScriptFilter() {
|
||||
var hostInfo = location.protocol + '//' + location.host;
|
||||
|
||||
var loadedScripts = $('script[src]').map(function () {
|
||||
return this.src.charAt(0) === '/' ? hostInfo + this.src : this.src;
|
||||
}).toArray();
|
||||
@ -355,14 +379,15 @@ yii = (function ($) {
|
||||
if (options.dataType == 'jsonp') {
|
||||
return;
|
||||
}
|
||||
|
||||
var url = options.url.charAt(0) === '/' ? hostInfo + options.url : options.url;
|
||||
if ($.inArray(url, loadedScripts) === -1) {
|
||||
loadedScripts.push(url);
|
||||
} else {
|
||||
var found = $.inArray(url, $.map(pub.reloadableScripts, function (script) {
|
||||
return script.charAt(0) === '/' ? hostInfo + script : script;
|
||||
})) !== -1;
|
||||
if (!found) {
|
||||
var isReloadable = $.inArray(url, $.map(pub.reloadableScripts, function (script) {
|
||||
return script.charAt(0) === '/' ? hostInfo + script : script;
|
||||
})) !== -1;
|
||||
if (!isReloadable) {
|
||||
xhr.abort();
|
||||
}
|
||||
}
|
||||
@ -389,3 +414,4 @@ yii = (function ($) {
|
||||
jQuery(document).ready(function () {
|
||||
yii.initModule(yii);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user