diff --git a/modules/.eslintignore b/modules/.eslintignore index 41fbb14996d15c..e076becc5aebcf 100644 --- a/modules/.eslintignore +++ b/modules/.eslintignore @@ -48,4 +48,5 @@ # These are generated third-party files, not intended for editing or # inspection. # + apps/frontend-js/frontend-js-jquery-web/src/main/resources/META-INF/resources/jquery/form.js apps/frontend-js/frontend-js-svg4everybody-web/src/main/resources/META-INF/resources/svg4everybody.js \ No newline at end of file diff --git a/modules/.prettierignore b/modules/.prettierignore index 21082801946d7e..019669676cb4ec 100644 --- a/modules/.prettierignore +++ b/modules/.prettierignore @@ -47,5 +47,6 @@ # These are generated third-party files, not intended for editing or # inspection. # + /apps/frontend-js/frontend-js-jquery-web/src/main/resources/META-INF/resources/jquery/form.js /apps/frontend-js/frontend-js-svg4everybody-web/src/main/resources/META-INF/resources/svg4everybody.js /yarn-*.js \ No newline at end of file diff --git a/modules/apps/frontend-js/frontend-js-jquery-web/build.gradle b/modules/apps/frontend-js/frontend-js-jquery-web/build.gradle index e8dbac94b496e6..209f6593b49e26 100644 --- a/modules/apps/frontend-js/frontend-js-jquery-web/build.gradle +++ b/modules/apps/frontend-js/frontend-js-jquery-web/build.gradle @@ -1,11 +1,21 @@ +import com.liferay.gradle.plugins.defaults.internal.util.GitUtil +import com.liferay.gradle.util.FileUtil import com.liferay.gradle.util.copy.StripPathSegmentsAction +ext { + jQueryFormVersion = "3.51" + + jQueryFormURL = "https://raw.githubusercontent.com/jquery-form/form/${jQueryFormVersion}/jquery.form.js" +} + task buildBootstrapJS(type: Copy) task buildJQuery(type: Copy) +task buildJQueryForm(type: Copy) task buildPopperJS(type: Copy) +task patchJQueryForm(type: Copy) File jsDestinationDir = file("tmp/META-INF/resources") -File jqueryDestinationDir = new File(jsDestinationDir, "jquery") +File jQueryDestinationDir = new File(jsDestinationDir, "jquery") buildBootstrapJS { dependsOn buildJQuery @@ -18,14 +28,14 @@ buildBootstrapJS { include "bootstrap/dist/js/bootstrap.bundle.min.js.map" includeEmptyDirs = false - into jqueryDestinationDir + into jQueryDestinationDir } buildJQuery { dependsOn npmInstall doFirst { - delete jqueryDestinationDir + delete jQueryDestinationDir } eachFile new StripPathSegmentsAction(2) @@ -36,7 +46,26 @@ buildJQuery { include "jquery/dist/jquery.min.js.map" includeEmptyDirs = false - into jqueryDestinationDir + into jQueryDestinationDir +} + +buildJQueryForm { + File jQueryFormURLFile = file("src/main/resources/META-INF/resources/jquery/form.js") + + ext { + autoClean = false + } + + from { + FileUtil.get(project, project.jQueryFormURL, jQueryFormURLFile) + } + + into jQueryFormURLFile.parentFile + + eachFile { + GitUtil.getGitResult(project, "apply", "-v", + "src/main/resources/META-INF/resources/_diffs/jquery.form.patch") + } } buildPopperJS { @@ -50,12 +79,13 @@ buildPopperJS { include "popper.js/dist/umd/popper.min.js.map" includeEmptyDirs = false - into jqueryDestinationDir + into jQueryDestinationDir } classes { dependsOn buildBootstrapJS dependsOn buildJQuery + dependsOn buildJQueryForm dependsOn buildPopperJS } diff --git a/modules/apps/frontend-js/frontend-js-jquery-web/src/main/resources/META-INF/resources/_diffs/jquery.form.patch b/modules/apps/frontend-js/frontend-js-jquery-web/src/main/resources/META-INF/resources/_diffs/jquery.form.patch new file mode 100644 index 00000000000000..d54f3394d0cb67 --- /dev/null +++ b/modules/apps/frontend-js/frontend-js-jquery-web/src/main/resources/META-INF/resources/_diffs/jquery.form.patch @@ -0,0 +1,39 @@ +diff --git a/modules/apps/frontend-js/frontend-js-jquery-web/src/main/resources/META-INF/resources/jquery/form.js b/modules/apps/frontend-js/frontend-js-jquery-web/src/main/resources/META-INF/resources/jquery/form.js +index 591ad6f1fe7b..04cf9498c9a2 100644 +--- a/modules/apps/frontend-js/frontend-js-jquery-web/src/main/resources/META-INF/resources/jquery/form.js ++++ b/modules/apps/frontend-js/frontend-js-jquery-web/src/main/resources/META-INF/resources/jquery/form.js +@@ -13,7 +13,7 @@ + // AMD support + (function (factory) { + "use strict"; +- if (typeof define === 'function' && define.amd) { ++ if (false && typeof define === 'function' && define.amd) { + // using AMD; register as anon module + define(['jquery'], factory); + } else { +@@ -190,6 +190,11 @@ $.fn.ajaxSubmit = function(options) { + var oldSuccess = options.success || function(){}; + callbacks.push(function(data) { + var fn = options.replaceTarget ? 'replaceWith' : 'html'; ++ ++ data = options.replaceTarget ++ ? data ++ : $.parseHTML($('
').text(data).html()); ++ + $(options.target)[fn](data).each(oldSuccess, arguments); + }); + } +@@ -800,9 +805,10 @@ $.fn.ajaxSubmit = function(options) { + } + return (doc && doc.documentElement && doc.documentElement.nodeName != 'parsererror') ? doc : null; + }; +- var parseJSON = $.parseJSON || function(s) { +- /*jslint evil:true */ +- return window['eval']('(' + s + ')'); ++ var parseJSON = $.parseJSON || function() { ++ window.console.error('jQuery.paseJSON is undefined'); ++ ++ return null; + }; + + var httpData = function( xhr, type, s ) { // mostly lifted from jq1.4.4 diff --git a/modules/apps/frontend-js/frontend-js-jquery-web/src/main/resources/META-INF/resources/jquery/form.js b/modules/apps/frontend-js/frontend-js-jquery-web/src/main/resources/META-INF/resources/jquery/form.js index bb6c3dd3ab38f8..04cf9498c9a22b 100644 --- a/modules/apps/frontend-js/frontend-js-jquery-web/src/main/resources/META-INF/resources/jquery/form.js +++ b/modules/apps/frontend-js/frontend-js-jquery-web/src/main/resources/META-INF/resources/jquery/form.js @@ -1,51 +1,31 @@ -/** - * Copyright (c) 2000-present Liferay, Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2.1 of the License, or (at your option) - * any later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. +/*! + * jQuery Form Plugin + * version: 3.51.0-2014.06.20 + * Requires jQuery v1.5 or later + * Copyright (c) 2014 M. Alsup + * Examples and documentation at: http://malsup.com/jquery/form/ + * Project repository: https://github.com/malsup/form + * Dual licensed under the MIT and GPL licenses. + * https://github.com/malsup/form#copyright-and-license */ - -(function (jQuery) { - - /*! - * jQuery Form Plugin - * version: 3.51.0-2014.06.20 - * Requires jQuery v1.5 or later - * Copyright (c) 2014 M. Alsup - * Examples and documentation at: http://malsup.com/jquery/form/ - * Project repository: https://github.com/malsup/form - * Dual licensed under the MIT and GPL licenses. - * https://github.com/malsup/form#copyright-and-license - */ - /*global ActiveXObject */ - - // AMD support - - (function (factory) { - 'use strict'; - if (false && typeof define === 'function' && define.amd) { - - // using AMD; register as anon module - - define(['jquery'], factory); - } - else { - - // no AMD; invoke directly - - factory(typeof jQuery != 'undefined' ? jQuery : window.Zepto); - } - })(function ($) { - 'use strict'; - - /* +/*global ActiveXObject */ + +// AMD support +(function (factory) { + "use strict"; + if (false && typeof define === 'function' && define.amd) { + // using AMD; register as anon module + define(['jquery'], factory); + } else { + // no AMD; invoke directly + factory( (typeof(jQuery) != 'undefined') ? jQuery : window.Zepto ); + } +} + +(function($) { +"use strict"; + +/* Usage Note: ----------- Do not use both ajaxSubmit and ajaxForm on the same form. These @@ -82,1581 +62,1222 @@ at the appropriate time. */ - /** - * Feature detection - */ - var feature = {}; - feature.fileapi = $("").get(0).files !== undefined; - feature.formdata = window.FormData !== undefined; - - var hasProp = !!$.fn.prop; - - // attr2 uses prop when it can but checks the return type for - // an expected string. this accounts for the case where a form - // contains inputs with names like "action" or "method"; in those - // cases "prop" returns the element - - $.fn.attr2 = function () { - if (!hasProp) { - return this.attr.apply(this, arguments); - } - var val = this.prop.apply(this, arguments); - if ((val && val.jquery) || typeof val === 'string') { - return val; - } - return this.attr.apply(this, arguments); - }; - - /** - * ajaxSubmit() provides a mechanism for immediately submitting - * an HTML form using AJAX. - */ - $.fn.ajaxSubmit = function (options) { - /*jshint scripturl:true */ - - // fast fail if nothing selected (http://dev.jquery.com/ticket/2752) - - if (!this.length) { - log( - 'ajaxSubmit: skipping submit process - no element selected' - ); - return this; - } - - var method, - action, - url, - $form = this; - - if (typeof options == 'function') { - options = {success: options}; - } - else if (options === undefined) { - options = {}; - } - - method = options.type || this.attr2('method'); - action = options.url || this.attr2('action'); - - url = typeof action === 'string' ? $.trim(action) : ''; - url = url || window.location.href || ''; - if (url) { - - // clean url (don't include hash vaue) - - url = (url.match(/^([^#]+)/) || [])[1]; - } - - options = $.extend( - true, - { - url, - success: $.ajaxSettings.success, - type: method || $.ajaxSettings.type, - iframeSrc: /^https/i.test(window.location.href || '') - ? 'javascript:false' - : 'about:blank', - }, - options - ); - - // hook for manipulating the form data before it is extracted; - // convenient for use with rich editors like tinyMCE or FCKEditor - - var veto = {}; - this.trigger('form-pre-serialize', [this, options, veto]); - if (veto.veto) { - log('ajaxSubmit: submit vetoed via form-pre-serialize trigger'); - return this; - } - - // provide opportunity to alter form data before it is serialized - - if ( - options.beforeSerialize && - options.beforeSerialize(this, options) === false - ) { - log('ajaxSubmit: submit aborted via beforeSerialize callback'); - return this; - } - - var traditional = options.traditional; - if (traditional === undefined) { - traditional = $.ajaxSettings.traditional; - } - - var elements = []; - var qx, - a = this.formToArray(options.semantic, elements); - if (options.data) { - options.extraData = options.data; - qx = $.param(options.data, traditional); - } - - // give pre-submit callback an opportunity to abort the submit - - if ( - options.beforeSubmit && - options.beforeSubmit(a, this, options) === false - ) { - log('ajaxSubmit: submit aborted via beforeSubmit callback'); - return this; - } - - // fire vetoable 'validate' event - - this.trigger('form-submit-validate', [a, this, options, veto]); - if (veto.veto) { - log( - 'ajaxSubmit: submit vetoed via form-submit-validate trigger' - ); - return this; - } - - var q = $.param(a, traditional); - if (qx) { - q = q ? q + '&' + qx : qx; - } - if (options.type.toUpperCase() == 'GET') { - options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q; - options.data = null; // data is null for 'get' - } - else { - options.data = q; // data is the query string for 'post' - } - - var callbacks = []; - if (options.resetForm) { - callbacks.push(function () { - $form.resetForm(); - }); - } - if (options.clearForm) { - callbacks.push(function () { - $form.clearForm(options.includeHidden); - }); - } - - // perform a load on the target only if dataType is not provided - - if (!options.dataType && options.target) { - var oldSuccess = options.success || function () {}; - callbacks.push(function (data) { - var fn = options.replaceTarget ? 'replaceWith' : 'html'; - $(options.target)[fn](data).each(oldSuccess, arguments); - }); - } - else if (options.success) { - callbacks.push(options.success); - } - - options.success = function (data, status, xhr) { - - // jQuery 1.4+ passes xhr as 3rd arg - var context = options.context || this; // jQuery 1.4+ supports scope context - for (var i = 0, max = callbacks.length; i < max; i++) { - callbacks[i].apply(context, [ - data, - status, - xhr || $form, - $form, - ]); - } - }; - - if (options.error) { - var oldError = options.error; - options.error = function (xhr, status, error) { - var context = options.context || this; - oldError.apply(context, [xhr, status, error, $form]); - }; - } - - if (options.complete) { - var oldComplete = options.complete; - options.complete = function (xhr, status) { - var context = options.context || this; - oldComplete.apply(context, [xhr, status, $form]); - }; - } - - // are there files to upload? - - // [value] (issue #113), also see comment: - // https://github.com/malsup/form/commit/588306aedba1de01388032d5f42a60159eea9228#commitcomment-2180219 - - var fileInputs = $('input[type=file]:enabled', this).filter( - function () { - return $(this).val() !== ''; - } - ); - - var hasFileInputs = fileInputs.length > 0; - var mp = 'multipart/form-data'; - var multipart = - $form.attr('enctype') == mp || $form.attr('encoding') == mp; - - var fileAPI = feature.fileapi && feature.formdata; - log('fileAPI :' + fileAPI); - var shouldUseFrame = (hasFileInputs || multipart) && !fileAPI; - - var jqxhr; - - // options.iframe allows user to force iframe mode - // 06-NOV-09: now defaulting to iframe mode if file input is detected - - if ( - options.iframe !== false && - (options.iframe || shouldUseFrame) - ) { - - // hack to fix Safari hang (thanks to Tim Molendijk for this) - // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d - - if (options.closeKeepAlive) { - $.get(options.closeKeepAlive, function () { - jqxhr = fileUploadIframe(a); - }); - } - else { - jqxhr = fileUploadIframe(a); - } - } - else if ((hasFileInputs || multipart) && fileAPI) { - jqxhr = fileUploadXhr(a); - } - else { - jqxhr = $.ajax(options); - } - - $form.removeData('jqxhr').data('jqxhr', jqxhr); - - // clear element array - - for (var k = 0; k < elements.length; k++) { - elements[k] = null; - } - - // fire 'notify' event - - this.trigger('form-submit-notify', [this, options]); - return this; - - // utility fn for deep serialization - - function deepSerialize(extraData) { - var serialized = $.param(extraData, options.traditional).split( - '&' - ); - var len = serialized.length; - var result = []; - var i, part; - for (i = 0; i < len; i++) { - - // #252; undo param space replacement - - serialized[i] = serialized[i].replace(/\+/g, ' '); - part = serialized[i].split('='); - - // #278; use array instead of object storage, favoring array serializations - - result.push([ - decodeURIComponent(part[0]), - decodeURIComponent(part[1]), - ]); - } - return result; - } - - // XMLHttpRequest Level 2 file uploads (big hat tip to francois2metz) - - function fileUploadXhr(a) { - var formdata = new FormData(); - - for (var i = 0; i < a.length; i++) { - formdata.append(a[i].name, a[i].value); - } - - if (options.extraData) { - var serializedData = deepSerialize(options.extraData); - for (i = 0; i < serializedData.length; i++) { - if (serializedData[i]) { - formdata.append( - serializedData[i][0], - serializedData[i][1] - ); - } - } - } - - options.data = null; - - var s = $.extend(true, {}, $.ajaxSettings, options, { - contentType: false, - processData: false, - cache: false, - type: method || 'POST', - }); - - if (options.uploadProgress) { - - // workaround because jqXHR does not expose upload property - - s.xhr = function () { - var xhr = $.ajaxSettings.xhr(); - if (xhr.upload) { - xhr.upload.addEventListener( - 'progress', - function (event) { - var percent = 0; - var position = - event.loaded || - event.position; /*event.position is deprecated*/ - var total = event.total; - if (event.lengthComputable) { - percent = Math.ceil( - (position / total) * 100 - ); - } - options.uploadProgress( - event, - position, - total, - percent - ); - }, - false - ); - } - return xhr; - }; - } - - s.data = null; - var beforeSend = s.beforeSend; - s.beforeSend = function (xhr, o) { - - //Send FormData() provided by user - - if (options.formData) { - o.data = options.formData; - } - else { - o.data = formdata; - } - if (beforeSend) { - beforeSend.call(this, xhr, o); - } - }; - return $.ajax(s); - } - - // private function for handling file uploads (hat tip to YAHOO!) - - function fileUploadIframe(a) { - var form = $form[0], - el, - i, - s, - g, - id, - $io, - io, - xhr, - sub, - n, - timedOut, - timeoutHandle; - var deferred = $.Deferred(); - - // #341 - - deferred.abort = function (status) { - xhr.abort(status); - }; - - if (a) { - - // ensure that every serialized input is still enabled - - for (i = 0; i < elements.length; i++) { - el = $(elements[i]); - if (hasProp) { - el.prop('disabled', false); - } - else { - el.removeAttr('disabled'); - } - } - } - - s = $.extend(true, {}, $.ajaxSettings, options); - s.context = s.context || s; - id = 'jqFormIO' + new Date().getTime(); - if (s.iframeTarget) { - $io = $(s.iframeTarget); - n = $io.attr2('name'); - if (!n) { - $io.attr2('name', id); - } - else { - id = n; - } - } - else { - $io = $( - '