Merge pull request #24081 from owncloud/migrate-deprecated-jquery-v1-functions

migrate deprecated jQuery 1.x functions
This commit is contained in:
Thomas Müller 2016-04-20 20:38:38 +02:00
commit 1ab27ddd4a
16 changed files with 30 additions and 238 deletions

View File

@ -137,7 +137,6 @@ class ViewController extends Controller {
\OCP\Util::addscript('files', 'app'); \OCP\Util::addscript('files', 'app');
\OCP\Util::addscript('files', 'file-upload'); \OCP\Util::addscript('files', 'file-upload');
\OCP\Util::addscript('files', 'newfilemenu'); \OCP\Util::addscript('files', 'newfilemenu');
\OCP\Util::addscript('files', 'jquery.iframe-transport');
\OCP\Util::addscript('files', 'jquery.fileupload'); \OCP\Util::addscript('files', 'jquery.fileupload');
\OCP\Util::addscript('files', 'jquery-visibility'); \OCP\Util::addscript('files', 'jquery-visibility');
\OCP\Util::addscript('files', 'fileinfomodel'); \OCP\Util::addscript('files', 'fileinfomodel');

View File

@ -504,7 +504,7 @@ OC.Upload = {
//fetch response from iframe //fetch response from iframe
response = data.result[0].body.innerText; response = data.result[0].body.innerText;
} }
var result = $.parseJSON(response); var result = JSON.parse(response);
delete data.jqXHR; delete data.jqXHR;

View File

@ -2593,7 +2593,7 @@
// fetch response from iframe // fetch response from iframe
response = data.result[0].body.innerText; response = data.result[0].body.innerText;
} }
var result=$.parseJSON(response); var result = JSON.parse(response);
if (typeof result[0] !== 'undefined' && result[0].status === 'success') { if (typeof result[0] !== 'undefined' && result[0].status === 'success') {
var file = result[0]; var file = result[0];
@ -2906,7 +2906,7 @@ $(document).ready(function() {
OCA.Files.FileList.lastAction(); OCA.Files.FileList.lastAction();
} }
}); });
$(window).unload(function () { $(window).on('unload', function () {
$(window).trigger('beforeunload'); $(window).trigger('beforeunload');
}); });

View File

@ -1,205 +0,0 @@
/*
* jQuery Iframe Transport Plugin 1.7
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
/*jslint unparam: true, nomen: true */
/*global define, window, document */
(function (factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// Register as an anonymous AMD module:
define(['jquery'], factory);
} else {
// Browser globals:
factory(window.jQuery);
}
}(function ($) {
'use strict';
// Helper variable to create unique names for the transport iframes:
var counter = 0;
// The iframe transport accepts three additional options:
// options.fileInput: a jQuery collection of file input fields
// options.paramName: the parameter name for the file form data,
// overrides the name property of the file input field(s),
// can be a string or an array of strings.
// options.formData: an array of objects with name and value properties,
// equivalent to the return data of .serializeArray(), e.g.:
// [{name: 'a', value: 1}, {name: 'b', value: 2}]
$.ajaxTransport('iframe', function (options) {
if (options.async) {
var form,
iframe,
addParamChar;
return {
send: function (_, completeCallback) {
form = $('<form style="display:none;"></form>');
form.attr('accept-charset', options.formAcceptCharset);
addParamChar = /\?/.test(options.url) ? '&' : '?';
// XDomainRequest only supports GET and POST:
if (options.type === 'DELETE') {
options.url = options.url + addParamChar + '_method=DELETE';
options.type = 'POST';
} else if (options.type === 'PUT') {
options.url = options.url + addParamChar + '_method=PUT';
options.type = 'POST';
} else if (options.type === 'PATCH') {
options.url = options.url + addParamChar + '_method=PATCH';
options.type = 'POST';
}
// javascript:false as initial iframe src
// prevents warning popups on HTTPS in IE6.
// IE versions below IE8 cannot set the name property of
// elements that have already been added to the DOM,
// so we set the name along with the iframe HTML markup:
counter += 1;
iframe = $(
'<iframe src="javascript:false;" name="iframe-transport-' +
counter + '"></iframe>'
).bind('load', function () {
var fileInputClones,
paramNames = $.isArray(options.paramName) ?
options.paramName : [options.paramName];
iframe
.unbind('load')
.bind('load', function () {
var response;
// Wrap in a try/catch block to catch exceptions thrown
// when trying to access cross-domain iframe contents:
try {
response = iframe.contents();
// Google Chrome and Firefox do not throw an
// exception when calling iframe.contents() on
// cross-domain requests, so we unify the response:
if (!response.length || !response[0].firstChild) {
throw new Error();
}
} catch (e) {
response = undefined;
}
// The complete callback returns the
// iframe content document as response object:
completeCallback(
200,
'success',
{'iframe': response}
);
// Fix for IE endless progress bar activity bug
// (happens on form submits to iframe targets):
$('<iframe src="javascript:false;"></iframe>')
.appendTo(form);
window.setTimeout(function () {
// Removing the form in a setTimeout call
// allows Chrome's developer tools to display
// the response result
form.remove();
}, 0);
});
form
.prop('target', iframe.prop('name'))
.prop('action', options.url)
.prop('method', options.type);
if (options.formData) {
$.each(options.formData, function (index, field) {
$('<input type="hidden"/>')
.prop('name', field.name)
.val(field.value)
.appendTo(form);
});
}
if (options.fileInput && options.fileInput.length &&
options.type === 'POST') {
fileInputClones = options.fileInput.clone();
// Insert a clone for each file input field:
options.fileInput.after(function (index) {
return fileInputClones[index];
});
if (options.paramName) {
options.fileInput.each(function (index) {
$(this).prop(
'name',
paramNames[index] || options.paramName
);
});
}
// Appending the file input fields to the hidden form
// removes them from their original location:
form
.append(options.fileInput)
.prop('enctype', 'multipart/form-data')
// enctype must be set as encoding for IE:
.prop('encoding', 'multipart/form-data');
}
form.submit();
// Insert the file input fields at their original location
// by replacing the clones with the originals:
if (fileInputClones && fileInputClones.length) {
options.fileInput.each(function (index, input) {
var clone = $(fileInputClones[index]);
$(input).prop('name', clone.prop('name'));
clone.replaceWith(input);
});
}
});
form.append(iframe).appendTo(document.body);
},
abort: function () {
if (iframe) {
// javascript:false as iframe src aborts the request
// and prevents warning popups on HTTPS in IE6.
// concat is used to avoid the "Script URL" JSLint error:
iframe
.unbind('load')
.prop('src', 'javascript'.concat(':false;'));
}
if (form) {
form.remove();
}
}
};
}
});
// The iframe transport returns the iframe content document as response.
// The following adds converters from iframe to text, json, html, xml
// and script.
// Please note that the Content-Type for JSON responses has to be text/plain
// or text/html, if the browser doesn't include application/json in the
// Accept header, else IE will show a download dialog.
// The Content-Type for XML responses on the other hand has to be always
// application/xml or text/xml, so IE properly parses the XML response.
// See also
// https://github.com/blueimp/jQuery-File-Upload/wiki/Setup#content-type-negotiation
$.ajaxSetup({
converters: {
'iframe text': function (iframe) {
return iframe && $(iframe[0].body).text();
},
'iframe json': function (iframe) {
return iframe && $.parseJSON($(iframe[0].body).text());
},
'iframe html': function (iframe) {
return iframe && $(iframe[0].body).html();
},
'iframe xml': function (iframe) {
var xmlDoc = iframe && iframe[0];
return xmlDoc && $.isXMLDoc(xmlDoc) ? xmlDoc :
$.parseXML((xmlDoc.XMLDocument && xmlDoc.XMLDocument.xml) ||
$(xmlDoc.body).html());
},
'iframe script': function (iframe) {
return iframe && $.globalEval($(iframe[0].body).text());
}
}
});
}));

View File

@ -8,7 +8,6 @@ OCP\Util::addStyle('files_sharing', 'mobile');
OCP\Util::addScript('files_sharing', 'public'); OCP\Util::addScript('files_sharing', 'public');
OCP\Util::addScript('files', 'fileactions'); OCP\Util::addScript('files', 'fileactions');
OCP\Util::addScript('files', 'fileactionsmenu'); OCP\Util::addScript('files', 'fileactionsmenu');
OCP\Util::addScript('files', 'jquery.iframe-transport');
OCP\Util::addScript('files', 'jquery.fileupload'); OCP\Util::addScript('files', 'jquery.fileupload');
// JS required for folders // JS required for folders

View File

@ -391,7 +391,7 @@ OCA = OCA || {};
*/ */
_setCheckBox: function($element, value) { _setCheckBox: function($element, value) {
if(parseInt(value, 10) === 1) { if(parseInt(value, 10) === 1) {
$element.attr('checked', 'checked'); $element.prop('checked', 'checked');
} else { } else {
$element.removeAttr('checked'); $element.removeAttr('checked');
} }

View File

@ -1337,9 +1337,6 @@ if(typeof localStorage !=='undefined' && localStorage !== null){
var item = localStorage.getItem(OC.localStorage.namespace+name); var item = localStorage.getItem(OC.localStorage.namespace+name);
if(item === null) { if(item === null) {
return null; return null;
} else if (typeof JSON === 'undefined') {
//fallback to jquery for IE6/7/8
return $.parseJSON(item);
} else { } else {
return JSON.parse(item); return JSON.parse(item);
} }
@ -1439,11 +1436,15 @@ function initCore() {
*/ */
moment.locale(OC.getLocale()); moment.locale(OC.getLocale());
if ($.browser.msie || !!navigator.userAgent.match(/Trident\/7\./)) { var userAgent = window.navigator.userAgent;
// for IE10+ that don't have conditional comments var msie = userAgent.indexOf('MSIE ');
// and IE11 doesn't identify as MSIE any more... var trident = userAgent.indexOf('Trident/');
var edge = userAgent.indexOf('Edge/');
if (msie > 0 || trident > 0) {
// (IE 10 or older) || IE 11
$('html').addClass('ie'); $('html').addClass('ie');
} else if (!!navigator.userAgent.match(/Edge\/12/)) { } else if (edge > 0) {
// for edge // for edge
$('html').addClass('edge'); $('html').addClass('edge');
} }

View File

@ -81,12 +81,12 @@ OC.Lostpassword = {
$('#password').parents('form').attr('action'), $('#password').parents('form').attr('action'),
{ {
password : $('#password').val(), password : $('#password').val(),
proceed: $('#encrypted-continue').attr('checked') ? 'true' : 'false' proceed: $('#encrypted-continue').is(':checked') ? 'true' : 'false'
}, },
OC.Lostpassword.resetDone OC.Lostpassword.resetDone
); );
} }
if($('#encrypted-continue').attr('checked')) { if($('#encrypted-continue').is(':checked')) {
$('#reset-password #submit').hide(); $('#reset-password #submit').hide();
$('#reset-password #float-spinner').removeClass('hidden'); $('#reset-password #float-spinner').removeClass('hidden');
} }

View File

@ -120,7 +120,7 @@
label.text(element.text() || item); label.text(element.text() || item);
label.attr('title', element.text() || item); label.attr('title', element.text() || item);
if(settings.checked.indexOf(item) !== -1 || checked) { if(settings.checked.indexOf(item) !== -1 || checked) {
input.attr('checked', true); input.prop('checked', true);
} }
if(checked){ if(checked){
if(settings.singleSelect) { if(settings.singleSelect) {
@ -145,7 +145,7 @@
element.attr('selected','selected'); element.attr('selected','selected');
if(typeof settings.oncheck === 'function') { if(typeof settings.oncheck === 'function') {
if(settings.oncheck(value)===false) { if(settings.oncheck(value)===false) {
$(this).attr('checked', false); $(this).prop('checked', false);
return; return;
} }
} }
@ -157,7 +157,7 @@
element.attr('selected',null); element.attr('selected',null);
if(typeof settings.onuncheck === 'function') { if(typeof settings.onuncheck === 'function') {
if(settings.onuncheck(value)===false) { if(settings.onuncheck(value)===false) {
$(this).attr('checked',true); $(this).prop('checked',true);
return; return;
} }
} }

View File

@ -268,11 +268,11 @@
if ($element.attr('name') === 'edit') { if ($element.attr('name') === 'edit') {
checked = $element.is(':checked'); checked = $element.is(':checked');
// Check/uncheck Create, Update, and Delete checkboxes if Edit is checked/unck // Check/uncheck Create, Update, and Delete checkboxes if Edit is checked/unck
$($checkboxes).attr('checked', checked); $($checkboxes).prop('checked', checked);
} else { } else {
var numberChecked = $checkboxes.filter(':checked').length; var numberChecked = $checkboxes.filter(':checked').length;
checked = numberChecked > 0; checked = numberChecked > 0;
$('input[name="edit"]', $li).attr('checked', checked); $('input[name="edit"]', $li).prop('checked', checked);
} }
var permissions = OC.PERMISSION_READ; var permissions = OC.PERMISSION_READ;

View File

@ -38,7 +38,6 @@ $template = new OC_Template('settings', 'admin', 'user');
$l = \OC::$server->getL10N('settings'); $l = \OC::$server->getL10N('settings');
OC_Util::addScript('settings', 'certificates'); OC_Util::addScript('settings', 'certificates');
OC_Util::addScript('files', 'jquery.iframe-transport');
OC_Util::addScript('files', 'jquery.fileupload'); OC_Util::addScript('files', 'jquery.fileupload');
\OC::$server->getEventDispatcher()->dispatch('OC\Settings\Admin::loadAdditionalScripts'); \OC::$server->getEventDispatcher()->dispatch('OC\Settings\Admin::loadAdditionalScripts');

View File

@ -38,7 +38,7 @@ $(document).ready(function(){
$('#backgroundjobs span.crondate').tipsy({gravity: 's', live: true}); $('#backgroundjobs span.crondate').tipsy({gravity: 's', live: true});
$('#backgroundjobs input').change(function(){ $('#backgroundjobs input').change(function(){
if($(this).attr('checked')){ if($(this).is(':checked')){
var mode = $(this).val(); var mode = $(this).val();
if (mode === 'ajax' || mode === 'webcron' || mode === 'cron') { if (mode === 'ajax' || mode === 'webcron' || mode === 'cron') {
OC.AppConfig.setValue('core', 'backgroundjobs_mode', mode); OC.AppConfig.setValue('core', 'backgroundjobs_mode', mode);
@ -131,7 +131,7 @@ $(document).ready(function(){
$('#setting_smtphost').removeClass('hidden'); $('#setting_smtphost').removeClass('hidden');
$('#mail_smtpsecure_label').removeClass('hidden'); $('#mail_smtpsecure_label').removeClass('hidden');
$('#mail_smtpsecure').removeClass('hidden'); $('#mail_smtpsecure').removeClass('hidden');
if ($('#mail_smtpauth').attr('checked')) { if ($('#mail_smtpauth').is(':checked')) {
$('#mail_credentials').removeClass('hidden'); $('#mail_credentials').removeClass('hidden');
} }
} }

View File

@ -193,15 +193,15 @@ OC.Settings.Apps = OC.Settings.Apps || {
OC.Settings.Apps.isType(app, 'authentication') || OC.Settings.Apps.isType(app, 'logging') || OC.Settings.Apps.isType(app, 'authentication') || OC.Settings.Apps.isType(app, 'logging') ||
OC.Settings.Apps.isType(app, 'prevent_group_restriction')) { OC.Settings.Apps.isType(app, 'prevent_group_restriction')) {
page.find(".groups-enable").hide(); page.find(".groups-enable").hide();
page.find(".groups-enable__checkbox").attr('checked', null); page.find(".groups-enable__checkbox").prop('checked', false);
} else { } else {
page.find('#group_select').val((app.groups || []).join('|')); page.find('#group_select').val((app.groups || []).join('|'));
if (app.active) { if (app.active) {
if (app.groups.length) { if (app.groups.length) {
OC.Settings.Apps.setupGroupsSelect(page.find('#group_select')); OC.Settings.Apps.setupGroupsSelect(page.find('#group_select'));
page.find(".groups-enable__checkbox").attr('checked','checked'); page.find(".groups-enable__checkbox").prop('checked', true);
} else { } else {
page.find(".groups-enable__checkbox").attr('checked', null); page.find(".groups-enable__checkbox").prop('checked', false);
} }
page.find(".groups-enable").show(); page.find(".groups-enable").show();
} else { } else {
@ -289,7 +289,7 @@ OC.Settings.Apps = OC.Settings.Apps || {
if (OC.Settings.Apps.isType(app, 'filesystem') || OC.Settings.Apps.isType(app, 'prelogin') || if (OC.Settings.Apps.isType(app, 'filesystem') || OC.Settings.Apps.isType(app, 'prelogin') ||
OC.Settings.Apps.isType(app, 'authentication') || OC.Settings.Apps.isType(app, 'logging')) { OC.Settings.Apps.isType(app, 'authentication') || OC.Settings.Apps.isType(app, 'logging')) {
element.parent().find(".groups-enable").attr('checked', null); element.parent().find(".groups-enable").prop('checked', true);
element.parent().find(".groups-enable").hide(); element.parent().find(".groups-enable").hide();
element.parent().find('#group_select').hide().val(null); element.parent().find('#group_select').hide().val(null);
} else { } else {

View File

@ -24,10 +24,10 @@ $(document).ready(function () {
}, },
success: function (data) { success: function (data) {
if (typeof data === 'string') { if (typeof data === 'string') {
data = $.parseJSON(data); data = JSON.parse(data);
} else if (data && data.length) { } else if (data && data.length) {
// fetch response from iframe // fetch response from iframe
data = $.parseJSON(data[0].body.innerText); data = JSON.parse(data[0].body.innerText);
} }
if (!data || typeof(data) === 'string') { if (!data || typeof(data) === 'string') {
// IE8 iframe workaround comes here instead of fail() // IE8 iframe workaround comes here instead of fail()

View File

@ -166,7 +166,7 @@ function cleanCropper () {
function avatarResponseHandler (data) { function avatarResponseHandler (data) {
if (typeof data === 'string') { if (typeof data === 'string') {
data = $.parseJSON(data); data = JSON.parse(data);
} }
var $warning = $('#avatar .warning'); var $warning = $('#avatar .warning');
$warning.hide(); $warning.hide();
@ -248,10 +248,10 @@ $(document).ready(function () {
done: function (e, data) { done: function (e, data) {
var response = data; var response = data;
if (typeof data.result === 'string') { if (typeof data.result === 'string') {
response = $.parseJSON(data.result); response = JSON.parse(data.result);
} else if (data.result && data.result.length) { } else if (data.result && data.result.length) {
// fetch response from iframe // fetch response from iframe
response = $.parseJSON(data.result[0].body.innerText); response = JSON.parse(data.result[0].body.innerText);
} else { } else {
response = data.result; response = data.result;
} }

View File

@ -47,7 +47,6 @@ OC_Util::addScript('settings', 'certificates');
OC_Util::addStyle( 'settings', 'settings' ); OC_Util::addStyle( 'settings', 'settings' );
\OC_Util::addVendorScript('strengthify/jquery.strengthify'); \OC_Util::addVendorScript('strengthify/jquery.strengthify');
\OC_Util::addVendorStyle('strengthify/strengthify'); \OC_Util::addVendorStyle('strengthify/strengthify');
\OC_Util::addScript('files', 'jquery.iframe-transport');
\OC_Util::addScript('files', 'jquery.fileupload'); \OC_Util::addScript('files', 'jquery.fileupload');
if ($config->getSystemValue('enable_avatars', true) === true) { if ($config->getSystemValue('enable_avatars', true) === true) {
\OC_Util::addVendorScript('jcrop/js/jquery.Jcrop'); \OC_Util::addVendorScript('jcrop/js/jquery.Jcrop');