1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-29 09:29:55 +02:00

Update JqueryCore so that setting $config->debug = 'dev'; makes it use a newer jQuery version and with jquery-migrate enabled.

This commit is contained in:
Ryan Cramer
2020-07-03 16:11:57 -04:00
parent 9389d4abdc
commit 6acb8028e3
4 changed files with 302 additions and 84 deletions

View File

@@ -20,18 +20,12 @@ class JqueryCore extends ModuleJS {
'autoload' => false 'autoload' => false
); );
} }
/**
* Set devMode to true in order to test/develop with newer versions of jQuery
*
*/
const devMode = false;
public function wired() { public function wired() {
$this->addComponents(array( $this->addComponents(array(
'core-dev' => 'jquery-1.11.1.js', 'core-dev' => 'dev/JqueryCore.js?v=1.11.1',
'latest' => 'jquery-1.11.1.js', 'migrate-dev' => 'dev/jquery-migrate-1.4.1.js',
'migrate-dev' => 'jquery-migrate-1.2.1.js', 'latest' => 'dev/JqueryCore.js',
'cookie' => 'jquery.cookie.js', 'cookie' => 'jquery.cookie.js',
'iframe-resizer' => 'iframe-resizer.min.js', 'iframe-resizer' => 'iframe-resizer.min.js',
'iframe-resizer-frame' => 'iframe-resizer-frame.min.js', 'iframe-resizer-frame' => 'iframe-resizer-frame.min.js',
@@ -41,7 +35,14 @@ class JqueryCore extends ModuleJS {
)); ));
$info = self::getModuleInfo(); $info = self::getModuleInfo();
$config = $this->config; $config = $this->config;
$config->scripts->prepend($config->urls('JqueryCore') . "JqueryCore.js?v=$info[version]"); $url = $this->config->urls('JqueryCore');
$this->loadScripts = false;
if($config->debug === 'dev') {
$config->scripts->prepend($url . $this->components['migrate-dev']);
$config->scripts->prepend($url . $this->components['core-dev']);
} else {
$config->scripts->prepend($url . "JqueryCore.js?v=$info[version]");
}
} }
public function ___use($name) { public function ___use($name) {
@@ -54,21 +55,4 @@ class JqueryCore extends ModuleJS {
} }
return parent::___use($name); return parent::___use($name);
} }
/**
* Initialize JqueryCore
*
*/
public function init() {
if(self::devMode) {
$this->use('core-dev');
$this->use('migrate-dev');
$this->loadStyles = false;
$this->loadScripts = false;
}
parent::init();
}
} }

File diff suppressed because one or more lines are too long

View File

@@ -1,13 +1,15 @@
/*! /*!
* jQuery Migrate - v1.2.1 - 2013-05-08 * jQuery Migrate - v1.4.1 - 2016-05-19
* https://github.com/jquery/jquery-migrate * Copyright jQuery Foundation and other contributors
* Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors; Licensed MIT
*/ */
(function( jQuery, window, undefined ) { (function( jQuery, window, undefined ) {
// See http://bugs.jquery.com/ticket/13335 // See http://bugs.jquery.com/ticket/13335
// "use strict"; // "use strict";
jQuery.migrateVersion = "1.4.1";
var warnedAbout = {}; var warnedAbout = {};
// List of warnings already given; public read only // List of warnings already given; public read only
@@ -17,8 +19,10 @@ jQuery.migrateWarnings = [];
// jQuery.migrateMute = false; // jQuery.migrateMute = false;
// Show a message on the console so devs know we're active // Show a message on the console so devs know we're active
if ( !jQuery.migrateMute && window.console && window.console.log ) { if ( window.console && window.console.log ) {
window.console.log("JQMIGRATE: Logging is active"); window.console.log( "JQMIGRATE: Migrate is installed" +
( jQuery.migrateMute ? "" : " with logging active" ) +
", version " + jQuery.migrateVersion );
} }
// Set to false to disable traces that appear with warnings // Set to false to disable traces that appear with warnings
@@ -152,7 +156,7 @@ jQuery.attr = function( elem, name, value, pass ) {
// Warn only for attributes that can remain distinct from their properties post-1.9 // Warn only for attributes that can remain distinct from their properties post-1.9
if ( ruseDefault.test( lowerName ) ) { if ( ruseDefault.test( lowerName ) ) {
migrateWarn( "jQuery.fn.attr('" + lowerName + "') may use property instead of attribute" ); migrateWarn( "jQuery.fn.attr('" + lowerName + "') might use property instead of attribute" );
} }
} }
@@ -189,46 +193,114 @@ jQuery.attrHooks.value = {
var matched, browser, var matched, browser,
oldInit = jQuery.fn.init, oldInit = jQuery.fn.init,
oldFind = jQuery.find,
oldParseJSON = jQuery.parseJSON, oldParseJSON = jQuery.parseJSON,
rspaceAngle = /^\s*</,
rattrHashTest = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/,
rattrHashGlob = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/g,
// Note: XSS check is done below after string is trimmed // Note: XSS check is done below after string is trimmed
rquickExpr = /^([^<]*)(<[\w\W]+>)([^>]*)$/; rquickExpr = /^([^<]*)(<[\w\W]+>)([^>]*)$/;
// $(html) "looks like html" rule change // $(html) "looks like html" rule change
jQuery.fn.init = function( selector, context, rootjQuery ) { jQuery.fn.init = function( selector, context, rootjQuery ) {
var match; var match, ret;
if ( selector && typeof selector === "string" && !jQuery.isPlainObject( context ) && if ( selector && typeof selector === "string" ) {
(match = rquickExpr.exec( jQuery.trim( selector ) )) && match[ 0 ] ) { if ( !jQuery.isPlainObject( context ) &&
// This is an HTML string according to the "old" rules; is it still? (match = rquickExpr.exec( jQuery.trim( selector ) )) && match[ 0 ] ) {
if ( selector.charAt( 0 ) !== "<" ) {
migrateWarn("$(html) HTML strings must start with '<' character"); // This is an HTML string according to the "old" rules; is it still?
} if ( !rspaceAngle.test( selector ) ) {
if ( match[ 3 ] ) { migrateWarn("$(html) HTML strings must start with '<' character");
migrateWarn("$(html) HTML text after last tag is ignored"); }
} if ( match[ 3 ] ) {
// Consistently reject any HTML-like string starting with a hash (#9521) migrateWarn("$(html) HTML text after last tag is ignored");
// Note that this may break jQuery 1.6.x code that otherwise would work. }
if ( match[ 0 ].charAt( 0 ) === "#" ) {
migrateWarn("HTML string cannot start with a '#' character"); // Consistently reject any HTML-like string starting with a hash (gh-9521)
jQuery.error("JQMIGRATE: Invalid selector string (XSS)"); // Note that this may break jQuery 1.6.x code that otherwise would work.
} if ( match[ 0 ].charAt( 0 ) === "#" ) {
// Now process using loose rules; let pre-1.8 play too migrateWarn("HTML string cannot start with a '#' character");
if ( context && context.context ) { jQuery.error("JQMIGRATE: Invalid selector string (XSS)");
// jQuery object as context; parseHTML expects a DOM object }
context = context.context;
} // Now process using loose rules; let pre-1.8 play too
if ( jQuery.parseHTML ) { // Is this a jQuery context? parseHTML expects a DOM element (#178)
return oldInit.call( this, jQuery.parseHTML( match[ 2 ], context, true ), if ( context && context.context && context.context.nodeType ) {
context, rootjQuery ); context = context.context;
}
if ( jQuery.parseHTML ) {
return oldInit.call( this,
jQuery.parseHTML( match[ 2 ], context && context.ownerDocument ||
context || document, true ), context, rootjQuery );
}
} }
} }
return oldInit.apply( this, arguments );
ret = oldInit.apply( this, arguments );
// Fill in selector and context properties so .live() works
if ( selector && selector.selector !== undefined ) {
// A jQuery object, copy its properties
ret.selector = selector.selector;
ret.context = selector.context;
} else {
ret.selector = typeof selector === "string" ? selector : "";
if ( selector ) {
ret.context = selector.nodeType? selector : context || document;
}
}
return ret;
}; };
jQuery.fn.init.prototype = jQuery.fn; jQuery.fn.init.prototype = jQuery.fn;
jQuery.find = function( selector ) {
var args = Array.prototype.slice.call( arguments );
// Support: PhantomJS 1.x
// String#match fails to match when used with a //g RegExp, only on some strings
if ( typeof selector === "string" && rattrHashTest.test( selector ) ) {
// The nonstandard and undocumented unquoted-hash was removed in jQuery 1.12.0
// First see if qS thinks it's a valid selector, if so avoid a false positive
try {
document.querySelector( selector );
} catch ( err1 ) {
// Didn't *look* valid to qSA, warn and try quoting what we think is the value
selector = selector.replace( rattrHashGlob, function( _, attr, op, value ) {
return "[" + attr + op + "\"" + value + "\"]";
} );
// If the regexp *may* have created an invalid selector, don't update it
// Note that there may be false alarms if selector uses jQuery extensions
try {
document.querySelector( selector );
migrateWarn( "Attribute selector with '#' must be quoted: " + args[ 0 ] );
args[ 0 ] = selector;
} catch ( err2 ) {
migrateWarn( "Attribute selector with '#' was not fixed: " + args[ 0 ] );
}
}
}
return oldFind.apply( this, args );
};
// Copy properties attached to original jQuery.find method (e.g. .attr, .isXML)
var findProp;
for ( findProp in oldFind ) {
if ( Object.prototype.hasOwnProperty.call( oldFind, findProp ) ) {
jQuery.find[ findProp ] = oldFind[ findProp ];
}
}
// Let $.parseJSON(falsy_value) return null // Let $.parseJSON(falsy_value) return null
jQuery.parseJSON = function( json ) { jQuery.parseJSON = function( json ) {
if ( !json && json !== null ) { if ( !json ) {
migrateWarn("jQuery.parseJSON requires a valid JSON string"); migrateWarn("jQuery.parseJSON requires a valid JSON string");
return null; return null;
} }
@@ -274,6 +346,11 @@ if ( !jQuery.browser ) {
// Warn if the code tries to get jQuery.browser // Warn if the code tries to get jQuery.browser
migrateWarnProp( jQuery, "browser", jQuery.browser, "jQuery.browser is deprecated" ); migrateWarnProp( jQuery, "browser", jQuery.browser, "jQuery.browser is deprecated" );
// jQuery.boxModel deprecated in 1.3, jQuery.support.boxModel deprecated in 1.7
jQuery.boxModel = jQuery.support.boxModel = (document.compatMode === "CSS1Compat");
migrateWarnProp( jQuery, "boxModel", jQuery.boxModel, "jQuery.boxModel is deprecated" );
migrateWarnProp( jQuery.support, "boxModel", jQuery.support.boxModel, "jQuery.support.boxModel is deprecated" );
jQuery.sub = function() { jQuery.sub = function() {
function jQuerySub( selector, context ) { function jQuerySub( selector, context ) {
return new jQuerySub.fn.init( selector, context ); return new jQuerySub.fn.init( selector, context );
@@ -284,11 +361,10 @@ jQuery.sub = function() {
jQuerySub.fn.constructor = jQuerySub; jQuerySub.fn.constructor = jQuerySub;
jQuerySub.sub = this.sub; jQuerySub.sub = this.sub;
jQuerySub.fn.init = function init( selector, context ) { jQuerySub.fn.init = function init( selector, context ) {
if ( context && context instanceof jQuery && !(context instanceof jQuerySub) ) { var instance = jQuery.fn.init.call( this, selector, context, rootjQuerySub );
context = jQuerySub( context ); return instance instanceof jQuerySub ?
} instance :
jQuerySub( instance );
return jQuery.fn.init.call( this, selector, context, rootjQuerySub );
}; };
jQuerySub.fn.init.prototype = jQuerySub.fn; jQuerySub.fn.init.prototype = jQuerySub.fn;
var rootjQuerySub = jQuerySub(document); var rootjQuerySub = jQuerySub(document);
@@ -296,6 +372,57 @@ jQuery.sub = function() {
return jQuerySub; return jQuerySub;
}; };
// The number of elements contained in the matched element set
jQuery.fn.size = function() {
migrateWarn( "jQuery.fn.size() is deprecated; use the .length property" );
return this.length;
};
var internalSwapCall = false;
// If this version of jQuery has .swap(), don't false-alarm on internal uses
if ( jQuery.swap ) {
jQuery.each( [ "height", "width", "reliableMarginRight" ], function( _, name ) {
var oldHook = jQuery.cssHooks[ name ] && jQuery.cssHooks[ name ].get;
if ( oldHook ) {
jQuery.cssHooks[ name ].get = function() {
var ret;
internalSwapCall = true;
ret = oldHook.apply( this, arguments );
internalSwapCall = false;
return ret;
};
}
});
}
jQuery.swap = function( elem, options, callback, args ) {
var ret, name,
old = {};
if ( !internalSwapCall ) {
migrateWarn( "jQuery.swap() is undocumented and deprecated" );
}
// Remember the old values, and insert the new ones
for ( name in options ) {
old[ name ] = elem.style[ name ];
elem.style[ name ] = options[ name ];
}
ret = callback.apply( elem, args || [] );
// Revert the old values
for ( name in options ) {
elem.style[ name ] = old[ name ];
}
return ret;
};
// Ensure that $.ajax gets the new parseJSON defined in core.js // Ensure that $.ajax gets the new parseJSON defined in core.js
jQuery.ajaxSetup({ jQuery.ajaxSetup({
@@ -324,13 +451,7 @@ jQuery.fn.data = function( name ) {
}; };
var rscriptType = /\/(java|ecma)script/i, var rscriptType = /\/(java|ecma)script/i;
oldSelf = jQuery.fn.andSelf || jQuery.fn.addBack;
jQuery.fn.andSelf = function() {
migrateWarn("jQuery.fn.andSelf() replaced by jQuery.fn.addBack()");
return oldSelf.apply( this, arguments );
};
// Since jQuery.clean is used internally on older versions, we only shim if it's missing // Since jQuery.clean is used internally on older versions, we only shim if it's missing
if ( !jQuery.clean ) { if ( !jQuery.clean ) {
@@ -388,6 +509,7 @@ var eventAdd = jQuery.event.add,
oldToggle = jQuery.fn.toggle, oldToggle = jQuery.fn.toggle,
oldLive = jQuery.fn.live, oldLive = jQuery.fn.live,
oldDie = jQuery.fn.die, oldDie = jQuery.fn.die,
oldLoad = jQuery.fn.load,
ajaxEvents = "ajaxStart|ajaxStop|ajaxSend|ajaxComplete|ajaxError|ajaxSuccess", ajaxEvents = "ajaxStart|ajaxStop|ajaxSend|ajaxComplete|ajaxError|ajaxSuccess",
rajaxEvent = new RegExp( "\\b(?:" + ajaxEvents + ")\\b" ), rajaxEvent = new RegExp( "\\b(?:" + ajaxEvents + ")\\b" ),
rhoverHack = /(?:^|\s)hover(\.\S+|)\b/, rhoverHack = /(?:^|\s)hover(\.\S+|)\b/,
@@ -422,17 +544,35 @@ jQuery.event.remove = function( elem, types, handler, selector, mappedTypes ){
eventRemove.call( this, elem, hoverHack( types ) || "", handler, selector, mappedTypes ); eventRemove.call( this, elem, hoverHack( types ) || "", handler, selector, mappedTypes );
}; };
jQuery.fn.error = function() { jQuery.each( [ "load", "unload", "error" ], function( _, name ) {
var args = Array.prototype.slice.call( arguments, 0);
migrateWarn("jQuery.fn.error() is deprecated"); jQuery.fn[ name ] = function() {
args.splice( 0, 0, "error" ); var args = Array.prototype.slice.call( arguments, 0 );
if ( arguments.length ) {
return this.bind.apply( this, args ); // If this is an ajax load() the first arg should be the string URL;
} // technically this could also be the "Anything" arg of the event .load()
// error event should not bubble to window, although it does pre-1.7 // which just goes to show why this dumb signature has been deprecated!
this.triggerHandler.apply( this, args ); // jQuery custom builds that exclude the Ajax module justifiably die here.
return this; if ( name === "load" && typeof args[ 0 ] === "string" ) {
}; return oldLoad.apply( this, args );
}
migrateWarn( "jQuery.fn." + name + "() is deprecated" );
args.splice( 0, 0, name );
if ( arguments.length ) {
return this.bind.apply( this, args );
}
// Use .triggerHandler here because:
// - load and unload events don't need to bubble, only applied to window or image
// - error event should not bubble to window, although it does pre-1.7
// See http://bugs.jquery.com/ticket/11820
this.triggerHandler.apply( this, args );
return this;
};
});
jQuery.fn.toggle = function( fn, fn2 ) { jQuery.fn.toggle = function( fn, fn2 ) {
@@ -501,7 +641,7 @@ jQuery.each( ajaxEvents.split("|"),
// The document needs no shimming; must be !== for oldIE // The document needs no shimming; must be !== for oldIE
if ( elem !== document ) { if ( elem !== document ) {
jQuery.event.add( document, name + "." + jQuery.guid, function() { jQuery.event.add( document, name + "." + jQuery.guid, function() {
jQuery.event.trigger( name, null, elem, true ); jQuery.event.trigger( name, Array.prototype.slice.call( arguments, 1 ), elem, true );
}); });
jQuery._data( this, name, jQuery.guid++ ); jQuery._data( this, name, jQuery.guid++ );
} }
@@ -517,5 +657,96 @@ jQuery.each( ajaxEvents.split("|"),
} }
); );
jQuery.event.special.ready = {
setup: function() {
if ( this === document ) {
migrateWarn( "'ready' event is deprecated" );
}
}
};
var oldSelf = jQuery.fn.andSelf || jQuery.fn.addBack,
oldFnFind = jQuery.fn.find;
jQuery.fn.andSelf = function() {
migrateWarn("jQuery.fn.andSelf() replaced by jQuery.fn.addBack()");
return oldSelf.apply( this, arguments );
};
jQuery.fn.find = function( selector ) {
var ret = oldFnFind.apply( this, arguments );
ret.context = this.context;
ret.selector = this.selector ? this.selector + " " + selector : selector;
return ret;
};
// jQuery 1.6 did not support Callbacks, do not warn there
if ( jQuery.Callbacks ) {
var oldDeferred = jQuery.Deferred,
tuples = [
// action, add listener, callbacks, .then handlers, final state
[ "resolve", "done", jQuery.Callbacks("once memory"),
jQuery.Callbacks("once memory"), "resolved" ],
[ "reject", "fail", jQuery.Callbacks("once memory"),
jQuery.Callbacks("once memory"), "rejected" ],
[ "notify", "progress", jQuery.Callbacks("memory"),
jQuery.Callbacks("memory") ]
];
jQuery.Deferred = function( func ) {
var deferred = oldDeferred(),
promise = deferred.promise();
deferred.pipe = promise.pipe = function( /* fnDone, fnFail, fnProgress */ ) {
var fns = arguments;
migrateWarn( "deferred.pipe() is deprecated" );
return jQuery.Deferred(function( newDefer ) {
jQuery.each( tuples, function( i, tuple ) {
var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
// deferred.done(function() { bind to newDefer or newDefer.resolve })
// deferred.fail(function() { bind to newDefer or newDefer.reject })
// deferred.progress(function() { bind to newDefer or newDefer.notify })
deferred[ tuple[1] ](function() {
var returned = fn && fn.apply( this, arguments );
if ( returned && jQuery.isFunction( returned.promise ) ) {
returned.promise()
.done( newDefer.resolve )
.fail( newDefer.reject )
.progress( newDefer.notify );
} else {
newDefer[ tuple[ 0 ] + "With" ](
this === promise ? newDefer.promise() : this,
fn ? [ returned ] : arguments
);
}
});
});
fns = null;
}).promise();
};
deferred.isResolved = function() {
migrateWarn( "deferred.isResolved is deprecated" );
return deferred.state() === "resolved";
};
deferred.isRejected = function() {
migrateWarn( "deferred.isRejected is deprecated" );
return deferred.state() === "rejected";
};
if ( func ) {
func.call( deferred, deferred );
}
return deferred;
};
}
})( jQuery, window ); })( jQuery, window );

File diff suppressed because one or more lines are too long